harnessed 5.0.4 → 5.0.6

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