@makaio/framework 1.0.0-dev-1789034250920 → 1.0.0-dev-1789056039016

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 (110) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/adapters/claude/index.d.mts +36 -36
  3. package/dist/bootstrap-start-client-D7t7d9ty.mjs +1 -0
  4. package/dist/bus/index.mjs +1 -1
  5. package/dist/contracts/adapter/index.d.mts +2 -2
  6. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  7. package/dist/contracts/artifact/index.d.mts +2 -2
  8. package/dist/contracts/automation-trigger/index.d.mts +1 -1
  9. package/dist/contracts/capabilities/index.d.mts +1 -1
  10. package/dist/contracts/client/index.d.mts +2 -2
  11. package/dist/contracts/extension/index.d.mts +4 -4
  12. package/dist/contracts/harness/index.d.mts +1 -1
  13. package/dist/contracts/index.d.mts +51 -51
  14. package/dist/contracts/index.mjs +1 -1
  15. package/dist/contracts/materialization/index.d.mts +1 -1
  16. package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
  17. package/dist/contracts/reaction/index.d.mts +1 -1
  18. package/dist/contracts/session/index.d.mts +2 -2
  19. package/dist/contracts/variant/index.d.mts +1 -1
  20. package/dist/contracts/worker/index.d.mts +2 -2
  21. package/dist/contracts/worker/index.mjs +1 -1
  22. package/dist/contracts/workflow/index.d.mts +2 -2
  23. package/dist/{contribution-CejwVIb3.d.mts → contribution-BWanQHUz.d.mts} +1 -1
  24. package/dist/{extension-context-SrQpa_kp.d.mts → extension-context-BGNUn34r.d.mts} +3 -3
  25. package/dist/{hook-responses-E1gipXIp.d.mts → hook-responses-DVjMuGh9.d.mts} +1 -1
  26. package/dist/{index-D1rYHYPO.d.mts → index-B4KCyY6J.d.mts} +8 -8
  27. package/dist/{index-yapYXeah.d.mts → index-BLhNHkiK.d.mts} +8 -8
  28. package/dist/{index-DWlmiprx2.d.mts → index-BgKU1PuR2.d.mts} +1 -1
  29. package/dist/{index-DKq33gti.d.mts → index-C0jn5nKJ.d.mts} +32 -32
  30. package/dist/{index-BncQwKi-2.d.mts → index-CAURP-Tl2.d.mts} +37 -37
  31. package/dist/{index-BN0qpem12.d.mts → index-CK5GEXLB2.d.mts} +16 -16
  32. package/dist/{index-B94tZHiU.d.mts → index-CKvliyuY.d.mts} +241 -241
  33. package/dist/{index-MKNhvbfG.d.mts → index-CO6ADD43.d.mts} +22 -22
  34. package/dist/{index-OLGGmjgd.d.mts → index-CU9xmTkP.d.mts} +1 -1
  35. package/dist/{index-B7VWSBm72.d.mts → index-CVP9K9-a2.d.mts} +4 -4
  36. package/dist/{index-BTwMms1p.d.mts → index-Caai1zAG.d.mts} +1 -1
  37. package/dist/{index-BPrpnLRQ.d.mts → index-CrvTRZqh.d.mts} +4 -4
  38. package/dist/{index-6BDbhx3A2.d.mts → index-DO0QO0ux2.d.mts} +1 -1
  39. package/dist/{index-BFchykav.d.mts → index-Ddk-kjif.d.mts} +1 -1
  40. package/dist/{index-Cp9olTr7.d.mts → index-DhW9WHFS.d.mts} +6 -6
  41. package/dist/{index-0_Ao0hwU.d.mts → index-Dtc5UYJG.d.mts} +54 -54
  42. package/dist/{index-BeLI73yw2.d.mts → index-H2NL2OwF2.d.mts} +116 -4
  43. package/dist/{index-DxUstDMY.d.mts → index-LRAmVQLj.d.mts} +277 -43
  44. package/dist/{index-BN2_TMtX.d.mts → index-fpGFhEmI.d.mts} +6 -6
  45. package/dist/kernel/extension/index.d.mts +1 -1
  46. package/dist/kernel/index.d.mts +2 -2
  47. package/dist/kernel/observability/index.d.mts +1 -1
  48. package/dist/{namespace-CZJQrexB.d.mts → namespace--mFdPlbu.d.mts} +18 -18
  49. package/dist/{namespace-CjFT0wBT.d.mts → namespace-CQPcYS-Q.d.mts} +2 -2
  50. package/dist/{namespace-BHkEHrUG.d.mts → namespace-DyWNxLt1.d.mts} +6 -6
  51. package/dist/{namespace-BYBMtQUy.d.mts → namespace-TX9DlWiQ.d.mts} +4 -4
  52. package/dist/package.json +1 -1
  53. package/dist/runtime-node/index.d.mts +2 -2
  54. package/dist/runtime-node/index.mjs +21 -21
  55. package/dist/runtime-node/workflow-execution-bus-access.mjs +1 -1
  56. package/dist/runtime-node/workflow-worker/index.d.mts +2 -2
  57. package/dist/runtime-node/workflow-worker/index.mjs +1 -1
  58. package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
  59. package/dist/{schemas-COQUToGQ.d.mts → schemas-BGcAiQE0.d.mts} +4 -4
  60. package/dist/{schemas-DNUfTOJ0.d.mts → schemas-D9WJH6We.d.mts} +1 -1
  61. package/dist/{schemas-Ct0tTtkV.d.mts → schemas-Dt1YwXLN.d.mts} +8 -8
  62. package/dist/{schemas-DYtUc2WA.d.mts → schemas-FkLOBJgq.d.mts} +4 -4
  63. package/dist/{schemas-DNvDh0eE2.d.mts → schemas-Fn-eeay32.d.mts} +7 -7
  64. package/dist/{schemas-mTWvDwx9.d.mts → schemas-_NrySTmN.d.mts} +1 -1
  65. package/dist/services/adapter-runtime/index.d.mts +3 -3
  66. package/dist/services/adapter-runtime/namespace.d.mts +1 -1
  67. package/dist/services/adapter-runtime/schemas.d.mts +1 -1
  68. package/dist/services/adapter-subsystem/index.d.mts +2 -2
  69. package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
  70. package/dist/services/context-rules/index.d.mts +3 -3
  71. package/dist/services/execution-target/index.d.mts +1 -1
  72. package/dist/services/filesystem/namespace.d.mts +6 -6
  73. package/dist/services/filesystem/schemas.d.mts +3 -3
  74. package/dist/services/git/namespace.d.mts +2 -2
  75. package/dist/services/git/schemas.d.mts +1 -1
  76. package/dist/services/harness/index.d.mts +3 -3
  77. package/dist/services/index.d.mts +34 -34
  78. package/dist/services/log-import/browser.d.mts +2 -2
  79. package/dist/services/log-import/index.d.mts +2 -2
  80. package/dist/services/log-import/log-import.d.mts +1 -1
  81. package/dist/services/log-import/namespace.d.mts +2 -2
  82. package/dist/services/log-import/schemas.d.mts +1 -1
  83. package/dist/services/preferences/index.d.mts +2 -2
  84. package/dist/services/preferences/schemas.d.mts +1 -1
  85. package/dist/services/preferences/storage-namespace.d.mts +2 -2
  86. package/dist/services/provider-context/index.d.mts +1 -1
  87. package/dist/services/session/index.d.mts +4 -4
  88. package/dist/services/session/messages/namespace.d.mts +1 -1
  89. package/dist/services/session/session-events/namespace.d.mts +1 -1
  90. package/dist/services/settings/namespace.d.mts +8 -8
  91. package/dist/services/settings/storage/extension-configs/namespace.d.mts +3 -3
  92. package/dist/services/subagent-template/index.d.mts +1 -1
  93. package/dist/services/subagent-template/schemas.d.mts +1 -1
  94. package/dist/{session-lineage-9_qwkjUq.d.mts → session-lineage-CoNs4WZy.d.mts} +1 -1
  95. package/dist/{storage-namespace-DITavhRL.d.mts → storage-namespace-BUSNKZLw.d.mts} +10 -10
  96. package/dist/{transition-DNi6L7i2.d.mts → transition-D2VKNtv6.d.mts} +1 -1
  97. package/dist/{types-BeAxyCuU2.d.mts → types-DafDuOcH2.d.mts} +1 -1
  98. package/dist/{types-DXobLxrf.d.mts → types-DyXXIK4c.d.mts} +15 -15
  99. package/dist/ui-kernel/index.d.mts +4 -4
  100. package/dist/ui-kernel/pages/namespace.d.mts +4 -4
  101. package/dist/ui-kernel/pages/schemas.d.mts +1 -1
  102. package/dist/{view-builder-B5gP9RnN.d.mts → view-builder-BFEvUe6n.d.mts} +1 -1
  103. package/dist/worker-L8vWpbYa.mjs +1 -0
  104. package/dist/workflow-engine/index.d.mts +32 -32
  105. package/dist/workflow-worker-BDA-E_pm.mjs +2 -0
  106. package/package.json +1 -1
  107. package/dist/bootstrap-start-client-rW55mDI-.mjs +0 -1
  108. package/dist/worker-Cmme3rMM.mjs +0 -1
  109. package/dist/workflow-worker-BAO7pQpx.mjs +0 -2
  110. package/dist/{index-C4DMSFLE2.d.mts → index-D4FE3jHM2.d.mts} +6 -6
@@ -836,8 +836,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
836
836
  completed: "completed";
837
837
  cancelled: "cancelled";
838
838
  failed: "failed";
839
- running: "running";
840
839
  paused: "paused";
840
+ running: "running";
841
841
  finalizing: "finalizing";
842
842
  }>;
843
843
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -878,8 +878,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
878
878
  completed: "completed";
879
879
  cancelled: "cancelled";
880
880
  failed: "failed";
881
- running: "running";
882
881
  paused: "paused";
882
+ running: "running";
883
883
  finalizing: "finalizing";
884
884
  }>;
885
885
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -927,8 +927,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
927
927
  completed: "completed";
928
928
  cancelled: "cancelled";
929
929
  failed: "failed";
930
- running: "running";
931
930
  paused: "paused";
931
+ running: "running";
932
932
  finalizing: "finalizing";
933
933
  }>;
934
934
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -1182,10 +1182,10 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1182
1182
  frameId: z.ZodString;
1183
1183
  nodeId: z.ZodString;
1184
1184
  nodeType: z.ZodEnum<{
1185
+ sequence: "sequence";
1185
1186
  station: "station";
1186
1187
  "delegate-agent": "delegate-agent";
1187
1188
  "delegate-role": "delegate-role";
1188
- sequence: "sequence";
1189
1189
  parallel: "parallel";
1190
1190
  gate: "gate";
1191
1191
  iterate: "iterate";
@@ -1227,10 +1227,10 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1227
1227
  frameId: z.ZodString;
1228
1228
  nodeId: z.ZodString;
1229
1229
  nodeType: z.ZodEnum<{
1230
+ sequence: "sequence";
1230
1231
  station: "station";
1231
1232
  "delegate-agent": "delegate-agent";
1232
1233
  "delegate-role": "delegate-role";
1233
- sequence: "sequence";
1234
1234
  parallel: "parallel";
1235
1235
  gate: "gate";
1236
1236
  iterate: "iterate";
@@ -1267,8 +1267,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1267
1267
  completed: "completed";
1268
1268
  cancelled: "cancelled";
1269
1269
  failed: "failed";
1270
- running: "running";
1271
1270
  paused: "paused";
1271
+ running: "running";
1272
1272
  finalizing: "finalizing";
1273
1273
  }>>;
1274
1274
  error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -1464,8 +1464,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1464
1464
  completed: "completed";
1465
1465
  cancelled: "cancelled";
1466
1466
  failed: "failed";
1467
- running: "running";
1468
1467
  paused: "paused";
1468
+ running: "running";
1469
1469
  finalizing: "finalizing";
1470
1470
  }>>;
1471
1471
  artifactRef: z.ZodOptional<z.ZodObject<{
@@ -1488,8 +1488,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1488
1488
  completed: "completed";
1489
1489
  cancelled: "cancelled";
1490
1490
  failed: "failed";
1491
- running: "running";
1492
1491
  paused: "paused";
1492
+ running: "running";
1493
1493
  finalizing: "finalizing";
1494
1494
  }>;
1495
1495
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -1541,8 +1541,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1541
1541
  completed: "completed";
1542
1542
  cancelled: "cancelled";
1543
1543
  failed: "failed";
1544
- running: "running";
1545
1544
  paused: "paused";
1545
+ running: "running";
1546
1546
  finalizing: "finalizing";
1547
1547
  }>;
1548
1548
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -1585,10 +1585,10 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1585
1585
  frameId: z.ZodString;
1586
1586
  nodeId: z.ZodString;
