@caupulican/pi-adaptative 0.90.2 → 0.90.4

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 (162) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/core/agent-session-contracts.d.ts +2 -0
  3. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  4. package/dist/core/agent-session-contracts.js.map +1 -1
  5. package/dist/core/autonomy/bounded-completion.d.ts +10 -1
  6. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  7. package/dist/core/autonomy/bounded-completion.js +24 -2
  8. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  9. package/dist/core/autonomy/lane-tracker.d.ts +1 -1
  10. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  11. package/dist/core/autonomy/lane-tracker.js +9 -1
  12. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  13. package/dist/core/background-lane-controller.d.ts +1 -3
  14. package/dist/core/background-lane-controller.d.ts.map +1 -1
  15. package/dist/core/background-lane-controller.js.map +1 -1
  16. package/dist/core/compaction-controller.d.ts.map +1 -1
  17. package/dist/core/compaction-controller.js +0 -1
  18. package/dist/core/compaction-controller.js.map +1 -1
  19. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
  20. package/dist/core/delegation/managed-lane-controller.js +5 -1
  21. package/dist/core/delegation/managed-lane-controller.js.map +1 -1
  22. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +8 -1
  23. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  24. package/dist/core/delegation/worker-agent-control-coordinator.js +94 -36
  25. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  26. package/dist/core/delegation/worker-agent-control.d.ts +1 -0
  27. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  28. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  29. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  30. package/dist/core/delegation/worker-attempt-executor.js +7 -2
  31. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  32. package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
  33. package/dist/core/delegation/worker-authority-resolver.js +26 -3
  34. package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
  35. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -4
  36. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  37. package/dist/core/delegation/worker-delegation-controller.js +110 -27
  38. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  39. package/dist/core/delegation/worker-fleet-limits.d.ts +9 -2
  40. package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
  41. package/dist/core/delegation/worker-fleet-limits.js +39 -3
  42. package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
  43. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
  44. package/dist/core/delegation/worker-lane-projection.js +4 -0
  45. package/dist/core/delegation/worker-lane-projection.js.map +1 -1
  46. package/dist/core/delegation/worker-lease-heartbeat.d.ts +16 -0
  47. package/dist/core/delegation/worker-lease-heartbeat.d.ts.map +1 -0
  48. package/dist/core/delegation/worker-lease-heartbeat.js +37 -0
  49. package/dist/core/delegation/worker-lease-heartbeat.js.map +1 -0
  50. package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
  51. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  52. package/dist/core/delegation/worker-lifecycle.js +6 -0
  53. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  54. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  55. package/dist/core/delegation/worker-notification-coordinator.js +2 -1
  56. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  57. package/dist/core/delegation/worker-runner.js +2 -2
  58. package/dist/core/delegation/worker-runner.js.map +1 -1
  59. package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts +1 -0
  60. package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts.map +1 -1
  61. package/dist/core/delegation/worker-terminal-handoff-coordinator.js +1 -0
  62. package/dist/core/delegation/worker-terminal-handoff-coordinator.js.map +1 -1
  63. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +4 -2
  64. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
  65. package/dist/core/delegation/worker-tree-budget-coordinator.js +10 -2
  66. package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
  67. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +14 -0
  68. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
  69. package/dist/core/delegation/worker-write-reservation-coordinator.js +121 -33
  70. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
  71. package/dist/core/foreground-terminal-handoff-controller.d.ts +5 -0
  72. package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
  73. package/dist/core/foreground-terminal-handoff-controller.js +28 -12
  74. package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
  75. package/dist/core/orchestration/capability-gateway.d.ts +2 -1
  76. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  77. package/dist/core/orchestration/capability-gateway.js +9 -2
  78. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  79. package/dist/core/orchestration/contracts.d.ts +16 -1
  80. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  81. package/dist/core/orchestration/contracts.js +5 -0
  82. package/dist/core/orchestration/contracts.js.map +1 -1
  83. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  84. package/dist/core/orchestration/profile-registry.js +38 -1
  85. package/dist/core/orchestration/profile-registry.js.map +1 -1
  86. package/dist/core/orchestration/risk-budget.d.ts +10 -0
  87. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  88. package/dist/core/orchestration/risk-budget.js +14 -0
  89. package/dist/core/orchestration/risk-budget.js.map +1 -1
  90. package/dist/core/orchestration/task-runtime-reducer.d.ts +1 -0
  91. package/dist/core/orchestration/task-runtime-reducer.d.ts.map +1 -1
  92. package/dist/core/orchestration/task-runtime-reducer.js +34 -0
  93. package/dist/core/orchestration/task-runtime-reducer.js.map +1 -1
  94. package/dist/core/orchestration/task-runtime.d.ts +1 -0
  95. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  96. package/dist/core/orchestration/task-runtime.js +24 -1
  97. package/dist/core/orchestration/task-runtime.js.map +1 -1
  98. package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
  99. package/dist/core/provider-prompt-contracts.js +2 -1
  100. package/dist/core/provider-prompt-contracts.js.map +1 -1
  101. package/dist/core/reflection-controller.d.ts.map +1 -1
  102. package/dist/core/reflection-controller.js +8 -1
  103. package/dist/core/reflection-controller.js.map +1 -1
  104. package/dist/core/settings-manager.d.ts +2 -2
  105. package/dist/core/settings-manager.d.ts.map +1 -1
  106. package/dist/core/settings-manager.js +2 -2
  107. package/dist/core/settings-manager.js.map +1 -1
  108. package/dist/core/tools/bash.d.ts +3 -0
  109. package/dist/core/tools/bash.d.ts.map +1 -1
  110. package/dist/core/tools/bash.js +13 -2
  111. package/dist/core/tools/bash.js.map +1 -1
  112. package/dist/core/tools/delegate-status.d.ts +1 -0
  113. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  114. package/dist/core/tools/delegate-status.js +19 -1
  115. package/dist/core/tools/delegate-status.js.map +1 -1
  116. package/dist/core/tools/delegate.d.ts +9 -1
  117. package/dist/core/tools/delegate.d.ts.map +1 -1
  118. package/dist/core/tools/delegate.js +198 -64
  119. package/dist/core/tools/delegate.js.map +1 -1
  120. package/dist/core/tools/edit.d.ts.map +1 -1
  121. package/dist/core/tools/edit.js +14 -1
  122. package/dist/core/tools/edit.js.map +1 -1
  123. package/dist/core/tools/file-failure-recovery.d.ts +3 -0
  124. package/dist/core/tools/file-failure-recovery.d.ts.map +1 -1
  125. package/dist/core/tools/file-failure-recovery.js +11 -0
  126. package/dist/core/tools/file-failure-recovery.js.map +1 -1
  127. package/dist/core/tools/orchestration-panel.d.ts +1 -1
  128. package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
  129. package/dist/core/tools/orchestration-panel.js +1 -0
  130. package/dist/core/tools/orchestration-panel.js.map +1 -1
  131. package/dist/core/tools/profile-writer.d.ts.map +1 -1
  132. package/dist/core/tools/profile-writer.js +2 -8
  133. package/dist/core/tools/profile-writer.js.map +1 -1
  134. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  135. package/dist/core/tools/search-command-guard.js +10 -3
  136. package/dist/core/tools/search-command-guard.js.map +1 -1
  137. package/dist/core/tools/write.d.ts.map +1 -1
  138. package/dist/core/tools/write.js +10 -1
  139. package/dist/core/tools/write.js.map +1 -1
  140. package/dist/modes/interactive/components/activity-lane.d.ts +1 -1
  141. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  142. package/dist/modes/interactive/components/activity-lane.js +11 -2
  143. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  144. package/dist/modes/interactive/components/settings-selector.js +1 -1
  145. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  146. package/dist/utils/shell.d.ts +2 -0
  147. package/dist/utils/shell.d.ts.map +1 -1
  148. package/dist/utils/shell.js +3 -1
  149. package/dist/utils/shell.js.map +1 -1
  150. package/docs/harness-architecture.md +6 -3
  151. package/docs/settings.md +8 -6
  152. package/docs/tool-repair.md +1 -1
  153. package/docs/worker-profiles.md +2 -2
  154. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  155. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  156. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  157. package/examples/extensions/sandbox/package-lock.json +2 -2
  158. package/examples/extensions/sandbox/package.json +1 -1
  159. package/examples/extensions/with-deps/package-lock.json +2 -2
  160. package/examples/extensions/with-deps/package.json +1 -1
  161. package/npm-shrinkwrap.json +12 -12
  162. package/package.json +4 -4
