harnessed 5.0.4 → 5.0.5

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,2260 @@
1
+ #!/usr/bin/env node
2
+ // biome-ignore-all format: esbuild-generated (hook drift gate owns this file)
3
+ // biome-ignore-all lint: esbuild-generated
4
+ // biome-ignore-all assist/source/organizeImports: esbuild-generated
5
+ import { createRequire } from 'node:module';
6
+ const require = createRequire(import.meta.url)
7
+ var __create = Object.create
8
+ var __defProp = Object.defineProperty
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor
10
+ var __getOwnPropNames = Object.getOwnPropertyNames
11
+ var __getProtoOf = Object.getPrototypeOf
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty
13
+ var __require = /* @__PURE__ */ ((x) =>
14
+ typeof require !== 'undefined'
15
+ ? require
16
+ : typeof Proxy !== 'undefined'
17
+ ? new Proxy(x, {
18
+ get: (a, b) => (typeof require !== 'undefined' ? require : a)[b],
19
+ })
20
+ : x)(function (x) {
21
+ if (typeof require !== 'undefined') return require.apply(this, arguments)
22
+ throw Error('Dynamic require of "' + x + '" is not supported')
23
+ })
24
+ var __esm = (fn, res) =>
25
+ function __init() {
26
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])((fn = 0))), res
27
+ }
28
+ var __commonJS = (cb, mod) =>
29
+ function __require2() {
30
+ return (
31
+ mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports
32
+ )
33
+ }
34
+ var __export = (target, all) => {
35
+ for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
36
+ }
37
+ var __copyProps = (to, from, except, desc) => {
38
+ if ((from && typeof from === 'object') || typeof from === 'function') {
39
+ for (let key of __getOwnPropNames(from))
40
+ if (!__hasOwnProp.call(to, key) && key !== except)
41
+ __defProp(to, key, {
42
+ get: () => from[key],
43
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
44
+ })
45
+ }
46
+ return to
47
+ }
48
+ var __toESM = (mod, isNodeMode, target) => (
49
+ (target = mod != null ? __create(__getProtoOf(mod)) : {}),
50
+ __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule
56
+ ? __defProp(target, 'default', { value: mod, enumerable: true })
57
+ : target,
58
+ mod,
59
+ )
60
+ )
61
+
62
+ // package.json
63
+ var package_default
64
+ var init_package = __esm({
65
+ 'package.json'() {
66
+ package_default = {
67
+ name: 'harnessed',
68
+ version: '5.0.5',
69
+ description: 'AI coding harness package manager + composition orchestrator',
70
+ type: 'module',
71
+ license: 'Apache-2.0',
72
+ author: 'easyinplay',
73
+ repository: {
74
+ type: 'git',
75
+ url: 'https://github.com/easyinplay/harnessed.git',
76
+ },
77
+ homepage: 'https://github.com/easyinplay/harnessed#readme',
78
+ bugs: 'https://github.com/easyinplay/harnessed/issues',
79
+ keywords: [
80
+ 'claude-code',
81
+ 'ai-harness',
82
+ 'package-manager',
83
+ 'composition',
84
+ 'skill-pack',
85
+ 'mcp',
86
+ 'orchestrator',
87
+ ],
88
+ engines: {
89
+ node: '>=22.0.0',
90
+ },
91
+ packageManager: 'pnpm@10.12.0',
92
+ bin: {
93
+ harnessed: './dist/cli.mjs',
94
+ 'harnessed-inject-state': './bin/harnessed-inject-state.mjs',
95
+ },
96
+ main: './dist/index.mjs',
97
+ types: './dist/index.d.ts',
98
+ exports: {
99
+ '.': {
100
+ types: './dist/index.d.ts',
101
+ import: './dist/index.mjs',
102
+ default: './dist/index.mjs',
103
+ },
104
+ './schemas': {
105
+ types: './dist/schemas/index.d.ts',
106
+ import: './dist/schemas/index.mjs',
107
+ },
108
+ './package.json': './package.json',
109
+ },
110
+ files: [
111
+ 'dist',
112
+ 'bin',
113
+ 'manifests',
114
+ 'messages',
115
+ 'workflows',
116
+ 'routing',
117
+ 'config-templates',
118
+ 'schemas',
119
+ 'README.md',
120
+ 'README-en.md',
121
+ 'README-zh.md',
122
+ 'LICENSE',
123
+ 'NOTICE',
124
+ 'THIRD-PARTY-NOTICES.md',
125
+ ],
126
+ scripts: {
127
+ dev: 'tsup --watch',
128
+ build: 'tsc --noEmit && tsup && node ./scripts/build-hooks.mjs',
129
+ 'build:hooks': 'node ./scripts/build-hooks.mjs',
130
+ 'build:schema': 'node ./scripts/build-schema.mjs',
131
+ 'validate:schema': 'node ./scripts/validate-schema.mjs',
132
+ typecheck: 'tsc --noEmit',
133
+ test: 'vitest run --passWithNoTests',
134
+ 'test:watch': 'vitest',
135
+ 'test:coverage': 'vitest run --coverage --passWithNoTests',
136
+ 'test:codex-live': 'node ./scripts/codex-live/run.mjs',
137
+ bench: 'vitest bench --run',
138
+ 'bench:runtime': 'node scripts/benchmark-runtime.mjs',
139
+ 'test:runtime-channels': 'node scripts/runtime-channel-smoke.mjs',
140
+ 'test:docs': 'node --test tests/docs/install-channels.contract.mjs',
141
+ lint: 'biome check .',
142
+ 'lint:fix': 'biome check --write .',
143
+ format: 'biome format --write .',
144
+ 'build:binary': 'bun scripts/build-binary.mjs',
145
+ },
146
+ dependencies: {
147
+ '@anthropic-ai/claude-agent-sdk': '0.3.142',
148
+ '@clack/prompts': '^0.10.1',
149
+ '@sinclair/typebox': '^0.34.49',
150
+ ajv: '^8.20.0',
151
+ 'ajv-errors': '^3.0.0',
152
+ 'ajv-formats': '^3.0.1',
153
+ commander: '^13.0.0',
154
+ diff: '^9.0.0',
155
+ 'expr-eval': '^2.0.2',
156
+ picocolors: '^1.1.1',
157
+ 'proper-lockfile': '^4.1.2',
158
+ 'smol-toml': '^1.9.1',
159
+ undici: '^8.12.1',
160
+ yaml: '^2.9.0',
161
+ },
162
+ devDependencies: {
163
+ '@biomejs/biome': '^2.0.0',
164
+ '@types/node': '^22.10.0',
165
+ '@types/proper-lockfile': '^4.1.4',
166
+ '@vitest/coverage-v8': '^4.0.0',
167
+ esbuild: '0.27.7',
168
+ tsup: '^8.3.0',
169
+ typescript: '^5.6.0',
170
+ vitest: '^4.0.0',
171
+ },
172
+ pnpm: {
173
+ onlyBuiltDependencies: ['esbuild'],
174
+ },
175
+ }
176
+ },
177
+ })
178
+
179
+ // src/cli/lib/updateReminderCache.ts
180
+ import fs from 'node:fs'
181
+ function isReminderVersion(value) {
182
+ return (
183
+ typeof value === 'string' &&
184
+ value.length <= 128 &&
185
+ /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(value)
186
+ )
187
+ }
188
+ function parseCache(text, identity, now) {
189
+ const cache = JSON.parse(text)
190
+ if (!cache || cache.schemaVersion !== 1 || !cache.identity) return null
191
+ const keys = ['host', 'runtime', 'channel', 'source', 'fingerprint']
192
+ if (identity.host !== 'claude' && identity.host !== 'codex') return null
193
+ for (const key of keys) {
194
+ const value = cache.identity[key]
195
+ if (
196
+ typeof value !== 'string' ||
197
+ !value.length ||
198
+ value.length > 512 ||
199
+ value !== identity[key]
200
+ ) {
201
+ return null
202
+ }
203
+ }
204
+ const { installed, latest, state, checkedAt, retryAfter } = cache
205
+ if (
206
+ !isReminderVersion(installed) ||
207
+ typeof checkedAt !== 'number' ||
208
+ !Number.isSafeInteger(checkedAt) ||
209
+ checkedAt < 0 ||
210
+ checkedAt > now ||
211
+ typeof retryAfter !== 'number' ||
212
+ !Number.isSafeInteger(retryAfter) ||
213
+ retryAfter < 0
214
+ )
215
+ return null
216
+ if (state === 'unknown') {
217
+ if (latest !== null || retryAfter !== checkedAt + REMINDER_RETRY_MS) return null
218
+ } else if (
219
+ !['behind', 'current', 'ahead'].includes(state ?? '') ||
220
+ !isReminderVersion(latest) ||
221
+ retryAfter !== 0
222
+ )
223
+ return null
224
+ return {
225
+ schemaVersion: 1,
226
+ identity: { ...identity },
227
+ installed,
228
+ latest: latest ?? null,
229
+ state,
230
+ checkedAt,
231
+ retryAfter,
232
+ }
233
+ }
234
+ function readReminderCache(cachePath, identity, now = Date.now()) {
235
+ let descriptor
236
+ try {
237
+ descriptor = fs.openSync(cachePath, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK)
238
+ const stat = fs.fstatSync(descriptor)
239
+ if (!stat.isFile() || stat.size > REMINDER_MAX_BYTES) return null
240
+ const buffer = Buffer.alloc(REMINDER_MAX_BYTES + 1)
241
+ const bytes = fs.readSync(descriptor, buffer, 0, buffer.length, 0)
242
+ if (bytes > REMINDER_MAX_BYTES || bytes < stat.size) return null
243
+ return parseCache(buffer.toString('utf8', 0, bytes), identity, now)
244
+ } catch {
245
+ return null
246
+ } finally {
247
+ if (descriptor !== void 0) {
248
+ try {
249
+ fs.closeSync(descriptor)
250
+ } catch {}
251
+ }
252
+ }
253
+ }
254
+ function shouldRefreshReminder(cache, now) {
255
+ if (!cache) return true
256
+ if (cache.retryAfter > now) return false
257
+ return cache.state === 'unknown' || now - cache.checkedAt >= REMINDER_TTL_MS
258
+ }
259
+ var REMINDER_TTL_MS, REMINDER_RETRY_MS, REMINDER_MAX_BYTES, REMINDER_LOCK_STALE_MS
260
+ var init_updateReminderCache = __esm({
261
+ 'src/cli/lib/updateReminderCache.ts'() {
262
+ 'use strict'
263
+ REMINDER_TTL_MS = 24 * 60 * 60 * 1e3
264
+ REMINDER_RETRY_MS = 60 * 60 * 1e3
265
+ REMINDER_MAX_BYTES = 16 * 1024
266
+ REMINDER_LOCK_STALE_MS = 3e4
267
+ },
268
+ })
269
+
270
+ // node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js
271
+ var require_polyfills = __commonJS({
272
+ 'node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js'(exports, module) {
273
+ var constants2 = __require('constants')
274
+ var origCwd = process.cwd
275
+ var cwd = null
276
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform
277
+ process.cwd = function () {
278
+ if (!cwd) cwd = origCwd.call(process)
279
+ return cwd
280
+ }
281
+ try {
282
+ process.cwd()
283
+ } catch (er) {}
284
+ if (typeof process.chdir === 'function') {
285
+ chdir = process.chdir
286
+ process.chdir = function (d) {
287
+ cwd = null
288
+ chdir.call(process, d)
289
+ }
290
+ if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir)
291
+ }
292
+ var chdir
293
+ module.exports = patch
294
+ function patch(fs2) {
295
+ if (
296
+ constants2.hasOwnProperty('O_SYMLINK') &&
297
+ process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)
298
+ ) {
299
+ patchLchmod(fs2)
300
+ }
301
+ if (!fs2.lutimes) {
302
+ patchLutimes(fs2)
303
+ }
304
+ fs2.chown = chownFix(fs2.chown)
305
+ fs2.fchown = chownFix(fs2.fchown)
306
+ fs2.lchown = chownFix(fs2.lchown)
307
+ fs2.chmod = chmodFix(fs2.chmod)
308
+ fs2.fchmod = chmodFix(fs2.fchmod)
309
+ fs2.lchmod = chmodFix(fs2.lchmod)
310
+ fs2.chownSync = chownFixSync(fs2.chownSync)
311
+ fs2.fchownSync = chownFixSync(fs2.fchownSync)
312
+ fs2.lchownSync = chownFixSync(fs2.lchownSync)
313
+ fs2.chmodSync = chmodFixSync(fs2.chmodSync)
314
+ fs2.fchmodSync = chmodFixSync(fs2.fchmodSync)
315
+ fs2.lchmodSync = chmodFixSync(fs2.lchmodSync)
316
+ fs2.stat = statFix(fs2.stat)
317
+ fs2.fstat = statFix(fs2.fstat)
318
+ fs2.lstat = statFix(fs2.lstat)
319
+ fs2.statSync = statFixSync(fs2.statSync)
320
+ fs2.fstatSync = statFixSync(fs2.fstatSync)
321
+ fs2.lstatSync = statFixSync(fs2.lstatSync)
322
+ if (fs2.chmod && !fs2.lchmod) {
323
+ fs2.lchmod = function (path, mode, cb) {
324
+ if (cb) process.nextTick(cb)
325
+ }
326
+ fs2.lchmodSync = function () {}
327
+ }
328
+ if (fs2.chown && !fs2.lchown) {
329
+ fs2.lchown = function (path, uid, gid, cb) {
330
+ if (cb) process.nextTick(cb)
331
+ }
332
+ fs2.lchownSync = function () {}
333
+ }
334
+ if (platform === 'win32') {
335
+ fs2.rename =
336
+ typeof fs2.rename !== 'function'
337
+ ? fs2.rename
338
+ : (function (fs$rename) {
339
+ function rename(from, to, cb) {
340
+ var start = Date.now()
341
+ var backoff = 0
342
+ fs$rename(from, to, function CB(er) {
343
+ if (
344
+ er &&
345
+ (er.code === 'EACCES' || er.code === 'EPERM' || er.code === 'EBUSY') &&
346
+ Date.now() - start < 6e4
347
+ ) {
348
+ setTimeout(function () {
349
+ fs2.stat(to, function (stater, st) {
350
+ if (stater && stater.code === 'ENOENT') fs$rename(from, to, CB)
351
+ else cb(er)
352
+ })
353
+ }, backoff)
354
+ if (backoff < 100) backoff += 10
355
+ return
356
+ }
357
+ if (cb) cb(er)
358
+ })
359
+ }
360
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename)
361
+ return rename
362
+ })(fs2.rename)
363
+ }
364
+ fs2.read =
365
+ typeof fs2.read !== 'function'
366
+ ? fs2.read
367
+ : (function (fs$read) {
368
+ function read(fd, buffer, offset, length, position, callback_) {
369
+ var callback
370
+ if (callback_ && typeof callback_ === 'function') {
371
+ var eagCounter = 0
372
+ callback = function (er, _, __) {
373
+ if (er && er.code === 'EAGAIN' && eagCounter < 10) {
374
+ eagCounter++
375
+ return fs$read.call(fs2, fd, buffer, offset, length, position, callback)
376
+ }
377
+ callback_.apply(this, arguments)
378
+ }
379
+ }
380
+ return fs$read.call(fs2, fd, buffer, offset, length, position, callback)
381
+ }
382
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read)
383
+ return read
384
+ })(fs2.read)
385
+ fs2.readSync =
386
+ typeof fs2.readSync !== 'function'
387
+ ? fs2.readSync
388
+ : /* @__PURE__ */ (function (fs$readSync) {
389
+ return function (fd, buffer, offset, length, position) {
390
+ var eagCounter = 0
391
+ while (true) {
392
+ try {
393
+ return fs$readSync.call(fs2, fd, buffer, offset, length, position)
394
+ } catch (er) {
395
+ if (er.code === 'EAGAIN' && eagCounter < 10) {
396
+ eagCounter++
397
+ continue
398
+ }
399
+ throw er
400
+ }
401
+ }
402
+ }
403
+ })(fs2.readSync)
404
+ function patchLchmod(fs3) {
405
+ fs3.lchmod = function (path, mode, callback) {
406
+ fs3.open(path, constants2.O_WRONLY | constants2.O_SYMLINK, mode, function (err, fd) {
407
+ if (err) {
408
+ if (callback) callback(err)
409
+ return
410
+ }
411
+ fs3.fchmod(fd, mode, function (err2) {
412
+ fs3.close(fd, function (err22) {
413
+ if (callback) callback(err2 || err22)
414
+ })
415
+ })
416
+ })
417
+ }
418
+ fs3.lchmodSync = function (path, mode) {
419
+ var fd = fs3.openSync(path, constants2.O_WRONLY | constants2.O_SYMLINK, mode)
420
+ var threw = true
421
+ var ret
422
+ try {
423
+ ret = fs3.fchmodSync(fd, mode)
424
+ threw = false
425
+ } finally {
426
+ if (threw) {
427
+ try {
428
+ fs3.closeSync(fd)
429
+ } catch (er) {}
430
+ } else {
431
+ fs3.closeSync(fd)
432
+ }
433
+ }
434
+ return ret
435
+ }
436
+ }
437
+ function patchLutimes(fs3) {
438
+ if (constants2.hasOwnProperty('O_SYMLINK') && fs3.futimes) {
439
+ fs3.lutimes = function (path, at, mt, cb) {
440
+ fs3.open(path, constants2.O_SYMLINK, function (er, fd) {
441
+ if (er) {
442
+ if (cb) cb(er)
443
+ return
444
+ }
445
+ fs3.futimes(fd, at, mt, function (er2) {
446
+ fs3.close(fd, function (er22) {
447
+ if (cb) cb(er2 || er22)
448
+ })
449
+ })
450
+ })
451
+ }
452
+ fs3.lutimesSync = function (path, at, mt) {
453
+ var fd = fs3.openSync(path, constants2.O_SYMLINK)
454
+ var ret
455
+ var threw = true
456
+ try {
457
+ ret = fs3.futimesSync(fd, at, mt)
458
+ threw = false
459
+ } finally {
460
+ if (threw) {
461
+ try {
462
+ fs3.closeSync(fd)
463
+ } catch (er) {}
464
+ } else {
465
+ fs3.closeSync(fd)
466
+ }
467
+ }
468
+ return ret
469
+ }
470
+ } else if (fs3.futimes) {
471
+ fs3.lutimes = function (_a, _b, _c, cb) {
472
+ if (cb) process.nextTick(cb)
473
+ }
474
+ fs3.lutimesSync = function () {}
475
+ }
476
+ }
477
+ function chmodFix(orig) {
478
+ if (!orig) return orig
479
+ return function (target, mode, cb) {
480
+ return orig.call(fs2, target, mode, function (er) {
481
+ if (chownErOk(er)) er = null
482
+ if (cb) cb.apply(this, arguments)
483
+ })
484
+ }
485
+ }
486
+ function chmodFixSync(orig) {
487
+ if (!orig) return orig
488
+ return function (target, mode) {
489
+ try {
490
+ return orig.call(fs2, target, mode)
491
+ } catch (er) {
492
+ if (!chownErOk(er)) throw er
493
+ }
494
+ }
495
+ }
496
+ function chownFix(orig) {
497
+ if (!orig) return orig
498
+ return function (target, uid, gid, cb) {
499
+ return orig.call(fs2, target, uid, gid, function (er) {
500
+ if (chownErOk(er)) er = null
501
+ if (cb) cb.apply(this, arguments)
502
+ })
503
+ }
504
+ }
505
+ function chownFixSync(orig) {
506
+ if (!orig) return orig
507
+ return function (target, uid, gid) {
508
+ try {
509
+ return orig.call(fs2, target, uid, gid)
510
+ } catch (er) {
511
+ if (!chownErOk(er)) throw er
512
+ }
513
+ }
514
+ }
515
+ function statFix(orig) {
516
+ if (!orig) return orig
517
+ return function (target, options, cb) {
518
+ if (typeof options === 'function') {
519
+ cb = options
520
+ options = null
521
+ }
522
+ function callback(er, stats) {
523
+ if (stats) {
524
+ if (stats.uid < 0) stats.uid += 4294967296
525
+ if (stats.gid < 0) stats.gid += 4294967296
526
+ }
527
+ if (cb) cb.apply(this, arguments)
528
+ }
529
+ return options
530
+ ? orig.call(fs2, target, options, callback)
531
+ : orig.call(fs2, target, callback)
532
+ }
533
+ }
534
+ function statFixSync(orig) {
535
+ if (!orig) return orig
536
+ return function (target, options) {
537
+ var stats = options ? orig.call(fs2, target, options) : orig.call(fs2, target)
538
+ if (stats) {
539
+ if (stats.uid < 0) stats.uid += 4294967296
540
+ if (stats.gid < 0) stats.gid += 4294967296
541
+ }
542
+ return stats
543
+ }
544
+ }
545
+ function chownErOk(er) {
546
+ if (!er) return true
547
+ if (er.code === 'ENOSYS') return true
548
+ var nonroot = !process.getuid || process.getuid() !== 0
549
+ if (nonroot) {
550
+ if (er.code === 'EINVAL' || er.code === 'EPERM') return true
551
+ }
552
+ return false
553
+ }
554
+ }
555
+ },
556
+ })
557
+
558
+ // node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/legacy-streams.js
559
+ var require_legacy_streams = __commonJS({
560
+ 'node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/legacy-streams.js'(
561
+ exports,
562
+ module,
563
+ ) {
564
+ var Stream = __require('stream').Stream
565
+ module.exports = legacy
566
+ function legacy(fs2) {
567
+ return {
568
+ ReadStream,
569
+ WriteStream,
570
+ }
571
+ function ReadStream(path, options) {
572
+ if (!(this instanceof ReadStream)) return new ReadStream(path, options)
573
+ Stream.call(this)
574
+ var self = this
575
+ this.path = path
576
+ this.fd = null
577
+ this.readable = true
578
+ this.paused = false
579
+ this.flags = 'r'
580
+ this.mode = 438
581
+ this.bufferSize = 64 * 1024
582
+ options = options || {}
583
+ var keys = Object.keys(options)
584
+ for (var index = 0, length = keys.length; index < length; index++) {
585
+ var key = keys[index]
586
+ this[key] = options[key]
587
+ }
588
+ if (this.encoding) this.setEncoding(this.encoding)
589
+ if (this.start !== void 0) {
590
+ if ('number' !== typeof this.start) {
591
+ throw TypeError('start must be a Number')
592
+ }
593
+ if (this.end === void 0) {
594
+ this.end = Infinity
595
+ } else if ('number' !== typeof this.end) {
596
+ throw TypeError('end must be a Number')
597
+ }
598
+ if (this.start > this.end) {
599
+ throw new Error('start must be <= end')
600
+ }
601
+ this.pos = this.start
602
+ }
603
+ if (this.fd !== null) {
604
+ process.nextTick(function () {
605
+ self._read()
606
+ })
607
+ return
608
+ }
609
+ fs2.open(this.path, this.flags, this.mode, function (err, fd) {
610
+ if (err) {
611
+ self.emit('error', err)
612
+ self.readable = false
613
+ return
614
+ }
615
+ self.fd = fd
616
+ self.emit('open', fd)
617
+ self._read()
618
+ })
619
+ }
620
+ function WriteStream(path, options) {
621
+ if (!(this instanceof WriteStream)) return new WriteStream(path, options)
622
+ Stream.call(this)
623
+ this.path = path
624
+ this.fd = null
625
+ this.writable = true
626
+ this.flags = 'w'
627
+ this.encoding = 'binary'
628
+ this.mode = 438
629
+ this.bytesWritten = 0
630
+ options = options || {}
631
+ var keys = Object.keys(options)
632
+ for (var index = 0, length = keys.length; index < length; index++) {
633
+ var key = keys[index]
634
+ this[key] = options[key]
635
+ }
636
+ if (this.start !== void 0) {
637
+ if ('number' !== typeof this.start) {
638
+ throw TypeError('start must be a Number')
639
+ }
640
+ if (this.start < 0) {
641
+ throw new Error('start must be >= zero')
642
+ }
643
+ this.pos = this.start
644
+ }
645
+ this.busy = false
646
+ this._queue = []
647
+ if (this.fd === null) {
648
+ this._open = fs2.open
649
+ this._queue.push([this._open, this.path, this.flags, this.mode, void 0])
650
+ this.flush()
651
+ }
652
+ }
653
+ }
654
+ },
655
+ })
656
+
657
+ // node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/clone.js
658
+ var require_clone = __commonJS({
659
+ 'node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/clone.js'(exports, module) {
660
+ 'use strict'
661
+ module.exports = clone
662
+ var getPrototypeOf =
663
+ Object.getPrototypeOf ||
664
+ function (obj) {
665
+ return obj.__proto__
666
+ }
667
+ function clone(obj) {
668
+ if (obj === null || typeof obj !== 'object') return obj
669
+ if (obj instanceof Object) var copy = { __proto__: getPrototypeOf(obj) }
670
+ else var copy = /* @__PURE__ */ Object.create(null)
671
+ Object.getOwnPropertyNames(obj).forEach(function (key) {
672
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
673
+ })
674
+ return copy
675
+ }
676
+ },
677
+ })
678
+
679
+ // node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js
680
+ var require_graceful_fs = __commonJS({
681
+ 'node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js'(exports, module) {
682
+ var fs2 = __require('fs')
683
+ var polyfills = require_polyfills()
684
+ var legacy = require_legacy_streams()
685
+ var clone = require_clone()
686
+ var util = __require('util')
687
+ var gracefulQueue
688
+ var previousSymbol
689
+ if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
690
+ gracefulQueue = /* @__PURE__ */ Symbol.for('graceful-fs.queue')
691
+ previousSymbol = /* @__PURE__ */ Symbol.for('graceful-fs.previous')
692
+ } else {
693
+ gracefulQueue = '___graceful-fs.queue'
694
+ previousSymbol = '___graceful-fs.previous'
695
+ }
696
+ function noop() {}
697
+ function publishQueue(context, queue2) {
698
+ Object.defineProperty(context, gracefulQueue, {
699
+ get: function () {
700
+ return queue2
701
+ },
702
+ })
703
+ }
704
+ var debug = noop
705
+ if (util.debuglog) debug = util.debuglog('gfs4')
706
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
707
+ debug = function () {
708
+ var m = util.format.apply(util, arguments)
709
+ m = 'GFS4: ' + m.split(/\n/).join('\nGFS4: ')
710
+ console.error(m)
711
+ }
712
+ if (!fs2[gracefulQueue]) {
713
+ queue = global[gracefulQueue] || []
714
+ publishQueue(fs2, queue)
715
+ fs2.close = (function (fs$close) {
716
+ function close(fd, cb) {
717
+ return fs$close.call(fs2, fd, function (err) {
718
+ if (!err) {
719
+ resetQueue()
720
+ }
721
+ if (typeof cb === 'function') cb.apply(this, arguments)
722
+ })
723
+ }
724
+ Object.defineProperty(close, previousSymbol, {
725
+ value: fs$close,
726
+ })
727
+ return close
728
+ })(fs2.close)
729
+ fs2.closeSync = (function (fs$closeSync) {
730
+ function closeSync2(fd) {
731
+ fs$closeSync.apply(fs2, arguments)
732
+ resetQueue()
733
+ }
734
+ Object.defineProperty(closeSync2, previousSymbol, {
735
+ value: fs$closeSync,
736
+ })
737
+ return closeSync2
738
+ })(fs2.closeSync)
739
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
740
+ process.on('exit', function () {
741
+ debug(fs2[gracefulQueue])
742
+ __require('assert').equal(fs2[gracefulQueue].length, 0)
743
+ })
744
+ }
745
+ }
746
+ var queue
747
+ if (!global[gracefulQueue]) {
748
+ publishQueue(global, fs2[gracefulQueue])
749
+ }
750
+ module.exports = patch(clone(fs2))
751
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs2.__patched) {
752
+ module.exports = patch(fs2)
753
+ fs2.__patched = true
754
+ }
755
+ function patch(fs3) {
756
+ polyfills(fs3)
757
+ fs3.gracefulify = patch
758
+ fs3.createReadStream = createReadStream
759
+ fs3.createWriteStream = createWriteStream
760
+ var fs$readFile = fs3.readFile
761
+ fs3.readFile = readFile
762
+ function readFile(path, options, cb) {
763
+ if (typeof options === 'function') (cb = options), (options = null)
764
+ return go$readFile(path, options, cb)
765
+ function go$readFile(path2, options2, cb2, startTime) {
766
+ return fs$readFile(path2, options2, function (err) {
767
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
768
+ enqueue([
769
+ go$readFile,
770
+ [path2, options2, cb2],
771
+ err,
772
+ startTime || Date.now(),
773
+ Date.now(),
774
+ ])
775
+ else {
776
+ if (typeof cb2 === 'function') cb2.apply(this, arguments)
777
+ }
778
+ })
779
+ }
780
+ }
781
+ var fs$writeFile = fs3.writeFile
782
+ fs3.writeFile = writeFile
783
+ function writeFile(path, data, options, cb) {
784
+ if (typeof options === 'function') (cb = options), (options = null)
785
+ return go$writeFile(path, data, options, cb)
786
+ function go$writeFile(path2, data2, options2, cb2, startTime) {
787
+ return fs$writeFile(path2, data2, options2, function (err) {
788
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
789
+ enqueue([
790
+ go$writeFile,
791
+ [path2, data2, options2, cb2],
792
+ err,
793
+ startTime || Date.now(),
794
+ Date.now(),
795
+ ])
796
+ else {
797
+ if (typeof cb2 === 'function') cb2.apply(this, arguments)
798
+ }
799
+ })
800
+ }
801
+ }
802
+ var fs$appendFile = fs3.appendFile
803
+ if (fs$appendFile) fs3.appendFile = appendFile
804
+ function appendFile(path, data, options, cb) {
805
+ if (typeof options === 'function') (cb = options), (options = null)
806
+ return go$appendFile(path, data, options, cb)
807
+ function go$appendFile(path2, data2, options2, cb2, startTime) {
808
+ return fs$appendFile(path2, data2, options2, function (err) {
809
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
810
+ enqueue([
811
+ go$appendFile,
812
+ [path2, data2, options2, cb2],
813
+ err,
814
+ startTime || Date.now(),
815
+ Date.now(),
816
+ ])
817
+ else {
818
+ if (typeof cb2 === 'function') cb2.apply(this, arguments)
819
+ }
820
+ })
821
+ }
822
+ }
823
+ var fs$copyFile = fs3.copyFile
824
+ if (fs$copyFile) fs3.copyFile = copyFile
825
+ function copyFile(src, dest, flags, cb) {
826
+ if (typeof flags === 'function') {
827
+ cb = flags
828
+ flags = 0
829
+ }
830
+ return go$copyFile(src, dest, flags, cb)
831
+ function go$copyFile(src2, dest2, flags2, cb2, startTime) {
832
+ return fs$copyFile(src2, dest2, flags2, function (err) {
833
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
834
+ enqueue([
835
+ go$copyFile,
836
+ [src2, dest2, flags2, cb2],
837
+ err,
838
+ startTime || Date.now(),
839
+ Date.now(),
840
+ ])
841
+ else {
842
+ if (typeof cb2 === 'function') cb2.apply(this, arguments)
843
+ }
844
+ })
845
+ }
846
+ }
847
+ var fs$readdir = fs3.readdir
848
+ fs3.readdir = readdir
849
+ var noReaddirOptionVersions = /^v[0-5]\./
850
+ function readdir(path, options, cb) {
851
+ if (typeof options === 'function') (cb = options), (options = null)
852
+ var go$readdir = noReaddirOptionVersions.test(process.version)
853
+ ? function go$readdir2(path2, options2, cb2, startTime) {
854
+ return fs$readdir(path2, fs$readdirCallback(path2, options2, cb2, startTime))
855
+ }
856
+ : function go$readdir2(path2, options2, cb2, startTime) {
857
+ return fs$readdir(
858
+ path2,
859
+ options2,
860
+ fs$readdirCallback(path2, options2, cb2, startTime),
861
+ )
862
+ }
863
+ return go$readdir(path, options, cb)
864
+ function fs$readdirCallback(path2, options2, cb2, startTime) {
865
+ return function (err, files) {
866
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
867
+ enqueue([
868
+ go$readdir,
869
+ [path2, options2, cb2],
870
+ err,
871
+ startTime || Date.now(),
872
+ Date.now(),
873
+ ])
874
+ else {
875
+ if (files && files.sort) files.sort()
876
+ if (typeof cb2 === 'function') cb2.call(this, err, files)
877
+ }
878
+ }
879
+ }
880
+ }
881
+ if (process.version.substr(0, 4) === 'v0.8') {
882
+ var legStreams = legacy(fs3)
883
+ ReadStream = legStreams.ReadStream
884
+ WriteStream = legStreams.WriteStream
885
+ }
886
+ var fs$ReadStream = fs3.ReadStream
887
+ if (fs$ReadStream) {
888
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype)
889
+ ReadStream.prototype.open = ReadStream$open
890
+ }
891
+ var fs$WriteStream = fs3.WriteStream
892
+ if (fs$WriteStream) {
893
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype)
894
+ WriteStream.prototype.open = WriteStream$open
895
+ }
896
+ Object.defineProperty(fs3, 'ReadStream', {
897
+ get: function () {
898
+ return ReadStream
899
+ },
900
+ set: function (val) {
901
+ ReadStream = val
902
+ },
903
+ enumerable: true,
904
+ configurable: true,
905
+ })
906
+ Object.defineProperty(fs3, 'WriteStream', {
907
+ get: function () {
908
+ return WriteStream
909
+ },
910
+ set: function (val) {
911
+ WriteStream = val
912
+ },
913
+ enumerable: true,
914
+ configurable: true,
915
+ })
916
+ var FileReadStream = ReadStream
917
+ Object.defineProperty(fs3, 'FileReadStream', {
918
+ get: function () {
919
+ return FileReadStream
920
+ },
921
+ set: function (val) {
922
+ FileReadStream = val
923
+ },
924
+ enumerable: true,
925
+ configurable: true,
926
+ })
927
+ var FileWriteStream = WriteStream
928
+ Object.defineProperty(fs3, 'FileWriteStream', {
929
+ get: function () {
930
+ return FileWriteStream
931
+ },
932
+ set: function (val) {
933
+ FileWriteStream = val
934
+ },
935
+ enumerable: true,
936
+ configurable: true,
937
+ })
938
+ function ReadStream(path, options) {
939
+ if (this instanceof ReadStream) return fs$ReadStream.apply(this, arguments), this
940
+ else return ReadStream.apply(Object.create(ReadStream.prototype), arguments)
941
+ }
942
+ function ReadStream$open() {
943
+ var that = this
944
+ open(that.path, that.flags, that.mode, function (err, fd) {
945
+ if (err) {
946
+ if (that.autoClose) that.destroy()
947
+ that.emit('error', err)
948
+ } else {
949
+ that.fd = fd
950
+ that.emit('open', fd)
951
+ that.read()
952
+ }
953
+ })
954
+ }
955
+ function WriteStream(path, options) {
956
+ if (this instanceof WriteStream) return fs$WriteStream.apply(this, arguments), this
957
+ else return WriteStream.apply(Object.create(WriteStream.prototype), arguments)
958
+ }
959
+ function WriteStream$open() {
960
+ var that = this
961
+ open(that.path, that.flags, that.mode, function (err, fd) {
962
+ if (err) {
963
+ that.destroy()
964
+ that.emit('error', err)
965
+ } else {
966
+ that.fd = fd
967
+ that.emit('open', fd)
968
+ }
969
+ })
970
+ }
971
+ function createReadStream(path, options) {
972
+ return new fs3.ReadStream(path, options)
973
+ }
974
+ function createWriteStream(path, options) {
975
+ return new fs3.WriteStream(path, options)
976
+ }
977
+ var fs$open = fs3.open
978
+ fs3.open = open
979
+ function open(path, flags, mode, cb) {
980
+ if (typeof mode === 'function') (cb = mode), (mode = null)
981
+ return go$open(path, flags, mode, cb)
982
+ function go$open(path2, flags2, mode2, cb2, startTime) {
983
+ return fs$open(path2, flags2, mode2, function (err, fd) {
984
+ if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
985
+ enqueue([
986
+ go$open,
987
+ [path2, flags2, mode2, cb2],
988
+ err,
989
+ startTime || Date.now(),
990
+ Date.now(),
991
+ ])
992
+ else {
993
+ if (typeof cb2 === 'function') cb2.apply(this, arguments)
994
+ }
995
+ })
996
+ }
997
+ }
998
+ return fs3
999
+ }
1000
+ function enqueue(elem) {
1001
+ debug('ENQUEUE', elem[0].name, elem[1])
1002
+ fs2[gracefulQueue].push(elem)
1003
+ retry()
1004
+ }
1005
+ var retryTimer
1006
+ function resetQueue() {
1007
+ var now = Date.now()
1008
+ for (var i = 0; i < fs2[gracefulQueue].length; ++i) {
1009
+ if (fs2[gracefulQueue][i].length > 2) {
1010
+ fs2[gracefulQueue][i][3] = now
1011
+ fs2[gracefulQueue][i][4] = now
1012
+ }
1013
+ }
1014
+ retry()
1015
+ }
1016
+ function retry() {
1017
+ clearTimeout(retryTimer)
1018
+ retryTimer = void 0
1019
+ if (fs2[gracefulQueue].length === 0) return
1020
+ var elem = fs2[gracefulQueue].shift()
1021
+ var fn = elem[0]
1022
+ var args = elem[1]
1023
+ var err = elem[2]
1024
+ var startTime = elem[3]
1025
+ var lastTime = elem[4]
1026
+ if (startTime === void 0) {
1027
+ debug('RETRY', fn.name, args)
1028
+ fn.apply(null, args)
1029
+ } else if (Date.now() - startTime >= 6e4) {
1030
+ debug('TIMEOUT', fn.name, args)
1031
+ var cb = args.pop()
1032
+ if (typeof cb === 'function') cb.call(null, err)
1033
+ } else {
1034
+ var sinceAttempt = Date.now() - lastTime
1035
+ var sinceStart = Math.max(lastTime - startTime, 1)
1036
+ var desiredDelay = Math.min(sinceStart * 1.2, 100)
1037
+ if (sinceAttempt >= desiredDelay) {
1038
+ debug('RETRY', fn.name, args)
1039
+ fn.apply(null, args.concat([startTime]))
1040
+ } else {
1041
+ fs2[gracefulQueue].push(elem)
1042
+ }
1043
+ }
1044
+ if (retryTimer === void 0) {
1045
+ retryTimer = setTimeout(retry, 0)
1046
+ }
1047
+ }
1048
+ },
1049
+ })
1050
+
1051
+ // node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry_operation.js
1052
+ var require_retry_operation = __commonJS({
1053
+ 'node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry_operation.js'(exports, module) {
1054
+ function RetryOperation(timeouts, options) {
1055
+ if (typeof options === 'boolean') {
1056
+ options = { forever: options }
1057
+ }
1058
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts))
1059
+ this._timeouts = timeouts
1060
+ this._options = options || {}
1061
+ this._maxRetryTime = (options && options.maxRetryTime) || Infinity
1062
+ this._fn = null
1063
+ this._errors = []
1064
+ this._attempts = 1
1065
+ this._operationTimeout = null
1066
+ this._operationTimeoutCb = null
1067
+ this._timeout = null
1068
+ this._operationStart = null
1069
+ if (this._options.forever) {
1070
+ this._cachedTimeouts = this._timeouts.slice(0)
1071
+ }
1072
+ }
1073
+ module.exports = RetryOperation
1074
+ RetryOperation.prototype.reset = function () {
1075
+ this._attempts = 1
1076
+ this._timeouts = this._originalTimeouts
1077
+ }
1078
+ RetryOperation.prototype.stop = function () {
1079
+ if (this._timeout) {
1080
+ clearTimeout(this._timeout)
1081
+ }
1082
+ this._timeouts = []
1083
+ this._cachedTimeouts = null
1084
+ }
1085
+ RetryOperation.prototype.retry = function (err) {
1086
+ if (this._timeout) {
1087
+ clearTimeout(this._timeout)
1088
+ }
1089
+ if (!err) {
1090
+ return false
1091
+ }
1092
+ var currentTime = /* @__PURE__ */ new Date().getTime()
1093
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
1094
+ this._errors.unshift(new Error('RetryOperation timeout occurred'))
1095
+ return false
1096
+ }
1097
+ this._errors.push(err)
1098
+ var timeout = this._timeouts.shift()
1099
+ if (timeout === void 0) {
1100
+ if (this._cachedTimeouts) {
1101
+ this._errors.splice(this._errors.length - 1, this._errors.length)
1102
+ this._timeouts = this._cachedTimeouts.slice(0)
1103
+ timeout = this._timeouts.shift()
1104
+ } else {
1105
+ return false
1106
+ }
1107
+ }
1108
+ var self = this
1109
+ var timer = setTimeout(function () {
1110
+ self._attempts++
1111
+ if (self._operationTimeoutCb) {
1112
+ self._timeout = setTimeout(function () {
1113
+ self._operationTimeoutCb(self._attempts)
1114
+ }, self._operationTimeout)
1115
+ if (self._options.unref) {
1116
+ self._timeout.unref()
1117
+ }
1118
+ }
1119
+ self._fn(self._attempts)
1120
+ }, timeout)
1121
+ if (this._options.unref) {
1122
+ timer.unref()
1123
+ }
1124
+ return true
1125
+ }
1126
+ RetryOperation.prototype.attempt = function (fn, timeoutOps) {
1127
+ this._fn = fn
1128
+ if (timeoutOps) {
1129
+ if (timeoutOps.timeout) {
1130
+ this._operationTimeout = timeoutOps.timeout
1131
+ }
1132
+ if (timeoutOps.cb) {
1133
+ this._operationTimeoutCb = timeoutOps.cb
1134
+ }
1135
+ }
1136
+ var self = this
1137
+ if (this._operationTimeoutCb) {
1138
+ this._timeout = setTimeout(function () {
1139
+ self._operationTimeoutCb()
1140
+ }, self._operationTimeout)
1141
+ }
1142
+ this._operationStart = /* @__PURE__ */ new Date().getTime()
1143
+ this._fn(this._attempts)
1144
+ }
1145
+ RetryOperation.prototype.try = function (fn) {
1146
+ console.log('Using RetryOperation.try() is deprecated')
1147
+ this.attempt(fn)
1148
+ }
1149
+ RetryOperation.prototype.start = function (fn) {
1150
+ console.log('Using RetryOperation.start() is deprecated')
1151
+ this.attempt(fn)
1152
+ }
1153
+ RetryOperation.prototype.start = RetryOperation.prototype.try
1154
+ RetryOperation.prototype.errors = function () {
1155
+ return this._errors
1156
+ }
1157
+ RetryOperation.prototype.attempts = function () {
1158
+ return this._attempts
1159
+ }
1160
+ RetryOperation.prototype.mainError = function () {
1161
+ if (this._errors.length === 0) {
1162
+ return null
1163
+ }
1164
+ var counts = {}
1165
+ var mainError = null
1166
+ var mainErrorCount = 0
1167
+ for (var i = 0; i < this._errors.length; i++) {
1168
+ var error = this._errors[i]
1169
+ var message = error.message
1170
+ var count = (counts[message] || 0) + 1
1171
+ counts[message] = count
1172
+ if (count >= mainErrorCount) {
1173
+ mainError = error
1174
+ mainErrorCount = count
1175
+ }
1176
+ }
1177
+ return mainError
1178
+ }
1179
+ },
1180
+ })
1181
+
1182
+ // node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry.js
1183
+ var require_retry = __commonJS({
1184
+ 'node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry.js'(exports) {
1185
+ var RetryOperation = require_retry_operation()
1186
+ exports.operation = function (options) {
1187
+ var timeouts = exports.timeouts(options)
1188
+ return new RetryOperation(timeouts, {
1189
+ forever: options && options.forever,
1190
+ unref: options && options.unref,
1191
+ maxRetryTime: options && options.maxRetryTime,
1192
+ })
1193
+ }
1194
+ exports.timeouts = function (options) {
1195
+ if (options instanceof Array) {
1196
+ return [].concat(options)
1197
+ }
1198
+ var opts = {
1199
+ retries: 10,
1200
+ factor: 2,
1201
+ minTimeout: 1 * 1e3,
1202
+ maxTimeout: Infinity,
1203
+ randomize: false,
1204
+ }
1205
+ for (var key in options) {
1206
+ opts[key] = options[key]
1207
+ }
1208
+ if (opts.minTimeout > opts.maxTimeout) {
1209
+ throw new Error('minTimeout is greater than maxTimeout')
1210
+ }
1211
+ var timeouts = []
1212
+ for (var i = 0; i < opts.retries; i++) {
1213
+ timeouts.push(this.createTimeout(i, opts))
1214
+ }
1215
+ if (options && options.forever && !timeouts.length) {
1216
+ timeouts.push(this.createTimeout(i, opts))
1217
+ }
1218
+ timeouts.sort(function (a, b) {
1219
+ return a - b
1220
+ })
1221
+ return timeouts
1222
+ }
1223
+ exports.createTimeout = function (attempt, opts) {
1224
+ var random = opts.randomize ? Math.random() + 1 : 1
1225
+ var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt))
1226
+ timeout = Math.min(timeout, opts.maxTimeout)
1227
+ return timeout
1228
+ }
1229
+ exports.wrap = function (obj, options, methods) {
1230
+ if (options instanceof Array) {
1231
+ methods = options
1232
+ options = null
1233
+ }
1234
+ if (!methods) {
1235
+ methods = []
1236
+ for (var key in obj) {
1237
+ if (typeof obj[key] === 'function') {
1238
+ methods.push(key)
1239
+ }
1240
+ }
1241
+ }
1242
+ for (var i = 0; i < methods.length; i++) {
1243
+ var method = methods[i]
1244
+ var original = obj[method]
1245
+ obj[method] = function retryWrapper(original2) {
1246
+ var op = exports.operation(options)
1247
+ var args = Array.prototype.slice.call(arguments, 1)
1248
+ var callback = args.pop()
1249
+ args.push(function (err) {
1250
+ if (op.retry(err)) {
1251
+ return
1252
+ }
1253
+ if (err) {
1254
+ arguments[0] = op.mainError()
1255
+ }
1256
+ callback.apply(this, arguments)
1257
+ })
1258
+ op.attempt(function () {
1259
+ original2.apply(obj, args)
1260
+ })
1261
+ }.bind(obj, original)
1262
+ obj[method].options = options
1263
+ }
1264
+ }
1265
+ },
1266
+ })
1267
+
1268
+ // node_modules/.pnpm/retry@0.12.0/node_modules/retry/index.js
1269
+ var require_retry2 = __commonJS({
1270
+ 'node_modules/.pnpm/retry@0.12.0/node_modules/retry/index.js'(exports, module) {
1271
+ module.exports = require_retry()
1272
+ },
1273
+ })
1274
+
1275
+ // node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/signals.js
1276
+ var require_signals = __commonJS({
1277
+ 'node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/signals.js'(exports, module) {
1278
+ module.exports = ['SIGABRT', 'SIGALRM', 'SIGHUP', 'SIGINT', 'SIGTERM']
1279
+ if (process.platform !== 'win32') {
1280
+ module.exports.push(
1281
+ 'SIGVTALRM',
1282
+ 'SIGXCPU',
1283
+ 'SIGXFSZ',
1284
+ 'SIGUSR2',
1285
+ 'SIGTRAP',
1286
+ 'SIGSYS',
1287
+ 'SIGQUIT',
1288
+ 'SIGIOT',
1289
+ // should detect profiler and enable/disable accordingly.
1290
+ // see #21
1291
+ // 'SIGPROF'
1292
+ )
1293
+ }
1294
+ if (process.platform === 'linux') {
1295
+ module.exports.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT', 'SIGUNUSED')
1296
+ }
1297
+ },
1298
+ })
1299
+
1300
+ // node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/index.js
1301
+ var require_signal_exit = __commonJS({
1302
+ 'node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/index.js'(exports, module) {
1303
+ var process2 = global.process
1304
+ var processOk = function (process3) {
1305
+ return (
1306
+ process3 &&
1307
+ typeof process3 === 'object' &&
1308
+ typeof process3.removeListener === 'function' &&
1309
+ typeof process3.emit === 'function' &&
1310
+ typeof process3.reallyExit === 'function' &&
1311
+ typeof process3.listeners === 'function' &&
1312
+ typeof process3.kill === 'function' &&
1313
+ typeof process3.pid === 'number' &&
1314
+ typeof process3.on === 'function'
1315
+ )
1316
+ }
1317
+ if (!processOk(process2)) {
1318
+ module.exports = function () {
1319
+ return function () {}
1320
+ }
1321
+ } else {
1322
+ assert = __require('assert')
1323
+ signals = require_signals()
1324
+ isWin = /^win/i.test(process2.platform)
1325
+ EE = __require('events')
1326
+ if (typeof EE !== 'function') {
1327
+ EE = EE.EventEmitter
1328
+ }
1329
+ if (process2.__signal_exit_emitter__) {
1330
+ emitter = process2.__signal_exit_emitter__
1331
+ } else {
1332
+ emitter = process2.__signal_exit_emitter__ = new EE()
1333
+ emitter.count = 0
1334
+ emitter.emitted = {}
1335
+ }
1336
+ if (!emitter.infinite) {
1337
+ emitter.setMaxListeners(Infinity)
1338
+ emitter.infinite = true
1339
+ }
1340
+ module.exports = function (cb, opts) {
1341
+ if (!processOk(global.process)) {
1342
+ return function () {}
1343
+ }
1344
+ assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler')
1345
+ if (loaded === false) {
1346
+ load()
1347
+ }
1348
+ var ev = 'exit'
1349
+ if (opts && opts.alwaysLast) {
1350
+ ev = 'afterexit'
1351
+ }
1352
+ var remove = function () {
1353
+ emitter.removeListener(ev, cb)
1354
+ if (
1355
+ emitter.listeners('exit').length === 0 &&
1356
+ emitter.listeners('afterexit').length === 0
1357
+ ) {
1358
+ unload()
1359
+ }
1360
+ }
1361
+ emitter.on(ev, cb)
1362
+ return remove
1363
+ }
1364
+ unload = function unload2() {
1365
+ if (!loaded || !processOk(global.process)) {
1366
+ return
1367
+ }
1368
+ loaded = false
1369
+ signals.forEach(function (sig) {
1370
+ try {
1371
+ process2.removeListener(sig, sigListeners[sig])
1372
+ } catch (er) {}
1373
+ })
1374
+ process2.emit = originalProcessEmit
1375
+ process2.reallyExit = originalProcessReallyExit
1376
+ emitter.count -= 1
1377
+ }
1378
+ module.exports.unload = unload
1379
+ emit = function emit2(event, code, signal) {
1380
+ if (emitter.emitted[event]) {
1381
+ return
1382
+ }
1383
+ emitter.emitted[event] = true
1384
+ emitter.emit(event, code, signal)
1385
+ }
1386
+ sigListeners = {}
1387
+ signals.forEach(function (sig) {
1388
+ sigListeners[sig] = function listener() {
1389
+ if (!processOk(global.process)) {
1390
+ return
1391
+ }
1392
+ var listeners = process2.listeners(sig)
1393
+ if (listeners.length === emitter.count) {
1394
+ unload()
1395
+ emit('exit', null, sig)
1396
+ emit('afterexit', null, sig)
1397
+ if (isWin && sig === 'SIGHUP') {
1398
+ sig = 'SIGINT'
1399
+ }
1400
+ process2.kill(process2.pid, sig)
1401
+ }
1402
+ }
1403
+ })
1404
+ module.exports.signals = function () {
1405
+ return signals
1406
+ }
1407
+ loaded = false
1408
+ load = function load2() {
1409
+ if (loaded || !processOk(global.process)) {
1410
+ return
1411
+ }
1412
+ loaded = true
1413
+ emitter.count += 1
1414
+ signals = signals.filter(function (sig) {
1415
+ try {
1416
+ process2.on(sig, sigListeners[sig])
1417
+ return true
1418
+ } catch (er) {
1419
+ return false
1420
+ }
1421
+ })
1422
+ process2.emit = processEmit
1423
+ process2.reallyExit = processReallyExit
1424
+ }
1425
+ module.exports.load = load
1426
+ originalProcessReallyExit = process2.reallyExit
1427
+ processReallyExit = function processReallyExit2(code) {
1428
+ if (!processOk(global.process)) {
1429
+ return
1430
+ }
1431
+ process2.exitCode = code /* istanbul ignore next */ || 0
1432
+ emit('exit', process2.exitCode, null)
1433
+ emit('afterexit', process2.exitCode, null)
1434
+ originalProcessReallyExit.call(process2, process2.exitCode)
1435
+ }
1436
+ originalProcessEmit = process2.emit
1437
+ processEmit = function processEmit2(ev, arg) {
1438
+ if (ev === 'exit' && processOk(global.process)) {
1439
+ if (arg !== void 0) {
1440
+ process2.exitCode = arg
1441
+ }
1442
+ var ret = originalProcessEmit.apply(this, arguments)
1443
+ emit('exit', process2.exitCode, null)
1444
+ emit('afterexit', process2.exitCode, null)
1445
+ return ret
1446
+ } else {
1447
+ return originalProcessEmit.apply(this, arguments)
1448
+ }
1449
+ }
1450
+ }
1451
+ var assert
1452
+ var signals
1453
+ var isWin
1454
+ var EE
1455
+ var emitter
1456
+ var unload
1457
+ var emit
1458
+ var sigListeners
1459
+ var loaded
1460
+ var load
1461
+ var originalProcessReallyExit
1462
+ var processReallyExit
1463
+ var originalProcessEmit
1464
+ var processEmit
1465
+ },
1466
+ })
1467
+
1468
+ // node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js
1469
+ var require_mtime_precision = __commonJS({
1470
+ 'node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js'(
1471
+ exports,
1472
+ module,
1473
+ ) {
1474
+ 'use strict'
1475
+ var cacheSymbol = /* @__PURE__ */ Symbol()
1476
+ function probe(file, fs2, callback) {
1477
+ const cachedPrecision = fs2[cacheSymbol]
1478
+ if (cachedPrecision) {
1479
+ return fs2.stat(file, (err, stat) => {
1480
+ if (err) {
1481
+ return callback(err)
1482
+ }
1483
+ callback(null, stat.mtime, cachedPrecision)
1484
+ })
1485
+ }
1486
+ const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5)
1487
+ fs2.utimes(file, mtime, mtime, (err) => {
1488
+ if (err) {
1489
+ return callback(err)
1490
+ }
1491
+ fs2.stat(file, (err2, stat) => {
1492
+ if (err2) {
1493
+ return callback(err2)
1494
+ }
1495
+ const precision = stat.mtime.getTime() % 1e3 === 0 ? 's' : 'ms'
1496
+ Object.defineProperty(fs2, cacheSymbol, { value: precision })
1497
+ callback(null, stat.mtime, precision)
1498
+ })
1499
+ })
1500
+ }
1501
+ function getMtime(precision) {
1502
+ let now = Date.now()
1503
+ if (precision === 's') {
1504
+ now = Math.ceil(now / 1e3) * 1e3
1505
+ }
1506
+ return new Date(now)
1507
+ }
1508
+ module.exports.probe = probe
1509
+ module.exports.getMtime = getMtime
1510
+ },
1511
+ })
1512
+
1513
+ // node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js
1514
+ var require_lockfile = __commonJS({
1515
+ 'node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js'(
1516
+ exports,
1517
+ module,
1518
+ ) {
1519
+ 'use strict'
1520
+ var path = __require('path')
1521
+ var fs2 = require_graceful_fs()
1522
+ var retry = require_retry2()
1523
+ var onExit = require_signal_exit()
1524
+ var mtimePrecision = require_mtime_precision()
1525
+ var locks = {}
1526
+ function getLockFile(file, options) {
1527
+ return options.lockfilePath || `${file}.lock`
1528
+ }
1529
+ function resolveCanonicalPath(file, options, callback) {
1530
+ if (!options.realpath) {
1531
+ return callback(null, path.resolve(file))
1532
+ }
1533
+ options.fs.realpath(file, callback)
1534
+ }
1535
+ function acquireLock(file, options, callback) {
1536
+ const lockfilePath = getLockFile(file, options)
1537
+ options.fs.mkdir(lockfilePath, (err) => {
1538
+ if (!err) {
1539
+ return mtimePrecision.probe(lockfilePath, options.fs, (err2, mtime, mtimePrecision2) => {
1540
+ if (err2) {
1541
+ options.fs.rmdir(lockfilePath, () => {})
1542
+ return callback(err2)
1543
+ }
1544
+ callback(null, mtime, mtimePrecision2)
1545
+ })
1546
+ }
1547
+ if (err.code !== 'EEXIST') {
1548
+ return callback(err)
1549
+ }
1550
+ if (options.stale <= 0) {
1551
+ return callback(
1552
+ Object.assign(new Error('Lock file is already being held'), { code: 'ELOCKED', file }),
1553
+ )
1554
+ }
1555
+ options.fs.stat(lockfilePath, (err2, stat) => {
1556
+ if (err2) {
1557
+ if (err2.code === 'ENOENT') {
1558
+ return acquireLock(file, { ...options, stale: 0 }, callback)
1559
+ }
1560
+ return callback(err2)
1561
+ }
1562
+ if (!isLockStale(stat, options)) {
1563
+ return callback(
1564
+ Object.assign(new Error('Lock file is already being held'), {
1565
+ code: 'ELOCKED',
1566
+ file,
1567
+ }),
1568
+ )
1569
+ }
1570
+ removeLock(file, options, (err3) => {
1571
+ if (err3) {
1572
+ return callback(err3)
1573
+ }
1574
+ acquireLock(file, { ...options, stale: 0 }, callback)
1575
+ })
1576
+ })
1577
+ })
1578
+ }
1579
+ function isLockStale(stat, options) {
1580
+ return stat.mtime.getTime() < Date.now() - options.stale
1581
+ }
1582
+ function removeLock(file, options, callback) {
1583
+ options.fs.rmdir(getLockFile(file, options), (err) => {
1584
+ if (err && err.code !== 'ENOENT') {
1585
+ return callback(err)
1586
+ }
1587
+ callback()
1588
+ })
1589
+ }
1590
+ function updateLock(file, options) {
1591
+ const lock2 = locks[file]
1592
+ if (lock2.updateTimeout) {
1593
+ return
1594
+ }
1595
+ lock2.updateDelay = lock2.updateDelay || options.update
1596
+ lock2.updateTimeout = setTimeout(() => {
1597
+ lock2.updateTimeout = null
1598
+ options.fs.stat(lock2.lockfilePath, (err, stat) => {
1599
+ const isOverThreshold = lock2.lastUpdate + options.stale < Date.now()
1600
+ if (err) {
1601
+ if (err.code === 'ENOENT' || isOverThreshold) {
1602
+ return setLockAsCompromised(file, lock2, Object.assign(err, { code: 'ECOMPROMISED' }))
1603
+ }
1604
+ lock2.updateDelay = 1e3
1605
+ return updateLock(file, options)
1606
+ }
1607
+ const isMtimeOurs = lock2.mtime.getTime() === stat.mtime.getTime()
1608
+ if (!isMtimeOurs) {
1609
+ return setLockAsCompromised(
1610
+ file,
1611
+ lock2,
1612
+ Object.assign(new Error('Unable to update lock within the stale threshold'), {
1613
+ code: 'ECOMPROMISED',
1614
+ }),
1615
+ )
1616
+ }
1617
+ const mtime = mtimePrecision.getMtime(lock2.mtimePrecision)
1618
+ options.fs.utimes(lock2.lockfilePath, mtime, mtime, (err2) => {
1619
+ const isOverThreshold2 = lock2.lastUpdate + options.stale < Date.now()
1620
+ if (lock2.released) {
1621
+ return
1622
+ }
1623
+ if (err2) {
1624
+ if (err2.code === 'ENOENT' || isOverThreshold2) {
1625
+ return setLockAsCompromised(
1626
+ file,
1627
+ lock2,
1628
+ Object.assign(err2, { code: 'ECOMPROMISED' }),
1629
+ )
1630
+ }
1631
+ lock2.updateDelay = 1e3
1632
+ return updateLock(file, options)
1633
+ }
1634
+ lock2.mtime = mtime
1635
+ lock2.lastUpdate = Date.now()
1636
+ lock2.updateDelay = null
1637
+ updateLock(file, options)
1638
+ })
1639
+ })
1640
+ }, lock2.updateDelay)
1641
+ if (lock2.updateTimeout.unref) {
1642
+ lock2.updateTimeout.unref()
1643
+ }
1644
+ }
1645
+ function setLockAsCompromised(file, lock2, err) {
1646
+ lock2.released = true
1647
+ if (lock2.updateTimeout) {
1648
+ clearTimeout(lock2.updateTimeout)
1649
+ }
1650
+ if (locks[file] === lock2) {
1651
+ delete locks[file]
1652
+ }
1653
+ lock2.options.onCompromised(err)
1654
+ }
1655
+ function lock(file, options, callback) {
1656
+ options = {
1657
+ stale: 1e4,
1658
+ update: null,
1659
+ realpath: true,
1660
+ retries: 0,
1661
+ fs: fs2,
1662
+ onCompromised: (err) => {
1663
+ throw err
1664
+ },
1665
+ ...options,
1666
+ }
1667
+ options.retries = options.retries || 0
1668
+ options.retries =
1669
+ typeof options.retries === 'number' ? { retries: options.retries } : options.retries
1670
+ options.stale = Math.max(options.stale || 0, 2e3)
1671
+ options.update = options.update == null ? options.stale / 2 : options.update || 0
1672
+ options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3)
1673
+ resolveCanonicalPath(file, options, (err, file2) => {
1674
+ if (err) {
1675
+ return callback(err)
1676
+ }
1677
+ const operation = retry.operation(options.retries)
1678
+ operation.attempt(() => {
1679
+ acquireLock(file2, options, (err2, mtime, mtimePrecision2) => {
1680
+ if (operation.retry(err2)) {
1681
+ return
1682
+ }
1683
+ if (err2) {
1684
+ return callback(operation.mainError())
1685
+ }
1686
+ const lock2 = (locks[file2] = {
1687
+ lockfilePath: getLockFile(file2, options),
1688
+ mtime,
1689
+ mtimePrecision: mtimePrecision2,
1690
+ options,
1691
+ lastUpdate: Date.now(),
1692
+ })
1693
+ updateLock(file2, options)
1694
+ callback(null, (releasedCallback) => {
1695
+ if (lock2.released) {
1696
+ return (
1697
+ releasedCallback &&
1698
+ releasedCallback(
1699
+ Object.assign(new Error('Lock is already released'), { code: 'ERELEASED' }),
1700
+ )
1701
+ )
1702
+ }
1703
+ unlock(file2, { ...options, realpath: false }, releasedCallback)
1704
+ })
1705
+ })
1706
+ })
1707
+ })
1708
+ }
1709
+ function unlock(file, options, callback) {
1710
+ options = {
1711
+ fs: fs2,
1712
+ realpath: true,
1713
+ ...options,
1714
+ }
1715
+ resolveCanonicalPath(file, options, (err, file2) => {
1716
+ if (err) {
1717
+ return callback(err)
1718
+ }
1719
+ const lock2 = locks[file2]
1720
+ if (!lock2) {
1721
+ return callback(
1722
+ Object.assign(new Error('Lock is not acquired/owned by you'), { code: 'ENOTACQUIRED' }),
1723
+ )
1724
+ }
1725
+ lock2.updateTimeout && clearTimeout(lock2.updateTimeout)
1726
+ lock2.released = true
1727
+ delete locks[file2]
1728
+ removeLock(file2, options, callback)
1729
+ })
1730
+ }
1731
+ function check(file, options, callback) {
1732
+ options = {
1733
+ stale: 1e4,
1734
+ realpath: true,
1735
+ fs: fs2,
1736
+ ...options,
1737
+ }
1738
+ options.stale = Math.max(options.stale || 0, 2e3)
1739
+ resolveCanonicalPath(file, options, (err, file2) => {
1740
+ if (err) {
1741
+ return callback(err)
1742
+ }
1743
+ options.fs.stat(getLockFile(file2, options), (err2, stat) => {
1744
+ if (err2) {
1745
+ return err2.code === 'ENOENT' ? callback(null, false) : callback(err2)
1746
+ }
1747
+ return callback(null, !isLockStale(stat, options))
1748
+ })
1749
+ })
1750
+ }
1751
+ function getLocks() {
1752
+ return locks
1753
+ }
1754
+ onExit(() => {
1755
+ for (const file in locks) {
1756
+ const options = locks[file].options
1757
+ try {
1758
+ options.fs.rmdirSync(getLockFile(file, options))
1759
+ } catch (e) {}
1760
+ }
1761
+ })
1762
+ module.exports.lock = lock
1763
+ module.exports.unlock = unlock
1764
+ module.exports.check = check
1765
+ module.exports.getLocks = getLocks
1766
+ },
1767
+ })
1768
+
1769
+ // node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/adapter.js
1770
+ var require_adapter = __commonJS({
1771
+ 'node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/adapter.js'(
1772
+ exports,
1773
+ module,
1774
+ ) {
1775
+ 'use strict'
1776
+ var fs2 = require_graceful_fs()
1777
+ function createSyncFs(fs3) {
1778
+ const methods = ['mkdir', 'realpath', 'stat', 'rmdir', 'utimes']
1779
+ const newFs = { ...fs3 }
1780
+ methods.forEach((method) => {
1781
+ newFs[method] = (...args) => {
1782
+ const callback = args.pop()
1783
+ let ret
1784
+ try {
1785
+ ret = fs3[`${method}Sync`](...args)
1786
+ } catch (err) {
1787
+ return callback(err)
1788
+ }
1789
+ callback(null, ret)
1790
+ }
1791
+ })
1792
+ return newFs
1793
+ }
1794
+ function toPromise(method) {
1795
+ return (...args) =>
1796
+ new Promise((resolve2, reject) => {
1797
+ args.push((err, result) => {
1798
+ if (err) {
1799
+ reject(err)
1800
+ } else {
1801
+ resolve2(result)
1802
+ }
1803
+ })
1804
+ method(...args)
1805
+ })
1806
+ }
1807
+ function toSync(method) {
1808
+ return (...args) => {
1809
+ let err
1810
+ let result
1811
+ args.push((_err, _result) => {
1812
+ err = _err
1813
+ result = _result
1814
+ })
1815
+ method(...args)
1816
+ if (err) {
1817
+ throw err
1818
+ }
1819
+ return result
1820
+ }
1821
+ }
1822
+ function toSyncOptions(options) {
1823
+ options = { ...options }
1824
+ options.fs = createSyncFs(options.fs || fs2)
1825
+ if (
1826
+ (typeof options.retries === 'number' && options.retries > 0) ||
1827
+ (options.retries &&
1828
+ typeof options.retries.retries === 'number' &&
1829
+ options.retries.retries > 0)
1830
+ ) {
1831
+ throw Object.assign(new Error('Cannot use retries with the sync api'), { code: 'ESYNC' })
1832
+ }
1833
+ return options
1834
+ }
1835
+ module.exports = {
1836
+ toPromise,
1837
+ toSync,
1838
+ toSyncOptions,
1839
+ }
1840
+ },
1841
+ })
1842
+
1843
+ // node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/index.js
1844
+ var require_proper_lockfile = __commonJS({
1845
+ 'node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/index.js'(
1846
+ exports,
1847
+ module,
1848
+ ) {
1849
+ 'use strict'
1850
+ var lockfile2 = require_lockfile()
1851
+ var { toPromise, toSync, toSyncOptions } = require_adapter()
1852
+ async function lock(file, options) {
1853
+ const release = await toPromise(lockfile2.lock)(file, options)
1854
+ return toPromise(release)
1855
+ }
1856
+ function lockSync(file, options) {
1857
+ const release = toSync(lockfile2.lock)(file, toSyncOptions(options))
1858
+ return toSync(release)
1859
+ }
1860
+ function unlock(file, options) {
1861
+ return toPromise(lockfile2.unlock)(file, options)
1862
+ }
1863
+ function unlockSync(file, options) {
1864
+ return toSync(lockfile2.unlock)(file, toSyncOptions(options))
1865
+ }
1866
+ function check(file, options) {
1867
+ return toPromise(lockfile2.check)(file, options)
1868
+ }
1869
+ function checkSync(file, options) {
1870
+ return toSync(lockfile2.check)(file, toSyncOptions(options))
1871
+ }
1872
+ module.exports = lock
1873
+ module.exports.lock = lock
1874
+ module.exports.unlock = unlock
1875
+ module.exports.lockSync = lockSync
1876
+ module.exports.unlockSync = unlockSync
1877
+ module.exports.check = check
1878
+ module.exports.checkSync = checkSync
1879
+ },
1880
+ })
1881
+
1882
+ // src/platform/packagePath.ts
1883
+ var init_packagePath = __esm({
1884
+ 'src/platform/packagePath.ts'() {
1885
+ 'use strict'
1886
+ },
1887
+ })
1888
+
1889
+ // src/platform/platform.ts
1890
+ var init_platform = __esm({
1891
+ 'src/platform/platform.ts'() {
1892
+ 'use strict'
1893
+ },
1894
+ })
1895
+
1896
+ // src/platform/assetsRoot.ts
1897
+ function isCompiledRuntime(url = import.meta.url) {
1898
+ return isCompiledModuleUrl(url)
1899
+ }
1900
+ function isCompiledModuleUrl(url) {
1901
+ let s = url
1902
+ try {
1903
+ s = decodeURIComponent(url)
1904
+ } catch {}
1905
+ const normalized = s.replace(/\\/g, '/').toLowerCase()
1906
+ return BUNFS_MARKERS.some((m) => normalized.includes(m))
1907
+ }
1908
+ var BUNFS_MARKERS
1909
+ var init_assetsRoot = __esm({
1910
+ 'src/platform/assetsRoot.ts'() {
1911
+ 'use strict'
1912
+ init_packagePath()
1913
+ init_platform()
1914
+ BUNFS_MARKERS = ['/$bunfs/', '/~bun/']
1915
+ },
1916
+ })
1917
+
1918
+ // src/platform/runtime.ts
1919
+ function isBunRuntime(versions = process.versions, compiled) {
1920
+ return (
1921
+ typeof versions.bun === 'string' &&
1922
+ versions.bun.trim().length > 0 &&
1923
+ !(compiled ?? isCompiledRuntime())
1924
+ )
1925
+ }
1926
+ function bunExecutable() {
1927
+ return isBunRuntime() ? process.execPath : process.platform === 'win32' ? 'bun.exe' : 'bun'
1928
+ }
1929
+ var init_runtime = __esm({
1930
+ 'src/platform/runtime.ts'() {
1931
+ 'use strict'
1932
+ init_assetsRoot()
1933
+ },
1934
+ })
1935
+
1936
+ // src/cli/lib/version-check.ts
1937
+ var version_check_exports = {}
1938
+ __export(version_check_exports, {
1939
+ compareVersions: () => compareVersions,
1940
+ fetchLatestBunVersion: () => fetchLatestBunVersion,
1941
+ fetchLatestNpmVersion: () => fetchLatestNpmVersion,
1942
+ fetchLatestVersion: () => fetchLatestVersion,
1943
+ })
1944
+ import { exec, execFile } from 'node:child_process'
1945
+ import { promisify } from 'node:util'
1946
+ function parse(v) {
1947
+ const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v.trim())
1948
+ if (!m) return null
1949
+ return { nums: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ?? null }
1950
+ }
1951
+ function compareVersions(installed, latest) {
1952
+ const a = parse(installed)
1953
+ const b = parse(latest)
1954
+ if (!a || !b) return 'unknown'
1955
+ for (let i = 0; i < 3; i++) {
1956
+ const ai = a.nums[i] ?? 0
1957
+ const bi = b.nums[i] ?? 0
1958
+ if (ai < bi) return 'behind'
1959
+ if (ai > bi) return 'ahead'
1960
+ }
1961
+ if (a.pre && !b.pre) return 'behind'
1962
+ if (!a.pre && b.pre) return 'ahead'
1963
+ if (a.pre && b.pre && a.pre !== b.pre) return a.pre < b.pre ? 'behind' : 'ahead'
1964
+ return 'current'
1965
+ }
1966
+ function npmExecutable() {
1967
+ return process.platform === 'win32' ? 'npm.cmd' : 'npm'
1968
+ }
1969
+ async function defaultRunner() {
1970
+ if (process.platform === 'win32') {
1971
+ const { stdout: stdout2 } = await execAsync('npm view harnessed version', {
1972
+ timeout: 8e3,
1973
+ windowsHide: true,
1974
+ })
1975
+ return stdout2
1976
+ }
1977
+ const { stdout } = await execFileAsync(npmExecutable(), ['view', 'harnessed', 'version'], {
1978
+ timeout: 8e3,
1979
+ windowsHide: true,
1980
+ })
1981
+ return stdout
1982
+ }
1983
+ async function fetchLatestVersion(runner) {
1984
+ try {
1985
+ if (runner !== void 0) return await fetchLatestNpmVersion(runner)
1986
+ return isBunRuntime() ? await fetchLatestBunVersion() : await fetchLatestNpmVersion()
1987
+ } catch {
1988
+ return null
1989
+ }
1990
+ }
1991
+ async function fetchLatestNpmVersion(runner = defaultRunner) {
1992
+ try {
1993
+ const out = (await runner()).trim()
1994
+ return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(out) ? out : null
1995
+ } catch {
1996
+ return null
1997
+ }
1998
+ }
1999
+ async function defaultBunRunner() {
2000
+ const { stdout } = await execFileAsync(
2001
+ bunExecutable(),
2002
+ ['info', 'harnessed@latest', 'version', '--json'],
2003
+ { timeout: 8e3, windowsHide: true, shell: false },
2004
+ )
2005
+ return stdout
2006
+ }
2007
+ async function fetchLatestBunVersion(runner = defaultBunRunner) {
2008
+ try {
2009
+ const version = JSON.parse(await runner())
2010
+ return typeof version === 'string' && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)
2011
+ ? version
2012
+ : null
2013
+ } catch {
2014
+ return null
2015
+ }
2016
+ }
2017
+ var execFileAsync, execAsync
2018
+ var init_version_check = __esm({
2019
+ 'src/cli/lib/version-check.ts'() {
2020
+ 'use strict'
2021
+ init_runtime()
2022
+ execFileAsync = promisify(execFile)
2023
+ execAsync = promisify(exec)
2024
+ },
2025
+ })
2026
+
2027
+ // src/cli/updateReminderWorkerMain.ts
2028
+ var updateReminderWorkerMain_exports = {}
2029
+ __export(updateReminderWorkerMain_exports, {
2030
+ runUpdateReminderWorker: () => runUpdateReminderWorker,
2031
+ })
2032
+ import { randomUUID } from 'node:crypto'
2033
+ import asyncFs from 'node:fs/promises'
2034
+ import { dirname } from 'node:path'
2035
+ async function runUpdateReminderWorker(options) {
2036
+ let release
2037
+ let temporary
2038
+ let timer
2039
+ const controller = new AbortController()
2040
+ let owned = false
2041
+ try {
2042
+ const now = options.now ?? Date.now
2043
+ if (!isReminderVersion(options.installed)) return 0
2044
+ await asyncFs.mkdir(dirname(options.cachePath), { recursive: true })
2045
+ release = await import_proper_lockfile.default.lock(options.cachePath, {
2046
+ realpath: false,
2047
+ retries: 0,
2048
+ stale: REMINDER_LOCK_STALE_MS,
2049
+ update: 1e4,
2050
+ onCompromised: () => {
2051
+ owned = false
2052
+ controller.abort()
2053
+ },
2054
+ })
2055
+ owned = true
2056
+ const cache = readReminderCache(options.cachePath, options.identity, now())
2057
+ if (!shouldRefreshReminder(cache, now())) return 0
2058
+ let latest = null
2059
+ try {
2060
+ const observation = await Promise.race([
2061
+ options.observe(controller.signal),
2062
+ new Promise((_, reject) => {
2063
+ timer = setTimeout(() => {
2064
+ controller.abort()
2065
+ reject(new Error('timeout'))
2066
+ }, 8e3)
2067
+ }),
2068
+ ])
2069
+ if (isReminderVersion(observation.latest)) latest = observation.latest
2070
+ } catch {}
2071
+ const checkedAt = now()
2072
+ const state = latest === null ? 'unknown' : compareVersions(options.installed, latest)
2073
+ const result = {
2074
+ schemaVersion: 1,
2075
+ identity: { ...options.identity },
2076
+ installed: options.installed,
2077
+ latest,
2078
+ state,
2079
+ checkedAt,
2080
+ retryAfter: state === 'unknown' ? checkedAt + REMINDER_RETRY_MS : 0,
2081
+ }
2082
+ const text = `${JSON.stringify(result)}
2083
+ `
2084
+ if (!owned || Buffer.byteLength(text) > REMINDER_MAX_BYTES) return 0
2085
+ temporary = `${options.cachePath}.${randomUUID()}.tmp`
2086
+ await asyncFs.writeFile(temporary, text, { encoding: 'utf8', flag: 'wx', mode: 384 })
2087
+ if (owned) await asyncFs.rename(temporary, options.cachePath)
2088
+ } catch {
2089
+ } finally {
2090
+ if (timer) clearTimeout(timer)
2091
+ controller.abort()
2092
+ if (temporary) await asyncFs.unlink(temporary).catch(() => {})
2093
+ if (release) await release().catch(() => {})
2094
+ }
2095
+ return 0
2096
+ }
2097
+ var import_proper_lockfile
2098
+ var init_updateReminderWorkerMain = __esm({
2099
+ 'src/cli/updateReminderWorkerMain.ts'() {
2100
+ 'use strict'
2101
+ import_proper_lockfile = __toESM(require_proper_lockfile(), 1)
2102
+ init_updateReminderCache()
2103
+ init_version_check()
2104
+ },
2105
+ })
2106
+
2107
+ // src/compile/updateReminderEntrypoint.ts
2108
+ init_package()
2109
+ import { createHash } from 'node:crypto'
2110
+ import { closeSync, constants, fstatSync, openSync, readSync, statSync } from 'node:fs'
2111
+ import { homedir } from 'node:os'
2112
+ import { dirname as dirname2, isAbsolute, join, resolve } from 'node:path'
2113
+ import { fileURLToPath } from 'node:url'
2114
+
2115
+ // src/cli/updateReminderHookMain.ts
2116
+ init_updateReminderCache()
2117
+
2118
+ // src/compile/updateReminderEntrypoint.ts
2119
+ var UPDATE_REMINDER_OPERATION = 'update-reminder'
2120
+ var UPDATE_REMINDER_WORKER_OPERATION = 'update-reminder-worker'
2121
+ var UPDATE_REMINDER_PREFERENCES_FILE = 'update-reminder-preferences.json'
2122
+ var BINARY_SOURCE = 'https://api.github.com/repos/easyinplay/harnessed/releases/latest'
2123
+ function resolveUpdateReminderRuntime(options = {}) {
2124
+ const args = [...(options.args ?? process.argv.slice(2))]
2125
+ if (args[0] === UPDATE_REMINDER_OPERATION || args[0] === UPDATE_REMINDER_WORKER_OPERATION)
2126
+ args.shift()
2127
+ let host = 'claude'
2128
+ let explicitStateRoot
2129
+ let platformSpecified = false
2130
+ for (let index = 0; index < args.length; index += 2) {
2131
+ const flag = args[index]
2132
+ const value = args[index + 1]
2133
+ if (
2134
+ !flag ||
2135
+ value === void 0 ||
2136
+ [flag, value].some((argument) =>
2137
+ Array.from(argument).some((character) => character < ' ' || character === '\x7F'),
2138
+ )
2139
+ )
2140
+ return null
2141
+ if (flag === '--platform') {
2142
+ if (platformSpecified || (value !== 'claude' && value !== 'codex')) return null
2143
+ platformSpecified = true
2144
+ host = value
2145
+ } else if (flag === '--state-root') {
2146
+ if (explicitStateRoot !== void 0 || !isAbsolute(value)) return null
2147
+ explicitStateRoot = resolve(value)
2148
+ } else return null
2149
+ }
2150
+ const nativeHome = resolve(
2151
+ (host === 'codex' ? process.env.CODEX_HOME?.trim() : process.env.CLAUDE_CONFIG_DIR) ||
2152
+ join(homedir(), host === 'codex' ? '.codex' : '.claude'),
2153
+ )
2154
+ const stateRoot =
2155
+ explicitStateRoot ??
2156
+ resolve(process.env.HARNESSED_ROOT_OVERRIDE || join(nativeHome, 'harnessed'))
2157
+ const channel = options.compiled ? 'binary' : process.versions.bun ? 'bun' : 'npm'
2158
+ const source = channel === 'binary' ? BINARY_SOURCE : `${channel}:harnessed`
2159
+ const fingerprint = createHash('sha256')
2160
+ .update(
2161
+ JSON.stringify([
2162
+ host === 'codex' ? stateRoot : nativeHome,
2163
+ process.execPath,
2164
+ package_default.version,
2165
+ source,
2166
+ ]),
2167
+ )
2168
+ .digest('hex')
2169
+ return {
2170
+ stateRoot,
2171
+ nativeHome,
2172
+ cachePath: join(stateRoot, `update-reminder-${host}.json`),
2173
+ preferencesPath: join(stateRoot, UPDATE_REMINDER_PREFERENCES_FILE),
2174
+ installed: package_default.version,
2175
+ identity: {
2176
+ host,
2177
+ runtime: options.compiled ? 'binary' : process.versions.bun ? 'bun' : 'node',
2178
+ channel,
2179
+ source,
2180
+ fingerprint,
2181
+ },
2182
+ worker: {
2183
+ executable: process.execPath,
2184
+ args: [
2185
+ options.compiled
2186
+ ? UPDATE_REMINDER_WORKER_OPERATION
2187
+ : join(dirname2(fileURLToPath(import.meta.url)), 'harnessed-update-reminder-worker.mjs'),
2188
+ '--platform',
2189
+ host,
2190
+ ...(explicitStateRoot ? ['--state-root', explicitStateRoot] : []),
2191
+ ],
2192
+ },
2193
+ }
2194
+ }
2195
+ function reminderEnabled(path) {
2196
+ let descriptor
2197
+ try {
2198
+ descriptor = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK)
2199
+ const info = fstatSync(descriptor)
2200
+ if (!info.isFile() || info.size > 1024) return false
2201
+ const buffer = Buffer.alloc(1025)
2202
+ const bytes = readSync(descriptor, buffer, 0, buffer.length, 0)
2203
+ if (bytes > 1024 || bytes < info.size) return false
2204
+ const value = JSON.parse(buffer.toString('utf8', 0, bytes))
2205
+ return (
2206
+ typeof value === 'object' &&
2207
+ value !== null &&
2208
+ 'schemaVersion' in value &&
2209
+ value.schemaVersion === 1 &&
2210
+ 'enabled' in value &&
2211
+ value.enabled === true
2212
+ )
2213
+ } catch (error) {
2214
+ return error.code === 'ENOENT'
2215
+ } finally {
2216
+ if (descriptor !== void 0) {
2217
+ try {
2218
+ closeSync(descriptor)
2219
+ } catch {}
2220
+ }
2221
+ }
2222
+ }
2223
+ async function runUpdateReminderWorkerEntrypoint(options = {}) {
2224
+ try {
2225
+ const runtime = resolveUpdateReminderRuntime(options)
2226
+ if (!runtime || !reminderEnabled(runtime.preferencesPath)) return 0
2227
+ const { runUpdateReminderWorker: runUpdateReminderWorker2 } = await Promise.resolve().then(
2228
+ () => (init_updateReminderWorkerMain(), updateReminderWorkerMain_exports),
2229
+ )
2230
+ return await runUpdateReminderWorker2({
2231
+ ...runtime,
2232
+ observe: async (signal) => {
2233
+ if (runtime.identity.channel === 'binary') {
2234
+ const response = await fetch(BINARY_SOURCE, {
2235
+ signal,
2236
+ headers: { 'user-agent': `harnessed/${package_default.version}` },
2237
+ })
2238
+ if (!response.ok) return { latest: null }
2239
+ const value = await response.json()
2240
+ return {
2241
+ latest: typeof value.tag_name === 'string' ? value.tag_name.replace(/^v/, '') : null,
2242
+ }
2243
+ }
2244
+ const {
2245
+ fetchLatestBunVersion: fetchLatestBunVersion2,
2246
+ fetchLatestNpmVersion: fetchLatestNpmVersion2,
2247
+ } = await Promise.resolve().then(() => (init_version_check(), version_check_exports))
2248
+ return {
2249
+ latest: await (runtime.identity.channel === 'bun'
2250
+ ? fetchLatestBunVersion2()
2251
+ : fetchLatestNpmVersion2()),
2252
+ }
2253
+ },
2254
+ })
2255
+ } catch {}
2256
+ return 0
2257
+ }
2258
+
2259
+ // bin/harnessed-update-reminder-worker.mjs.entry.ts
2260
+ await runUpdateReminderWorkerEntrypoint()