1587
1587
  nodeType: z.ZodEnum<{
1588
+ sequence: "sequence";
1588
1589
  station: "station";
1589
1590
  "delegate-agent": "delegate-agent";
1590
1591
  "delegate-role": "delegate-role";
1591
- sequence: "sequence";
1592
1592
  parallel: "parallel";
1593
1593
  gate: "gate";
1594
1594
  iterate: "iterate";
@@ -1631,10 +1631,10 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1631
1631
  frameId: z.ZodString;
1632
1632
  nodeId: z.ZodString;
1633
1633
  nodeType: z.ZodEnum<{
1634
+ sequence: "sequence";
1634
1635
  station: "station";
1635
1636
  "delegate-agent": "delegate-agent";
1636
1637
  "delegate-role": "delegate-role";
1637
- sequence: "sequence";
1638
1638
  parallel: "parallel";
1639
1639
  gate: "gate";
1640
1640
  iterate: "iterate";
@@ -1674,10 +1674,10 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
1674
1674
  frameId: z.ZodString;
1675
1675
  nodeId: z.ZodString;
1676
1676
  nodeType: z.ZodEnum<{
1677
+ sequence: "sequence";
1677
1678
  station: "station";
1678
1679
  "delegate-agent": "delegate-agent";
1679
1680
  "delegate-role": "delegate-role";
1680
- sequence: "sequence";
1681
1681
  parallel: "parallel";
1682
1682
  gate: "gate";
1683
1683
  iterate: "iterate";
@@ -3058,7 +3058,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
3058
3058
  tableName: "workflow_executions";
3059
3059
  dataType: "string";
3060
3060
  columnType: "SQLiteText";
3061
- data: "pending" | "completed" | "cancelled" | "failed" | "running" | "paused" | "finalizing";
3061
+ data: "pending" | "completed" | "cancelled" | "failed" | "paused" | "running" | "finalizing";
3062
3062
  driverParam: string;
3063
3063
  notNull: true;
3064
3064
  hasDefault: false;
@@ -3327,7 +3327,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
3327
3327
  tableName: "workflow_execution_frames";
3328
3328
  dataType: "string";
3329
3329
  columnType: "SQLiteText";
3330
- data: "station" | "delegate-agent" | "delegate-role" | "sequence" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
3330
+ data: "sequence" | "station" | "delegate-agent" | "delegate-role" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
3331
3331
  driverParam: string;
3332
3332
  notNull: true;
3333
3333
  hasDefault: false;
@@ -3340,7 +3340,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
3340
3340
  generated: undefined;
3341
3341
  }, {}, {
3342
3342
  length: number | undefined;
3343
- $type: "station" | "delegate-agent" | "delegate-role" | "sequence" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
3343
+ $type: "sequence" | "station" | "delegate-agent" | "delegate-role" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
3344
3344
  }>;
3345
3345
  path: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
3346
3346
  name: string;
@@ -4918,7 +4918,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
4918
4918
  tableName: "worklog_summaries";
4919
4919
  dataType: "string";
4920
4920
  columnType: "SQLiteText";
4921
- data: "pending" | "completed" | "cancelled" | "failed" | "running" | "paused" | "finalizing";
4921
+ data: "pending" | "completed" | "cancelled" | "failed" | "paused" | "running" | "finalizing";
4922
4922
  driverParam: string;
4923
4923
  notNull: true;
4924
4924
  hasDefault: false;
@@ -5141,7 +5141,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
5141
5141
  tableName: "worklog_frame_entries";
5142
5142
  dataType: "string";
5143
5143
  columnType: "SQLiteText";
5144
- data: "station" | "delegate-agent" | "delegate-role" | "sequence" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
5144
+ data: "sequence" | "station" | "delegate-agent" | "delegate-role" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
5145
5145
  driverParam: string;
5146
5146
  notNull: true;
5147
5147
  hasDefault: false;
@@ -5154,7 +5154,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
5154
5154
  generated: undefined;
5155
5155
  }, {}, {
5156
5156
  length: number | undefined;
5157
- $type: "station" | "delegate-agent" | "delegate-role" | "sequence" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
5157
+ $type: "sequence" | "station" | "delegate-agent" | "delegate-role" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop";
5158
5158
  }>;
5159
5159
  path: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
5160
5160
  name: string;
@@ -6014,7 +6014,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
6014
6014
  tableName: "workflow_finalizations";
6015
6015
  dataType: "string";
6016
6016
  columnType: "SQLiteText";
6017
- data: "failed" | "acknowledged" | "claimed";
6017
+ data: "acknowledged" | "failed" | "claimed";
6018
6018
  driverParam: string;
6019
6019
  notNull: true;
6020
6020
  hasDefault: false;
@@ -6459,8 +6459,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
6459
6459
  completed: "completed";
6460
6460
  cancelled: "cancelled";
6461
6461
  failed: "failed";
6462
- running: "running";
6463
6462
  paused: "paused";
6463
+ running: "running";
6464
6464
  finalizing: "finalizing";
6465
6465
  }>;
6466
6466
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -6501,8 +6501,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
6501
6501
  completed: "completed";
6502
6502
  cancelled: "cancelled";
6503
6503
  failed: "failed";
6504
- running: "running";
6505
6504
  paused: "paused";
6505
+ running: "running";
6506
6506
  finalizing: "finalizing";
6507
6507
  }>;
6508
6508
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -6550,8 +6550,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
6550
6550
  completed: "completed";
6551
6551
  cancelled: "cancelled";
6552
6552
  failed: "failed";
6553
- running: "running";
6554
6553
  paused: "paused";
6554
+ running: "running";
6555
6555
  finalizing: "finalizing";
6556
6556
  }>;
6557
6557
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -6805,10 +6805,10 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
6805
6805
  frameId: z.ZodString;
6806
6806
  nodeId: z.ZodString;
6807
6807
  nodeType: z.ZodEnum<{
6808
+ sequence: "sequence";
6808
6809
  station: "station";
6809
6810
  "delegate-agent": "delegate-agent";
6810
6811
  "delegate-role": "delegate-role";
6811
- sequence: "sequence";
6812
6812
  parallel: "parallel";
6813
6813
  gate: "gate";
6814
6814
  iterate: "iterate";
@@ -6850,10 +6850,10 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
6850
6850
  frameId: z.ZodString;
6851
6851
  nodeId: z.ZodString;
6852
6852
  nodeType: z.ZodEnum<{
6853
+ sequence: "sequence";
6853
6854
  station: "station";
6854
6855
  "delegate-agent": "delegate-agent";
6855
6856
  "delegate-role": "delegate-role";
6856
- sequence: "sequence";
6857
6857
  parallel: "parallel";
6858
6858
  gate: "gate";
6859
6859
  iterate: "iterate";
@@ -6890,8 +6890,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
6890
6890
  completed: "completed";
6891
6891
  cancelled: "cancelled";
6892
6892
  failed: "failed";
6893
- running: "running";
6894
6893
  paused: "paused";
6894
+ running: "running";
6895
6895
  finalizing: "finalizing";
6896
6896
  }>>;
6897
6897
  error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -7087,8 +7087,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
7087
7087
  completed: "completed";
7088
7088
  cancelled: "cancelled";
7089
7089
  failed: "failed";
7090
- running: "running";
7091
7090
  paused: "paused";
7091
+ running: "running";
7092
7092
  finalizing: "finalizing";
7093
7093
  }>>;
7094
7094
  artifactRef: z.ZodOptional<z.ZodObject<{
@@ -7111,8 +7111,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
7111
7111
  completed: "completed";
7112
7112
  cancelled: "cancelled";
7113
7113
  failed: "failed";
7114
- running: "running";
7115
7114
  paused: "paused";
7115
+ running: "running";
7116
7116
  finalizing: "finalizing";
7117
7117
  }>;
7118
7118
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -7164,8 +7164,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
7164
7164
  completed: "completed";
7165
7165
  cancelled: "cancelled";
7166
7166
  failed: "failed";
7167
- running: "running";
7168
7167
  paused: "paused";
7168
+ running: "running";
7169
7169
  finalizing: "finalizing";
7170
7170
  }>;
7171
7171
  inputs: z.ZodType<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue, z.core.$ZodTypeInternals<_$_makaio_contracts0.JsonValue, _$_makaio_contracts0.JsonValue>>;
@@ -7208,10 +7208,10 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
7208
7208
  frameId: z.ZodString;
7209
7209
  nodeId: z.ZodString;
