@cydm/pie 4.10.0 → 4.10.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.
@@ -0,0 +1,251 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ getConfigDir
4
+ } from "./chunk-CBDQJMUI.js";
5
+
6
+ // src/commands/manager-allow.ts
7
+ import * as fs from "node:fs";
8
+ import * as os from "node:os";
9
+ import * as path from "node:path";
10
+ import { randomBytes } from "node:crypto";
11
+ function expandTilde(p) {
12
+ return p === "~" ? os.homedir() : p.startsWith("~/") || p.startsWith("~\\") ? path.join(os.homedir(), p.slice(2)) : p;
13
+ }
14
+ function resolveProcConfigCandidates() {
15
+ const root = getConfigDir();
16
+ const candidates = [path.join(root, "pie-proc.json")];
17
+ const pinnedRoot = process.env.PIE_PROC_REGISTRY_ROOT;
18
+ if (pinnedRoot) {
19
+ const pinDerived = path.join(path.dirname(path.resolve(expandTilde(pinnedRoot))), "pie-proc.json");
20
+ if (!candidates.includes(pinDerived)) candidates.push(pinDerived);
21
+ } else {
22
+ const homeFile = path.join(os.homedir(), ".pie", "pie-proc.json");
23
+ if (!candidates.includes(homeFile)) candidates.push(homeFile);
24
+ }
25
+ return candidates;
26
+ }
27
+ function resolveEffectiveProcConfigFile() {
28
+ const candidates = resolveProcConfigCandidates();
29
+ for (const candidate of candidates) {
30
+ try {
31
+ if (fs.existsSync(candidate)) return { file: candidate, exists: true };
32
+ } catch {
33
+ return { file: candidate, exists: true };
34
+ }
35
+ }
36
+ return { file: candidates[0], exists: false };
37
+ }
38
+ function resolveWritableProcConfigFile() {
39
+ return path.join(getConfigDir(), "pie-proc.json");
40
+ }
41
+ function isTooBroadForWorkerSandbox(input) {
42
+ let resolved;
43
+ try {
44
+ resolved = fs.realpathSync(input);
45
+ } catch {
46
+ return true;
47
+ }
48
+ const root = path.parse(resolved).root;
49
+ if (resolved === root || resolved === os.homedir()) return true;
50
+ const forbidden = [os.homedir(), os.tmpdir(), "/tmp", "/var/tmp", "/private/tmp", "/private/var/tmp"];
51
+ for (const candidate of forbidden) {
52
+ try {
53
+ if (resolved === fs.realpathSync(candidate)) return true;
54
+ } catch {
55
+ }
56
+ }
57
+ try {
58
+ const stat = fs.statSync(resolved);
59
+ if ((stat.mode & 2) !== 0 && (stat.mode & 512) === 0) return true;
60
+ } catch {
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ function seedProcConfig(launchCwd) {
66
+ const root = getConfigDir();
67
+ const file = path.join(root, "pie-proc.json");
68
+ const resolved = path.resolve(launchCwd);
69
+ try {
70
+ if (fs.existsSync(file)) return { state: "exists", file, root };
71
+ } catch {
72
+ return { state: "exists", file, root };
73
+ }
74
+ const userLayer = path.join(os.homedir(), ".pie", "pie-proc.json");
75
+ try {
76
+ if (fs.existsSync(userLayer)) return { state: "user-layer", file: userLayer, root };
77
+ } catch {
78
+ }
79
+ if (isTooBroadForWorkerSandbox(resolved)) {
80
+ return { state: "too-broad", file, root };
81
+ }
82
+ fs.mkdirSync(root, { recursive: true });
83
+ fs.writeFileSync(file, `${JSON.stringify({ allowCwd: [resolved] }, null, " ")}
84
+ `);
85
+ return { state: "seeded", file, root };
86
+ }
87
+ function isTooBroadDir(canonical) {
88
+ return isTooBroadForWorkerSandbox(canonical);
89
+ }
90
+ function addAllowedWorkerCwd(rawDir, opts = {}) {
91
+ const resolved = path.resolve(expandTilde(rawDir));
92
+ let canonical;
93
+ try {
94
+ canonical = fs.realpathSync(resolved);
95
+ if (!fs.statSync(canonical).isDirectory()) {
96
+ throw new Error(`"${rawDir}" is not a directory.`);
97
+ }
98
+ } catch (error) {
99
+ throw new Error(
100
+ error instanceof Error && error.message.includes("not a directory") ? error.message : `Directory does not exist or is unreadable: "${rawDir}" (${resolved}).`
101
+ );
102
+ }
103
+ if (isTooBroadDir(canonical) && !opts.force) {
104
+ throw new Error(
105
+ `Refusing to authorize broad root "${canonical}" without --force. Pass a narrower project root (e.g. ~/Projects), or re-run with --force if you intentionally want this root.`
106
+ );
107
+ }
108
+ const target = opts.file ? path.resolve(expandTilde(opts.file)) : resolveWritableProcConfigFile();
109
+ const shadowedFallback = !opts.file && !fs.existsSync(target) ? resolveProcConfigCandidates().slice(1).find((c) => {
110
+ try {
111
+ return fs.existsSync(c);
112
+ } catch {
113
+ return false;
114
+ }
115
+ }) : void 0;
116
+ let doc = {};
117
+ let backedUpTo;
118
+ if (fs.existsSync(target)) {
119
+ const rawText = fs.readFileSync(target, "utf8");
120
+ try {
121
+ const parsed = JSON.parse(rawText);
122
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
123
+ throw new Error("top-level JSON value must be an object");
124
+ }
125
+ doc = { ...parsed };
126
+ } catch (error) {
127
+ const detail = error instanceof Error ? error.message : String(error);
128
+ if (!opts.backupCorrupt) {
129
+ throw new Error(
130
+ `Cannot update ${target}: invalid JSON (${detail}). Re-run with --backup-corrupt to back up the broken file and recreate it.`
131
+ );
132
+ }
133
+ backedUpTo = `${target}.corrupt-${Date.now()}-${randomBytes(3).toString("hex")}`;
134
+ fs.renameSync(target, backedUpTo);
135
+ doc = {};
136
+ }
137
+ }
138
+ const existing = Array.isArray(doc.allowCwd) ? doc.allowCwd.filter((v) => typeof v === "string" && v.trim().length > 0) : [];
139
+ const alreadyCovered = existing.some((entry) => {
140
+ try {
141
+ return fs.realpathSync(path.resolve(expandTilde(entry))) === canonical;
142
+ } catch {
143
+ return path.resolve(expandTilde(entry)) === canonical;
144
+ }
145
+ });
146
+ const nextAllowCwd = alreadyCovered ? existing : [...existing, canonical];
147
+ if (!alreadyCovered || backedUpTo) {
148
+ doc.allowCwd = nextAllowCwd;
149
+ fs.mkdirSync(path.dirname(target), { recursive: true });
150
+ const tmp = path.join(path.dirname(target), `.pie-proc-${process.pid}-${randomBytes(4).toString("hex")}.tmp`);
151
+ try {
152
+ fs.writeFileSync(tmp, `${JSON.stringify(doc, null, " ")}
153
+ `, { encoding: "utf8", mode: 384 });
154
+ fs.renameSync(tmp, target);
155
+ } finally {
156
+ try {
157
+ fs.rmSync(tmp, { force: true });
158
+ } catch {
159
+ }
160
+ }
161
+ }
162
+ return {
163
+ file: target,
164
+ canonicalDir: canonical,
165
+ added: !alreadyCovered,
166
+ allowCwd: nextAllowCwd,
167
+ ...backedUpTo ? { backedUpTo } : {},
168
+ ...shadowedFallback ? { shadowedFallback } : {}
169
+ };
170
+ }
171
+ function runManagerAllowCommand(args) {
172
+ const json = args.includes("--json");
173
+ const force = args.includes("--force");
174
+ const backupCorrupt = args.includes("--backup-corrupt");
175
+ const list = args.includes("--list");
176
+ const help = args.includes("--help") || args.includes("-h");
177
+ const fileIdx = args.indexOf("--file");
178
+ const explicitFile = fileIdx >= 0 ? args[fileIdx + 1] : void 0;
179
+ if (fileIdx >= 0 && (!explicitFile || explicitFile.startsWith("-"))) {
180
+ console.error("--file expects a pie-proc.json path.");
181
+ process.exitCode = 2;
182
+ return;
183
+ }
184
+ if (help) {
185
+ console.log(
186
+ "Usage:\n pie manager allow <dir> [--file <path>] [--force] [--backup-corrupt] [--json]\n pie manager allow --list [--json]\n\nAdds a canonical project root to the active pie-proc.json allowCwd list.\nRe-read on every worker spawn; no manager restart required."
187
+ );
188
+ return;
189
+ }
190
+ if (list) {
191
+ const { file, exists } = resolveEffectiveProcConfigFile();
192
+ if (!exists) {
193
+ if (json) console.log(JSON.stringify({ ok: true, file, exists: false, allowCwd: [] }));
194
+ else console.log(`No pie-proc.json found yet (next write target: ${file}).`);
195
+ return;
196
+ }
197
+ try {
198
+ const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
199
+ const allowCwd = Array.isArray(parsed.allowCwd) ? parsed.allowCwd.filter((v) => typeof v === "string") : [];
200
+ if (json) console.log(JSON.stringify({ ok: true, file, exists: true, allowCwd, maxWorkers: parsed.maxWorkers ?? 50 }));
201
+ else {
202
+ console.log(`Policy file: ${file}`);
203
+ console.log(`maxWorkers: ${typeof parsed.maxWorkers === "number" ? parsed.maxWorkers : "50 (default)"}`);
204
+ console.log(allowCwd.length ? `allowCwd:
205
+ ${allowCwd.map((d) => ` - ${d}`).join("\n")}` : "allowCwd: (empty)");
206
+ }
207
+ } catch (error) {
208
+ const detail = error instanceof Error ? error.message : String(error);
209
+ if (json) console.log(JSON.stringify({ ok: false, file, error: detail }));
210
+ else console.error(`Invalid pie-proc.json at ${file}: ${detail}`);
211
+ process.exitCode = 1;
212
+ }
213
+ return;
214
+ }
215
+ const positional = [];
216
+ for (let i = 0; i < args.length; i += 1) {
217
+ if (args[i] === "--file") {
218
+ i += 1;
219
+ continue;
220
+ }
221
+ if (!args[i].startsWith("-")) positional.push(args[i]);
222
+ }
223
+ const targetDir = positional[0];
224
+ if (!targetDir) {
225
+ console.error("Usage: pie manager allow <dir> [--file <path>] [--force] [--backup-corrupt] [--json] | pie manager allow --list");
226
+ process.exitCode = 2;
227
+ return;
228
+ }
229
+ const result = addAllowedWorkerCwd(targetDir, { file: explicitFile, force, backupCorrupt });
230
+ if (json) {
231
+ console.log(JSON.stringify({ ok: true, ...result }));
232
+ return;
233
+ }
234
+ if (result.backedUpTo) console.log(`Backed up corrupt config to: ${result.backedUpTo}`);
235
+ if (result.shadowedFallback) {
236
+ console.log(`Note: created ${result.file}, which takes precedence over ${result.shadowedFallback}. Pass --file ${result.shadowedFallback} to update the shared policy instead.`);
237
+ }
238
+ console.log(
239
+ result.added ? `Authorized worker root "${result.canonicalDir}" in ${result.file} (effective immediately; no restart needed).` : `Worker root "${result.canonicalDir}" is already authorized in ${result.file}.`
240
+ );
241
+ }
242
+
243
+ export {
244
+ resolveProcConfigCandidates,
245
+ resolveEffectiveProcConfigFile,
246
+ resolveWritableProcConfigFile,
247
+ isTooBroadForWorkerSandbox,
248
+ seedProcConfig,
249
+ addAllowedWorkerCwd,
250
+ runManagerAllowCommand
251
+ };
@@ -0,0 +1,21 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ addAllowedWorkerCwd,
4
+ isTooBroadForWorkerSandbox,
5
+ resolveEffectiveProcConfigFile,
6
+ resolveProcConfigCandidates,
7
+ resolveWritableProcConfigFile,
8
+ runManagerAllowCommand,
9
+ seedProcConfig
10
+ } from "./chunk-Z2RT3P4F.js";
11
+ import "./chunk-CBDQJMUI.js";
12
+ import "./chunk-LZQXQOPJ.js";
13
+ export {
14
+ addAllowedWorkerCwd,
15
+ isTooBroadForWorkerSandbox,
16
+ resolveEffectiveProcConfigFile,
17
+ resolveProcConfigCandidates,
18
+ resolveWritableProcConfigFile,
19
+ runManagerAllowCommand,
20
+ seedProcConfig
21
+ };
@@ -1,10 +1,12 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ isTooBroadForWorkerSandbox,
4
+ seedProcConfig
5
+ } from "./chunk-Z2RT3P4F.js";
2
6
  import {
3
7
  readProcessCommandLine
4
8
  } from "./chunk-7RJXKN7N.js";