@@ -1,7 +1,17 @@
1
+ import { Type } from "typebox";
1
2
  import type { RiskBudget } from "./contracts.ts";
2
3
  export declare const RISK_BUDGET_LIMIT_FIELDS: readonly ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls"];
3
4
  export type RiskBudgetLimitField = (typeof RISK_BUDGET_LIMIT_FIELDS)[number];
4
5
  export declare const RISK_BUDGET_FIELDS: readonly ["maxTokens", "maxWallClockMs", "maxCostUsd", "maxAttempts", "maxToolCalls", "requireApprovalAboveCostUsd"];
6
+ /** One model-facing schema for every explicit worker/profile budget boundary. */
7
+ export declare function createRiskBudgetSchema(): Type.TObject<{
8
+ maxTokens: Type.TOptional<Type.TNumber>;
9
+ maxWallClockMs: Type.TOptional<Type.TNumber>;
10
+ maxCostUsd: Type.TOptional<Type.TNumber>;
11
+ maxAttempts: Type.TOptional<Type.TNumber>;
12
+ maxToolCalls: Type.TOptional<Type.TNumber>;
13
+ requireApprovalAboveCostUsd: Type.TOptional<Type.TNumber>;
14
+ }>;
5
15
  /** Parse raw durable budget input without cloning untrusted values. */
