pi-adaptive-thinking 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/config-loader.d.ts +2 -2
- package/dist/index.js +1470 -20
- package/package.json +22 -17
package/dist/index.js
CHANGED
|
@@ -1,8 +1,1383 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
1
5
|
import { Type } from "typebox";
|
|
2
6
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
7
|
+
import { homedir as homedir$1 } from "node:os";
|
|
8
|
+
import { join as join$1 } from "node:path";
|
|
5
9
|
import { getSupportedThinkingLevels } from "@earendil-works/pi-ai";
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
var __create = Object.create;
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js
|
|
35
|
+
var require_polyfills = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
36
|
+
var constants = __require("constants");
|
|
37
|
+
var origCwd = process.cwd;
|
|
38
|
+
var cwd = null;
|
|
39
|
+
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
|
|
40
|
+
process.cwd = function() {
|
|
41
|
+
if (!cwd) cwd = origCwd.call(process);
|
|
42
|
+
return cwd;
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
process.cwd();
|
|
46
|
+
} catch (er) {}
|
|
47
|
+
if (typeof process.chdir === "function") {
|
|
48
|
+
var chdir = process.chdir;
|
|
49
|
+
process.chdir = function(d) {
|
|
50
|
+
cwd = null;
|
|
51
|
+
chdir.call(process, d);
|
|
52
|
+
};
|
|
53
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
|
|
54
|
+
}
|
|
55
|
+
module.exports = patch;
|
|
56
|
+
function patch(fs) {
|
|
57
|
+
if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) patchLchmod(fs);
|
|
58
|
+
if (!fs.lutimes) patchLutimes(fs);
|
|
59
|
+
fs.chown = chownFix(fs.chown);
|
|
60
|
+
fs.fchown = chownFix(fs.fchown);
|
|
61
|
+
fs.lchown = chownFix(fs.lchown);
|
|
62
|
+
fs.chmod = chmodFix(fs.chmod);
|
|
63
|
+
fs.fchmod = chmodFix(fs.fchmod);
|
|
64
|
+
fs.lchmod = chmodFix(fs.lchmod);
|
|
65
|
+
fs.chownSync = chownFixSync(fs.chownSync);
|
|
66
|
+
fs.fchownSync = chownFixSync(fs.fchownSync);
|
|
67
|
+
fs.lchownSync = chownFixSync(fs.lchownSync);
|
|
68
|
+
fs.chmodSync = chmodFixSync(fs.chmodSync);
|
|
69
|
+
fs.fchmodSync = chmodFixSync(fs.fchmodSync);
|
|
70
|
+
fs.lchmodSync = chmodFixSync(fs.lchmodSync);
|
|
71
|
+
fs.stat = statFix(fs.stat);
|
|
72
|
+
fs.fstat = statFix(fs.fstat);
|
|
73
|
+
fs.lstat = statFix(fs.lstat);
|
|
74
|
+
fs.statSync = statFixSync(fs.statSync);
|
|
75
|
+
fs.fstatSync = statFixSync(fs.fstatSync);
|
|
76
|
+
fs.lstatSync = statFixSync(fs.lstatSync);
|
|
77
|
+
if (fs.chmod && !fs.lchmod) {
|
|
78
|
+
fs.lchmod = function(path, mode, cb) {
|
|
79
|
+
if (cb) process.nextTick(cb);
|
|
80
|
+
};
|
|
81
|
+
fs.lchmodSync = function() {};
|
|
82
|
+
}
|
|
83
|
+
if (fs.chown && !fs.lchown) {
|
|
84
|
+
fs.lchown = function(path, uid, gid, cb) {
|
|
85
|
+
if (cb) process.nextTick(cb);
|
|
86
|
+
};
|
|
87
|
+
fs.lchownSync = function() {};
|
|
88
|
+
}
|
|
89
|
+
if (platform === "win32") fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
|
|
90
|
+
function rename(from, to, cb) {
|
|
91
|
+
var start = Date.now();
|
|
92
|
+
var backoff = 0;
|
|
93
|
+
fs$rename(from, to, function CB(er) {
|
|
94
|
+
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
|
|
95
|
+
setTimeout(function() {
|
|
96
|
+
fs.stat(to, function(stater, st) {
|
|
97
|
+
if (stater && stater.code === "ENOENT") fs$rename(from, to, CB);
|
|
98
|
+
else cb(er);
|
|
99
|
+
});
|
|
100
|
+
}, backoff);
|
|
101
|
+
if (backoff < 100) backoff += 10;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (cb) cb(er);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
|
|
108
|
+
return rename;
|
|
109
|
+
})(fs.rename);
|
|
110
|
+
fs.read = typeof fs.read !== "function" ? fs.read : (function(fs$read) {
|
|
111
|
+
function read(fd, buffer, offset, length, position, callback_) {
|
|
112
|
+
var callback;
|
|
113
|
+
if (callback_ && typeof callback_ === "function") {
|
|
114
|
+
var eagCounter = 0;
|
|
115
|
+
callback = function(er, _, __) {
|
|
116
|
+
if (er && er.code === "EAGAIN" && eagCounter < 10) {
|
|
117
|
+
eagCounter++;
|
|
118
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
|
|
119
|
+
}
|
|
120
|
+
callback_.apply(this, arguments);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
|
|
124
|
+
}
|
|
125
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
|
|
126
|
+
return read;
|
|
127
|
+
})(fs.read);
|
|
128
|
+
fs.readSync = typeof fs.readSync !== "function" ? fs.readSync : (function(fs$readSync) {
|
|
129
|
+
return function(fd, buffer, offset, length, position) {
|
|
130
|
+
var eagCounter = 0;
|
|
131
|
+
while (true) try {
|
|
132
|
+
return fs$readSync.call(fs, fd, buffer, offset, length, position);
|
|
133
|
+
} catch (er) {
|
|
134
|
+
if (er.code === "EAGAIN" && eagCounter < 10) {
|
|
135
|
+
eagCounter++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
throw er;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
})(fs.readSync);
|
|
142
|
+
function patchLchmod(fs) {
|
|
143
|
+
fs.lchmod = function(path, mode, callback) {
|
|
144
|
+
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, mode, function(err, fd) {
|
|
145
|
+
if (err) {
|
|
146
|
+
if (callback) callback(err);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
fs.fchmod(fd, mode, function(err) {
|
|
150
|
+
fs.close(fd, function(err2) {
|
|
151
|
+
if (callback) callback(err || err2);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
fs.lchmodSync = function(path, mode) {
|
|
157
|
+
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
|
|
158
|
+
var threw = true;
|
|
159
|
+
var ret;
|
|
160
|
+
try {
|
|
161
|
+
ret = fs.fchmodSync(fd, mode);
|
|
162
|
+
threw = false;
|
|
163
|
+
} finally {
|
|
164
|
+
if (threw) try {
|
|
165
|
+
fs.closeSync(fd);
|
|
166
|
+
} catch (er) {}
|
|
167
|
+
else fs.closeSync(fd);
|
|
168
|
+
}
|
|
169
|
+
return ret;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function patchLutimes(fs) {
|
|
173
|
+
if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
|
|
174
|
+
fs.lutimes = function(path, at, mt, cb) {
|
|
175
|
+
fs.open(path, constants.O_SYMLINK, function(er, fd) {
|
|
176
|
+
if (er) {
|
|
177
|
+
if (cb) cb(er);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
fs.futimes(fd, at, mt, function(er) {
|
|
181
|
+
fs.close(fd, function(er2) {
|
|
182
|
+
if (cb) cb(er || er2);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
fs.lutimesSync = function(path, at, mt) {
|
|
188
|
+
var fd = fs.openSync(path, constants.O_SYMLINK);
|
|
189
|
+
var ret;
|
|
190
|
+
var threw = true;
|
|
191
|
+
try {
|
|
192
|
+
ret = fs.futimesSync(fd, at, mt);
|
|
193
|
+
threw = false;
|
|
194
|
+
} finally {
|
|
195
|
+
if (threw) try {
|
|
196
|
+
fs.closeSync(fd);
|
|
197
|
+
} catch (er) {}
|
|
198
|
+
else fs.closeSync(fd);
|
|
199
|
+
}
|
|
200
|
+
return ret;
|
|
201
|
+
};
|
|
202
|
+
} else if (fs.futimes) {
|
|
203
|
+
fs.lutimes = function(_a, _b, _c, cb) {
|
|
204
|
+
if (cb) process.nextTick(cb);
|
|
205
|
+
};
|
|
206
|
+
fs.lutimesSync = function() {};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function chmodFix(orig) {
|
|
210
|
+
if (!orig) return orig;
|
|
211
|
+
return function(target, mode, cb) {
|
|
212
|
+
return orig.call(fs, target, mode, function(er) {
|
|
213
|
+
if (chownErOk(er)) er = null;
|
|
214
|
+
if (cb) cb.apply(this, arguments);
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function chmodFixSync(orig) {
|
|
219
|
+
if (!orig) return orig;
|
|
220
|
+
return function(target, mode) {
|
|
221
|
+
try {
|
|
222
|
+
return orig.call(fs, target, mode);
|
|
223
|
+
} catch (er) {
|
|
224
|
+
if (!chownErOk(er)) throw er;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function chownFix(orig) {
|
|
229
|
+
if (!orig) return orig;
|
|
230
|
+
return function(target, uid, gid, cb) {
|
|
231
|
+
return orig.call(fs, target, uid, gid, function(er) {
|
|
232
|
+
if (chownErOk(er)) er = null;
|
|
233
|
+
if (cb) cb.apply(this, arguments);
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function chownFixSync(orig) {
|
|
238
|
+
if (!orig) return orig;
|
|
239
|
+
return function(target, uid, gid) {
|
|
240
|
+
try {
|
|
241
|
+
return orig.call(fs, target, uid, gid);
|
|
242
|
+
} catch (er) {
|
|
243
|
+
if (!chownErOk(er)) throw er;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function statFix(orig) {
|
|
248
|
+
if (!orig) return orig;
|
|
249
|
+
return function(target, options, cb) {
|
|
250
|
+
if (typeof options === "function") {
|
|
251
|
+
cb = options;
|
|
252
|
+
options = null;
|
|
253
|
+
}
|
|
254
|
+
function callback(er, stats) {
|
|
255
|
+
if (stats) {
|
|
256
|
+
if (stats.uid < 0) stats.uid += 4294967296;
|
|
257
|
+
if (stats.gid < 0) stats.gid += 4294967296;
|
|
258
|
+
}
|
|
259
|
+
if (cb) cb.apply(this, arguments);
|
|
260
|
+
}
|
|
261
|
+
return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function statFixSync(orig) {
|
|
265
|
+
if (!orig) return orig;
|
|
266
|
+
return function(target, options) {
|
|
267
|
+
var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
|
|
268
|
+
if (stats) {
|
|
269
|
+
if (stats.uid < 0) stats.uid += 4294967296;
|
|
270
|
+
if (stats.gid < 0) stats.gid += 4294967296;
|
|
271
|
+
}
|
|
272
|
+
return stats;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function chownErOk(er) {
|
|
276
|
+
if (!er) return true;
|
|
277
|
+
if (er.code === "ENOSYS") return true;
|
|
278
|
+
if (!process.getuid || process.getuid() !== 0) {
|
|
279
|
+
if (er.code === "EINVAL" || er.code === "EPERM") return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}));
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/legacy-streams.js
|
|
287
|
+
var require_legacy_streams = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
288
|
+
var Stream = __require("stream").Stream;
|
|
289
|
+
module.exports = legacy;
|
|
290
|
+
function legacy(fs) {
|
|
291
|
+
return {
|
|
292
|
+
ReadStream,
|
|
293
|
+
WriteStream
|
|
294
|
+
};
|
|
295
|
+
function ReadStream(path, options) {
|
|
296
|
+
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
|
|
297
|
+
Stream.call(this);
|
|
298
|
+
var self = this;
|
|
299
|
+
this.path = path;
|
|
300
|
+
this.fd = null;
|
|
301
|
+
this.readable = true;
|
|
302
|
+
this.paused = false;
|
|
303
|
+
this.flags = "r";
|
|
304
|
+
this.mode = 438;
|
|
305
|
+
this.bufferSize = 64 * 1024;
|
|
306
|
+
options = options || {};
|
|
307
|
+
var keys = Object.keys(options);
|
|
308
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
309
|
+
var key = keys[index];
|
|
310
|
+
this[key] = options[key];
|
|
311
|
+
}
|
|
312
|
+
if (this.encoding) this.setEncoding(this.encoding);
|
|
313
|
+
if (this.start !== void 0) {
|
|
314
|
+
if ("number" !== typeof this.start) throw TypeError("start must be a Number");
|
|
315
|
+
if (this.end === void 0) this.end = Infinity;
|
|
316
|
+
else if ("number" !== typeof this.end) throw TypeError("end must be a Number");
|
|
317
|
+
if (this.start > this.end) throw new Error("start must be <= end");
|
|
318
|
+
this.pos = this.start;
|
|
319
|
+
}
|
|
320
|
+
if (this.fd !== null) {
|
|
321
|
+
process.nextTick(function() {
|
|
322
|
+
self._read();
|
|
323
|
+
});
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
fs.open(this.path, this.flags, this.mode, function(err, fd) {
|
|
327
|
+
if (err) {
|
|
328
|
+
self.emit("error", err);
|
|
329
|
+
self.readable = false;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
self.fd = fd;
|
|
333
|
+
self.emit("open", fd);
|
|
334
|
+
self._read();
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function WriteStream(path, options) {
|
|
338
|
+
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
|
|
339
|
+
Stream.call(this);
|
|
340
|
+
this.path = path;
|
|
341
|
+
this.fd = null;
|
|
342
|
+
this.writable = true;
|
|
343
|
+
this.flags = "w";
|
|
344
|
+
this.encoding = "binary";
|
|
345
|
+
this.mode = 438;
|
|
346
|
+
this.bytesWritten = 0;
|
|
347
|
+
options = options || {};
|
|
348
|
+
var keys = Object.keys(options);
|
|
349
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
350
|
+
var key = keys[index];
|
|
351
|
+
this[key] = options[key];
|
|
352
|
+
}
|
|
353
|
+
if (this.start !== void 0) {
|
|
354
|
+
if ("number" !== typeof this.start) throw TypeError("start must be a Number");
|
|
355
|
+
if (this.start < 0) throw new Error("start must be >= zero");
|
|
356
|
+
this.pos = this.start;
|
|
357
|
+
}
|
|
358
|
+
this.busy = false;
|
|
359
|
+
this._queue = [];
|
|
360
|
+
if (this.fd === null) {
|
|
361
|
+
this._open = fs.open;
|
|
362
|
+
this._queue.push([
|
|
363
|
+
this._open,
|
|
364
|
+
this.path,
|
|
365
|
+
this.flags,
|
|
366
|
+
this.mode,
|
|
367
|
+
void 0
|
|
368
|
+
]);
|
|
369
|
+
this.flush();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}));
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/clone.js
|
|
376
|
+
var require_clone = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
377
|
+
module.exports = clone;
|
|
378
|
+
var getPrototypeOf = Object.getPrototypeOf || function(obj) {
|
|
379
|
+
return obj.__proto__;
|
|
380
|
+
};
|
|
381
|
+
function clone(obj) {
|
|
382
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
383
|
+
if (obj instanceof Object) var copy = { __proto__: getPrototypeOf(obj) };
|
|
384
|
+
else var copy = Object.create(null);
|
|
385
|
+
Object.getOwnPropertyNames(obj).forEach(function(key) {
|
|
386
|
+
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
|
|
387
|
+
});
|
|
388
|
+
return copy;
|
|
389
|
+
}
|
|
390
|
+
}));
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js
|
|
393
|
+
var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
394
|
+
var fs = __require("fs");
|
|
395
|
+
var polyfills = require_polyfills();
|
|
396
|
+
var legacy = require_legacy_streams();
|
|
397
|
+
var clone = require_clone();
|
|
398
|
+
var util = __require("util");
|
|
399
|
+
/* istanbul ignore next - node 0.x polyfill */
|
|
400
|
+
var gracefulQueue;
|
|
401
|
+
var previousSymbol;
|
|
402
|
+
/* istanbul ignore else - node 0.x polyfill */
|
|
403
|
+
if (typeof Symbol === "function" && typeof Symbol.for === "function") {
|
|
404
|
+
gracefulQueue = Symbol.for("graceful-fs.queue");
|
|
405
|
+
previousSymbol = Symbol.for("graceful-fs.previous");
|
|
406
|
+
} else {
|
|
407
|
+
gracefulQueue = "___graceful-fs.queue";
|
|
408
|
+
previousSymbol = "___graceful-fs.previous";
|
|
409
|
+
}
|
|
410
|
+
function noop() {}
|
|
411
|
+
function publishQueue(context, queue) {
|
|
412
|
+
Object.defineProperty(context, gracefulQueue, { get: function() {
|
|
413
|
+
return queue;
|
|
414
|
+
} });
|
|
415
|
+
}
|
|
416
|
+
var debug = noop;
|
|
417
|
+
if (util.debuglog) debug = util.debuglog("gfs4");
|
|
418
|
+
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) debug = function() {
|
|
419
|
+
var m = util.format.apply(util, arguments);
|
|
420
|
+
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
|
|
421
|
+
console.error(m);
|
|
422
|
+
};
|
|
423
|
+
if (!fs[gracefulQueue]) {
|
|
424
|
+
publishQueue(fs, global[gracefulQueue] || []);
|
|
425
|
+
fs.close = (function(fs$close) {
|
|
426
|
+
function close(fd, cb) {
|
|
427
|
+
return fs$close.call(fs, fd, function(err) {
|
|
428
|
+
if (!err) resetQueue();
|
|
429
|
+
if (typeof cb === "function") cb.apply(this, arguments);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
Object.defineProperty(close, previousSymbol, { value: fs$close });
|
|
433
|
+
return close;
|
|
434
|
+
})(fs.close);
|
|
435
|
+
fs.closeSync = (function(fs$closeSync) {
|
|
436
|
+
function closeSync(fd) {
|
|
437
|
+
fs$closeSync.apply(fs, arguments);
|
|
438
|
+
resetQueue();
|
|
439
|
+
}
|
|
440
|
+
Object.defineProperty(closeSync, previousSymbol, { value: fs$closeSync });
|
|
441
|
+
return closeSync;
|
|
442
|
+
})(fs.closeSync);
|
|
443
|
+
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) process.on("exit", function() {
|
|
444
|
+
debug(fs[gracefulQueue]);
|
|
445
|
+
__require("assert").equal(fs[gracefulQueue].length, 0);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (!global[gracefulQueue]) publishQueue(global, fs[gracefulQueue]);
|
|
449
|
+
module.exports = patch(clone(fs));
|
|
450
|
+
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) {
|
|
451
|
+
module.exports = patch(fs);
|
|
452
|
+
fs.__patched = true;
|
|
453
|
+
}
|
|
454
|
+
function patch(fs) {
|
|
455
|
+
polyfills(fs);
|
|
456
|
+
fs.gracefulify = patch;
|
|
457
|
+
fs.createReadStream = createReadStream;
|
|
458
|
+
fs.createWriteStream = createWriteStream;
|
|
459
|
+
var fs$readFile = fs.readFile;
|
|
460
|
+
fs.readFile = readFile;
|
|
461
|
+
function readFile(path, options, cb) {
|
|
462
|
+
if (typeof options === "function") cb = options, options = null;
|
|
463
|
+
return go$readFile(path, options, cb);
|
|
464
|
+
function go$readFile(path, options, cb, startTime) {
|
|
465
|
+
return fs$readFile(path, options, function(err) {
|
|
466
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
|
|
467
|
+
go$readFile,
|
|
468
|
+
[
|
|
469
|
+
path,
|
|
470
|
+
options,
|
|
471
|
+
cb
|
|
472
|
+
],
|
|
473
|
+
err,
|
|
474
|
+
startTime || Date.now(),
|
|
475
|
+
Date.now()
|
|
476
|
+
]);
|
|
477
|
+
else if (typeof cb === "function") cb.apply(this, arguments);
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
var fs$writeFile = fs.writeFile;
|
|
482
|
+
fs.writeFile = writeFile;
|
|
483
|
+
function writeFile(path, data, options, cb) {
|
|
484
|
+
if (typeof options === "function") cb = options, options = null;
|
|
485
|
+
return go$writeFile(path, data, options, cb);
|
|
486
|
+
function go$writeFile(path, data, options, cb, startTime) {
|
|
487
|
+
return fs$writeFile(path, data, options, function(err) {
|
|
488
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
|
|
489
|
+
go$writeFile,
|
|
490
|
+
[
|
|
491
|
+
path,
|
|
492
|
+
data,
|
|
493
|
+
options,
|
|
494
|
+
cb
|
|
495
|
+
],
|
|
496
|
+
err,
|
|
497
|
+
startTime || Date.now(),
|
|
498
|
+
Date.now()
|
|
499
|
+
]);
|
|
500
|
+
else if (typeof cb === "function") cb.apply(this, arguments);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
var fs$appendFile = fs.appendFile;
|
|
505
|
+
if (fs$appendFile) fs.appendFile = appendFile;
|
|
506
|
+
function appendFile(path, data, options, cb) {
|
|
507
|
+
if (typeof options === "function") cb = options, options = null;
|
|
508
|
+
return go$appendFile(path, data, options, cb);
|
|
509
|
+
function go$appendFile(path, data, options, cb, startTime) {
|
|
510
|
+
return fs$appendFile(path, data, options, function(err) {
|
|
511
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
|
|
512
|
+
go$appendFile,
|
|
513
|
+
[
|
|
514
|
+
path,
|
|
515
|
+
data,
|
|
516
|
+
options,
|
|
517
|
+
cb
|
|
518
|
+
],
|
|
519
|
+
err,
|
|
520
|
+
startTime || Date.now(),
|
|
521
|
+
Date.now()
|
|
522
|
+
]);
|
|
523
|
+
else if (typeof cb === "function") cb.apply(this, arguments);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
var fs$copyFile = fs.copyFile;
|
|
528
|
+
if (fs$copyFile) fs.copyFile = copyFile;
|
|
529
|
+
function copyFile(src, dest, flags, cb) {
|
|
530
|
+
if (typeof flags === "function") {
|
|
531
|
+
cb = flags;
|
|
532
|
+
flags = 0;
|
|
533
|
+
}
|
|
534
|
+
return go$copyFile(src, dest, flags, cb);
|
|
535
|
+
function go$copyFile(src, dest, flags, cb, startTime) {
|
|
536
|
+
return fs$copyFile(src, dest, flags, function(err) {
|
|
537
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
|
|
538
|
+
go$copyFile,
|
|
539
|
+
[
|
|
540
|
+
src,
|
|
541
|
+
dest,
|
|
542
|
+
flags,
|
|
543
|
+
cb
|
|
544
|
+
],
|
|
545
|
+
err,
|
|
546
|
+
startTime || Date.now(),
|
|
547
|
+
Date.now()
|
|
548
|
+
]);
|
|
549
|
+
else if (typeof cb === "function") cb.apply(this, arguments);
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
var fs$readdir = fs.readdir;
|
|
554
|
+
fs.readdir = readdir;
|
|
555
|
+
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
556
|
+
function readdir(path, options, cb) {
|
|
557
|
+
if (typeof options === "function") cb = options, options = null;
|
|
558
|
+
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir(path, options, cb, startTime) {
|
|
559
|
+
return fs$readdir(path, fs$readdirCallback(path, options, cb, startTime));
|
|
560
|
+
} : function go$readdir(path, options, cb, startTime) {
|
|
561
|
+
return fs$readdir(path, options, fs$readdirCallback(path, options, cb, startTime));
|
|
562
|
+
};
|
|
563
|
+
return go$readdir(path, options, cb);
|
|
564
|
+
function fs$readdirCallback(path, options, cb, startTime) {
|
|
565
|
+
return function(err, files) {
|
|
566
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
|
|
567
|
+
go$readdir,
|
|
568
|
+
[
|
|
569
|
+
path,
|
|
570
|
+
options,
|
|
571
|
+
cb
|
|
572
|
+
],
|
|
573
|
+
err,
|
|
574
|
+
startTime || Date.now(),
|
|
575
|
+
Date.now()
|
|
576
|
+
]);
|
|
577
|
+
else {
|
|
578
|
+
if (files && files.sort) files.sort();
|
|
579
|
+
if (typeof cb === "function") cb.call(this, err, files);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (process.version.substr(0, 4) === "v0.8") {
|
|
585
|
+
var legStreams = legacy(fs);
|
|
586
|
+
ReadStream = legStreams.ReadStream;
|
|
587
|
+
WriteStream = legStreams.WriteStream;
|
|
588
|
+
}
|
|
589
|
+
var fs$ReadStream = fs.ReadStream;
|
|
590
|
+
if (fs$ReadStream) {
|
|
591
|
+
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
|
|
592
|
+
ReadStream.prototype.open = ReadStream$open;
|
|
593
|
+
}
|
|
594
|
+
var fs$WriteStream = fs.WriteStream;
|
|
595
|
+
if (fs$WriteStream) {
|
|
596
|
+
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
|
|
597
|
+
WriteStream.prototype.open = WriteStream$open;
|
|
598
|
+
}
|
|
599
|
+
Object.defineProperty(fs, "ReadStream", {
|
|
600
|
+
get: function() {
|
|
601
|
+
return ReadStream;
|
|
602
|
+
},
|
|
603
|
+
set: function(val) {
|
|
604
|
+
ReadStream = val;
|
|
605
|
+
},
|
|
606
|
+
enumerable: true,
|
|
607
|
+
configurable: true
|
|
608
|
+
});
|
|
609
|
+
Object.defineProperty(fs, "WriteStream", {
|
|
610
|
+
get: function() {
|
|
611
|
+
return WriteStream;
|
|
612
|
+
},
|
|
613
|
+
set: function(val) {
|
|
614
|
+
WriteStream = val;
|
|
615
|
+
},
|
|
616
|
+
enumerable: true,
|
|
617
|
+
configurable: true
|
|
618
|
+
});
|
|
619
|
+
var FileReadStream = ReadStream;
|
|
620
|
+
Object.defineProperty(fs, "FileReadStream", {
|
|
621
|
+
get: function() {
|
|
622
|
+
return FileReadStream;
|
|
623
|
+
},
|
|
624
|
+
set: function(val) {
|
|
625
|
+
FileReadStream = val;
|
|
626
|
+
},
|
|
627
|
+
enumerable: true,
|
|
628
|
+
configurable: true
|
|
629
|
+
});
|
|
630
|
+
var FileWriteStream = WriteStream;
|
|
631
|
+
Object.defineProperty(fs, "FileWriteStream", {
|
|
632
|
+
get: function() {
|
|
633
|
+
return FileWriteStream;
|
|
634
|
+
},
|
|
635
|
+
set: function(val) {
|
|
636
|
+
FileWriteStream = val;
|
|
637
|
+
},
|
|
638
|
+
enumerable: true,
|
|
639
|
+
configurable: true
|
|
640
|
+
});
|
|
641
|
+
function ReadStream(path, options) {
|
|
642
|
+
if (this instanceof ReadStream) return fs$ReadStream.apply(this, arguments), this;
|
|
643
|
+
else return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
|
|
644
|
+
}
|
|
645
|
+
function ReadStream$open() {
|
|
646
|
+
var that = this;
|
|
647
|
+
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
648
|
+
if (err) {
|
|
649
|
+
if (that.autoClose) that.destroy();
|
|
650
|
+
that.emit("error", err);
|
|
651
|
+
} else {
|
|
652
|
+
that.fd = fd;
|
|
653
|
+
that.emit("open", fd);
|
|
654
|
+
that.read();
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
function WriteStream(path, options) {
|
|
659
|
+
if (this instanceof WriteStream) return fs$WriteStream.apply(this, arguments), this;
|
|
660
|
+
else return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
|
|
661
|
+
}
|
|
662
|
+
function WriteStream$open() {
|
|
663
|
+
var that = this;
|
|
664
|
+
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
665
|
+
if (err) {
|
|
666
|
+
that.destroy();
|
|
667
|
+
that.emit("error", err);
|
|
668
|
+
} else {
|
|
669
|
+
that.fd = fd;
|
|
670
|
+
that.emit("open", fd);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
function createReadStream(path, options) {
|
|
675
|
+
return new fs.ReadStream(path, options);
|
|
676
|
+
}
|
|
677
|
+
function createWriteStream(path, options) {
|
|
678
|
+
return new fs.WriteStream(path, options);
|
|
679
|
+
}
|
|
680
|
+
var fs$open = fs.open;
|
|
681
|
+
fs.open = open;
|
|
682
|
+
function open(path, flags, mode, cb) {
|
|
683
|
+
if (typeof mode === "function") cb = mode, mode = null;
|
|
684
|
+
return go$open(path, flags, mode, cb);
|
|
685
|
+
function go$open(path, flags, mode, cb, startTime) {
|
|
686
|
+
return fs$open(path, flags, mode, function(err, fd) {
|
|
687
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
|
|
688
|
+
go$open,
|
|
689
|
+
[
|
|
690
|
+
path,
|
|
691
|
+
flags,
|
|
692
|
+
mode,
|
|
693
|
+
cb
|
|
694
|
+
],
|
|
695
|
+
err,
|
|
696
|
+
startTime || Date.now(),
|
|
697
|
+
Date.now()
|
|
698
|
+
]);
|
|
699
|
+
else if (typeof cb === "function") cb.apply(this, arguments);
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return fs;
|
|
704
|
+
}
|
|
705
|
+
function enqueue(elem) {
|
|
706
|
+
debug("ENQUEUE", elem[0].name, elem[1]);
|
|
707
|
+
fs[gracefulQueue].push(elem);
|
|
708
|
+
retry();
|
|
709
|
+
}
|
|
710
|
+
var retryTimer;
|
|
711
|
+
function resetQueue() {
|
|
712
|
+
var now = Date.now();
|
|
713
|
+
for (var i = 0; i < fs[gracefulQueue].length; ++i) if (fs[gracefulQueue][i].length > 2) {
|
|
714
|
+
fs[gracefulQueue][i][3] = now;
|
|
715
|
+
fs[gracefulQueue][i][4] = now;
|
|
716
|
+
}
|
|
717
|
+
retry();
|
|
718
|
+
}
|
|
719
|
+
function retry() {
|
|
720
|
+
clearTimeout(retryTimer);
|
|
721
|
+
retryTimer = void 0;
|
|
722
|
+
if (fs[gracefulQueue].length === 0) return;
|
|
723
|
+
var elem = fs[gracefulQueue].shift();
|
|
724
|
+
var fn = elem[0];
|
|
725
|
+
var args = elem[1];
|
|
726
|
+
var err = elem[2];
|
|
727
|
+
var startTime = elem[3];
|
|
728
|
+
var lastTime = elem[4];
|
|
729
|
+
if (startTime === void 0) {
|
|
730
|
+
debug("RETRY", fn.name, args);
|
|
731
|
+
fn.apply(null, args);
|
|
732
|
+
} else if (Date.now() - startTime >= 6e4) {
|
|
733
|
+
debug("TIMEOUT", fn.name, args);
|
|
734
|
+
var cb = args.pop();
|
|
735
|
+
if (typeof cb === "function") cb.call(null, err);
|
|
736
|
+
} else {
|
|
737
|
+
var sinceAttempt = Date.now() - lastTime;
|
|
738
|
+
var sinceStart = Math.max(lastTime - startTime, 1);
|
|
739
|
+
if (sinceAttempt >= Math.min(sinceStart * 1.2, 100)) {
|
|
740
|
+
debug("RETRY", fn.name, args);
|
|
741
|
+
fn.apply(null, args.concat([startTime]));
|
|
742
|
+
} else fs[gracefulQueue].push(elem);
|
|
743
|
+
}
|
|
744
|
+
if (retryTimer === void 0) retryTimer = setTimeout(retry, 0);
|
|
745
|
+
}
|
|
746
|
+
}));
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry_operation.js
|
|
749
|
+
var require_retry_operation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
750
|
+
function RetryOperation(timeouts, options) {
|
|
751
|
+
if (typeof options === "boolean") options = { forever: options };
|
|
752
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
753
|
+
this._timeouts = timeouts;
|
|
754
|
+
this._options = options || {};
|
|
755
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
756
|
+
this._fn = null;
|
|
757
|
+
this._errors = [];
|
|
758
|
+
this._attempts = 1;
|
|
759
|
+
this._operationTimeout = null;
|
|
760
|
+
this._operationTimeoutCb = null;
|
|
761
|
+
this._timeout = null;
|
|
762
|
+
this._operationStart = null;
|
|
763
|
+
if (this._options.forever) this._cachedTimeouts = this._timeouts.slice(0);
|
|
764
|
+
}
|
|
765
|
+
module.exports = RetryOperation;
|
|
766
|
+
RetryOperation.prototype.reset = function() {
|
|
767
|
+
this._attempts = 1;
|
|
768
|
+
this._timeouts = this._originalTimeouts;
|
|
769
|
+
};
|
|
770
|
+
RetryOperation.prototype.stop = function() {
|
|
771
|
+
if (this._timeout) clearTimeout(this._timeout);
|
|
772
|
+
this._timeouts = [];
|
|
773
|
+
this._cachedTimeouts = null;
|
|
774
|
+
};
|
|
775
|
+
RetryOperation.prototype.retry = function(err) {
|
|
776
|
+
if (this._timeout) clearTimeout(this._timeout);
|
|
777
|
+
if (!err) return false;
|
|
778
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
779
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
780
|
+
this._errors.unshift(/* @__PURE__ */ new Error("RetryOperation timeout occurred"));
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
this._errors.push(err);
|
|
784
|
+
var timeout = this._timeouts.shift();
|
|
785
|
+
if (timeout === void 0) if (this._cachedTimeouts) {
|
|
786
|
+
this._errors.splice(this._errors.length - 1, this._errors.length);
|
|
787
|
+
this._timeouts = this._cachedTimeouts.slice(0);
|
|
788
|
+
timeout = this._timeouts.shift();
|
|
789
|
+
} else return false;
|
|
790
|
+
var self = this;
|
|
791
|
+
var timer = setTimeout(function() {
|
|
792
|
+
self._attempts++;
|
|
793
|
+
if (self._operationTimeoutCb) {
|
|
794
|
+
self._timeout = setTimeout(function() {
|
|
795
|
+
self._operationTimeoutCb(self._attempts);
|
|
796
|
+
}, self._operationTimeout);
|
|
797
|
+
if (self._options.unref) self._timeout.unref();
|
|
798
|
+
}
|
|
799
|
+
self._fn(self._attempts);
|
|
800
|
+
}, timeout);
|
|
801
|
+
if (this._options.unref) timer.unref();
|
|
802
|
+
return true;
|
|
803
|
+
};
|
|
804
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
805
|
+
this._fn = fn;
|
|
806
|
+
if (timeoutOps) {
|
|
807
|
+
if (timeoutOps.timeout) this._operationTimeout = timeoutOps.timeout;
|
|
808
|
+
if (timeoutOps.cb) this._operationTimeoutCb = timeoutOps.cb;
|
|
809
|
+
}
|
|
810
|
+
var self = this;
|
|
811
|
+
if (this._operationTimeoutCb) this._timeout = setTimeout(function() {
|
|
812
|
+
self._operationTimeoutCb();
|
|
813
|
+
}, self._operationTimeout);
|
|
814
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
815
|
+
this._fn(this._attempts);
|
|
816
|
+
};
|
|
817
|
+
RetryOperation.prototype.try = function(fn) {
|
|
818
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
819
|
+
this.attempt(fn);
|
|
820
|
+
};
|
|
821
|
+
RetryOperation.prototype.start = function(fn) {
|
|
822
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
823
|
+
this.attempt(fn);
|
|
824
|
+
};
|
|
825
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
826
|
+
RetryOperation.prototype.errors = function() {
|
|
827
|
+
return this._errors;
|
|
828
|
+
};
|
|
829
|
+
RetryOperation.prototype.attempts = function() {
|
|
830
|
+
return this._attempts;
|
|
831
|
+
};
|
|
832
|
+
RetryOperation.prototype.mainError = function() {
|
|
833
|
+
if (this._errors.length === 0) return null;
|
|
834
|
+
var counts = {};
|
|
835
|
+
var mainError = null;
|
|
836
|
+
var mainErrorCount = 0;
|
|
837
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
838
|
+
var error = this._errors[i];
|
|
839
|
+
var message = error.message;
|
|
840
|
+
var count = (counts[message] || 0) + 1;
|
|
841
|
+
counts[message] = count;
|
|
842
|
+
if (count >= mainErrorCount) {
|
|
843
|
+
mainError = error;
|
|
844
|
+
mainErrorCount = count;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return mainError;
|
|
848
|
+
};
|
|
849
|
+
}));
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry.js
|
|
852
|
+
var require_retry$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
853
|
+
var RetryOperation = require_retry_operation();
|
|
854
|
+
exports.operation = function(options) {
|
|
855
|
+
return new RetryOperation(exports.timeouts(options), {
|
|
856
|
+
forever: options && options.forever,
|
|
857
|
+
unref: options && options.unref,
|
|
858
|
+
maxRetryTime: options && options.maxRetryTime
|
|
859
|
+
});
|
|
860
|
+
};
|
|
861
|
+
exports.timeouts = function(options) {
|
|
862
|
+
if (options instanceof Array) return [].concat(options);
|
|
863
|
+
var opts = {
|
|
864
|
+
retries: 10,
|
|
865
|
+
factor: 2,
|
|
866
|
+
minTimeout: 1 * 1e3,
|
|
867
|
+
maxTimeout: Infinity,
|
|
868
|
+
randomize: false
|
|
869
|
+
};
|
|
870
|
+
for (var key in options) opts[key] = options[key];
|
|
871
|
+
if (opts.minTimeout > opts.maxTimeout) throw new Error("minTimeout is greater than maxTimeout");
|
|
872
|
+
var timeouts = [];
|
|
873
|
+
for (var i = 0; i < opts.retries; i++) timeouts.push(this.createTimeout(i, opts));
|
|
874
|
+
if (options && options.forever && !timeouts.length) timeouts.push(this.createTimeout(i, opts));
|
|
875
|
+
timeouts.sort(function(a, b) {
|
|
876
|
+
return a - b;
|
|
877
|
+
});
|
|
878
|
+
return timeouts;
|
|
879
|
+
};
|
|
880
|
+
exports.createTimeout = function(attempt, opts) {
|
|
881
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
882
|
+
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
|
|
883
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
884
|
+
return timeout;
|
|
885
|
+
};
|
|
886
|
+
exports.wrap = function(obj, options, methods) {
|
|
887
|
+
if (options instanceof Array) {
|
|
888
|
+
methods = options;
|
|
889
|
+
options = null;
|
|
890
|
+
}
|
|
891
|
+
if (!methods) {
|
|
892
|
+
methods = [];
|
|
893
|
+
for (var key in obj) if (typeof obj[key] === "function") methods.push(key);
|
|
894
|
+
}
|
|
895
|
+
for (var i = 0; i < methods.length; i++) {
|
|
896
|
+
var method = methods[i];
|
|
897
|
+
var original = obj[method];
|
|
898
|
+
obj[method] = function retryWrapper(original) {
|
|
899
|
+
var op = exports.operation(options);
|
|
900
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
901
|
+
var callback = args.pop();
|
|
902
|
+
args.push(function(err) {
|
|
903
|
+
if (op.retry(err)) return;
|
|
904
|
+
if (err) arguments[0] = op.mainError();
|
|
905
|
+
callback.apply(this, arguments);
|
|
906
|
+
});
|
|
907
|
+
op.attempt(function() {
|
|
908
|
+
original.apply(obj, args);
|
|
909
|
+
});
|
|
910
|
+
}.bind(obj, original);
|
|
911
|
+
obj[method].options = options;
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
}));
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region node_modules/.pnpm/retry@0.12.0/node_modules/retry/index.js
|
|
917
|
+
var require_retry = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
918
|
+
module.exports = require_retry$1();
|
|
919
|
+
}));
|
|
920
|
+
//#endregion
|
|
921
|
+
//#region node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/signals.js
|
|
922
|
+
var require_signals = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
923
|
+
module.exports = [
|
|
924
|
+
"SIGABRT",
|
|
925
|
+
"SIGALRM",
|
|
926
|
+
"SIGHUP",
|
|
927
|
+
"SIGINT",
|
|
928
|
+
"SIGTERM"
|
|
929
|
+
];
|
|
930
|
+
if (process.platform !== "win32") module.exports.push("SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
|
|
931
|
+
if (process.platform === "linux") module.exports.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT", "SIGUNUSED");
|
|
932
|
+
}));
|
|
933
|
+
//#endregion
|
|
934
|
+
//#region node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/index.js
|
|
935
|
+
var require_signal_exit = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
936
|
+
var process = global.process;
|
|
937
|
+
const processOk = function(process) {
|
|
938
|
+
return process && typeof process === "object" && typeof process.removeListener === "function" && typeof process.emit === "function" && typeof process.reallyExit === "function" && typeof process.listeners === "function" && typeof process.kill === "function" && typeof process.pid === "number" && typeof process.on === "function";
|
|
939
|
+
};
|
|
940
|
+
/* istanbul ignore if */
|
|
941
|
+
if (!processOk(process)) module.exports = function() {
|
|
942
|
+
return function() {};
|
|
943
|
+
};
|
|
944
|
+
else {
|
|
945
|
+
var assert = __require("assert");
|
|
946
|
+
var signals = require_signals();
|
|
947
|
+
var isWin = /^win/i.test(process.platform);
|
|
948
|
+
var EE = __require("events");
|
|
949
|
+
/* istanbul ignore if */
|
|
950
|
+
if (typeof EE !== "function") EE = EE.EventEmitter;
|
|
951
|
+
var emitter;
|
|
952
|
+
if (process.__signal_exit_emitter__) emitter = process.__signal_exit_emitter__;
|
|
953
|
+
else {
|
|
954
|
+
emitter = process.__signal_exit_emitter__ = new EE();
|
|
955
|
+
emitter.count = 0;
|
|
956
|
+
emitter.emitted = {};
|
|
957
|
+
}
|
|
958
|
+
if (!emitter.infinite) {
|
|
959
|
+
emitter.setMaxListeners(Infinity);
|
|
960
|
+
emitter.infinite = true;
|
|
961
|
+
}
|
|
962
|
+
module.exports = function(cb, opts) {
|
|
963
|
+
/* istanbul ignore if */
|
|
964
|
+
if (!processOk(global.process)) return function() {};
|
|
965
|
+
assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
|
|
966
|
+
if (loaded === false) load();
|
|
967
|
+
var ev = "exit";
|
|
968
|
+
if (opts && opts.alwaysLast) ev = "afterexit";
|
|
969
|
+
var remove = function() {
|
|
970
|
+
emitter.removeListener(ev, cb);
|
|
971
|
+
if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) unload();
|
|
972
|
+
};
|
|
973
|
+
emitter.on(ev, cb);
|
|
974
|
+
return remove;
|
|
975
|
+
};
|
|
976
|
+
var unload = function unload() {
|
|
977
|
+
if (!loaded || !processOk(global.process)) return;
|
|
978
|
+
loaded = false;
|
|
979
|
+
signals.forEach(function(sig) {
|
|
980
|
+
try {
|
|
981
|
+
process.removeListener(sig, sigListeners[sig]);
|
|
982
|
+
} catch (er) {}
|
|
983
|
+
});
|
|
984
|
+
process.emit = originalProcessEmit;
|
|
985
|
+
process.reallyExit = originalProcessReallyExit;
|
|
986
|
+
emitter.count -= 1;
|
|
987
|
+
};
|
|
988
|
+
module.exports.unload = unload;
|
|
989
|
+
var emit = function emit(event, code, signal) {
|
|
990
|
+
/* istanbul ignore if */
|
|
991
|
+
if (emitter.emitted[event]) return;
|
|
992
|
+
emitter.emitted[event] = true;
|
|
993
|
+
emitter.emit(event, code, signal);
|
|
994
|
+
};
|
|
995
|
+
var sigListeners = {};
|
|
996
|
+
signals.forEach(function(sig) {
|
|
997
|
+
sigListeners[sig] = function listener() {
|
|
998
|
+
/* istanbul ignore if */
|
|
999
|
+
if (!processOk(global.process)) return;
|
|
1000
|
+
if (process.listeners(sig).length === emitter.count) {
|
|
1001
|
+
unload();
|
|
1002
|
+
emit("exit", null, sig);
|
|
1003
|
+
/* istanbul ignore next */
|
|
1004
|
+
emit("afterexit", null, sig);
|
|
1005
|
+
/* istanbul ignore next */
|
|
1006
|
+
if (isWin && sig === "SIGHUP") sig = "SIGINT";
|
|
1007
|
+
/* istanbul ignore next */
|
|
1008
|
+
process.kill(process.pid, sig);
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
});
|
|
1012
|
+
module.exports.signals = function() {
|
|
1013
|
+
return signals;
|
|
1014
|
+
};
|
|
1015
|
+
var loaded = false;
|
|
1016
|
+
var load = function load() {
|
|
1017
|
+
if (loaded || !processOk(global.process)) return;
|
|
1018
|
+
loaded = true;
|
|
1019
|
+
emitter.count += 1;
|
|
1020
|
+
signals = signals.filter(function(sig) {
|
|
1021
|
+
try {
|
|
1022
|
+
process.on(sig, sigListeners[sig]);
|
|
1023
|
+
return true;
|
|
1024
|
+
} catch (er) {
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
process.emit = processEmit;
|
|
1029
|
+
process.reallyExit = processReallyExit;
|
|
1030
|
+
};
|
|
1031
|
+
module.exports.load = load;
|
|
1032
|
+
var originalProcessReallyExit = process.reallyExit;
|
|
1033
|
+
var processReallyExit = function processReallyExit(code) {
|
|
1034
|
+
/* istanbul ignore if */
|
|
1035
|
+
if (!processOk(global.process)) return;
|
|
1036
|
+
process.exitCode = code || 0;
|
|
1037
|
+
emit("exit", process.exitCode, null);
|
|
1038
|
+
/* istanbul ignore next */
|
|
1039
|
+
emit("afterexit", process.exitCode, null);
|
|
1040
|
+
/* istanbul ignore next */
|
|
1041
|
+
originalProcessReallyExit.call(process, process.exitCode);
|
|
1042
|
+
};
|
|
1043
|
+
var originalProcessEmit = process.emit;
|
|
1044
|
+
var processEmit = function processEmit(ev, arg) {
|
|
1045
|
+
if (ev === "exit" && processOk(global.process)) {
|
|
1046
|
+
/* istanbul ignore else */
|
|
1047
|
+
if (arg !== void 0) process.exitCode = arg;
|
|
1048
|
+
var ret = originalProcessEmit.apply(this, arguments);
|
|
1049
|
+
/* istanbul ignore next */
|
|
1050
|
+
emit("exit", process.exitCode, null);
|
|
1051
|
+
/* istanbul ignore next */
|
|
1052
|
+
emit("afterexit", process.exitCode, null);
|
|
1053
|
+
/* istanbul ignore next */
|
|
1054
|
+
return ret;
|
|
1055
|
+
} else return originalProcessEmit.apply(this, arguments);
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
}));
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js
|
|
1061
|
+
var require_mtime_precision = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1062
|
+
const cacheSymbol = Symbol();
|
|
1063
|
+
function probe(file, fs, callback) {
|
|
1064
|
+
const cachedPrecision = fs[cacheSymbol];
|
|
1065
|
+
if (cachedPrecision) return fs.stat(file, (err, stat) => {
|
|
1066
|
+
/* istanbul ignore if */
|
|
1067
|
+
if (err) return callback(err);
|
|
1068
|
+
callback(null, stat.mtime, cachedPrecision);
|
|
1069
|
+
});
|
|
1070
|
+
const mtime = /* @__PURE__ */ new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
|
|
1071
|
+
fs.utimes(file, mtime, mtime, (err) => {
|
|
1072
|
+
/* istanbul ignore if */
|
|
1073
|
+
if (err) return callback(err);
|
|
1074
|
+
fs.stat(file, (err, stat) => {
|
|
1075
|
+
/* istanbul ignore if */
|
|
1076
|
+
if (err) return callback(err);
|
|
1077
|
+
const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
|
|
1078
|
+
Object.defineProperty(fs, cacheSymbol, { value: precision });
|
|
1079
|
+
callback(null, stat.mtime, precision);
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
function getMtime(precision) {
|
|
1084
|
+
let now = Date.now();
|
|
1085
|
+
if (precision === "s") now = Math.ceil(now / 1e3) * 1e3;
|
|
1086
|
+
return new Date(now);
|
|
1087
|
+
}
|
|
1088
|
+
module.exports.probe = probe;
|
|
1089
|
+
module.exports.getMtime = getMtime;
|
|
1090
|
+
}));
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js
|
|
1093
|
+
var require_lockfile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1094
|
+
const path = __require("path");
|
|
1095
|
+
const fs = require_graceful_fs();
|
|
1096
|
+
const retry = require_retry();
|
|
1097
|
+
const onExit = require_signal_exit();
|
|
1098
|
+
const mtimePrecision = require_mtime_precision();
|
|
1099
|
+
const locks = {};
|
|
1100
|
+
function getLockFile(file, options) {
|
|
1101
|
+
return options.lockfilePath || `${file}.lock`;
|
|
1102
|
+
}
|
|
1103
|
+
function resolveCanonicalPath(file, options, callback) {
|
|
1104
|
+
if (!options.realpath) return callback(null, path.resolve(file));
|
|
1105
|
+
options.fs.realpath(file, callback);
|
|
1106
|
+
}
|
|
1107
|
+
function acquireLock(file, options, callback) {
|
|
1108
|
+
const lockfilePath = getLockFile(file, options);
|
|
1109
|
+
options.fs.mkdir(lockfilePath, (err) => {
|
|
1110
|
+
if (!err) return mtimePrecision.probe(lockfilePath, options.fs, (err, mtime, mtimePrecision) => {
|
|
1111
|
+
/* istanbul ignore if */
|
|
1112
|
+
if (err) {
|
|
1113
|
+
options.fs.rmdir(lockfilePath, () => {});
|
|
1114
|
+
return callback(err);
|
|
1115
|
+
}
|
|
1116
|
+
callback(null, mtime, mtimePrecision);
|
|
1117
|
+
});
|
|
1118
|
+
if (err.code !== "EEXIST") return callback(err);
|
|
1119
|
+
if (options.stale <= 0) return callback(Object.assign(/* @__PURE__ */ new Error("Lock file is already being held"), {
|
|
1120
|
+
code: "ELOCKED",
|
|
1121
|
+
file
|
|
1122
|
+
}));
|
|
1123
|
+
options.fs.stat(lockfilePath, (err, stat) => {
|
|
1124
|
+
if (err) {
|
|
1125
|
+
if (err.code === "ENOENT") return acquireLock(file, {
|
|
1126
|
+
...options,
|
|
1127
|
+
stale: 0
|
|
1128
|
+
}, callback);
|
|
1129
|
+
return callback(err);
|
|
1130
|
+
}
|
|
1131
|
+
if (!isLockStale(stat, options)) return callback(Object.assign(/* @__PURE__ */ new Error("Lock file is already being held"), {
|
|
1132
|
+
code: "ELOCKED",
|
|
1133
|
+
file
|
|
1134
|
+
}));
|
|
1135
|
+
removeLock(file, options, (err) => {
|
|
1136
|
+
if (err) return callback(err);
|
|
1137
|
+
acquireLock(file, {
|
|
1138
|
+
...options,
|
|
1139
|
+
stale: 0
|
|
1140
|
+
}, callback);
|
|
1141
|
+
});
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
function isLockStale(stat, options) {
|
|
1146
|
+
return stat.mtime.getTime() < Date.now() - options.stale;
|
|
1147
|
+
}
|
|
1148
|
+
function removeLock(file, options, callback) {
|
|
1149
|
+
options.fs.rmdir(getLockFile(file, options), (err) => {
|
|
1150
|
+
if (err && err.code !== "ENOENT") return callback(err);
|
|
1151
|
+
callback();
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
function updateLock(file, options) {
|
|
1155
|
+
const lock = locks[file];
|
|
1156
|
+
/* istanbul ignore if */
|
|
1157
|
+
if (lock.updateTimeout) return;
|
|
1158
|
+
lock.updateDelay = lock.updateDelay || options.update;
|
|
1159
|
+
lock.updateTimeout = setTimeout(() => {
|
|
1160
|
+
lock.updateTimeout = null;
|
|
1161
|
+
options.fs.stat(lock.lockfilePath, (err, stat) => {
|
|
1162
|
+
const isOverThreshold = lock.lastUpdate + options.stale < Date.now();
|
|
1163
|
+
if (err) {
|
|
1164
|
+
if (err.code === "ENOENT" || isOverThreshold) return setLockAsCompromised(file, lock, Object.assign(err, { code: "ECOMPROMISED" }));
|
|
1165
|
+
lock.updateDelay = 1e3;
|
|
1166
|
+
return updateLock(file, options);
|
|
1167
|
+
}
|
|
1168
|
+
if (!(lock.mtime.getTime() === stat.mtime.getTime())) return setLockAsCompromised(file, lock, Object.assign(/* @__PURE__ */ new Error("Unable to update lock within the stale threshold"), { code: "ECOMPROMISED" }));
|
|
1169
|
+
const mtime = mtimePrecision.getMtime(lock.mtimePrecision);
|
|
1170
|
+
options.fs.utimes(lock.lockfilePath, mtime, mtime, (err) => {
|
|
1171
|
+
const isOverThreshold = lock.lastUpdate + options.stale < Date.now();
|
|
1172
|
+
if (lock.released) return;
|
|
1173
|
+
if (err) {
|
|
1174
|
+
if (err.code === "ENOENT" || isOverThreshold) return setLockAsCompromised(file, lock, Object.assign(err, { code: "ECOMPROMISED" }));
|
|
1175
|
+
lock.updateDelay = 1e3;
|
|
1176
|
+
return updateLock(file, options);
|
|
1177
|
+
}
|
|
1178
|
+
lock.mtime = mtime;
|
|
1179
|
+
lock.lastUpdate = Date.now();
|
|
1180
|
+
lock.updateDelay = null;
|
|
1181
|
+
updateLock(file, options);
|
|
1182
|
+
});
|
|
1183
|
+
});
|
|
1184
|
+
}, lock.updateDelay);
|
|
1185
|
+
/* istanbul ignore else */
|
|
1186
|
+
if (lock.updateTimeout.unref) lock.updateTimeout.unref();
|
|
1187
|
+
}
|
|
1188
|
+
function setLockAsCompromised(file, lock, err) {
|
|
1189
|
+
lock.released = true;
|
|
1190
|
+
/* istanbul ignore if */
|
|
1191
|
+
if (lock.updateTimeout) clearTimeout(lock.updateTimeout);
|
|
1192
|
+
if (locks[file] === lock) delete locks[file];
|
|
1193
|
+
lock.options.onCompromised(err);
|
|
1194
|
+
}
|
|
1195
|
+
function lock(file, options, callback) {
|
|
1196
|
+
/* istanbul ignore next */
|
|
1197
|
+
options = {
|
|
1198
|
+
stale: 1e4,
|
|
1199
|
+
update: null,
|
|
1200
|
+
realpath: true,
|
|
1201
|
+
retries: 0,
|
|
1202
|
+
fs,
|
|
1203
|
+
onCompromised: (err) => {
|
|
1204
|
+
throw err;
|
|
1205
|
+
},
|
|
1206
|
+
...options
|
|
1207
|
+
};
|
|
1208
|
+
options.retries = options.retries || 0;
|
|
1209
|
+
options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
|
|
1210
|
+
options.stale = Math.max(options.stale || 0, 2e3);
|
|
1211
|
+
options.update = options.update == null ? options.stale / 2 : options.update || 0;
|
|
1212
|
+
options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
|
|
1213
|
+
resolveCanonicalPath(file, options, (err, file) => {
|
|
1214
|
+
if (err) return callback(err);
|
|
1215
|
+
const operation = retry.operation(options.retries);
|
|
1216
|
+
operation.attempt(() => {
|
|
1217
|
+
acquireLock(file, options, (err, mtime, mtimePrecision) => {
|
|
1218
|
+
if (operation.retry(err)) return;
|
|
1219
|
+
if (err) return callback(operation.mainError());
|
|
1220
|
+
const lock = locks[file] = {
|
|
1221
|
+
lockfilePath: getLockFile(file, options),
|
|
1222
|
+
mtime,
|
|
1223
|
+
mtimePrecision,
|
|
1224
|
+
options,
|
|
1225
|
+
lastUpdate: Date.now()
|
|
1226
|
+
};
|
|
1227
|
+
updateLock(file, options);
|
|
1228
|
+
callback(null, (releasedCallback) => {
|
|
1229
|
+
if (lock.released) return releasedCallback && releasedCallback(Object.assign(/* @__PURE__ */ new Error("Lock is already released"), { code: "ERELEASED" }));
|
|
1230
|
+
unlock(file, {
|
|
1231
|
+
...options,
|
|
1232
|
+
realpath: false
|
|
1233
|
+
}, releasedCallback);
|
|
1234
|
+
});
|
|
1235
|
+
});
|
|
1236
|
+
});
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
function unlock(file, options, callback) {
|
|
1240
|
+
options = {
|
|
1241
|
+
fs,
|
|
1242
|
+
realpath: true,
|
|
1243
|
+
...options
|
|
1244
|
+
};
|
|
1245
|
+
resolveCanonicalPath(file, options, (err, file) => {
|
|
1246
|
+
if (err) return callback(err);
|
|
1247
|
+
const lock = locks[file];
|
|
1248
|
+
if (!lock) return callback(Object.assign(/* @__PURE__ */ new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
|
|
1249
|
+
lock.updateTimeout && clearTimeout(lock.updateTimeout);
|
|
1250
|
+
lock.released = true;
|
|
1251
|
+
delete locks[file];
|
|
1252
|
+
removeLock(file, options, callback);
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
function check(file, options, callback) {
|
|
1256
|
+
options = {
|
|
1257
|
+
stale: 1e4,
|
|
1258
|
+
realpath: true,
|
|
1259
|
+
fs,
|
|
1260
|
+
...options
|
|
1261
|
+
};
|
|
1262
|
+
options.stale = Math.max(options.stale || 0, 2e3);
|
|
1263
|
+
resolveCanonicalPath(file, options, (err, file) => {
|
|
1264
|
+
if (err) return callback(err);
|
|
1265
|
+
options.fs.stat(getLockFile(file, options), (err, stat) => {
|
|
1266
|
+
if (err) return err.code === "ENOENT" ? callback(null, false) : callback(err);
|
|
1267
|
+
return callback(null, !isLockStale(stat, options));
|
|
1268
|
+
});
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
function getLocks() {
|
|
1272
|
+
return locks;
|
|
1273
|
+
}
|
|
1274
|
+
/* istanbul ignore next */
|
|
1275
|
+
onExit(() => {
|
|
1276
|
+
for (const file in locks) {
|
|
1277
|
+
const options = locks[file].options;
|
|
1278
|
+
try {
|
|
1279
|
+
options.fs.rmdirSync(getLockFile(file, options));
|
|
1280
|
+
} catch (e) {}
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
module.exports.lock = lock;
|
|
1284
|
+
module.exports.unlock = unlock;
|
|
1285
|
+
module.exports.check = check;
|
|
1286
|
+
module.exports.getLocks = getLocks;
|
|
1287
|
+
}));
|
|
1288
|
+
//#endregion
|
|
1289
|
+
//#region node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/adapter.js
|
|
1290
|
+
var require_adapter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1291
|
+
const fs = require_graceful_fs();
|
|
1292
|
+
function createSyncFs(fs) {
|
|
1293
|
+
const methods = [
|
|
1294
|
+
"mkdir",
|
|
1295
|
+
"realpath",
|
|
1296
|
+
"stat",
|
|
1297
|
+
"rmdir",
|
|
1298
|
+
"utimes"
|
|
1299
|
+
];
|
|
1300
|
+
const newFs = { ...fs };
|
|
1301
|
+
methods.forEach((method) => {
|
|
1302
|
+
newFs[method] = (...args) => {
|
|
1303
|
+
const callback = args.pop();
|
|
1304
|
+
let ret;
|
|
1305
|
+
try {
|
|
1306
|
+
ret = fs[`${method}Sync`](...args);
|
|
1307
|
+
} catch (err) {
|
|
1308
|
+
return callback(err);
|
|
1309
|
+
}
|
|
1310
|
+
callback(null, ret);
|
|
1311
|
+
};
|
|
1312
|
+
});
|
|
1313
|
+
return newFs;
|
|
1314
|
+
}
|
|
1315
|
+
function toPromise(method) {
|
|
1316
|
+
return (...args) => new Promise((resolve, reject) => {
|
|
1317
|
+
args.push((err, result) => {
|
|
1318
|
+
if (err) reject(err);
|
|
1319
|
+
else resolve(result);
|
|
1320
|
+
});
|
|
1321
|
+
method(...args);
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
function toSync(method) {
|
|
1325
|
+
return (...args) => {
|
|
1326
|
+
let err;
|
|
1327
|
+
let result;
|
|
1328
|
+
args.push((_err, _result) => {
|
|
1329
|
+
err = _err;
|
|
1330
|
+
result = _result;
|
|
1331
|
+
});
|
|
1332
|
+
method(...args);
|
|
1333
|
+
if (err) throw err;
|
|
1334
|
+
return result;
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
function toSyncOptions(options) {
|
|
1338
|
+
options = { ...options };
|
|
1339
|
+
options.fs = createSyncFs(options.fs || fs);
|
|
1340
|
+
if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) throw Object.assign(/* @__PURE__ */ new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
|
|
1341
|
+
return options;
|
|
1342
|
+
}
|
|
1343
|
+
module.exports = {
|
|
1344
|
+
toPromise,
|
|
1345
|
+
toSync,
|
|
1346
|
+
toSyncOptions
|
|
1347
|
+
};
|
|
1348
|
+
}));
|
|
1349
|
+
//#endregion
|
|
1350
|
+
//#region node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/index.js
|
|
1351
|
+
var require_proper_lockfile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1352
|
+
const lockfile = require_lockfile();
|
|
1353
|
+
const { toPromise, toSync, toSyncOptions } = require_adapter();
|
|
1354
|
+
async function lock(file, options) {
|
|
1355
|
+
return toPromise(await toPromise(lockfile.lock)(file, options));
|
|
1356
|
+
}
|
|
1357
|
+
function lockSync(file, options) {
|
|
1358
|
+
return toSync(toSync(lockfile.lock)(file, toSyncOptions(options)));
|
|
1359
|
+
}
|
|
1360
|
+
function unlock(file, options) {
|
|
1361
|
+
return toPromise(lockfile.unlock)(file, options);
|
|
1362
|
+
}
|
|
1363
|
+
function unlockSync(file, options) {
|
|
1364
|
+
return toSync(lockfile.unlock)(file, toSyncOptions(options));
|
|
1365
|
+
}
|
|
1366
|
+
function check(file, options) {
|
|
1367
|
+
return toPromise(lockfile.check)(file, options);
|
|
1368
|
+
}
|
|
1369
|
+
function checkSync(file, options) {
|
|
1370
|
+
return toSync(lockfile.check)(file, toSyncOptions(options));
|
|
1371
|
+
}
|
|
1372
|
+
module.exports = lock;
|
|
1373
|
+
module.exports.lock = lock;
|
|
1374
|
+
module.exports.unlock = unlock;
|
|
1375
|
+
module.exports.lockSync = lockSync;
|
|
1376
|
+
module.exports.unlockSync = unlockSync;
|
|
1377
|
+
module.exports.check = check;
|
|
1378
|
+
module.exports.checkSync = checkSync;
|
|
1379
|
+
}));
|
|
1380
|
+
//#endregion
|
|
6
1381
|
//#region node_modules/.pnpm/typebox@1.1.38/node_modules/typebox/build/guard/string.mjs
|
|
7
1382
|
function IsBetween(value, min, max) {
|
|
8
1383
|
return value >= min && value <= max;
|
|
@@ -709,6 +2084,7 @@ function IsUnevaluatedProperties(schema) {
|
|
|
709
2084
|
}
|
|
710
2085
|
//#endregion
|
|
711
2086
|
//#region node_modules/.pnpm/typebox@1.1.38/node_modules/typebox/build/schema/engine/_context.mjs
|
|
2087
|
+
var import_proper_lockfile = /* @__PURE__ */ __toESM(require_proper_lockfile(), 1);
|
|
712
2088
|
var CheckContext = class {
|
|
713
2089
|
constructor() {
|
|
714
2090
|
const indices = /* @__PURE__ */ new Set();
|
|
@@ -2706,9 +4082,9 @@ function Parse(...args) {
|
|
|
2706
4082
|
const configDefaults = {
|
|
2707
4083
|
enabled: true,
|
|
2708
4084
|
quiet: false,
|
|
2709
|
-
toolName: "
|
|
2710
|
-
toolDescription: "Set your
|
|
2711
|
-
systemPrompt: "You MUST manage
|
|
4085
|
+
toolName: "set_thinking_level",
|
|
4086
|
+
toolDescription: "Set your thinking level",
|
|
4087
|
+
systemPrompt: "You MUST manage thinking level actively. Lower it before trivial or routine turns; raise it for ambiguity, debugging, risky changes, or multi-step synthesis. Reassess at turn start, after meaningful new evidence, and when the task shifts. NEVER leave the current level unchanged by inertia, and NEVER reply to a trivial turn before considering a downshift."
|
|
2712
4088
|
};
|
|
2713
4089
|
const ConfigSchema = Type.Object({
|
|
2714
4090
|
enabled: Type.Boolean(),
|
|
@@ -2734,8 +4110,8 @@ const invalidConfig = (source, error) => ({
|
|
|
2734
4110
|
source,
|
|
2735
4111
|
error: /* @__PURE__ */ new Error(`Invalid Adaptive Thinking configuration in ${source}: ${errorMessage$1(error)}`)
|
|
2736
4112
|
});
|
|
2737
|
-
const loadConfig = async ({ cwd, homeDir = homedir() }) => {
|
|
2738
|
-
const candidates = [join(cwd, ".pi", "adaptive-thinking.json"), join(homeDir, ".pi", "agent", "adaptive-thinking.json")];
|
|
4113
|
+
const loadConfig = async ({ cwd, homeDir = homedir$1() }) => {
|
|
4114
|
+
const candidates = [join$1(cwd, ".pi", "adaptive-thinking.json"), join$1(homeDir, ".pi", "agent", "adaptive-thinking.json")];
|
|
2739
4115
|
for (const source of candidates) {
|
|
2740
4116
|
let raw;
|
|
2741
4117
|
try {
|
|
@@ -2780,7 +4156,7 @@ const resolveSupportedThinkingLevels = (model) => {
|
|
|
2780
4156
|
const ToolParameters = Type.Object({
|
|
2781
4157
|
level: Type.String({
|
|
2782
4158
|
minLength: 1,
|
|
2783
|
-
description: "The
|
|
4159
|
+
description: "The Pi thinking level to apply. Higher levels may improve hard-task quality but may take more time and resources."
|
|
2784
4160
|
}),
|
|
2785
4161
|
persist: Type.Optional(Type.Boolean({
|
|
2786
4162
|
default: false,
|
|
@@ -2795,6 +4171,62 @@ const textResult = (text) => ({
|
|
|
2795
4171
|
details: void 0
|
|
2796
4172
|
});
|
|
2797
4173
|
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
4174
|
+
const agentDir = () => process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
4175
|
+
const globalSettingsPath = () => join(agentDir(), "settings.json");
|
|
4176
|
+
const sleepSync = (milliseconds) => {
|
|
4177
|
+
const end = Date.now() + milliseconds;
|
|
4178
|
+
while (Date.now() < end);
|
|
4179
|
+
};
|
|
4180
|
+
const acquireSettingsLock = (lockPath) => {
|
|
4181
|
+
const maxAttempts = 100;
|
|
4182
|
+
const delayMs = 20;
|
|
4183
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) try {
|
|
4184
|
+
return import_proper_lockfile.default.lockSync(lockPath, { realpath: false });
|
|
4185
|
+
} catch (error) {
|
|
4186
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) !== "ELOCKED" || attempt === maxAttempts) throw error;
|
|
4187
|
+
sleepSync(delayMs);
|
|
4188
|
+
}
|
|
4189
|
+
throw new Error(`Failed to acquire settings lock: ${lockPath}`);
|
|
4190
|
+
};
|
|
4191
|
+
const withSettingsLock = (settingsPath, fn) => {
|
|
4192
|
+
mkdirSync(join(settingsPath, ".."), { recursive: true });
|
|
4193
|
+
const lockPath = `${settingsPath}.adaptive-thinking`;
|
|
4194
|
+
if (!existsSync(lockPath)) writeFileSync(lockPath, "");
|
|
4195
|
+
const release = acquireSettingsLock(lockPath);
|
|
4196
|
+
try {
|
|
4197
|
+
return fn();
|
|
4198
|
+
} finally {
|
|
4199
|
+
release();
|
|
4200
|
+
}
|
|
4201
|
+
};
|
|
4202
|
+
const readDefaultThinkingLevel = (settingsPath) => {
|
|
4203
|
+
if (!existsSync(settingsPath)) return void 0;
|
|
4204
|
+
try {
|
|
4205
|
+
const parsed = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
4206
|
+
return typeof parsed.defaultThinkingLevel === "string" && isThinkingLevel(parsed.defaultThinkingLevel) ? parsed.defaultThinkingLevel : void 0;
|
|
4207
|
+
} catch {
|
|
4208
|
+
return;
|
|
4209
|
+
}
|
|
4210
|
+
};
|
|
4211
|
+
const restoreDefaultThinkingLevel = (settingsPath, previousDefaultThinkingLevel) => {
|
|
4212
|
+
if (!existsSync(settingsPath)) return;
|
|
4213
|
+
try {
|
|
4214
|
+
const settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
4215
|
+
if (previousDefaultThinkingLevel === void 0) delete settings.defaultThinkingLevel;
|
|
4216
|
+
else settings.defaultThinkingLevel = previousDefaultThinkingLevel;
|
|
4217
|
+
writeFileSync(settingsPath, JSON.stringify(settings, void 0, 2) + "\n");
|
|
4218
|
+
} catch {
|
|
4219
|
+
return;
|
|
4220
|
+
}
|
|
4221
|
+
};
|
|
4222
|
+
const withSessionOnlyThinkingLevelChange = (changeThinkingLevel) => {
|
|
4223
|
+
const settingsPath = globalSettingsPath();
|
|
4224
|
+
return withSettingsLock(settingsPath, () => {
|
|
4225
|
+
const previousDefaultThinkingLevel = readDefaultThinkingLevel(settingsPath);
|
|
4226
|
+
changeThinkingLevel();
|
|
4227
|
+
restoreDefaultThinkingLevel(settingsPath, previousDefaultThinkingLevel);
|
|
4228
|
+
});
|
|
4229
|
+
};
|
|
2798
4230
|
const notify = (ctx, type, message, config) => {
|
|
2799
4231
|
if (config?.quiet) return;
|
|
2800
4232
|
if (!ctx.hasUI) return;
|
|
@@ -2807,7 +4239,7 @@ const appendSystemPromptBlock = (systemPrompt, block) => {
|
|
|
2807
4239
|
return `${systemPrompt.trimEnd()}\n\n${trimmedBlock}`;
|
|
2808
4240
|
};
|
|
2809
4241
|
const formatGuidance = (config, currentLevel, validLevels) => {
|
|
2810
|
-
return config.systemPrompt.trim() + " " + (currentLevel ? `Current
|
|
4242
|
+
return config.systemPrompt.trim() + " " + (currentLevel ? `Current thinking level: ${currentLevel}. ` : "") + `Valid thinking levels for this session: ${validLevels.join(", ")}. To change the thinking level, use the \`${config.toolName}\` tool with one of the valid levels. Only call it when the task complexity justifies changing levels. Do not call ${config.toolName} if the current thinking level already matches the target level. Do not call ${config.toolName} twice in a row; reassess only after new evidence from other tool calls or user input.`;
|
|
2811
4243
|
};
|
|
2812
4244
|
function adaptiveThinking(pi) {
|
|
2813
4245
|
let runtime;
|
|
@@ -2819,14 +4251,27 @@ function adaptiveThinking(pi) {
|
|
|
2819
4251
|
if (!runtime) return;
|
|
2820
4252
|
runtime.currentLevel = event.level;
|
|
2821
4253
|
});
|
|
4254
|
+
pi.on("tool_call", async (event) => {
|
|
4255
|
+
const state = runtime;
|
|
4256
|
+
if (!state) return;
|
|
4257
|
+
if (event.toolName === state.config.toolName) {
|
|
4258
|
+
state.reasoningToolCallBackToBackById.set(event.toolCallId, state.lastToolCallWasReasoningTool ?? false);
|
|
4259
|
+
state.lastToolCallWasReasoningTool = true;
|
|
4260
|
+
} else state.lastToolCallWasReasoningTool = false;
|
|
4261
|
+
});
|
|
2822
4262
|
pi.on("before_agent_start", async (event, ctx) => beforeAgentStart(event, ctx));
|
|
2823
4263
|
pi.on("agent_end", async (_event, ctx) => {
|
|
2824
4264
|
await resetTemporaryLevel(ctx);
|
|
4265
|
+
if (!runtime) return;
|
|
4266
|
+
runtime.lastToolCallWasReasoningTool = false;
|
|
4267
|
+
runtime.reasoningToolCallBackToBackById.clear();
|
|
2825
4268
|
});
|
|
2826
4269
|
};
|
|
2827
4270
|
const beforeAgentStart = async (event, ctx) => {
|
|
2828
4271
|
const state = runtime;
|
|
2829
4272
|
if (!state) return { systemPrompt: event.systemPrompt };
|
|
4273
|
+
state.lastToolCallWasReasoningTool = false;
|
|
4274
|
+
state.reasoningToolCallBackToBackById.clear();
|
|
2830
4275
|
const currentLevel = state.currentLevel ?? pi.getThinkingLevel();
|
|
2831
4276
|
if (isThinkingLevel(currentLevel)) state.currentLevel = currentLevel;
|
|
2832
4277
|
const validLevels = resolveSupportedThinkingLevels(ctx.model);
|
|
@@ -2837,11 +4282,11 @@ function adaptiveThinking(pi) {
|
|
|
2837
4282
|
const resetLevel = state?.temporaryResetLevel;
|
|
2838
4283
|
if (!state || !resetLevel) return;
|
|
2839
4284
|
try {
|
|
2840
|
-
pi.setThinkingLevel(resetLevel);
|
|
4285
|
+
withSessionOnlyThinkingLevelChange(() => pi.setThinkingLevel(resetLevel));
|
|
2841
4286
|
state.currentLevel = resetLevel;
|
|
2842
4287
|
delete state.temporaryResetLevel;
|
|
2843
4288
|
} catch (error) {
|
|
2844
|
-
notify(ctx, "error", `Failed to reset
|
|
4289
|
+
notify(ctx, "error", `Failed to reset thinking level: ${errorMessage(error)}`, state.config);
|
|
2845
4290
|
}
|
|
2846
4291
|
};
|
|
2847
4292
|
pi.on("session_start", async (_event, ctx) => {
|
|
@@ -2857,28 +4302,33 @@ function adaptiveThinking(pi) {
|
|
|
2857
4302
|
return;
|
|
2858
4303
|
}
|
|
2859
4304
|
const initialLevel = pi.getThinkingLevel();
|
|
2860
|
-
runtime = {
|
|
4305
|
+
runtime = {
|
|
4306
|
+
config,
|
|
4307
|
+
reasoningToolCallBackToBackById: /* @__PURE__ */ new Map()
|
|
4308
|
+
};
|
|
2861
4309
|
if (isThinkingLevel(initialLevel)) runtime.currentLevel = initialLevel;
|
|
2862
4310
|
pi.registerTool({
|
|
2863
4311
|
name: config.toolName,
|
|
2864
|
-
label: "Set
|
|
4312
|
+
label: "Set Thinking Level",
|
|
2865
4313
|
description: config.toolDescription,
|
|
2866
|
-
promptSnippet: "Set the current
|
|
2867
|
-
promptGuidelines: [`Use ${config.toolName} to change
|
|
4314
|
+
promptSnippet: "Set the current Pi thinking level.",
|
|
4315
|
+
promptGuidelines: [`Use ${config.toolName} to change the thinking level when task complexity justifies a different level.`],
|
|
2868
4316
|
parameters: ToolParameters,
|
|
2869
|
-
execute: async (
|
|
4317
|
+
execute: async (toolCallId, params, _signal, _onUpdate, ctx) => {
|
|
2870
4318
|
const state = runtime;
|
|
2871
4319
|
if (!state) return textResult("Adaptive Thinking is not enabled for this session.");
|
|
2872
4320
|
const level = params.level.trim();
|
|
2873
4321
|
const validLevels = resolveSupportedThinkingLevels(ctx.model);
|
|
2874
|
-
if (!isThinkingLevel(level) || !validLevels.includes(level)) return textResult(`Invalid
|
|
4322
|
+
if (!isThinkingLevel(level) || !validLevels.includes(level)) return textResult(`Invalid thinking level: ${level}. Valid levels: ${validLevels.join(", ")}.`);
|
|
2875
4323
|
const persist = params.persist ?? false;
|
|
2876
4324
|
const currentLevel = state.currentLevel ?? pi.getThinkingLevel();
|
|
4325
|
+
if (currentLevel === level) return textResult(`Thinking level is already ${level}; no change made.`);
|
|
4326
|
+
if (state.reasoningToolCallBackToBackById.get(toolCallId) ?? false) return textResult(`Thinking level change skipped because the previous tool call was also ${state.config.toolName}. Reassess after another tool call or new user input.`);
|
|
2877
4327
|
const resetLevel = state.persistedLevel ?? (isThinkingLevel(currentLevel) ? currentLevel : void 0);
|
|
2878
4328
|
try {
|
|
2879
|
-
pi.setThinkingLevel(level);
|
|
4329
|
+
withSessionOnlyThinkingLevelChange(() => pi.setThinkingLevel(level));
|
|
2880
4330
|
} catch (error) {
|
|
2881
|
-
return textResult(`Failed to set
|
|
4331
|
+
return textResult(`Failed to set thinking level: ${errorMessage(error)}`);
|
|
2882
4332
|
}
|
|
2883
4333
|
state.currentLevel = level;
|
|
2884
4334
|
if (persist) {
|
|
@@ -2886,7 +4336,7 @@ function adaptiveThinking(pi) {
|
|
|
2886
4336
|
delete state.temporaryResetLevel;
|
|
2887
4337
|
} else if (resetLevel && resetLevel !== level) state.temporaryResetLevel = resetLevel;
|
|
2888
4338
|
else delete state.temporaryResetLevel;
|
|
2889
|
-
return textResult(`
|
|
4339
|
+
return textResult(`Thinking level set to ${level}`);
|
|
2890
4340
|
}
|
|
2891
4341
|
});
|
|
2892
4342
|
registerRuntimeHandlers();
|