@caupulican/pi-adaptative 0.81.41 → 0.81.42

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 (237) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
  3. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
  4. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
  5. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
  6. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
  7. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
  8. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
  9. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
  10. package/dist/core/agent-paths.d.ts +32 -0
  11. package/dist/core/agent-paths.d.ts.map +1 -1
  12. package/dist/core/agent-paths.js +65 -0
  13. package/dist/core/agent-paths.js.map +1 -1
  14. package/dist/core/agent-session-contracts.d.ts +19 -1
  15. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  16. package/dist/core/agent-session-contracts.js.map +1 -1
  17. package/dist/core/agent-session.d.ts.map +1 -1
  18. package/dist/core/agent-session.js +4 -9
  19. package/dist/core/agent-session.js.map +1 -1
  20. package/dist/core/autonomy/contracts.d.ts +2 -0
  21. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  22. package/dist/core/autonomy/contracts.js.map +1 -1
  23. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  24. package/dist/core/autonomy/envelope-enforcement.js +4 -9
  25. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  26. package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
  27. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  28. package/dist/core/autonomy/lane-tool-surface.js +17 -4
  29. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  30. package/dist/core/autonomy/path-scope.d.ts +14 -0
  31. package/dist/core/autonomy/path-scope.d.ts.map +1 -1
  32. package/dist/core/autonomy/path-scope.js +37 -6
  33. package/dist/core/autonomy/path-scope.js.map +1 -1
  34. package/dist/core/background-lane-controller.d.ts +27 -1
  35. package/dist/core/background-lane-controller.d.ts.map +1 -1
  36. package/dist/core/background-lane-controller.js +32 -1
  37. package/dist/core/background-lane-controller.js.map +1 -1
  38. package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
  39. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  40. package/dist/core/delegation/managed-lane-controller.js +84 -41
  41. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  42. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
  43. package/dist/core/delegation/session-worker-claim.js +4 -3
  44. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  45. package/dist/core/delegation/worker-action-journal.d.ts +73 -0
  46. package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
  47. package/dist/core/delegation/worker-action-journal.js +297 -0
  48. package/dist/core/delegation/worker-action-journal.js.map +1 -0
  49. package/dist/core/delegation/worker-actions.d.ts +36 -1
  50. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  51. package/dist/core/delegation/worker-actions.js +171 -46
  52. package/dist/core/delegation/worker-actions.js.map +1 -1
  53. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
  54. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
  55. package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
  56. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
  57. package/dist/core/delegation/worker-agent-control.d.ts +66 -0
  58. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
  59. package/dist/core/delegation/worker-agent-control.js +163 -0
  60. package/dist/core/delegation/worker-agent-control.js.map +1 -0
  61. package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
  62. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
  63. package/dist/core/delegation/worker-attempt-executor.js +343 -0
  64. package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
  65. package/dist/core/delegation/worker-claim.d.ts +30 -0
  66. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  67. package/dist/core/delegation/worker-claim.js +205 -53
  68. package/dist/core/delegation/worker-claim.js.map +1 -1
  69. package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
  70. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
  71. package/dist/core/delegation/worker-conversation-store.js +442 -0
  72. package/dist/core/delegation/worker-conversation-store.js.map +1 -0
  73. package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
  74. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  75. package/dist/core/delegation/worker-delegation-controller.js +386 -251
  76. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  77. package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
  78. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  79. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  80. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
  81. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
  82. package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
  83. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
  84. package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
  85. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  86. package/dist/core/delegation/worker-execution-policy.js +5 -7
  87. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  88. package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
  89. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  90. package/dist/core/delegation/worker-lifecycle.js +120 -0
  91. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  92. package/dist/core/delegation/worker-process-owner.d.ts +18 -0
  93. package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
  94. package/dist/core/delegation/worker-process-owner.js +54 -0
  95. package/dist/core/delegation/worker-process-owner.js.map +1 -0
  96. package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
  97. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  98. package/dist/core/delegation/worker-profile-resolver.js +8 -0
  99. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  100. package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
  101. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
  102. package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
  103. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
  104. package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
  105. package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
  106. package/dist/core/delegation/worker-resource-catalog.js +116 -0
  107. package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
  108. package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
  109. package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
  110. package/dist/core/delegation/worker-resource-materializer.js +137 -0
  111. package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
  112. package/dist/core/delegation/worker-runner.d.ts +3 -1
  113. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  114. package/dist/core/delegation/worker-runner.js +189 -54
  115. package/dist/core/delegation/worker-runner.js.map +1 -1
  116. package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
  117. package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
  118. package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
  119. package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
  120. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
  121. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
  122. package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
  123. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
  124. package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
  125. package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
  126. package/dist/core/delegation/worker-write-reservation.js +348 -0
  127. package/dist/core/delegation/worker-write-reservation.js.map +1 -0
  128. package/dist/core/models/model-endpoint.d.ts +3 -0
  129. package/dist/core/models/model-endpoint.d.ts.map +1 -0
  130. package/dist/core/models/model-endpoint.js +11 -0
  131. package/dist/core/models/model-endpoint.js.map +1 -0
  132. package/dist/core/orchestration/agent-resume.d.ts +2 -0
  133. package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
  134. package/dist/core/orchestration/agent-resume.js +7 -0
  135. package/dist/core/orchestration/agent-resume.js.map +1 -1
  136. package/dist/core/orchestration/attempt-usage.d.ts +28 -0
  137. package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
  138. package/dist/core/orchestration/attempt-usage.js +168 -0
  139. package/dist/core/orchestration/attempt-usage.js.map +1 -0
  140. package/dist/core/orchestration/capability-gateway.d.ts +19 -1
  141. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  142. package/dist/core/orchestration/capability-gateway.js +128 -28
  143. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  144. package/dist/core/orchestration/contracts.d.ts +35 -0
  145. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  146. package/dist/core/orchestration/contracts.js +17 -0
  147. package/dist/core/orchestration/contracts.js.map +1 -1
  148. package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
  149. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  150. package/dist/core/orchestration/delegation-ledger.js +78 -3
  151. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  152. package/dist/core/orchestration/event-store.d.ts +1 -0
  153. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  154. package/dist/core/orchestration/event-store.js +78 -38
  155. package/dist/core/orchestration/event-store.js.map +1 -1
  156. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  157. package/dist/core/orchestration/profile-registry.js +81 -41
  158. package/dist/core/orchestration/profile-registry.js.map +1 -1
  159. package/dist/core/orchestration/profile-store.d.ts.map +1 -1
  160. package/dist/core/orchestration/profile-store.js +18 -4
  161. package/dist/core/orchestration/profile-store.js.map +1 -1
  162. package/dist/core/orchestration/risk-budget.d.ts +2 -0
  163. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  164. package/dist/core/orchestration/risk-budget.js +26 -0
  165. package/dist/core/orchestration/risk-budget.js.map +1 -1
  166. package/dist/core/orchestration/task-runtime.d.ts +13 -1
  167. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  168. package/dist/core/orchestration/task-runtime.js +127 -16
  169. package/dist/core/orchestration/task-runtime.js.map +1 -1
  170. package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
  171. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  172. package/dist/core/orchestration/worker-execution-contract.js +75 -23
  173. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  174. package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
  175. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  176. package/dist/core/orchestration/worker-result-adapter.js +167 -14
  177. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  178. package/dist/core/reflection-controller.d.ts +1 -1
  179. package/dist/core/reflection-controller.d.ts.map +1 -1
  180. package/dist/core/reflection-controller.js +90 -54
  181. package/dist/core/reflection-controller.js.map +1 -1
  182. package/dist/core/research/evidence-bundle.d.ts +20 -0
  183. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  184. package/dist/core/research/evidence-bundle.js +173 -69
  185. package/dist/core/research/evidence-bundle.js.map +1 -1
  186. package/dist/core/runtime-builder.d.ts +7 -0
  187. package/dist/core/runtime-builder.d.ts.map +1 -1
  188. package/dist/core/runtime-builder.js +15 -1
  189. package/dist/core/runtime-builder.js.map +1 -1
  190. package/dist/core/session-artifact-bundle.d.ts +35 -0
  191. package/dist/core/session-artifact-bundle.d.ts.map +1 -0
  192. package/dist/core/session-artifact-bundle.js +61 -0
  193. package/dist/core/session-artifact-bundle.js.map +1 -0
  194. package/dist/core/tools/delegate-status.d.ts +6 -1
  195. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  196. package/dist/core/tools/delegate-status.js +100 -18
  197. package/dist/core/tools/delegate-status.js.map +1 -1
  198. package/dist/core/tools/delegate.d.ts +9 -1
  199. package/dist/core/tools/delegate.d.ts.map +1 -1
  200. package/dist/core/tools/delegate.js +323 -61
  201. package/dist/core/tools/delegate.js.map +1 -1
  202. package/dist/core/tools/run-process.d.ts +1 -1
  203. package/dist/core/tools/run-process.d.ts.map +1 -1
  204. package/dist/core/tools/run-process.js +69 -9
  205. package/dist/core/tools/run-process.js.map +1 -1
  206. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  207. package/dist/core/tools/shell-contract-router.js +12 -5
  208. package/dist/core/tools/shell-contract-router.js.map +1 -1
  209. package/dist/core/util/bounded-file.d.ts +15 -0
  210. package/dist/core/util/bounded-file.d.ts.map +1 -0
  211. package/dist/core/util/bounded-file.js +120 -0
  212. package/dist/core/util/bounded-file.js.map +1 -0
  213. package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
  214. package/dist/core/util/bounded-jsonl.js +119 -9
  215. package/dist/core/util/bounded-jsonl.js.map +1 -1
  216. package/dist/core/util/bounded-value.d.ts +3 -0
  217. package/dist/core/util/bounded-value.d.ts.map +1 -0
  218. package/dist/core/util/bounded-value.js +12 -0
  219. package/dist/core/util/bounded-value.js.map +1 -0
  220. package/dist/core/util/value-guards.d.ts +2 -0
  221. package/dist/core/util/value-guards.d.ts.map +1 -1
  222. package/dist/core/util/value-guards.js +5 -0
  223. package/dist/core/util/value-guards.js.map +1 -1
  224. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  225. package/dist/modes/interactive/components/session-selector.js +27 -44
  226. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  227. package/docs/tool-repair.md +3 -0
  228. package/docs/windows.md +4 -2
  229. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  230. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  231. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  232. package/examples/extensions/sandbox/package-lock.json +2 -2
  233. package/examples/extensions/sandbox/package.json +1 -1
  234. package/examples/extensions/with-deps/package-lock.json +2 -2
  235. package/examples/extensions/with-deps/package.json +1 -1
  236. package/npm-shrinkwrap.json +12 -12
  237. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"profile-store.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/profile-store.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAEN,4BAA4B,EAG5B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,yBAAyB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE7D,MAAM,WAAW,8BAA8B;IAC9C,KAAK,EAAE,yBAAyB,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,8BAA8B;IAC9C,QAAQ,EAAE,4BAA4B,CAAC;IACvC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAC1C,WAAW,EAAE,SAAS,8BAA8B,EAAE,CAAC;CACvD;AAaD,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IAEzC,YAAY,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,EAI9E;IAED,SAAS,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAIlD;IAED,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAOpE;IAED,IAAI,IAAI,8BAA8B,CA0DrC;IAED,IAAI,CACH,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,yBAAyB,EAChC,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO,GACnC,MAAM,CAiBR;IAED,OAAO,CAAC,SAAS;CAgCjB","sourcesContent":["import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { resourceDir } from \"../agent-paths.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport type { OrchestrationProfile } from \"./contracts.ts\";\nimport {\n\tOrchestrationProfileError,\n\tOrchestrationProfileRegistry,\n\tparseOrchestrationProfile,\n\tvalidateOrchestrationProfile,\n} from \"./profile-registry.ts\";\n\nexport type OrchestrationProfileScope = \"global\" | \"project\";\n\nexport interface OrchestrationProfileDiagnostic {\n\tscope: OrchestrationProfileScope;\n\tpath: string;\n\tmessage: string;\n}\n\nexport interface OrchestrationProfileLoadResult {\n\tregistry: OrchestrationProfileRegistry;\n\tprofiles: readonly OrchestrationProfile[];\n\tdiagnostics: readonly OrchestrationProfileDiagnostic[];\n}\n\nconst PROFILE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;\n\nfunction authoredProfile(profile: OrchestrationProfile): Omit<OrchestrationProfile, \"sourcePath\"> {\n\tconst { sourcePath: _sourcePath, ...authored } = profile;\n\treturn authored;\n}\n\nfunction messageFrom(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport class OrchestrationProfileStore {\n\tprivate readonly agentDir: string;\n\tprivate readonly cwd: string;\n\tprivate readonly projectTrusted: boolean;\n\n\tconstructor(options: { agentDir: string; cwd: string; projectTrusted: boolean }) {\n\t\tthis.agentDir = resolve(options.agentDir);\n\t\tthis.cwd = resolve(options.cwd);\n\t\tthis.projectTrusted = options.projectTrusted;\n\t}\n\n\tdirectory(scope: OrchestrationProfileScope): string {\n\t\treturn scope === \"global\"\n\t\t\t? join(resourceDir(\"profiles\", this.agentDir), \"orchestration\")\n\t\t\t: join(this.cwd, CONFIG_DIR_NAME, \"profiles\", \"orchestration\");\n\t}\n\n\tfilePath(profileId: string, scope: OrchestrationProfileScope): string {\n\t\tif (!PROFILE_ID_PATTERN.test(profileId)) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Orchestration profile IDs must be 1-128 characters using only letters, numbers, '.', '_', or '-'.\",\n\t\t\t);\n\t\t}\n\t\treturn join(this.directory(scope), `${profileId}.json`);\n\t}\n\n\tload(): OrchestrationProfileLoadResult {\n\t\tconst diagnostics: OrchestrationProfileDiagnostic[] = [];\n\t\tconst globalProfiles = this.loadScope(\"global\", diagnostics);\n\t\tconst projectProfiles = this.projectTrusted ? this.loadScope(\"project\", diagnostics) : [];\n\t\tif (!this.projectTrusted && existsSync(this.directory(\"project\"))) {\n\t\t\tdiagnostics.push({\n\t\t\t\tscope: \"project\",\n\t\t\t\tpath: this.directory(\"project\"),\n\t\t\t\tmessage: \"Project orchestration profiles were not loaded because the project is untrusted.\",\n\t\t\t});\n\t\t}\n\t\tconst profilesById = new Map(globalProfiles.map((profile) => [profile.profileId, profile]));\n\t\tfor (const profile of projectProfiles) profilesById.set(profile.profileId, profile);\n\t\tlet profiles = [...profilesById.values()].sort((left, right) => left.profileId.localeCompare(right.profileId));\n\t\tlet removed = true;\n\t\twhile (removed) {\n\t\t\tremoved = false;\n\t\t\tconst available = new Map(profiles.map((profile) => [profile.profileId, profile]));\n\t\t\tprofiles = profiles.filter((profile) => {\n\t\t\t\tconst invalidTarget = profile.dispatchProfileIds.find((profileId) => {\n\t\t\t\t\tconst target = available.get(profileId);\n\t\t\t\t\treturn !target || target.role === \"orchestrator\";\n\t\t\t\t});\n\t\t\t\tconst verifier = profile.verificationProfileId ? available.get(profile.verificationProfileId) : undefined;\n\t\t\t\tconst invalidVerifier =\n\t\t\t\t\tprofile.verificationProfileId && verifier?.role !== \"verifier\"\n\t\t\t\t\t\t? profile.verificationProfileId\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst unauthorizedVerifier =\n\t\t\t\t\tprofile.role === \"orchestrator\"\n\t\t\t\t\t\t? profile.dispatchProfileIds\n\t\t\t\t\t\t\t\t.map((profileId) => available.get(profileId))\n\t\t\t\t\t\t\t\t.find(\n\t\t\t\t\t\t\t\t\t(target) =>\n\t\t\t\t\t\t\t\t\t\ttarget?.verificationProfileId &&\n\t\t\t\t\t\t\t\t\t\t!profile.dispatchProfileIds.includes(target.verificationProfileId),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (!invalidTarget && !invalidVerifier && !unauthorizedVerifier) return true;\n\t\t\t\tremoved = true;\n\t\t\t\tconst message = invalidTarget\n\t\t\t\t\t? `Dispatch target '${invalidTarget}' is missing or is another orchestrator.`\n\t\t\t\t\t: invalidVerifier\n\t\t\t\t\t\t? `Verifier target '${invalidVerifier}' is missing or is not a verifier.`\n\t\t\t\t\t\t: `Dispatched profile '${unauthorizedVerifier?.profileId}' requires verifier '${unauthorizedVerifier?.verificationProfileId}', which this orchestrator does not authorize.`;\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tscope: profile.sourcePath?.startsWith(this.directory(\"project\")) ? \"project\" : \"global\",\n\t\t\t\t\tpath: profile.sourcePath ?? profile.profileId,\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tregistry: new OrchestrationProfileRegistry(profiles),\n\t\t\tprofiles,\n\t\t\tdiagnostics,\n\t\t};\n\t}\n\n\tsave(\n\t\tprofile: OrchestrationProfile,\n\t\tscope: OrchestrationProfileScope,\n\t\toptions: { overwrite?: boolean } = {},\n\t): string {\n\t\tif (scope === \"project\" && !this.projectTrusted) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Project is not trusted; refusing to write project orchestration profiles.\",\n\t\t\t);\n\t\t}\n\t\tvalidateOrchestrationProfile(profile);\n\t\tconst filePath = this.filePath(profile.profileId, scope);\n\t\twithFileLockSync(filePath, () => {\n\t\t\tif (!options.overwrite && existsSync(filePath)) {\n\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t`Orchestration profile '${profile.profileId}' already exists in ${scope} scope.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\twriteFileAtomicSync(filePath, `${JSON.stringify(authoredProfile(profile), null, 2)}\\n`);\n\t\t});\n\t\treturn filePath;\n\t}\n\n\tprivate loadScope(\n\t\tscope: OrchestrationProfileScope,\n\t\tdiagnostics: OrchestrationProfileDiagnostic[],\n\t): OrchestrationProfile[] {\n\t\tconst directory = this.directory(scope);\n\t\tif (!existsSync(directory)) return [];\n\t\tlet entries: string[];\n\t\ttry {\n\t\t\tentries = readdirSync(directory)\n\t\t\t\t.filter((entry) => entry.endsWith(\".json\"))\n\t\t\t\t.sort((left, right) => left.localeCompare(right));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({ scope, path: directory, message: messageFrom(error) });\n\t\t\treturn [];\n\t\t}\n\t\tconst profilesById = new Map<string, OrchestrationProfile>();\n\t\tfor (const entry of entries) {\n\t\t\tconst sourcePath = join(directory, entry);\n\t\t\ttry {\n\t\t\t\tconst profile = parseOrchestrationProfile(JSON.parse(readFileSync(sourcePath, \"utf-8\")), sourcePath);\n\t\t\t\tif (profilesById.has(profile.profileId)) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Duplicate orchestration profile '${profile.profileId}' in ${scope} scope.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tprofilesById.set(profile.profileId, profile);\n\t\t\t} catch (error) {\n\t\t\t\tdiagnostics.push({ scope, path: sourcePath, message: messageFrom(error) });\n\t\t\t}\n\t\t}\n\t\treturn [...profilesById.values()];\n\t}\n}\n"]}