5
- import {
6
- getConfigDir
7
- } from "./chunk-CBDQJMUI.js";
9
+ import "./chunk-CBDQJMUI.js";
8
10
  import "./chunk-LZQXQOPJ.js";
9
11
 
10
12
  // src/commands/manager-cli.ts
@@ -337,56 +339,6 @@ function seedWorkspace(dir) {
337
339
  fs2.appendFileSync(agents, "\n> Note: the resident role is now named manager. Update the role card manually if you want the latest template.\n");
338
340
  }
339
341
  }
340
- function isTooBroadForWorkerSandbox(input) {
341
- let resolved;
342
- try {
343
- resolved = fs2.realpathSync(input);
344
- } catch {
345
- return true;
346
- }
347
- const root = path2.parse(resolved).root;
348
- if (resolved === root || resolved === os.homedir()) return true;
349
- const forbidden = [os.homedir(), os.tmpdir(), "/tmp", "/var/tmp", "/private/tmp", "/private/var/tmp"];
350
- for (const candidate of forbidden) {
351
- try {
352
- const real = fs2.realpathSync(candidate);
353
- if (resolved === real) return true;
354
- } catch {
355
- }
356
- }
357
- try {
358
- const stat = fs2.statSync(resolved);
359
- if ((stat.mode & 2) !== 0 && (stat.mode & 512) === 0) return true;
360
- } catch {
361
- return true;
362
- }
363
- return false;
364
- }
365
- function seedProcConfig(launchCwd) {
366
- const root = getConfigDir();
367
- const file = path2.join(root, "pie-proc.json");
368
- const resolved = path2.resolve(launchCwd);
369
- try {
370
- if (fs2.existsSync(file)) return { state: "exists", file, root };
371
- } catch {
372
- return { state: "exists", file, root };
373
- }
374
- const userLayer = path2.join(os.homedir(), ".pie", "pie-proc.json");
375
- try {
376
- if (fs2.existsSync(userLayer)) return { state: "user-layer", file: userLayer, root };
377
- } catch {
378
- }
379
- if (isTooBroadForWorkerSandbox(resolved)) {
380
- return { state: "too-broad", file, root };
381
- }
382
- fs2.mkdirSync(root, { recursive: true });
383
- fs2.writeFileSync(
384
- file,
385
- `${JSON.stringify({ allowCwd: [resolved] }, null, " ")}
386
- `
387
- );
388
- return { state: "seeded", file, root };
389
- }
390
342
  function cliEntry() {
391
343
  return process.argv[1] ? path2.resolve(process.argv[1]) : "";
392
344
  }