7210
7210
  nodeType: z.ZodEnum<{
7211
+ sequence: "sequence";
7211
7212
  station: "station";
7212
7213
  "delegate-agent": "delegate-agent";
7213
7214
  "delegate-role": "delegate-role";
7214
- sequence: "sequence";
7215
7215
  parallel: "parallel";
7216
7216
  gate: "gate";
7217
7217
  iterate: "iterate";
@@ -7254,10 +7254,10 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
7254
7254
  frameId: z.ZodString;
7255
7255
  nodeId: z.ZodString;
7256
7256
  nodeType: z.ZodEnum<{
7257
+ sequence: "sequence";
7257
7258
  station: "station";
7258
7259
  "delegate-agent": "delegate-agent";
7259
7260
  "delegate-role": "delegate-role";
7260
- sequence: "sequence";
7261
7261
  parallel: "parallel";
7262
7262
  gate: "gate";
7263
7263
  iterate: "iterate";
@@ -7297,10 +7297,10 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
7297
7297
  frameId: z.ZodString;
7298
7298
  nodeId: z.ZodString;
7299
7299
  nodeType: z.ZodEnum<{
7300
+ sequence: "sequence";
7300
7301
  station: "station";
7301
7302
  "delegate-agent": "delegate-agent";
7302
7303
  "delegate-role": "delegate-role";
7303
- sequence: "sequence";
7304
7304
  parallel: "parallel";
7305
7305
  gate: "gate";
7306
7306
  iterate: "iterate";
@@ -8379,7 +8379,7 @@ declare const worklogFrameEntriesDual: _$_makaio_storage_drizzle0.DualTable<"wor
8379
8379
  /** Unique frame identifier within the execution. */frameId: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm0.IsPrimaryKey<_$drizzle_orm0.NotNull<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"frame_id", [string, ...string[]], number | undefined>>>, _$drizzle_orm0.IsPrimaryKey<_$drizzle_orm0.NotNull<_$drizzle_orm_pg_core0.PgTextBuilderInitial<"frame_id", [string, ...string[]]>>>>; /** Execution this frame belongs to. */
8380
8380
  executionId: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm0.NotNull<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"execution_id", [string, ...string[]], number | undefined>>, _$drizzle_orm0.NotNull<_$drizzle_orm_pg_core0.PgTextBuilderInitial<"execution_id", [string, ...string[]]>>>; /** Node identifier from the workflow definition. */
8381
8381
  nodeId: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm0.NotNull<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"node_id", [string, ...string[]], number | undefined>>, _$drizzle_orm0.NotNull<_$drizzle_orm_pg_core0.PgTextBuilderInitial<"node_id", [string, ...string[]]>>>; /** Node type discriminant. */
8382
- nodeType: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm0.$Type<_$drizzle_orm0.NotNull<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"node_type", [string, ...string[]], number | undefined>>, "station" | "delegate-agent" | "delegate-role" | "sequence" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop">, _$drizzle_orm0.$Type<_$drizzle_orm0.NotNull<_$drizzle_orm_pg_core0.PgTextBuilderInitial<"node_type", [string, ...string[]]>>, "station" | "delegate-agent" | "delegate-role" | "sequence" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop">>;
8382
+ nodeType: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm0.$Type<_$drizzle_orm0.NotNull<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"node_type", [string, ...string[]], number | undefined>>, "sequence" | "station" | "delegate-agent" | "delegate-role" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop">, _$drizzle_orm0.$Type<_$drizzle_orm0.NotNull<_$drizzle_orm_pg_core0.PgTextBuilderInitial<"node_type", [string, ...string[]]>>, "sequence" | "station" | "delegate-agent" | "delegate-role" | "parallel" | "gate" | "iterate" | "iterate-chain" | "loop">>;
8383
8383
  /**
8384
8384
  * Ordered path of frame IDs from the root frame to this frame (inclusive).
8385
8385
  * Stored as a JSON array for tree correlation.
@@ -0,0 +1,2 @@
1
+ import{resolveMakaioHome as e}from"./runtime-node/makaio-config.mjs";import{t}from"./extension-package-provenance-Dr7JXjLS.mjs";import{_ as n,d as r,l as i,n as a,o,r as s,u as c,x as l,y as u}from"./bootstrap-start-client-D7t7d9ty.mjs";import{mintOrRotateWorkflowExecutionBusSecret as d}from"./runtime-node/workflow-execution-bus-access.mjs";import{z as f}from"zod";import{execFile as p,spawn as m}from"node:child_process";import{promisify as ee}from"node:util";import*as h from"node:fs/promises";import{access as te}from"node:fs/promises";import*as g from"node:path";import{basename as ne,isAbsolute as re,join as ie,relative as ae}from"node:path";import*as _ from"node:crypto";import{randomUUID as v}from"node:crypto";import{constants as oe}from"node:fs";import{AdapterSubjects as se,BoundedRecoveryEvidenceSchema as y,ExecutionAttemptSchemas as b,ExecutionAttemptSubjects as x,FrameworkContractNamespaces as ce,FrameworkStorageNamespaces as le,JsonValueSchema as ue,PRE_REQUEST_REJECTION_CODE as de,PROVIDER_ALLOCATION_REF_VERSION as fe,ProviderAllocationRefSchema as pe,RECOVERY_EVIDENCE_LIMITS as S,WorkerCapabilitiesSchema as me,WorkerSchemas as he,WorkerSubjects as C,WorkflowRunContextSchema as ge,WorkflowRunResultSchema as _e,WorkflowWorkerConfigSchema as ve,createWorkflowCancelSubject as ye}from"@makaio/framework/contracts";import{BusAbortError as be,createBusInstance as w,isRequestCancellation as T,waitForSubscriptionPropagation as xe}from"@makaio/framework/bus";import{ExtensionCoordinator as Se,KernelSubjects as Ce,coalesceExtensionOverrides as we,filterEligibleExtensions as Te}from"@makaio/framework/kernel";import{BaseService as Ee}from"@makaio/framework/service-base";import{AdapterRuntimeSubjects as De,registerAdapterRuntimeIdentityHandlers as Oe}from"@makaio/framework/services/adapter-runtime";import{devNull as E}from"node:os";import{CLIDetectionNamespace as ke,CLIDetectionSubjects as Ae}from"@makaio/framework/services/cli-detection/namespace";import{SessionOrchestratorToken as je,ToolRegistryToken as Me,canonicalModelPackage as Ne,createSubagentServicePackage as Pe,createToolContributionProcessor as Fe,frameworkCorePackages as D,sessionBridgePackage as Ie,sessionOrchestratorPackage as Le,sessionPackage as Re,sessionStoragePackage as ze,toolRegistryPackage as Be}from"@makaio/framework/services";import{AdapterSubsystemSubjects as Ve}from"@makaio/framework/services/adapter-subsystem";import{createClientsCorePackage as He}from"@makaio/framework/clients";import{AdapterSubsystemToken as O,createAdapterSubsystemContributionProcessor as Ue,createAdapterSubsystemPackage as We,orderAfterAdapterSubsystem as Ge}from"@makaio/framework/adapter-subsystem";import{execa as Ke}from"execa";import qe from"piscina";import{ExecutionAttemptAuthority as Je,WORKFLOW_WORKLOAD_KIND as Ye,WORKFLOW_WORKLOAD_VERSION as Xe,WorkflowStorageSubjects as Ze,buildWorkflowAttemptInstruction as Qe,parseWorkflowAttemptInstruction as k,runAuthorityDispatchedAttempt as $e,toCommittedWorkflowRunnerCompletion as et}from"@makaio/framework/workflow-engine";import{runWorkflowOrchestrator as tt}from"@makaio/framework/workflow-engine/workflow-orchestrator";import{setTimeout as nt}from"node:timers/promises";function A(e){return e.on(se.getCapabilities,async t=>{let{adapterName:n,adapterId:r}=t.payload;if(r){await t.next();return}if(n){let r=await e.requestOptional(De.resolveId,{adapterName:n}),i=r.handled?r.data.adapterId:void 0;i&&(t.payload.adapterId=i)}await t.next()},{priority:20})}function j(e){let{coordinator:t,configRepository:n,platformDefaults:r,prepareAuthRuntime:i,runtimeSnapshotHandlerPriority:a,runtimeDefinitionHandlerPriority:o}=e,s=We({configRepository:n,coordinator:t,platformDefaults:r,...i!==void 0&&{prepareAuthRuntime:i},...a!==void 0&&{runtimeSnapshotHandlerPriority:a},...o!==void 0&&{runtimeDefinitionHandlerPriority:o}});return t.registerContributionProcessor(Ue({getAdapterSubsystemService:()=>t.getExtensionService(O)})),{adapterSubsystemPackage:s}}function M(e){let{bus:t,currentMachineId:n}=e,r=Oe(t,{currentMachineId:n,listKnownAdapterNames:e.listKnownAdapterNames??(async()=>{let{configs:e}=await t.request(Ve.listAdapterConfigs,{});return e.map(e=>e.name)}),...e.resolveLiveAdapterId!==void 0&&{resolveLiveAdapterId:e.resolveLiveAdapterId},...e.resolveLiveAdapterIdentity!==void 0&&{resolveLiveAdapterIdentity:e.resolveLiveAdapterIdentity},...e.listLiveAdapterIdentities!==void 0&&{listLiveAdapterIdentities:e.listLiveAdapterIdentities}}),i=A(t);return{cleanup:()=>{r.cleanup(),i()}}}function N(e,t){if(!(e instanceof Error))return!1;let{rootPackageName:n,subpath:r}=rt(t),i=(r===void 0?[t]:[t,n]).flatMap(e=>[`Cannot find package '${e}'`,`Cannot find module '${e}'`,`Cannot find package "${e}"`,`Cannot find module "${e}"`]),a=e;return(a.code===`ERR_MODULE_NOT_FOUND`||a.code===`MODULE_NOT_FOUND`)&&i.some(t=>e.message.includes(t))||a.code===`ERR_PACKAGE_PATH_NOT_EXPORTED`&&r!==void 0&&e.message.includes(`Package subpath '${r}' is not defined by "exports"`)&&it(e.message,n)?!0:i.some(t=>e.message.includes(t))}async function P(e){try{return await import(e)}catch(t){if(N(t,e))return null;throw t}}function rt(e){let t=e.split(`/`);return e.startsWith(`@`)?{rootPackageName:t.slice(0,2).join(`/`),subpath:t.length>2?`./${t.slice(2).join(`/`)}`:void 0}:{rootPackageName:t[0]??e,subpath:t.length>1?`./${t.slice(1).join(`/`)}`:void 0}}function it(e,t){let n=t,r=t.replaceAll(`/`,`\\`);return e.includes(`/${n}/package.json`)||e.includes(`\\${r}\\package.json`)}async function F(e,t=process.env,n=process.platform){let r=t[Object.keys(t).find(e=>e.toUpperCase()===`PATH`)??`PATH`]??``,i=(t.PATHEXT??`.EXE;.CMD;.BAT;.COM`).split(`;`).filter(Boolean),a=n===`win32`?g.extname(e)===``?i:[``,...i]:[``];for(let t of r.split(g.delimiter)){let n=t.replace(/^"|"$/gu,``),r=g.resolve(n||process.cwd());for(let t of a){let n=g.join(r,`${e}${t}`);try{return await te(n,oe.X_OK),n}catch{}}}}async function I(e,t=5e3,n=1e3){let{stdout:r}=await Ke(e,[`--version`],{forceKillAfterDelay:n,timeout:t});return r}function at(e){return e.match(/(\d+\.\d+\.\d+)/u)?.[1]??`unknown`}async function ot(e,t=F,n=I){try{let r=await t(e);if(r===void 0)return{binary:e,found:!1};let i=await n(r);return i.length===0?{binary:e,found:!1}:{binary:e,found:!0,path:r,version:at(i)}}catch{return{binary:e,found:!1}}}async function st(e,t=F,n=I){return Promise.all(e.map(e=>ot(e,t,n)))}var ct=class extends Ee{constructor(e){super(e)}onInit(){this.registerHandler(Ae.scan,async e=>{let t=await st(e.payload.binaries);e.setResult({results:t})})}};const L={name:`makaio.cli-detection`,displayName:`CLI Detection`,version:`0.1.0`,critical:!0,surface:`any`,namespaces:[ke],create:e=>new ct(e.bus)};function R(e,t){e.push(...lt(t))}function lt(e){return e===void 0?[]:typeof e==`function`?[e]:[...e]}function ut(e,t=[]){let n=new Set([e]),r=new Set,i=new Map;for(let e of t)typeof e==`string`?n.add(e):(r.add(e.id),e.version!==void 0&&i.set(e.id,e.version));return{hosts:n,capabilities:r,...i.size>0?{capabilityVersions:i}:{}}}function dt(e=[]){return e.some(e=>typeof e==`string`&&e===`node`)?e:[`node`,...e]}function ft(e){return we(Te(mt(e.packages,e.configProvider),e.surface,e.runtimeEnvironment))}function pt(e,n){let r=ft(n),i=new Set(r.map(t));return e.filter(({ownerPackage:e})=>i.has(e)).map(({package:e})=>e)}function mt(e,t){return t?e.filter(e=>t.loadEnabled(e.name)!==!1):e}function ht(e,t){return e.filter(e=>e.runtimeOwnership?.[t]===!0).map(e=>e.name)}function gt(e,t){let n=ht(e,t);if(n.length>1)throw Error(`Multiple extensions own runtimeOwnership.${t}: ${n.join(`, `)}`)}function _t(e){return gt(e,`sessionOrchestrator`),ht(e,`sessionOrchestrator`).length===0}function vt(e){return e===!0||_t(e)?D:D.filter(e=>e.name!==je.name)}function yt(e,t,n){let r=[];try{for(let i of e){let e=i.runtimeBoot;e&&R(r,e.configure({bus:t,registerContributionProcessor:e=>{r.push(n.registerContributionProcessor(e))},forEachActiveExtension:e=>{n.forEachActiveExtension(e)}}))}}catch(e){let t=[];for(let e of[...r].reverse())try{e()}catch(e){t.push(e)}throw t.length>0?AggregateError([e,...t],`Extension boot contribution failed and rollback cleanup reported additional errors`,{cause:e}):e}return r}function bt(){let e=process.env.MAKAIO_SKIP_EXTENSIONS;if(!e)return new Set;let t=e.split(`,`).map(e=>e.trim()).filter(Boolean);return new Set(t)}var xt=class{pool;constructor(e){this.pool=new qe({filename:e.workerEntry,maxThreads:e.maxConcurrency??4,idleTimeout:e.idleTimeoutMs??3e4})}async run(e,t,n){return this.pool.run(e,{signal:t,transferList:n})}onMessage(e){return this.pool.on(`message`,e),()=>this.pool.off(`message`,e)}async dispose(){await this.pool.destroy()}},z=class extends Error{code;constructor(e,t){super(e),this.code=t,this.name=`MaterializationError`}};function B(e,t,n){let r=g.resolve(t)+g.sep,i=g.resolve(e);if(i!==g.resolve(t)&&!i.startsWith(r))throw new z(`${n} escapes allowed root: ${e} is not within ${t}`,`containment-violation`)}async function V(e,t,n,r){let i=r??await h.realpath(t),a;try{a=await h.realpath(e)}catch{return e}let o=i+g.sep;if(a!==i&&!a.startsWith(o))throw new z(`${n} escapes allowed root via symlink: real path ${a} is not within ${i}`,`symlink-escape`);return a}function St(e){let t=e.indexOf(`-`);if(t===-1)throw new z(`Invalid SRI integrity format: ${e}`,`contribution-integrity-mismatch`);return{algorithm:e.slice(0,t),digest:e.slice(t+1)}}async function Ct(e,t){let n=await h.readFile(e);return _.createHash(t).update(n).digest(`base64`)}const H=new Set([`.git`,`node_modules`]);function wt(e){return H.has(e.toLowerCase())}async function Tt(e,t){let n=t.toLowerCase();if(!H.has(n))return!1;if(t===n)return!0;try{let[r,i]=await Promise.all([h.lstat(g.join(e,t)),h.lstat(g.join(e,n))]);return r.dev===i.dev&&r.ino===i.ino}catch(e){if(e.code===`ENOENT`)return!1;throw e}}const Et=H,Dt=new Set([`.DS_Store`]);async function Ot(e,t){let n=_.createHash(t),r=[];async function i(t){let n=await h.readdir(t,{withFileTypes:!0});for(let a of n){let n=g.join(t,a.name);if(a.isSymbolicLink())throw new z(`Contribution package contains a symbolic link: ${g.relative(e,n)}`,`symlink-escape`);if(a.isDirectory()){Et.has(a.name)||await i(n);continue}if(a.isFile()){Dt.has(a.name)||r.push(g.relative(e,n));continue}throw new z(`Contribution package contains an unsupported filesystem entry: ${g.relative(e,n)}`,`contribution-integrity-mismatch`)}}await i(e),r.sort();for(let t of r)n.update(t.split(g.sep).join(`/`)),n.update(`\0`),n.update(await h.readFile(g.join(e,t))),n.update(`\0`);return`${t}-${n.digest(`base64`)}`}async function kt(e,t=`sha256`){let n=_.createHash(t),r=[];async function i(t){let n=await h.readdir(t,{withFileTypes:!0});for(let a of n){let n=g.join(t,a.name);if(!await Tt(t,a.name)){if(a.isDirectory()){await i(n);continue}if(a.isFile()){r.push(g.relative(e,n));continue}throw a.isSymbolicLink()?new z(`Workspace root contains a symbolic link: ${g.relative(e,n)}`,`symlink-escape`):new z(`Workspace root contains an unsupported filesystem entry: ${g.relative(e,n)}`,`unsupported-filesystem-entry`)}}}await i(e),r.sort();for(let t of r){n.update(t),n.update(`\0`);let r=await h.readFile(g.join(e,t));n.update(r),n.update(`\0`)}return`${t}-${n.digest(`base64`)}`}async function At(e,t,n){let r=g.join(t,`node_modules`,e.packageName);B(r,t,`Contribution package directory`),await V(r,t,`Contribution package directory`,n);let i=g.join(r,`package.json`),a;try{a=await h.readFile(i,`utf-8`)}catch{throw new z(`Contribution package not found: ${e.packageName} (expected at ${r})`,`contribution-missing`)}let o=JSON.parse(a);if(o.name!==e.packageName)throw new z(`Contribution identity mismatch: expected ${e.packageName}, found ${o.name??`<none>`}`,`contribution-missing`);if(o.version!==e.version)throw new z(`Contribution version mismatch for ${e.packageName}: expected ${e.version}, found ${o.version??`<none>`}`,`contribution-version-mismatch`);let s=g.join(r,e.entrypoint);B(s,r,`Contribution entrypoint`),await V(s,t,`Contribution entrypoint`,n);try{await h.access(s)}catch{throw new z(`Contribution entrypoint not found for ${e.packageName}: ${e.entrypoint}`,`contribution-entrypoint-mismatch`)}let{algorithm:c}=St(e.integrity),l;try{l=await Ot(r,c)}catch(t){if(t instanceof z)throw t;let n=typeof t==`object`&&t&&`code`in t&&typeof t.code==`string`?t.code:void 0;throw n!==void 0&&!n.startsWith(`ERR_`)?new z(`Contribution package cannot be read for ${e.packageName}`,`contribution-entrypoint-mismatch`):t}if(l!==e.integrity)throw new z(`Contribution integrity mismatch for ${e.packageName}: expected ${e.integrity}, computed ${l}`,`contribution-integrity-mismatch`);return s}async function jt(e,t,n){let r=await n.resolveWorkspaceRoot(e.workspaceId);if(r===void 0)throw new z(`Unknown workspace ID: ${e.workspaceId}`,`unknown-workspace`);try{if(!(await h.stat(r)).isDirectory())throw new z(`Workspace root is not a directory: ${r}`,`containment-violation`)}catch(e){throw e instanceof z?e:new z(`Workspace root does not exist: ${r}`,`containment-violation`)}let i=await h.realpath(r),a=g.resolve(r,e.sourcePath);if(B(a,r,`Source path`),g.relative(r,a).split(g.sep).some(wt))throw new z(`Workflow source path selects excluded workspace content: ${e.sourcePath}`,`source-path-mismatch`);await V(a,r,`Source path`,i);let o=await kt(r);if(o!==e.rootDigest)throw new z(`Workspace root digest mismatch: expected ${e.rootDigest}, computed ${o}`,`digest-mismatch`);try{await h.access(a)}catch{throw new z(`Workflow source file not found: ${a}`,`source-missing`)}return{workspaceRoot:r,sourcePath:a,contributionEntrypoints:await Promise.all(t.map(e=>At(e,r,i))),platform:process.platform,arch:process.arch}}var U=class{options;manifest;pool;constructor(e){this.options=e,this.manifest=e.manifest}async run(e,t,n){this.pool??=new xt(this.options);let r=n??this.manifest,i=await this.materializeTask(e,r,t);return{state:`uncommitted`,result:await this.pool.run(i,t)}}runWithReadiness(e,t,r,i){this.pool??=new xt(this.options);let a=this.pool,o,s=!1,c,u=new Promise((t,n)=>{c=n,o=a.onMessage(n=>{l(n)&&n.executionAttemptId===i.executionAttemptId&&(n.executionId!==e.executionId||n.cancelSubject!==e.cancelSubject||(s=!0,o?.(),t(n)))})}),d=r??this.manifest,f=n(i.bootstrapDeadlineAt,t,async(t,n)=>{let r=await this.materializeTask(e,d,n);return a.run({...r,kind:`attempt-bound`,executionAttemptId:i.executionAttemptId,bootstrapDeadlineAt:i.bootstrapDeadlineAt,bootstrapPort:t},n,[t])});return f.then(()=>{s||(s=!0,o?.(),c(Error(`Workflow worker completed before ready signal: ${e.executionId}`)))},e=>{s||(s=!0,o?.(),c(e instanceof Error?e:Error(String(e))))}),{result:f,ready:u}}async dispose(){await this.pool?.dispose()}async materializeTask(e,t,n){if(n.throwIfAborted(),!(e.source.kind===`path`||t.contributionRefs.length>0))return{kind:`unbound`,config:e,manifest:t,contributionEntrypoints:[]};let r=e.materializationSpec;if(r?.kind!==`local-directory`)throw Error(`ThinWorkflowPiscinaRunner requires a local-directory materialization spec for path-backed workflows or declared contributions.`);if(this.options.resolveWorkspaceRoot===void 0)throw Error(`ThinWorkflowPiscinaRunner requires a host workspace-root resolver for local-directory materialization.`);let i=await jt(r,t.contributionRefs,{resolveWorkspaceRoot:this.options.resolveWorkspaceRoot});if(n.throwIfAborted(),e.source.kind!==`path`)throw Error(`local-directory materialization requires a path-backed workflow source.`);return{kind:`unbound`,config:{...e,source:{kind:`path`,path:i.sourcePath}},manifest:t,contributionEntrypoints:i.contributionEntrypoints}}};function Mt(e){return e.mode===`source`?ie(e.moduleDir,`workflow-worker`,`worker-entry.ts`):ie(e.moduleDir,`workflow-worker`,`worker-entry.mjs`)}var Nt=class{options;terminalAuthority=`authority`;constructor(e){this.options=e}async run(e,t,n,r){let i={...e,terminalAuthority:`authority`},a=n??this.options.manifest,o=this.options.requirements,s=r?.dispatchMetadata;t.throwIfAborted();let c=e.source.kind===`path`?await this.options.readRunContext?.(e.executionId,t):void 0;t.throwIfAborted();let l=Qe({id:v(),revision:`1`,config:e,...c==null?{}:{runContext:c},preservation:{required:[]}});return et(await $e({authority:this.options.authority,executionId:e.executionId,instruction:l,withAttemptCreation:r?.withAttemptCreation,dispatch:e=>this.options.dispatch({executionAttemptId:e,config:i,...a!==void 0&&{manifest:a},...o!==void 0&&{requirements:o},...s!==void 0&&{metadata:s}},t)}),e)}},Pt=class{#e;constructor(e){this.#e=e.bus}async run(e,t,n){let i=ve.parse(e),a=await r(i);return{state:`uncommitted`,result:await tt({config:await c(i,a,this.#e,t),loaded:a,bus:this.#e,signal:t})}}};function Ft(){return{contributionRefs:[]}}function It(e){if(e.workflowRunner?.mode===`worker`&&!e.executionAttemptRepository)throw Error(`Worker dispatch mode requires an ExecutionAttemptRepository. Pass 'executionAttemptRepository' to createNodeWorkflowRunnerPackageOptions when workflowRunner.mode is 'worker'.`);let t;if(e.executionAttemptRepository){let n=e.executionAttemptBootstrapTimeoutMs;if(n===void 0)throw Error(`An ExecutionAttemptRepository requires executionAttemptBootstrapTimeoutMs`);t=new Je(e.executionAttemptRepository,{bootstrapTimeoutMs:n})}let n=ne(e.runtimeModuleDir)===`src`?`source`:`dist`,r=Lt({moduleDir:e.runtimeModuleDir,defaultWorkerEntryMode:n,runner:e.workflowRunner,bus:e.bus,authority:t});return{...r!==void 0&&{workflowRunner:r},executorConfig:{busUrl:e.busUrl,busAuth:{kind:`none`},platformDefaults:e.platformDefaults,makaioHome:e.makaioHome},...e.executionAttemptRepository!==void 0&&{executionAttemptRepository:e.executionAttemptRepository},...t!==void 0&&{executionAttemptAuthority:t},...e.workflowMaterializationSpecResolvers!==void 0&&{workflowMaterializationSpecResolvers:e.workflowMaterializationSpecResolvers}}}function Lt(e){let{runner:t}=e;if(t)switch(t.mode){case void 0:case`in-process`:if(e.bus===void 0)throw Error(`InProcessWorkflowRunner requires a bus instance. Pass 'bus' to createNodeWorkflowRunner when runner.mode is 'in-process'.`);return new Pt({bus:e.bus});case`worker`:{if(e.authority===void 0)throw Error(`WorkerRunner requires an ExecutionAttemptAuthority. Pass 'authority' to createNodeWorkflowRunner when runner.mode is 'worker'.`);let n=e.bus,r=t.dispatch??(n===void 0?void 0:(e,t)=>n.request(C.dispatch,{executionAttemptId:e.executionAttemptId,config:e.config,manifest:e.manifest,requirements:e.requirements,metadata:e.metadata},{signal:t}));if(r===void 0)throw Error(`WorkerRunner requires either a dispatch function or a bus instance. Pass 'bus' to createNodeWorkflowRunner when runner.mode is 'worker'.`);return new Nt({dispatch:r,authority:e.authority,...n!==void 0&&{readRunContext:async(e,t)=>(await n.request(Ze.getRunContext,{executionId:e},{signal:t})).runContext},...t.manifest!==void 0&&{manifest:t.manifest},...t.requirements!==void 0&&{requirements:t.requirements}})}case`piscina`:return new U({workerEntry:t.workerEntry??Mt({moduleDir:e.moduleDir,mode:t.workerEntryMode??e.defaultWorkerEntryMode}),manifest:t.manifest??Ft(),...t.resolveWorkspaceRoot!==void 0&&{resolveWorkspaceRoot:t.resolveWorkspaceRoot},maxConcurrency:t.maxConcurrency,idleTimeoutMs:t.idleTimeoutMs})}}const Rt=new Set([`accepted`,`duplicate`]);var W=class extends Error{decision;result;reason;constructor(e,t,n=`authority-rejected`){super(`Outcome delivery ${n===`deadline-exceeded`?`deadline exceeded`:`rejected by Authority`} (decision=${e}, executionId=${t.executionId}, status=${t.status})`),this.decision=e,this.result=t,this.reason=n,this.name=`OutcomeDeliveryError`}},G=class extends Error{decision;payload;reason;constructor(e,t,n=`authority-rejected`){super(`Attempt outcome delivery ${n===`deadline-exceeded`?`deadline exceeded`:`rejected by Authority`} (decision=${e}, executionAttemptId=${t.executionAttemptId}, outcome=${t.outcome.kind})`),this.decision=e,this.payload=t,this.reason=n,this.name=`AttemptOutcomeDeliveryError`}},zt=class extends Error{reason;constructor(e=`deadline-exceeded`){super(`Authority request delivery deadline exceeded`),this.reason=e,this.name=`AuthorityRequestDeliveryError`}};function Bt(e){let t={maxRetries:e?.maxRetries??7,baseDelayMs:e?.baseDelayMs??1e3,maxDelayMs:e?.maxDelayMs??3e4,deadlineMs:e?.deadlineMs??12e4};if(!Number.isSafeInteger(t.maxRetries)||t.maxRetries<0)throw TypeError(`Outcome submission maxRetries must be a non-negative safe integer, got ${t.maxRetries}`);for(let[e,n]of Object.entries({baseDelayMs:t.baseDelayMs,maxDelayMs:t.maxDelayMs,deadlineMs:t.deadlineMs}))if(!Number.isFinite(n)||n<=0)throw TypeError(`Outcome submission ${e} must be a positive finite number, got ${n}`);return t}async function Vt(e,t,n,r){let i=t.baseDelayMs*2**(e-1),a=n-Date.now(),o=Math.min(i,t.maxDelayMs,a);await new Promise(e=>setTimeout(e,o));let s=n-Date.now();if(s<=0)return!1;if(r!==void 0){let e;try{await Promise.race([r(),new Promise(t=>{e=setTimeout(t,s)})])}catch{}finally{e!==void 0&&clearTimeout(e)}}return Date.now()<n}async function Ht(e,t,n,r){let i=Bt(n?.retry),a=n?.reconnect,o=Date.now()+i.deadlineMs,s;for(let n=0;n<=i.maxRetries;n++){if(o-Date.now()<=0||n>0&&!await Vt(n,i,o,a))throw t();try{let n=o-Date.now();if(n<=0)throw t();return await e(n)}catch(e){if(r(e))throw e;if(s=e,Date.now()>=o)throw t()}}throw s??t()}async function K(e,t){return await Ht(e,()=>new zt,t,()=>!1)}async function Ut(e,t,n){return await Ht(async n=>{let r=await e(n);if(Rt.has(r))return r;throw t(r)},()=>t(`deadline-exceeded`,`deadline-exceeded`),n,e=>e instanceof W||e instanceof G)}async function Wt(e,t,n){return await Ut(async n=>(await e.request(C.control.outcome.submit,{executionAttemptId:t.executionAttemptId,executionId:t.executionId,result:t.result},{timeout:n})).decision,(e,n)=>n===void 0?new W(e,t.result):new W(e,t.result,n),n)}async function Gt(e,t,n){return await Ut(async n=>(await e.request(x.outcome.submit,t,{timeout:n})).decision,(e,n)=>n===void 0?new G(e,t):new G(e,t,n),n)}const Kt={maxRetries:3,baseDelayMs:200,maxDelayMs:2e3,deadlineMs:1e4},qt={persistentStorage:!0,customCapabilities:[`workflow.local-runtime`,`workflow.thin-runner`],suspensionStrategy:`wait-in-process`,supportsRecovery:!1,materializationModes:[`local-directory`]},Jt={code:`outcome-acknowledged`,summary:`Piscina runner settled and the Authority acknowledged its workflow outcome`},Yt={code:`outcome-delivery-ended`,summary:`Piscina runner settled and its bounded workflow outcome delivery ended`};function q(e){let t=new Set,n;return{publish:r=>{if(n!==void 0)return;let i=r();n=i;let a=[...t];t.clear();for(let t of a)try{t(i)}catch(t){console.error(`${e} observer failed:`,t)}},observe:e=>n===void 0?(t.add(e),()=>t.delete(e)):(e(n),()=>void 0)}}function Xt(e){let t=q(`[PiscinaThinWorkflowProvider] Infrastructure-conclusion`);return{conclude:n=>{t.publish(()=>({evidence:y.parse({source:e.slice(0,S.source),summary:n.slice(0,S.summary),observedAt:new Date().toISOString()})}))},observe:t.observe}}function Zt(e,t){let n=q(`[PiscinaThinWorkflowProvider] Provider-completion`),r=q(`[PiscinaThinWorkflowProvider] Local-observation-loss`),i;return{completion:{complete:r=>{i===void 0&&n.publish(()=>{let n=y.parse({source:e.slice(0,S.source),code:r.code,summary:r.summary,observedAt:new Date().toISOString()});return t(),i=`completion`,n})},observe:n.observe},localObservationLoss:{lose:()=>{i===void 0&&r.publish(()=>(i=`local-observation-loss`,{}))},observe:e=>r.observe(()=>e())}}}var Qt=class{executionAttemptId;controller;detachCallerAbort;infrastructure;completion;localObservationLoss;revokeBusIdentity;constructor(e,t,n,r,i,a,o){this.executionAttemptId=e,this.controller=t,this.detachCallerAbort=n,this.infrastructure=r,this.completion=i,this.localObservationLoss=a,this.revokeBusIdentity=o}cancel(e){return this.controller.abort(e??`Worker cancelled`),this.detachCallerAbort(),Promise.resolve()}terminate(){return this.controller.abort(`Worker terminated`),this.detachCallerAbort(),this.revokeBusIdentity(),Promise.resolve()}release(){return this.detachCallerAbort(),Promise.resolve()}observeInfrastructureConclusion(e){return this.infrastructure.observe(e)}observeProviderCompletion(e){return this.completion.observe(e)}observeLocalObservationLoss(e){return this.localObservationLoss.observe(e)}},$t=class{options;environment=`piscina`;allocationLifetime=`provisioner-process-bound`;baseCapabilities;constructor(e){this.options=e,this.baseCapabilities=me.parse({...qt,...e.baseCapabilities,suspensionStrategy:e.baseCapabilities?.suspensionStrategy??qt.suspensionStrategy,supportsRecovery:!1})}get id(){return this.options.id}get displayName(){return this.options.displayName}async provision(e,t){t.throwIfAborted();let n=await this.resolveLaunchBeforeAllocation(e,t);if(t.throwIfAborted(),`kind`in n)return n;let r=n,i=new AbortController,a=Xt(this.id),o=()=>{i.abort(t.reason)};t.addEventListener(`abort`,o,{once:!0});let s=()=>t.removeEventListener(`abort`,o),c;try{let{executionAttemptId:n,executionId:o}=e,l=this.buildAllocationRef(n),u=d({executionAttemptId:n,executionId:o}),f=!1,p=()=>{f||(f=!0,u.cleanup())};c=p;let m=Zt(this.id,p),ee=new Qt(n,i,s,a,m.completion,m.localObservationLoss,p);t.throwIfAborted();let h=this.options.runner.runWithReadiness({...r,busAuth:{kind:`hmac`,secret:u.secret}},i.signal,e.runtimeInputs.workerManifest,{executionAttemptId:n,bootstrapDeadlineAt:e.bootstrapDeadlineAt});return h.ready.then(()=>this.submitOutcomeOnSettlement(h.result,o,n,r.workflowId,a.conclude,m.completion.complete),e=>{i.abort(e),h.result.catch(()=>void 0),c?.(),a.conclude(`Piscina worker for attempt '${n}' was refused before its workflow run was admitted: `+(e instanceof Error?e.message:String(e))),m.localObservationLoss.lose()}),{kind:`allocated`,allocationRef:l,handle:ee}}catch(e){throw i.abort(e),s(),c?.(),e}}async resolveLaunchBeforeAllocation(e,t){try{let n=await this.options.launchResolver(e,t);return t.throwIfAborted(),n.busUrl?n:this.confirmedAbsent(`Piscina workflow configuration has no bus URL before local allocation setup`)}catch{return t.throwIfAborted(),this.confirmedAbsent(`Workflow launch resolution failed before Piscina local allocation setup`)}}confirmedAbsent(e){return{kind:`confirmed-absent`,evidence:y.parse({source:`piscina-thin-workflow-provider`,code:de,summary:e,observedAt:new Date().toISOString()})}}async submitOutcomeOnSettlement(e,t,n,r,i,a){let o;try{o=await e}catch(e){o={executionId:t,workflowId:r,status:`failed`,error:e instanceof Error?e.message:String(e)}}try{let e={...Kt,...this.options.outcomeRetry};await Wt(this.options.bus,{executionAttemptId:n,executionId:t,result:o},{retry:e})}catch(e){e instanceof W?console.error(`[PiscinaThinWorkflowProvider] Outcome rejected for execution '${t}' attempt '${n}' (decision=${e.decision}):`,e):console.error(`[PiscinaThinWorkflowProvider] Failed to submit outcome for execution '${t}' attempt '${n}':`,e),i(`Piscina worker for attempt '${n}' ended without an acknowledged outcome because outcome submission could not be completed`),a(Yt);return}a(Jt)}buildAllocationRef(e){let t={version:fe,providerId:this.id,providerData:{executionAttemptId:e,allocatedAt:Date.now()}};return pe.parse(t)}};function en(e){return async(t,n)=>{n.throwIfAborted();let r=await e({executionId:t.executionId,executionAttemptId:t.executionAttemptId});if(n.throwIfAborted(),r===null)throw Error(`Workflow launch instruction is unavailable for execution '${t.executionId}' attempt '${t.executionAttemptId}'`);let i=k(r);if(i.executionId!==t.executionId)throw Error(`Workflow instruction execution '${i.executionId}' does not match Worker request '${t.executionId}'`);return ve.parse({source:i.source,...i.definitionSnapshot===void 0?{}:{definition:i.definitionSnapshot},executionId:i.executionId,workflowId:i.workflowId,triggerPayload:i.triggerPayload,...i.triggerMode===void 0?{}:{triggerMode:i.triggerMode},inputs:i.inputs,...i.config===void 0?{}:{config:i.config},...i.artifactRef===void 0?{}:{artifactRef:i.artifactRef},scope:i.scope,...t.connection.busUrl===void 0?{}:{busUrl:t.connection.busUrl},busAuth:t.connection.busAuth,...t.connection.env===void 0?{}:{env:t.connection.env},coordinatorSessionId:i.coordinatorSessionId,cancelSubject:i.cancelSubject,suspensionStrategy:t.runtimeInputs.suspensionStrategy,terminalAuthority:i.terminalAuthority,...i.materializationSpec===void 0?{}:{materializationSpec:i.materializationSpec}})}}const tn=[ze,Ie,Re];function nn(e){let t;return()=>(t??=(async()=>{let t=[];for(let n of[...e].reverse())try{await n()}catch(e){t.push(e)}if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Isolated workflow runtime shutdown reported errors`)})(),t)}function rn(e,t,n){return M({bus:e,currentMachineId:n,resolveLiveAdapterId:e=>t.getExtensionService(O)?.resolveLiveAdapterId(e),resolveLiveAdapterIdentity:e=>t.getExtensionService(O)?.resolveLiveAdapterIdentity(e),listLiveAdapterIdentities:()=>t.getExtensionService(O)?.getLiveAdapterIdentities()??[]})}async function an(e){let t=w();t.registerNamespaces([...ce,...le]);let{context:n}=e,r=new Se(t,{surface:`headless`,extensionContextBase:{cwd:n.cwd,platform:n.platform,homedir:n.homedir,makaioHome:n.makaioHome,username:n.username,machineId:n.machineId,tryImport:P}}),i,a=[()=>t.disconnect()],o=nn(a);try{await e.connectAuthority(t);let s=[...e.contributedPackages,...await e.loadContributedPackages?.(t)??[]],{adapterSubsystemPackage:c}=j({coordinator:r,configRepository:e.configRepository,platformDefaults:{cwd:n.cwd},runtimeSnapshotHandlerPriority:1,runtimeDefinitionHandlerPriority:1,...e.prepareAuthRuntime!==void 0&&{prepareAuthRuntime:e.prepareAuthRuntime}}),l=He({definitions:s.flatMap(e=>e.clients??[]),binaryResolutionPolicy:`global-only`});r.registerContributionProcessor(Fe());let u=[...tn,c,Ne,..._t(s)?[Le]:[],Pe(1),Be,L,l,...Ge(s)];r.load(u),a.push(...yt(u,t,r)),a.push(()=>r.shutdown()),await r.startAll(),i=rn(t,r,n.machineId),a.push(()=>{i?.cleanup(),i=void 0});let d=r.getExtensionService(Me);if(d===void 0)throw Error(`Isolated workflow tool registry did not start.`);for(let t of e.toolsets)await d.register(t);return await t.emit(Ce.ready,{machineId:n.machineId}),{bus:t,coordinator:r,machineId:n.machineId,shutdown:o}}catch(e){throw await o().catch(()=>void 0),e}}function on(e){return Number.isInteger(e)&&e>=1&&e<=2147483647}function J(e,t){try{return process.kill(-e,t),`signalled`}catch(e){if(e.code!==`ESRCH`)throw e;return`absent`}}function sn(e){return typeof e==`object`&&!!e&&e.code===`ENOENT`}async function cn(e,t,n){try{process.kill(-e,0)}catch(e){if(e.code===`ESRCH`)return{alive:!1};if(e.code!==`EPERM`)throw e}if(n)return{alive:!0};let r;try{r=await ln(t)}catch(e){return sn(e)?{alive:!0,psMissing:!0}:{alive:!0}}let i=!1;for(let t of r.trim().split(`
2
+ `)){let[n,r,a]=t.trim().split(/\s+/);if(n===``||r===void 0||a!==void 0||!/^\d+$/.test(n)||r===``||Number(n)===e&&(i=!0,!r.startsWith(`Z`)))return{alive:!0}}return i?{alive:!1}:{alive:!0}}function ln(e){return new Promise((t,n)=>{p(`ps`,[`-A`,`-o`,`pgid=,stat=`],{timeout:e,maxBuffer:1024*1024},(e,r)=>{if(e!==null){n(e);return}t(r)})})}async function un(e){if(e===void 0)return{quiesced:!0,signalledLiveGroup:!1};let t=!1;try{try{t=J(e,`SIGKILL`)===`signalled`}catch(e){if(e.code!==`EPERM`)throw e}let n=Date.now()+2e3,r=!1;for(;Date.now()<n;){let i=n-Date.now();if(i<=0)break;let a=await cn(e,Math.min(1e3,i),r);if(!a.alive)return{quiesced:!0,signalledLiveGroup:t};r||=a.psMissing===!0,await nt(20)}return{quiesced:!1,cause:r?`ps-unavailable`:`poll-timeout`,signalledLiveGroup:t}}catch{return{quiesced:!1,cause:`signal-error`,signalledLiveGroup:t}}}function dn(e,t,n){let r=new Date;return n.quiesced?t||n.signalledLiveGroup?{pid:e,outcome:`signalled-and-quiesced`,observedAt:r}:{pid:e,outcome:`exited`,observedAt:r}:{pid:e,outcome:t||n.signalledLiveGroup?`signalled-unconfirmed`:`unsignalled-unconfirmed`,cause:n.cause,observedAt:r}}async function fn(e){if(e.signal?.aborted)return{status:`cancelled`,exitCode:null};if(!on(e.recipe.timeoutMs))return{status:`spawn-failed`,exitCode:null,message:`Setup timeout must be an integer between 1 and 2147483647 milliseconds`};if(process.platform===`win32`)return{status:`spawn-failed`,exitCode:null,message:`Setup process groups require a POSIX host`};try{return await pn(e)}catch{return{status:`spawn-failed`,exitCode:null,message:`Could not start the setup command`}}}function pn(e){return new Promise(t=>{let n=m(e.recipe.command,e.recipe.args,{cwd:e.workspaceRoot,env:{...process.env,...e.recipe.env,...e.env},shell:!1,detached:!0,stdio:`ignore`}),r,i,a=!1,o=e=>{if(r===void 0&&(r=e,n.pid!==void 0)){try{J(n.pid,`SIGTERM`)===`signalled`&&(a=!0)}catch(e){if(e.code!==`EPERM`){r=`stop-failed`;return}}i=setTimeout(()=>{try{n.pid!==void 0&&J(n.pid,`SIGKILL`)===`signalled`&&(a=!0)}catch(e){e.code!==`EPERM`&&(r=`stop-failed`)}},200)}},s=()=>o(`cancelled`),c=setTimeout(()=>o(`timed-out`),e.recipe.timeoutMs);e.signal?.addEventListener(`abort`,s,{once:!0}),e.signal?.aborted&&s(),n.once(`error`,()=>{r=`spawn-failed`}),n.once(`close`,o=>{clearTimeout(c),clearTimeout(i),e.signal?.removeEventListener(`abort`,s),un(n.pid).then(e=>{t({status:e.quiesced?r??(o===0?`completed`:`failed`):`stop-failed`,exitCode:o,processGroup:n.pid===void 0?void 0:dn(n.pid,a,e)})})})})}async function mn(e,t,n){if(g.isAbsolute(t)||t.includes(`\\`)||t.split(`/`).includes(`..`))throw Error(`Source root must be workspace-relative`);let r=e;for(let i of t.split(`/`).filter(e=>e!==``&&e!==`.`))if(r=g.join(r,i),B(r,e,`Source root`),await V(r,e,`Source root`,e),n&&await h.mkdir(r).catch(e=>{if(e.code!==`EEXIST`)throw e}),!(await h.stat(r)).isDirectory())throw Error(`Source root must be a directory`);return V(r,e,`Source root`,e)}async function hn(e){e.signal?.throwIfAborted();let{requirement:t}=e,n=g.resolve(e.workspaceRoot);if(!g.isAbsolute(e.workspaceRoot)||n===g.parse(n).root)throw Error(`Workspace root must be an absolute, non-filesystem-root directory`);if(t.sourceRoots.length>1)throw Error(`Multiple source roots are not implemented`);if(t.sourceRoots.some(e=>e.source!==void 0)){if(e.realizeSource===void 0)throw Error(`Source acquisition requires an installed strategy`);if(t.provisioning!==`create`||t.custody!==`disposable`)throw Error(`Source acquisition currently requires a created disposable workspace`)}if(t.provisioning===`create`&&await h.mkdir(n),!(await h.lstat(n)).isDirectory())throw Error(`Workspace root must be a directory, not a symlink`);let r=await h.realpath(n),i=[];for(let n of t.sourceRoots){let a=await mn(r,n.path,t.provisioning===`create`);n.source!==void 0&&(await e.realizeSource({source:n.source,destination:a,signal:e.signal}),e.signal?.throwIfAborted()),i.push({id:n.id,path:a})}return gn(t,{workspaceRoot:r,sourceRoots:i})}function gn(e,t){let n=t.workspaceRoot,r=e.custody,i=!1,a=!0,o;return{binding:t,async runSetup(t={}){if(o!==void 0||i||!a)throw Error(`Workspace setup is unavailable`);if(t.signal?.aborted)return{status:`cancelled`,exitCode:null};i=!0;try{let r;for(let[i,o]of e.setup.entries()){let e=await fn({...t,recipe:o,workspaceRoot:n});if(r=e,a=e.status!==`stop-failed`,e.status!==`completed`)return{...e,commandIndex:i}}let i=r?.processGroup;return i===void 0?{status:`completed`,exitCode:0}:{status:`completed`,exitCode:0,processGroup:i}}finally{i=!1}},release(){return i||!a?Promise.reject(Error(`Workspace commands have not stopped`)):(o??=r===`external`?Promise.resolve():h.rm(n,{recursive:!0,force:!0}),o)}}}function Y(e,t){return e instanceof be?T(e,t):t?.aborted===!0?e===t.reason||e instanceof DOMException&&e.name===`AbortError`?!0:e instanceof Error&&e.name===`AbortError`&&`code`in e&&e.code===`ABORT_ERR`&&Object.is(e.cause,t.reason):!1}function X(e){return(e instanceof Error?e.message:String(e)).slice(0,8192)||`Local execution failed without a diagnostic message`}function _n(e){if(e.status!==`completed`)return e.status===`cancelled`?{kind:`cancelled`}:e.status===`stop-failed`?{kind:`technical-failure`,stage:`workspace-preparation`,message:`Workspace setup stop-failed`}:{kind:`technical-failure`,stage:`workspace-preparation`,message:`Workspace setup ${e.status}`}}function vn(e,t){return Y(e,t)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`workspace-preparation`,message:X(e)}}async function yn(e,t,n,r){let i=b[`instruction.get`].response.parse(await e.request(x.instruction.get,{executionAttemptId:t,runtimeGeneration:n},{signal:r}));if(i.decision===`found`)return i.instruction;throw Error(`Attempt instruction read refused: ${i.refusalReason}`)}async function bn(e,t,n,r){let{executionAttemptId:i,runtimeGeneration:a}=t;t.control?.admissionPending();let o=b[`operation.admit`].response.parse(await K(async t=>await e.request(x.operation.admit,{executionAttemptId:i,runtimeGeneration:a,operationKind:n,admissionKey:r},{timeout:t}),{retry:t.retry,reconnect:t.reconnect}));if(o.decision===`refused`)throw t.control?.admissionSettled(o.refusalReason),new s(t.executionAttemptId,r,o.refusalReason);if(o.operationId===void 0)throw Error(`Attempt ${n} admission decision '${o.decision}' named no operation (executionAttemptId=${i}, admissionKey=${r})`);return t.control?.operationAdmitted(n,o.operationId),o.operationId}async function xn(e,t,n){try{return{operationId:await bn(e,t,n.operationKind,n.admissionKey)}}catch(r){if(!(r instanceof s&&r.refusalReason===`gate-closed`&&n.signal.aborted))throw r;return await Z(e,t,n.instruction,{kind:`cancelled`},void 0,n.workspace)}}function Sn(e,t){return e.find(e=>e.kind===t.workload.kind&&e.version===t.workload.version)}function Cn(e){return{signal:e??new AbortController().signal,release:()=>{}}}async function Z(e,t,n,r,i,a){i!==void 0&&t.control?.operationConcluded(i);let o=await Gt(e,{executionAttemptId:t.executionAttemptId,runtimeGeneration:t.runtimeGeneration,...i===void 0?{}:{operationId:i.operationId},outcome:r},{retry:t.retry,reconnect:t.reconnect});if(a!==void 0&&n!==void 0&&r.kind===`workload-result`&&n.preservation.required.length===0)try{await a.release()}catch{console.warn(`[makaio-worker] Acknowledged workspace cleanup failed.`)}return{outcome:r,decision:o}}async function wn(e,t,n,r){let i=b[`operation.report`].response.parse(await K(async i=>await e.request(x.operation.report,{executionAttemptId:t.executionAttemptId,runtimeGeneration:t.runtimeGeneration,operationId:n,result:{kind:`workspace-prepared`,binding:r.binding}},{timeout:i}),{retry:t.retry,reconnect:t.reconnect}));return i.decision===`refused`?void 0:i.binding}async function Tn(e,t,n,r){if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,void 0);let i=await xn(e,t,{operationKind:`workspace-preparation`,admissionKey:`workspace-preparation:${n.id}:${t.runtimeGeneration}`,signal:r,instruction:n});if(`outcome`in i)return i;let a=i.operationId;if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},Q(a,`not-started`),void 0);let o,s,c=!1;try{if(t.workspaceRoot===void 0)throw Error(`Workspace preparation requires an explicit local root`);let e=await(t.preparation??{prepare:hn}).prepare({requirement:n.workspace,workspaceRoot:t.workspaceRoot,signal:r});o=e,c=!0,s=await e.runSetup({signal:r,env:t.setupEnv})}catch(i){return await Z(e,t,n,vn(i,r),Q(a,c?`no-observation`:`not-started`),o)}let l=Q(a,s.processGroup??`no-spawn`);t.control?.operationConcluded(l);let u=_n(s);if(u!==void 0)return await Z(e,t,n,u,l,o);if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},l,o);let d=await wn(e,t,a,o);return d===void 0?await Z(e,t,n,{kind:`technical-failure`,stage:`workspace-preparation`,message:`Workspace preparation report refused by the Authority`},l,o):r.aborted?await Z(e,t,n,{kind:`cancelled`},void 0,o):{handle:o,binding:d}}function Q(e,t){return{kind:`workspace-preparation`,operationId:e,setup:t}}async function En(e,t,n,r,i){if(i.signal.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,void 0);let a,o;if(n.workspace!==void 0){let r=await Tn(e,t,n,i.signal);if(`outcome`in r)return r;a=r.handle,o=r.binding}if(i.signal.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,a);let s=await xn(e,t,{operationKind:`workload-invocation`,admissionKey:`workload-invocation:${n.id}:${t.runtimeGeneration}`,signal:i.signal,instruction:n,...a===void 0?{}:{workspace:a}});if(`outcome`in s)return s;let c={kind:`workload-invocation`,operationId:s.operationId};if(i.signal.aborted)return await Z(e,t,n,{kind:`cancelled`},c,a);let l;try{l={kind:`workload-result`,result:ue.parse(await r.invoke({instruction:n,...o===void 0?{}:{workspace:o},signal:i.signal}))}}catch(e){l=Y(e,i.signal)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`workload-invocation`,message:X(e)}}return await Z(e,t,n,l,c,a)}async function Dn(e,t){let n;try{n=await yn(e,t.executionAttemptId,t.runtimeGeneration,t.signal)}catch(n){if(T(n,t.signal))return await Z(e,t,void 0,{kind:`cancelled`},void 0,void 0);throw n}let r=Sn(t.adapters,n);if(r===void 0)return await Z(e,t,n,{kind:`technical-failure`,stage:`startup`,message:`Required adapter '${n.workload.kind}' version '${n.workload.version}' is unavailable`},void 0,void 0);let i;try{i=await(r.bindControl?.({instruction:n,signal:t.signal})??Cn(t.signal))}catch(r){let i=Y(r,t.signal)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`startup`,message:X(r)};return await Z(e,t,n,i,void 0,void 0)}try{return await En(e,t,n,r,i)}finally{try{i.release()}catch{console.warn(`[makaio-worker] Workload control release failed.`)}}}async function On(e,t,n,r,i){let a=he[`runtime.inputs.get`].response.parse(await e.request(C.runtime.inputs.get,{executionAttemptId:t},{signal:i}));if(a.runtimeInputs===null)throw Error(`Selected Worker Runtime inputs are unavailable`);return ge.parse({...n,...a.runtimeInputs,createdAt:0,env:r})}function kn(e,t){let n=(e,t)=>{let n=ae(e,t);return n===``||!re(n)&&n!==`..`&&!n.startsWith(`../`)&&!n.startsWith(`..\\`)};return n(e,t)||n(t,e)}async function An(t,n,r,i){let a=await t.loadContributions(r,i);i.throwIfAborted();let o=e();return await an({connectAuthority:e=>t.connectBus(e,n,i),contributedPackages:[...a],configRepository:t.configRepository,context:{cwd:r.workspaceRoot,platform:r.platform,homedir:o,makaioHome:o,username:`workflow-worker`,machineId:`headless-worker-${t.executionAttemptId}`},toolsets:[...t.toolsets],...t.prepareAuthRuntime!==void 0&&{prepareAuthRuntime:t.prepareAuthRuntime}})}function jn(e,t,n){let r={...e.workflowEnv},i,a=!0;return{adapter:{kind:Ye,version:Xe,async bindControl({instruction:t,signal:r}){let i=k(t);if(i.executionId!==e.executionId)throw Error(`Workflow instruction execution identity mismatch`);let a=new AbortController,o=n.on(ye(i.cancelSubject),()=>a.abort());try{return await xe(o),{signal:AbortSignal.any([...r===void 0?[]:[r],a.signal]),release:o}}catch(e){throw o(),e}},async invoke({instruction:o,workspace:s,signal:c}){let l=k(o);a=o.preservation.required.length!==0;let u=c??new AbortController().signal,d;try{u.throwIfAborted();let a=await On(n,e.executionAttemptId,l,r,u),o=await e.materialize(a,u);(s===void 0||!kn(o.context.workspaceRoot,s.workspaceRoot))&&(i=o.cleanup);let c=Mn(o.context,s);return u.throwIfAborted(),d=await An(e,t,c,u),u.throwIfAborted(),await e.execute(d.bus,a,c,u)}finally{await d?.shutdown()}}},async releaseExecutable(e){e===void 0||a||e.outcome.kind===`workload-result`&&(e.decision!==`accepted`&&e.decision!==`duplicate`||await i?.().catch(()=>void 0))}}}function Mn(e,t){return t===void 0?e:{...e,workspaceRoot:t.workspaceRoot}}const Nn={exited:`setup process group leader exited; whole group proven quiescent`,"signalled-and-quiesced":`setup process group signalled; group proven quiescent afterwards`,"signalled-unconfirmed":`setup process group signalled; quiescence not proven`,"unsignalled-unconfirmed":`setup process group could not be signalled; quiescence not proven`},Pn={"poll-timeout":`quiescence poll timed out`,"ps-unavailable":`ps unavailable on this host`,"signal-error":`a cleanup signal failed`};function Fn(e){let t=Nn[e.outcome];return e.cause===void 0?t:`${t} (${Pn[e.cause]})`}function $(e){return{...e.operationId===void 0?{}:{operationId:e.operationId},conclusion:{status:e.status,boundary:e.boundary,evidence:{source:e.source,summary:e.summary,observedAt:e.observedAt.toISOString(),...e.code===void 0?{}:{code:e.code}}}}}function In(e,t){if(!e.cancelReceived||e.admissionPending)return`pending`;let n=e.admittedOperation;if(n===null)return!e.admissionSettled&&!e.finished?`pending`:$({status:`achieved`,boundary:`admission-closed`,source:`headless-runtime`,summary:Ln(e.admissionRefusalReason),observedAt:t});if(n.kind===`workload-invocation`)return $({operationId:n.operationId,status:`unsupported`,boundary:`workload`,source:`headless-runtime`,summary:`generic workload adapter offers no stop evidence`,observedAt:t});let r=e.conclusion;return r===null||r.kind!==`workspace-preparation`||r.operationId!==n.operationId?`pending`:Rn(n.operationId,r.setup,t)}function Ln(e){let t=`no mutating operation admitted before cancellation`;return e===null?t:`${t}; admission refused (${e})`}function Rn(e,t,n){return $(t===`not-started`?{operationId:e,status:`achieved`,boundary:`setup-process-group`,source:`headless-runtime`,summary:`preparation admitted; setup never started before cancellation`,observedAt:n}:t===`no-spawn`?{operationId:e,status:`achieved`,boundary:`setup-process-group`,source:`setup-driver`,summary:`no live setup process group remains under this operation`,observedAt:n}:t===`no-observation`?{operationId:e,status:`unsupported`,boundary:`setup-process-group`,source:`setup-driver`,summary:`setup driver supplied no process-group observation`,observedAt:n}:{operationId:e,status:t.outcome===`signalled-unconfirmed`||t.outcome===`unsignalled-unconfirmed`?`unconfirmed`:`achieved`,boundary:`setup-process-group`,source:`setup-driver`,summary:Fn(t),observedAt:t.observedAt,code:t.outcome})}var zn=class{state={cancelReceived:!1,admissionPending:!1,admissionSettled:!1,admissionRefusalReason:null,admittedOperation:null,conclusion:null,finished:!1};onUpdate;constructor(e){this.onUpdate=e}markCancelReceived(){this.state.cancelReceived=!0,this.onUpdate()}admissionPending(){this.state.admissionPending=!0,this.onUpdate()}admissionSettled(e){this.state.admissionPending=!1,this.state.admissionSettled=!0,e!==void 0&&(this.state.admissionRefusalReason=e),this.onUpdate()}operationAdmitted(e,t){this.state.admissionPending=!1,this.state.admittedOperation={kind:e,operationId:t},this.onUpdate()}operationConcluded(e){this.state.conclusion=e,this.onUpdate()}finished(){this.state.finished=!0,this.onUpdate()}snapshot(){return{...this.state}}};function Bn(e){return!e.reportPending&&(e.lastReportStatus===void 0||e.lastReportStatus===`error`)}function Vn(e,t){return{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:e.runtimeIncarnationId,runtimeGeneration:e.runtimeGeneration,controlRevision:e.cancellation.controlRevision,requestKey:e.cancellation.requestKey,receivedAt:t.toISOString()}}async function Hn(e,t,n,r){let i={executionAttemptId:t.executionAttemptId,runtimeIncarnationId:t.runtimeIncarnationId,runtimeGeneration:t.runtimeGeneration,controlRevision:t.controlRevision,requestKey:t.requestKey,...n.operationId===void 0?{}:{operationId:n.operationId},conclusion:n.conclusion};try{let t=await K(t=>e.request(x.control.report,i,{timeout:t}),r),n=b[`control.report`].response.parse(t);return n.decision===`accepted`||n.decision===`duplicate`?{status:n.decision,response:n}:{status:`refused`,response:n}}catch(e){return{status:`error`,error:e}}}function Un(e,t){let n=new Set,r;return{dispatch(i,a,o){let s=Hn(e,i,a,t).then(e=>{r=e,n.delete(s),o(e)});n.add(s)},async settle(){for(await new Promise(e=>setImmediate(e));n.size>0;)await Promise.allSettled([...n])},get lastReport(){return r}}}async function Wn(e,t,n={}){let r=n.now??(()=>new Date),i=new Map,a=new AbortController,s=Un(e,n.reportOptions);function c(e){if(!Bn(e))return;let t=In(u.snapshot(),r());t!==`pending`&&(e.reportPending=!0,s.dispatch(e.receipt,t,t=>{e.reportPending=!1,e.lastReportStatus=t.status}))}function l(e){let{controlRevision:t}=e.cancellation,n=i.get(t);if(n!==void 0)return setImmediate(()=>c(n)),n.receipt;let o={receipt:Vn(e,r()),reportPending:!1,lastReportStatus:void 0};return i.set(t,o),setImmediate(()=>{a.abort(),u.markCancelReceived(),c(o)}),o.receipt}let u=new zn(()=>{for(let e of i.values())c(e)}),d=await o(e,t,e=>e.bus.on(x.control.deliver,async t=>{let n=b[`control.deliver`].request.safeParse(t.payload);if(!n.success){t.setResult({decision:`refused`,reason:`unsupported`});return}let r=n.data,i=e.acceptedGeneration??await e.awaitGeneration();if(i===void 0||r.runtimeGeneration!==i){t.setResult({decision:`refused`,reason:`stale-generation`});return}t.setResult({decision:`received`,receipt:l(r)})}),n.signal);return{bindGeneration:e=>d.bindGeneration(e),cleanup:()=>d.cleanup(),signal:a.signal,observer:u,settle:()=>s.settle(),get lastReport(){return s.lastReport}}}async function Gn(e,t){if(!(t.outcome.kind!==`workload-result`||e.onPostCommit===void 0))try{let n=_e.parse(t.outcome.result);await e.onPostCommit(n,t.decision)}catch{}}async function Kn(e,t){t.throwIfAborted();let n={...e.workflowEnv},r=v(),o=await u(e.bootstrapDeadlineAt,t,t=>e.bootstrap(t)),{connection:s,endpoint:c}=await a({executionAttemptId:e.executionAttemptId,runtimeIncarnationId:r,bootstrapDeadlineAt:e.bootstrapDeadlineAt,signal:t,createConnection:()=>qn(e,o)}),l=s.bus,d=jn({...e,workflowEnv:n},o,l),f,p;try{p=await Wn(l,{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:r},{reportOptions:{retry:e.outcomeRetry,reconnect:()=>l.reconnect()},signal:t});let n=await i(l,{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:r,signal:t});return c.bindGeneration(n),p.bindGeneration(n),f=await Dn(l,{executionAttemptId:e.executionAttemptId,runtimeGeneration:n,workspaceRoot:e.workspaceRoot,setupEnv:e.setupEnv,preparation:e.preparation,adapters:[d.adapter],signal:AbortSignal.any([t,p.signal]),control:p.observer,retry:e.outcomeRetry,reconnect:()=>l.reconnect()}),await Gn(e,f),f}finally{try{await d.releaseExecutable(f)}finally{p?.observer.finished(),p?.cleanup(),await p?.settle(),c.cleanup(),await s.close()}}}function qn(e,t){let n=w();return n.registerNamespaces([...ce,...le]),{bus:n,async connect(r){try{await e.connectBus(n,t,r),r.throwIfAborted()}catch(e){throw n.disconnect(),e}},close:()=>n.disconnect()}}const Jn=ee(p),Yn=[`-c`,`core.attributesFile=${E}`],Xn=f.object({repositoryId:f.string().min(1),revision:f.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i,`Git source revision must be a full commit object ID`)}).strict();async function Zn(e,t,n){try{let r=await e.resolveRepository(t,n);if(!g.isAbsolute(r))throw Error(`Repository access did not return an absolute path`);return await h.realpath(r)}catch(e){throw Y(e,n)?e:Error(`Git source access failed`)}}async function Qn(e,t,n,r,i){let a;try{a=(await Jn(`git`,[...Yn,`cat-file`,`-t`,t],{cwd:e,env:{...process.env,...n},signal:i,timeout:r,maxBuffer:1024,shell:!1,killSignal:`SIGKILL`,encoding:`utf8`})).stdout.trim()}catch(e){throw Y(e,i)?e:Error(`Git source object inspection failed`)}if(a!==`commit`)throw Error(`Git source revision must identify a commit object`)}function $n(e){if(!on(e.timeoutMs))throw Error(`Git command timeout must be an integer between 1 and 2147483647 milliseconds`);if(process.platform===`win32`)throw Error(`Local Git source preparation requires a POSIX host`);return async({source:t,destination:n,signal:r})=>{if(r?.throwIfAborted(),t.kind!==`git`)throw Error(`Unsupported local Git source kind`);let i=Xn.parse(t.input),a=await Zn(e,i.repositoryId,r);r?.throwIfAborted();let o={...Object.fromEntries(Object.keys(process.env).filter(e=>/^git_/i.test(e)).map(e=>[e,void 0])),GIT_CONFIG_GLOBAL:E,GIT_CONFIG_SYSTEM:E,GIT_ATTR_NOSYSTEM:`1`},s=[[`init`,`--object-format=${i.revision.length===64?`sha256`:`sha1`}`],[`fetch`,`--no-tags`,`--no-write-fetch-head`,`--update-shallow`,`--`,a,i.revision],[`checkout`,`--detach`,i.revision,`--`]];for(let t of s){t[0]===`checkout`&&await Qn(n,i.revision,o,e.timeoutMs,r);let a=await fn({workspaceRoot:n,signal:r,env:o,recipe:{command:`git`,args:[...Yn,...t],env:{},timeoutMs:e.timeoutMs}});if(a.status===`cancelled`&&r?.throwIfAborted(),a.status!==`completed`)throw Error(`Git source ${t[0]} ${a.status}`)}}}function er(e){let t=$n(e);return{prepare:e=>hn({...e,realizeSource:t})}}export{R as A,M as B,Ot as C,St as D,jt as E,pt as F,A as H,vt as I,L,bt as M,yt as N,At as O,ft as P,N as R,V as S,Ct as T,j as V,Nt as _,an as a,z as b,G as c,W as d,Gt as f,Pt as g,It as h,Dn as i,dt as j,ut as k,zt as l,Lt as m,Kn as n,en as o,Wt as p,Wn as r,$t as s,er as t,Rt as u,Mt as v,kt as w,B as x,U as y,P as z};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makaio/framework",
3
- "version": "1.0.0-dev-1789034250920",
3
+ "version": "1.0.0-dev-1789056039016",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/makaio-ai/makaio-framework.git",
@@ -1 +0,0 @@
1
- import{pathToFileURL as e}from"node:url";import{mkdir as t,rm as n,writeFile as r}from"node:fs/promises";import{basename as i,join as a}from"node:path";import{randomBytes as o}from"node:crypto";import{ExecutionAttemptBootstrapAwaitStartResponseSchema as s,ExecutionAttemptSchemas as c,ExecutionAttemptSubjects as l,WorkflowDefinitionSchema as u,WorkflowError as d,WorkflowErrorCode as f}from"@makaio/framework/contracts";import{ConnectionLostError as p,TimeoutError as m,waitForSubscriptionPropagation as h}from"@makaio/framework/bus";import{HmacAuth as g,WebSocketConnectionError as _}from"@makaio/framework/node/transports";import{tmpdir as ee}from"node:os";import{AUTOMATION_TRIGGER_BUILTINS_OWNER as te,AutomationTriggerBindingRuntime as v,busBackedAutomationTriggers as y}from"@makaio/framework/services/automation-trigger";import{MessageChannel as ne}from"node:worker_threads";import{WorkerBootstrapDeadlineAtSchema as re}from"@makaio/framework/contracts/worker";import{assertWorkflowTriggerPayload as b,compileWorkflowTriggerBindingFilter as x}from"@makaio/framework/workflow-engine/workflow-trigger-binding-consumer";function S(e,t,n){return{type:`makaio.workflow-worker.ready`,executionId:e,cancelSubject:t,executionAttemptId:n}}function C(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`makaio.workflow-worker.ready`&&typeof t.executionId==`string`&&typeof t.cancelSubject==`string`&&typeof t.executionAttemptId==`string`}var w=class extends Error{code=`WORKER_BOOTSTRAP_DEADLINE_EXCEEDED`;constructor(){super(`Worker bootstrap deadline exceeded`),this.name=`BootstrapDeadlineExceededError`}};function T(e,t){if(!re.safeParse(e).success)throw TypeError(`bootstrapDeadlineAt must be a valid absolute ISO timestamp`);let n={deadline:Date.parse(e),signal:t};return D(n),n}function E(e,t,n){let r=T(e,t);return O(r,r.deadline-Date.now(),n)}function D(e){if(e.signal.throwIfAborted(),Date.now()>=e.deadline)throw new w}async function O(e,t,n){D(e);let r=Math.min(t,e.deadline-Date.now()),i=Date.now()+r,a=new AbortController,o,s=()=>{},c=new Promise((t,n)=>{s=()=>{a.abort(e.signal.reason),n(e.signal.reason)},e.signal.addEventListener(`abort`,s,{once:!0});let c=()=>{let t=i-Date.now();if(t>0){o=setTimeout(c,Math.min(t,2147483647));return}let s=Date.now()>=e.deadline?new w:new m(`worker bootstrap`,r);a.abort(s),n(s)};o=setTimeout(c,Math.min(r,2147483647))});try{let t=Promise.resolve().then(()=>(D(e),n(a.signal,r))),o=await Promise.race([c,t]);if(D(e),Date.now()>=i)throw new m(`worker bootstrap`,r);return o}catch(t){throw a.abort(t),D(e),t}finally{clearTimeout(o),e.signal.removeEventListener(`abort`,s)}}async function ie(e,t,n){let r=new ne,i=new AbortController,a=()=>i.abort(t.reason);t.addEventListener(`abort`,a,{once:!0});try{let a=await E(e,t,async e=>{let t=k(r.port1,`takeover`,e),a=Promise.resolve().then(()=>n(r.port2,i.signal));return await Promise.race([t,a.then(()=>{throw Error(`Piscina task completed before bootstrap handoff`)})]),{result:a}});return T(e,t),r.port1.postMessage(`acknowledged`),r.port1.close(),await a.result}catch(e){throw i.abort(e),e}finally{t.removeEventListener(`abort`,a),r.port1.close(),r.port2.close()}}async function ae(e,t=new AbortController().signal){try{await E(e.bootstrapDeadlineAt,t,t=>k(e.bootstrapPort,`acknowledged`,t,`takeover`))}finally{e.bootstrapPort.close()}}async function k(e,t,n,r){n.throwIfAborted();let i=Promise.withResolvers(),a=e=>{e===t?i.resolve():i.reject(Error(`Invalid Piscina bootstrap handoff message`))},o=()=>i.reject(Error(`Piscina bootstrap handoff port closed`)),s=e=>i.reject(e),c=()=>i.reject(n.reason);e.on(`message`,a),e.on(`messageerror`,s),e.on(`close`,o),n.addEventListener(`abort`,c,{once:!0});try{r!==void 0&&e.postMessage(r),await i.promise}finally{e.off(`message`,a),e.off(`messageerror`,s),e.off(`close`,o),n.removeEventListener(`abort`,c)}}function oe(e,t){return e===void 0?void 0:new g({secret:e,...t!==void 0&&{identityId:t}})}async function A(e){let t=T(e.bootstrapDeadlineAt,e.signal),n=1e3;for(;;){D(t);let r=e.createSession();try{await O(t,1e4,t=>e.connect(r,t));let i=await j(e,r,t,()=>{n=1e3});return D(t),{session:r,value:i}}catch(i){try{await M(e,r,t)}finally{D(t)}if(!N(i))throw i;await O(t,t.deadline-Date.now(),e=>P(Math.min(n,t.deadline-Date.now()),e)),n=Math.min(n*2,1e4)}}}async function j(e,t,n,r){for(;;){let i=await O(n,35e3,(n,r)=>e.exchange(t,{signal:n,timeoutMs:r}));if(r(),i.status===`complete`)return i.value;await O(n,35e3,e=>P(0,e))}}async function M(e,t,n){let r=Promise.resolve(e.dispose(t));r.catch(()=>{}),await O(n,n.deadline-Date.now(),()=>r)}function N(e){if(e instanceof p||e instanceof m)return!0;let t=e instanceof Error&&e.cause instanceof _&&`code`in e&&e.code===e.cause.code?e.cause:e;return t instanceof _&&(t.code===`WS_CONNECTION_UNAVAILABLE`||t.code===`WS_HANDSHAKE_TIMEOUT`||t.code===`WS_CONNECTION_TIMEOUT`)}function P(e,t){return t.throwIfAborted(),new Promise((n,r)=>{let i=()=>{clearTimeout(a),r(t.reason)},a=setTimeout(()=>{t.removeEventListener(`abort`,i),n()},e);t.addEventListener(`abort`,i,{once:!0})})}function F(e){if(typeof e!=`object`||!e)throw new d(f.NOT_EXECUTABLE,`Invalid workflow module default export: expected an object with 'definition' and 'runtimeHandlers', got ${typeof e}.`);let t=e;if(!(t.runtimeHandlers instanceof Map))throw new d(f.NOT_EXECUTABLE,`Invalid workflow module default export: 'runtimeHandlers' must be a Map instance.`);let n=u.safeParse(t.definition);if(!n.success)throw new d(f.NOT_EXECUTABLE,`Invalid workflow module default export: 'definition' must satisfy WorkflowDefinitionSchema. `+n.error.message);let r=I(t.zodSchemas)?t.zodSchemas:void 0,i=t.runtimeLoopGates;if(i!==void 0&&!(i instanceof Map))throw new d(f.NOT_EXECUTABLE,`Invalid workflow module default export: 'runtimeLoopGates' must be a Map instance when provided.`);return{definition:n.data,runtimeHandlers:t.runtimeHandlers,...r===void 0?{}:{zodSchemas:r},...i===void 0?{}:{runtimeLoopGates:i}}}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&`gates`in e}async function L(e,s){let c=i(e);if(!c||c===`.`||c===`..`)throw Error(`Invalid workflow source filename: ${e}`);let l=a(ee(),`makaio-wf-${o(6).toString(`hex`)}`);await t(l,{recursive:!0});let u=a(l,c.endsWith(`.mjs`)?c:`${c}.mjs`);try{await r(u,s,`utf8`)}catch(e){throw await n(l,{recursive:!0,force:!0}).catch(()=>{}),e}return{tempDir:l,tempPath:u}}function R(e){return typeof e==`object`&&e&&Array.isArray(e.workflows)?e.workflows.map(F):[F(e)]}async function z(t){if(t.kind===`path`)return R((await import(e(t.path).href)).default);let{tempDir:r,tempPath:i}=await L(t.filename,t.source);try{return R((await import(e(i).href)).default)}finally{await n(r,{recursive:!0,force:!0})}}async function B(e){if(e.kind===`definition`)throw new d(f.NOT_EXECUTABLE,`Definition-sourced workers are handled by the workflow executor, not the file loader. Received source: ${JSON.stringify(e)}`);let t=await z(e);if(t.length!==1)throw new d(f.NOT_EXECUTABLE,`loadWorkflowModule expects a single workflow export, but the module exported ${String(t.length)} workflows. Use loadWorkflowModules for bundle exports.`);return t[0]}async function V(e){if(e.source.kind===`definition`){if(e.definition===void 0)throw Error(`Definition-sourced worker config for workflowId "${e.source.workflowId}" is missing the required 'definition' field. Ensure the executor populates WorkflowWorkerConfig.definition before dispatching.`);return{definition:e.definition,runtimeHandlers:new Map}}let t=await B(e.source);return H(e,t),e.definition===void 0?t:{...t,definition:e.definition}}function H(e,t){if(e.workflowId!==e.executionId&&t.definition.id!==e.workflowId)throw new d(f.SOURCE_MISMATCH,`Source-backed workflow for logical workflow '${e.workflowId}' loaded definition '${t.definition.id}'.`)}const U=`[WorkflowWorkerAwaitTrigger]`;function W(e){let t=y(e);return{resolveRegistration:e=>{let n=t.find(t=>t.kind===e);return n===void 0?void 0:{owner:te,type:n}}}}async function G(e,t,n){let r=new v(W(e)),i=t.flatMap(e=>{let t=r.prepareBinding(e);return t===void 0?(console.warn(`${U} skipping binding '${e.kind}': awaiting it inside a worker is unsupported. A worker carries only bus-backed trigger types; schedules and extension-contributed sources are activated by the host that owns their placement.`),[]):t.workflowCompatible?[{binding:e,prepared:t}]:(console.warn(`${U} skipping binding '${e.kind}': its event payload does not have an object root.`),[])});if(i.length===0){await r.close();return}try{if(n.aborted)throw n.reason??Error(`Await-trigger aborted`);let e=Promise.withResolvers();e.promise.catch(()=>void 0);let t=()=>{e.reject(n.reason??Error(`Await-trigger aborted`))};n.addEventListener(`abort`,t,{once:!0});try{return await Promise.all(i.map(async({binding:t,prepared:n})=>{let r=x(t);await n.subscribe(t=>{r(t.payload)&&e.resolve(b(t.payload))})})),await e.promise}finally{n.removeEventListener(`abort`,t)}}finally{await r.close()}}async function K(e,t,n,r){let i=t.definition.triggers??[];if(e.triggerMode!==`await-trigger`||i.length===0)return e;let a=await G(n,i,r);return a===void 0?e:{...e,triggerPayload:a}}async function se(e,t,n){if(e.operationKind===`runtime-probe`)return{receipt:`completed`};if(n===void 0||e.runtimeGeneration!==n)return{receipt:`refused`,refusalReason:`stale-generation`};let r=t[e.operationKind];return r===void 0?{receipt:`refused`,refusalReason:`unknown-kind`}:await r(e)}async function q(e,t,n,r){r?.throwIfAborted();let{executionAttemptId:i,runtimeIncarnationId:a}=t,o=t.runtimeGeneration,s=e.withFilter({executionAttemptId:i,runtimeIncarnationId:a}).on(l.operation.deliver,async e=>{e.setResult(await se(e.payload,n,o))}),c={bindGeneration(e){o=e},cleanup(){let e=s;s=void 0,e?.()}},u=()=>c.cleanup();r?.addEventListener(`abort`,u,{once:!0});try{return await h(s),r?.throwIfAborted(),c}catch(e){throw c.cleanup(),e}finally{r?.removeEventListener(`abort`,u)}}var J=class extends Error{executionAttemptId;refusalReason;constructor(e,t){super(`Runtime registration refused by the Authority (executionAttemptId=${e}, refusalReason=${t??`unreported`})`),this.executionAttemptId=e,this.refusalReason=t,this.name=`RuntimeRegistrationRefusedError`}},Y=class extends Error{executionAttemptId;admissionKey;refusalReason;constructor(e,t,n){super(`Operation admission refused by the Authority (executionAttemptId=${e}, admissionKey=${t}, refusalReason=${n??`unreported`})`),this.executionAttemptId=e,this.admissionKey=t,this.refusalReason=n,this.name=`OperationAdmissionRefusedError`}};function X(e,t,n,r){let i=t.safeParse(n);if(i.success)return i.data;let a=i.error.issues.map(e=>`${e.path.join(`.`)||`<root>`}: ${e.message}`);throw Error(`Malformed '${e.$meta.namespace}.${e.subject}' response from the Authority (executionAttemptId=${r}): ${a.join(`; `)}`)}async function Z(e,t){let{executionAttemptId:n,runtimeIncarnationId:r,signal:i}=t;i?.throwIfAborted();let a=X(l.runtime.register,c[`runtime.register`].response,await e.request(l.runtime.register,{executionAttemptId:n,runtimeIncarnationId:r},{signal:i}),n);if(a.decision===`refused`)throw new J(n,a.refusalReason);return a.runtimeGeneration}async function Q(e,t){let{executionAttemptId:n,runtimeGeneration:r,admissionKey:i,signal:a}=t,o=X(l.operation.admit,c[`operation.admit`].response,await e.request(l.operation.admit,{executionAttemptId:n,operationKind:`workflow-run`,admissionKey:i,runtimeGeneration:r},{signal:a}),n);if(o.decision===`refused`)throw new Y(n,i,o.refusalReason);if(o.operationId===void 0)throw Error(`Operation admission decision '${o.decision}' named no operation (executionAttemptId=${n}, admissionKey=${i})`);return o.operationId}async function ce(e,t){let{executionAttemptId:n,runtimeIncarnationId:r,endpoint:i,signal:a}=t,o=await Z(e,{executionAttemptId:n,runtimeIncarnationId:r,signal:a});return i.bindGeneration(o),{runtimeGeneration:o,operationId:await Q(e,{executionAttemptId:n,runtimeGeneration:o,admissionKey:`workflow-run:${r}`,signal:a})}}var $=class extends Error{refusalReason;constructor(e){super(`Worker bootstrap start refused: ${e}`),this.refusalReason=e,this.name=`BootstrapStartRefusedError`}};async function le(e){let{session:t}=await A({bootstrapDeadlineAt:e.bootstrapDeadlineAt,signal:e.signal,createSession:()=>({connection:e.createConnection()}),connect:async(t,n)=>{await t.connection.connect(n),n.throwIfAborted(),t.endpoint=await q(t.connection.bus,e,{},n)},exchange:async(t,{signal:n,timeoutMs:r})=>{let i=s.parse(await t.connection.bus.request(l.bootstrap.awaitStart,{executionAttemptId:e.executionAttemptId},{signal:n,timeout:r}));if(i.status===`refused`)throw new $(i.reason);return i.status===`pending`?{status:`pending`}:{status:`complete`,value:void 0}},dispose:async e=>{e.endpoint?.cleanup(),await e.connection.close()}});if(t.endpoint===void 0)throw Error(`Bootstrap completed without an operation endpoint`);return{connection:t.connection,endpoint:t.endpoint}}export{w as _,Q as a,C as b,Z as c,B as d,z as f,ie as g,ae as h,J as i,K as l,oe as m,le as n,q as o,A as p,Y as r,ce as s,$ as t,V as u,E as v,S as y};
@@ -1 +0,0 @@
1
- import{n as e,o as t}from"./json-value-DM-EjTC1.mjs";import{r as n}from"./definitions-CyFaNG_c.mjs";import{A as r,M as i,_ as a,d as o,x as s}from"./worker-B0xwfo9-.mjs";import{G as c,H as l,V as u}from"./workflow-DNks09Ip.mjs";import{z as d}from"zod";import{createBusNamespace as f}from"@makaio/framework/core";const p=d.object({requestKey:d.string().min(1),controlRevision:d.number().int().positive(),requestedAt:d.iso.datetime({offset:!0}),reason:d.string().optional()}).strict(),m=d.object({executionAttemptId:d.string().min(1),runtimeIncarnationId:d.string().min(1),runtimeGeneration:d.number().int().positive(),controlRevision:d.number().int().positive(),requestKey:d.string().min(1)}).strict(),h=m.omit({requestKey:!0,controlRevision:!0}).extend({cancellation:p}),g=m.extend({receivedAt:d.iso.datetime({offset:!0})}),_=d.discriminatedUnion(`decision`,[d.object({decision:d.literal(`received`),receipt:g}).strict(),d.object({decision:d.literal(`refused`),reason:d.enum([`stale-generation`,`unsupported`])}).strict()]),v=d.object({status:d.enum([`achieved`,`unsupported`,`unconfirmed`]),boundary:d.enum([`admission-closed`,`setup-process-group`,`workload`]),evidence:o}).strict(),y=m.extend({operationId:d.string().min(1).optional(),conclusion:v}),b=d.enum([`not-found`,`cancel-mismatch`,`stale-generation`,`operation-mismatch`,`conflict`]),x=d.discriminatedUnion(`decision`,[d.object({decision:d.literal(`accepted`)}).strict(),d.object({decision:d.literal(`duplicate`)}).strict(),d.object({decision:d.literal(`refused`),reason:b}).strict()]),S=d.string().min(1),C=S.refine(e=>!e.startsWith(`/`)&&!e.includes(`\\`)&&!/^[A-Za-z]:/.test(e)&&!e.split(`/`).includes(`..`),{message:`Source paths must be workspace-relative and may not traverse outside the workspace`}),w=d.object({command:S,args:d.array(d.string()),env:d.record(d.string(),d.string()),timeoutMs:d.number().int().positive()}).strict(),T=d.object({provisioning:d.enum([`bind`,`create`]),custody:d.enum([`external`,`disposable`]),sourceRoots:d.array(d.object({id:S,path:C,source:d.object({kind:S,input:t}).strict().optional()}).strict()),setup:d.array(w)}).strict(),E=d.object({required:d.array(d.enum([`source-state`,`diagnostics`,`workspace-state`,`live-state`]))}).strict(),D=d.object({id:S,revision:S,workload:d.object({kind:S,version:S,input:t}).strict(),workspace:T.optional(),preservation:E}).strict(),O=d.object({workspaceRoot:S,sourceRoots:d.array(d.object({id:S,path:S}).strict())}).strict(),k=d.object({kind:d.literal(`workspace-prepared`),binding:O}).strict(),A=d.discriminatedUnion(`kind`,[d.object({kind:d.literal(`technical-failure`),stage:d.enum([`startup`,`workspace-preparation`,`workload-invocation`]),message:d.string().min(1).max(8192)}).strict(),d.object({kind:d.literal(`workload-result`),result:t}).strict(),d.object({kind:d.literal(`cancelled`),reason:d.string().min(1).max(8192).optional()}).strict()]),j=d.enum([`runtime-probe`,`workflow-run`,`workspace-preparation`,`workload-invocation`]),M=j.exclude([`runtime-probe`]),N=d.object({executionAttemptId:d.string().min(1),runtimeIncarnationId:d.string().min(1),operationId:d.string().min(1),operationKind:j,runtimeGeneration:d.number().int().positive()}).strict(),P=d.object({receipt:d.enum([`completed`,`duplicate`,`refused`]),refusalReason:d.enum([`stale-generation`,`unknown-kind`]).optional()}).strict(),F=d.enum([`not-found`,`resolved`,`fenced`,`not-allocated`,`operation-active`,`probe-failed`]),I=e=>d.object({decision:d.literal(e),runtimeGeneration:d.number().int().positive()}).strict(),L=d.enum([`not-found`,`resolved`,`fenced`,`allocation-terminated`,`gate-closed`,`bootstrap-expired`]),R=d.object({executionAttemptId:d.string().min(1)}).strict(),z=d.discriminatedUnion(`status`,[d.object({status:d.literal(`permitted`)}).strict(),d.object({status:d.literal(`pending`)}).strict(),d.object({status:d.literal(`refused`),reason:L}).strict()]),B={"control.deliver":{request:h,response:_},"control.report":{request:y,response:x},"bootstrap.awaitStart":{request:R,response:z},"runtime.register":{request:d.object({executionAttemptId:d.string().min(1),runtimeIncarnationId:d.string().min(1)}).strict(),response:d.discriminatedUnion(`decision`,[I(`ready`),I(`duplicate`),d.object({decision:d.literal(`refused`),runtimeGeneration:d.literal(0),refusalReason:F}).strict()])},"runtime.ready":d.object({executionAttemptId:d.string().min(1),runtimeGeneration:d.number().int().positive(),acceptedAt:d.string().min(1)}).strict(),"operation.admit":{request:d.object({executionAttemptId:d.string().min(1),operationKind:j,admissionKey:d.string().min(1),runtimeGeneration:d.number().int().positive()}).strict(),response:d.object({decision:d.enum([`admitted`,`duplicate`,`refused`]),operationId:d.string().min(1).optional(),refusalReason:d.enum([`not-found`,`resolved`,`fenced`,`not-allocated`,`operation-active`,`gate-closed`,`not-ready`,`stale-generation`,`preparation-required`,`preparation-not-required`,`preparation-already-completed`]).optional()}).strict()},"operation.admitted":d.object({executionAttemptId:d.string().min(1),operationId:d.string().min(1),operationKind:M,runtimeGeneration:d.number().int().positive(),admittedAt:d.string().min(1)}).strict(),"operation.deliver":{request:N,response:P},"instruction.get":{request:d.object({executionAttemptId:d.string().min(1),runtimeGeneration:d.number().int().positive()}).strict(),response:d.discriminatedUnion(`decision`,[d.object({decision:d.literal(`found`),instruction:D}).strict(),d.object({decision:d.literal(`refused`),refusalReason:d.enum([`not-found`,`resolved`,`fenced`,`not-ready`,`stale-generation`])}).strict()])},"operation.report":{request:d.object({executionAttemptId:d.string().min(1),runtimeGeneration:d.number().int().positive(),operationId:d.string().min(1),result:k}).strict(),response:d.discriminatedUnion(`decision`,[d.object({decision:d.literal(`accepted`),binding:O}).strict(),d.object({decision:d.literal(`duplicate`),binding:O}).strict(),d.object({decision:d.literal(`refused`),refusalReason:d.enum([`not-found`,`resolved`,`fenced`,`not-allocated`,`stale-generation`,`no-active-operation`,`operation-mismatch`,`preparation-not-required`,`binding-mismatch`,`conflict`])}).strict()])},"outcome.submit":{request:d.object({executionAttemptId:d.string().min(1),runtimeGeneration:d.number().int().positive(),operationId:d.string().min(1).optional(),outcome:A}).strict().superRefine((e,t)=>{!e.operationId&&e.outcome.kind!==`cancelled`&&!(e.outcome.kind===`technical-failure`&&e.outcome.stage===`startup`)&&t.addIssue({code:`custom`,path:[`operationId`],message:`An admitted operation is required for this outcome`})}),response:d.object({decision:a}).strict()}},V=d.object({workerManifest:u,suspensionStrategy:i}).strict(),H=d.iso.datetime({offset:!0}),U=d.string().refine(e=>{let t=Date.parse(e);return Number.isFinite(t)&&(H.safeParse(e).success||new Date(t).toISOString()===e)},`Expected a representable ISO bootstrap deadline`),W=d.object({busUrl:d.string().min(1),busAuthSecret:d.string().min(1)}).strict(),G=d.object({status:d.literal(`granted`),credentials:W,runtimeEnv:d.record(n,d.string())}).strict(),K=d.enum([...L.options,`provider-mismatch`,`claim-expired`,`not-claimable`]),q=d.discriminatedUnion(`status`,[G,d.object({status:d.literal(`pending`)}).strict(),d.object({status:d.literal(`refused`),reason:K}).strict()]),J=d.object({executionAttemptId:d.string().min(1),executionId:d.string().min(1),environment:d.string().min(1),metadata:e.optional()}),Y=d.object({executionAttemptId:d.string().min(1),config:c,manifest:u.optional(),requirements:r.optional(),metadata:e.optional()}),X=d.object({executionAttemptId:d.string().min(1),allocationRef:s}).strict(),Z={dispatch:{request:Y,response:X},"runtime.inputs.get":{request:d.object({executionAttemptId:d.string().min(1)}).strict(),response:d.object({runtimeInputs:V.nullable()}).strict()},"control.outcome.submit":{request:d.object({executionAttemptId:d.string().min(1),executionId:d.string().min(1),result:l}).strict().superRefine((e,t)=>{e.result.executionId!==e.executionId&&t.addIssue({code:d.ZodIssueCode.custom,path:[`result`,`executionId`],message:`result.executionId must match executionId`})}),response:d.object({decision:a}).strict()},"control.bootstrap.claim":{request:d.object({executionId:d.string().min(1),executionAttemptId:d.string().min(1)}).strict(),response:q},"lifecycle.provisioning":J,"lifecycle.booting":J,"lifecycle.ready":J,"lifecycle.busy":J,"lifecycle.completed":J,"lifecycle.failed":J.extend({error:d.string().min(1)}),"lifecycle.terminated":J.extend({reason:d.string().optional()}),"lifecycle.paused":J.extend({pausedAtGateId:d.string().min(1),pausedAtFrameId:d.string().min(1)})},Q=`worker-bootstrap`,$=f(`worker`,Z),ee=$.subjects;export{v as A,A as C,T as D,E,b as F,x as I,y as L,_ as M,h as N,w as O,g as P,D as S,O as T,N as _,q as a,F as b,G as c,Z as d,V as f,L as g,z as h,K as i,m as j,p as k,Y as l,R as m,$ as n,W as o,M as p,ee as r,U as s,Q as t,X as u,j as v,k as w,B as x,P as y};