1
+ {"version":3,"file":"profile-store.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/profile-store.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAEN,4BAA4B,EAG5B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,yBAAyB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE7D,MAAM,WAAW,8BAA8B;IAC9C,KAAK,EAAE,yBAAyB,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,8BAA8B;IAC9C,QAAQ,EAAE,4BAA4B,CAAC;IACvC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAC1C,WAAW,EAAE,SAAS,8BAA8B,EAAE,CAAC;CACvD;AAwBD,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IAEzC,YAAY,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,EAI9E;IAED,SAAS,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAIlD;IAED,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAOpE;IAED,IAAI,IAAI,8BAA8B,CA0DrC;IAED,IAAI,CACH,OAAO,EAAE,oBAAoB,EAC7B,KAAK,EAAE,yBAAyB,EAChC,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO,GACnC,MAAM,CAoBR;IAED,OAAO,CAAC,SAAS;CAuCjB","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { resourceDir } from \"../agent-paths.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport { readBoundedDirectoryNamesSync, readBoundedTextFileSync } from \"../util/bounded-file.ts\";\nimport type { OrchestrationProfile } from \"./contracts.ts\";\nimport {\n\tOrchestrationProfileError,\n\tOrchestrationProfileRegistry,\n\tparseOrchestrationProfile,\n\tvalidateOrchestrationProfile,\n} from \"./profile-registry.ts\";\n\nexport type OrchestrationProfileScope = \"global\" | \"project\";\n\nexport interface OrchestrationProfileDiagnostic {\n\tscope: OrchestrationProfileScope;\n\tpath: string;\n\tmessage: string;\n}\n\nexport interface OrchestrationProfileLoadResult {\n\tregistry: OrchestrationProfileRegistry;\n\tprofiles: readonly OrchestrationProfile[];\n\tdiagnostics: readonly OrchestrationProfileDiagnostic[];\n}\n\nconst PROFILE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;\n/** A fully populated profile is below this cap; reject expansion before JSON parsing or persistence. */\nconst MAX_PROFILE_FILE_BYTES = 512 * 1024;\nconst MAX_PROFILE_DIRECTORY_ENTRIES = 512;\n\nfunction authoredProfile(profile: OrchestrationProfile): Omit<OrchestrationProfile, \"sourcePath\"> {\n\tconst { sourcePath: _sourcePath, ...authored } = profile;\n\treturn authored;\n}\n\nfunction messageFrom(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction serializeBoundedProfile(profile: Omit<OrchestrationProfile, \"sourcePath\">): string {\n\tconst serialized = `${JSON.stringify(profile, null, 2)}\\n`;\n\tif (Buffer.byteLength(serialized, \"utf-8\") > MAX_PROFILE_FILE_BYTES) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile exceeds its byte limit.\");\n\t}\n\treturn serialized;\n}\n\nexport class OrchestrationProfileStore {\n\tprivate readonly agentDir: string;\n\tprivate readonly cwd: string;\n\tprivate readonly projectTrusted: boolean;\n\n\tconstructor(options: { agentDir: string; cwd: string; projectTrusted: boolean }) {\n\t\tthis.agentDir = resolve(options.agentDir);\n\t\tthis.cwd = resolve(options.cwd);\n\t\tthis.projectTrusted = options.projectTrusted;\n\t}\n\n\tdirectory(scope: OrchestrationProfileScope): string {\n\t\treturn scope === \"global\"\n\t\t\t? join(resourceDir(\"profiles\", this.agentDir), \"orchestration\")\n\t\t\t: join(this.cwd, CONFIG_DIR_NAME, \"profiles\", \"orchestration\");\n\t}\n\n\tfilePath(profileId: string, scope: OrchestrationProfileScope): string {\n\t\tif (!PROFILE_ID_PATTERN.test(profileId)) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Orchestration profile IDs must be 1-128 characters using only letters, numbers, '.', '_', or '-'.\",\n\t\t\t);\n\t\t}\n\t\treturn join(this.directory(scope), `${profileId}.json`);\n\t}\n\n\tload(): OrchestrationProfileLoadResult {\n\t\tconst diagnostics: OrchestrationProfileDiagnostic[] = [];\n\t\tconst globalProfiles = this.loadScope(\"global\", diagnostics);\n\t\tconst projectProfiles = this.projectTrusted ? this.loadScope(\"project\", diagnostics) : [];\n\t\tif (!this.projectTrusted && existsSync(this.directory(\"project\"))) {\n\t\t\tdiagnostics.push({\n\t\t\t\tscope: \"project\",\n\t\t\t\tpath: this.directory(\"project\"),\n\t\t\t\tmessage: \"Project orchestration profiles were not loaded because the project is untrusted.\",\n\t\t\t});\n\t\t}\n\t\tconst profilesById = new Map(globalProfiles.map((profile) => [profile.profileId, profile]));\n\t\tfor (const profile of projectProfiles) profilesById.set(profile.profileId, profile);\n\t\tlet profiles = [...profilesById.values()].sort((left, right) => left.profileId.localeCompare(right.profileId));\n\t\tlet removed = true;\n\t\twhile (removed) {\n\t\t\tremoved = false;\n\t\t\tconst available = new Map(profiles.map((profile) => [profile.profileId, profile]));\n\t\t\tprofiles = profiles.filter((profile) => {\n\t\t\t\tconst invalidTarget = profile.dispatchProfileIds.find((profileId) => {\n\t\t\t\t\tconst target = available.get(profileId);\n\t\t\t\t\treturn !target || target.role === \"orchestrator\";\n\t\t\t\t});\n\t\t\t\tconst verifier = profile.verificationProfileId ? available.get(profile.verificationProfileId) : undefined;\n\t\t\t\tconst invalidVerifier =\n\t\t\t\t\tprofile.verificationProfileId && verifier?.role !== \"verifier\"\n\t\t\t\t\t\t? profile.verificationProfileId\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst unauthorizedVerifier =\n\t\t\t\t\tprofile.role === \"orchestrator\"\n\t\t\t\t\t\t? profile.dispatchProfileIds\n\t\t\t\t\t\t\t\t.map((profileId) => available.get(profileId))\n\t\t\t\t\t\t\t\t.find(\n\t\t\t\t\t\t\t\t\t(target) =>\n\t\t\t\t\t\t\t\t\t\ttarget?.verificationProfileId &&\n\t\t\t\t\t\t\t\t\t\t!profile.dispatchProfileIds.includes(target.verificationProfileId),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (!invalidTarget && !invalidVerifier && !unauthorizedVerifier) return true;\n\t\t\t\tremoved = true;\n\t\t\t\tconst message = invalidTarget\n\t\t\t\t\t? `Dispatch target '${invalidTarget}' is missing or is another orchestrator.`\n\t\t\t\t\t: invalidVerifier\n\t\t\t\t\t\t? `Verifier target '${invalidVerifier}' is missing or is not a verifier.`\n\t\t\t\t\t\t: `Dispatched profile '${unauthorizedVerifier?.profileId}' requires verifier '${unauthorizedVerifier?.verificationProfileId}', which this orchestrator does not authorize.`;\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tscope: profile.sourcePath?.startsWith(this.directory(\"project\")) ? \"project\" : \"global\",\n\t\t\t\t\tpath: profile.sourcePath ?? profile.profileId,\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tregistry: new OrchestrationProfileRegistry(profiles),\n\t\t\tprofiles,\n\t\t\tdiagnostics,\n\t\t};\n\t}\n\n\tsave(\n\t\tprofile: OrchestrationProfile,\n\t\tscope: OrchestrationProfileScope,\n\t\toptions: { overwrite?: boolean } = {},\n\t): string {\n\t\tif (scope === \"project\" && !this.projectTrusted) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Project is not trusted; refusing to write project orchestration profiles.\",\n\t\t\t);\n\t\t}\n\t\tvalidateOrchestrationProfile(profile);\n\t\tconst filePath = this.filePath(profile.profileId, scope);\n\t\tconst serialized = serializeBoundedProfile(authoredProfile(profile));\n\t\t// Keep the save path as strict as load: typed callers cannot persist a record the loader rejects.\n\t\tparseOrchestrationProfile(JSON.parse(serialized));\n\t\twithFileLockSync(filePath, () => {\n\t\t\tif (!options.overwrite && existsSync(filePath)) {\n\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t`Orchestration profile '${profile.profileId}' already exists in ${scope} scope.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\twriteFileAtomicSync(filePath, serialized);\n\t\t});\n\t\treturn filePath;\n\t}\n\n\tprivate loadScope(\n\t\tscope: OrchestrationProfileScope,\n\t\tdiagnostics: OrchestrationProfileDiagnostic[],\n\t): OrchestrationProfile[] {\n\t\tconst directory = this.directory(scope);\n\t\tif (!existsSync(directory)) return [];\n\t\tlet entries: string[];\n\t\ttry {\n\t\t\tentries = readBoundedDirectoryNamesSync(\n\t\t\t\tdirectory,\n\t\t\t\tMAX_PROFILE_DIRECTORY_ENTRIES,\n\t\t\t\t\"Orchestration profiles directory\",\n\t\t\t)\n\t\t\t\t.filter((entry) => entry.endsWith(\".json\"))\n\t\t\t\t.sort((left, right) => left.localeCompare(right));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({ scope, path: directory, message: messageFrom(error) });\n\t\t\treturn [];\n\t\t}\n\t\tconst profilesById = new Map<string, OrchestrationProfile>();\n\t\tfor (const entry of entries) {\n\t\t\tconst sourcePath = join(directory, entry);\n\t\t\ttry {\n\t\t\t\tconst profile = parseOrchestrationProfile(\n\t\t\t\t\tJSON.parse(readBoundedTextFileSync(sourcePath, MAX_PROFILE_FILE_BYTES, \"Orchestration profile\")),\n\t\t\t\t\tsourcePath,\n\t\t\t\t);\n\t\t\t\tif (profilesById.has(profile.profileId)) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Duplicate orchestration profile '${profile.profileId}' in ${scope} scope.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tprofilesById.set(profile.profileId, profile);\n\t\t\t} catch (error) {\n\t\t\t\tdiagnostics.push({ scope, path: sourcePath, message: messageFrom(error) });\n\t\t\t}\n\t\t}\n\t\treturn [...profilesById.values()];\n\t}\n}\n"]}
@@ -1,10 +1,14 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
1
+ import { existsSync } from "node:fs";
2
2
  import { join, resolve } from "node:path";