@@ -907,7 +859,7 @@ function withStartLock(dir, fn) {
907
859
  });
908
860
  }
909
861
  async function runUpgradeCommand(args) {
910
- const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-LSTOHBUV.js");
862
+ const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-XPFXKO7A.js");
911
863
  const targetIdx = args.indexOf("--target");
912
864
  if (targetIdx >= 0 && typeof args[targetIdx + 1] !== "string") {
913
865
  console.error('--target expects "latest" or an x.y.z version (no value given)');
@@ -1134,6 +1086,11 @@ async function runManagerCommand(args) {
1134
1086
  await runUpgradeCommand(args.slice(1));
1135
1087
  return;
1136
1088
  }
1089
+ if (sub === "allow") {
1090
+ const { runManagerAllowCommand } = await import("./manager-allow-SF5ROGDM.js");
1091
+ runManagerAllowCommand(args.slice(1));
1092
+ return;
1093
+ }
1137
1094
  if (sub === "tail") {
1138
1095
  const follow = args.includes("-f") || args.includes("--follow");
1139
1096
  const jsonOut = args.includes("--json");
@@ -1379,7 +1336,7 @@ async function runManagerCommand(args) {
1379
1336
  );
1380
1337
  } else if (procSeed.state === "too-broad") {
1381
1338
  console.log(
1382
- `Did not seed pie-proc config (the current directory ${path2.resolve(process.cwd())} is too broad). To dispatch work, write ${procSeed.file}: {"allowCwd": ["/your/project"]}`
1339
+ `Did not seed pie-proc config (the current directory ${path2.resolve(process.cwd())} is too broad). To dispatch work, run: pie manager allow /your/project (writes ${procSeed.file})`
1383
1340
  );
1384
1341
  }
1385
1342
  let readinessReport;
@@ -1,4 +1,10 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ normalizePreInstallStopOutcome,
4
+ resolveDefaultTuiUsePidFile,
5
+ runWindowsPreInstallStop,
6
+ scanBlockingWindowsPeers
7
+ } from "./chunk-BB7ETSJK.js";
2
8
  import {
3
9
  readProcessCommandLine
4
10
  } from "./chunk-7RJXKN7N.js";
@@ -245,22 +251,28 @@ async function performUpgrade(paths, effects, options) {
245
251
  stage = s;
246
252
  }, build));
