@makaio/framework 1.0.0-dev-1790599449321 → 1.0.0-dev-1790614475240
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.
- package/dist/.makaio-build.json +2 -2
- package/dist/contracts/artifact/index.d.mts +1 -1
- package/dist/contracts/capabilities/index.d.mts +1 -1
- package/dist/contracts/extension/index.d.mts +2 -2
- package/dist/contracts/index.d.mts +11 -11
- package/dist/contracts/materialization/index.d.mts +2 -2
- package/dist/contracts/variant/index.d.mts +1 -1
- package/dist/contracts/worker/index.d.mts +1 -1
- package/dist/contracts/workflow/index.d.mts +1 -1
- package/dist/{framework-packages-CLrOCDDK.mjs → framework-packages-D2fycy02.mjs} +1 -1
- package/dist/{index-CpaWzUE5.d.mts → index-1mY0aNe3.d.mts} +1 -1
- package/dist/{index-uusIGFLo.d.mts → index-3G70bNLs.d.mts} +2 -2
- package/dist/{index-9O8N514B2.d.mts → index-6UlianLY2.d.mts} +4 -4
- package/dist/{index-oE2q0pTG.d.mts → index-B1uHTa1l.d.mts} +1 -1
- package/dist/{index-UbOsrzp6.d.mts → index-BM8oUon_.d.mts} +12 -12
- package/dist/{index-CPOJqxrf2.d.mts → index-BYMgvz_a2.d.mts} +3 -3
- package/dist/{index-GlDcAkrf.d.mts → index-C-tLT_IE.d.mts} +2 -2
- package/dist/{index-BstMoG8p.d.mts → index-CU0AgN84.d.mts} +1 -1
- package/dist/{index-xqiInEhj.d.mts → index-DmV9ybgT.d.mts} +24 -2
- package/dist/{index-D9hIDsPr.d.mts → index-DyWD9bfP.d.mts} +46 -2
- package/dist/{index-BSYu8AXG.d.mts → index-bXozN5vc.d.mts} +6 -6
- package/dist/{index-CcTlPuIg.d.mts → index-e3AB0Iyv.d.mts} +18 -18
- package/dist/kernel/extension/index.d.mts +2 -2
- package/dist/kernel/index.d.mts +2 -2
- package/dist/kernel/observability/index.d.mts +1 -1
- package/dist/{namespace-C1-ZAKEG.d.mts → namespace-CNX4llM5.d.mts} +6 -6
- package/dist/package.json +1 -1
- package/dist/runtime-node/index.d.mts +1 -1
- package/dist/runtime-node/index.mjs +22 -22
- package/dist/runtime-node/workflow-worker/index.d.mts +1 -1
- package/dist/runtime-node/workflow-worker/index.mjs +1 -1
- package/dist/{schemas-CjFPsYeV.d.mts → schemas-BjhhkGN_.d.mts} +4 -4
- package/dist/{schemas-Dyp3rHZ7.d.mts → schemas-D9pXu76T.d.mts} +4 -4
- package/dist/{schemas-DPtj1sPC2.d.mts → schemas-RwAlAMbq2.d.mts} +7 -7
- package/dist/services/adapter-subsystem/index.d.mts +2 -2
- package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
- package/dist/services/filesystem/namespace.d.mts +6 -6
- package/dist/services/filesystem/schemas.d.mts +3 -3
- package/dist/services/index.d.mts +37 -18
- package/dist/services/index.mjs +1 -1
- package/dist/services/preferences/index.d.mts +2 -2
- package/dist/services/preferences/schemas.d.mts +1 -1
- package/dist/services/preferences/storage-namespace.d.mts +2 -2
- package/dist/services/provider-context/index.d.mts +1 -1
- package/dist/services/session/index.d.mts +1 -1
- package/dist/services/tool-approval/index.d.mts +1 -1
- package/dist/services/tool-approval/index.mjs +1 -1
- package/dist/services/tools/index.mjs +1 -1
- package/dist/services/workflow-transitions/index.mjs +1 -1
- package/dist/{storage-namespace-CwwiV3kt.d.mts → storage-namespace-NHTWAjaX.d.mts} +10 -10
- package/dist/tool-approval-service-BCN4W8eS.mjs +1 -0
- package/dist/tools/index.d.mts +13 -1
- package/dist/tools/index.mjs +1 -1
- package/dist/{tools-nkqlVAQ1.mjs → tools-BCL_dtHe.mjs} +1 -1
- package/dist/ui-kernel/index.d.mts +4 -4
- package/dist/ui-kernel/pages/namespace.d.mts +4 -4
- package/dist/ui-kernel/pages/schemas.d.mts +1 -1
- package/dist/{view-builder-Nffvg8MI.d.mts → view-builder-tgwZ1ucc.d.mts} +1 -1
- package/dist/workflow-engine/index.d.mts +23 -23
- package/dist/{workflow-transitions-DEaRIZDU.mjs → workflow-transitions-7d9lGi08.mjs} +1 -1
- package/dist/workflow-worker-BCLy_g_a.mjs +3 -0
- package/package.json +1 -1
- package/dist/tool-approval-service-BRyBObcL.mjs +0 -1
- package/dist/workflow-worker-DXCXb3g-.mjs +0 -3
|
@@ -1604,8 +1604,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1604
1604
|
cancelled: "cancelled";
|
|
1605
1605
|
failed: "failed";
|
|
1606
1606
|
running: "running";
|
|
1607
|
-
waiting: "waiting";
|
|
1608
1607
|
skipped: "skipped";
|
|
1608
|
+
waiting: "waiting";
|
|
1609
1609
|
}>;
|
|
1610
1610
|
attempt: z.ZodDefault<z.ZodNumber>;
|
|
1611
1611
|
iteration: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1650,8 +1650,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1650
1650
|
cancelled: "cancelled";
|
|
1651
1651
|
failed: "failed";
|
|
1652
1652
|
running: "running";
|
|
1653
|
-
waiting: "waiting";
|
|
1654
1653
|
skipped: "skipped";
|
|
1654
|
+
waiting: "waiting";
|
|
1655
1655
|
}>;
|
|
1656
1656
|
attempt: z.ZodDefault<z.ZodNumber>;
|
|
1657
1657
|
iteration: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1693,8 +1693,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1693
1693
|
cancelled: "cancelled";
|
|
1694
1694
|
failed: "failed";
|
|
1695
1695
|
running: "running";
|
|
1696
|
-
waiting: "waiting";
|
|
1697
1696
|
skipped: "skipped";
|
|
1697
|
+
waiting: "waiting";
|
|
1698
1698
|
}>;
|
|
1699
1699
|
attempt: z.ZodDefault<z.ZodNumber>;
|
|
1700
1700
|
iteration: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1722,8 +1722,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1722
1722
|
status: z.ZodEnum<{
|
|
1723
1723
|
cancelled: "cancelled";
|
|
1724
1724
|
rejected: "rejected";
|
|
1725
|
-
waiting: "waiting";
|
|
1726
1725
|
resumed: "resumed";
|
|
1726
|
+
waiting: "waiting";
|
|
1727
1727
|
"timed-out": "timed-out";
|
|
1728
1728
|
}>;
|
|
1729
1729
|
autoAction: z.ZodEnum<{
|
|
@@ -1857,8 +1857,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1857
1857
|
status: z.ZodEnum<{
|
|
1858
1858
|
cancelled: "cancelled";
|
|
1859
1859
|
rejected: "rejected";
|
|
1860
|
-
waiting: "waiting";
|
|
1861
1860
|
resumed: "resumed";
|
|
1861
|
+
waiting: "waiting";
|
|
1862
1862
|
"timed-out": "timed-out";
|
|
1863
1863
|
}>;
|
|
1864
1864
|
autoAction: z.ZodEnum<{
|
|
@@ -1882,8 +1882,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1882
1882
|
status: z.ZodOptional<z.ZodEnum<{
|
|
1883
1883
|
cancelled: "cancelled";
|
|
1884
1884
|
rejected: "rejected";
|
|
1885
|
-
waiting: "waiting";
|
|
1886
1885
|
resumed: "resumed";
|
|
1886
|
+
waiting: "waiting";
|
|
1887
1887
|
"timed-out": "timed-out";
|
|
1888
1888
|
}>>;
|
|
1889
1889
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
@@ -1899,8 +1899,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1899
1899
|
status: z.ZodEnum<{
|
|
1900
1900
|
cancelled: "cancelled";
|
|
1901
1901
|
rejected: "rejected";
|
|
1902
|
-
waiting: "waiting";
|
|
1903
1902
|
resumed: "resumed";
|
|
1903
|
+
waiting: "waiting";
|
|
1904
1904
|
"timed-out": "timed-out";
|
|
1905
1905
|
}>;
|
|
1906
1906
|
autoAction: z.ZodEnum<{
|
|
@@ -1935,8 +1935,8 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
1935
1935
|
status: z.ZodEnum<{
|
|
1936
1936
|
cancelled: "cancelled";
|
|
1937
1937
|
rejected: "rejected";
|
|
1938
|
-
waiting: "waiting";
|
|
1939
1938
|
resumed: "resumed";
|
|
1939
|
+
waiting: "waiting";
|
|
1940
1940
|
"timed-out": "timed-out";
|
|
1941
1941
|
}>;
|
|
1942
1942
|
autoAction: z.ZodEnum<{
|
|
@@ -3392,7 +3392,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
3392
3392
|
tableName: "workflow_execution_frames";
|
|
3393
3393
|
dataType: "string";
|
|
3394
3394
|
columnType: "SQLiteText";
|
|
3395
|
-
data: "pending" | "completed" | "cancelled" | "failed" | "running" | "
|
|
3395
|
+
data: "pending" | "completed" | "cancelled" | "failed" | "running" | "skipped" | "waiting";
|
|
3396
3396
|
driverParam: string;
|
|
3397
3397
|
notNull: true;
|
|
3398
3398
|
hasDefault: true;
|
|
@@ -3405,7 +3405,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
3405
3405
|
generated: undefined;
|
|
3406
3406
|
}, {}, {
|
|
3407
3407
|
length: number | undefined;
|
|
3408
|
-
$type: "pending" | "completed" | "cancelled" | "failed" | "running" | "
|
|
3408
|
+
$type: "pending" | "completed" | "cancelled" | "failed" | "running" | "skipped" | "waiting";
|
|
3409
3409
|
}>;
|
|
3410
3410
|
attempt: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
|
|
3411
3411
|
name: string;
|
|
@@ -3694,7 +3694,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
3694
3694
|
tableName: "workflow_gate_instances";
|
|
3695
3695
|
dataType: "string";
|
|
3696
3696
|
columnType: "SQLiteText";
|
|
3697
|
-
data: "cancelled" | "rejected" | "
|
|
3697
|
+
data: "cancelled" | "rejected" | "resumed" | "waiting" | "timed-out";
|
|
3698
3698
|
driverParam: string;
|
|
3699
3699
|
notNull: true;
|
|
3700
3700
|
hasDefault: true;
|
|
@@ -3707,7 +3707,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
3707
3707
|
generated: undefined;
|
|
3708
3708
|
}, {}, {
|
|
3709
3709
|
length: number | undefined;
|
|
3710
|
-
$type: "cancelled" | "rejected" | "
|
|
3710
|
+
$type: "cancelled" | "rejected" | "resumed" | "waiting" | "timed-out";
|
|
3711
3711
|
}>;
|
|
3712
3712
|
autoAction: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
|
|
3713
3713
|
name: "auto_action";
|
|
@@ -5206,7 +5206,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
5206
5206
|
tableName: "worklog_frame_entries";
|
|
5207
5207
|
dataType: "string";
|
|
5208
5208
|
columnType: "SQLiteText";
|
|
5209
|
-
data: "pending" | "completed" | "cancelled" | "failed" | "running" | "
|
|
5209
|
+
data: "pending" | "completed" | "cancelled" | "failed" | "running" | "skipped" | "waiting";
|
|
5210
5210
|
driverParam: string;
|
|
5211
5211
|
notNull: true;
|
|
5212
5212
|
hasDefault: false;
|
|
@@ -5640,7 +5640,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
5640
5640
|
tableName: "worklog_gate_events";
|
|
5641
5641
|
dataType: "string";
|
|
5642
5642
|
columnType: "SQLiteText";
|
|
5643
|
-
data: "cancelled" | "rejected" | "
|
|
5643
|
+
data: "cancelled" | "rejected" | "resumed" | "waiting" | "timed-out";
|
|
5644
5644
|
driverParam: string;
|
|
5645
5645
|
notNull: true;
|
|
5646
5646
|
hasDefault: false;
|
|
@@ -5653,7 +5653,7 @@ declare const WorkflowStorageNamespace: _$_makaio_storage_core0.StorageNamespace
|
|
|
5653
5653
|
generated: undefined;
|
|
5654
5654
|
}, {}, {
|
|
5655
5655
|
length: number | undefined;
|
|
5656
|
-
$type: "cancelled" | "rejected" | "
|
|
5656
|
+
$type: "cancelled" | "rejected" | "resumed" | "waiting" | "timed-out";
|
|
5657
5657
|
}>;
|
|
5658
5658
|
prompt: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
|
|
5659
5659
|
name: "prompt";
|
|
@@ -7253,8 +7253,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7253
7253
|
cancelled: "cancelled";
|
|
7254
7254
|
failed: "failed";
|
|
7255
7255
|
running: "running";
|
|
7256
|
-
waiting: "waiting";
|
|
7257
7256
|
skipped: "skipped";
|
|
7257
|
+
waiting: "waiting";
|
|
7258
7258
|
}>;
|
|
7259
7259
|
attempt: z.ZodDefault<z.ZodNumber>;
|
|
7260
7260
|
iteration: z.ZodOptional<z.ZodNumber>;
|
|
@@ -7299,8 +7299,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7299
7299
|
cancelled: "cancelled";
|
|
7300
7300
|
failed: "failed";
|
|
7301
7301
|
running: "running";
|
|
7302
|
-
waiting: "waiting";
|
|
7303
7302
|
skipped: "skipped";
|
|
7303
|
+
waiting: "waiting";
|
|
7304
7304
|
}>;
|
|
7305
7305
|
attempt: z.ZodDefault<z.ZodNumber>;
|
|
7306
7306
|
iteration: z.ZodOptional<z.ZodNumber>;
|
|
@@ -7342,8 +7342,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7342
7342
|
cancelled: "cancelled";
|
|
7343
7343
|
failed: "failed";
|
|
7344
7344
|
running: "running";
|
|
7345
|
-
waiting: "waiting";
|
|
7346
7345
|
skipped: "skipped";
|
|
7346
|
+
waiting: "waiting";
|
|
7347
7347
|
}>;
|
|
7348
7348
|
attempt: z.ZodDefault<z.ZodNumber>;
|
|
7349
7349
|
iteration: z.ZodOptional<z.ZodNumber>;
|
|
@@ -7371,8 +7371,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7371
7371
|
status: z.ZodEnum<{
|
|
7372
7372
|
cancelled: "cancelled";
|
|
7373
7373
|
rejected: "rejected";
|
|
7374
|
-
waiting: "waiting";
|
|
7375
7374
|
resumed: "resumed";
|
|
7375
|
+
waiting: "waiting";
|
|
7376
7376
|
"timed-out": "timed-out";
|
|
7377
7377
|
}>;
|
|
7378
7378
|
autoAction: z.ZodEnum<{
|
|
@@ -7506,8 +7506,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7506
7506
|
status: z.ZodEnum<{
|
|
7507
7507
|
cancelled: "cancelled";
|
|
7508
7508
|
rejected: "rejected";
|
|
7509
|
-
waiting: "waiting";
|
|
7510
7509
|
resumed: "resumed";
|
|
7510
|
+
waiting: "waiting";
|
|
7511
7511
|
"timed-out": "timed-out";
|
|
7512
7512
|
}>;
|
|
7513
7513
|
autoAction: z.ZodEnum<{
|
|
@@ -7531,8 +7531,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7531
7531
|
status: z.ZodOptional<z.ZodEnum<{
|
|
7532
7532
|
cancelled: "cancelled";
|
|
7533
7533
|
rejected: "rejected";
|
|
7534
|
-
waiting: "waiting";
|
|
7535
7534
|
resumed: "resumed";
|
|
7535
|
+
waiting: "waiting";
|
|
7536
7536
|
"timed-out": "timed-out";
|
|
7537
7537
|
}>>;
|
|
7538
7538
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
@@ -7548,8 +7548,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7548
7548
|
status: z.ZodEnum<{
|
|
7549
7549
|
cancelled: "cancelled";
|
|
7550
7550
|
rejected: "rejected";
|
|
7551
|
-
waiting: "waiting";
|
|
7552
7551
|
resumed: "resumed";
|
|
7552
|
+
waiting: "waiting";
|
|
7553
7553
|
"timed-out": "timed-out";
|
|
7554
7554
|
}>;
|
|
7555
7555
|
autoAction: z.ZodEnum<{
|
|
@@ -7584,8 +7584,8 @@ declare const WorkflowStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
|
|
|
7584
7584
|
status: z.ZodEnum<{
|
|
7585
7585
|
cancelled: "cancelled";
|
|
7586
7586
|
rejected: "rejected";
|
|
7587
|
-
waiting: "waiting";
|
|
7588
7587
|
resumed: "resumed";
|
|
7588
|
+
waiting: "waiting";
|
|
7589
7589
|
"timed-out": "timed-out";
|
|
7590
7590
|
}>;
|
|
7591
7591
|
autoAction: z.ZodEnum<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as e}from"./framework-packages-
|
|
1
|
+
import{u as e}from"./framework-packages-D2fycy02.mjs";function t(){let t=new Map;return{filter:e=>!!(e.transitionRules?.rules?.length||e.transitionActions?.actions),async processActivated(i,a,o){let s=o.getService(e);if(!s)throw Error(`TransitionContributionProcessor: TransitionPipelineService is not available — ensure '${e.name}' is started before extensions with transitionRules or transitionActions.`);let c=a.transitionRules?.rules??[],l=a.transitionActions?.actions,u=c.length>0,d=l!==void 0;u&&n(i,c),d&&r(i,l);let f=!1,p=!1;try{u&&(s.ruleRegistry.register(i,c),f=!0),d&&(s.actionRegistry.register(i,l),p=!0)}catch(e){throw f&&s.ruleRegistry.deregister(i),p&&s.actionRegistry.deregister(i),e}t.set(i,()=>{u&&s.ruleRegistry.deregister(i),d&&s.actionRegistry.deregister(i)})},async processStopped(e){let n=t.get(e);if(n){try{n()}catch(t){console.error(`[TransitionContributionProcessor] Deregister error for "${e}":`,t)}t.delete(e)}}}}function n(e,t){let n=`${e}.`;for(let e of t)if(!e.id.startsWith(n))throw Error(`TransitionContributionProcessor: rule '${e.id}' must be namespaced by extension '${n}'`)}function r(e,t){let n=`${e}.`;for(let e of Object.keys(t))if(!e.startsWith(n))throw Error(`TransitionContributionProcessor: action type '${e}' must be namespaced by extension '${n}'`)}export{t};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{i as e,t}from"./chunk-DTipWd-i.mjs";import{t as n}from"./extension-package-provenance-ClpN3GHp.mjs";import{resolveMakaioHome as r}from"./runtime-node/makaio-config.mjs";import{_ as i,d as a,l as o,n as s,o as c,r as l,u,x as d,y as f}from"./bootstrap-start-client-9nOdeDYl.mjs";import{mintOrRotateWorkflowExecutionBusSecret as p}from"./runtime-node/workflow-execution-bus-access.mjs";import{z as m}from"zod";import{execFile as h,spawn as g}from"node:child_process";import{promisify as _}from"node:util";import*as v from"node:fs/promises";import y,{access as b}from"node:fs/promises";import*as x from"node:path";import{basename as ee,isAbsolute as S,join as C,relative as te}from"node:path";import*as w from"node:crypto";import{randomUUID as T}from"node:crypto";import{constants as E}from"node:fs";import{summarizeDiagnosticText as ne}from"@makaio/framework/utils";import{AdapterSubjects as re,BoundedRecoveryEvidenceSchema as D,CredentialSubjects as ie,ExecutionAttemptSchemas as O,ExecutionAttemptSubjects as k,FrameworkContractNamespaces as A,FrameworkStorageNamespaces as ae,JsonValueSchema as oe,PRE_REQUEST_REJECTION_CODE as se,PROVIDER_ALLOCATION_REF_VERSION as ce,ProviderAllocationRefSchema as le,RECOVERY_EVIDENCE_LIMITS as j,WorkerCapabilitiesSchema as ue,WorkerSchemas as de,WorkerSubjects as M,WorkflowRunContextSchema as fe,WorkflowRunResultSchema as pe,WorkflowWorkerConfigSchema as me,createWorkflowCancelSubject as he,isRuntimeOwnershipFieldClaimed as ge}from"@makaio/framework/contracts";import{BusAbortError as _e,ChannelClosedError as ve,createBusInstance as ye,isRequestCancellation as be,openChannel as xe,waitForSubscriptionPropagation as Se}from"@makaio/framework/bus";import{ExtensionCoordinator as Ce,KernelSubjects as we,coalesceExtensionOverrides as Te,filterEligibleExtensions as Ee}from"@makaio/framework/kernel";import{BaseService as De}from"@makaio/framework/service-base";import{parseStoredCredentialRef as Oe}from"@makaio/framework/contracts/config";import{AdapterRuntimeSubjects as ke,registerAdapterRuntimeIdentityHandlers as Ae}from"@makaio/framework/services/adapter-runtime";import{devNull as N}from"node:os";import{CLIDetectionNamespace as je,CLIDetectionSubjects as Me}from"@makaio/framework/services/cli-detection/namespace";import{SessionOrchestratorToken as Ne,ToolApprovalToken as Pe,ToolRegistryToken as P,canonicalModelPackage as Fe,createFrameworkCorePackages as Ie,createSubagentServicePackage as Le,createToolContributionProcessor as Re,sessionBridgePackage as ze,sessionOrchestratorPackage as Be,sessionPackage as Ve,sessionStoragePackage as He,toolRegistryPackage as Ue}from"@makaio/framework/services";import{AdapterSubsystemSubjects as We}from"@makaio/framework/services/adapter-subsystem";import{createClientsCorePackage as Ge}from"@makaio/framework/clients";import{resolveCredentialRef as Ke}from"@makaio/framework/adapters/config";import{AdapterSubsystemToken as F,createAdapterSubsystemContributionProcessor as qe,createAdapterSubsystemPackage as Je,orderAfterAdapterSubsystem as Ye}from"@makaio/framework/adapter-subsystem";import{execa as Xe}from"execa";import Ze from"piscina";import{ExecutionAttemptAuthority as Qe,WORKFLOW_WORKLOAD_KIND as $e,WORKFLOW_WORKLOAD_VERSION as et,WorkflowStorageSubjects as tt,buildWorkflowAttemptInstruction as nt,parseWorkflowAttemptInstruction as I,runAuthorityDispatchedAttempt as rt,toCommittedWorkflowRunnerCompletion as it}from"@makaio/framework/workflow-engine";import{runWorkflowOrchestrator as at}from"@makaio/framework/workflow-engine/workflow-orchestrator";import{setTimeout as ot}from"node:timers/promises";function st(e){return e.on(re.getCapabilities,async t=>{let{adapterName:n,adapterId:r}=t.payload;if(r){await t.next();return}if(n){let r=await e.requestOptional(ke.resolveId,{adapterName:n}),i=r.handled?r.data.adapterId:void 0;i&&(t.payload.adapterId=i)}await t.next()},{priority:20})}function ct(e){let{coordinator:t,configRepository:n,platformDefaults:r,prepareAuthRuntime:i,runtimeSnapshotHandlerPriority:a,runtimeDefinitionHandlerPriority:o}=e,s=Je({configRepository:n,coordinator:t,platformDefaults:r,...i!==void 0&&{prepareAuthRuntime:i},...a!==void 0&&{runtimeSnapshotHandlerPriority:a},...o!==void 0&&{runtimeDefinitionHandlerPriority:o}});return t.registerContributionProcessor(qe({getAdapterSubsystemService:()=>t.getExtensionService(F)})),{adapterSubsystemPackage:s}}function lt(e){let{bus:t,currentMachineId:n}=e,r=Ae(t,{currentMachineId:n,listKnownAdapterNames:e.listKnownAdapterNames??(async()=>{let{configs:e}=await t.request(We.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=st(t);return{cleanup:()=>{r.cleanup(),i()}}}function ut(e,t){if(!(e instanceof Error))return!1;let{rootPackageName:n,subpath:r}=ft(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"`)&&pt(e.message,n)?!0:i.some(t=>e.message.includes(t))}async function dt(e){try{return await import(e)}catch(t){if(ut(t,e))return null;throw t}}function ft(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 pt(e,t){let n=t,r=t.replaceAll(`/`,`\\`);return e.includes(`/${n}/package.json`)||e.includes(`\\${r}\\package.json`)}async function mt(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`?x.extname(e)===``?i:[``,...i]:[``];for(let t of r.split(x.delimiter)){let n=t.replace(/^"|"$/gu,``),r=x.resolve(n||process.cwd());for(let t of a){let n=x.join(r,`${e}${t}`);try{return await b(n,E.X_OK),n}catch{}}}}async function ht(e,t=5e3,n=1e3){let{stdout:r}=await Xe(e,[`--version`],{forceKillAfterDelay:n,timeout:t});return r}function gt(e){return e.match(/(\d+\.\d+\.\d+)/u)?.[1]??`unknown`}async function _t(e,t=mt,n=ht){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:gt(i)}}catch{return{binary:e,found:!1}}}async function vt(e,t=mt,n=ht){return Promise.all(e.map(e=>_t(e,t,n)))}var yt=class extends De{constructor(e){super(e)}onInit(){this.registerHandler(Me.scan,async e=>{let t=await vt(e.payload.binaries);e.setResult({results:t})})}};const bt={name:`makaio.cli-detection`,displayName:`CLI Detection`,version:`0.1.0`,critical:!0,surface:`any`,namespaces:[je],create:e=>new yt(e.bus)};var xt=t(((t,n)=>{var r=e(`constants`),i=process.cwd,a=null,o=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){return a||=i.call(process),a};try{process.cwd()}catch{}if(typeof process.chdir==`function`){var s=process.chdir;process.chdir=function(e){a=null,s.call(process,e)},Object.setPrototypeOf&&Object.setPrototypeOf(process.chdir,s)}n.exports=c;function c(e){r.hasOwnProperty(`O_SYMLINK`)&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&t(e),e.lutimes||n(e),e.chown=s(e.chown),e.fchown=s(e.fchown),e.lchown=s(e.lchown),e.chmod=i(e.chmod),e.fchmod=i(e.fchmod),e.lchmod=i(e.lchmod),e.chownSync=c(e.chownSync),e.fchownSync=c(e.fchownSync),e.lchownSync=c(e.lchownSync),e.chmodSync=a(e.chmodSync),e.fchmodSync=a(e.fchmodSync),e.lchmodSync=a(e.lchmodSync),e.stat=l(e.stat),e.fstat=l(e.fstat),e.lstat=l(e.lstat),e.statSync=u(e.statSync),e.fstatSync=u(e.fstatSync),e.lstatSync=u(e.lstatSync),e.chmod&&!e.lchmod&&(e.lchmod=function(e,t,n){n&&process.nextTick(n)},e.lchmodSync=function(){}),e.chown&&!e.lchown&&(e.lchown=function(e,t,n,r){r&&process.nextTick(r)},e.lchownSync=function(){}),o===`win32`&&(e.rename=typeof e.rename==`function`?(function(t){function n(n,r,i){var a=Date.now(),o=0;t(n,r,function s(c){if(c&&(c.code===`EACCES`||c.code===`EPERM`||c.code===`EBUSY`)&&Date.now()-a<6e4){setTimeout(function(){e.stat(r,function(e,a){e&&e.code===`ENOENT`?t(n,r,s):i(c)})},o),o<100&&(o+=10);return}i&&i(c)})}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n})(e.rename):e.rename),e.read=typeof e.read==`function`?(function(t){function n(n,r,i,a,o,s){var c;if(s&&typeof s==`function`){var l=0;c=function(u,d,f){if(u&&u.code===`EAGAIN`&&l<10)return l++,t.call(e,n,r,i,a,o,c);s.apply(this,arguments)}}return t.call(e,n,r,i,a,o,c)}return Object.setPrototypeOf&&Object.setPrototypeOf(n,t),n})(e.read):e.read,e.readSync=typeof e.readSync==`function`?(function(t){return function(n,r,i,a,o){for(var s=0;;)try{return t.call(e,n,r,i,a,o)}catch(e){if(e.code===`EAGAIN`&&s<10){s++;continue}throw e}}})(e.readSync):e.readSync;function t(e){e.lchmod=function(t,n,i){e.open(t,r.O_WRONLY|r.O_SYMLINK,n,function(t,r){if(t){i&&i(t);return}e.fchmod(r,n,function(t){e.close(r,function(e){i&&i(t||e)})})})},e.lchmodSync=function(t,n){var i=e.openSync(t,r.O_WRONLY|r.O_SYMLINK,n),a=!0,o;try{o=e.fchmodSync(i,n),a=!1}finally{if(a)try{e.closeSync(i)}catch{}else e.closeSync(i)}return o}}function n(e){r.hasOwnProperty(`O_SYMLINK`)&&e.futimes?(e.lutimes=function(t,n,i,a){e.open(t,r.O_SYMLINK,function(t,r){if(t){a&&a(t);return}e.futimes(r,n,i,function(t){e.close(r,function(e){a&&a(t||e)})})})},e.lutimesSync=function(t,n,i){var a=e.openSync(t,r.O_SYMLINK),o,s=!0;try{o=e.futimesSync(a,n,i),s=!1}finally{if(s)try{e.closeSync(a)}catch{}else e.closeSync(a)}return o}):e.futimes&&(e.lutimes=function(e,t,n,r){r&&process.nextTick(r)},e.lutimesSync=function(){})}function i(t){return t&&function(n,r,i){return t.call(e,n,r,function(e){d(e)&&(e=null),i&&i.apply(this,arguments)})}}function a(t){return t&&function(n,r){try{return t.call(e,n,r)}catch(e){if(!d(e))throw e}}}function s(t){return t&&function(n,r,i,a){return t.call(e,n,r,i,function(e){d(e)&&(e=null),a&&a.apply(this,arguments)})}}function c(t){return t&&function(n,r,i){try{return t.call(e,n,r,i)}catch(e){if(!d(e))throw e}}}function l(t){return t&&function(n,r,i){typeof r==`function`&&(i=r,r=null);function a(e,t){t&&(t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296)),i&&i.apply(this,arguments)}return r?t.call(e,n,r,a):t.call(e,n,a)}}function u(t){return t&&function(n,r){var i=r?t.call(e,n,r):t.call(e,n);return i&&(i.uid<0&&(i.uid+=4294967296),i.gid<0&&(i.gid+=4294967296)),i}}function d(e){return!e||e.code===`ENOSYS`||(!process.getuid||process.getuid()!==0)&&(e.code===`EINVAL`||e.code===`EPERM`)}}})),St=t(((t,n)=>{var r=e(`stream`).Stream;n.exports=i;function i(e){return{ReadStream:t,WriteStream:n};function t(n,i){if(!(this instanceof t))return new t(n,i);r.call(this);var a=this;this.path=n,this.fd=null,this.readable=!0,this.paused=!1,this.flags=`r`,this.mode=438,this.bufferSize=64*1024,i||={};for(var o=Object.keys(i),s=0,c=o.length;s<c;s++){var l=o[s];this[l]=i[l]}if(this.encoding&&this.setEncoding(this.encoding),this.start!==void 0){if(typeof this.start!=`number`)throw TypeError(`start must be a Number`);if(this.end===void 0)this.end=1/0;else if(typeof this.end!=`number`)throw TypeError(`end must be a Number`);if(this.start>this.end)throw Error(`start must be <= end`);this.pos=this.start}if(this.fd!==null){process.nextTick(function(){a._read()});return}e.open(this.path,this.flags,this.mode,function(e,t){if(e){a.emit(`error`,e),a.readable=!1;return}a.fd=t,a.emit(`open`,t),a._read()})}function n(t,i){if(!(this instanceof n))return new n(t,i);r.call(this),this.path=t,this.fd=null,this.writable=!0,this.flags=`w`,this.encoding=`binary`,this.mode=438,this.bytesWritten=0,i||={};for(var a=Object.keys(i),o=0,s=a.length;o<s;o++){var c=a[o];this[c]=i[c]}if(this.start!==void 0){if(typeof this.start!=`number`)throw TypeError(`start must be a Number`);if(this.start<0)throw Error(`start must be >= zero`);this.pos=this.start}this.busy=!1,this._queue=[],this.fd===null&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}}})),Ct=t(((e,t)=>{t.exports=r;var n=Object.getPrototypeOf||function(e){return e.__proto__};function r(e){if(typeof e!=`object`||!e)return e;if(e instanceof Object)var t={__proto__:n(e)};else var t=Object.create(null);return Object.getOwnPropertyNames(e).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}),t}})),wt=t(((t,n)=>{var r=e(`fs`),i=xt(),a=St(),o=Ct(),s=e(`util`),c,l;typeof Symbol==`function`&&typeof Symbol.for==`function`?(c=Symbol.for(`graceful-fs.queue`),l=Symbol.for(`graceful-fs.previous`)):(c=`___graceful-fs.queue`,l=`___graceful-fs.previous`);function u(){}function d(e,t){Object.defineProperty(e,c,{get:function(){return t}})}var f=u;s.debuglog?f=s.debuglog(`gfs4`):/\bgfs4\b/i.test(process.env.NODE_DEBUG||``)&&(f=function(){var e=s.format.apply(s,arguments);e=`GFS4: `+e.split(/\n/).join(`
|
|
2
|
+
GFS4: `),console.error(e)}),r[c]||(d(r,global[c]||[]),r.close=(function(e){function t(t,n){return e.call(r,t,function(e){e||g(),typeof n==`function`&&n.apply(this,arguments)})}return Object.defineProperty(t,l,{value:e}),t})(r.close),r.closeSync=(function(e){function t(t){e.apply(r,arguments),g()}return Object.defineProperty(t,l,{value:e}),t})(r.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||``)&&process.on(`exit`,function(){f(r[c]),e(`assert`).equal(r[c].length,0)})),global[c]||d(global,r[c]),n.exports=p(o(r)),process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!r.__patched&&(n.exports=p(r),r.__patched=!0);function p(e){i(e),e.gracefulify=p,e.createReadStream=te,e.createWriteStream=w;var t=e.readFile;e.readFile=n;function n(e,n,r){return typeof n==`function`&&(r=n,n=null),i(e,n,r);function i(e,n,r,a){return t(e,n,function(t){t&&(t.code===`EMFILE`||t.code===`ENFILE`)?m([i,[e,n,r],t,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var r=e.writeFile;e.writeFile=o;function o(e,t,n,i){return typeof n==`function`&&(i=n,n=null),a(e,t,n,i);function a(e,t,n,i,o){return r(e,t,n,function(r){r&&(r.code===`EMFILE`||r.code===`ENFILE`)?m([a,[e,t,n,i],r,o||Date.now(),Date.now()]):typeof i==`function`&&i.apply(this,arguments)})}}var s=e.appendFile;s&&(e.appendFile=c);function c(e,t,n,r){return typeof n==`function`&&(r=n,n=null),i(e,t,n,r);function i(e,t,n,r,a){return s(e,t,n,function(o){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var l=e.copyFile;l&&(e.copyFile=u);function u(e,t,n,r){return typeof n==`function`&&(r=n,n=0),i(e,t,n,r);function i(e,t,n,r,a){return l(e,t,n,function(o){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}var d=e.readdir;e.readdir=h;var f=/^v[0-5]\./;function h(e,t,n){typeof t==`function`&&(n=t,t=null);var r=f.test(process.version)?function(e,t,n,r){return d(e,i(e,t,n,r))}:function(e,t,n,r){return d(e,t,i(e,t,n,r))};return r(e,t,n);function i(e,t,n,i){return function(a,o){a&&(a.code===`EMFILE`||a.code===`ENFILE`)?m([r,[e,t,n],a,i||Date.now(),Date.now()]):(o&&o.sort&&o.sort(),typeof n==`function`&&n.call(this,a,o))}}}if(process.version.substr(0,4)===`v0.8`){var g=a(e);x=g.ReadStream,S=g.WriteStream}var _=e.ReadStream;_&&(x.prototype=Object.create(_.prototype),x.prototype.open=ee);var v=e.WriteStream;v&&(S.prototype=Object.create(v.prototype),S.prototype.open=C),Object.defineProperty(e,`ReadStream`,{get:function(){return x},set:function(e){x=e},enumerable:!0,configurable:!0}),Object.defineProperty(e,`WriteStream`,{get:function(){return S},set:function(e){S=e},enumerable:!0,configurable:!0});var y=x;Object.defineProperty(e,`FileReadStream`,{get:function(){return y},set:function(e){y=e},enumerable:!0,configurable:!0});var b=S;Object.defineProperty(e,`FileWriteStream`,{get:function(){return b},set:function(e){b=e},enumerable:!0,configurable:!0});function x(e,t){return this instanceof x?(_.apply(this,arguments),this):x.apply(Object.create(x.prototype),arguments)}function ee(){var e=this;E(e.path,e.flags,e.mode,function(t,n){t?(e.autoClose&&e.destroy(),e.emit(`error`,t)):(e.fd=n,e.emit(`open`,n),e.read())})}function S(e,t){return this instanceof S?(v.apply(this,arguments),this):S.apply(Object.create(S.prototype),arguments)}function C(){var e=this;E(e.path,e.flags,e.mode,function(t,n){t?(e.destroy(),e.emit(`error`,t)):(e.fd=n,e.emit(`open`,n))})}function te(t,n){return new e.ReadStream(t,n)}function w(t,n){return new e.WriteStream(t,n)}var T=e.open;e.open=E;function E(e,t,n,r){return typeof n==`function`&&(r=n,n=null),i(e,t,n,r);function i(e,t,n,r,a){return T(e,t,n,function(o,s){o&&(o.code===`EMFILE`||o.code===`ENFILE`)?m([i,[e,t,n,r],o,a||Date.now(),Date.now()]):typeof r==`function`&&r.apply(this,arguments)})}}return e}function m(e){f(`ENQUEUE`,e[0].name,e[1]),r[c].push(e),_()}var h;function g(){for(var e=Date.now(),t=0;t<r[c].length;++t)r[c][t].length>2&&(r[c][t][3]=e,r[c][t][4]=e);_()}function _(){if(clearTimeout(h),h=void 0,r[c].length!==0){var e=r[c].shift(),t=e[0],n=e[1],i=e[2],a=e[3],o=e[4];if(a===void 0)f(`RETRY`,t.name,n),t.apply(null,n);else if(Date.now()-a>=6e4){f(`TIMEOUT`,t.name,n);var s=n.pop();typeof s==`function`&&s.call(null,i)}else{var l=Date.now()-o,u=Math.max(o-a,1);l>=Math.min(u*1.2,100)?(f(`RETRY`,t.name,n),t.apply(null,n.concat([a]))):r[c].push(e)}h===void 0&&(h=setTimeout(_,0))}}})),Tt=t(((e,t)=>{function n(e,t){typeof t==`boolean`&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}t.exports=n,n.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},n.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timeouts=[],this._cachedTimeouts=null},n.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=new Date().getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.unshift(Error(`RetryOperation timeout occurred`)),!1;this._errors.push(e);var n=this._timeouts.shift();if(n===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),n=this._timeouts.shift();else return!1;var r=this,i=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},n);return this._options.unref&&i.unref(),!0},n.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){n._operationTimeoutCb()},n._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)},n.prototype.try=function(e){console.log(`Using RetryOperation.try() is deprecated`),this.attempt(e)},n.prototype.start=function(e){console.log(`Using RetryOperation.start() is deprecated`),this.attempt(e)},n.prototype.start=n.prototype.try,n.prototype.errors=function(){return this._errors},n.prototype.attempts=function(){return this._attempts},n.prototype.mainError=function(){if(this._errors.length===0)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var i=this._errors[r],a=i.message,o=(e[a]||0)+1;e[a]=o,o>=n&&(t=i,n=o)}return t}})),Et=t((e=>{var t=Tt();e.operation=function(n){return new t(e.timeouts(n),{forever:n&&n.forever,unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw Error(`minTimeout is greater than maxTimeout`);for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return e&&e.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(e,t){return e-t}),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*t.minTimeout*t.factor**+e);return r=Math.min(r,t.maxTimeout),r},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var i in r=[],t)typeof t[i]==`function`&&r.push(i);for(var a=0;a<r.length;a++){var o=r[a],s=t[o];t[o]=function(r){var i=e.operation(n),a=Array.prototype.slice.call(arguments,1),o=a.pop();a.push(function(e){i.retry(e)||(e&&(arguments[0]=i.mainError()),o.apply(this,arguments))}),i.attempt(function(){r.apply(t,a)})}.bind(t,s),t[o].options=n}}})),Dt=t(((e,t)=>{t.exports=Et()})),Ot=t(((e,t)=>{t.exports=[`SIGABRT`,`SIGALRM`,`SIGHUP`,`SIGINT`,`SIGTERM`],process.platform!==`win32`&&t.exports.push(`SIGVTALRM`,`SIGXCPU`,`SIGXFSZ`,`SIGUSR2`,`SIGTRAP`,`SIGSYS`,`SIGQUIT`,`SIGIOT`),process.platform===`linux`&&t.exports.push(`SIGIO`,`SIGPOLL`,`SIGPWR`,`SIGSTKFLT`,`SIGUNUSED`)})),kt=t(((t,n)=>{var r=global.process;let i=function(e){return e&&typeof e==`object`&&typeof e.removeListener==`function`&&typeof e.emit==`function`&&typeof e.reallyExit==`function`&&typeof e.listeners==`function`&&typeof e.kill==`function`&&typeof e.pid==`number`&&typeof e.on==`function`};if(!i(r))n.exports=function(){return function(){}};else{var a=e(`assert`),o=Ot(),s=/^win/i.test(r.platform),c=e(`events`);typeof c!=`function`&&(c=c.EventEmitter);var l;r.__signal_exit_emitter__?l=r.__signal_exit_emitter__:(l=r.__signal_exit_emitter__=new c,l.count=0,l.emitted={}),l.infinite||(l.setMaxListeners(1/0),l.infinite=!0),n.exports=function(e,t){if(!i(global.process))return function(){};a.equal(typeof e,`function`,`a callback must be provided for exit handler`),p===!1&&m();var n=`exit`;return t&&t.alwaysLast&&(n=`afterexit`),l.on(n,e),function(){l.removeListener(n,e),l.listeners(`exit`).length===0&&l.listeners(`afterexit`).length===0&&u()}};var u=function(){!p||!i(global.process)||(p=!1,o.forEach(function(e){try{r.removeListener(e,f[e])}catch{}}),r.emit=_,r.reallyExit=h,--l.count)};n.exports.unload=u;var d=function(e,t,n){l.emitted[e]||(l.emitted[e]=!0,l.emit(e,t,n))},f={};o.forEach(function(e){f[e]=function(){i(global.process)&&r.listeners(e).length===l.count&&(u(),d(`exit`,null,e),d(`afterexit`,null,e),s&&e===`SIGHUP`&&(e=`SIGINT`),r.kill(r.pid,e))}}),n.exports.signals=function(){return o};var p=!1,m=function(){p||!i(global.process)||(p=!0,l.count+=1,o=o.filter(function(e){try{return r.on(e,f[e]),!0}catch{return!1}}),r.emit=v,r.reallyExit=g)};n.exports.load=m;var h=r.reallyExit,g=function(e){i(global.process)&&(r.exitCode=e||0,d(`exit`,r.exitCode,null),d(`afterexit`,r.exitCode,null),h.call(r,r.exitCode))},_=r.emit,v=function(e,t){if(e===`exit`&&i(global.process)){t!==void 0&&(r.exitCode=t);var n=_.apply(this,arguments);return d(`exit`,r.exitCode,null),d(`afterexit`,r.exitCode,null),n}else return _.apply(this,arguments)}}})),At=t(((e,t)=>{let n=Symbol();function r(e,t,r){let i=t[n];if(i)return t.stat(e,(e,t)=>{if(e)return r(e);r(null,t.mtime,i)});let a=new Date(Math.ceil(Date.now()/1e3)*1e3+5);t.utimes(e,a,a,i=>{if(i)return r(i);t.stat(e,(e,i)=>{if(e)return r(e);let a=i.mtime.getTime()%1e3==0?`s`:`ms`;Object.defineProperty(t,n,{value:a}),r(null,i.mtime,a)})})}function i(e){let t=Date.now();return e===`s`&&(t=Math.ceil(t/1e3)*1e3),new Date(t)}t.exports.probe=r,t.exports.getMtime=i})),jt=t(((t,n)=>{let r=e(`path`),i=wt(),a=Dt(),o=kt(),s=At(),c={};function l(e,t){return t.lockfilePath||`${e}.lock`}function u(e,t,n){if(!t.realpath)return n(null,r.resolve(e));t.fs.realpath(e,n)}function d(e,t,n){let r=l(e,t);t.fs.mkdir(r,i=>{if(!i)return s.probe(r,t.fs,(e,i,a)=>{if(e)return t.fs.rmdir(r,()=>{}),n(e);n(null,i,a)});if(i.code!==`EEXIST`)return n(i);if(t.stale<=0)return n(Object.assign(Error(`Lock file is already being held`),{code:`ELOCKED`,file:e}));t.fs.stat(r,(r,i)=>{if(r)return r.code===`ENOENT`?d(e,{...t,stale:0},n):n(r);if(!f(i,t))return n(Object.assign(Error(`Lock file is already being held`),{code:`ELOCKED`,file:e}));p(e,t,r=>{if(r)return n(r);d(e,{...t,stale:0},n)})})})}function f(e,t){return e.mtime.getTime()<Date.now()-t.stale}function p(e,t,n){t.fs.rmdir(l(e,t),e=>{if(e&&e.code!==`ENOENT`)return n(e);n()})}function m(e,t){let n=c[e];n.updateTimeout||(n.updateDelay=n.updateDelay||t.update,n.updateTimeout=setTimeout(()=>{n.updateTimeout=null,t.fs.stat(n.lockfilePath,(r,i)=>{let a=n.lastUpdate+t.stale<Date.now();if(r)return r.code===`ENOENT`||a?h(e,n,Object.assign(r,{code:`ECOMPROMISED`})):(n.updateDelay=1e3,m(e,t));if(n.mtime.getTime()!==i.mtime.getTime())return h(e,n,Object.assign(Error(`Unable to update lock within the stale threshold`),{code:`ECOMPROMISED`}));let o=s.getMtime(n.mtimePrecision);t.fs.utimes(n.lockfilePath,o,o,r=>{let i=n.lastUpdate+t.stale<Date.now();if(!n.released){if(r)return r.code===`ENOENT`||i?h(e,n,Object.assign(r,{code:`ECOMPROMISED`})):(n.updateDelay=1e3,m(e,t));n.mtime=o,n.lastUpdate=Date.now(),n.updateDelay=null,m(e,t)}})})},n.updateDelay),n.updateTimeout.unref&&n.updateTimeout.unref())}function h(e,t,n){t.released=!0,t.updateTimeout&&clearTimeout(t.updateTimeout),c[e]===t&&delete c[e],t.options.onCompromised(n)}function g(e,t,n){t={stale:1e4,update:null,realpath:!0,retries:0,fs:i,onCompromised:e=>{throw e},...t},t.retries=t.retries||0,t.retries=typeof t.retries==`number`?{retries:t.retries}:t.retries,t.stale=Math.max(t.stale||0,2e3),t.update=t.update==null?t.stale/2:t.update||0,t.update=Math.max(Math.min(t.update,t.stale/2),1e3),u(e,t,(e,r)=>{if(e)return n(e);let i=a.operation(t.retries);i.attempt(()=>{d(r,t,(e,a,o)=>{if(i.retry(e))return;if(e)return n(i.mainError());let s=c[r]={lockfilePath:l(r,t),mtime:a,mtimePrecision:o,options:t,lastUpdate:Date.now()};m(r,t),n(null,e=>{if(s.released)return e&&e(Object.assign(Error(`Lock is already released`),{code:`ERELEASED`}));_(r,{...t,realpath:!1},e)})})})})}function _(e,t,n){t={fs:i,realpath:!0,...t},u(e,t,(e,r)=>{if(e)return n(e);let i=c[r];if(!i)return n(Object.assign(Error(`Lock is not acquired/owned by you`),{code:`ENOTACQUIRED`}));i.updateTimeout&&clearTimeout(i.updateTimeout),i.released=!0,delete c[r],p(r,t,n)})}function v(e,t,n){t={stale:1e4,realpath:!0,fs:i,...t},t.stale=Math.max(t.stale||0,2e3),u(e,t,(e,r)=>{if(e)return n(e);t.fs.stat(l(r,t),(e,r)=>e?e.code===`ENOENT`?n(null,!1):n(e):n(null,!f(r,t)))})}function y(){return c}o(()=>{for(let e in c){let t=c[e].options;try{t.fs.rmdirSync(l(e,t))}catch{}}}),n.exports.lock=g,n.exports.unlock=_,n.exports.check=v,n.exports.getLocks=y})),Mt=t(((e,t)=>{let n=wt();function r(e){let t=[`mkdir`,`realpath`,`stat`,`rmdir`,`utimes`],n={...e};return t.forEach(t=>{n[t]=(...n)=>{let r=n.pop(),i;try{i=e[`${t}Sync`](...n)}catch(e){return r(e)}r(null,i)}}),n}function i(e){return(...t)=>new Promise((n,r)=>{t.push((e,t)=>{e?r(e):n(t)}),e(...t)})}function a(e){return(...t)=>{let n,r;if(t.push((e,t)=>{n=e,r=t}),e(...t),n)throw n;return r}}function o(e){if(e={...e},e.fs=r(e.fs||n),typeof e.retries==`number`&&e.retries>0||e.retries&&typeof e.retries.retries==`number`&&e.retries.retries>0)throw Object.assign(Error(`Cannot use retries with the sync api`),{code:`ESYNC`});return e}t.exports={toPromise:i,toSync:a,toSyncOptions:o}})),Nt=t(((e,t)=>{let n=jt(),{toPromise:r,toSync:i,toSyncOptions:a}=Mt();async function o(e,t){return r(await r(n.lock)(e,t))}function s(e,t){return i(i(n.lock)(e,a(t)))}function c(e,t){return r(n.unlock)(e,t)}function l(e,t){return i(n.unlock)(e,a(t))}function u(e,t){return r(n.check)(e,t)}function d(e,t){return i(n.check)(e,a(t))}t.exports=o,t.exports.lock=o,t.exports.unlock=c,t.exports.lockSync=s,t.exports.unlockSync=l,t.exports.check=u,t.exports.checkSync=d}))();const Pt=[`config`,`extensions.json`],Ft={realpath:!1,stale:1e4,retries:{retries:50,factor:1.2,minTimeout:20,maxTimeout:200}},It=1024*1024;function L(e,t,n){return e.loadEnabled?.(t)!==!1||(n.critical??!1)}function Lt(e,t){return e.loadEnabled?.(t)===!1}function Rt(e){return x.join(e,...Pt)}async function zt(e){let t=Rt(e),{disabled:n,readFailure:r}=await Bt(t),i=new Set(n),a=Promise.resolve();return{readFailure:r,loadEnabled(e){return i.has(e)?!1:void 0},persistEnabled(e,n){let r=async()=>{await v.mkdir(x.dirname(t),{recursive:!0});let r=await(0,Nt.lock)(t,Ft);try{let{disabled:r,readFailure:i}=await Bt(t);if(i)throw Error(`Refusing to persist extension enablement for "${e}": the existing file at "${t}" could not be read (${i.reason}): ${i.diagnostic} Repair or delete the file, then retry.`);let a=new Set(r);n?a.delete(e):a.add(e),await Vt(t,[...a])}finally{await r()}n?i.delete(e):i.add(e)},o=a.then(r,r);return a=o.catch(()=>void 0),o}}}async function Bt(e){let t;try{let n=await v.stat(e);if(!n.isFile())return{disabled:[],readFailure:{reason:`unreadable`,diagnostic:`Enablement path at "${e}" is not a regular file; treating all extensions as enabled.`}};if(n.size>1048576)return{disabled:[],readFailure:{reason:`too-large`,diagnostic:`Enablement file at "${e}" exceeds ${It} bytes (${n.size} bytes); treating all extensions as enabled.`}};t=await v.readFile(e,`utf-8`)}catch(t){return t?.code===`ENOENT`?{disabled:[],readFailure:void 0}:{disabled:[],readFailure:{reason:`unreadable`,diagnostic:`Could not read enablement file at "${e}": ${ne(String(t))}`}}}let n;try{n=JSON.parse(t)}catch{return{disabled:[],readFailure:{reason:`not-json`,diagnostic:`Enablement file at "${e}" contains invalid JSON; treating all extensions as enabled.`}}}if(typeof n!=`object`||!n||Array.isArray(n))return{disabled:[],readFailure:{reason:`not-object`,diagnostic:`Enablement file at "${e}" is not a JSON object; treating all extensions as enabled.`}};let r=n;if(!(`disabled`in r))return{disabled:[],readFailure:void 0};let i=r.disabled;return!Array.isArray(i)||i.some(e=>typeof e!=`string`)?{disabled:[],readFailure:{reason:`invalid-disabled-field`,diagnostic:`Enablement file at "${e}" has a "disabled" field that is not a string array; treating all extensions as enabled.`}}:{disabled:i,readFailure:void 0}}async function Vt(e,t){let n=x.dirname(e);await v.mkdir(n,{recursive:!0});let r=t.length>0?{disabled:t}:{},i=`${JSON.stringify(r,null,2)}\n`,a=x.join(n,`.extensions-${process.pid}-${Date.now()}.json.tmp`);try{await v.writeFile(a,i,`utf-8`),await v.rename(a,e)}catch(e){throw await v.unlink(a).catch(()=>void 0),e}}function Ht(e,t){e.push(...Ut(t))}function Ut(e){return e===void 0?[]:typeof e==`function`?[e]:[...e]}function Wt(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 Gt(e=[]){return e.some(e=>typeof e==`string`&&e===`node`)?e:[`node`,...e]}function Kt(e){return Te(Ee(e.packages,e.surface,e.runtimeEnvironment))}function qt(e,t,r){let i=r??Jt(t),a=new Set(i.map(n));return e.filter(({ownerPackage:e})=>a.has(e)).map(({package:e})=>e)}function Jt(e){let{configProvider:t}=e,n=Kt(e);return R(t?n.filter(e=>L(t,e.name,e)):n,n)}function R(e,t){let n=new Set(t.map(e=>e.name)),r=new Map(e.map(e=>[e.name,e])),i=!0;for(;i;){i=!1;for(let e of r.values()){let t=(e.dependencies??[]).filter(e=>!e.optional&&n.has(e.name)&&!r.has(e.name));t.length!==0&&(r.delete(e.name),i=!0,console.warn(`[boot] Excluding extension "%s" from boot composition: required dependency %s is disabled`,e.name,t.map(e=>e.name).join(`, `)))}}return[...r.values()]}function Yt(e,t,n){return e.filter(e=>!t.has(e.name)||n.has(e.name)?!0:(console.warn(`[boot] Excluding extension "%s": a disabled override would replace core package %s; the core package stays active; the override applies after enabling and restart`,e.name,e.name),!1))}function Xt(e){let{bootEligibleExtensionPackages:t,configProvider:n,frameworkPackageNames:r}=e,i=n?t.filter(e=>L(n,e.name,e)):t,a=Yt(t,r,new Set(R(i,t).map(e=>e.name))),o=new Set(a.map(e=>e.name)),s=R(i.filter(e=>o.has(e.name)),a);return{mergeableExtensionPackages:a,extensionManagedPackageNames:o,effectiveEnabledBootPackages:s,effectiveEnabledPackageNames:new Set(s.map(e=>e.name))}}function Zt(e,t,n){return e.filter(e=>!t.has(e.name)||n.has(e.name))}function Qt(e,t){return e.filter(e=>ge(e.runtimeOwnership,t)).map(e=>e.name)}function $t(e,t){let n=Qt(e,t);if(n.length>1)throw Error(`Multiple extensions own runtimeOwnership.${t}: ${n.join(`, `)}`)}function en(e){return $t(e,`sessionOrchestrator`),Qt(e,`sessionOrchestrator`).length===0}function tn(e,t={}){let n=Ie(t);return e===!0||en(e)?n:n.filter(e=>e.name!==Ne.name)}function nn(e,t){if(!t.fileAccessRuleProvider)return;let n=e.find(e=>e.name===P.name||e.name===Pe.name);if(n)throw Error(`Extension "${n.displayName}" v${n.version} overrides the framework "${n.name}" package, but boot was given a fileAccessRuleProvider that is bound into that framework package. Remove or disable the extension, or boot without fileAccessRuleProvider.`)}function rn(e,t,n){let r=[];try{for(let i of e){let e=i.runtimeBoot;e&&Ht(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 an(){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)}const on=_(h);var z=class{async resolve(e){return e.startsWith(`stored:`)?(console.warn(`[NodeCredentialProvider] Cannot resolve "stored:" credential ref "${e}": Register a credential service handler on this host to enable stored credential resolution.`),null):Ke(e,{resolveKeychain:this.resolveKeychain,readFile:async e=>{try{return await y.readFile(e,`utf-8`)}catch(t){let n=t.code??`unknown error`;return console.warn(`[NodeCredentialProvider] Cannot read file credential at "${e}" (${n}). Returning null.`),``}}})}async resolveKeychain(e,t){try{let{stdout:n}=await on(`security`,[`find-generic-password`,`-s`,e,`-a`,t,`-w`]);return n.trim()||null}catch{return null}}},sn=class{bus;fallbackProvider=new z;channelPromise;constructor(e){this.bus=e}async resolve(e){let t=Oe(e);if(t){let{configId:n,key:r}=t;for(let t=0;t<2;t++){let i=this.getChannel();try{let t=await i;return t?(await t.request(ie.get,{configId:n})).credentials?.[r]??null:(console.warn(`[StoredCredentialProvider] Cannot resolve "stored:" credential ref "${e}": Register a credential service handler on this host to enable stored credential resolution.`),null)}catch(e){if(e instanceof ve&&(this.channelPromise===i&&(this.channelPromise=void 0),t===0))continue;throw e}}}return e.startsWith(`stored:`)?(console.warn(`[StoredCredentialProvider] Unresolvable credential ref "${e}". Only the "stored:providerConfig:" format is supported. Re-save the credential using the current format.`),null):this.fallbackProvider.resolve(e)}close(){let e=this.channelPromise;this.channelPromise=void 0,e!==void 0&&e.then(e=>{e?.close()}).catch(()=>{})}getChannel(){return this.channelPromise??=this.openCredentialChannel().then(e=>(e===null&&(this.channelPromise=void 0),e),e=>{throw this.channelPromise=void 0,e}),this.channelPromise}async openCredentialChannel(){let e=await this.bus.requestOptional(ie.getChannelToken,{});if(!e.handled)return null;let{token:t}=e.data;return xe(this.bus.getContext(),`credentials`,{token:t,transports:[]})}},cn=class{pool;constructor(e){this.pool=new Ze({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()}},B=class extends Error{code;constructor(e,t){super(e),this.code=t,this.name=`MaterializationError`}};function V(e,t,n){let r=x.resolve(t)+x.sep,i=x.resolve(e);if(i!==x.resolve(t)&&!i.startsWith(r))throw new B(`${n} escapes allowed root: ${e} is not within ${t}`,`containment-violation`)}async function H(e,t,n,r){let i=r??await v.realpath(t),a;try{a=await v.realpath(e)}catch{return e}let o=i+x.sep;if(a!==i&&!a.startsWith(o))throw new B(`${n} escapes allowed root via symlink: real path ${a} is not within ${i}`,`symlink-escape`);return a}function ln(e){let t=e.indexOf(`-`);if(t===-1)throw new B(`Invalid SRI integrity format: ${e}`,`contribution-integrity-mismatch`);return{algorithm:e.slice(0,t),digest:e.slice(t+1)}}async function un(e,t){let n=await v.readFile(e);return w.createHash(t).update(n).digest(`base64`)}const U=new Set([`.git`,`node_modules`]);function dn(e){return U.has(e.toLowerCase())}async function fn(e,t){let n=t.toLowerCase();if(!U.has(n))return!1;if(t===n)return!0;try{let[r,i]=await Promise.all([v.lstat(x.join(e,t)),v.lstat(x.join(e,n))]);return r.dev===i.dev&&r.ino===i.ino}catch(e){if(e.code===`ENOENT`)return!1;throw e}}const pn=U,mn=new Set([`.DS_Store`]);async function hn(e,t){let n=w.createHash(t),r=[];async function i(t){let n=await v.readdir(t,{withFileTypes:!0});for(let a of n){let n=x.join(t,a.name);if(a.isSymbolicLink())throw new B(`Contribution package contains a symbolic link: ${x.relative(e,n)}`,`symlink-escape`);if(a.isDirectory()){pn.has(a.name)||await i(n);continue}if(a.isFile()){mn.has(a.name)||r.push(x.relative(e,n));continue}throw new B(`Contribution package contains an unsupported filesystem entry: ${x.relative(e,n)}`,`contribution-integrity-mismatch`)}}await i(e),r.sort();for(let t of r)n.update(t.split(x.sep).join(`/`)),n.update(`\0`),n.update(await v.readFile(x.join(e,t))),n.update(`\0`);return`${t}-${n.digest(`base64`)}`}async function gn(e,t=`sha256`){let n=w.createHash(t),r=[];async function i(t){let n=await v.readdir(t,{withFileTypes:!0});for(let a of n){let n=x.join(t,a.name);if(!await fn(t,a.name)){if(a.isDirectory()){await i(n);continue}if(a.isFile()){r.push(x.relative(e,n));continue}throw a.isSymbolicLink()?new B(`Workspace root contains a symbolic link: ${x.relative(e,n)}`,`symlink-escape`):new B(`Workspace root contains an unsupported filesystem entry: ${x.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 v.readFile(x.join(e,t));n.update(r),n.update(`\0`)}return`${t}-${n.digest(`base64`)}`}async function _n(e,t,n){let r=x.join(t,`node_modules`,e.packageName);V(r,t,`Contribution package directory`),await H(r,t,`Contribution package directory`,n);let i=x.join(r,`package.json`),a;try{a=await v.readFile(i,`utf-8`)}catch{throw new B(`Contribution package not found: ${e.packageName} (expected at ${r})`,`contribution-missing`)}let o=JSON.parse(a);if(o.name!==e.packageName)throw new B(`Contribution identity mismatch: expected ${e.packageName}, found ${o.name??`<none>`}`,`contribution-missing`);if(o.version!==e.version)throw new B(`Contribution version mismatch for ${e.packageName}: expected ${e.version}, found ${o.version??`<none>`}`,`contribution-version-mismatch`);let s=x.join(r,e.entrypoint);V(s,r,`Contribution entrypoint`),await H(s,t,`Contribution entrypoint`,n);try{await v.access(s)}catch{throw new B(`Contribution entrypoint not found for ${e.packageName}: ${e.entrypoint}`,`contribution-entrypoint-mismatch`)}let{algorithm:c}=ln(e.integrity),l;try{l=await hn(r,c)}catch(t){if(t instanceof B)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 B(`Contribution package cannot be read for ${e.packageName}`,`contribution-entrypoint-mismatch`):t}if(l!==e.integrity)throw new B(`Contribution integrity mismatch for ${e.packageName}: expected ${e.integrity}, computed ${l}`,`contribution-integrity-mismatch`);return s}async function vn(e,t,n){let r=await n.resolveWorkspaceRoot(e.workspaceId);if(r===void 0)throw new B(`Unknown workspace ID: ${e.workspaceId}`,`unknown-workspace`);try{if(!(await v.stat(r)).isDirectory())throw new B(`Workspace root is not a directory: ${r}`,`containment-violation`)}catch(e){throw e instanceof B?e:new B(`Workspace root does not exist: ${r}`,`containment-violation`)}let i=await v.realpath(r),a=x.resolve(r,e.sourcePath);if(V(a,r,`Source path`),x.relative(r,a).split(x.sep).some(dn))throw new B(`Workflow source path selects excluded workspace content: ${e.sourcePath}`,`source-path-mismatch`);await H(a,r,`Source path`,i);let o=await gn(r);if(o!==e.rootDigest)throw new B(`Workspace root digest mismatch: expected ${e.rootDigest}, computed ${o}`,`digest-mismatch`);try{await v.access(a)}catch{throw new B(`Workflow source file not found: ${a}`,`source-missing`)}return{workspaceRoot:r,sourcePath:a,contributionEntrypoints:await Promise.all(t.map(e=>_n(e,r,i))),platform:process.platform,arch:process.arch}}var yn=class{options;manifest;pool;constructor(e){this.options=e,this.manifest=e.manifest}async run(e,t,n){this.pool??=new cn(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,n,r){this.pool??=new cn(this.options);let a=this.pool,o,s=!1,c,l=new Promise((t,n)=>{c=n,o=a.onMessage(n=>{d(n)&&n.executionAttemptId===r.executionAttemptId&&(n.executionId!==e.executionId||n.cancelSubject!==e.cancelSubject||(s=!0,o?.(),t(n)))})}),u=n??this.manifest,f=i(r.bootstrapDeadlineAt,t,async(t,n)=>{let i=await this.materializeTask(e,u,n);return a.run({...i,kind:`attempt-bound`,executionAttemptId:r.executionAttemptId,bootstrapDeadlineAt:r.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:l}}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 vn(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 bn(e){return e.mode===`source`?C(e.moduleDir,`workflow-worker`,`worker-entry.ts`):C(e.moduleDir,`workflow-worker`,`worker-entry.mjs`)}var xn=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=nt({id:T(),revision:`1`,config:e,...c==null?{}:{runContext:c},preservation:{required:[]}});return it(await rt({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)}},Sn=class{#e;constructor(e){this.#e=e.bus}async run(e,t,n){let r=me.parse(e),i=await a(r);return{state:`uncommitted`,result:await at({config:await u(r,i,this.#e,t),loaded:i,bus:this.#e,signal:t})}}};function Cn(){return{contributionRefs:[]}}function wn(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 Qe(e.executionAttemptRepository,{bootstrapTimeoutMs:n})}let n=ee(e.runtimeModuleDir)===`src`?`source`:`dist`,r=Tn({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 Tn(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 Sn({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(M.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 xn({dispatch:r,authority:e.authority,...n!==void 0&&{readRunContext:async(e,t)=>(await n.request(tt.getRunContext,{executionId:e},{signal:t})).runContext},...t.manifest!==void 0&&{manifest:t.manifest},...t.requirements!==void 0&&{requirements:t.requirements}})}case`piscina`:return new yn({workerEntry:t.workerEntry??bn({moduleDir:e.moduleDir,mode:t.workerEntryMode??e.defaultWorkerEntryMode}),manifest:t.manifest??Cn(),...t.resolveWorkspaceRoot!==void 0&&{resolveWorkspaceRoot:t.resolveWorkspaceRoot},maxConcurrency:t.maxConcurrency,idleTimeoutMs:t.idleTimeoutMs})}}const En=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`}},Dn=class extends Error{reason;constructor(e=`deadline-exceeded`){super(`Authority request delivery deadline exceeded`),this.reason=e,this.name=`AuthorityRequestDeliveryError`}};function On(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 kn(e,t){if(t===void 0){await new Promise(t=>setTimeout(t,e));return}let n=t;n.throwIfAborted(),await new Promise((t,r)=>{let i=setTimeout(o,e),a=()=>o(n.reason);function o(e){clearTimeout(i),n.removeEventListener(`abort`,a),e===void 0?t():r(e)}n.addEventListener(`abort`,a,{once:!0})})}async function An(e,t,n){n?.throwIfAborted();let r;try{r=e()}catch{return}await new Promise((e,i)=>{let a=setTimeout(s,t),o=()=>s(n?.reason);function s(t){clearTimeout(a),n?.removeEventListener(`abort`,o),t===void 0?e():i(t)}r.then(()=>s(),()=>s()),n?.addEventListener(`abort`,o,{once:!0}),n?.aborted&&o()})}async function jn(e,t,n,r,i){let a=t.baseDelayMs*2**(e-1),o=n-Date.now();await kn(Math.min(a,t.maxDelayMs,o),i);let s=n-Date.now();if(s<=0)return!1;if(r!==void 0)try{await An(r,s,i)}catch{i?.throwIfAborted()}return Date.now()<n}async function Mn(e,t,n,r){let i=On(n?.retry),a=n?.reconnect,o=n?.signal,s=Date.now()+i.deadlineMs,c;for(let n=0;n<=i.maxRetries;n++){if(o?.throwIfAborted(),s-Date.now()<=0||n>0&&!await jn(n,i,s,a,o))throw t();try{let n=s-Date.now();if(n<=0)throw t();return await e(n,o)}catch(e){if(o?.throwIfAborted(),r(e))throw e;if(c=e,Date.now()>=s)throw t()}}throw c??t()}async function K(e,t){return await Mn(e,()=>new Dn,t,()=>!1)}async function Nn(e,t,n){return await Mn(async(n,r)=>{let i=await e(n,r);if(En.has(i))return i;throw t(i)},()=>t(`deadline-exceeded`,`deadline-exceeded`),n,e=>e instanceof W||e instanceof G)}async function Pn(e,t,n){return await Nn(async(n,r)=>(await e.request(M.control.outcome.submit,{executionAttemptId:t.executionAttemptId,executionId:t.executionId,result:t.result},r===void 0?{timeout:n}:{timeout:n,signal:r})).decision,(e,n)=>n===void 0?new W(e,t.result):new W(e,t.result,n),n)}async function Fn(e,t,n){return await Nn(async(n,r)=>(await e.request(k.outcome.submit,t,r===void 0?{timeout:n}:{timeout:n,signal:r})).decision,(e,n)=>n===void 0?new G(e,t):new G(e,t,n),n)}const In={maxRetries:3,baseDelayMs:200,maxDelayMs:2e3,deadlineMs:1e4},Ln={persistentStorage:!0,customCapabilities:[`workflow.local-runtime`,`workflow.thin-runner`],suspensionStrategy:`wait-in-process`,supportsRecovery:!1,materializationModes:[`local-directory`]},Rn={code:`outcome-acknowledged`,summary:`Piscina runner settled and the Authority acknowledged its workflow outcome`},zn={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 Bn(e){let t=q(`[PiscinaThinWorkflowProvider] Infrastructure-conclusion`);return{conclude:n=>{t.publish(()=>({evidence:D.parse({source:e.slice(0,j.source),summary:n.slice(0,j.summary),observedAt:new Date().toISOString()})}))},observe:t.observe}}function Vn(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=D.parse({source:e.slice(0,j.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 Hn=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)}},Un=class{options;environment=`piscina`;allocationLifetime=`provisioner-process-bound`;baseCapabilities;constructor(e){this.options=e,this.baseCapabilities=ue.parse({...Ln,...e.baseCapabilities,suspensionStrategy:e.baseCapabilities?.suspensionStrategy??Ln.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=Bn(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=p({executionAttemptId:n,executionId:o}),d=!1,f=()=>{d||(d=!0,u.cleanup())};c=f;let m=Vn(this.id,f),h=new Hn(n,i,s,a,m.completion,m.localObservationLoss,f);t.throwIfAborted();let g=this.options.runner.runWithReadiness({...r,busAuth:{kind:`hmac`,secret:u.secret}},i.signal,e.runtimeInputs.workerManifest,{executionAttemptId:n,bootstrapDeadlineAt:e.bootstrapDeadlineAt});return g.ready.then(()=>this.submitOutcomeOnSettlement(g.result,o,n,r.workflowId,a.conclude,m.completion.complete),e=>{i.abort(e),g.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:h}}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:D.parse({source:`piscina-thin-workflow-provider`,code:se,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={...In,...this.options.outcomeRetry};await Pn(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(zn);return}a(Rn)}buildAllocationRef(e){let t={version:ce,providerId:this.id,providerData:{executionAttemptId:e,allocatedAt:Date.now()}};return le.parse(t)}};function Wn(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=I(r);if(i.executionId!==t.executionId)throw Error(`Workflow instruction execution '${i.executionId}' does not match Worker request '${t.executionId}'`);return me.parse({source:i.source,...i.definitionSnapshot===void 0?{}:{definition:i.definitionSnapshot},executionId:i.executionId,executionAttemptId:t.executionAttemptId,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 Gn=[He,ze,Ve];function Kn(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 qn(e,t,n){return lt({bus:e,currentMachineId:n,resolveLiveAdapterId:e=>t.getExtensionService(F)?.resolveLiveAdapterId(e),resolveLiveAdapterIdentity:e=>t.getExtensionService(F)?.resolveLiveAdapterIdentity(e),listLiveAdapterIdentities:()=>t.getExtensionService(F)?.getLiveAdapterIdentities()??[]})}async function Jn(e){let t=ye();t.registerNamespaces([...A,...ae]);let{context:n}=e,r=new Ce(t,{surface:`headless`,extensionContextBase:{cwd:n.cwd,platform:n.platform,homedir:n.homedir,makaioHome:n.makaioHome,username:n.username,machineId:n.machineId,tryImport:dt,credentials:new z}}),i,a=[()=>t.disconnect()],o=Kn(a);try{await e.connectAuthority(t);let s=[...e.contributedPackages,...await e.loadContributedPackages?.(t)??[]],{adapterSubsystemPackage:c}=ct({coordinator:r,configRepository:e.configRepository,platformDefaults:{cwd:n.cwd},runtimeSnapshotHandlerPriority:1,runtimeDefinitionHandlerPriority:1,...e.prepareAuthRuntime!==void 0&&{prepareAuthRuntime:e.prepareAuthRuntime}}),l=Ge({definitions:s.flatMap(e=>e.clients??[]),binaryResolutionPolicy:`global-only`});r.registerContributionProcessor(Re());let u=[...Gn,c,Fe,...en(s)?[Be]:[],Le(1),Ue,bt,l,...Ye(s)],d=r.load(u);a.push(...rn(d,t,r)),a.push(()=>r.shutdown()),await r.startAll(),i=qn(t,r,n.machineId),a.push(()=>{i?.cleanup(),i=void 0});let f=r.getExtensionService(P);if(f===void 0)throw Error(`Isolated workflow tool registry did not start.`);for(let t of e.toolsets)await f.register(t);return await t.emit(we.ready,{machineId:n.machineId}),{bus:t,coordinator:r,machineId:n.machineId,shutdown:o}}catch(e){throw await o().catch(()=>void 0),e}}function Yn(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 Xn(e){return typeof e==`object`&&!!e&&e.code===`ENOENT`}async function Zn(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 Qn(t)}catch(e){return Xn(e)?{alive:!0,psMissing:!0}:{alive:!0}}let i=!1;for(let t of r.trim().split(`
|
|
3
|
+
`)){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 Qn(e){return new Promise((t,n)=>{h(`ps`,[`-A`,`-o`,`pgid=,stat=`],{timeout:e,maxBuffer:1024*1024},(e,r)=>{if(e!==null){n(e);return}t(r)})})}async function $n(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 Zn(e,Math.min(1e3,i),r);if(!a.alive)return{quiesced:!0,signalledLiveGroup:t};r||=a.psMissing===!0,await ot(20)}return{quiesced:!1,cause:r?`ps-unavailable`:`poll-timeout`,signalledLiveGroup:t}}catch{return{quiesced:!1,cause:`signal-error`,signalledLiveGroup:t}}}function er(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 tr(e){if(e.signal?.aborted)return{status:`cancelled`,exitCode:null};if(!Yn(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 nr(e)}catch{return{status:`spawn-failed`,exitCode:null,message:`Could not start the setup command`}}}function nr(e){return new Promise(t=>{let n=g(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),$n(n.pid).then(e=>{t({status:e.quiesced?r??(o===0?`completed`:`failed`):`stop-failed`,exitCode:o,processGroup:n.pid===void 0?void 0:er(n.pid,a,e)})})})})}async function rr(e,t,n){if(x.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=x.join(r,i),V(r,e,`Source root`),await H(r,e,`Source root`,e),n&&await v.mkdir(r).catch(e=>{if(e.code!==`EEXIST`)throw e}),!(await v.stat(r)).isDirectory())throw Error(`Source root must be a directory`);return H(r,e,`Source root`,e)}async function ir(e){e.signal?.throwIfAborted();let{requirement:t}=e,n=x.resolve(e.workspaceRoot);if(!x.isAbsolute(e.workspaceRoot)||n===x.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 v.mkdir(n),!(await v.lstat(n)).isDirectory())throw Error(`Workspace root must be a directory, not a symlink`);let r=await v.realpath(n),i=[];for(let n of t.sourceRoots){let a=await rr(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 ar(t,{workspaceRoot:r,sourceRoots:i})}function ar(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 tr({...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():v.rm(n,{recursive:!0,force:!0}),o)}}}function Y(e,t){return e instanceof _e?be(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 or(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 sr(e,t){return Y(e,t)?{kind:`cancelled`}:{kind:`technical-failure`,stage:`workspace-preparation`,message:X(e)}}async function cr(e,t,n,r){let i=O[`instruction.get`].response.parse(await e.request(k.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 lr(e,t,n,r){let{executionAttemptId:i,runtimeGeneration:a}=t;t.control?.admissionPending();let o=O[`operation.admit`].response.parse(await K(async t=>await e.request(k.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 l(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 ur(e,t,n){try{return{operationId:await lr(e,t,n.operationKind,n.admissionKey)}}catch(r){if(!(r instanceof l&&r.refusalReason===`gate-closed`&&n.signal.aborted))throw r;return await Z(e,t,n.instruction,{kind:`cancelled`},void 0,n.workspace)}}function dr(e,t){return e.find(e=>e.kind===t.workload.kind&&e.version===t.workload.version)}function fr(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 Fn(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 pr(e,t,n,r){let i=O[`operation.report`].response.parse(await K(async i=>await e.request(k.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 mr(e,t,n,r){if(r.aborted)return await Z(e,t,n,{kind:`cancelled`},void 0,void 0);let i=await ur(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:ir}).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,sr(i,r),Q(a,c?`no-observation`:`not-started`),o)}let l=Q(a,s.processGroup??`no-spawn`);t.control?.operationConcluded(l);let u=or(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 pr(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 hr(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 mr(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 ur(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:oe.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 gr(e,t){let n;try{n=await cr(e,t.executionAttemptId,t.runtimeGeneration,t.signal)}catch(n){if(be(n,t.signal))return await Z(e,t,void 0,{kind:`cancelled`},void 0,void 0);throw n}let r=dr(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})??fr(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 hr(e,t,n,r,i)}finally{try{i.release()}catch{console.warn(`[makaio-worker] Workload control release failed.`)}}}const _r={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`},vr={"poll-timeout":`quiescence poll timed out`,"ps-unavailable":`ps unavailable on this host`,"signal-error":`a cleanup signal failed`};function yr(e){let t=_r[e.outcome];return e.cause===void 0?t:`${t} (${vr[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 br(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:xr(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`:Sr(n.operationId,r.setup,t)}function xr(e){let t=`no mutating operation admitted before cancellation`;return e===null?t:`${t}; admission refused (${e})`}function Sr(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:yr(t),observedAt:t.observedAt,code:t.outcome})}var Cr=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 wr(e){return!e.reportPending&&(e.lastReportStatus===void 0||e.lastReportStatus===`error`)}function Tr(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 Er(e,t,n,r,i){let a={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,n)=>e.request(k.control.report,a,{timeout:t,signal:n}),i===void 0?r:{...r,signal:i}),n=O[`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 Dr(e,t,n){let r=new Set,i;return{dispatch(a,o,s){if(n?.aborted===!0)return!1;let c=Er(e,a,o,t,n).then(e=>{i=e,r.delete(c),s(e)});return r.add(c),!0},async settle(){for(await new Promise(e=>setImmediate(e));r.size>0;)await Promise.allSettled([...r])},get lastReport(){return i}}}async function Or(e,t,n={}){let r=n.now??(()=>new Date),i=new Map,a=new AbortController,o=Dr(e,n.reportOptions,n.reportSignal);function s(e){if(!wr(e))return;let t=br(u.snapshot(),r());t!==`pending`&&o.dispatch(e.receipt,t,t=>{e.reportPending=!1,e.lastReportStatus=t.status})&&(e.reportPending=!0)}function l(e){let{controlRevision:t}=e.cancellation,n=i.get(t);if(n!==void 0)return setImmediate(()=>s(n)),n.receipt;let o={receipt:Tr(e,r()),reportPending:!1,lastReportStatus:void 0};return i.set(t,o),setImmediate(()=>{a.abort(),u.markCancelReceived(),s(o)}),o.receipt}let u=new Cr(()=>{for(let e of i.values())s(e)}),d=await c(e,t,e=>e.bus.on(k.control.deliver,async t=>{let n=O[`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:()=>o.settle(),get lastReport(){return o.lastReport}}}async function kr(e,t){t.throwIfAborted();let n=T(),r=await f(e.bootstrapDeadlineAt,t,t=>e.bootstrap(t)),{connection:i,endpoint:a}=await s({executionAttemptId:e.executionAttemptId,runtimeIncarnationId:n,bootstrapDeadlineAt:e.bootstrapDeadlineAt,signal:t,createConnection:()=>Ar(e,r)}),c=i.bus,l=new AbortController,u,d;try{d=await Or(c,{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:n},{reportOptions:{retry:e.outcomeRetry,reconnect:()=>c.reconnect()},reportSignal:l.signal,signal:t});let r=await o(c,{executionAttemptId:e.executionAttemptId,runtimeIncarnationId:n,signal:t});return a.bindGeneration(r),d.bindGeneration(r),u=await gr(c,{executionAttemptId:e.executionAttemptId,runtimeGeneration:r,workspaceRoot:e.workspaceRoot,setupEnv:e.setupEnv,preparation:e.preparation,adapters:e.adapters,signal:AbortSignal.any([t,d.signal]),control:d.observer,retry:e.outcomeRetry,reconnect:()=>c.reconnect()}),u}finally{try{d?.observer.finished(),d?.cleanup();let e,t=setTimeout(()=>{l.abort(),e=Promise.resolve(i.close()),e.catch(()=>{})},5e3);try{await d?.settle()}finally{clearTimeout(t)}a.cleanup(),await(e??i.close())}catch{}}}function Ar(e,t){let n=ye();return n.registerNamespaces([...A,...ae]),{bus:n,async connect(r){try{await e.connectBus(n,t,r),r.throwIfAborted()}catch(e){throw n.disconnect(),e}},close:()=>n.disconnect()}}async function jr(e,t,n,r,i){let a=de[`runtime.inputs.get`].response.parse(await e.request(M.runtime.inputs.get,{executionAttemptId:t},{signal:i}));if(a.runtimeInputs===null)throw Error(`Selected Worker Runtime inputs are unavailable`);return fe.parse({...n,...a.runtimeInputs,createdAt:0,env:r})}function Mr(e,t){let n=(e,t)=>{let n=te(e,t);return n===``||!S(n)&&n!==`..`&&!n.startsWith(`../`)&&!n.startsWith(`..\\`)};return n(e,t)||n(t,e)}async function Nr(e,t,n,i){let a=await e.loadContributions(n,i);i.throwIfAborted();let o=r();return await Jn({connectAuthority:n=>e.connectBus(n,t,i),contributedPackages:[...a],configRepository:e.configRepository,context:{cwd:n.workspaceRoot,platform:n.platform,homedir:o,makaioHome:o,username:`workflow-worker`,machineId:`headless-worker-${e.executionAttemptId}`},toolsets:[...e.toolsets],...e.prepareAuthRuntime!==void 0&&{prepareAuthRuntime:e.prepareAuthRuntime}})}function Pr(e,t,n){let r={...e.workflowEnv},i,a=!0;return{adapter:{kind:$e,version:et,async bindControl({instruction:t,signal:r}){let i=I(t);if(i.executionId!==e.executionId)throw Error(`Workflow instruction execution identity mismatch`);let a=new AbortController,o=n.on(he(i.cancelSubject),()=>a.abort());try{return await Se(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=I(o);a=o.preservation.required.length!==0;let u=c??new AbortController().signal,d;try{u.throwIfAborted();let a=await jr(n,e.executionAttemptId,l,r,u),o=await e.materialize(a,u);(s===void 0||!Mr(o.context.workspaceRoot,s.workspaceRoot))&&(i=o.cleanup);let c=Fr(o.context,s);return u.throwIfAborted(),d=await Nr(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 Fr(e,t){return t===void 0?e:{...e,workspaceRoot:t.workspaceRoot}}async function Ir(e,t){if(!(t.outcome.kind!==`workload-result`||e.onPostCommit===void 0))try{let n=pe.parse(t.outcome.result);await e.onPostCommit(n,t.decision)}catch{}}async function Lr(e,t){t.throwIfAborted();let n={...e.workflowEnv},r,i,a,o,s=async(t,n,a)=>{r=t,i=n,await e.connectBus(t,n,a)},c={kind:$e,version:et,async bindControl(t){if(r===void 0||i===void 0)throw Error(`Bus not yet connected when adapter control was bound`);return a=Pr({...e,workflowEnv:n},i,r),a.adapter.bindControl(t)},async invoke(e){if(a===void 0)throw Error(`Workflow adapter was not initialized via bindControl`);return a.adapter.invoke(e)}};try{return o=await kr({executionId:e.executionId,executionAttemptId:e.executionAttemptId,bootstrapDeadlineAt:e.bootstrapDeadlineAt,workflowEnv:e.workflowEnv,setupEnv:e.setupEnv,bootstrap:e.bootstrap,connectBus:s,workspaceRoot:e.workspaceRoot,preparation:e.preparation,adapters:[c],outcomeRetry:e.outcomeRetry},t),await Ir(e,o),o}finally{await a?.releaseExecutable(o)}}const Rr=_(h),zr=[`-c`,`core.attributesFile=${N}`],Br=m.object({repositoryId:m.string().min(1),revision:m.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i,`Git source revision must be a full commit object ID`)}).strict();async function Vr(e,t,n){try{let r=await e.resolveRepository(t,n);if(!x.isAbsolute(r))throw Error(`Repository access did not return an absolute path`);return await v.realpath(r)}catch(e){throw Y(e,n)?e:Error(`Git source access failed`)}}async function Hr(e,t,n,r,i){let a;try{a=(await Rr(`git`,[...zr,`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 Ur(e){if(!Yn(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=Br.parse(t.input),a=await Vr(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:N,GIT_CONFIG_SYSTEM:N,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 Hr(n,i.revision,o,e.timeoutMs,r);let a=await tr({workspaceRoot:n,signal:r,env:o,recipe:{command:`git`,args:[...zr,...t],env:{},timeoutMs:e.timeoutMs}});if(a.status===`cancelled`&&r?.throwIfAborted(),a.status!==`completed`)throw Error(`Git source ${t[0]} ${a.status}`)}}}function Wr(e){let t=Ur(e);return{prepare:e=>ir({...e,realizeSource:t})}}export{st as $,z as A,qt as B,H as C,vn as D,un as E,Xt as F,L as G,tn as H,Gt as I,bt as J,zt as K,an as L,nn as M,Wt as N,ln as O,Ht as P,ct as Q,rn as R,V as S,gn as T,It as U,Zt as V,Lt as W,dt as X,ut as Y,lt as Z,Sn as _,gr as a,yn as b,Un as c,En as d,W as f,wn as g,Tn as h,Or as i,sn as j,_n as k,G as l,Pn as m,Lr as n,Jn as o,Fn as p,Rt as q,kr as r,Wn as s,Wr as t,Dn as u,xn as v,hn as w,B as x,bn as y,Kt as z};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./ownership-recovery-guard-C9h8K1jo.mjs";import{SessionStorageSubjects as t}from"./services/session/storage/namespace.mjs";import"./session-Tj_635zr.mjs";import n from"node:path";import{lstatSync as r,realpathSync as i}from"node:fs";import{AgentSubjects as a,ApprovalSubjects as o,HarnessSubjects as s,ToolNameError as c,computeMetaTags as l,resolveToolPolicy as u,toolVocabularyForAdapter as d}from"@makaio/framework/contracts";import{BaseService as f}from"@makaio/framework/service-base";import{extractToolFilePath as p}from"@makaio/framework/tools";const m={"full-access":0,"always-ask":1,reject:2};function h(){return`apr_${crypto.randomUUID()}`}function g(e){switch(e){case`allow`:return`full-access`;case`deny`:return`reject`;case`ask`:return`always-ask`}}function _(e){if(!e?.length)return`neutral`;let t=l(e);return t.includes(`destructive`)?`destructive`:t.includes(`read-only`)?`safe`:`neutral`}function v(e,t){if(e)return t&&e.toolApprovalOverrides?.[t]!==void 0?e.toolApprovalOverrides[t]:e.approvalPolicy}function y(e,t,n,r){let i=r[t];if(!i?.length)return e;let a=e;for(let e of i){let t=n[e];t&&m[t]>m[a]&&(a=t)}return a}function b(e,t,n){return n.handled?n.data.allowedDirectories??void 0:t?[]:void 0}function x(e,t,n){if(!n||!e?.cwd)return{};let r;return(e.personaId||e.profileId)&&t&&(r=b(e.personaId,e.profileId,t)),{cwd:e.cwd,...r&&{allowedDirectories:r}}}function S(e,t,n){if(!(!e&&!t))return!n||!n.handled?{policy:`always-ask`}:{policy:g(n.data.action),...n.data.personaName&&{personaName:n.data.personaName},...n.data.profileName&&{profileName:n.data.profileName}}}function C(e,t,n,r){if(!t||!e)return{kind:`none`};let{allowedTools:i,disallowedTools:a}=e;if(i===void 0&&a===void 0)return{kind:`none`};let o=d(e.adapterName);if(o===void 0)return{kind:`none`};let s;try{s=u(o,{allowedTools:i,disallowedTools:a})}catch(e){if(e instanceof c)return{kind:`deny`,message:e.message};throw e}let l=s.checkToolCall(t,n??{});if(!l.allowed)return{kind:`deny`,message:l.reason};if(i===void 0)return{kind:`none`};let f=T(e,r);return f!==void 0&&!D(f,t,n,e.cwd)?{kind:`none`}:{kind:`granted`}}const w=new Set([`Glob`,`Grep`]);function T(e,t){if(e.allowedDirectories!==void 0)return e.allowedDirectories;if((e.personaId||e.profileId)&&t)return b(e.personaId,e.profileId,t)}function E(e){let t=e;for(;;)try{return n.resolve(i(t),n.relative(t,e))}catch(e){if(e.code!==`ENOENT`||r(t,{throwIfNoEntry:!1})!==void 0)return;let i=n.dirname(t);if(i===t)return;t=i}}function D(e,t,r,i){if(!i)return!1;let a=r?.path,o=w.has(t)?n.resolve(i,typeof a==`string`&&a.length>0?a:`.`):p(t,r,i);if(o===null)return!1;let s=E(o);if(s===void 0)return!1;let c=e=>process.platform===`win32`?e.toLowerCase():e;return e.some(e=>{let t=E(n.resolve(i,e));if(t===void 0)return!1;let r=n.relative(c(t),c(s));return r===``||r!==`..`&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)})}function O(e,t){let n=t.harness?.toolCapabilityMap&&e.toolName?t.harness.toolCapabilityMap[e.toolName]:void 0;return{requestId:h(),toolCallId:e.toolCallId,toolName:e.toolName,args:e.args,agentId:e.agentId,sessionId:e.sessionId,adapterName:t.resolvedAdapterName,...t.personaName&&{personaName:t.personaName},...t.profileName&&{profileName:t.profileName},capabilities:n,riskLevel:_(n),reasoning:e.reasoning,createdAt:Date.now()}}function k(e,t,n,r){return n===`always-ask`?`always-ask`:e===`reject`?`reject`:r?`always-ask`:t.kind===`granted`?`full-access`:e}var A=class extends f{logger=console;options;constructor(e,t={}){super(e),this.options=t}async onInit(){this.registerHandler(a.toolApprove,async e=>{let t=await this.getAgentMetadata(e.payload.agentId,e.payload.sessionId),n=t.kind===`found`?t.agent:null,r=t.kind===`error`,i=(n?.personaId||n?.profileId)&&e.payload.toolName?await this.fetchRawEnrichedPolicy(n?.personaId,n?.profileId,e.payload.toolName):void 0,a=x(n,i,this.options.fileAccessRuleProvider),o=await this.checkFileAccessDenyReason(e.payload,a);if(o){e.setResult({action:`deny`,message:o,shouldAbort:!1});return}let s=await this.resolveSessionOverride(e.payload.sessionId);if(s===`reject`){e.setResult({action:`deny`,message:`Tool use rejected by session approval policy override`,shouldAbort:!1});return}let c=C(n,e.payload.toolName,e.payload.args,i);if(c.kind===`deny`){e.setResult({action:`deny`,message:c.message,shouldAbort:!1});return}if(s===`full-access`&&!r){e.setResult({action:`allow`});return}let l=await this.resolvePolicyWithContext({adapterName:e.payload.adapterName,toolName:e.payload.toolName},n,i);switch(k(l.policy,c,s,r)){case`full-access`:e.setResult({action:`allow`});return;case`reject`:e.setResult({action:`deny`,message:`Tool use rejected by approval policy`,shouldAbort:!1});return;case`always-ask`:await this.dispatchAlwaysAskApproval(e.payload,e.setResult.bind(e),l);return}})}async dispatchAlwaysAskApproval(e,t,n){let r=O(e,n),i=new AbortController,s=this.bus.on(a.session.closed,()=>{i.abort()},{filter:{agentId:r.agentId,...e.adapterSessionId!==void 0&&{adapterSessionId:e.adapterSessionId}}});try{let e=await this.bus.requestOptional(o.request,r,{timeout:0,signal:i.signal});e.handled&&e.data.action===`allow`?t({action:`allow`,...e.data.updatedInput&&{updatedInput:e.data.updatedInput}}):t({action:`deny`,message:e.handled&&e.data.action===`deny`?e.data.message??`User denied tool execution`:`No approval handler available`,shouldAbort:!1})}catch{t({action:`deny`,message:i.signal.aborted?`Approval cancelled — agent session closed`:`Tool approval request failed`,shouldAbort:!1})}finally{s()}}async checkFileAccessDenyReason(e,t){if(!this.options.fileAccessRuleProvider||!t.cwd)return;let n=p(e.toolName,e.args,t.cwd);if(n)try{return(await this.options.fileAccessRuleProvider(t.cwd,t.allowedDirectories)).isDenied(n)?`Access denied: '${n}' is restricted by .makaioignore rules`:void 0}catch{return`Access denied: file access rules could not be evaluated`}}async fetchRawEnrichedPolicy(e,t,n){try{return await this.bus.requestOptional(o.resolveEnrichedPolicy,{toolName:n,personaId:e,profileId:t})}catch(r){return this.logger.error(`[ToolApprovalService] approval.resolveEnrichedPolicy failed; falling back to fail-closed`,{toolName:n,personaId:e,profileId:t,error:r}),{handled:!1}}}async resolvePolicyWithContext(e,t,n){let r=t?.adapterName??e.adapterName,i=S(t?.personaId,t?.profileId,n),a=await this.resolveHarnessPolicy(r,t?.harnessId,t?.clientId),o=v(a,e.toolName),s=i?.policy??o??`always-ask`,c=s;return a?.capabilityOverrides&&a.toolCapabilityMap&&e.toolName&&(c=y(s,e.toolName,a.capabilityOverrides,a.toolCapabilityMap)),{policy:c,harness:a,agent:t,resolvedAdapterName:r,...i?.personaName&&{personaName:i.personaName},...i?.profileName&&{profileName:i.profileName}}}async getAgentMetadata(t,n){try{let r;if(n){let i=await this.bus.requestOptional(e.listBySession,{sessionId:n});r=i.handled?i.data.agents.find(e=>e.agentId===t):void 0}else{let n=await this.bus.requestOptional(e.get,{agentId:t});r=n.handled?n.data.agent:void 0}return r?{kind:`found`,agent:r}:{kind:`absent`}}catch(e){return this.logger.warn(`[ToolApprovalService] agent lookup failed; forcing always-ask`,{agentId:t,sessionId:n,error:e}),{kind:`error`}}}async resolveSessionOverride(e){if(e)try{let n=await this.bus.requestOptional(t.get,{sessionId:e});return n.handled?n.data.session?.approvalPolicyOverride??void 0:void 0}catch{return}}async resolveHarnessPolicy(e,t,n){try{let r=await this.bus.request(s.resolve,{adapterName:e,...t&&{profileHarnessId:t},...n&&{clientId:n}});return{approvalPolicy:r.approvalPolicy,capabilityOverrides:r.capabilityOverrides,toolCapabilityMap:r.toolCapabilityMap,toolApprovalOverrides:r.toolApprovalOverrides}}catch{return}}};export{A as t};
|