6
16
  export declare function parseRiskBudget(value: unknown, label: string): RiskBudget;
7
17
  export declare function validateRiskBudget(budget: RiskBudget, label: string): void;
@@ -1 +1 @@
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,YACpC,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,CACL,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"}
1
+ {"version":3,"file":"risk-budget.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,wBAAwB,YACpC,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,CACL,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,eAAO,MAAM,kBAAkB,sHAAwE,CAAC;AASxG,iFAAiF;AACjF,wBAAgB,sBAAsB;;;;;;;GAcrC;AASD,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"}
@@ -1,3 +1,4 @@
1
+ import { Type } from "typebox";
1
2
  import { isPlainRecord } from "../util/value-guards.js";
2
3
  export const RISK_BUDGET_LIMIT_FIELDS = [
3
4
  "maxTokens",
@@ -13,6 +14,19 @@ const DISCRETE_BUDGET_FIELDS = new Set([
13
14
  "maxAttempts",
14
15
  "maxToolCalls",
15
16
  ]);
17
+ /** One model-facing schema for every explicit worker/profile budget boundary. */
18
+ export function createRiskBudgetSchema() {
19
+ // Shape belongs to the tool schema. Numeric range and integer invariants belong to
20
+ // parseRiskBudget so every caller follows the same authoritative validation path.
21
+ return Type.Object({
22
+ maxTokens: Type.Optional(Type.Number()),
23
+ maxWallClockMs: Type.Optional(Type.Number()),
24
+ maxCostUsd: Type.Optional(Type.Number()),
25
+ maxAttempts: Type.Optional(Type.Number()),
26
+ maxToolCalls: Type.Optional(Type.Number()),
27
+ requireApprovalAboveCostUsd: Type.Optional(Type.Number()),
28
+ }, { additionalProperties: false });
29
+ }
16
30
  function assertKnownRiskBudgetFields(budget, label) {
17
31
  const unknownField = Object.keys(budget).find((field) => !RISK_BUDGET_FIELDS.includes(field));
18
32
  if (unknownField)
@@ -1 +1 @@
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,IAAI,GAAG,CAAC;IACxF,WAAW;IACX,gBAAgB;IAChB,aAAa;IACb,cAAc;CACd,CAAC,CAAC;AAEH,SAAS,2BAA2B,CAAC,MAA+B,EAAE,KAAa;IAClF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAC5C,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAA4C,CAAC,CACrF,CAAC;IACF,IAAI,YA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AAI,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","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
+ {"version":3,"file":"risk-budget.js","sourceRoot":"","sources":["../../../src/core/orchestration/risk-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,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,MAA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AAqB;IACpF,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAChD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,GAAG,OAAO,CAAC;IAC5E,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,GAAG,OAA8B;IACrE,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;AACf,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport { 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\n/** One model-facing schema for every explicit worker/profile budget boundary. */\nexport function createRiskBudgetSchema() {\n\t// Shape belongs to the tool schema. Numeric range and integer invariants belong to\n\t// parseRiskBudget so every caller follows the same authoritative validation path.\n\treturn Type.Object(\n\t\t{\n\t\t\tmaxTokens: Type.Optional(Type.Number()),\n\t\t\tmaxWallClockMs: Type.Optional(Type.Number()),\n\t\t\tmaxCostUsd: Type.Optional(Type.Number()),\n\t\t\tmaxAttempts: Type.Optional(Type.Number()),\n\t\t\tmaxToolCalls: Type.Optional(Type.Number()),\n\t\t\trequireApprovalAboveCostUsd: Type.Optional(Type.Number()),\n\t\t},\n\t\t{ additionalProperties: false },\n\t);\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"]}
@@ -17,6 +17,7 @@ export declare function assertAttemptFinishTransition(state: TaskRuntimeProjecti
17
17
  export declare function assertAttemptGrantTransition(state: TaskRuntimeProjection, aggregateId: string, attemptId: string, grant: ExecutionGrant): AttemptRuntimeState;
18
18
  export declare function assertAttemptLeaseTransition(state: TaskRuntimeProjection, aggregateId: string, lease: AttemptLease, agentId: string | undefined, occurredAt: string): AttemptRuntimeState;
19
19
  export declare function assertAttemptStartTransition(state: TaskRuntimeProjection, aggregateId: string, attemptId: string, leaseId: string, fencingToken: number, occurredAt: string): AttemptRuntimeState;
20
+ export declare function assertAttemptLeaseRenewalTransition(state: TaskRuntimeProjection, aggregateId: string, attemptId: string, leaseId: string, fencingToken: number, expiresAt: string, occurredAt: string): AttemptRuntimeState;
20
21
  export declare function assertAttemptCheckpointTransition(state: TaskRuntimeProjection, aggregateId: string, checkpoint: AttemptCheckpoint, leaseId: string, occurredAt: string): AttemptRuntimeState;
21
22
  export declare function assertApprovalRequestTransition(state: TaskRuntimeProjection, aggregateId: string, approval: ApprovalRequestContract): void;
22
23
  export declare function assertApprovalResolutionTransition(state: TaskRuntimeProjection, aggregateId: string, resolution: ApprovalResolutionContract): ApprovalRuntimeState;
@@ -1 +1 @@
1
- {"version":3,"file":"task-runtime-reducer.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/task-runtime-reducer.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGjB,KAAK,cAAc,EAQnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAEpB,KAAK,kBAAkB,EAIvB,KAAK,oBAAoB,EACzB,MAAM,gBAAgB,CAAC;AA8BxB,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EAKxB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EAErB,MAAM,yBAAyB,CAAC;AAuDjC,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AA0C9F,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,qBAAqB,EAC5B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,eAAe,EACvB,gBAAgB,CAAC,EAAE,yBAAyB,GAC1C,IAAI,CAi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DD,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,qBAAqB,EACjC,KAAK,EAAE,kBAAkB,GACvB,qBAAqB,CAokBvB;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,GAAG,qBAAqB,CAEvG"}
@@ -543,6 +543,27 @@ export function assertAttemptStartTransition(state, aggregateId, attemptId, leas
543
543
  requireActiveObjectiveForAttemptInProjection(state, attempt);
544
544
  return attempt;
545
545
  }
546
+ export function assertAttemptLeaseRenewalTransition(state, aggregateId, attemptId, leaseId, fencingToken, expiresAt, occurredAt) {
547
+ if (aggregateId !== attemptId) {
548
+ throw new DurableTaskRuntimeError(`Renewed attempt '${attemptId}' does not match its aggregate.`);
549
+ }
550
+ const attempt = state.attempts[attemptId];
551
+ if (!attempt)
552
+ throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);
553
+ if (attempt.status !== "leased" && attempt.status !== "running") {
554
+ throw new DurableTaskRuntimeError(`Attempt '${attemptId}' cannot renew from '${attempt.status}'.`);
555
+ }
556
+ if (!attempt.lease || attempt.lease.leaseId !== leaseId || attempt.lease.fencingToken !== fencingToken) {
557
+ throw new DurableTaskRuntimeError(`Attempt '${attemptId}' lease or fencing token is stale.`);
558
+ }
559
+ assertLeaseLiveAt(attempt.lease, occurredAt, `Attempt '${attemptId}'`);
560
+ const expiresAtMs = Date.parse(expiresAt);
561
+ if (!Number.isFinite(expiresAtMs) || expiresAtMs <= Date.parse(attempt.lease.expiresAt)) {
562
+ throw new DurableTaskRuntimeError(`Attempt '${attemptId}' renewed lease must extend its expiration.`);
563
+ }
564
+ requireActiveObjectiveForAttemptInProjection(state, attempt);
565
+ return attempt;
566
+ }
546
567
  export function assertAttemptCheckpointTransition(state, aggregateId, checkpoint, leaseId, occurredAt) {
547
568
  if (aggregateId !== checkpoint.attemptId) {
548
569
  throw new DurableTaskRuntimeError(`Checkpointed attempt '${checkpoint.attemptId}' does not match its aggregate.`);
@@ -1022,6 +1043,19 @@ export function reduceOrchestrationEvent(projection, event) {
1022
1043
  attempts[attemptId] = { ...attempt, status: "running", updatedAt: event.occurredAt };
1023
1044
  break;
1024
1045
  }
1046
+ case "attempt.lease_renewed": {
1047
+ const attemptId = string(event.payload.attemptId, "attempt.lease_renewed.attemptId");
1048
+ const leaseId = string(event.payload.leaseId, "attempt.lease_renewed.leaseId");
1049
+ const fencingToken = number(event.payload.fencingToken, "attempt.lease_renewed.fencingToken");
1050
+ const expiresAt = string(event.payload.expiresAt, "attempt.lease_renewed.expiresAt");
1051
+ const attempt = assertAttemptLeaseRenewalTransition(state, event.aggregateId, attemptId, leaseId, fencingToken, expiresAt, event.occurredAt);
1052
+ attempts[attemptId] = {
1053
+ ...attempt,
1054
+ lease: { ...attempt.lease, expiresAt },
1055
+ updatedAt: event.occurredAt,
1056
+ };
1057
+ break;
1058
+ }
1025
1059
  case "attempt.checkpointed": {
1026
1060
  const checkpoint = checkpointFromPayload(event.payload);
1027
1061
  const leaseId = string(event.payload.leaseId, "attempt.checkpointed.leaseId");