247
253
  }
254
+ let stoppedBeforeInstall = false;
248
255
  if (effects.preInstallStop) {
249
- const stopped = effects.preInstallStop(state);
250
- if (stopped === "refused") {
251
- return finish(build("install", "refused: could not stop the resident/workers before install (Windows file locks); check pie manager status and retry"));
256
+ const stopped = normalizePreInstallStopOutcome(effects.preInstallStop(state));
257
+ if (stopped.status === "refused") {
258
+ return finish(build("install", stopped.detail || "refused: could not stop the resident/workers before install (Windows file locks); check pie manager status and retry"));
259
+ }
260
+ if (stopped.status === "stopped") {
261
+ stoppedBeforeInstall = true;
262
+ effects.log("windows: resident/workers stopped before install (native-module file locks)");
252
263
  }
253
- if (stopped === "stopped") effects.log("windows: resident/workers stopped before install (native-module file locks)");
254
264
  }
255
265
  const install = effects.npmInstall(toVersion);
256
266
  if (install.code !== 0) {
267
+ const recovery = stoppedBeforeInstall ? "\n(Windows: manager was stopped before install; run `pie manager start` or retry `pie manager upgrade`.)" : "";
257
268
  return finish(build("install", `npm install @cydm/pie@${toVersion} failed (exit ${install.code}):
258
- ${install.tail}`));
269
+ ${install.tail}${recovery}`));
259
270
  }
260
271
  const target = effects.installTargetCheck();
261
272
  if (!target.ok) {
273
+ const recovery = stoppedBeforeInstall ? "\n(Windows: manager was stopped before install; run `pie manager start` or retry `pie manager upgrade`.)" : "";
262
274
  return finish(build("install", `install target mismatch \u2014 restart skipped:
263
- ${target.detail}`));
275
+ ${target.detail}${recovery}`));
264
276
  }