3
3
  import { CONFIG_DIR_NAME } from "../../config.js";
4
4
  import { resourceDir } from "../agent-paths.js";
5
5
  import { withFileLockSync, writeFileAtomicSync } from "../util/atomic-file.js";
6
+ import { readBoundedDirectoryNamesSync, readBoundedTextFileSync } from "../util/bounded-file.js";
6
7
  import { OrchestrationProfileError, OrchestrationProfileRegistry, parseOrchestrationProfile, validateOrchestrationProfile, } from "./profile-registry.js";
7
8
  const PROFILE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;
9
+ /** A fully populated profile is below this cap; reject expansion before JSON parsing or persistence. */
10
+ const MAX_PROFILE_FILE_BYTES = 512 * 1024;
11
+ const MAX_PROFILE_DIRECTORY_ENTRIES = 512;
8
12
  function authoredProfile(profile) {
9
13
  const { sourcePath: _sourcePath, ...authored } = profile;
10
14
  return authored;
@@ -12,6 +16,13 @@ function authoredProfile(profile) {
12
16
  function messageFrom(error) {
13
17
  return error instanceof Error ? error.message : String(error);
14
18
  }
19
+ function serializeBoundedProfile(profile) {
20
+ const serialized = `${JSON.stringify(profile, null, 2)}\n`;
21
+ if (Buffer.byteLength(serialized, "utf-8") > MAX_PROFILE_FILE_BYTES) {
22
+ throw new OrchestrationProfileError("Orchestration profile exceeds its byte limit.");
23
+ }
24
+ return serialized;
25
+ }
15
26
  export class OrchestrationProfileStore {
16
27
  agentDir;
17
28
  cwd;
@@ -94,11 +105,14 @@ export class OrchestrationProfileStore {
94
105
  }
95
106
  validateOrchestrationProfile(profile);
96
107
  const filePath = this.filePath(profile.profileId, scope);
108
+ const serialized = serializeBoundedProfile(authoredProfile(profile));
109
+ // Keep the save path as strict as load: typed callers cannot persist a record the loader rejects.
110
+ parseOrchestrationProfile(JSON.parse(serialized));
97
111
  withFileLockSync(filePath, () => {
98
112
  if (!options.overwrite && existsSync(filePath)) {
99
113
  throw new OrchestrationProfileError(`Orchestration profile '${profile.profileId}' already exists in ${scope} scope.`);
100
114
  }
101
- writeFileAtomicSync(filePath, `${JSON.stringify(authoredProfile(profile), null, 2)}\n`);
115
+ writeFileAtomicSync(filePath, serialized);
102
116
  });
103
117
  return filePath;
104
118
  }
@@ -108,7 +122,7 @@ export class OrchestrationProfileStore {
108
122
  return [];
109
123
  let entries;
110
124
  try {
111
- entries = readdirSync(directory)
125
+ entries = readBoundedDirectoryNamesSync(directory, MAX_PROFILE_DIRECTORY_ENTRIES, "Orchestration profiles directory")
112
126
  .filter((entry) => entry.endsWith(".json"))
113
127
  .sort((left, right) => left.localeCompare(right));
114
128
  }
@@ -120,7 +134,7 @@ export class OrchestrationProfileStore {
120
134
  for (const entry of entries) {
121
135
  const sourcePath = join(directory, entry);
122
136
  try {
123
- const profile = parseOrchestrationProfile(JSON.parse(readFileSync(sourcePath, "utf-8")), sourcePath);
137
+ const profile = parseOrchestrationProfile(JSON.parse(readBoundedTextFileSync(sourcePath, MAX_PROFILE_FILE_BYTES, "Orchestration profile")), sourcePath);
124
138
  if (profilesById.has(profile.profileId)) {
125
139
  throw new OrchestrationProfileError(`Duplicate orchestration profile '${profile.profileId}' in ${scope} scope.`);
126
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"profile-store.js","sourceRoot":"","sources":["../../../src/core/orchestration/profile-store.ts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,CAAC;QACD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC7D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC;gBACJ,MAAM,OAAO,GAAG,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;gBACrG,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;oBACzC,MAAM,IAAI,yBAAyB,CAClC,oCAAoC,OAAO,CAAC,SAAS,QAAQ,KAAK,SAAS,CAC3E,CAAC;gBACH,CAAC;gBACD,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC9C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5E,CAAC;QACF,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;IAAA,CAClC;CACD","sourcesContent":["import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { resourceDir } from \"../agent-paths.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport type { OrchestrationProfile } from \"./contracts.ts\";\nimport {\n\tOrchestrationProfileError,\n\tOrchestrationProfileRegistry,\n\tparseOrchestrationProfile,\n\tvalidateOrchestrationProfile,\n} from \"./profile-registry.ts\";\n\nexport type OrchestrationProfileScope = \"global\" | \"project\";\n\nexport interface OrchestrationProfileDiagnostic {\n\tscope: OrchestrationProfileScope;\n\tpath: string;\n\tmessage: string;\n}\n\nexport interface OrchestrationProfileLoadResult {\n\tregistry: OrchestrationProfileRegistry;\n\tprofiles: readonly OrchestrationProfile[];\n\tdiagnostics: readonly OrchestrationProfileDiagnostic[];\n}\n\nconst PROFILE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;\n\nfunction authoredProfile(profile: OrchestrationProfile): Omit<OrchestrationProfile, \"sourcePath\"> {\n\tconst { sourcePath: _sourcePath, ...authored } = profile;\n\treturn authored;\n}\n\nfunction messageFrom(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport class OrchestrationProfileStore {\n\tprivate readonly agentDir: string;\n\tprivate readonly cwd: string;\n\tprivate readonly projectTrusted: boolean;\n\n\tconstructor(options: { agentDir: string; cwd: string; projectTrusted: boolean }) {\n\t\tthis.agentDir = resolve(options.agentDir);\n\t\tthis.cwd = resolve(options.cwd);\n\t\tthis.projectTrusted = options.projectTrusted;\n\t}\n\n\tdirectory(scope: OrchestrationProfileScope): string {\n\t\treturn scope === \"global\"\n\t\t\t? join(resourceDir(\"profiles\", this.agentDir), \"orchestration\")\n\t\t\t: join(this.cwd, CONFIG_DIR_NAME, \"profiles\", \"orchestration\");\n\t}\n\n\tfilePath(profileId: string, scope: OrchestrationProfileScope): string {\n\t\tif (!PROFILE_ID_PATTERN.test(profileId)) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Orchestration profile IDs must be 1-128 characters using only letters, numbers, '.', '_', or '-'.\",\n\t\t\t);\n\t\t}\n\t\treturn join(this.directory(scope), `${profileId}.json`);\n\t}\n\n\tload(): OrchestrationProfileLoadResult {\n\t\tconst diagnostics: OrchestrationProfileDiagnostic[] = [];\n\t\tconst globalProfiles = this.loadScope(\"global\", diagnostics);\n\t\tconst projectProfiles = this.projectTrusted ? this.loadScope(\"project\", diagnostics) : [];\n\t\tif (!this.projectTrusted && existsSync(this.directory(\"project\"))) {\n\t\t\tdiagnostics.push({\n\t\t\t\tscope: \"project\",\n\t\t\t\tpath: this.directory(\"project\"),\n\t\t\t\tmessage: \"Project orchestration profiles were not loaded because the project is untrusted.\",\n\t\t\t});\n\t\t}\n\t\tconst profilesById = new Map(globalProfiles.map((profile) => [profile.profileId, profile]));\n\t\tfor (const profile of projectProfiles) profilesById.set(profile.profileId, profile);\n\t\tlet profiles = [...profilesById.values()].sort((left, right) => left.profileId.localeCompare(right.profileId));\n\t\tlet removed = true;\n\t\twhile (removed) {\n\t\t\tremoved = false;\n\t\t\tconst available = new Map(profiles.map((profile) => [profile.profileId, profile]));\n\t\t\tprofiles = profiles.filter((profile) => {\n\t\t\t\tconst invalidTarget = profile.dispatchProfileIds.find((profileId) => {\n\t\t\t\t\tconst target = available.get(profileId);\n\t\t\t\t\treturn !target || target.role === \"orchestrator\";\n\t\t\t\t});\n\t\t\t\tconst verifier = profile.verificationProfileId ? available.get(profile.verificationProfileId) : undefined;\n\t\t\t\tconst invalidVerifier =\n\t\t\t\t\tprofile.verificationProfileId && verifier?.role !== \"verifier\"\n\t\t\t\t\t\t? profile.verificationProfileId\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst unauthorizedVerifier =\n\t\t\t\t\tprofile.role === \"orchestrator\"\n\t\t\t\t\t\t? profile.dispatchProfileIds\n\t\t\t\t\t\t\t\t.map((profileId) => available.get(profileId))\n\t\t\t\t\t\t\t\t.find(\n\t\t\t\t\t\t\t\t\t(target) =>\n\t\t\t\t\t\t\t\t\t\ttarget?.verificationProfileId &&\n\t\t\t\t\t\t\t\t\t\t!profile.dispatchProfileIds.includes(target.verificationProfileId),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (!invalidTarget && !invalidVerifier && !unauthorizedVerifier) return true;\n\t\t\t\tremoved = true;\n\t\t\t\tconst message = invalidTarget\n\t\t\t\t\t? `Dispatch target '${invalidTarget}' is missing or is another orchestrator.`\n\t\t\t\t\t: invalidVerifier\n\t\t\t\t\t\t? `Verifier target '${invalidVerifier}' is missing or is not a verifier.`\n\t\t\t\t\t\t: `Dispatched profile '${unauthorizedVerifier?.profileId}' requires verifier '${unauthorizedVerifier?.verificationProfileId}', which this orchestrator does not authorize.`;\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tscope: profile.sourcePath?.startsWith(this.directory(\"project\")) ? \"project\" : \"global\",\n\t\t\t\t\tpath: profile.sourcePath ?? profile.profileId,\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tregistry: new OrchestrationProfileRegistry(profiles),\n\t\t\tprofiles,\n\t\t\tdiagnostics,\n\t\t};\n\t}\n\n\tsave(\n\t\tprofile: OrchestrationProfile,\n\t\tscope: OrchestrationProfileScope,\n\t\toptions: { overwrite?: boolean } = {},\n\t): string {\n\t\tif (scope === \"project\" && !this.projectTrusted) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Project is not trusted; refusing to write project orchestration profiles.\",\n\t\t\t);\n\t\t}\n\t\tvalidateOrchestrationProfile(profile);\n\t\tconst filePath = this.filePath(profile.profileId, scope);\n\t\twithFileLockSync(filePath, () => {\n\t\t\tif (!options.overwrite && existsSync(filePath)) {\n\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t`Orchestration profile '${profile.profileId}' already exists in ${scope} scope.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\twriteFileAtomicSync(filePath, `${JSON.stringify(authoredProfile(profile), null, 2)}\\n`);\n\t\t});\n\t\treturn filePath;\n\t}\n\n\tprivate loadScope(\n\t\tscope: OrchestrationProfileScope,\n\t\tdiagnostics: OrchestrationProfileDiagnostic[],\n\t): OrchestrationProfile[] {\n\t\tconst directory = this.directory(scope);\n\t\tif (!existsSync(directory)) return [];\n\t\tlet entries: string[];\n\t\ttry {\n\t\t\tentries = readdirSync(directory)\n\t\t\t\t.filter((entry) => entry.endsWith(\".json\"))\n\t\t\t\t.sort((left, right) => left.localeCompare(right));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({ scope, path: directory, message: messageFrom(error) });\n\t\t\treturn [];\n\t\t}\n\t\tconst profilesById = new Map<string, OrchestrationProfile>();\n\t\tfor (const entry of entries) {\n\t\t\tconst sourcePath = join(directory, entry);\n\t\t\ttry {\n\t\t\t\tconst profile = parseOrchestrationProfile(JSON.parse(readFileSync(sourcePath, \"utf-8\")), sourcePath);\n\t\t\t\tif (profilesById.has(profile.profileId)) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Duplicate orchestration profile '${profile.profileId}' in ${scope} scope.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tprofilesById.set(profile.profileId, profile);\n\t\t\t} catch (error) {\n\t\t\t\tdiagnostics.push({ scope, path: sourcePath, message: messageFrom(error) });\n\t\t\t}\n\t\t}\n\t\treturn [...profilesById.values()];\n\t}\n}\n"]}
1
+ {"version":3,"file":"profile-store.js","sourceRoot":"","sources":["../../../src/core/orchestration/profile-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEjG,OAAO,EACN,yBAAyB,EACzB,4BAA4B,EAC5B,yBAAyB,EACzB,4BAA4B,GAC5B,MAAM,uBAAuB,CAAC;AAgB/B,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAChE,wGAAwG;AACxG,MAAM,sBAAsB,GAAG,GAAG,GAAG,IAAI,CAAC;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AE,CAAC;QACX,CAAC;QACD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC7D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC;gBACJ,MAAM,OAAO,GAAG,yBAAyB,CACxC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,UAAU,EAAE,sBAAsB,EAAE,uBAAuB,CAAC,CAAC,EAChG,UAAU,CACV,CAAC;gBACF,IAAI,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;oBACzC,MAAM,IAAI,yBAAyB,CAClC,oCAAoC,OAAO,CAAC,SAAS,QAAQ,KAAK,SAAS,CAC3E,CAAC;gBACH,CAAC;gBACD,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC9C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5E,CAAC;QACF,CAAC;QACD,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;IAAA,CAClC;CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../../config.ts\";\nimport { resourceDir } from \"../agent-paths.ts\";\nimport { withFileLockSync, writeFileAtomicSync } from \"../util/atomic-file.ts\";\nimport { readBoundedDirectoryNamesSync, readBoundedTextFileSync } from \"../util/bounded-file.ts\";\nimport type { OrchestrationProfile } from \"./contracts.ts\";\nimport {\n\tOrchestrationProfileError,\n\tOrchestrationProfileRegistry,\n\tparseOrchestrationProfile,\n\tvalidateOrchestrationProfile,\n} from \"./profile-registry.ts\";\n\nexport type OrchestrationProfileScope = \"global\" | \"project\";\n\nexport interface OrchestrationProfileDiagnostic {\n\tscope: OrchestrationProfileScope;\n\tpath: string;\n\tmessage: string;\n}\n\nexport interface OrchestrationProfileLoadResult {\n\tregistry: OrchestrationProfileRegistry;\n\tprofiles: readonly OrchestrationProfile[];\n\tdiagnostics: readonly OrchestrationProfileDiagnostic[];\n}\n\nconst PROFILE_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;\n/** A fully populated profile is below this cap; reject expansion before JSON parsing or persistence. */\nconst MAX_PROFILE_FILE_BYTES = 512 * 1024;\nconst MAX_PROFILE_DIRECTORY_ENTRIES = 512;\n\nfunction authoredProfile(profile: OrchestrationProfile): Omit<OrchestrationProfile, \"sourcePath\"> {\n\tconst { sourcePath: _sourcePath, ...authored } = profile;\n\treturn authored;\n}\n\nfunction messageFrom(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction serializeBoundedProfile(profile: Omit<OrchestrationProfile, \"sourcePath\">): string {\n\tconst serialized = `${JSON.stringify(profile, null, 2)}\\n`;\n\tif (Buffer.byteLength(serialized, \"utf-8\") > MAX_PROFILE_FILE_BYTES) {\n\t\tthrow new OrchestrationProfileError(\"Orchestration profile exceeds its byte limit.\");\n\t}\n\treturn serialized;\n}\n\nexport class OrchestrationProfileStore {\n\tprivate readonly agentDir: string;\n\tprivate readonly cwd: string;\n\tprivate readonly projectTrusted: boolean;\n\n\tconstructor(options: { agentDir: string; cwd: string; projectTrusted: boolean }) {\n\t\tthis.agentDir = resolve(options.agentDir);\n\t\tthis.cwd = resolve(options.cwd);\n\t\tthis.projectTrusted = options.projectTrusted;\n\t}\n\n\tdirectory(scope: OrchestrationProfileScope): string {\n\t\treturn scope === \"global\"\n\t\t\t? join(resourceDir(\"profiles\", this.agentDir), \"orchestration\")\n\t\t\t: join(this.cwd, CONFIG_DIR_NAME, \"profiles\", \"orchestration\");\n\t}\n\n\tfilePath(profileId: string, scope: OrchestrationProfileScope): string {\n\t\tif (!PROFILE_ID_PATTERN.test(profileId)) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Orchestration profile IDs must be 1-128 characters using only letters, numbers, '.', '_', or '-'.\",\n\t\t\t);\n\t\t}\n\t\treturn join(this.directory(scope), `${profileId}.json`);\n\t}\n\n\tload(): OrchestrationProfileLoadResult {\n\t\tconst diagnostics: OrchestrationProfileDiagnostic[] = [];\n\t\tconst globalProfiles = this.loadScope(\"global\", diagnostics);\n\t\tconst projectProfiles = this.projectTrusted ? this.loadScope(\"project\", diagnostics) : [];\n\t\tif (!this.projectTrusted && existsSync(this.directory(\"project\"))) {\n\t\t\tdiagnostics.push({\n\t\t\t\tscope: \"project\",\n\t\t\t\tpath: this.directory(\"project\"),\n\t\t\t\tmessage: \"Project orchestration profiles were not loaded because the project is untrusted.\",\n\t\t\t});\n\t\t}\n\t\tconst profilesById = new Map(globalProfiles.map((profile) => [profile.profileId, profile]));\n\t\tfor (const profile of projectProfiles) profilesById.set(profile.profileId, profile);\n\t\tlet profiles = [...profilesById.values()].sort((left, right) => left.profileId.localeCompare(right.profileId));\n\t\tlet removed = true;\n\t\twhile (removed) {\n\t\t\tremoved = false;\n\t\t\tconst available = new Map(profiles.map((profile) => [profile.profileId, profile]));\n\t\t\tprofiles = profiles.filter((profile) => {\n\t\t\t\tconst invalidTarget = profile.dispatchProfileIds.find((profileId) => {\n\t\t\t\t\tconst target = available.get(profileId);\n\t\t\t\t\treturn !target || target.role === \"orchestrator\";\n\t\t\t\t});\n\t\t\t\tconst verifier = profile.verificationProfileId ? available.get(profile.verificationProfileId) : undefined;\n\t\t\t\tconst invalidVerifier =\n\t\t\t\t\tprofile.verificationProfileId && verifier?.role !== \"verifier\"\n\t\t\t\t\t\t? profile.verificationProfileId\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst unauthorizedVerifier =\n\t\t\t\t\tprofile.role === \"orchestrator\"\n\t\t\t\t\t\t? profile.dispatchProfileIds\n\t\t\t\t\t\t\t\t.map((profileId) => available.get(profileId))\n\t\t\t\t\t\t\t\t.find(\n\t\t\t\t\t\t\t\t\t(target) =>\n\t\t\t\t\t\t\t\t\t\ttarget?.verificationProfileId &&\n\t\t\t\t\t\t\t\t\t\t!profile.dispatchProfileIds.includes(target.verificationProfileId),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: undefined;\n\t\t\t\tif (!invalidTarget && !invalidVerifier && !unauthorizedVerifier) return true;\n\t\t\t\tremoved = true;\n\t\t\t\tconst message = invalidTarget\n\t\t\t\t\t? `Dispatch target '${invalidTarget}' is missing or is another orchestrator.`\n\t\t\t\t\t: invalidVerifier\n\t\t\t\t\t\t? `Verifier target '${invalidVerifier}' is missing or is not a verifier.`\n\t\t\t\t\t\t: `Dispatched profile '${unauthorizedVerifier?.profileId}' requires verifier '${unauthorizedVerifier?.verificationProfileId}', which this orchestrator does not authorize.`;\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tscope: profile.sourcePath?.startsWith(this.directory(\"project\")) ? \"project\" : \"global\",\n\t\t\t\t\tpath: profile.sourcePath ?? profile.profileId,\n\t\t\t\t\tmessage,\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t});\n\t\t}\n\t\treturn {\n\t\t\tregistry: new OrchestrationProfileRegistry(profiles),\n\t\t\tprofiles,\n\t\t\tdiagnostics,\n\t\t};\n\t}\n\n\tsave(\n\t\tprofile: OrchestrationProfile,\n\t\tscope: OrchestrationProfileScope,\n\t\toptions: { overwrite?: boolean } = {},\n\t): string {\n\t\tif (scope === \"project\" && !this.projectTrusted) {\n\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\"Project is not trusted; refusing to write project orchestration profiles.\",\n\t\t\t);\n\t\t}\n\t\tvalidateOrchestrationProfile(profile);\n\t\tconst filePath = this.filePath(profile.profileId, scope);\n\t\tconst serialized = serializeBoundedProfile(authoredProfile(profile));\n\t\t// Keep the save path as strict as load: typed callers cannot persist a record the loader rejects.\n\t\tparseOrchestrationProfile(JSON.parse(serialized));\n\t\twithFileLockSync(filePath, () => {\n\t\t\tif (!options.overwrite && existsSync(filePath)) {\n\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t`Orchestration profile '${profile.profileId}' already exists in ${scope} scope.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\twriteFileAtomicSync(filePath, serialized);\n\t\t});\n\t\treturn filePath;\n\t}\n\n\tprivate loadScope(\n\t\tscope: OrchestrationProfileScope,\n\t\tdiagnostics: OrchestrationProfileDiagnostic[],\n\t): OrchestrationProfile[] {\n\t\tconst directory = this.directory(scope);\n\t\tif (!existsSync(directory)) return [];\n\t\tlet entries: string[];\n\t\ttry {\n\t\t\tentries = readBoundedDirectoryNamesSync(\n\t\t\t\tdirectory,\n\t\t\t\tMAX_PROFILE_DIRECTORY_ENTRIES,\n\t\t\t\t\"Orchestration profiles directory\",\n\t\t\t)\n\t\t\t\t.filter((entry) => entry.endsWith(\".json\"))\n\t\t\t\t.sort((left, right) => left.localeCompare(right));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push({ scope, path: directory, message: messageFrom(error) });\n\t\t\treturn [];\n\t\t}\n\t\tconst profilesById = new Map<string, OrchestrationProfile>();\n\t\tfor (const entry of entries) {\n\t\t\tconst sourcePath = join(directory, entry);\n\t\t\ttry {\n\t\t\t\tconst profile = parseOrchestrationProfile(\n\t\t\t\t\tJSON.parse(readBoundedTextFileSync(sourcePath, MAX_PROFILE_FILE_BYTES, \"Orchestration profile\")),\n\t\t\t\t\tsourcePath,\n\t\t\t\t);\n\t\t\t\tif (profilesById.has(profile.profileId)) {\n\t\t\t\t\tthrow new OrchestrationProfileError(\n\t\t\t\t\t\t`Duplicate orchestration profile '${profile.profileId}' in ${scope} scope.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tprofilesById.set(profile.profileId, profile);\n\t\t\t} catch (error) {\n\t\t\t\tdiagnostics.push({ scope, path: sourcePath, message: messageFrom(error) });\n\t\t\t}\n\t\t}\n\t\treturn [...profilesById.values()];\n\t}\n}\n"]}
@@ -2,6 +2,8 @@ import type { RiskBudget } from "./contracts.ts";
2
2
  export declare const RISK_BUDGET_LIMIT_FIELDS: readonly ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls"];
3
3
  export type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];
4
4
  export declare const RISK_BUDGET_FIELDS: readonly ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls", "requireApprovalAboveCostUsd"];
5
+ /** Parse raw durable budget input without cloning untrusted values. */
6
+ export declare function parseRiskBudget(value: unknown, label: string): RiskBudget;
5
7
  export declare function validateRiskBudget(budget: RiskBudget, label: string): void;
6
8
  export declare function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[];
7
9
  /** Intersects independent ceilings. Undefined fields do not constrain the result. */
@@ -1 +1 @@
1
- {"version":3,"file":"risk-budget.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,wBAAwB,uFAM3B,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,eAAO,MAAM,kBAAkB,sHAAwE,CAAC;AASxG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAS1E;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,oBAAoB,EAAE,CAM7G;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,GAAG,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAWlF","sourcesContent":["import type { RiskBudget } from \"./contracts.ts\";\n\nexport const RISK_BUDGET_LIMIT_FIELDS = [\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxCostUsd\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n] as const;\n\nexport type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];\n\nexport const RISK_BUDGET_FIELDS = [...RISK_BUDGET_LIMIT_FIELDS, \"requireApprovalAboveCostUsd\"] as const;\n\nconst DISCRETE_BUDGET_FIELDS: ReadonlySet<(typeof RISK_BUDGET_FIELDS)[number]> = new Set([\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n]);\n\nexport function validateRiskBudget(budget: RiskBudget, label: string): void {\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst value = budget[field];\n\t\tif (value === undefined) continue;\n\t\tif (!Number.isFinite(value) || value < 0) throw new TypeError(`${label}.${field} must be non-negative.`);\n\t\tif (DISCRETE_BUDGET_FIELDS.has(field) && !Number.isSafeInteger(value)) {\n\t\t\tthrow new TypeError(`${label}.${field} must be a non-negative safe integer.`);\n\t\t}\n\t}\n}\n\nexport function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[] {\n\treturn RISK_BUDGET_LIMIT_FIELDS.filter((field) => {\n\t\tconst request = requested[field];\n\t\tconst ceiling = authority[field];\n\t\treturn request !== undefined && ceiling !== undefined && request > ceiling;\n\t});\n}\n\n/** Intersects independent ceilings. Undefined fields do not constrain the result. */\nexport function intersectRiskBudgets(...budgets: readonly RiskBudget[]): RiskBudget {\n\tconst result: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst values = budgets.map((budget) => budget[field]).filter((value): value is number => value !== undefined);\n\t\tif (values.length > 0) result[field] = Math.min(...values);\n\t}\n\tconst approvalThreshold = result.requireApprovalAboveCostUsd;\n\tif (approvalThreshold !== undefined) {\n\t\tresult.maxCostUsd = Math.min(result.maxCostUsd ?? approvalThreshold, approvalThreshold);\n\t}\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"risk-budget.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,wBAAwB,uFAM3B,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,eAAO,MAAM,kBAAkB,sHAAwE,CAAC;AAgBxG,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAYzE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW1E;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,oBAAoB,EAAE,CAM7G;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,GAAG,OAAO,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAWlF","sourcesContent":["import { isPlainRecord } from \"../util/value-guards.ts\";\nimport type { RiskBudget } from \"./contracts.ts\";\n\nexport const RISK_BUDGET_LIMIT_FIELDS = [\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxCostUsd\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n] as const;\n\nexport type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];\n\nexport const RISK_BUDGET_FIELDS = [...RISK_BUDGET_LIMIT_FIELDS, \"requireApprovalAboveCostUsd\"] as const;\n\nconst DISCRETE_BUDGET_FIELDS: ReadonlySet<(typeof RISK_BUDGET_FIELDS)[number]> = new Set([\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n]);\n\nfunction assertKnownRiskBudgetFields(budget: Record<string, unknown>, label: string): void {\n\tconst unknownField = Object.keys(budget).find(\n\t\t(field) => !RISK_BUDGET_FIELDS.includes(field as (typeof RISK_BUDGET_FIELDS)[number]),\n\t);\n\tif (unknownField) throw new TypeError(`${label} contains an unsupported field.`);\n}\n\n/** Parse raw durable budget input without cloning untrusted values. */\nexport function parseRiskBudget(value: unknown, label: string): RiskBudget {\n\tif (!isPlainRecord(value)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(value, label);\n\tconst budget: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst candidate = value[field];\n\t\tif (candidate === undefined) continue;\n\t\tif (typeof candidate !== \"number\") throw new TypeError(`${label}.${field} must be a number.`);\n\t\tbudget[field] = candidate;\n\t}\n\tvalidateRiskBudget(budget, label);\n\treturn budget;\n}\n\nexport function validateRiskBudget(budget: RiskBudget, label: string): void {\n\tif (!isPlainRecord(budget)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(budget, label);\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst value = (budget as RiskBudget)[field];\n\t\tif (value === undefined) continue;\n\t\tif (!Number.isFinite(value) || value < 0) throw new TypeError(`${label}.${field} must be non-negative.`);\n\t\tif (DISCRETE_BUDGET_FIELDS.has(field) && !Number.isSafeInteger(value)) {\n\t\t\tthrow new TypeError(`${label}.${field} must be a non-negative safe integer.`);\n\t\t}\n\t}\n}\n\nexport function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[] {\n\treturn RISK_BUDGET_LIMIT_FIELDS.filter((field) => {\n\t\tconst request = requested[field];\n\t\tconst ceiling = authority[field];\n\t\treturn request !== undefined && ceiling !== undefined && request > ceiling;\n\t});\n}\n\n/** Intersects independent ceilings. Undefined fields do not constrain the result. */\nexport function intersectRiskBudgets(...budgets: readonly RiskBudget[]): RiskBudget {\n\tconst result: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst values = budgets.map((budget) => budget[field]).filter((value): value is number => value !== undefined);\n\t\tif (values.length > 0) result[field] = Math.min(...values);\n\t}\n\tconst approvalThreshold = result.requireApprovalAboveCostUsd;\n\tif (approvalThreshold !== undefined) {\n\t\tresult.maxCostUsd = Math.min(result.maxCostUsd ?? approvalThreshold, approvalThreshold);\n\t}\n\treturn result;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { isPlainRecord } from "../util/value-guards.js";
1
2
  export const RISK_BUDGET_LIMIT_FIELDS = [
2
3
  "maxTokens",
3
4
  "maxWallClockMs",
@@ -12,7 +13,32 @@ const DISCRETE_BUDGET_FIELDS = new Set([
12
13
  "maxAttempts",
13
14
  "maxToolCalls",
14
15
  ]);
16
+ function assertKnownRiskBudgetFields(budget, label) {
17
+ const unknownField = Object.keys(budget).find((field) => !RISK_BUDGET_FIELDS.includes(field));
18
+ if (unknownField)
19
+ throw new TypeError(`${label} contains an unsupported field.`);
20
+ }
21
+ /** Parse raw durable budget input without cloning untrusted values. */
22
+ export function parseRiskBudget(value, label) {
23
+ if (!isPlainRecord(value))
24
+ throw new TypeError(`${label} must be an object.`);
25
+ assertKnownRiskBudgetFields(value, label);
26
+ const budget = {};
27
+ for (const field of RISK_BUDGET_FIELDS) {
28
+ const candidate = value[field];
29
+ if (candidate === undefined)
30
+ continue;
31
+ if (typeof candidate !== "number")
32
+ throw new TypeError(`${label}.${field} must be a number.`);
33
+ budget[field] = candidate;
34
+ }
35
+ validateRiskBudget(budget, label);
36
+ return budget;
37
+ }
15
38
  export function validateRiskBudget(budget, label) {
39
+ if (!isPlainRecord(budget))
40
+ throw new TypeError(`${label} must be an object.`);
41
+ assertKnownRiskBudgetFields(budget, label);
16
42
  for (const field of RISK_BUDGET_FIELDS) {
17
43
  const value = budget[field];
18
44
  if (value === undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"risk-budget.js","sourceRoot":"","sources":["../../../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,OAAO,CAAC;IAAA,CAC3E,CAAC,CAAC;AAAA,CACH;AAED,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,GAAG,OAA8B,EAAc;IACnF,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,kBAAkB,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QAC9G,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,iBAAiB,GAAG,MAAM,CAAC,2BAA2B,CAAC;IAC7D,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import type { RiskBudget } from \"./contracts.ts\";\n\nexport const RISK_BUDGET_LIMIT_FIELDS = [\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxCostUsd\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n] as const;\n\nexport type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];\n\nexport const RISK_BUDGET_FIELDS = [...RISK_BUDGET_LIMIT_FIELDS, \"requireApprovalAboveCostUsd\"] as const;\n\nconst DISCRETE_BUDGET_FIELDS: ReadonlySet<(typeof RISK_BUDGET_FIELDS)[number]> = new Set([\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n]);\n\nexport function validateRiskBudget(budget: RiskBudget, label: string): void {\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst value = budget[field];\n\t\tif (value === undefined) continue;\n\t\tif (!Number.isFinite(value) || value < 0) throw new TypeError(`${label}.${field} must be non-negative.`);\n\t\tif (DISCRETE_BUDGET_FIELDS.has(field) && !Number.isSafeInteger(value)) {\n\t\t\tthrow new TypeError(`${label}.${field} must be a non-negative safe integer.`);\n\t\t}\n\t}\n}\n\nexport function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[] {\n\treturn RISK_BUDGET_LIMIT_FIELDS.filter((field) => {\n\t\tconst request = requested[field];\n\t\tconst ceiling = authority[field];\n\t\treturn request !== undefined && ceiling !== undefined && request > ceiling;\n\t});\n}\n\n/** Intersects independent ceilings. Undefined fields do not constrain the result. */\nexport function intersectRiskBudgets(...budgets: readonly RiskBudget[]): RiskBudget {\n\tconst result: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst values = budgets.map((budget) => budget[field]).filter((value): value is number => value !== undefined);\n\t\tif (values.length > 0) result[field] = Math.min(...values);\n\t}\n\tconst approvalThreshold = result.requireApprovalAboveCostUsd;\n\tif (approvalThreshold !== undefined) {\n\t\tresult.maxCostUsd = Math.min(result.maxCostUsd ?? approvalThreshold, approvalThreshold);\n\t}\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"risk-budget.js","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,WAAW;IACX,gBAAgB;IAChB,YAAY;IACZ,aAAa;IACb,cAAc;CACL,CAAC;AAIX,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,wBAAwB,EAAE,6BAA6B,CAAU,CAAC;AAExG,MAAM,sBAAsB,GAAqD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EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QAC9G,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,iBAAiB,GAAG,MAAM,CAAC,2BAA2B,CAAC;IAC7D,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import { isPlainRecord } from \"../util/value-guards.ts\";\nimport type { RiskBudget } from \"./contracts.ts\";\n\nexport const RISK_BUDGET_LIMIT_FIELDS = [\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxCostUsd\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n] as const;\n\nexport type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];\n\nexport const RISK_BUDGET_FIELDS = [...RISK_BUDGET_LIMIT_FIELDS, \"requireApprovalAboveCostUsd\"] as const;\n\nconst DISCRETE_BUDGET_FIELDS: ReadonlySet<(typeof RISK_BUDGET_FIELDS)[number]> = new Set([\n\t\"maxTokens\",\n\t\"maxWallClockMs\",\n\t\"maxAttempts\",\n\t\"maxToolCalls\",\n]);\n\nfunction assertKnownRiskBudgetFields(budget: Record<string, unknown>, label: string): void {\n\tconst unknownField = Object.keys(budget).find(\n\t\t(field) => !RISK_BUDGET_FIELDS.includes(field as (typeof RISK_BUDGET_FIELDS)[number]),\n\t);\n\tif (unknownField) throw new TypeError(`${label} contains an unsupported field.`);\n}\n\n/** Parse raw durable budget input without cloning untrusted values. */\nexport function parseRiskBudget(value: unknown, label: string): RiskBudget {\n\tif (!isPlainRecord(value)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(value, label);\n\tconst budget: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst candidate = value[field];\n\t\tif (candidate === undefined) continue;\n\t\tif (typeof candidate !== \"number\") throw new TypeError(`${label}.${field} must be a number.`);\n\t\tbudget[field] = candidate;\n\t}\n\tvalidateRiskBudget(budget, label);\n\treturn budget;\n}\n\nexport function validateRiskBudget(budget: RiskBudget, label: string): void {\n\tif (!isPlainRecord(budget)) throw new TypeError(`${label} must be an object.`);\n\tassertKnownRiskBudgetFields(budget, label);\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst value = (budget as RiskBudget)[field];\n\t\tif (value === undefined) continue;\n\t\tif (!Number.isFinite(value) || value < 0) throw new TypeError(`${label}.${field} must be non-negative.`);\n\t\tif (DISCRETE_BUDGET_FIELDS.has(field) && !Number.isSafeInteger(value)) {\n\t\t\tthrow new TypeError(`${label}.${field} must be a non-negative safe integer.`);\n\t\t}\n\t}\n}\n\nexport function exceededRiskBudgetFields(requested: RiskBudget, authority: RiskBudget): RiskBudgetLimitField[] {\n\treturn RISK_BUDGET_LIMIT_FIELDS.filter((field) => {\n\t\tconst request = requested[field];\n\t\tconst ceiling = authority[field];\n\t\treturn request !== undefined && ceiling !== undefined && request > ceiling;\n\t});\n}\n\n/** Intersects independent ceilings. Undefined fields do not constrain the result. */\nexport function intersectRiskBudgets(...budgets: readonly RiskBudget[]): RiskBudget {\n\tconst result: RiskBudget = {};\n\tfor (const field of RISK_BUDGET_FIELDS) {\n\t\tconst values = budgets.map((budget) => budget[field]).filter((value): value is number => value !== undefined);\n\t\tif (values.length > 0) result[field] = Math.min(...values);\n\t}\n\tconst approvalThreshold = result.requireApprovalAboveCostUsd;\n\tif (approvalThreshold !== undefined) {\n\t\tresult.maxCostUsd = Math.min(result.maxCostUsd ?? approvalThreshold, approvalThreshold);\n\t}\n\treturn result;\n}\n"]}
@@ -117,6 +117,7 @@ export declare class DurableTaskRuntime {
117
117
  summary: string;
118
118
  artifactIds?: readonly string[];
119
119
  evidenceIds?: readonly string[];
120
+ usage?: AttemptCheckpoint["usage"];
120
121
  }): AttemptCheckpoint;
121
122
  finishAttempt(result: WorkerResultContract): AttemptRuntimeState;
122
123
  finishVerification(args: {
@@ -127,6 +128,17 @@ export declare class DurableTaskRuntime {
127
128
  reasonCode: string;
128
129
  }): TaskRuntimeState;
129
130
  cancelAttempt(attemptId: string, reasonCode: string): AttemptRuntimeState;
131
+ /**
132
+ * The only runtime suspension transition. Callers must present the exact current owner and lease
133
+ * fence; liveness/restart policy stays outside this deterministic runtime.
134
+ */
135
+ suspendBoundAttempt(args: {
136
+ attemptId: string;
137
+ ownerId: string;
138
+ leaseId: string;
139
+ fencingToken: number;
140
+ reasonCode: string;
141
+ }): AttemptRuntimeState;
130
142
  failTask(taskId: string, reasonCode: string): TaskContract;
131
143
  /**
132
144
  * Recover unbound in-process work after a process restart. A completion has no resumable model
@@ -136,7 +148,7 @@ export declare class DurableTaskRuntime {
136
148
  recoverInterruptedUnboundAttempts(shouldRecover?: (attempt: AttemptRuntimeState) => boolean): string[];
137
149
  expireLeases(at?: number): string[];
138
150
  requestAgentResume(agentId: string): AgentBindingContract;
139
- resumeAttempt(attemptId: string, agentId: string, ttlMs: number): AttemptLease;
151
+ resumeAttempt(attemptId: string, agentId: string, ttlMs: number, ownerId?: string): AttemptLease;
140
152
  pauseObjective(objectiveId: string): void;
141
153
  resumeObjective(objectiveId: string): void;
142
154
  cancelObjective(objectiveId: string): void;