pi-lens 4.5.1 → 4.5.2
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/CHANGELOG-USER.md +6 -6
- package/CHANGELOG.md +121 -0
- package/README.md +9 -2
- package/dist/{chunk-ZVQUYCBU.js → chunk-2ERVW2UF.js} +161 -100
- package/dist/{chunk-AFSG6YUB.js → chunk-2K7BUOKS.js} +13 -13
- package/dist/{chunk-BJGWP4UX.js → chunk-3JJ4OAJI.js} +10 -10
- package/dist/{chunk-GIK6VUCY.js → chunk-3UHGSUVL.js} +1 -1
- package/dist/{chunk-EKQDQPX6.js → chunk-463WN3VP.js} +1 -1
- package/dist/{chunk-F7BFIENK.js → chunk-4X3ML2UQ.js} +29 -32
- package/dist/{chunk-7JMEPY6P.js → chunk-5BI5YP57.js} +10 -10
- package/dist/{chunk-MKW7ZUTT.js → chunk-5Z4XLUFF.js} +3 -3
- package/dist/{chunk-NIZKGBOU.js → chunk-62AJH3IN.js} +12 -14
- package/dist/{chunk-4GLSO2EM.js → chunk-6F34GMP7.js} +12 -12
- package/dist/{chunk-35UJUF27.js → chunk-6LIUVGOR.js} +13 -3
- package/dist/{chunk-WJ7GY5WJ.js → chunk-6REF4GCO.js} +1 -1
- package/dist/{chunk-HFIFEH46.js → chunk-7KRR24GO.js} +3 -3
- package/dist/{chunk-WAK2AXQQ.js → chunk-7OMOMBEQ.js} +9 -9
- package/dist/{chunk-S7KUDW73.js → chunk-7ZFXICNN.js} +15 -15
- package/dist/{chunk-VEF3GFOL.js → chunk-ABKRQVOY.js} +28 -52
- package/dist/{chunk-Y2LIOCA7.js → chunk-ANSLRJBG.js} +1 -1
- package/dist/{chunk-ARTCVE6I.js → chunk-AWMFBPGJ.js} +9 -9
- package/dist/{chunk-H6DNTQ4V.js → chunk-BG7KHGNX.js} +2 -2
- package/dist/{chunk-FD4LJQ6Y.js → chunk-BK2R2223.js} +10 -8
- package/dist/{chunk-TWAQFMLW.js → chunk-BXXC6KRR.js} +31 -34
- package/dist/{chunk-S247BOH2.js → chunk-CKJS2AUI.js} +4 -4
- package/dist/{chunk-GNK2IHVG.js → chunk-COGU5KQJ.js} +15 -15
- package/dist/{chunk-P7EV5ISR.js → chunk-CQNXALZJ.js} +12 -6
- package/dist/{chunk-IO6P3NBP.js → chunk-CSZESDPP.js} +1 -1
- package/dist/chunk-CZ5TCJPB.js +98 -0
- package/dist/{chunk-DLGJYQML.js → chunk-D2LFEA5U.js} +9 -2
- package/dist/chunk-D3KLF5CD.js +50 -0
- package/dist/{chunk-W2JPGW7Q.js → chunk-ENJ2M76Y.js} +20 -20
- package/dist/{chunk-2DWNYVUN.js → chunk-EQKF6BAK.js} +3 -3
- package/dist/{chunk-KIQSNH3F.js → chunk-F2SAP2FM.js} +38 -45
- package/dist/{chunk-BYIEU4E4.js → chunk-F6QAJXQV.js} +2 -2
- package/dist/chunk-GR2QDWH5.js +25 -0
- package/dist/{chunk-T2D2WWP6.js → chunk-GVE5VZYQ.js} +5 -5
- package/dist/{chunk-HMXWZUQW.js → chunk-GWZZOJD2.js} +1 -1
- package/dist/chunk-GZS6VPIE.js +27 -0
- package/dist/chunk-H4B4SC7I.js +71 -0
- package/dist/{chunk-2RQREVGO.js → chunk-HA6TUJOE.js} +1 -1
- package/dist/{chunk-NAACKIKT.js → chunk-HKPJTI47.js} +2 -2
- package/dist/{chunk-NHHS5T52.js → chunk-HPKC55MA.js} +1 -1
- package/dist/{chunk-B2QO7GHY.js → chunk-I65CQLCG.js} +1 -1
- package/dist/{chunk-BQ72NQQM.js → chunk-IDKLWVKY.js} +11 -11
- package/dist/chunk-IUM2Q7NF.js +25 -0
- package/dist/{chunk-PVV27TOX.js → chunk-J24IS3KZ.js} +5 -5
- package/dist/{chunk-DKXIUGNA.js → chunk-J2DAHH4T.js} +2 -2
- package/dist/{chunk-CDAJQBKJ.js → chunk-JBDZVOFL.js} +11 -11
- package/dist/{chunk-T7KHGEJ5.js → chunk-JC6NFC57.js} +3 -3
- package/dist/{chunk-BWGNVM33.js → chunk-JTHEUTW7.js} +11 -11
- package/dist/{chunk-WWZLT6AM.js → chunk-JWW3ODBN.js} +2 -2
- package/dist/{chunk-Q32RJDYC.js → chunk-K3ZIYLHT.js} +4 -4
- package/dist/{chunk-LDPY22FS.js → chunk-KDPZA2UE.js} +2 -3
- package/dist/{chunk-YIEHUKX2.js → chunk-KMY2OU4T.js} +489 -285
- package/dist/{chunk-WH6O4IFD.js → chunk-KQF7VT26.js} +10 -10
- package/dist/{chunk-OG3UCAHV.js → chunk-KVGA7X76.js} +3 -3
- package/dist/{chunk-TABDCX35.js → chunk-KW7O72AK.js} +2 -2
- package/dist/{chunk-AOEVZXR6.js → chunk-LEQTVRSV.js} +9 -9
- package/dist/{chunk-7BWPQZHE.js → chunk-LKPSBM6S.js} +3 -3
- package/dist/{chunk-WA6U2URH.js → chunk-LKW2HFSZ.js} +6 -6
- package/dist/{chunk-M3QGXGY4.js → chunk-LURFD4HD.js} +624 -97
- package/dist/{chunk-2YQ5LI7R.js → chunk-M6ELTECW.js} +4 -4
- package/dist/{chunk-OHTHVILU.js → chunk-MGVVYYKW.js} +12 -12
- package/dist/{chunk-W2YHHNY3.js → chunk-MQBKGRSB.js} +7 -7
- package/dist/{chunk-MET776XM.js → chunk-MVG2ZEAO.js} +6 -6
- package/dist/{chunk-2XALJI2K.js → chunk-MY4XNNTX.js} +39 -41
- package/dist/{chunk-GFCPPCNR.js → chunk-N4AJVFRF.js} +11 -11
- package/dist/{chunk-UARVPNAU.js → chunk-OFKKMXWM.js} +31 -36
- package/dist/{chunk-DHFJS2I4.js → chunk-OFZE4ANN.js} +8 -8
- package/dist/chunk-OLXBUTJR.js +61 -0
- package/dist/{chunk-SJ2SR432.js → chunk-OZGEHOSG.js} +38 -17
- package/dist/{chunk-6MDWNZ7E.js → chunk-PKGOROPQ.js} +40 -2
- package/dist/{chunk-3IWMNN2S.js → chunk-Q6D5QKRG.js} +17 -17
- package/dist/{chunk-JGCBMCCS.js → chunk-QECLJFHI.js} +12 -17
- package/dist/{chunk-KXKM2DFP.js → chunk-QJA33VD5.js} +4 -4
- package/dist/{chunk-YV7XVYSJ.js → chunk-R5XVJ6AN.js} +11 -11
- package/dist/{chunk-62PIU4TO.js → chunk-REZL4OM4.js} +1 -1
- package/dist/{chunk-NNDZ7DOP.js → chunk-RK5RBREN.js} +74 -107
- package/dist/chunk-RP5ZQTHO.js +86 -0
- package/dist/{chunk-HKRESBMC.js → chunk-RURPX2YV.js} +23 -23
- package/dist/chunk-TB5MGZLS.js +53 -0
- package/dist/chunk-TC63XRYP.js +27 -0
- package/dist/chunk-TJOYHAXJ.js +69 -0
- package/dist/{chunk-NZ7NSKIW.js → chunk-TRXKDCBP.js} +13 -13
- package/dist/{chunk-7WAQ3K26.js → chunk-TTK37D7R.js} +22 -23
- package/dist/{chunk-ALTHJUZO.js → chunk-UH3QHLR5.js} +2 -2
- package/dist/{chunk-6MZLS6CK.js → chunk-UNTJJ7GN.js} +7 -7
- package/dist/{chunk-XRLZ75YY.js → chunk-UPAFSETJ.js} +54 -59
- package/dist/{chunk-N2U644ZW.js → chunk-UX75PTQW.js} +50 -17
- package/dist/{chunk-EXHSWN3P.js → chunk-V353PYMK.js} +423 -233
- package/dist/{chunk-SL4G67AP.js → chunk-V4TFQY5G.js} +2 -2
- package/dist/{chunk-YOMLAKU6.js → chunk-VC3W54G3.js} +289 -138
- package/dist/{chunk-KSQJBGRO.js → chunk-VSBCJVPC.js} +5 -5
- package/dist/{chunk-EBXCYEII.js → chunk-WAQQGXVV.js} +3 -3
- package/dist/{chunk-7ORBRDFY.js → chunk-WLEVWR7Y.js} +2 -2
- package/dist/{chunk-Q4UQNTLB.js → chunk-WPMPVP5I.js} +4 -4
- package/dist/{chunk-TQKWR5AZ.js → chunk-WXNLFOC2.js} +7 -7
- package/dist/{chunk-HOWHAKXO.js → chunk-Y3ZNOZZS.js} +6 -6
- package/dist/{chunk-DNJJVKJZ.js → chunk-YL6JQTWC.js} +29 -32
- package/dist/{chunk-HUWW77QY.js → chunk-YVE5Q2UU.js} +86 -217
- package/dist/{chunk-25CAONWT.js → chunk-YZNARDMM.js} +12 -9
- package/dist/{chunk-HERQPNY6.js → chunk-ZDWNFZJ2.js} +8 -8
- package/dist/{chunk-MKQFSW2Q.js → chunk-ZEUF7BIN.js} +2 -2
- package/dist/{chunk-AB26NAHA.js → chunk-ZIF4WLWR.js} +45 -25
- package/dist/{chunk-6MWX2J5H.js → chunk-ZSPVF7KI.js} +227 -24
- package/dist/{chunk-QQGZY2BR.js → chunk-ZX6OKBVO.js} +2 -2
- package/dist/index.js +6455 -5243
- package/dist/mcp/analyze-cli.js +8 -8
- package/dist/mcp/cli.js +39 -41
- package/dist/mcp/server.js +870 -559
- package/dist/mcp/worker.js +68 -59
- package/dist/probes/installer.js +19 -20
- package/docs/configuration.md +24 -10
- package/docs/defect-shapes.md +18 -2
- package/docs/environment-variables.md +18 -9
- package/docs/globalconfig.md +16 -0
- package/docs/invariants/dispatch-runners.md +7 -0
- package/docs/invariants/lsp-trust-exec.md +33 -3
- package/docs/lsp-capability-matrix.md +23 -10
- package/docs/lsp-idle-eviction.md +8 -3
- package/docs/release-qa-baseline.md +22 -17
- package/docs/servercapabilities.md +1 -1
- package/docs/settings.md +9 -2
- package/docs/tools.md +1 -1
- package/package.json +3 -3
- package/dist/chunk-3UTDLQWO.js +0 -88
- package/dist/chunk-3Z7Z3B7V.js +0 -27
- package/dist/chunk-4E4OCW3L.js +0 -38
- package/dist/chunk-5HVDD7IA.js +0 -17
- package/dist/chunk-BKJ6WZKP.js +0 -255
- package/dist/chunk-D3UQWOCB.js +0 -46
- package/dist/chunk-EH6EHFW2.js +0 -73
- package/dist/chunk-J7VNGHLN.js +0 -69
- package/dist/chunk-L3Q72QGQ.js +0 -25
- package/dist/chunk-TFSBHRL2.js +0 -25
- package/dist/chunk-UWBD3JMH.js +0 -56
- package/dist/chunk-XWWFESYZ.js +0 -27
- package/dist/chunk-XZSXSM4K.js +0 -27
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
reportPiLensConfigRecords,
|
|
14
14
|
resolveOnePiLensConfigDocument,
|
|
15
15
|
warnIgnoredConfigOnce
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-UX75PTQW.js";
|
|
17
17
|
import {
|
|
18
18
|
CANONICAL_GLOBAL_CONFIG_FILE,
|
|
19
19
|
FRESHNESS_CADENCE_MS,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
errorClassName,
|
|
24
24
|
getPiLensGlobalConfigPath,
|
|
25
25
|
getProductionGlobalConfigResolution
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-D2LFEA5U.js";
|
|
27
27
|
import {
|
|
28
28
|
DEFAULT_MAX_OUTPUT_BYTES,
|
|
29
29
|
createBoundedOutputSink,
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
truncatedByOutputCap,
|
|
32
32
|
writeFileAtomic,
|
|
33
33
|
writeFileAtomicAsync
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-463WN3VP.js";
|
|
35
35
|
import {
|
|
36
36
|
GLOBAL_NON_FLAG_CONFIG_SECTIONS,
|
|
37
37
|
LENS_FLAGS,
|
|
@@ -50,13 +50,13 @@ import {
|
|
|
50
50
|
recordDegradationOnce,
|
|
51
51
|
spawnAbortScope,
|
|
52
52
|
spawnCooldownScope
|
|
53
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-CQNXALZJ.js";
|
|
54
54
|
import {
|
|
55
55
|
getProcessSingleton,
|
|
56
56
|
isToolInstallDisabled,
|
|
57
57
|
logLatency,
|
|
58
58
|
machineStateDir
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-YVE5Q2UU.js";
|
|
60
60
|
import {
|
|
61
61
|
STAGE_TMP_PATTERN,
|
|
62
62
|
stagePathFor,
|
|
@@ -64,7 +64,6 @@ import {
|
|
|
64
64
|
} from "./chunk-LJDODBBZ.js";
|
|
65
65
|
import {
|
|
66
66
|
BoundedFifoMap,
|
|
67
|
-
BoundedSet,
|
|
68
67
|
Minimatch,
|
|
69
68
|
homeRelativePath,
|
|
70
69
|
isAtOrAboveHomeDir,
|
|
@@ -86,7 +85,7 @@ import {
|
|
|
86
85
|
toPosix,
|
|
87
86
|
toProjectRelativePath,
|
|
88
87
|
walkUpDirs
|
|
89
|
-
} from "./chunk-
|
|
88
|
+
} from "./chunk-ZSPVF7KI.js";
|
|
90
89
|
import {
|
|
91
90
|
__commonJS,
|
|
92
91
|
__require,
|
|
@@ -426,7 +425,7 @@ var require_cpu = __commonJS({
|
|
|
426
425
|
var require_procfile = __commonJS({
|
|
427
426
|
"node_modules/pidusage/lib/procfile.js"(exports, module) {
|
|
428
427
|
var fs10 = __require("fs");
|
|
429
|
-
var
|
|
428
|
+
var path14 = __require("path");
|
|
430
429
|
var updateCpu = require_cpu();
|
|
431
430
|
var parallel = require_parallel();
|
|
432
431
|
var history = require_history();
|
|
@@ -434,11 +433,11 @@ var require_procfile = __commonJS({
|
|
|
434
433
|
var SIZE = 1024;
|
|
435
434
|
function noop() {
|
|
436
435
|
}
|
|
437
|
-
function open(
|
|
436
|
+
function open(path15, history2, cb) {
|
|
438
437
|
if (history2.fd) {
|
|
439
438
|
return cb(null, history2.fd);
|
|
440
439
|
}
|
|
441
|
-
fs10.open(
|
|
440
|
+
fs10.open(path15, "r", cb);
|
|
442
441
|
}
|
|
443
442
|
function close(history2) {
|
|
444
443
|
if (history2.fd) {
|
|
@@ -472,7 +471,7 @@ var require_procfile = __commonJS({
|
|
|
472
471
|
again = true;
|
|
473
472
|
hst = {};
|
|
474
473
|
}
|
|
475
|
-
open(
|
|
474
|
+
open(path14.join("/proc", "" + pid, "stat"), hst, function(err, fd) {
|
|
476
475
|
if (err) {
|
|
477
476
|
if (err.code === "ENOENT") {
|
|
478
477
|
err.message = "No matching pid found";
|
|
@@ -737,7 +736,7 @@ var require_stats = __commonJS({
|
|
|
737
736
|
"use strict";
|
|
738
737
|
var fs10 = __require("fs");
|
|
739
738
|
var os4 = __require("os");
|
|
740
|
-
var
|
|
739
|
+
var path14 = __require("path");
|
|
741
740
|
var requireMap = {
|
|
742
741
|
ps: () => require_ps(),
|
|
743
742
|
procfile: () => require_procfile(),
|
|
@@ -773,7 +772,7 @@ var require_stats = __commonJS({
|
|
|
773
772
|
var wmicAvailable;
|
|
774
773
|
function hasWmic() {
|
|
775
774
|
if (wmicAvailable === void 0) {
|
|
776
|
-
wmicAvailable = fs10.existsSync(
|
|
775
|
+
wmicAvailable = fs10.existsSync(path14.join(process.env.SystemRoot || "C:\\Windows", "System32", "wbem", "WMIC.exe"));
|
|
777
776
|
}
|
|
778
777
|
return wmicAvailable;
|
|
779
778
|
}
|
|
@@ -838,10 +837,10 @@ var require_pidusage = __commonJS({
|
|
|
838
837
|
stats(pids, options, callback);
|
|
839
838
|
return;
|
|
840
839
|
}
|
|
841
|
-
return new Promise(function(
|
|
840
|
+
return new Promise(function(resolve8, reject) {
|
|
842
841
|
stats(pids, options, function(err, data) {
|
|
843
842
|
if (err) return reject(err);
|
|
844
|
-
|
|
843
|
+
resolve8(data);
|
|
845
844
|
});
|
|
846
845
|
});
|
|
847
846
|
}
|
|
@@ -852,12 +851,9 @@ var require_pidusage = __commonJS({
|
|
|
852
851
|
|
|
853
852
|
// dist/clients/spawn-timeout-cooldown.js
|
|
854
853
|
import path from "node:path";
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (!_global[COOLDOWN_STATE_KEY]) {
|
|
858
|
-
_global[COOLDOWN_STATE_KEY] = { timedOutByCommand: /* @__PURE__ */ new Map() };
|
|
854
|
+
function cooldowns() {
|
|
855
|
+
return getProcessSingleton("spawn-timeout-cooldown", 1, () => ({ timedOutByCommand: /* @__PURE__ */ new Map() })).timedOutByCommand;
|
|
859
856
|
}
|
|
860
|
-
var timedOutByCommand = _global[COOLDOWN_STATE_KEY].timedOutByCommand;
|
|
861
857
|
function wrapperKindOf(command) {
|
|
862
858
|
const ext = path.extname(command);
|
|
863
859
|
return ext ? ext.slice(1) : "bare";
|
|
@@ -867,7 +863,7 @@ function cooldownKey(command) {
|
|
|
867
863
|
}
|
|
868
864
|
function noteSpawnTimeout(input) {
|
|
869
865
|
const key = cooldownKey(input.subject ?? input.command);
|
|
870
|
-
|
|
866
|
+
cooldowns().set(key, {
|
|
871
867
|
tool: input.tool,
|
|
872
868
|
command: input.command,
|
|
873
869
|
phase: input.phase,
|
|
@@ -896,10 +892,10 @@ function noteSpawnTimeout(input) {
|
|
|
896
892
|
});
|
|
897
893
|
}
|
|
898
894
|
function isInSpawnTimeoutCooldown(command) {
|
|
899
|
-
return
|
|
895
|
+
return cooldowns().has(cooldownKey(command));
|
|
900
896
|
}
|
|
901
897
|
function resetSpawnTimeoutCooldowns() {
|
|
902
|
-
|
|
898
|
+
cooldowns().clear();
|
|
903
899
|
}
|
|
904
900
|
|
|
905
901
|
// dist/clients/review-graph/git-identity.js
|
|
@@ -1069,6 +1065,7 @@ function resolveGitIdentity(cwd) {
|
|
|
1069
1065
|
}
|
|
1070
1066
|
|
|
1071
1067
|
// dist/clients/session-repository.js
|
|
1068
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1072
1069
|
import * as fs2 from "node:fs";
|
|
1073
1070
|
import * as os from "node:os";
|
|
1074
1071
|
import * as path3 from "node:path";
|
|
@@ -1148,6 +1145,40 @@ function hasGitEntry(dir) {
|
|
|
1148
1145
|
function pathForm(real) {
|
|
1149
1146
|
return process.platform === "win32" ? normalizeEphemeralMapKey(real) : real;
|
|
1150
1147
|
}
|
|
1148
|
+
function projectSearchJudge(root) {
|
|
1149
|
+
const binDirs = [...projectLocalBinDirs(root)];
|
|
1150
|
+
const spellings = [root, ...binDirs].map(normalizePathSpelling);
|
|
1151
|
+
let identities;
|
|
1152
|
+
return (entry) => {
|
|
1153
|
+
if (entry === "")
|
|
1154
|
+
return process.platform !== "win32";
|
|
1155
|
+
if (!path3.isAbsolute(entry))
|
|
1156
|
+
return true;
|
|
1157
|
+
const spelled = normalizePathSpelling(entry);
|
|
1158
|
+
if (spellings.some((dir) => isWithinForm(spelled, dir)))
|
|
1159
|
+
return true;
|
|
1160
|
+
if (process.platform === "win32")
|
|
1161
|
+
return false;
|
|
1162
|
+
identities ??= [
|
|
1163
|
+
root,
|
|
1164
|
+
...binDirs.flatMap((dir) => fs2.existsSync(dir) ? [dir] : [])
|
|
1165
|
+
].map(normalizeFilePath);
|
|
1166
|
+
const real = normalizeFilePath(entry);
|
|
1167
|
+
return identities.some((dir) => isWithinForm(real, dir));
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
var unadmittedRootSpawns;
|
|
1171
|
+
function withUnadmittedRootSpawns(root, run) {
|
|
1172
|
+
unadmittedRootSpawns ??= new AsyncLocalStorage();
|
|
1173
|
+
return unadmittedRootSpawns.run(root, run);
|
|
1174
|
+
}
|
|
1175
|
+
function unadmittedSpawnRoot() {
|
|
1176
|
+
return unadmittedRootSpawns?.getStore();
|
|
1177
|
+
}
|
|
1178
|
+
function inUnadmittedSpawnRoot(resolved) {
|
|
1179
|
+
const root = unadmittedRootSpawns?.getStore();
|
|
1180
|
+
return root !== void 0 && projectSearchJudge(root)(path3.dirname(realpathOrResolve(resolved)));
|
|
1181
|
+
}
|
|
1151
1182
|
function isSessionRepositoryPath(target) {
|
|
1152
1183
|
return sessionRepositoryJudge()(target);
|
|
1153
1184
|
}
|
|
@@ -1174,7 +1205,7 @@ function recordProjectCommandRefusal(resolvedCommand) {
|
|
|
1174
1205
|
}
|
|
1175
1206
|
function admittedLookupAnswer(stdout) {
|
|
1176
1207
|
const answer = stdout.trim().split(/\r?\n/)[0] || null;
|
|
1177
|
-
if (answer === null || !isUntrustedProjectPath(answer))
|
|
1208
|
+
if (answer === null || !(isUntrustedProjectPath(answer) || inUnadmittedSpawnRoot(answer)))
|
|
1178
1209
|
return answer;
|
|
1179
1210
|
recordProjectCommandRefusal(answer);
|
|
1180
1211
|
return null;
|
|
@@ -1464,7 +1495,7 @@ function unrefChildAndPipes(child) {
|
|
|
1464
1495
|
}
|
|
1465
1496
|
}
|
|
1466
1497
|
function spawnCollectStdoutResult(command, args, options, collectOptions = {}) {
|
|
1467
|
-
return new Promise((
|
|
1498
|
+
return new Promise((resolve8) => {
|
|
1468
1499
|
let settled = false;
|
|
1469
1500
|
let timer;
|
|
1470
1501
|
const settle = (result) => {
|
|
@@ -1473,7 +1504,7 @@ function spawnCollectStdoutResult(command, args, options, collectOptions = {}) {
|
|
|
1473
1504
|
settled = true;
|
|
1474
1505
|
if (timer)
|
|
1475
1506
|
clearTimeout(timer);
|
|
1476
|
-
|
|
1507
|
+
resolve8(result);
|
|
1477
1508
|
};
|
|
1478
1509
|
try {
|
|
1479
1510
|
const child = nodeSpawn(command, args, options);
|
|
@@ -1588,23 +1619,28 @@ function ownProcessStart(options) {
|
|
|
1588
1619
|
return Promise.resolve(readLinuxProcessStart(process.pid));
|
|
1589
1620
|
if (ownStart)
|
|
1590
1621
|
return ownStart.promise;
|
|
1591
|
-
const
|
|
1622
|
+
const cell2 = {
|
|
1592
1623
|
promise: readProcessStart(process.pid, options).then((start) => {
|
|
1593
1624
|
if (start === void 0)
|
|
1594
1625
|
ownStart = null;
|
|
1595
1626
|
else
|
|
1596
|
-
|
|
1627
|
+
cell2.value = start;
|
|
1597
1628
|
return start;
|
|
1598
1629
|
})
|
|
1599
1630
|
};
|
|
1600
|
-
ownStart =
|
|
1601
|
-
return
|
|
1631
|
+
ownStart = cell2;
|
|
1632
|
+
return cell2.promise;
|
|
1602
1633
|
}
|
|
1603
1634
|
async function readProcessStart(pid, options) {
|
|
1604
1635
|
if (process.platform === "linux")
|
|
1605
1636
|
return readLinuxProcessStart(pid);
|
|
1606
1637
|
return (await queryProcessIdentities([pid], options)).identities.get(pid)?.start;
|
|
1607
1638
|
}
|
|
1639
|
+
function ownProcessStartIfKnown() {
|
|
1640
|
+
if (process.platform === "linux")
|
|
1641
|
+
return readLinuxProcessStart(process.pid);
|
|
1642
|
+
return ownStart?.value;
|
|
1643
|
+
}
|
|
1608
1644
|
|
|
1609
1645
|
// dist/clients/pid-liveness.js
|
|
1610
1646
|
function realIsPidAlive(pid) {
|
|
@@ -1859,13 +1895,13 @@ function makeHandle(sourceName, generation, read, tallyName) {
|
|
|
1859
1895
|
function createGenerationSource(name, store) {
|
|
1860
1896
|
declare(name);
|
|
1861
1897
|
const local = { generation: 0 };
|
|
1862
|
-
const
|
|
1863
|
-
const read = () =>
|
|
1898
|
+
const cell2 = store ?? (() => local);
|
|
1899
|
+
const read = () => cell2().generation;
|
|
1864
1900
|
return {
|
|
1865
1901
|
name,
|
|
1866
1902
|
current: read,
|
|
1867
1903
|
bump() {
|
|
1868
|
-
const held =
|
|
1904
|
+
const held = cell2();
|
|
1869
1905
|
held.generation += 1;
|
|
1870
1906
|
return held.generation;
|
|
1871
1907
|
},
|
|
@@ -1925,6 +1961,7 @@ function createGenerationMap(name, options = {}) {
|
|
|
1925
1961
|
|
|
1926
1962
|
// dist/clients/instance-reaper.js
|
|
1927
1963
|
import { spawn as nodeSpawn2 } from "node:child_process";
|
|
1964
|
+
import * as path13 from "node:path";
|
|
1928
1965
|
|
|
1929
1966
|
// dist/clients/bounded-pid-file-lock.js
|
|
1930
1967
|
import { randomUUID } from "node:crypto";
|
|
@@ -1963,7 +2000,7 @@ async function releaseQuarantineLock(lockPath, token) {
|
|
|
1963
2000
|
} catch (error) {
|
|
1964
2001
|
if (error.code !== "ENOENT" || attempt === 2)
|
|
1965
2002
|
return;
|
|
1966
|
-
await new Promise((
|
|
2003
|
+
await new Promise((resolve8) => setImmediate(resolve8));
|
|
1967
2004
|
}
|
|
1968
2005
|
}
|
|
1969
2006
|
if (!renamed)
|
|
@@ -2090,7 +2127,7 @@ async function acquireQuarantinePidFileLock(lockPath, options) {
|
|
|
2090
2127
|
}
|
|
2091
2128
|
throw new Error(options.timeoutMessage);
|
|
2092
2129
|
}
|
|
2093
|
-
await new Promise((
|
|
2130
|
+
await new Promise((resolve8) => setTimeout(resolve8, Math.min(options.retryMs, remaining)));
|
|
2094
2131
|
}
|
|
2095
2132
|
}
|
|
2096
2133
|
function createLegacyBoundedLock(lockPath, token) {
|
|
@@ -2207,6 +2244,21 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
2207
2244
|
import * as fs6 from "node:fs";
|
|
2208
2245
|
import * as path7 from "node:path";
|
|
2209
2246
|
|
|
2247
|
+
// dist/clients/held-children.js
|
|
2248
|
+
var FAMILY = "held-children.ledger";
|
|
2249
|
+
var VERSION = 1;
|
|
2250
|
+
function cell() {
|
|
2251
|
+
return getProcessSingleton(FAMILY, VERSION, () => ({
|
|
2252
|
+
ledger: void 0
|
|
2253
|
+
}));
|
|
2254
|
+
}
|
|
2255
|
+
function provideHeldChildrenLedger(ledger) {
|
|
2256
|
+
cell().ledger = ledger;
|
|
2257
|
+
}
|
|
2258
|
+
function endHeldChildren() {
|
|
2259
|
+
return cell().ledger?.end() ?? true;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2210
2262
|
// dist/clients/resource-sampler.js
|
|
2211
2263
|
var import_pidusage = __toESM(require_pidusage(), 1);
|
|
2212
2264
|
var RESOURCE_SAMPLE_QUERY_TIMEOUT_MS = 2e3;
|
|
@@ -2436,9 +2488,9 @@ async function sampleProcessTreeCpuPercent(pid, windowMs = 1200, floorPercent =
|
|
|
2436
2488
|
}
|
|
2437
2489
|
};
|
|
2438
2490
|
const first = await readOnce();
|
|
2439
|
-
const second = await new Promise((
|
|
2491
|
+
const second = await new Promise((resolve8) => {
|
|
2440
2492
|
const timer = setTimeout(() => {
|
|
2441
|
-
void readOnce().then(
|
|
2493
|
+
void readOnce().then(resolve8);
|
|
2442
2494
|
}, windowMs);
|
|
2443
2495
|
timer.unref?.();
|
|
2444
2496
|
});
|
|
@@ -2677,12 +2729,9 @@ function classifySpawnFailureSync(error, options) {
|
|
|
2677
2729
|
const cwdUnresolvable = needsCwdProbe && cwdIsUnresolvableSync(options.cwd);
|
|
2678
2730
|
return classifyWithCwdFlag(cause, options, cwdUnresolvable);
|
|
2679
2731
|
}
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
pids: /* @__PURE__ */ new Set(),
|
|
2684
|
-
installed: false
|
|
2685
|
-
});
|
|
2732
|
+
function lifetimeState() {
|
|
2733
|
+
return getProcessSingleton("safe-spawn-lifetime", 1, () => ({ pids: /* @__PURE__ */ new Set(), installed: false }));
|
|
2734
|
+
}
|
|
2686
2735
|
var PROC_PPID_READABLE = (() => {
|
|
2687
2736
|
if (process.platform !== "linux")
|
|
2688
2737
|
return false;
|
|
@@ -2695,7 +2744,11 @@ var PROC_PPID_READABLE = (() => {
|
|
|
2695
2744
|
var VERIFIED_OWN_PID_CAP = 512;
|
|
2696
2745
|
var verifiedOwnPids = new BoundedFifoMap(VERIFIED_OWN_PID_CAP);
|
|
2697
2746
|
var HELD_OWN_PID_SWEEP_AT = 256;
|
|
2698
|
-
|
|
2747
|
+
function heldChildren() {
|
|
2748
|
+
const state = lifetimeState();
|
|
2749
|
+
state.held ??= new BoundedFifoMap(HELD_OWN_PID_SWEEP_AT);
|
|
2750
|
+
return state.held;
|
|
2751
|
+
}
|
|
2699
2752
|
function groupIsGone(pid) {
|
|
2700
2753
|
try {
|
|
2701
2754
|
process.kill(-pid, 0);
|
|
@@ -2705,20 +2758,22 @@ function groupIsGone(pid) {
|
|
|
2705
2758
|
}
|
|
2706
2759
|
}
|
|
2707
2760
|
function sweepHeldOwnPids() {
|
|
2708
|
-
|
|
2761
|
+
const held = heldChildren();
|
|
2762
|
+
if (held.size < HELD_OWN_PID_SWEEP_AT)
|
|
2709
2763
|
return;
|
|
2710
|
-
for (const pid of
|
|
2764
|
+
for (const pid of held.keys()) {
|
|
2711
2765
|
if (groupIsGone(pid))
|
|
2712
|
-
|
|
2766
|
+
held.delete(pid);
|
|
2713
2767
|
}
|
|
2714
2768
|
}
|
|
2715
|
-
function holdOwnChildPid(
|
|
2769
|
+
function holdOwnChildPid(child, site) {
|
|
2770
|
+
const pid = child.pid;
|
|
2716
2771
|
const owned = isOwnLiveChild(pid, site);
|
|
2717
|
-
if (!owned ||
|
|
2772
|
+
if (!owned || process.platform === "win32" || typeof pid !== "number")
|
|
2718
2773
|
return owned;
|
|
2719
2774
|
verifiedOwnPids.delete(pid);
|
|
2720
2775
|
sweepHeldOwnPids();
|
|
2721
|
-
const evicted =
|
|
2776
|
+
const evicted = heldChildren().set(pid, child).map(([dropped]) => dropped);
|
|
2722
2777
|
if (evicted.length > 0) {
|
|
2723
2778
|
incrementDegradationCount({
|
|
2724
2779
|
kind: "held-own-pid-evicted",
|
|
@@ -2727,12 +2782,55 @@ function holdOwnChildPid(pid, site) {
|
|
|
2727
2782
|
metadata: { evicted: evicted.length }
|
|
2728
2783
|
});
|
|
2729
2784
|
}
|
|
2785
|
+
installLifetimeCleanup();
|
|
2730
2786
|
return true;
|
|
2731
2787
|
}
|
|
2732
2788
|
function releaseOwnChildPid(pid) {
|
|
2733
|
-
if (typeof pid
|
|
2734
|
-
|
|
2789
|
+
if (typeof pid !== "number")
|
|
2790
|
+
return;
|
|
2791
|
+
const held = heldChildren();
|
|
2792
|
+
const child = held.get(pid);
|
|
2793
|
+
if (child === void 0)
|
|
2794
|
+
return;
|
|
2795
|
+
if (!groupIsGone(pid)) {
|
|
2796
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
2797
|
+
incrementDegradationCount({
|
|
2798
|
+
kind: "held-group-outlived-leader",
|
|
2799
|
+
subject: "lsp-shutdown",
|
|
2800
|
+
reason: `process group ${pid} outlived its leader's exit at shutdown`
|
|
2801
|
+
});
|
|
2802
|
+
if (!endHeldGroup(pid, child, "lsp-shutdown"))
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
held.delete(pid);
|
|
2806
|
+
}
|
|
2807
|
+
function endHeldChildren2() {
|
|
2808
|
+
const held = heldChildren();
|
|
2809
|
+
let allEnded = true;
|
|
2810
|
+
for (const [pid, child] of held.entriesArray()) {
|
|
2811
|
+
if (endHeldGroup(pid, child, "lsp-host-exit"))
|
|
2812
|
+
held.delete(pid);
|
|
2813
|
+
else
|
|
2814
|
+
allEnded = false;
|
|
2815
|
+
}
|
|
2816
|
+
return allEnded;
|
|
2817
|
+
}
|
|
2818
|
+
function endHeldGroup(pid, child, site) {
|
|
2819
|
+
if (groupIsGone(pid))
|
|
2820
|
+
return true;
|
|
2821
|
+
if (!isOwnLiveChild(pid, site, child))
|
|
2822
|
+
return false;
|
|
2823
|
+
try {
|
|
2824
|
+
process.kill(-pid, "SIGKILL");
|
|
2825
|
+
return true;
|
|
2826
|
+
} catch (cause) {
|
|
2827
|
+
return errorCode(cause) === "ESRCH";
|
|
2828
|
+
}
|
|
2735
2829
|
}
|
|
2830
|
+
provideHeldChildrenLedger({
|
|
2831
|
+
holds: () => heldChildren().size > 0,
|
|
2832
|
+
end: endHeldChildren2
|
|
2833
|
+
});
|
|
2736
2834
|
function recordProcUnavailable(site) {
|
|
2737
2835
|
if (process.platform !== "linux")
|
|
2738
2836
|
return;
|
|
@@ -2755,13 +2853,13 @@ function isOwnLiveChild(pid, site, handle) {
|
|
|
2755
2853
|
try {
|
|
2756
2854
|
status = fs6.readFileSync(`/proc/${pid}/status`, "utf8");
|
|
2757
2855
|
} catch {
|
|
2758
|
-
return
|
|
2856
|
+
return heldChildren().has(pid) || verifiedOwnPids.has(pid);
|
|
2759
2857
|
}
|
|
2760
2858
|
const parent = /^PPid:\s*(\d+)$/m.exec(status);
|
|
2761
2859
|
if (!parent)
|
|
2762
2860
|
return true;
|
|
2763
2861
|
if (Number(parent[1]) === process.pid) {
|
|
2764
|
-
if (!
|
|
2862
|
+
if (!heldChildren().has(pid))
|
|
2765
2863
|
verifiedOwnPids.set(pid, true);
|
|
2766
2864
|
return true;
|
|
2767
2865
|
}
|
|
@@ -2795,17 +2893,19 @@ function killPidTreeSync(pid) {
|
|
|
2795
2893
|
}
|
|
2796
2894
|
}
|
|
2797
2895
|
function installLifetimeCleanup() {
|
|
2798
|
-
if (lifetimeState.installed)
|
|
2896
|
+
if (lifetimeState().installed)
|
|
2799
2897
|
return;
|
|
2800
|
-
lifetimeState.installed = true;
|
|
2898
|
+
lifetimeState().installed = true;
|
|
2801
2899
|
process.once("exit", () => {
|
|
2802
|
-
for (const pid of lifetimeState.pids)
|
|
2900
|
+
for (const pid of lifetimeState().pids)
|
|
2803
2901
|
killPidTreeSync(pid);
|
|
2902
|
+
endHeldChildren2();
|
|
2804
2903
|
});
|
|
2805
2904
|
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
2806
2905
|
process.once(signal, () => {
|
|
2807
|
-
for (const pid of lifetimeState.pids)
|
|
2906
|
+
for (const pid of lifetimeState().pids)
|
|
2808
2907
|
killPidTreeSync(pid);
|
|
2908
|
+
endHeldChildren2();
|
|
2809
2909
|
if (process.platform === "win32" && signal === "SIGHUP") {
|
|
2810
2910
|
recordDegradationOnce({
|
|
2811
2911
|
kind: "safe-spawn-signal-reraise-unsupported",
|
|
@@ -3092,43 +3192,45 @@ function posixSearchPathEntryDir(entry, cwd) {
|
|
|
3092
3192
|
return cwd;
|
|
3093
3193
|
return path7.isAbsolute(entry) ? entry : `${cwd}${path7.sep}${entry}`;
|
|
3094
3194
|
}
|
|
3095
|
-
function trustScopedSearchPath(pathValue, cwd = process.cwd(), env = process.env) {
|
|
3195
|
+
function trustScopedSearchPath(pathValue, cwd = process.cwd(), env = process.env, rootEntry) {
|
|
3096
3196
|
if (pathValue === void 0)
|
|
3097
3197
|
return void 0;
|
|
3098
3198
|
const trust = getProjectTrustState();
|
|
3099
|
-
if (trust === "trusted")
|
|
3199
|
+
if (trust === "trusted" && rootEntry === void 0)
|
|
3100
3200
|
return pathValue;
|
|
3101
|
-
const owned = sessionRepositoryJudge();
|
|
3201
|
+
const owned = trust === "trusted" ? () => false : sessionRepositoryJudge();
|
|
3102
3202
|
const kept = [];
|
|
3103
3203
|
for (const entry of pathValue.split(path7.delimiter)) {
|
|
3104
3204
|
const dir = searchPathEntryDir(entry, cwd, env);
|
|
3105
|
-
|
|
3205
|
+
const bySession = dir !== void 0 && owned(dir);
|
|
3206
|
+
const byRoot = !bySession && rootEntry?.(entry) === true;
|
|
3207
|
+
if (!bySession && !byRoot) {
|
|
3106
3208
|
kept.push(entry);
|
|
3107
3209
|
continue;
|
|
3108
3210
|
}
|
|
3109
|
-
const real = realpathOrResolve(dir);
|
|
3211
|
+
const real = realpathOrResolve(dir ?? path7.resolve(cwd, entry));
|
|
3110
3212
|
if (recordDegradationOnce({
|
|
3111
3213
|
kind: "trust-refusal",
|
|
3112
3214
|
subject: `project-path-entry:${real}`,
|
|
3113
|
-
reason: `search-path entry inside the project ignored: pi project trust is ${trust}`
|
|
3215
|
+
reason: byRoot ? `search-path entry inside an LSP root not admitted for project code ignored: pi project trust is ${trust}` : `search-path entry inside the project ignored: pi project trust is ${trust}`
|
|
3114
3216
|
})) {
|
|
3115
3217
|
logExtension({
|
|
3116
3218
|
subsystem: "project-trust",
|
|
3117
3219
|
level: "warn",
|
|
3118
|
-
message: "search-path entry inside the project ignored: mark the project trusted in pi or upgrade pi",
|
|
3220
|
+
message: trust === "trusted" ? "search-path entry inside an LSP root not admitted for project code ignored" : "search-path entry inside the project ignored: mark the project trusted in pi or upgrade pi",
|
|
3119
3221
|
metadata: { entry, dir: real, trust }
|
|
3120
3222
|
});
|
|
3121
3223
|
}
|
|
3122
3224
|
}
|
|
3123
3225
|
return kept.length > 0 ? kept.join(path7.delimiter) : void 0;
|
|
3124
3226
|
}
|
|
3125
|
-
function trustScopedEnvironment(env, cwd = process.cwd()) {
|
|
3227
|
+
function trustScopedEnvironment(env, cwd = process.cwd(), rootEntry) {
|
|
3126
3228
|
const keys = process.platform === "win32" ? windowsEnvironmentKeys(env, "PATH") : ["PATH"];
|
|
3127
3229
|
const lastKey = keys.at(-1);
|
|
3128
3230
|
if (lastKey === void 0)
|
|
3129
3231
|
return env;
|
|
3130
3232
|
const value = env[lastKey];
|
|
3131
|
-
const scoped = trustScopedSearchPath(value, cwd, env);
|
|
3233
|
+
const scoped = trustScopedSearchPath(value, cwd, env, rootEntry);
|
|
3132
3234
|
if (scoped === value)
|
|
3133
3235
|
return env;
|
|
3134
3236
|
const next = { ...env };
|
|
@@ -3157,14 +3259,15 @@ function resolveSearchPathCommand(command, pathValue, cwd) {
|
|
|
3157
3259
|
return void 0;
|
|
3158
3260
|
}
|
|
3159
3261
|
function admitSpawn(command, cwd, env) {
|
|
3160
|
-
|
|
3262
|
+
const trusted = getProjectTrustState() === "trusted";
|
|
3263
|
+
if (trusted && unadmittedSpawnRoot() === void 0)
|
|
3161
3264
|
return { admitted: true, env };
|
|
3162
3265
|
const childCwd = cwd ?? process.cwd();
|
|
3163
3266
|
const scoped = trustScopedEnvironment(env, childCwd);
|
|
3164
3267
|
if (!isSpawnLookup(command))
|
|
3165
3268
|
return { admitted: true, env: scoped };
|
|
3166
3269
|
const executable = process.platform === "win32" ? resolveWindowsCommandForEnvironment(command, cwd, scoped)?.resolvedPath : resolveSearchPathCommand(command, scoped.PATH, childCwd);
|
|
3167
|
-
if (executable === void 0 || !isSessionRepositoryPath(executable))
|
|
3270
|
+
if (executable === void 0 || !(!trusted && isSessionRepositoryPath(executable) || inUnadmittedSpawnRoot(executable)))
|
|
3168
3271
|
return { admitted: true, env: scoped };
|
|
3169
3272
|
recordProjectCommandRefusal(executable);
|
|
3170
3273
|
return { admitted: false, executable };
|
|
@@ -3226,10 +3329,10 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3226
3329
|
const scopedSignal = options?.ignoreAmbientSignal ? void 0 : spawnAbortScope.getStore();
|
|
3227
3330
|
const abortSignal = scopedSignal && callerSignal ? AbortSignal.any([scopedSignal, callerSignal]) : scopedSignal ?? callerSignal;
|
|
3228
3331
|
const cooldown = options?.cooldown ?? (options?.ignoreAmbientSignal ? void 0 : spawnCooldownScope.getStore());
|
|
3229
|
-
const result = await new Promise((
|
|
3332
|
+
const result = await new Promise((resolve8) => {
|
|
3230
3333
|
if (abortSignal?.aborted) {
|
|
3231
3334
|
const cause = new Error("Spawn aborted before start");
|
|
3232
|
-
|
|
3335
|
+
resolve8({
|
|
3233
3336
|
stdout: "",
|
|
3234
3337
|
stderr: "",
|
|
3235
3338
|
status: null,
|
|
@@ -3241,7 +3344,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3241
3344
|
}
|
|
3242
3345
|
if (timeout <= 0) {
|
|
3243
3346
|
const cause = new Error(`Process timed out after ${timeout}ms`);
|
|
3244
|
-
|
|
3347
|
+
resolve8({
|
|
3245
3348
|
stdout: "",
|
|
3246
3349
|
stderr: "",
|
|
3247
3350
|
status: null,
|
|
@@ -3374,7 +3477,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3374
3477
|
const isWindows2 = process.platform === "win32";
|
|
3375
3478
|
const admission = admitSpawn(command, options?.cwd, getSpawnEnvironment(command, options?.env, options?.stripNpmConfig));
|
|
3376
3479
|
if (!admission.admitted) {
|
|
3377
|
-
|
|
3480
|
+
resolve8(trustRefusalResult(command, admission.executable));
|
|
3378
3481
|
return;
|
|
3379
3482
|
}
|
|
3380
3483
|
const spawnEnv = admission.env;
|
|
@@ -3411,7 +3514,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3411
3514
|
void classifySpawnFailure(resolutionError, {
|
|
3412
3515
|
command,
|
|
3413
3516
|
cwd: options?.cwd
|
|
3414
|
-
}).then((spawnFailure) =>
|
|
3517
|
+
}).then((spawnFailure) => resolve8({
|
|
3415
3518
|
stdout: "",
|
|
3416
3519
|
stderr: "",
|
|
3417
3520
|
status: null,
|
|
@@ -3434,7 +3537,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3434
3537
|
});
|
|
3435
3538
|
} catch (err) {
|
|
3436
3539
|
const cause = toError(err);
|
|
3437
|
-
void classifySpawnFailure(cause, { command, cwd: options?.cwd }).then((spawnFailure) =>
|
|
3540
|
+
void classifySpawnFailure(cause, { command, cwd: options?.cwd }).then((spawnFailure) => resolve8({
|
|
3438
3541
|
stdout: "",
|
|
3439
3542
|
stderr: "",
|
|
3440
3543
|
status: null,
|
|
@@ -3452,7 +3555,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3452
3555
|
const ownsChildPid = isOwnLiveChild(child.pid, "safe-spawn-register");
|
|
3453
3556
|
if (ownsChildPid && (posixProcessGroup || options?.lifetimeCoupled)) {
|
|
3454
3557
|
installLifetimeCleanup();
|
|
3455
|
-
lifetimeState.pids.add(child.pid);
|
|
3558
|
+
lifetimeState().pids.add(child.pid);
|
|
3456
3559
|
}
|
|
3457
3560
|
let usageSampler;
|
|
3458
3561
|
try {
|
|
@@ -3700,7 +3803,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3700
3803
|
clearTimeout(timeoutId);
|
|
3701
3804
|
abortSignal?.removeEventListener("abort", onAbort);
|
|
3702
3805
|
if (child.pid)
|
|
3703
|
-
lifetimeState.pids.delete(child.pid);
|
|
3806
|
+
lifetimeState().pids.delete(child.pid);
|
|
3704
3807
|
void finalize(code, signal);
|
|
3705
3808
|
};
|
|
3706
3809
|
const finalize = async (code, signal) => {
|
|
@@ -3727,7 +3830,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3727
3830
|
deathObservedAtMs: closedAtMs,
|
|
3728
3831
|
escalated: teardownEscalated
|
|
3729
3832
|
});
|
|
3730
|
-
|
|
3833
|
+
resolve8({
|
|
3731
3834
|
stdout,
|
|
3732
3835
|
stderr,
|
|
3733
3836
|
status: null,
|
|
@@ -3742,7 +3845,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3742
3845
|
});
|
|
3743
3846
|
} else if (aborted) {
|
|
3744
3847
|
const cause = new Error("Spawn aborted");
|
|
3745
|
-
|
|
3848
|
+
resolve8({
|
|
3746
3849
|
stdout,
|
|
3747
3850
|
stderr,
|
|
3748
3851
|
status: null,
|
|
@@ -3756,7 +3859,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3756
3859
|
});
|
|
3757
3860
|
} else if (signal) {
|
|
3758
3861
|
const cause = new Error(`Process killed by signal: ${signal}`);
|
|
3759
|
-
|
|
3862
|
+
resolve8({
|
|
3760
3863
|
stdout,
|
|
3761
3864
|
stderr,
|
|
3762
3865
|
status: null,
|
|
@@ -3774,7 +3877,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3774
3877
|
command,
|
|
3775
3878
|
cwd: options?.cwd
|
|
3776
3879
|
});
|
|
3777
|
-
|
|
3880
|
+
resolve8({
|
|
3778
3881
|
stdout,
|
|
3779
3882
|
stderr,
|
|
3780
3883
|
status: code,
|
|
@@ -3786,7 +3889,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3786
3889
|
resourceUsage
|
|
3787
3890
|
});
|
|
3788
3891
|
} else {
|
|
3789
|
-
|
|
3892
|
+
resolve8({
|
|
3790
3893
|
stdout,
|
|
3791
3894
|
stderr,
|
|
3792
3895
|
status: code,
|
|
@@ -3810,7 +3913,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3810
3913
|
clearTimeout(escalationTimer);
|
|
3811
3914
|
}
|
|
3812
3915
|
if (child.pid)
|
|
3813
|
-
lifetimeState.pids.delete(child.pid);
|
|
3916
|
+
lifetimeState().pids.delete(child.pid);
|
|
3814
3917
|
const resourceUsage = finishResourceUsage();
|
|
3815
3918
|
let failure = "spawn";
|
|
3816
3919
|
if (aborted)
|
|
@@ -3818,7 +3921,7 @@ async function safeSpawnAsync(command, args, options) {
|
|
|
3818
3921
|
else if (timedOut)
|
|
3819
3922
|
failure = "timeout";
|
|
3820
3923
|
const controlFailure = aborted ? new SpawnFailureError("killed", err.message, err) : timedOut ? new SpawnFailureError("timeout", err.message, err) : void 0;
|
|
3821
|
-
const finish = (spawnFailure) =>
|
|
3924
|
+
const finish = (spawnFailure) => resolve8({
|
|
3822
3925
|
stdout,
|
|
3823
3926
|
stderr,
|
|
3824
3927
|
status: null,
|
|
@@ -4238,14 +4341,23 @@ function loadPiLensGlobalConfig(configPath) {
|
|
|
4238
4341
|
}
|
|
4239
4342
|
const widget = asConfigObject(raw.widget);
|
|
4240
4343
|
if (widget) {
|
|
4344
|
+
const widgetConfig = {};
|
|
4241
4345
|
if (typeof widget.visible === "boolean") {
|
|
4242
|
-
|
|
4243
|
-
} else {
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4346
|
+
widgetConfig.visible = widget.visible;
|
|
4347
|
+
} else if ("visible" in widget) {
|
|
4348
|
+
warnInvalid("widget.visible must be a boolean", "PILENS_CFG_0005");
|
|
4349
|
+
}
|
|
4350
|
+
if (widget.position === "aboveEditor" || widget.position === "belowEditor") {
|
|
4351
|
+
widgetConfig.position = widget.position;
|
|
4352
|
+
} else if ("position" in widget) {
|
|
4353
|
+
warnInvalid('widget.position must be "aboveEditor" or "belowEditor"', "PILENS_CFG_0005");
|
|
4248
4354
|
}
|
|
4355
|
+
if (typeof widget.hideWhenClean === "boolean") {
|
|
4356
|
+
widgetConfig.hideWhenClean = widget.hideWhenClean;
|
|
4357
|
+
} else if ("hideWhenClean" in widget) {
|
|
4358
|
+
warnInvalid("widget.hideWhenClean must be a boolean", "PILENS_CFG_0005");
|
|
4359
|
+
}
|
|
4360
|
+
config.widget = widgetConfig;
|
|
4249
4361
|
}
|
|
4250
4362
|
const format = asConfigObject(raw.format);
|
|
4251
4363
|
if (format) {
|
|
@@ -4567,7 +4679,9 @@ async function sweepDeadEphemeralDataDirs(options) {
|
|
|
4567
4679
|
return removed;
|
|
4568
4680
|
}
|
|
4569
4681
|
function projectDataDirReadableSlug(canonicalRoot) {
|
|
4570
|
-
|
|
4682
|
+
return readableSlugOfSpelling(normalizePathSpelling(canonicalRoot));
|
|
4683
|
+
}
|
|
4684
|
+
function readableSlugOfSpelling(normalized) {
|
|
4571
4685
|
return normalized.replace(/^[a-z]:/i, "").replace(/\/+/g, "-").replace(/[^A-Za-z0-9-]/g, "").replace(/^-+/, "").replace(/-+$/, "");
|
|
4572
4686
|
}
|
|
4573
4687
|
function dataDirCanonicalRoot(cwd, platform = process.platform) {
|
|
@@ -4578,6 +4692,86 @@ function dataDirCanonicalRoot(cwd, platform = process.platform) {
|
|
|
4578
4692
|
function projectDataDirRootHash(canonicalRoot) {
|
|
4579
4693
|
return createHash("sha256").update(canonicalRoot).digest("hex").slice(0, 8);
|
|
4580
4694
|
}
|
|
4695
|
+
var PROJECT_DATA_DIR_ROOT_PROBE_MAX_READDIRS = 256;
|
|
4696
|
+
var LINK_NOT_A_DIR_CODES = /* @__PURE__ */ new Set(["ENOENT", "ENOTDIR", "ELOOP"]);
|
|
4697
|
+
function realProjectDataDirRootFs() {
|
|
4698
|
+
return {
|
|
4699
|
+
listDirs(dir) {
|
|
4700
|
+
const names = [];
|
|
4701
|
+
try {
|
|
4702
|
+
for (const entry of fs7.readdirSync(dir, { withFileTypes: true })) {
|
|
4703
|
+
if (entry.isDirectory()) {
|
|
4704
|
+
names.push(entry.name);
|
|
4705
|
+
continue;
|
|
4706
|
+
}
|
|
4707
|
+
if (!entry.isSymbolicLink())
|
|
4708
|
+
continue;
|
|
4709
|
+
try {
|
|
4710
|
+
if (fs7.statSync(path10.join(dir, entry.name)).isDirectory()) {
|
|
4711
|
+
names.push(entry.name);
|
|
4712
|
+
}
|
|
4713
|
+
} catch (cause) {
|
|
4714
|
+
const code = cause.code ?? "";
|
|
4715
|
+
if (!LINK_NOT_A_DIR_CODES.has(code))
|
|
4716
|
+
throw cause;
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
} catch {
|
|
4720
|
+
return void 0;
|
|
4721
|
+
}
|
|
4722
|
+
return names;
|
|
4723
|
+
}
|
|
4724
|
+
};
|
|
4725
|
+
}
|
|
4726
|
+
var SLUG_NAME_RE = /^([A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)-[0-9a-f]{8}$/;
|
|
4727
|
+
function hasProjectDataDirReading(dir, targets, budget, fsLike) {
|
|
4728
|
+
if (budget.left <= 0) {
|
|
4729
|
+
budget.exhausted = true;
|
|
4730
|
+
return false;
|
|
4731
|
+
}
|
|
4732
|
+
budget.left--;
|
|
4733
|
+
const names = fsLike.listDirs(dir);
|
|
4734
|
+
if (names === void 0) {
|
|
4735
|
+
budget.exhausted = true;
|
|
4736
|
+
return false;
|
|
4737
|
+
}
|
|
4738
|
+
for (const name of names) {
|
|
4739
|
+
const candidate = path10.posix.join(dir, name);
|
|
4740
|
+
const slug = readableSlugOfSpelling(candidate).toLowerCase();
|
|
4741
|
+
let viable = false;
|
|
4742
|
+
for (const target of targets) {
|
|
4743
|
+
if (slug === target)
|
|
4744
|
+
return true;
|
|
4745
|
+
if (slug === "" || target.startsWith(`${slug}-`))
|
|
4746
|
+
viable = true;
|
|
4747
|
+
}
|
|
4748
|
+
if (viable && hasProjectDataDirReading(candidate, targets, budget, fsLike)) {
|
|
4749
|
+
return true;
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
return false;
|
|
4753
|
+
}
|
|
4754
|
+
function createProjectDataDirRootProbe(platform = process.platform, fsLike = realProjectDataDirRootFs()) {
|
|
4755
|
+
return {
|
|
4756
|
+
statusFor(dirName) {
|
|
4757
|
+
if (platform === "win32")
|
|
4758
|
+
return "unrecognized";
|
|
4759
|
+
const readable = SLUG_NAME_RE.exec(dirName)?.[1];
|
|
4760
|
+
if (readable === void 0 || readable === "default") {
|
|
4761
|
+
return "unrecognized";
|
|
4762
|
+
}
|
|
4763
|
+
const budget = {
|
|
4764
|
+
left: PROJECT_DATA_DIR_ROOT_PROBE_MAX_READDIRS,
|
|
4765
|
+
exhausted: false
|
|
4766
|
+
};
|
|
4767
|
+
const targets = [readable.toLowerCase(), dirName.toLowerCase()];
|
|
4768
|
+
if (hasProjectDataDirReading("/", targets, budget, fsLike)) {
|
|
4769
|
+
return "exists";
|
|
4770
|
+
}
|
|
4771
|
+
return budget.exhausted ? "unrecognized" : "gone";
|
|
4772
|
+
}
|
|
4773
|
+
};
|
|
4774
|
+
}
|
|
4581
4775
|
var pendingDataDirMigrations = [];
|
|
4582
4776
|
var settledDataDirs = /* @__PURE__ */ new Map();
|
|
4583
4777
|
function resetProjectDataDirSessionState() {
|
|
@@ -5291,6 +5485,13 @@ function recordLegacyHeld(target) {
|
|
|
5291
5485
|
reason: `backed off: ${path11.basename(lock)} is held by pid ${pidFileOwner(lock) ?? "unknown"}, a writer from before #3476`
|
|
5292
5486
|
});
|
|
5293
5487
|
}
|
|
5488
|
+
function recordOwnHold(target) {
|
|
5489
|
+
incrementDegradationCount({
|
|
5490
|
+
kind: "instance-registry-lock-own-hold",
|
|
5491
|
+
subject: path11.resolve(target),
|
|
5492
|
+
reason: "did not wait: an async registry op of this process holds the lock"
|
|
5493
|
+
});
|
|
5494
|
+
}
|
|
5294
5495
|
function recordLockTimeout(target) {
|
|
5295
5496
|
incrementDegradationCount({
|
|
5296
5497
|
kind: "instance-registry-lock-timeout",
|
|
@@ -5301,6 +5502,9 @@ function recordLockTimeout(target) {
|
|
|
5301
5502
|
function backoffMs() {
|
|
5302
5503
|
return randomInt2(LOCK_MIN_BACKOFF_MS, LOCK_MAX_BACKOFF_MS + 1);
|
|
5303
5504
|
}
|
|
5505
|
+
function backoff() {
|
|
5506
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, backoffMs());
|
|
5507
|
+
}
|
|
5304
5508
|
var LOCK_WAIT_THROUGH_LEASE_MS = LOCK_STALE_MS + LOCK_WAIT_MS;
|
|
5305
5509
|
async function withInstanceRegistryLock(target, op, waitMs = LOCK_WAIT_MS) {
|
|
5306
5510
|
const deadline = Date.now() + waitMs;
|
|
@@ -5310,7 +5514,7 @@ async function withInstanceRegistryLock(target, op, waitMs = LOCK_WAIT_MS) {
|
|
|
5310
5514
|
return void 0;
|
|
5311
5515
|
if (hold === "busy") {
|
|
5312
5516
|
if (Date.now() <= deadline)
|
|
5313
|
-
await new Promise((
|
|
5517
|
+
await new Promise((resolve8) => setTimeout(resolve8, backoffMs()));
|
|
5314
5518
|
continue;
|
|
5315
5519
|
}
|
|
5316
5520
|
const holds = ownAsyncHolds();
|
|
@@ -5325,6 +5529,30 @@ async function withInstanceRegistryLock(target, op, waitMs = LOCK_WAIT_MS) {
|
|
|
5325
5529
|
recordLockTimeout(target);
|
|
5326
5530
|
return void 0;
|
|
5327
5531
|
}
|
|
5532
|
+
function withInstanceRegistryLockSync(target, op) {
|
|
5533
|
+
if (ownAsyncHolds().count > 0) {
|
|
5534
|
+
recordOwnHold(target);
|
|
5535
|
+
return void 0;
|
|
5536
|
+
}
|
|
5537
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
5538
|
+
while (Date.now() <= deadline) {
|
|
5539
|
+
const hold = tryAcquire(target);
|
|
5540
|
+
if (hold === "failed")
|
|
5541
|
+
return void 0;
|
|
5542
|
+
if (hold === "busy") {
|
|
5543
|
+
if (Date.now() <= deadline)
|
|
5544
|
+
backoff();
|
|
5545
|
+
continue;
|
|
5546
|
+
}
|
|
5547
|
+
try {
|
|
5548
|
+
return op();
|
|
5549
|
+
} finally {
|
|
5550
|
+
release(target, hold);
|
|
5551
|
+
}
|
|
5552
|
+
}
|
|
5553
|
+
recordLockTimeout(target);
|
|
5554
|
+
return void 0;
|
|
5555
|
+
}
|
|
5328
5556
|
|
|
5329
5557
|
// dist/clients/instance-registry-tail.js
|
|
5330
5558
|
var REGISTRY_TAIL_FAMILY = "instance-registry.mutation-tail";
|
|
@@ -5411,6 +5639,22 @@ function recordCorruptRegistryRead(reasonCode) {
|
|
|
5411
5639
|
reason: `read failed (${reasonCode}); treating as empty`
|
|
5412
5640
|
});
|
|
5413
5641
|
}
|
|
5642
|
+
function readRegistrySync(target = registryPath()) {
|
|
5643
|
+
try {
|
|
5644
|
+
const raw = fs9.readFileSync(target, "utf-8");
|
|
5645
|
+
const parsed = JSON.parse(raw);
|
|
5646
|
+
if (parsed && Array.isArray(parsed.instances)) {
|
|
5647
|
+
return parsed;
|
|
5648
|
+
}
|
|
5649
|
+
recordCorruptRegistryRead("invalid shape");
|
|
5650
|
+
return { instances: [] };
|
|
5651
|
+
} catch (err) {
|
|
5652
|
+
const code = err?.code;
|
|
5653
|
+
if (code !== "ENOENT")
|
|
5654
|
+
recordCorruptRegistryRead(code ?? "invalid");
|
|
5655
|
+
return { instances: [] };
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5414
5658
|
async function readRegistryAsync() {
|
|
5415
5659
|
try {
|
|
5416
5660
|
const raw = await fs9.promises.readFile(registryPath(), "utf-8");
|
|
@@ -5454,6 +5698,15 @@ async function writeRegistryWithRetry(mutate, isCommitted) {
|
|
|
5454
5698
|
}
|
|
5455
5699
|
});
|
|
5456
5700
|
}
|
|
5701
|
+
function writeRegistrySync(file, target = registryPath()) {
|
|
5702
|
+
const dir = path12.dirname(target);
|
|
5703
|
+
try {
|
|
5704
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
5705
|
+
} catch {
|
|
5706
|
+
return;
|
|
5707
|
+
}
|
|
5708
|
+
writeFileAtomic(target, JSON.stringify(file));
|
|
5709
|
+
}
|
|
5457
5710
|
function getInstanceRoots(entry) {
|
|
5458
5711
|
const listed = Array.isArray(entry.projectRoots) ? entry.projectRoots.filter((root) => typeof root === "string" && root.length > 0) : [];
|
|
5459
5712
|
if (listed.length > 0)
|
|
@@ -5511,6 +5764,7 @@ async function registerInstanceNow(projectRoot, generation) {
|
|
|
5511
5764
|
if (!registrationIsCurrent(generation, normalizedRoot))
|
|
5512
5765
|
return;
|
|
5513
5766
|
rememberRegistrationRoot(projectRoot);
|
|
5767
|
+
armExitRemoval();
|
|
5514
5768
|
const pid = process.pid;
|
|
5515
5769
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5516
5770
|
const identity = isSubagentSession() ? getSubagentIdentity() : void 0;
|
|
@@ -5634,6 +5888,7 @@ function recordLspChild(entry) {
|
|
|
5634
5888
|
async function recordLspChildNow(entry, generation) {
|
|
5635
5889
|
if (!isInstanceRegistryEnabled())
|
|
5636
5890
|
return;
|
|
5891
|
+
armExitRemoval();
|
|
5637
5892
|
const pid = process.pid;
|
|
5638
5893
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5639
5894
|
const [selfStart, childStart] = await Promise.all([
|
|
@@ -5735,6 +5990,34 @@ async function removeLspChildNow(pid, expectedMarker) {
|
|
|
5735
5990
|
await writeRegistryAsync(file);
|
|
5736
5991
|
});
|
|
5737
5992
|
}
|
|
5993
|
+
var EXIT_REMOVAL_FAMILY = "instance-registry.exit-removal";
|
|
5994
|
+
var EXIT_REMOVAL_VERSION = 1;
|
|
5995
|
+
function armExitRemoval() {
|
|
5996
|
+
const state = getProcessSingleton(EXIT_REMOVAL_FAMILY, EXIT_REMOVAL_VERSION, () => ({ target: void 0, armed: false }));
|
|
5997
|
+
state.target = registryPath();
|
|
5998
|
+
if (state.armed)
|
|
5999
|
+
return;
|
|
6000
|
+
state.armed = true;
|
|
6001
|
+
process.once("exit", (code) => {
|
|
6002
|
+
if (state.target)
|
|
6003
|
+
removeOwnEntryAtExit(state.target, code);
|
|
6004
|
+
});
|
|
6005
|
+
}
|
|
6006
|
+
function removeOwnEntryAtExit(target, code) {
|
|
6007
|
+
if (!endHeldChildren() || code !== 0 || !fs9.existsSync(target))
|
|
6008
|
+
return;
|
|
6009
|
+
const selfStart = ownProcessStartIfKnown();
|
|
6010
|
+
withInstanceRegistryLockSync(target, () => {
|
|
6011
|
+
const next = withoutOwnEntry(readRegistrySync(target), selfStart);
|
|
6012
|
+
if (next)
|
|
6013
|
+
writeRegistrySync(next, target);
|
|
6014
|
+
return true;
|
|
6015
|
+
});
|
|
6016
|
+
}
|
|
6017
|
+
function withoutOwnEntry(file, selfStart) {
|
|
6018
|
+
const remaining = file.instances.filter((entry) => !isOwnEntry(entry, selfStart));
|
|
6019
|
+
return remaining.length === file.instances.length ? void 0 : { instances: remaining };
|
|
6020
|
+
}
|
|
5738
6021
|
function selectLivePeerInstances(entries, root, now = Date.now(), isPidAlive = realIsPidAlive, match = "exact") {
|
|
5739
6022
|
const normalizedRoot = normalizeFilePath(root);
|
|
5740
6023
|
return entries.filter((entry) => entry.pid !== process.pid && // #2130: a host serves a SET of roots. Matching only
|
|
@@ -5815,6 +6098,79 @@ async function prunePids(dead) {
|
|
|
5815
6098
|
// dist/clients/instance-reaper.js
|
|
5816
6099
|
var STALE_HEARTBEAT_MS = 6 * 60 * 60 * 1e3;
|
|
5817
6100
|
var isWindows = process.platform === "win32";
|
|
6101
|
+
function isInstanceKillEligible(instance, isPidAlive, startOf) {
|
|
6102
|
+
if (!isPidAlive(instance.pid))
|
|
6103
|
+
return true;
|
|
6104
|
+
return isAnotherProcess(instance.processStart, startOf(instance.pid));
|
|
6105
|
+
}
|
|
6106
|
+
function isAnotherProcess(recorded, current) {
|
|
6107
|
+
const bootOf = (start) => start.includes("@") ? start.slice(start.indexOf("@") + 1) : "";
|
|
6108
|
+
return recorded !== void 0 && current !== void 0 && current !== recorded && bootOf(current) === bootOf(recorded);
|
|
6109
|
+
}
|
|
6110
|
+
function isInstanceEntryStale(instance, now) {
|
|
6111
|
+
const heartbeatMs = Date.parse(instance.heartbeatAt);
|
|
6112
|
+
if (Number.isNaN(heartbeatMs))
|
|
6113
|
+
return true;
|
|
6114
|
+
return now - heartbeatMs > STALE_HEARTBEAT_MS;
|
|
6115
|
+
}
|
|
6116
|
+
function collectLiveMarkers(registry, isPidAlive) {
|
|
6117
|
+
const liveMarkers = /* @__PURE__ */ new Set();
|
|
6118
|
+
for (const instance of registry) {
|
|
6119
|
+
if (!isPidAlive(instance.pid))
|
|
6120
|
+
continue;
|
|
6121
|
+
for (const child of instance.lspChildren) {
|
|
6122
|
+
if (child.marker)
|
|
6123
|
+
liveMarkers.add(child.marker);
|
|
6124
|
+
}
|
|
6125
|
+
}
|
|
6126
|
+
return liveMarkers;
|
|
6127
|
+
}
|
|
6128
|
+
function classifyDeadInstanceChildren(instance, isPidAlive, matchProcess, liveMarkers, out) {
|
|
6129
|
+
for (const child of instance.lspChildren) {
|
|
6130
|
+
const childAlive = isPidAlive(child.pid);
|
|
6131
|
+
if (childAlive) {
|
|
6132
|
+
const expected = {
|
|
6133
|
+
command: child.command,
|
|
6134
|
+
marker: child.marker,
|
|
6135
|
+
processStart: child.processStart
|
|
6136
|
+
};
|
|
6137
|
+
const identityOk = matchProcess ? matchProcess(child.pid, expected) : true;
|
|
6138
|
+
if (identityOk) {
|
|
6139
|
+
out.childrenToKill.push({
|
|
6140
|
+
pid: child.pid,
|
|
6141
|
+
serverId: child.serverId,
|
|
6142
|
+
...expected
|
|
6143
|
+
});
|
|
6144
|
+
continue;
|
|
6145
|
+
}
|
|
6146
|
+
}
|
|
6147
|
+
if (child.marker && !liveMarkers.has(child.marker)) {
|
|
6148
|
+
out.markerSearches.push({
|
|
6149
|
+
marker: child.marker,
|
|
6150
|
+
serverId: child.serverId
|
|
6151
|
+
});
|
|
6152
|
+
}
|
|
6153
|
+
}
|
|
6154
|
+
}
|
|
6155
|
+
function decideOrphanReaping(registry, isPidAlive, matchProcess, now = Date.now(), startOf = () => void 0, judgeable = () => true) {
|
|
6156
|
+
const deadInstances = [];
|
|
6157
|
+
const staleInstances = [];
|
|
6158
|
+
const childrenToKill = [];
|
|
6159
|
+
const markerSearches = [];
|
|
6160
|
+
const liveMarkers = collectLiveMarkers(registry, isPidAlive);
|
|
6161
|
+
for (const instance of registry) {
|
|
6162
|
+
if (judgeable(instance) && isInstanceKillEligible(instance, isPidAlive, startOf)) {
|
|
6163
|
+
deadInstances.push(instance);
|
|
6164
|
+
classifyDeadInstanceChildren(instance, isPidAlive, matchProcess, liveMarkers, {
|
|
6165
|
+
childrenToKill,
|
|
6166
|
+
markerSearches
|
|
6167
|
+
});
|
|
6168
|
+
} else if (isInstanceEntryStale(instance, now)) {
|
|
6169
|
+
staleInstances.push(instance);
|
|
6170
|
+
}
|
|
6171
|
+
}
|
|
6172
|
+
return { deadInstances, staleInstances, childrenToKill, markerSearches };
|
|
6173
|
+
}
|
|
5818
6174
|
var STAGE_PID_PATTERN = /\.stage-(\d+)-/;
|
|
5819
6175
|
function isStaleStageFile(entry, artifactPrefix) {
|
|
5820
6176
|
if (!entry.startsWith(artifactPrefix))
|
|
@@ -5831,11 +6187,82 @@ async function sweepAtomicWriteStages(directories, options = {}) {
|
|
|
5831
6187
|
const isPidAlive = options.isPidAlive ?? realIsPidAlive;
|
|
5832
6188
|
return sweepOwnStagingFiles(directories, { maxEntries, isPidAlive });
|
|
5833
6189
|
}
|
|
6190
|
+
async function findPidsByMarkerWindows(marker) {
|
|
6191
|
+
if (!isWindows || !marker)
|
|
6192
|
+
return [];
|
|
6193
|
+
const result = await queryProcessTable({
|
|
6194
|
+
fields: ["pid"],
|
|
6195
|
+
filter: { column: "CommandLine", op: "like", values: [marker] },
|
|
6196
|
+
// The query's own powershell.exe command line embeds the marker, so
|
|
6197
|
+
// without this exclusion the search matches itself.
|
|
6198
|
+
excludeSelfPid: true
|
|
6199
|
+
}, {
|
|
6200
|
+
timeoutMs: BACKSTOP_SCAN_TIMEOUT_MS,
|
|
6201
|
+
// #2527 review F2: omitting `onTimeout` falls through to
|
|
6202
|
+
// child-unref.ts's default — one bare, unverified `child.kill()`, no
|
|
6203
|
+
// tree kill, no identity-carrying record — inside the orphan backstop
|
|
6204
|
+
// path, the exact abandonment `terminateScannerChild`'s own doc
|
|
6205
|
+
// comment says it exists to prevent. This query shares the backstop's
|
|
6206
|
+
// scanner identity and budget (same producer as
|
|
6207
|
+
// `enumerateManagedProcesses`), so it gets the same kind.
|
|
6208
|
+
onTimeout: (child) => terminateScannerChild(child, {
|
|
6209
|
+
kind: "orphan-backstop-scanner-escalated",
|
|
6210
|
+
timeoutMs: BACKSTOP_SCAN_TIMEOUT_MS
|
|
6211
|
+
})
|
|
6212
|
+
});
|
|
6213
|
+
if (result.status !== "ok") {
|
|
6214
|
+
recordDegradationOnce({
|
|
6215
|
+
kind: "orphan-backstop-scan-failed",
|
|
6216
|
+
subject: "marker-search",
|
|
6217
|
+
reason: `marker command-line search ${result.status}`
|
|
6218
|
+
});
|
|
6219
|
+
}
|
|
6220
|
+
return result.rows.map((row) => row.pid);
|
|
6221
|
+
}
|
|
6222
|
+
async function queryIdentities(pids) {
|
|
6223
|
+
const result = await queryProcessIdentities(pids, {
|
|
6224
|
+
timeoutMs: BACKSTOP_SCAN_TIMEOUT_MS,
|
|
6225
|
+
// #2527 review F2: same rationale as findPidsByMarkerWindows above —
|
|
6226
|
+
// route through the reaper's own tree-kill-and-verify machinery with
|
|
6227
|
+
// the backstop's kind rather than falling through to the unverified
|
|
6228
|
+
// default kill with no ledger record.
|
|
6229
|
+
onTimeout: (child) => terminateScannerChild(child, {
|
|
6230
|
+
kind: "orphan-backstop-scanner-escalated",
|
|
6231
|
+
timeoutMs: BACKSTOP_SCAN_TIMEOUT_MS
|
|
6232
|
+
})
|
|
6233
|
+
});
|
|
6234
|
+
const psReportedNoSuchPid = !isWindows && result.status === "exit-error";
|
|
6235
|
+
const failed = result.status !== "ok" && !psReportedNoSuchPid;
|
|
6236
|
+
if (failed) {
|
|
6237
|
+
recordDegradationOnce({
|
|
6238
|
+
kind: "orphan-backstop-scan-failed",
|
|
6239
|
+
subject: "identity-query",
|
|
6240
|
+
reason: `command-line identity query ${result.status}; reap suppressed this sweep`
|
|
6241
|
+
});
|
|
6242
|
+
}
|
|
6243
|
+
return { identities: result.identities, failed };
|
|
6244
|
+
}
|
|
6245
|
+
function buildIdentityMatcher(identities) {
|
|
6246
|
+
return (pid, expected) => {
|
|
6247
|
+
const identity = identities.get(pid);
|
|
6248
|
+
if (identity === void 0)
|
|
6249
|
+
return false;
|
|
6250
|
+
if (expected.processStart === void 0 || identity.start !== expected.processStart)
|
|
6251
|
+
return false;
|
|
6252
|
+
const cmdline = identity.command;
|
|
6253
|
+
if (expected.marker && cmdline.includes(expected.marker))
|
|
6254
|
+
return true;
|
|
6255
|
+
const basename5 = path13.basename(expected.command ?? "").toLowerCase();
|
|
6256
|
+
if (!basename5)
|
|
6257
|
+
return false;
|
|
6258
|
+
return cmdline.toLowerCase().includes(basename5);
|
|
6259
|
+
};
|
|
6260
|
+
}
|
|
5834
6261
|
var KILL_VERIFY_ATTEMPTS = 5;
|
|
5835
6262
|
var KILL_VERIFY_INTERVAL_MS = 100;
|
|
5836
6263
|
function sleepUnref(ms) {
|
|
5837
|
-
return new Promise((
|
|
5838
|
-
const timer = setTimeout(
|
|
6264
|
+
return new Promise((resolve8) => {
|
|
6265
|
+
const timer = setTimeout(resolve8, ms);
|
|
5839
6266
|
timer.unref();
|
|
5840
6267
|
});
|
|
5841
6268
|
}
|
|
@@ -5853,9 +6280,9 @@ async function killPidTree(pid, options = {}) {
|
|
|
5853
6280
|
stdio: "ignore"
|
|
5854
6281
|
});
|
|
5855
6282
|
unrefChildAndPipes(killer);
|
|
5856
|
-
await new Promise((
|
|
5857
|
-
killer.once("close", () =>
|
|
5858
|
-
killer.once("error", () =>
|
|
6283
|
+
await new Promise((resolve8) => {
|
|
6284
|
+
killer.once("close", () => resolve8());
|
|
6285
|
+
killer.once("error", () => resolve8());
|
|
5859
6286
|
});
|
|
5860
6287
|
} catch {
|
|
5861
6288
|
}
|
|
@@ -5918,6 +6345,100 @@ async function terminateScannerChild(child, options) {
|
|
|
5918
6345
|
}
|
|
5919
6346
|
var BACKSTOP_SCAN_TIMEOUT_MS = 5e3;
|
|
5920
6347
|
var BACKSTOP_COOLDOWN_MS = 30 * 60 * 1e3;
|
|
6348
|
+
async function sweepOrphans() {
|
|
6349
|
+
if (!isInstanceRegistryEnabled())
|
|
6350
|
+
return;
|
|
6351
|
+
const startedAt = Date.now();
|
|
6352
|
+
try {
|
|
6353
|
+
const registry = await readInstanceRegistry();
|
|
6354
|
+
if (registry.length === 0)
|
|
6355
|
+
return;
|
|
6356
|
+
const ownNamespace = ownPidNamespace();
|
|
6357
|
+
const judgeable = (entry) => isInPidNamespace(entry, ownNamespace);
|
|
6358
|
+
const candidatePids = registry.flatMap((instance) => [
|
|
6359
|
+
instance.pid,
|
|
6360
|
+
...instance.lspChildren.map((child) => child.pid)
|
|
6361
|
+
]);
|
|
6362
|
+
const { identities, failed } = await queryIdentities(candidatePids);
|
|
6363
|
+
const matchProcess = buildIdentityMatcher(identities);
|
|
6364
|
+
const decision = decideOrphanReaping(registry, realIsPidAlive, matchProcess, Date.now(), (pid) => identities.get(pid)?.start, judgeable);
|
|
6365
|
+
let killedCount = 0;
|
|
6366
|
+
let unverifiedCount = 0;
|
|
6367
|
+
let identityChangedCount = 0;
|
|
6368
|
+
const killedServerIds = [];
|
|
6369
|
+
const killAndAccount = async (pid, serverId, stillSame) => {
|
|
6370
|
+
const outcome = await killPidTree(pid, {
|
|
6371
|
+
confirmIdentity: async () => stillSame((await queryIdentities([pid])).identities)
|
|
6372
|
+
});
|
|
6373
|
+
if (outcome === "changed") {
|
|
6374
|
+
identityChangedCount++;
|
|
6375
|
+
return;
|
|
6376
|
+
}
|
|
6377
|
+
if (outcome === "gone") {
|
|
6378
|
+
killedCount++;
|
|
6379
|
+
killedServerIds.push(serverId);
|
|
6380
|
+
return;
|
|
6381
|
+
}
|
|
6382
|
+
unverifiedCount++;
|
|
6383
|
+
incrementDegradationCount({
|
|
6384
|
+
kind: "orphan-reap-kill-unverified",
|
|
6385
|
+
subject: `${serverId}#${pid}`,
|
|
6386
|
+
reason: `kill attempted, process still ${outcome === "alive" ? "alive" : "unresolvable"}`
|
|
6387
|
+
});
|
|
6388
|
+
};
|
|
6389
|
+
for (const child of decision.childrenToKill) {
|
|
6390
|
+
await killAndAccount(child.pid, child.serverId, (now) => buildIdentityMatcher(now)(child.pid, child));
|
|
6391
|
+
}
|
|
6392
|
+
for (const search of decision.markerSearches) {
|
|
6393
|
+
try {
|
|
6394
|
+
const pids = await findPidsByMarkerWindows(search.marker);
|
|
6395
|
+
for (const pid of pids) {
|
|
6396
|
+
await killAndAccount(pid, search.serverId, (now) => now.get(pid)?.command.includes(search.marker) === true);
|
|
6397
|
+
}
|
|
6398
|
+
} catch {
|
|
6399
|
+
}
|
|
6400
|
+
}
|
|
6401
|
+
const pruneTargets = [
|
|
6402
|
+
...failed ? [] : decision.deadInstances,
|
|
6403
|
+
...decision.staleInstances
|
|
6404
|
+
].map((instance) => ({
|
|
6405
|
+
pid: instance.pid,
|
|
6406
|
+
processStart: instance.processStart,
|
|
6407
|
+
pidNamespace: instance.pidNamespace
|
|
6408
|
+
}));
|
|
6409
|
+
if (pruneTargets.length > 0) {
|
|
6410
|
+
try {
|
|
6411
|
+
await pruneDeadInstances2(pruneTargets);
|
|
6412
|
+
} catch {
|
|
6413
|
+
}
|
|
6414
|
+
}
|
|
6415
|
+
try {
|
|
6416
|
+
logLatency({
|
|
6417
|
+
type: "phase",
|
|
6418
|
+
phase: "orphan_lsp_reaped",
|
|
6419
|
+
filePath: "",
|
|
6420
|
+
durationMs: Date.now() - startedAt,
|
|
6421
|
+
metadata: {
|
|
6422
|
+
deadInstances: decision.deadInstances.length,
|
|
6423
|
+
staleInstances: decision.staleInstances.length,
|
|
6424
|
+
killed: killedCount,
|
|
6425
|
+
killUnverified: unverifiedCount,
|
|
6426
|
+
identityChanged: identityChangedCount,
|
|
6427
|
+
serverIds: killedServerIds,
|
|
6428
|
+
markerSearches: decision.markerSearches.length
|
|
6429
|
+
}
|
|
6430
|
+
});
|
|
6431
|
+
} catch {
|
|
6432
|
+
}
|
|
6433
|
+
} catch {
|
|
6434
|
+
}
|
|
6435
|
+
}
|
|
6436
|
+
async function pruneDeadInstances2(dead) {
|
|
6437
|
+
try {
|
|
6438
|
+
await pruneDeadInstances(dead);
|
|
6439
|
+
} catch {
|
|
6440
|
+
}
|
|
6441
|
+
}
|
|
5921
6442
|
|
|
5922
6443
|
export {
|
|
5923
6444
|
isInSpawnTimeoutCooldown,
|
|
@@ -5932,6 +6453,9 @@ export {
|
|
|
5932
6453
|
VENV_BIN_DIRS,
|
|
5933
6454
|
PROJECT_BIN_DIR_WINDOWS_EXT,
|
|
5934
6455
|
projectLocalBinDirs,
|
|
6456
|
+
sessionRepositoryJudge,
|
|
6457
|
+
projectSearchJudge,
|
|
6458
|
+
withUnadmittedRootSpawns,
|
|
5935
6459
|
isSessionRepositoryPath,
|
|
5936
6460
|
isUntrustedProjectPath,
|
|
5937
6461
|
recordProjectCommandRefusal,
|
|
@@ -5964,6 +6488,7 @@ export {
|
|
|
5964
6488
|
getResourceFootprint,
|
|
5965
6489
|
isStaleStageFile,
|
|
5966
6490
|
sweepAtomicWriteStages,
|
|
6491
|
+
sweepOrphans,
|
|
5967
6492
|
sampleProcessTreeCpuPercent,
|
|
5968
6493
|
SpawnFailureError,
|
|
5969
6494
|
hasSpawnFailureKind,
|
|
@@ -5991,7 +6516,9 @@ export {
|
|
|
5991
6516
|
ephemeralStagingRoot,
|
|
5992
6517
|
isEphemeralCheckoutRoot,
|
|
5993
6518
|
getProjectDataDir,
|
|
6519
|
+
projectDataBase,
|
|
5994
6520
|
sweepDeadEphemeralDataDirs,
|
|
6521
|
+
createProjectDataDirRootProbe,
|
|
5995
6522
|
resetProjectDataDirSessionState,
|
|
5996
6523
|
drainProjectDataDirMigrations,
|
|
5997
6524
|
displayProjectDataPath,
|