265
277
  return finish(await restartAndRecycle(effects, paths, state, fromVersion, toVersion, (s) => {
266
278
  stage = s;
@@ -589,54 +601,67 @@ function cliEffects(paths, log) {
589
601
  },
590
602
  scanWorkers: () => scanWorkers(paths.discoveryDir),
591
603
  retireWorkerIfStillIdle: (peer) => {
604
+ const isPidAlive = (pid) => {
605
+ try {
606
+ process.kill(pid, 0);
607
+ return true;
608
+ } catch (error) {
609
+ return error.code !== "ESRCH";
610
+ }
611
+ };
592
612
  const fresh = readDiscoveryEntry(paths.discoveryDir, peer.file);
593
- if (!fresh || fresh.pid !== peer.pid) return "gone";
613
+ if (!fresh || fresh.pid !== peer.pid) return isPidAlive(peer.pid) ? "unknown" : "gone";
594
614
  if (fresh.unattended !== true || fresh.isManager === true) return "foreign";
595
615
  if (fresh.state !== "idle") return "busy";
596
- if (residentCommandLineLooksLikePie(peer.pid) === void 0) return "foreign";
616
+ const cmdline = readProcessCommandLine(peer.pid);
617
+ if (cmdline === void 0) return isPidAlive(peer.pid) ? "unknown" : "gone";
618
+ if (!cmdline || !/json-events/.test(cmdline) || !/--idle/.test(cmdline)) return "foreign";
597
619
  const updatedAt = typeof fresh.updatedAt === "number" ? fresh.updatedAt : peer.updatedAt;
598
620
  const startedAt = processStartedAt(peer.pid);
599
621
  if (updatedAt !== void 0 && startedAt !== void 0 && startedAt > updatedAt + 1e4) return "foreign";
600
622
  try {
601
623
  process.kill(peer.pid, process.platform === "win32" ? void 0 : "SIGTERM");
602
624
  return "retired";
603
- } catch {
604
- return "gone";
625
+ } catch (error) {
626
+ return error.code === "ESRCH" ? "gone" : "failed";
605
627
  }
606
628
  },
607
629
  writeResult: (result) => writeResultAtomic(paths.resultFile, result, log),
608
630
  tryLock: () => tryLockWithReclamation(paths.lockFile),
609
631
  unlock: () => unlockOwned(paths.lockFile),
610
- ...process.platform === "win32" ? { preInstallStop: (state) => {
611
- let touched = false;
612
- for (const peer of partitionWorkers(effects.scanWorkers()).recycle) {
613
- if (effects.retireWorkerIfStillIdle(peer) === "retired") {
614
- touched = true;
615
- effects.log(`windows pre-install: retired idle worker pid ${peer.pid} (${peer.name})`);
616
- }
617
- }
618
- if (state.service === true) {
619
- try {
620
- spawnSync("schtasks", ["/End", "/TN", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4, windowsHide: true });
621
- touched = true;
622
- } catch (error) {
623
- log(`windows pre-install: schtasks /End failed: ${error instanceof Error ? error.message : String(error)}`);
624
- return "refused";
625
- }
626
- } else {
627
- const status = effects.residentStatus(state);
628
- if (status === "foreign" || status === "unknown") return "refused";
629
- if (status === "alive") {
630
- const stopped = effects.terminateResident(state);
631
- if (stopped !== "terminated" && stopped !== "dead") return "refused";
632
- if (stopped === "terminated" && typeof state.pid === "number") {
633
- if (!effects.waitExit(state.pid, 2e4)) log(`windows pre-install: resident pid ${state.pid} did not exit within 20s; npm may still hit file locks`);
632
+ ...process.platform === "win32" ? {
633
+ preInstallStop: (state) => runWindowsPreInstallStop(state, {
634
+ scanBlockingPeers: (s) => scanBlockingWindowsPeers(paths.discoveryDir, s.sessionId, s.pid, {
635
+ tuiUsePidFile: resolveDefaultTuiUsePidFile()
636
+ }),
637
+ scanIdleWorkers: () => partitionWorkers(effects.scanWorkers()).recycle,
638
+ retireWorkerIfStillIdle: (peer) => effects.retireWorkerIfStillIdle(peer),
639
+ findManagerResident: (sid) => findManagerResident(paths.discoveryDir, sid),
640
+ residentStatus: (s) => effects.residentStatus(s),
641
+ terminateResident: (s) => effects.terminateResident(s),
642
+ endServiceTask: () => {
643
+ const r = spawnSync("schtasks", ["/End", "/TN", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4, windowsHide: true });
644
+ return {
645
+ status: r.status,
646
+ detail: `${r.stdout ?? ""} ${r.stderr ?? ""}`.trim().slice(0, 200),
647
+ ...r.error ? { spawnError: r.error.message } : {}
648
+ };
649
+ },
650
+ waitExit: (pid, timeoutMs) => effects.waitExit(pid, timeoutMs),
651
+ isPidAlive: (pid) => {
652
+ try {
653
+ process.kill(pid, 0);
654
+ return true;
655
+ } catch (error) {
656
+ return error.code !== "ESRCH";
634
657
  }
635
- touched = true;
636
- }
637
- }
638
- return touched ? "stopped" : "unnecessary";
639
- } } : {},
658
+ },
659
+ settleAfterStop: () => {
660
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 300);
661
+ },
662
+ log
663
+ })
664
+ } : {},
640
665
  log
641
666
  };
642
667
  return effects;