@tasker-systems/tasker 0.1.0-alpha.1

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.
@@ -0,0 +1,1945 @@
1
+ import { existsSync } from 'fs';
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __esm = (fn, res) => function __init() {
16
+ return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
17
+ };
18
+ var __commonJS2 = (cb, mod3) => function __require2() {
19
+ return mod3 || (0, cb[__getOwnPropNames2(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames2(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ __defProp(target, "default", { value: mod3, enumerable: true }) ,
39
+ mod3
40
+ ));
41
+
42
+ // src/ffi/runtime-interface.ts
43
+ var BaseTaskerRuntime;
44
+ var init_runtime_interface = __esm({
45
+ "src/ffi/runtime-interface.ts"() {
46
+ BaseTaskerRuntime = class {
47
+ /**
48
+ * Helper to parse JSON string from FFI
49
+ */
50
+ parseJson(jsonStr) {
51
+ if (jsonStr === null || jsonStr === "") {
52
+ return null;
53
+ }
54
+ try {
55
+ return JSON.parse(jsonStr);
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
60
+ /**
61
+ * Helper to stringify JSON for FFI
62
+ */
63
+ toJson(value) {
64
+ return JSON.stringify(value);
65
+ }
66
+ };
67
+ }
68
+ });
69
+
70
+ // node_modules/koffi/build/koffi/darwin_arm64/koffi.node
71
+ var koffi_default;
72
+ var init_koffi = __esm({
73
+ "node_modules/koffi/build/koffi/darwin_arm64/koffi.node"() {
74
+ koffi_default = "../koffi-X7JMBSZH.node";
75
+ }
76
+ });
77
+
78
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/darwin_arm64/koffi.node
79
+ var require_koffi = __commonJS2({
80
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/darwin_arm64/koffi.node"(exports2, module2) {
81
+ init_koffi();
82
+ try {
83
+ module2.exports = __require(koffi_default);
84
+ } catch {
85
+ }
86
+ }
87
+ });
88
+
89
+ // node_modules/koffi/build/koffi/darwin_x64/koffi.node
90
+ var koffi_default2;
91
+ var init_koffi2 = __esm({
92
+ "node_modules/koffi/build/koffi/darwin_x64/koffi.node"() {
93
+ koffi_default2 = "../koffi-OMHWL3D6.node";
94
+ }
95
+ });
96
+
97
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/darwin_x64/koffi.node
98
+ var require_koffi2 = __commonJS2({
99
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/darwin_x64/koffi.node"(exports2, module2) {
100
+ init_koffi2();
101
+ try {
102
+ module2.exports = __require(koffi_default2);
103
+ } catch {
104
+ }
105
+ }
106
+ });
107
+
108
+ // node_modules/koffi/build/koffi/freebsd_arm64/koffi.node
109
+ var koffi_default3;
110
+ var init_koffi3 = __esm({
111
+ "node_modules/koffi/build/koffi/freebsd_arm64/koffi.node"() {
112
+ koffi_default3 = "../koffi-AVDVVSXH.node";
113
+ }
114
+ });
115
+
116
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/freebsd_arm64/koffi.node
117
+ var require_koffi3 = __commonJS2({
118
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/freebsd_arm64/koffi.node"(exports2, module2) {
119
+ init_koffi3();
120
+ try {
121
+ module2.exports = __require(koffi_default3);
122
+ } catch {
123
+ }
124
+ }
125
+ });
126
+
127
+ // node_modules/koffi/build/koffi/freebsd_ia32/koffi.node
128
+ var koffi_default4;
129
+ var init_koffi4 = __esm({
130
+ "node_modules/koffi/build/koffi/freebsd_ia32/koffi.node"() {
131
+ koffi_default4 = "../koffi-GG4SDSYA.node";
132
+ }
133
+ });
134
+
135
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/freebsd_ia32/koffi.node
136
+ var require_koffi4 = __commonJS2({
137
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/freebsd_ia32/koffi.node"(exports2, module2) {
138
+ init_koffi4();
139
+ try {
140
+ module2.exports = __require(koffi_default4);
141
+ } catch {
142
+ }
143
+ }
144
+ });
145
+
146
+ // node_modules/koffi/build/koffi/freebsd_x64/koffi.node
147
+ var koffi_default5;
148
+ var init_koffi5 = __esm({
149
+ "node_modules/koffi/build/koffi/freebsd_x64/koffi.node"() {
150
+ koffi_default5 = "../koffi-AHHUCM3C.node";
151
+ }
152
+ });
153
+
154
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/freebsd_x64/koffi.node
155
+ var require_koffi5 = __commonJS2({
156
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/freebsd_x64/koffi.node"(exports2, module2) {
157
+ init_koffi5();
158
+ try {
159
+ module2.exports = __require(koffi_default5);
160
+ } catch {
161
+ }
162
+ }
163
+ });
164
+
165
+ // node_modules/koffi/build/koffi/linux_armhf/koffi.node
166
+ var koffi_default6;
167
+ var init_koffi6 = __esm({
168
+ "node_modules/koffi/build/koffi/linux_armhf/koffi.node"() {
169
+ koffi_default6 = "../koffi-YNQDUF3Q.node";
170
+ }
171
+ });
172
+
173
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_armhf/koffi.node
174
+ var require_koffi6 = __commonJS2({
175
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_armhf/koffi.node"(exports2, module2) {
176
+ init_koffi6();
177
+ try {
178
+ module2.exports = __require(koffi_default6);
179
+ } catch {
180
+ }
181
+ }
182
+ });
183
+
184
+ // node_modules/koffi/build/koffi/linux_arm64/koffi.node
185
+ var koffi_default7;
186
+ var init_koffi7 = __esm({
187
+ "node_modules/koffi/build/koffi/linux_arm64/koffi.node"() {
188
+ koffi_default7 = "../koffi-SE4ZI36U.node";
189
+ }
190
+ });
191
+
192
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_arm64/koffi.node
193
+ var require_koffi7 = __commonJS2({
194
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_arm64/koffi.node"(exports2, module2) {
195
+ init_koffi7();
196
+ try {
197
+ module2.exports = __require(koffi_default7);
198
+ } catch {
199
+ }
200
+ }
201
+ });
202
+
203
+ // node_modules/koffi/build/koffi/linux_ia32/koffi.node
204
+ var koffi_default8;
205
+ var init_koffi8 = __esm({
206
+ "node_modules/koffi/build/koffi/linux_ia32/koffi.node"() {
207
+ koffi_default8 = "../koffi-LOH6WKRQ.node";
208
+ }
209
+ });
210
+
211
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_ia32/koffi.node
212
+ var require_koffi8 = __commonJS2({
213
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_ia32/koffi.node"(exports2, module2) {
214
+ init_koffi8();
215
+ try {
216
+ module2.exports = __require(koffi_default8);
217
+ } catch {
218
+ }
219
+ }
220
+ });
221
+
222
+ // node_modules/koffi/build/koffi/linux_loong64/koffi.node
223
+ var koffi_default9;
224
+ var init_koffi9 = __esm({
225
+ "node_modules/koffi/build/koffi/linux_loong64/koffi.node"() {
226
+ koffi_default9 = "../koffi-QKY2KSXW.node";
227
+ }
228
+ });
229
+
230
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_loong64/koffi.node
231
+ var require_koffi9 = __commonJS2({
232
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_loong64/koffi.node"(exports2, module2) {
233
+ init_koffi9();
234
+ try {
235
+ module2.exports = __require(koffi_default9);
236
+ } catch {
237
+ }
238
+ }
239
+ });
240
+
241
+ // node_modules/koffi/build/koffi/linux_riscv64d/koffi.node
242
+ var koffi_default10;
243
+ var init_koffi10 = __esm({
244
+ "node_modules/koffi/build/koffi/linux_riscv64d/koffi.node"() {
245
+ koffi_default10 = "../koffi-X3YT67KE.node";
246
+ }
247
+ });
248
+
249
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_riscv64d/koffi.node
250
+ var require_koffi10 = __commonJS2({
251
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_riscv64d/koffi.node"(exports2, module2) {
252
+ init_koffi10();
253
+ try {
254
+ module2.exports = __require(koffi_default10);
255
+ } catch {
256
+ }
257
+ }
258
+ });
259
+
260
+ // node_modules/koffi/build/koffi/linux_x64/koffi.node
261
+ var koffi_default11;
262
+ var init_koffi11 = __esm({
263
+ "node_modules/koffi/build/koffi/linux_x64/koffi.node"() {
264
+ koffi_default11 = "../koffi-G4D35B2D.node";
265
+ }
266
+ });
267
+
268
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_x64/koffi.node
269
+ var require_koffi11 = __commonJS2({
270
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/linux_x64/koffi.node"(exports2, module2) {
271
+ init_koffi11();
272
+ try {
273
+ module2.exports = __require(koffi_default11);
274
+ } catch {
275
+ }
276
+ }
277
+ });
278
+
279
+ // node_modules/koffi/build/koffi/openbsd_ia32/koffi.node
280
+ var koffi_default12;
281
+ var init_koffi12 = __esm({
282
+ "node_modules/koffi/build/koffi/openbsd_ia32/koffi.node"() {
283
+ koffi_default12 = "../koffi-LUY2JHJP.node";
284
+ }
285
+ });
286
+
287
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/openbsd_ia32/koffi.node
288
+ var require_koffi12 = __commonJS2({
289
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/openbsd_ia32/koffi.node"(exports2, module2) {
290
+ init_koffi12();
291
+ try {
292
+ module2.exports = __require(koffi_default12);
293
+ } catch {
294
+ }
295
+ }
296
+ });
297
+
298
+ // node_modules/koffi/build/koffi/openbsd_x64/koffi.node
299
+ var koffi_default13;
300
+ var init_koffi13 = __esm({
301
+ "node_modules/koffi/build/koffi/openbsd_x64/koffi.node"() {
302
+ koffi_default13 = "../koffi-ROB3FRHA.node";
303
+ }
304
+ });
305
+
306
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/openbsd_x64/koffi.node
307
+ var require_koffi13 = __commonJS2({
308
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/openbsd_x64/koffi.node"(exports2, module2) {
309
+ init_koffi13();
310
+ try {
311
+ module2.exports = __require(koffi_default13);
312
+ } catch {
313
+ }
314
+ }
315
+ });
316
+
317
+ // node_modules/koffi/build/koffi/win32_arm64/koffi.node
318
+ var koffi_default14;
319
+ var init_koffi14 = __esm({
320
+ "node_modules/koffi/build/koffi/win32_arm64/koffi.node"() {
321
+ koffi_default14 = "../koffi-GOENU54R.node";
322
+ }
323
+ });
324
+
325
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/win32_arm64/koffi.node
326
+ var require_koffi14 = __commonJS2({
327
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/win32_arm64/koffi.node"(exports2, module2) {
328
+ init_koffi14();
329
+ try {
330
+ module2.exports = __require(koffi_default14);
331
+ } catch {
332
+ }
333
+ }
334
+ });
335
+
336
+ // node_modules/koffi/build/koffi/win32_ia32/koffi.node
337
+ var koffi_default15;
338
+ var init_koffi15 = __esm({
339
+ "node_modules/koffi/build/koffi/win32_ia32/koffi.node"() {
340
+ koffi_default15 = "../koffi-KFZAXWPQ.node";
341
+ }
342
+ });
343
+
344
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/win32_ia32/koffi.node
345
+ var require_koffi15 = __commonJS2({
346
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/win32_ia32/koffi.node"(exports2, module2) {
347
+ init_koffi15();
348
+ try {
349
+ module2.exports = __require(koffi_default15);
350
+ } catch {
351
+ }
352
+ }
353
+ });
354
+
355
+ // node_modules/koffi/build/koffi/win32_x64/koffi.node
356
+ var koffi_default16;
357
+ var init_koffi16 = __esm({
358
+ "node_modules/koffi/build/koffi/win32_x64/koffi.node"() {
359
+ koffi_default16 = "../koffi-IDX6JEDH.node";
360
+ }
361
+ });
362
+
363
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/win32_x64/koffi.node
364
+ var require_koffi16 = __commonJS2({
365
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/win32_x64/koffi.node"(exports2, module2) {
366
+ init_koffi16();
367
+ try {
368
+ module2.exports = __require(koffi_default16);
369
+ } catch {
370
+ }
371
+ }
372
+ });
373
+
374
+ // node_modules/koffi/build/koffi/musl_arm64/koffi.node
375
+ var koffi_default17;
376
+ var init_koffi17 = __esm({
377
+ "node_modules/koffi/build/koffi/musl_arm64/koffi.node"() {
378
+ koffi_default17 = "../koffi-3HFAASOB.node";
379
+ }
380
+ });
381
+
382
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/musl_arm64/koffi.node
383
+ var require_koffi17 = __commonJS2({
384
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/musl_arm64/koffi.node"(exports2, module2) {
385
+ init_koffi17();
386
+ try {
387
+ module2.exports = __require(koffi_default17);
388
+ } catch {
389
+ }
390
+ }
391
+ });
392
+
393
+ // node_modules/koffi/build/koffi/musl_x64/koffi.node
394
+ var koffi_default18;
395
+ var init_koffi18 = __esm({
396
+ "node_modules/koffi/build/koffi/musl_x64/koffi.node"() {
397
+ koffi_default18 = "../koffi-BMO5K7B3.node";
398
+ }
399
+ });
400
+
401
+ // node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/musl_x64/koffi.node
402
+ var require_koffi18 = __commonJS2({
403
+ "node-file:/Users/petetaylor/projects/tasker-systems/tasker-core/workers/typescript/node_modules/koffi/build/koffi/musl_x64/koffi.node"(exports2, module2) {
404
+ init_koffi18();
405
+ try {
406
+ module2.exports = __require(koffi_default18);
407
+ } catch {
408
+ }
409
+ }
410
+ });
411
+
412
+ // node_modules/koffi/index.js
413
+ var require_koffi19 = __commonJS2({
414
+ "node_modules/koffi/index.js"(exports$1, module) {
415
+ var __getOwnPropNames = Object.getOwnPropertyNames;
416
+ var __commonJS = (cb, mod3) => function __require2() {
417
+ return mod3 || (0, cb[__getOwnPropNames(cb)[0]])((mod3 = { exports: {} }).exports, mod3), mod3.exports;
418
+ };
419
+ var require_tools = __commonJS({
420
+ "bin/Koffi/package/src/cnoke/src/tools.js"(exports2, module2) {
421
+ var crypto = __require("crypto");
422
+ var fs2 = __require("fs");
423
+ var http = __require("https");
424
+ var path2 = __require("path");
425
+ var zlib = __require("zlib");
426
+ async function download_http(url, dest) {
427
+ console.log(">> Downloading " + url);
428
+ let [tmp_name, file] = open_temporary_stream(dest);
429
+ try {
430
+ await new Promise((resolve, reject) => {
431
+ let request = http.get(url, (response) => {
432
+ if (response.statusCode != 200) {
433
+ let err = new Error(`Download failed: ${response.statusMessage} [${response.statusCode}]`);
434
+ err.code = response.statusCode;
435
+ reject(err);
436
+ return;
437
+ }
438
+ response.pipe(file);
439
+ file.on("finish", () => file.close(() => {
440
+ try {
441
+ fs2.renameSync(file.path, dest);
442
+ } catch (err) {
443
+ if (!fs2.existsSync(dest))
444
+ reject(err);
445
+ }
446
+ resolve();
447
+ }));
448
+ });
449
+ request.on("error", reject);
450
+ file.on("error", reject);
451
+ });
452
+ } catch (err) {
453
+ file.close();
454
+ try {
455
+ fs2.unlinkSync(tmp_name);
456
+ } catch (err2) {
457
+ if (err2.code != "ENOENT")
458
+ throw err2;
459
+ }
460
+ throw err;
461
+ }
462
+ }
463
+ function open_temporary_stream(prefix) {
464
+ let buf = Buffer.allocUnsafe(4);
465
+ for (; ; ) {
466
+ try {
467
+ crypto.randomFillSync(buf);
468
+ let suffix = buf.toString("hex").padStart(8, "0");
469
+ let filename2 = `${prefix}.${suffix}`;
470
+ let file = fs2.createWriteStream(filename2, { flags: "wx", mode: 420 });
471
+ return [filename2, file];
472
+ } catch (err) {
473
+ if (err.code != "EEXIST")
474
+ throw err;
475
+ }
476
+ }
477
+ }
478
+ function extract_targz(filename2, dest_dir, strip = 0) {
479
+ let reader = fs2.createReadStream(filename2).pipe(zlib.createGunzip());
480
+ return new Promise((resolve, reject) => {
481
+ let header = null;
482
+ let extended = {};
483
+ reader.on("readable", () => {
484
+ try {
485
+ for (; ; ) {
486
+ if (header == null) {
487
+ let buf = reader.read(512);
488
+ if (buf == null)
489
+ break;
490
+ if (!buf[0])
491
+ continue;
492
+ header = {
493
+ filename: buf.toString("utf-8", 0, 100).replace(/\0/g, ""),
494
+ mode: parseInt(buf.toString("ascii", 100, 109), 8),
495
+ size: parseInt(buf.toString("ascii", 124, 137), 8),
496
+ type: String.fromCharCode(buf[156])
497
+ };
498
+ Object.assign(header, extended);
499
+ extended = {};
500
+ header.filename = header.filename.replace(/\\/g, "/");
501
+ if (!header.filename.length)
502
+ throw new Error(`Insecure empty filename inside TAR archive`);
503
+ if (path_is_absolute(header.filename[0]))
504
+ throw new Error(`Insecure filename starting with / inside TAR archive`);
505
+ if (path_has_dotdot(header.filename))
506
+ throw new Error(`Insecure filename containing '..' inside TAR archive`);
507
+ for (let i = 0; i < strip; i++)
508
+ header.filename = header.filename.substr(header.filename.indexOf("/") + 1);
509
+ }
510
+ let aligned = Math.floor((header.size + 511) / 512) * 512;
511
+ let data = header.size ? reader.read(aligned) : null;
512
+ if (data == null) {
513
+ if (header.size)
514
+ break;
515
+ data = Buffer.alloc(0);
516
+ }
517
+ data = data.subarray(0, header.size);
518
+ if (header.type == "0" || header.type == "7") {
519
+ let filename3 = dest_dir + "/" + header.filename;
520
+ let dirname = path2.dirname(filename3);
521
+ fs2.mkdirSync(dirname, { recursive: true, mode: 493 });
522
+ fs2.writeFileSync(filename3, data, { mode: header.mode });
523
+ } else if (header.type == "5") {
524
+ let filename3 = dest_dir + "/" + header.filename;
525
+ fs2.mkdirSync(filename3, { recursive: true, mode: header.mode });
526
+ } else if (header.type == "L") {
527
+ extended.filename = data.toString("utf-8").replace(/\0/g, "");
528
+ } else if (header.type == "x") {
529
+ let str = data.toString("utf-8");
530
+ try {
531
+ while (str.length) {
532
+ let matches = str.match(/^([0-9]+) ([a-zA-Z0-9\._]+)=(.*)\n/);
533
+ let skip = parseInt(matches[1], 10);
534
+ let key = matches[2];
535
+ let value = matches[3];
536
+ switch (key) {
537
+ case "path":
538
+ {
539
+ extended.filename = value;
540
+ }
541
+ break;
542
+ case "size":
543
+ {
544
+ extended.size = parseInt(value, 10);
545
+ }
546
+ break;
547
+ }
548
+ str = str.substr(skip).trimStart();
549
+ }
550
+ } catch (err) {
551
+ throw new Error("Malformed PAX entry");
552
+ }
553
+ }
554
+ header = null;
555
+ }
556
+ } catch (err) {
557
+ reject(err);
558
+ }
559
+ });
560
+ reader.on("error", reject);
561
+ reader.on("end", resolve);
562
+ });
563
+ }
564
+ function path_is_absolute(path3) {
565
+ if (process.platform == "win32" && path3.match(/^[a-zA-Z]:/))
566
+ path3 = path3.substr(2);
567
+ return is_path_separator(path3[0]);
568
+ }
569
+ function path_has_dotdot(path3) {
570
+ let start = 0;
571
+ for (; ; ) {
572
+ let offset = path3.indexOf("..", start);
573
+ if (offset < 0)
574
+ break;
575
+ start = offset + 2;
576
+ if (offset && !is_path_separator(path3[offset - 1]))
577
+ continue;
578
+ if (offset + 2 < path3.length && !is_path_separator(path3[offset + 2]))
579
+ continue;
580
+ return true;
581
+ }
582
+ return false;
583
+ }
584
+ function is_path_separator(c) {
585
+ if (c == "/")
586
+ return true;
587
+ if (process.platform == "win32" && c == "\\")
588
+ return true;
589
+ return false;
590
+ }
591
+ function sync_files(src_dir, dest_dir) {
592
+ let keep = /* @__PURE__ */ new Set();
593
+ {
594
+ let entries = fs2.readdirSync(src_dir, { withFileTypes: true });
595
+ for (let entry of entries) {
596
+ if (!entry.isFile())
597
+ continue;
598
+ keep.add(entry.name);
599
+ fs2.copyFileSync(src_dir + `/${entry.name}`, dest_dir + `/${entry.name}`);
600
+ }
601
+ }
602
+ {
603
+ let entries = fs2.readdirSync(dest_dir, { withFileTypes: true });
604
+ for (let entry of entries) {
605
+ if (!entry.isFile())
606
+ continue;
607
+ if (keep.has(entry.name))
608
+ continue;
609
+ fs2.unlinkSync(dest_dir + `/${entry.name}`);
610
+ }
611
+ }
612
+ }
613
+ function determine_arch2() {
614
+ let arch = process.arch;
615
+ if (arch == "riscv32" || arch == "riscv64") {
616
+ let buf = read_file_header(process.execPath, 512);
617
+ let header = decode_elf_header(buf);
618
+ let float_abi = header.e_flags & 6;
619
+ switch (float_abi) {
620
+ case 0:
621
+ break;
622
+ case 2:
623
+ {
624
+ arch += "f";
625
+ }
626
+ break;
627
+ case 4:
628
+ {
629
+ arch += "d";
630
+ }
631
+ break;
632
+ case 6:
633
+ {
634
+ arch += "q";
635
+ }
636
+ break;
637
+ }
638
+ } else if (arch == "arm") {
639
+ let buf = read_file_header(process.execPath, 512);
640
+ let header = decode_elf_header(buf);
641
+ if (header.e_flags & 1024) {
642
+ arch += "hf";
643
+ } else if (header.e_flags & 512) {
644
+ arch += "sf";
645
+ } else {
646
+ throw new Error("Unknown ARM floating-point ABI");
647
+ }
648
+ }
649
+ return arch;
650
+ }
651
+ function read_file_header(filename2, read) {
652
+ try {
653
+ let fd2 = fs2.openSync(filename2);
654
+ let buf = Buffer.allocUnsafe(read);
655
+ let len = fs2.readSync(fd2, buf);
656
+ return buf.subarray(0, len);
657
+ } finally {
658
+ }
659
+ }
660
+ function decode_elf_header(buf) {
661
+ let header = {};
662
+ if (buf.length < 16)
663
+ throw new Error("Truncated header");
664
+ if (buf[0] != 127 || buf[1] != 69 || buf[2] != 76 || buf[3] != 70)
665
+ throw new Error("Invalid magic number");
666
+ if (buf[6] != 1)
667
+ throw new Error("Invalid ELF version");
668
+ if (buf[5] != 1)
669
+ throw new Error("Big-endian architectures are not supported");
670
+ let machine = buf.readUInt16LE(18);
671
+ switch (machine) {
672
+ case 3:
673
+ {
674
+ header.e_machine = "ia32";
675
+ }
676
+ break;
677
+ case 40:
678
+ {
679
+ header.e_machine = "arm";
680
+ }
681
+ break;
682
+ case 62:
683
+ {
684
+ header.e_machine = "amd64";
685
+ }
686
+ break;
687
+ case 183:
688
+ {
689
+ header.e_machine = "arm64";
690
+ }
691
+ break;
692
+ case 243:
693
+ {
694
+ switch (buf[4]) {
695
+ case 1:
696
+ {
697
+ header.e_machine = "riscv32";
698
+ }
699
+ break;
700
+ case 2:
701
+ {
702
+ header.e_machine = "riscv64";
703
+ }
704
+ break;
705
+ }
706
+ }
707
+ break;
708
+ case 248:
709
+ {
710
+ switch (buf[4]) {
711
+ case 1:
712
+ {
713
+ header.e_machine = "loong32";
714
+ }
715
+ break;
716
+ case 2:
717
+ {
718
+ header.e_machine = "loong64";
719
+ }
720
+ break;
721
+ }
722
+ }
723
+ break;
724
+ default:
725
+ throw new Error("Unknown ELF machine type");
726
+ }
727
+ switch (buf[4]) {
728
+ case 1:
729
+ {
730
+ buf = buf.subarray(0, 68);
731
+ if (buf.length < 68)
732
+ throw new Error("Truncated ELF header");
733
+ header.ei_class = 32;
734
+ header.e_flags = buf.readUInt32LE(36);
735
+ }
736
+ break;
737
+ case 2:
738
+ {
739
+ buf = buf.subarray(0, 120);
740
+ if (buf.length < 120)
741
+ throw new Error("Truncated ELF header");
742
+ header.ei_class = 64;
743
+ header.e_flags = buf.readUInt32LE(48);
744
+ }
745
+ break;
746
+ default:
747
+ throw new Error("Invalid ELF class");
748
+ }
749
+ return header;
750
+ }
751
+ function unlink_recursive(path3) {
752
+ try {
753
+ if (fs2.rmSync != null) {
754
+ fs2.rmSync(path3, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
755
+ } else {
756
+ fs2.rmdirSync(path3, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
757
+ }
758
+ } catch (err) {
759
+ if (err.code !== "ENOENT")
760
+ throw err;
761
+ }
762
+ }
763
+ function get_napi_version2(napi, major) {
764
+ if (napi > 8)
765
+ return null;
766
+ const support = {
767
+ 6: ["6.14.2", "6.14.2", "6.14.2"],
768
+ 8: ["8.6.0", "8.10.0", "8.11.2"],
769
+ 9: ["9.0.0", "9.3.0", "9.11.0"],
770
+ 10: ["10.0.0", "10.0.0", "10.0.0", "10.16.0", "10.17.0", "10.20.0", "10.23.0"],
771
+ 11: ["11.0.0", "11.0.0", "11.0.0", "11.8.0"],
772
+ 12: ["12.0.0", "12.0.0", "12.0.0", "12.0.0", "12.11.0", "12.17.0", "12.19.0", "12.22.0"],
773
+ 13: ["13.0.0", "13.0.0", "13.0.0", "13.0.0", "13.0.0"],
774
+ 14: ["14.0.0", "14.0.0", "14.0.0", "14.0.0", "14.0.0", "14.0.0", "14.12.0", "14.17.0"],
775
+ 15: ["15.0.0", "15.0.0", "15.0.0", "15.0.0", "15.0.0", "15.0.0", "15.0.0", "15.12.0"]
776
+ };
777
+ const max = Math.max(...Object.keys(support).map((k) => parseInt(k, 10)));
778
+ if (major > max)
779
+ return major + ".0.0";
780
+ if (support[major] == null)
781
+ return null;
782
+ let required = support[major][napi - 1] || null;
783
+ return required;
784
+ }
785
+ function cmp_version(ver1, ver2) {
786
+ ver1 = String(ver1).replace(/-.*$/, "").split(".").reduce((acc, v, idx) => acc + parseInt(v, 10) * Math.pow(10, 2 * (5 - idx)), 0);
787
+ ver2 = String(ver2).replace(/-.*$/, "").split(".").reduce((acc, v, idx) => acc + parseInt(v, 10) * Math.pow(10, 2 * (5 - idx)), 0);
788
+ let cmp = Math.min(Math.max(ver1 - ver2, -1), 1);
789
+ return cmp;
790
+ }
791
+ module2.exports = {
792
+ download_http,
793
+ extract_targz,
794
+ path_is_absolute,
795
+ path_has_dotdot,
796
+ sync_files,
797
+ determine_arch: determine_arch2,
798
+ unlink_recursive,
799
+ get_napi_version: get_napi_version2,
800
+ cmp_version
801
+ };
802
+ }
803
+ });
804
+ var require_package = __commonJS({
805
+ "bin/Koffi/package/src/koffi/package.json"(exports2, module2) {
806
+ module2.exports = {
807
+ name: "koffi",
808
+ version: "2.15.0",
809
+ description: "Fast and simple C FFI (foreign function interface) for Node.js",
810
+ keywords: [
811
+ "foreign",
812
+ "function",
813
+ "interface",
814
+ "ffi",
815
+ "binding",
816
+ "c",
817
+ "napi"
818
+ ],
819
+ repository: {
820
+ type: "git",
821
+ url: "https://github.com/Koromix/koffi"
822
+ },
823
+ homepage: "https://koffi.dev/",
824
+ author: {
825
+ name: "Niels Martign\xE8ne",
826
+ email: "niels.martignene@protonmail.com",
827
+ url: "https://koromix.dev/"
828
+ },
829
+ main: "./index.js",
830
+ types: "./index.d.ts",
831
+ scripts: {
832
+ test: "node tools/koffi.js test",
833
+ prepack: `echo 'Use "npm run package" instead' && false`,
834
+ prepublishOnly: `echo 'Use "npm run package" instead' && false`,
835
+ package: "node tools/koffi.js build"
836
+ },
837
+ license: "MIT",
838
+ cnoke: {
839
+ api: "../../vendor/node-api-headers",
840
+ output: "../../bin/Koffi/{{ platform }}_{{ arch }}",
841
+ node: 16,
842
+ napi: 8,
843
+ require: "./index.js"
844
+ },
845
+ funding: "https://buymeacoffee.com/koromix"
846
+ };
847
+ }
848
+ });
849
+ var require_init = __commonJS({
850
+ "bin/Koffi/package/src/koffi/src/init.js"(exports$1, module) {
851
+ var fs = __require("fs");
852
+ var path = __require("path");
853
+ var util = __require("util");
854
+ var { get_napi_version, determine_arch } = require_tools();
855
+ var pkg = require_package();
856
+ function detect() {
857
+ if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
858
+ let major = parseInt(process.versions.node, 10);
859
+ let required = get_napi_version(pkg.cnoke.napi, major);
860
+ if (required != null) {
861
+ throw new Error(`This engine is based on Node ${process.versions.node}, but ${pkg.name} requires Node >= ${required} in the Node ${major}.x branch (N-API >= ${pkg.cnoke.napi})`);
862
+ } else {
863
+ throw new Error(`This engine is based on Node ${process.versions.node}, but ${pkg.name} does not support the Node ${major}.x branch (N-API < ${pkg.cnoke.napi})`);
864
+ }
865
+ }
866
+ let arch = determine_arch();
867
+ let triplet3 = `${process.platform}_${arch}`;
868
+ return triplet3;
869
+ }
870
+ function init(triplet, native) {
871
+ if (native == null) {
872
+ let roots = [path.join(__dirname, "..")];
873
+ let triplets = [triplet];
874
+ if (process.resourcesPath != null)
875
+ roots.push(process.resourcesPath);
876
+ if (triplet.startsWith("linux_")) {
877
+ let musl = triplet.replace(/^linux_/, "musl_");
878
+ triplets.push(musl);
879
+ }
880
+ let filenames = roots.flatMap((root) => triplets.flatMap((triplet3) => [
881
+ `${root}/build/koffi/${triplet3}/koffi.node`,
882
+ `${root}/koffi/${triplet3}/koffi.node`,
883
+ `${root}/node_modules/koffi/build/koffi/${triplet3}/koffi.node`,
884
+ `${root}/../../bin/Koffi/${triplet3}/koffi.node`
885
+ ]));
886
+ let first_err = null;
887
+ for (let filename of filenames) {
888
+ if (!fs.existsSync(filename))
889
+ continue;
890
+ try {
891
+ native = eval("require")(filename);
892
+ } catch (err) {
893
+ if (first_err == null)
894
+ first_err = err;
895
+ continue;
896
+ }
897
+ break;
898
+ }
899
+ if (first_err != null)
900
+ throw first_err;
901
+ }
902
+ if (native == null)
903
+ throw new Error("Cannot find the native Koffi module; did you bundle it correctly?");
904
+ if (native.version != pkg.version)
905
+ throw new Error("Mismatched native Koffi modules");
906
+ let mod = wrap(native);
907
+ return mod;
908
+ }
909
+ function wrap(native3) {
910
+ let obj = {
911
+ ...native3,
912
+ // Deprecated functions
913
+ handle: util.deprecate(native3.opaque, "The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead", "KOFFI001"),
914
+ callback: util.deprecate(native3.proto, "The koffi.callback() function was deprecated in Koffi 2.4, use koffi.proto() instead", "KOFFI002")
915
+ };
916
+ obj.load = (...args) => {
917
+ let lib = native3.load(...args);
918
+ lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
919
+ lib.stdcall = util.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
920
+ lib.fastcall = util.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
921
+ lib.thiscall = util.deprecate((...args2) => lib.func("__thiscall", ...args2), 'The koffi.thiscall() function was deprecated in Koffi 2.7, use koffi.func("__thiscall", ...) instead', "KOFFI006");
922
+ return lib;
923
+ };
924
+ return obj;
925
+ }
926
+ module.exports = {
927
+ detect,
928
+ init
929
+ };
930
+ }
931
+ });
932
+ var { detect: detect2, init: init2 } = require_init();
933
+ var triplet2 = detect2();
934
+ var native2 = null;
935
+ try {
936
+ switch (triplet2) {
937
+ case "darwin_arm64":
938
+ {
939
+ native2 = require_koffi();
940
+ }
941
+ break;
942
+ case "darwin_x64":
943
+ {
944
+ native2 = require_koffi2();
945
+ }
946
+ break;
947
+ case "freebsd_arm64":
948
+ {
949
+ native2 = require_koffi3();
950
+ }
951
+ break;
952
+ case "freebsd_ia32":
953
+ {
954
+ native2 = require_koffi4();
955
+ }
956
+ break;
957
+ case "freebsd_x64":
958
+ {
959
+ native2 = require_koffi5();
960
+ }
961
+ break;
962
+ case "linux_armhf":
963
+ {
964
+ native2 = require_koffi6();
965
+ }
966
+ break;
967
+ case "linux_arm64":
968
+ {
969
+ native2 = require_koffi7();
970
+ }
971
+ break;
972
+ case "linux_ia32":
973
+ {
974
+ native2 = require_koffi8();
975
+ }
976
+ break;
977
+ case "linux_loong64":
978
+ {
979
+ native2 = require_koffi9();
980
+ }
981
+ break;
982
+ case "linux_riscv64d":
983
+ {
984
+ native2 = require_koffi10();
985
+ }
986
+ break;
987
+ case "linux_x64":
988
+ {
989
+ native2 = require_koffi11();
990
+ }
991
+ break;
992
+ case "openbsd_ia32":
993
+ {
994
+ native2 = require_koffi12();
995
+ }
996
+ break;
997
+ case "openbsd_x64":
998
+ {
999
+ native2 = require_koffi13();
1000
+ }
1001
+ break;
1002
+ case "win32_arm64":
1003
+ {
1004
+ native2 = require_koffi14();
1005
+ }
1006
+ break;
1007
+ case "win32_ia32":
1008
+ {
1009
+ native2 = require_koffi15();
1010
+ }
1011
+ break;
1012
+ case "win32_x64":
1013
+ {
1014
+ native2 = require_koffi16();
1015
+ }
1016
+ break;
1017
+ }
1018
+ } catch {
1019
+ try {
1020
+ switch (triplet2) {
1021
+ case "linux_arm64":
1022
+ {
1023
+ native2 = require_koffi17();
1024
+ }
1025
+ break;
1026
+ case "linux_x64":
1027
+ {
1028
+ native2 = require_koffi18();
1029
+ }
1030
+ break;
1031
+ }
1032
+ } catch {
1033
+ }
1034
+ }
1035
+ var mod2 = init2(triplet2, native2);
1036
+ module.exports = mod2;
1037
+ }
1038
+ });
1039
+
1040
+ // src/ffi/node-runtime.ts
1041
+ var node_runtime_exports = {};
1042
+ __export(node_runtime_exports, {
1043
+ NodeRuntime: () => NodeRuntime
1044
+ });
1045
+ var NodeRuntime;
1046
+ var init_node_runtime = __esm({
1047
+ "src/ffi/node-runtime.ts"() {
1048
+ init_runtime_interface();
1049
+ NodeRuntime = class extends BaseTaskerRuntime {
1050
+ name = "node";
1051
+ lib = null;
1052
+ // biome-ignore lint/suspicious/noExplicitAny: koffi module type
1053
+ koffi = null;
1054
+ get isLoaded() {
1055
+ return this.lib !== null;
1056
+ }
1057
+ async load(libraryPath) {
1058
+ if (this.lib !== null) {
1059
+ return;
1060
+ }
1061
+ const koffiModule = await Promise.resolve().then(() => __toESM(require_koffi19()));
1062
+ this.koffi = koffiModule.default ?? koffiModule;
1063
+ const lib = this.koffi.load(libraryPath);
1064
+ this.lib = {
1065
+ get_version: lib.func("void* get_version()"),
1066
+ get_rust_version: lib.func("void* get_rust_version()"),
1067
+ health_check: lib.func("int health_check()"),
1068
+ is_worker_running: lib.func("int is_worker_running()"),
1069
+ bootstrap_worker: lib.func("void* bootstrap_worker(str)"),
1070
+ get_worker_status: lib.func("void* get_worker_status()"),
1071
+ stop_worker: lib.func("void* stop_worker()"),
1072
+ transition_to_graceful_shutdown: lib.func("void* transition_to_graceful_shutdown()"),
1073
+ poll_step_events: lib.func("void* poll_step_events()"),
1074
+ poll_in_process_events: lib.func("void* poll_in_process_events()"),
1075
+ complete_step_event: lib.func("int complete_step_event(str, str)"),
1076
+ checkpoint_yield_step_event: lib.func("int checkpoint_yield_step_event(str, str)"),
1077
+ get_ffi_dispatch_metrics: lib.func("void* get_ffi_dispatch_metrics()"),
1078
+ check_starvation_warnings: lib.func("void check_starvation_warnings()"),
1079
+ cleanup_timeouts: lib.func("void cleanup_timeouts()"),
1080
+ log_error: lib.func("void log_error(str, str)"),
1081
+ log_warn: lib.func("void log_warn(str, str)"),
1082
+ log_info: lib.func("void log_info(str, str)"),
1083
+ log_debug: lib.func("void log_debug(str, str)"),
1084
+ log_trace: lib.func("void log_trace(str, str)"),
1085
+ free_rust_string: lib.func("void free_rust_string(void*)"),
1086
+ // Client API functions (TAS-231)
1087
+ client_create_task: lib.func("void* client_create_task(str)"),
1088
+ client_get_task: lib.func("void* client_get_task(str)"),
1089
+ client_list_tasks: lib.func("void* client_list_tasks(str)"),
1090
+ client_cancel_task: lib.func("void* client_cancel_task(str)"),
1091
+ client_list_task_steps: lib.func("void* client_list_task_steps(str)"),
1092
+ client_get_step: lib.func("void* client_get_step(str, str)"),
1093
+ client_get_step_audit_history: lib.func("void* client_get_step_audit_history(str, str)"),
1094
+ client_health_check: lib.func("void* client_health_check()")
1095
+ };
1096
+ }
1097
+ unload() {
1098
+ this.lib = null;
1099
+ this.koffi = null;
1100
+ }
1101
+ ensureLoaded() {
1102
+ if (!this.lib) {
1103
+ throw new Error("Native library not loaded. Call load() first.");
1104
+ }
1105
+ return this.lib;
1106
+ }
1107
+ /**
1108
+ * Read a C string from a pointer and free the Rust-allocated memory.
1109
+ *
1110
+ * Uses koffi.decode with 'char' type and -1 length for null-terminated strings.
1111
+ */
1112
+ readAndFreeRustString(ptr) {
1113
+ if (!ptr) return null;
1114
+ const lib = this.ensureLoaded();
1115
+ const str = this.koffi.decode(ptr, "char", -1);
1116
+ lib.free_rust_string(ptr);
1117
+ return str;
1118
+ }
1119
+ getVersion() {
1120
+ const lib = this.ensureLoaded();
1121
+ const ptr = lib.get_version();
1122
+ return this.readAndFreeRustString(ptr) ?? "unknown";
1123
+ }
1124
+ getRustVersion() {
1125
+ const lib = this.ensureLoaded();
1126
+ const ptr = lib.get_rust_version();
1127
+ return this.readAndFreeRustString(ptr) ?? "unknown";
1128
+ }
1129
+ healthCheck() {
1130
+ const lib = this.ensureLoaded();
1131
+ return lib.health_check() === 1;
1132
+ }
1133
+ bootstrapWorker(config) {
1134
+ const lib = this.ensureLoaded();
1135
+ const configJson = config ? this.toJson(config) : null;
1136
+ const ptr = lib.bootstrap_worker(configJson);
1137
+ const jsonStr = this.readAndFreeRustString(ptr);
1138
+ const parsed = this.parseJson(jsonStr);
1139
+ return parsed ?? {
1140
+ success: false,
1141
+ status: "error",
1142
+ message: "Failed to parse bootstrap result",
1143
+ error: "Invalid JSON response"
1144
+ };
1145
+ }
1146
+ isWorkerRunning() {
1147
+ const lib = this.ensureLoaded();
1148
+ return lib.is_worker_running() === 1;
1149
+ }
1150
+ getWorkerStatus() {
1151
+ const lib = this.ensureLoaded();
1152
+ const ptr = lib.get_worker_status();
1153
+ const jsonStr = this.readAndFreeRustString(ptr);
1154
+ const parsed = this.parseJson(jsonStr);
1155
+ return parsed ?? { success: false, running: false };
1156
+ }
1157
+ stopWorker() {
1158
+ const lib = this.ensureLoaded();
1159
+ const ptr = lib.stop_worker();
1160
+ const jsonStr = this.readAndFreeRustString(ptr);
1161
+ const parsed = this.parseJson(jsonStr);
1162
+ return parsed ?? {
1163
+ success: false,
1164
+ status: "error",
1165
+ message: "Failed to parse stop result",
1166
+ error: "Invalid JSON response"
1167
+ };
1168
+ }
1169
+ transitionToGracefulShutdown() {
1170
+ const lib = this.ensureLoaded();
1171
+ const ptr = lib.transition_to_graceful_shutdown();
1172
+ const jsonStr = this.readAndFreeRustString(ptr);
1173
+ const parsed = this.parseJson(jsonStr);
1174
+ return parsed ?? {
1175
+ success: false,
1176
+ status: "error",
1177
+ message: "Failed to parse shutdown result",
1178
+ error: "Invalid JSON response"
1179
+ };
1180
+ }
1181
+ pollStepEvents() {
1182
+ const lib = this.ensureLoaded();
1183
+ const ptr = lib.poll_step_events();
1184
+ if (!ptr) return null;
1185
+ const jsonStr = this.readAndFreeRustString(ptr);
1186
+ return this.parseJson(jsonStr);
1187
+ }
1188
+ pollInProcessEvents() {
1189
+ const lib = this.ensureLoaded();
1190
+ const ptr = lib.poll_in_process_events();
1191
+ if (!ptr) return null;
1192
+ const jsonStr = this.readAndFreeRustString(ptr);
1193
+ return this.parseJson(jsonStr);
1194
+ }
1195
+ completeStepEvent(eventId, result) {
1196
+ const lib = this.ensureLoaded();
1197
+ return lib.complete_step_event(eventId, this.toJson(result)) === 1;
1198
+ }
1199
+ checkpointYieldStepEvent(eventId, checkpointData) {
1200
+ const lib = this.ensureLoaded();
1201
+ return lib.checkpoint_yield_step_event(eventId, this.toJson(checkpointData)) === 1;
1202
+ }
1203
+ getFfiDispatchMetrics() {
1204
+ const lib = this.ensureLoaded();
1205
+ const ptr = lib.get_ffi_dispatch_metrics();
1206
+ const jsonStr = this.readAndFreeRustString(ptr);
1207
+ const parsed = this.parseJson(jsonStr);
1208
+ if (parsed && typeof parsed.pending_count === "number") {
1209
+ return parsed;
1210
+ }
1211
+ return {
1212
+ pending_count: 0,
1213
+ starvation_detected: false,
1214
+ starving_event_count: 0,
1215
+ oldest_pending_age_ms: null,
1216
+ newest_pending_age_ms: null,
1217
+ oldest_event_id: null
1218
+ };
1219
+ }
1220
+ checkStarvationWarnings() {
1221
+ const lib = this.ensureLoaded();
1222
+ lib.check_starvation_warnings();
1223
+ }
1224
+ cleanupTimeouts() {
1225
+ const lib = this.ensureLoaded();
1226
+ lib.cleanup_timeouts();
1227
+ }
1228
+ logError(message, fields) {
1229
+ const lib = this.ensureLoaded();
1230
+ lib.log_error(message, fields ? this.toJson(fields) : null);
1231
+ }
1232
+ logWarn(message, fields) {
1233
+ const lib = this.ensureLoaded();
1234
+ lib.log_warn(message, fields ? this.toJson(fields) : null);
1235
+ }
1236
+ logInfo(message, fields) {
1237
+ const lib = this.ensureLoaded();
1238
+ lib.log_info(message, fields ? this.toJson(fields) : null);
1239
+ }
1240
+ logDebug(message, fields) {
1241
+ const lib = this.ensureLoaded();
1242
+ lib.log_debug(message, fields ? this.toJson(fields) : null);
1243
+ }
1244
+ logTrace(message, fields) {
1245
+ const lib = this.ensureLoaded();
1246
+ lib.log_trace(message, fields ? this.toJson(fields) : null);
1247
+ }
1248
+ // ==========================================================================
1249
+ // Client API Operations (TAS-231)
1250
+ // ==========================================================================
1251
+ parseClientResult(ptr) {
1252
+ const jsonStr = this.readAndFreeRustString(ptr);
1253
+ const parsed = this.parseJson(jsonStr);
1254
+ return parsed ?? {
1255
+ success: false,
1256
+ data: null,
1257
+ error: "Failed to parse client result",
1258
+ recoverable: null
1259
+ };
1260
+ }
1261
+ clientCreateTask(requestJson) {
1262
+ const lib = this.ensureLoaded();
1263
+ const ptr = lib.client_create_task(requestJson);
1264
+ return this.parseClientResult(ptr);
1265
+ }
1266
+ clientGetTask(taskUuid) {
1267
+ const lib = this.ensureLoaded();
1268
+ const ptr = lib.client_get_task(taskUuid);
1269
+ return this.parseClientResult(ptr);
1270
+ }
1271
+ clientListTasks(paramsJson) {
1272
+ const lib = this.ensureLoaded();
1273
+ const ptr = lib.client_list_tasks(paramsJson);
1274
+ return this.parseClientResult(ptr);
1275
+ }
1276
+ clientCancelTask(taskUuid) {
1277
+ const lib = this.ensureLoaded();
1278
+ const ptr = lib.client_cancel_task(taskUuid);
1279
+ return this.parseClientResult(ptr);
1280
+ }
1281
+ clientListTaskSteps(taskUuid) {
1282
+ const lib = this.ensureLoaded();
1283
+ const ptr = lib.client_list_task_steps(taskUuid);
1284
+ return this.parseClientResult(ptr);
1285
+ }
1286
+ clientGetStep(taskUuid, stepUuid) {
1287
+ const lib = this.ensureLoaded();
1288
+ const ptr = lib.client_get_step(taskUuid, stepUuid);
1289
+ return this.parseClientResult(ptr);
1290
+ }
1291
+ clientGetStepAuditHistory(taskUuid, stepUuid) {
1292
+ const lib = this.ensureLoaded();
1293
+ const ptr = lib.client_get_step_audit_history(taskUuid, stepUuid);
1294
+ return this.parseClientResult(ptr);
1295
+ }
1296
+ clientHealthCheck() {
1297
+ const lib = this.ensureLoaded();
1298
+ const ptr = lib.client_health_check();
1299
+ return this.parseClientResult(ptr);
1300
+ }
1301
+ };
1302
+ }
1303
+ });
1304
+
1305
+ // src/ffi/deno-runtime.ts
1306
+ var deno_runtime_exports = {};
1307
+ __export(deno_runtime_exports, {
1308
+ DenoRuntime: () => DenoRuntime
1309
+ });
1310
+ var DenoRuntime;
1311
+ var init_deno_runtime = __esm({
1312
+ "src/ffi/deno-runtime.ts"() {
1313
+ init_runtime_interface();
1314
+ DenoRuntime = class extends BaseTaskerRuntime {
1315
+ name = "deno";
1316
+ lib = null;
1317
+ encoder = new TextEncoder();
1318
+ get isLoaded() {
1319
+ return this.lib !== null;
1320
+ }
1321
+ async load(libraryPath) {
1322
+ if (this.lib !== null) {
1323
+ return;
1324
+ }
1325
+ if (typeof Deno === "undefined") {
1326
+ throw new Error("Deno runtime not detected");
1327
+ }
1328
+ this.lib = Deno.dlopen(libraryPath, {
1329
+ get_version: {
1330
+ parameters: [],
1331
+ result: "pointer"
1332
+ },
1333
+ get_rust_version: {
1334
+ parameters: [],
1335
+ result: "pointer"
1336
+ },
1337
+ health_check: {
1338
+ parameters: [],
1339
+ result: "i32"
1340
+ },
1341
+ is_worker_running: {
1342
+ parameters: [],
1343
+ result: "i32"
1344
+ },
1345
+ bootstrap_worker: {
1346
+ parameters: ["buffer"],
1347
+ result: "pointer"
1348
+ },
1349
+ get_worker_status: {
1350
+ parameters: [],
1351
+ result: "pointer"
1352
+ },
1353
+ stop_worker: {
1354
+ parameters: [],
1355
+ result: "pointer"
1356
+ },
1357
+ transition_to_graceful_shutdown: {
1358
+ parameters: [],
1359
+ result: "pointer"
1360
+ },
1361
+ poll_step_events: {
1362
+ parameters: [],
1363
+ result: "pointer"
1364
+ },
1365
+ poll_in_process_events: {
1366
+ parameters: [],
1367
+ result: "pointer"
1368
+ },
1369
+ complete_step_event: {
1370
+ parameters: ["buffer", "buffer"],
1371
+ result: "i32"
1372
+ },
1373
+ checkpoint_yield_step_event: {
1374
+ parameters: ["buffer", "buffer"],
1375
+ result: "i32"
1376
+ },
1377
+ get_ffi_dispatch_metrics: {
1378
+ parameters: [],
1379
+ result: "pointer"
1380
+ },
1381
+ check_starvation_warnings: {
1382
+ parameters: [],
1383
+ result: "void"
1384
+ },
1385
+ cleanup_timeouts: {
1386
+ parameters: [],
1387
+ result: "void"
1388
+ },
1389
+ log_error: {
1390
+ parameters: ["buffer", "buffer"],
1391
+ result: "void"
1392
+ },
1393
+ log_warn: {
1394
+ parameters: ["buffer", "buffer"],
1395
+ result: "void"
1396
+ },
1397
+ log_info: {
1398
+ parameters: ["buffer", "buffer"],
1399
+ result: "void"
1400
+ },
1401
+ log_debug: {
1402
+ parameters: ["buffer", "buffer"],
1403
+ result: "void"
1404
+ },
1405
+ log_trace: {
1406
+ parameters: ["buffer", "buffer"],
1407
+ result: "void"
1408
+ },
1409
+ free_rust_string: {
1410
+ parameters: ["pointer"],
1411
+ result: "void"
1412
+ },
1413
+ // Client API functions (TAS-231)
1414
+ client_create_task: {
1415
+ parameters: ["buffer"],
1416
+ result: "pointer"
1417
+ },
1418
+ client_get_task: {
1419
+ parameters: ["buffer"],
1420
+ result: "pointer"
1421
+ },
1422
+ client_list_tasks: {
1423
+ parameters: ["buffer"],
1424
+ result: "pointer"
1425
+ },
1426
+ client_cancel_task: {
1427
+ parameters: ["buffer"],
1428
+ result: "pointer"
1429
+ },
1430
+ client_list_task_steps: {
1431
+ parameters: ["buffer"],
1432
+ result: "pointer"
1433
+ },
1434
+ client_get_step: {
1435
+ parameters: ["buffer", "buffer"],
1436
+ result: "pointer"
1437
+ },
1438
+ client_get_step_audit_history: {
1439
+ parameters: ["buffer", "buffer"],
1440
+ result: "pointer"
1441
+ },
1442
+ client_health_check: {
1443
+ parameters: [],
1444
+ result: "pointer"
1445
+ }
1446
+ });
1447
+ }
1448
+ unload() {
1449
+ if (this.lib) {
1450
+ this.lib.close();
1451
+ this.lib = null;
1452
+ }
1453
+ }
1454
+ ensureLoaded() {
1455
+ if (!this.lib) {
1456
+ throw new Error("Native library not loaded. Call load() first.");
1457
+ }
1458
+ return this.lib.symbols;
1459
+ }
1460
+ /**
1461
+ * Creates a null-terminated C string buffer.
1462
+ * With 'buffer' FFI type, we return Uint8Array directly.
1463
+ */
1464
+ toCString(str) {
1465
+ return this.encoder.encode(`${str}\0`);
1466
+ }
1467
+ // biome-ignore lint/suspicious/noExplicitAny: Deno PointerValue type
1468
+ fromCString(ptr) {
1469
+ if (ptr === null || Deno.UnsafePointer.equals(ptr, null)) {
1470
+ return null;
1471
+ }
1472
+ const view = new Deno.UnsafePointerView(ptr);
1473
+ return view.getCString();
1474
+ }
1475
+ getVersion() {
1476
+ const symbols = this.ensureLoaded();
1477
+ const result = symbols.get_version();
1478
+ const version = this.fromCString(result) ?? "unknown";
1479
+ if (result !== null) symbols.free_rust_string(result);
1480
+ return version;
1481
+ }
1482
+ getRustVersion() {
1483
+ const symbols = this.ensureLoaded();
1484
+ const result = symbols.get_rust_version();
1485
+ const version = this.fromCString(result) ?? "unknown";
1486
+ if (result !== null) symbols.free_rust_string(result);
1487
+ return version;
1488
+ }
1489
+ healthCheck() {
1490
+ const symbols = this.ensureLoaded();
1491
+ return symbols.health_check() === 1;
1492
+ }
1493
+ bootstrapWorker(config) {
1494
+ const symbols = this.ensureLoaded();
1495
+ const configBuf = config ? this.toCString(this.toJson(config)) : null;
1496
+ const result = symbols.bootstrap_worker(configBuf);
1497
+ const jsonStr = this.fromCString(result);
1498
+ if (result !== null) symbols.free_rust_string(result);
1499
+ const parsed = this.parseJson(jsonStr);
1500
+ return parsed ?? {
1501
+ success: false,
1502
+ status: "error",
1503
+ message: "Failed to parse bootstrap result",
1504
+ error: "Invalid JSON response"
1505
+ };
1506
+ }
1507
+ isWorkerRunning() {
1508
+ const symbols = this.ensureLoaded();
1509
+ return symbols.is_worker_running() === 1;
1510
+ }
1511
+ getWorkerStatus() {
1512
+ const symbols = this.ensureLoaded();
1513
+ const result = symbols.get_worker_status();
1514
+ const jsonStr = this.fromCString(result);
1515
+ if (result !== null) symbols.free_rust_string(result);
1516
+ const parsed = this.parseJson(jsonStr);
1517
+ return parsed ?? { success: false, running: false };
1518
+ }
1519
+ stopWorker() {
1520
+ const symbols = this.ensureLoaded();
1521
+ const result = symbols.stop_worker();
1522
+ const jsonStr = this.fromCString(result);
1523
+ if (result !== null) symbols.free_rust_string(result);
1524
+ const parsed = this.parseJson(jsonStr);
1525
+ return parsed ?? {
1526
+ success: false,
1527
+ status: "error",
1528
+ message: "Failed to parse stop result",
1529
+ error: "Invalid JSON response"
1530
+ };
1531
+ }
1532
+ transitionToGracefulShutdown() {
1533
+ const symbols = this.ensureLoaded();
1534
+ const result = symbols.transition_to_graceful_shutdown();
1535
+ const jsonStr = this.fromCString(result);
1536
+ if (result !== null) symbols.free_rust_string(result);
1537
+ const parsed = this.parseJson(jsonStr);
1538
+ return parsed ?? {
1539
+ success: false,
1540
+ status: "error",
1541
+ message: "Failed to parse shutdown result",
1542
+ error: "Invalid JSON response"
1543
+ };
1544
+ }
1545
+ pollStepEvents() {
1546
+ const symbols = this.ensureLoaded();
1547
+ const result = symbols.poll_step_events();
1548
+ if (result === null || Deno.UnsafePointer.equals(result, null)) {
1549
+ return null;
1550
+ }
1551
+ const jsonStr = this.fromCString(result);
1552
+ symbols.free_rust_string(result);
1553
+ return this.parseJson(jsonStr);
1554
+ }
1555
+ pollInProcessEvents() {
1556
+ const symbols = this.ensureLoaded();
1557
+ const result = symbols.poll_in_process_events();
1558
+ if (result === null || Deno.UnsafePointer.equals(result, null)) {
1559
+ return null;
1560
+ }
1561
+ const jsonStr = this.fromCString(result);
1562
+ symbols.free_rust_string(result);
1563
+ return this.parseJson(jsonStr);
1564
+ }
1565
+ completeStepEvent(eventId, result) {
1566
+ const symbols = this.ensureLoaded();
1567
+ const eventIdBuf = this.toCString(eventId);
1568
+ const resultJsonBuf = this.toCString(this.toJson(result));
1569
+ return symbols.complete_step_event(eventIdBuf, resultJsonBuf) === 1;
1570
+ }
1571
+ checkpointYieldStepEvent(eventId, checkpointData) {
1572
+ const symbols = this.ensureLoaded();
1573
+ const eventIdBuf = this.toCString(eventId);
1574
+ const checkpointJsonBuf = this.toCString(this.toJson(checkpointData));
1575
+ return symbols.checkpoint_yield_step_event(eventIdBuf, checkpointJsonBuf) === 1;
1576
+ }
1577
+ getFfiDispatchMetrics() {
1578
+ const symbols = this.ensureLoaded();
1579
+ const result = symbols.get_ffi_dispatch_metrics();
1580
+ const jsonStr = this.fromCString(result);
1581
+ if (result !== null) symbols.free_rust_string(result);
1582
+ const parsed = this.parseJson(jsonStr);
1583
+ if (parsed && typeof parsed.pending_count === "number") {
1584
+ return parsed;
1585
+ }
1586
+ return {
1587
+ pending_count: 0,
1588
+ starvation_detected: false,
1589
+ starving_event_count: 0,
1590
+ oldest_pending_age_ms: null,
1591
+ newest_pending_age_ms: null,
1592
+ oldest_event_id: null
1593
+ };
1594
+ }
1595
+ checkStarvationWarnings() {
1596
+ const symbols = this.ensureLoaded();
1597
+ symbols.check_starvation_warnings();
1598
+ }
1599
+ cleanupTimeouts() {
1600
+ const symbols = this.ensureLoaded();
1601
+ symbols.cleanup_timeouts();
1602
+ }
1603
+ logError(message, fields) {
1604
+ const symbols = this.ensureLoaded();
1605
+ const msgBuf = this.toCString(message);
1606
+ const fieldsBuf = fields ? this.toCString(this.toJson(fields)) : null;
1607
+ symbols.log_error(msgBuf, fieldsBuf);
1608
+ }
1609
+ logWarn(message, fields) {
1610
+ const symbols = this.ensureLoaded();
1611
+ const msgBuf = this.toCString(message);
1612
+ const fieldsBuf = fields ? this.toCString(this.toJson(fields)) : null;
1613
+ symbols.log_warn(msgBuf, fieldsBuf);
1614
+ }
1615
+ logInfo(message, fields) {
1616
+ const symbols = this.ensureLoaded();
1617
+ const msgBuf = this.toCString(message);
1618
+ const fieldsBuf = fields ? this.toCString(this.toJson(fields)) : null;
1619
+ symbols.log_info(msgBuf, fieldsBuf);
1620
+ }
1621
+ logDebug(message, fields) {
1622
+ const symbols = this.ensureLoaded();
1623
+ const msgBuf = this.toCString(message);
1624
+ const fieldsBuf = fields ? this.toCString(this.toJson(fields)) : null;
1625
+ symbols.log_debug(msgBuf, fieldsBuf);
1626
+ }
1627
+ logTrace(message, fields) {
1628
+ const symbols = this.ensureLoaded();
1629
+ const msgBuf = this.toCString(message);
1630
+ const fieldsBuf = fields ? this.toCString(this.toJson(fields)) : null;
1631
+ symbols.log_trace(msgBuf, fieldsBuf);
1632
+ }
1633
+ // ==========================================================================
1634
+ // Client API Operations (TAS-231)
1635
+ // ==========================================================================
1636
+ parseClientResult(result) {
1637
+ const jsonStr = this.fromCString(result);
1638
+ if (result !== null) this.ensureLoaded().free_rust_string(result);
1639
+ const parsed = this.parseJson(jsonStr);
1640
+ return parsed ?? {
1641
+ success: false,
1642
+ data: null,
1643
+ error: "Failed to parse client result",
1644
+ recoverable: null
1645
+ };
1646
+ }
1647
+ clientCreateTask(requestJson) {
1648
+ const symbols = this.ensureLoaded();
1649
+ const buf = this.toCString(requestJson);
1650
+ const result = symbols.client_create_task(buf);
1651
+ return this.parseClientResult(result);
1652
+ }
1653
+ clientGetTask(taskUuid) {
1654
+ const symbols = this.ensureLoaded();
1655
+ const buf = this.toCString(taskUuid);
1656
+ const result = symbols.client_get_task(buf);
1657
+ return this.parseClientResult(result);
1658
+ }
1659
+ clientListTasks(paramsJson) {
1660
+ const symbols = this.ensureLoaded();
1661
+ const buf = this.toCString(paramsJson);
1662
+ const result = symbols.client_list_tasks(buf);
1663
+ return this.parseClientResult(result);
1664
+ }
1665
+ clientCancelTask(taskUuid) {
1666
+ const symbols = this.ensureLoaded();
1667
+ const buf = this.toCString(taskUuid);
1668
+ const result = symbols.client_cancel_task(buf);
1669
+ return this.parseClientResult(result);
1670
+ }
1671
+ clientListTaskSteps(taskUuid) {
1672
+ const symbols = this.ensureLoaded();
1673
+ const buf = this.toCString(taskUuid);
1674
+ const result = symbols.client_list_task_steps(buf);
1675
+ return this.parseClientResult(result);
1676
+ }
1677
+ clientGetStep(taskUuid, stepUuid) {
1678
+ const symbols = this.ensureLoaded();
1679
+ const tBuf = this.toCString(taskUuid);
1680
+ const sBuf = this.toCString(stepUuid);
1681
+ const result = symbols.client_get_step(tBuf, sBuf);
1682
+ return this.parseClientResult(result);
1683
+ }
1684
+ clientGetStepAuditHistory(taskUuid, stepUuid) {
1685
+ const symbols = this.ensureLoaded();
1686
+ const tBuf = this.toCString(taskUuid);
1687
+ const sBuf = this.toCString(stepUuid);
1688
+ const result = symbols.client_get_step_audit_history(tBuf, sBuf);
1689
+ return this.parseClientResult(result);
1690
+ }
1691
+ clientHealthCheck() {
1692
+ const symbols = this.ensureLoaded();
1693
+ const result = symbols.client_health_check();
1694
+ return this.parseClientResult(result);
1695
+ }
1696
+ };
1697
+ }
1698
+ });
1699
+
1700
+ // src/ffi/bun-runtime.ts
1701
+ init_node_runtime();
1702
+ var BunRuntime = class extends NodeRuntime {
1703
+ name = "bun";
1704
+ };
1705
+
1706
+ // src/ffi/index.ts
1707
+ init_deno_runtime();
1708
+
1709
+ // src/ffi/runtime.ts
1710
+ var cachedRuntimeType = null;
1711
+ function detectRuntime() {
1712
+ if (cachedRuntimeType !== null) {
1713
+ return cachedRuntimeType;
1714
+ }
1715
+ if (typeof globalThis !== "undefined" && "Bun" in globalThis) {
1716
+ cachedRuntimeType = "bun";
1717
+ return "bun";
1718
+ }
1719
+ if (typeof globalThis !== "undefined" && "Deno" in globalThis) {
1720
+ cachedRuntimeType = "deno";
1721
+ return "deno";
1722
+ }
1723
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
1724
+ cachedRuntimeType = "node";
1725
+ return "node";
1726
+ }
1727
+ cachedRuntimeType = "unknown";
1728
+ return "unknown";
1729
+ }
1730
+ function isBun() {
1731
+ return detectRuntime() === "bun";
1732
+ }
1733
+ function isNode() {
1734
+ return detectRuntime() === "node";
1735
+ }
1736
+ function isDeno() {
1737
+ return detectRuntime() === "deno";
1738
+ }
1739
+ function getRuntimeInfo() {
1740
+ const type = detectRuntime();
1741
+ switch (type) {
1742
+ case "bun": {
1743
+ const Bun = globalThis.Bun;
1744
+ return {
1745
+ type: "bun",
1746
+ version: Bun?.version ?? "unknown",
1747
+ platform: process?.platform ?? "unknown",
1748
+ arch: process?.arch ?? "unknown"
1749
+ };
1750
+ }
1751
+ case "deno": {
1752
+ const Deno2 = globalThis.Deno;
1753
+ return {
1754
+ type: "deno",
1755
+ version: Deno2?.version?.deno ?? "unknown",
1756
+ platform: Deno2?.build?.os ?? "unknown",
1757
+ arch: Deno2?.build?.arch ?? "unknown"
1758
+ };
1759
+ }
1760
+ case "node":
1761
+ return {
1762
+ type: "node",
1763
+ version: process.versions.node,
1764
+ platform: process.platform,
1765
+ arch: process.arch
1766
+ };
1767
+ default:
1768
+ return {
1769
+ type: "unknown",
1770
+ version: "unknown",
1771
+ platform: "unknown",
1772
+ arch: "unknown"
1773
+ };
1774
+ }
1775
+ }
1776
+ function getLibraryFilename() {
1777
+ const platform = process?.platform ?? "unknown";
1778
+ switch (platform) {
1779
+ case "darwin":
1780
+ return "libtasker_ts.dylib";
1781
+ case "linux":
1782
+ return "libtasker_ts.so";
1783
+ case "win32":
1784
+ return "tasker_ts.dll";
1785
+ default:
1786
+ throw new Error(`Unsupported platform: ${platform}`);
1787
+ }
1788
+ }
1789
+ function getLibraryPath(basePath) {
1790
+ const envPath = process.env.TASKER_FFI_LIBRARY_PATH;
1791
+ if (envPath) {
1792
+ return envPath;
1793
+ }
1794
+ if (basePath) {
1795
+ return `${basePath}/${getLibraryFilename()}`;
1796
+ }
1797
+ throw new Error(
1798
+ "FFI library path not configured. Set TASKER_FFI_LIBRARY_PATH environment variable.\nExample: export TASKER_FFI_LIBRARY_PATH=/path/to/target/debug/libtasker_ts.dylib"
1799
+ );
1800
+ }
1801
+
1802
+ // src/ffi/ffi-layer.ts
1803
+ var FfiLayer = class _FfiLayer {
1804
+ runtime = null;
1805
+ libraryPath = null;
1806
+ runtimeType;
1807
+ configuredLibraryPath;
1808
+ /**
1809
+ * Create a new FfiLayer.
1810
+ *
1811
+ * @param config - Optional configuration for runtime type and library path
1812
+ */
1813
+ constructor(config = {}) {
1814
+ this.runtimeType = config.runtimeType ?? detectRuntime();
1815
+ this.configuredLibraryPath = config.libraryPath;
1816
+ }
1817
+ /**
1818
+ * Load the FFI library.
1819
+ *
1820
+ * Discovers and loads the native library for the current runtime.
1821
+ *
1822
+ * @param customPath - Optional override for library path (takes precedence over config)
1823
+ * @throws Error if library not found or failed to load
1824
+ */
1825
+ async load(customPath) {
1826
+ if (this.runtime?.isLoaded) {
1827
+ return;
1828
+ }
1829
+ const path2 = customPath ?? this.configuredLibraryPath ?? this.discoverLibraryPath();
1830
+ if (!path2) {
1831
+ throw new Error(
1832
+ "FFI library not found. TASKER_FFI_LIBRARY_PATH environment variable must be set to the path of the compiled library.\nExample: export TASKER_FFI_LIBRARY_PATH=/path/to/target/debug/libtasker_ts.dylib\nBuild the library with: cargo build -p tasker-ts"
1833
+ );
1834
+ }
1835
+ this.runtime = await this.createRuntime();
1836
+ await this.runtime.load(path2);
1837
+ this.libraryPath = path2;
1838
+ }
1839
+ /**
1840
+ * Unload the FFI library and release resources.
1841
+ *
1842
+ * Safe to call even if not loaded.
1843
+ */
1844
+ async unload() {
1845
+ if (this.runtime?.isLoaded) {
1846
+ this.runtime.unload();
1847
+ }
1848
+ this.runtime = null;
1849
+ this.libraryPath = null;
1850
+ }
1851
+ /**
1852
+ * Check if the FFI library is loaded.
1853
+ */
1854
+ isLoaded() {
1855
+ return this.runtime?.isLoaded ?? false;
1856
+ }
1857
+ /**
1858
+ * Get the loaded runtime.
1859
+ *
1860
+ * @throws Error if runtime is not loaded
1861
+ */
1862
+ getRuntime() {
1863
+ if (!this.runtime?.isLoaded) {
1864
+ throw new Error("FFI not loaded. Call load() first.");
1865
+ }
1866
+ return this.runtime;
1867
+ }
1868
+ /**
1869
+ * Get the path to the loaded library.
1870
+ */
1871
+ getLibraryPath() {
1872
+ return this.libraryPath;
1873
+ }
1874
+ /**
1875
+ * Get the detected runtime type.
1876
+ */
1877
+ getRuntimeType() {
1878
+ return this.runtimeType;
1879
+ }
1880
+ /**
1881
+ * Find the FFI library path.
1882
+ *
1883
+ * Static method for finding the library path without creating an instance.
1884
+ * Useful for test utilities and pre-flight checks.
1885
+ *
1886
+ * REQUIRES: TASKER_FFI_LIBRARY_PATH environment variable to be set.
1887
+ * This explicit requirement prevents confusion from automatic debug/release
1888
+ * library discovery and ensures intentional configuration at build/runtime.
1889
+ *
1890
+ * @param _callerDir Deprecated parameter, kept for API compatibility
1891
+ * @returns Path to the library if found and exists, null otherwise
1892
+ */
1893
+ static findLibraryPath(_callerDir) {
1894
+ const envPath = process.env.TASKER_FFI_LIBRARY_PATH;
1895
+ if (!envPath) {
1896
+ return null;
1897
+ }
1898
+ if (!existsSync(envPath)) {
1899
+ console.warn(`TASKER_FFI_LIBRARY_PATH is set to "${envPath}" but the file does not exist`);
1900
+ return null;
1901
+ }
1902
+ return envPath;
1903
+ }
1904
+ /**
1905
+ * Discover the FFI library path.
1906
+ *
1907
+ * Instance method that delegates to the static findLibraryPath.
1908
+ */
1909
+ discoverLibraryPath() {
1910
+ return _FfiLayer.findLibraryPath();
1911
+ }
1912
+ /**
1913
+ * Create a runtime adapter for the configured runtime type.
1914
+ *
1915
+ * NOTE: We use koffi (NodeRuntime) for both Node.js and Bun because:
1916
+ * - bun:ffi is experimental with known bugs (per Bun docs)
1917
+ * - koffi is stable and works with both Node.js and Bun via Node-API
1918
+ * - See: https://bun.sh/docs/runtime/node-api
1919
+ */
1920
+ async createRuntime() {
1921
+ switch (this.runtimeType) {
1922
+ case "bun":
1923
+ case "node": {
1924
+ const { NodeRuntime: NodeRuntime2 } = await Promise.resolve().then(() => (init_node_runtime(), node_runtime_exports));
1925
+ return new NodeRuntime2();
1926
+ }
1927
+ case "deno": {
1928
+ const { DenoRuntime: DenoRuntime2 } = await Promise.resolve().then(() => (init_deno_runtime(), deno_runtime_exports));
1929
+ return new DenoRuntime2();
1930
+ }
1931
+ default:
1932
+ throw new Error(
1933
+ `Unsupported runtime: ${this.runtimeType}. Tasker TypeScript worker requires Bun, Node.js, or Deno.`
1934
+ );
1935
+ }
1936
+ }
1937
+ };
1938
+
1939
+ // src/ffi/index.ts
1940
+ init_node_runtime();
1941
+ init_runtime_interface();
1942
+
1943
+ export { BaseTaskerRuntime, BunRuntime, DenoRuntime, FfiLayer, NodeRuntime, detectRuntime, getLibraryPath, getRuntimeInfo, isBun, isDeno, isNode };
1944
+ //# sourceMappingURL=index.js.map
1945
+ //# sourceMappingURL=index.js.map