@cydm/pie 4.5.0 → 4.6.0

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.
@@ -1,18 +1,120 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  readProcessCommandLine
4
- } from "./chunk-X6LBWHK3.js";
4
+ } from "./chunk-7RJXKN7N.js";
5
5
  import {
6
6
  getConfigDir
7
7
  } from "./chunk-CBDQJMUI.js";
8
8
  import "./chunk-LZQXQOPJ.js";
9
9
 
10
10
  // src/commands/manager-cli.ts
11
- import { spawn, execFileSync } from "node:child_process";
11
+ import { spawn, execFileSync as execFileSync2 } from "node:child_process";
12
12
  import { createRequire } from "node:module";
13
- import * as fs from "node:fs";
13
+ import * as fs2 from "node:fs";
14
14
  import * as os from "node:os";
15
+ import * as path2 from "node:path";
16
+
17
+ // src/commands/manager-service-windows.ts
18
+ import * as fs from "node:fs";
15
19
  import * as path from "node:path";
20
+ import { execFileSync } from "node:child_process";
21
+ function installWindowsManagerLauncher(dir, node, entry, sessionId, env) {
22
+ const systemRoot = process.env.SystemRoot || "C:\\Windows";
23
+ const compiler = ["Framework64", "Framework"].map((folder) => path.join(systemRoot, "Microsoft.NET", folder, "v4.0.30319", "csc.exe")).find((file) => fs.existsSync(file));
24
+ if (!compiler) throw new Error("Windows .NET Framework compiler is unavailable; manager service was not changed.");
25
+ const cs = (value) => `@"${value.replace(/"/g, '""')}"`;
26
+ const launcher = path.join(dir, "service-launcher.exe");
27
+ const source = path.join(dir, "service-launcher.cs");
28
+ const output = path.join(dir, `service-launcher.${process.pid}.exe`);
29
+ const command = `"${node}" "${entry}" --json-events --idle --session-id "${sessionId}"`;
30
+ const assignments = env.filter(([, value]) => typeof value === "string" && value.length > 0).map(([key, value]) => `Environment.SetEnvironmentVariable(${cs(key)}, ${cs(value)});`).join("\n ");
31
+ fs.writeFileSync(source, `// Generated by Pie. Reinstall the service to refresh this launcher.
32
+ using System;
33
+ using System.ComponentModel;
34
+ using System.IO;
35
+ using System.Runtime.InteropServices;
36
+ using System.Text;
37
+
38
+ internal static class PieManagerService {
39
+ [StructLayout(LayoutKind.Sequential)] struct SECURITY_ATTRIBUTES { public int Length; public IntPtr Descriptor; public int Inherit; }
40
+ [StructLayout(LayoutKind.Sequential)] struct STARTUPINFO {
41
+ public int Size; public string Reserved, Desktop, Title;
42
+ public int X, Y, XSize, YSize, XCountChars, YCountChars, FillAttribute, Flags;
43
+ public short ShowWindow, ReservedSize; public IntPtr Reserved2, Input, Output, Error;
44
+ }
45
+ [StructLayout(LayoutKind.Sequential)] struct PROCESS_INFORMATION { public IntPtr Process, Thread; public uint ProcessId, ThreadId; }
46
+ [StructLayout(LayoutKind.Sequential)] struct BASIC_LIMITS {
47
+ public long ProcessTime, JobTime; public uint Flags; public UIntPtr MinWorkingSet, MaxWorkingSet;
48
+ public uint ActiveProcesses; public UIntPtr Affinity; public uint PriorityClass, SchedulingClass;
49
+ }
50
+ [StructLayout(LayoutKind.Sequential)] struct IO_COUNTERS { public ulong ReadOps, WriteOps, OtherOps, ReadBytes, WriteBytes, OtherBytes; }
51
+ [StructLayout(LayoutKind.Sequential)] struct EXTENDED_LIMITS {
52
+ public BASIC_LIMITS Basic; public IO_COUNTERS Io; public UIntPtr ProcessMemory, JobMemory, PeakProcessMemory, PeakJobMemory;
53
+ }
54
+ [DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern IntPtr CreateJobObject(IntPtr attributes, string name);
55
+ [DllImport("kernel32.dll", SetLastError=true)] static extern bool SetInformationJobObject(IntPtr job, int type, ref EXTENDED_LIMITS limits, uint size);
56
+ [DllImport("kernel32.dll", SetLastError=true)] static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
57
+ [DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern bool CreateProcess(string app, StringBuilder command, IntPtr pa, IntPtr ta, bool inherit, uint flags, IntPtr env, string cwd, ref STARTUPINFO startup, out PROCESS_INFORMATION process);
58
+ [DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern IntPtr CreateFile(string name, uint access, uint share, ref SECURITY_ATTRIBUTES attributes, uint disposition, uint flags, IntPtr template);
59
+ [DllImport("kernel32.dll", SetLastError=true)] static extern uint ResumeThread(IntPtr thread);
60
+ [DllImport("kernel32.dll", SetLastError=true)] static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
61
+ [DllImport("kernel32.dll", SetLastError=true)] static extern bool GetExitCodeProcess(IntPtr process, out uint code);
62
+ [DllImport("kernel32.dll", SetLastError=true)] static extern bool TerminateProcess(IntPtr process, uint code);
63
+ [DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr handle);
64
+ static void Check(bool ok) { if (!ok) throw new Win32Exception(Marshal.GetLastWin32Error()); }
65
+ static void Close(IntPtr handle) { if (handle != IntPtr.Zero && handle != new IntPtr(-1)) CloseHandle(handle); }
66
+
67
+ static int Main() {
68
+ IntPtr job = IntPtr.Zero, input = IntPtr.Zero, output = IntPtr.Zero;
69
+ PROCESS_INFORMATION child = new PROCESS_INFORMATION();
70
+ bool assigned = false;
71
+ try {
72
+ ${assignments}
73
+ job = CreateJobObject(IntPtr.Zero, null);
74
+ Check(job != IntPtr.Zero);
75
+ EXTENDED_LIMITS limits = new EXTENDED_LIMITS();
76
+ limits.Basic.Flags = 0x2000; // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
77
+ Check(SetInformationJobObject(job, 9, ref limits, (uint)Marshal.SizeOf(typeof(EXTENDED_LIMITS))));
78
+ SECURITY_ATTRIBUTES inherit = new SECURITY_ATTRIBUTES();
79
+ inherit.Length = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)); inherit.Inherit = 1;
80
+ input = CreateFile("NUL", 0x80000000, 3, ref inherit, 3, 0, IntPtr.Zero);
81
+ Check(input != new IntPtr(-1));
82
+ output = CreateFile(${cs(path.join(dir, "log.jsonl"))}, 4, 3, ref inherit, 4, 0, IntPtr.Zero); // FILE_APPEND_DATA, OPEN_ALWAYS
83
+ Check(output != new IntPtr(-1));
84
+ STARTUPINFO startup = new STARTUPINFO();
85
+ startup.Size = Marshal.SizeOf(typeof(STARTUPINFO)); startup.Flags = 0x100; // USESTDHANDLES
86
+ startup.Input = input; startup.Output = output; startup.Error = output;
87
+ // CREATE_NO_WINDOW | CREATE_SUSPENDED. The job handle is NOT inheritable.
88
+ Check(CreateProcess(${cs(node)}, new StringBuilder(${cs(command)}), IntPtr.Zero, IntPtr.Zero, true, 0x08000004, IntPtr.Zero, ${cs(dir)}, ref startup, out child));
89
+ Check(AssignProcessToJobObject(job, child.Process)); assigned = true;
90
+ Check(ResumeThread(child.Thread) != UInt32.MaxValue);
91
+ Check(WaitForSingleObject(child.Process, UInt32.MaxValue) == 0);
92
+ uint code; Check(GetExitCodeProcess(child.Process, out code));
93
+ return unchecked((int)code);
94
+ } catch (Exception error) {
95
+ try { File.AppendAllText(${cs(path.join(dir, "service-launcher.log"))}, DateTime.UtcNow.ToString("o") + " " + error + Environment.NewLine); } catch {}
96
+ return 1;
97
+ } finally {
98
+ if (!assigned && child.Process != IntPtr.Zero) TerminateProcess(child.Process, 1);
99
+ Close(job); Close(child.Thread); Close(child.Process); Close(input); Close(output);
100
+ }
101
+ }
102
+ }
103
+ `, { encoding: "utf8", mode: 384 });
104
+ try {
105
+ execFileSync(compiler, ["/nologo", "/target:winexe", "/platform:anycpu", "/optimize+", `/out:${output}`, source], {
106
+ windowsHide: true,
107
+ stdio: ["ignore", "pipe", "pipe"],
108
+ timeout: 3e4
109
+ });
110
+ fs.renameSync(output, launcher);
111
+ } finally {
112
+ fs.rmSync(output, { force: true });
113
+ }
114
+ return launcher;
115
+ }
116
+
117
+ // src/commands/manager-cli.ts
16
118
  var require_ = createRequire(import.meta.url);
17
119
  var CRON_SECTION_MARKER = "## \u5B9A\u65F6\u4EFB\u52A1";
18
120
  var CRON_SECTION = `
@@ -48,33 +150,33 @@ var SEED_AGENTS_MD = `# Pie Manager (manager)
48
150
  - \u6D88\u606F\u6CA1\u6536\u5230 reaction \u65F6\u4E0D\u8981\u8BA9\u5B83\u60AC\u7740\uFF1A\u540C\u4E00\u4EFD\u6B63\u6587\u518D\u53D1\u4E00\u6B21\u5373\u53EF\uFF08\u4E0D\u5E26\u5F15\u7528\uFF09\uFF0C\u6216\u52A0 \`\u4F1A\u8BDD\u540D:\` \u6307\u5B9A\u76EE\u6807\u3002
49
151
  ${CRON_SECTION}`;
50
152
  function workspaceDir() {
51
- const dir = path.join(os.homedir(), ".pie", "manager");
153
+ const dir = path2.join(os.homedir(), ".pie", "manager");
52
154
  migrateLegacyWorkspace(dir);
53
155
  return dir;
54
156
  }
55
157
  function tailWorkspaceDir() {
56
- const dir = path.join(os.homedir(), ".pie", "manager");
57
- if (fs.existsSync(dir)) return dir;
58
- const legacy = path.join(os.homedir(), ".pie", "concierge");
59
- return fs.existsSync(legacy) ? legacy : dir;
158
+ const dir = path2.join(os.homedir(), ".pie", "manager");
159
+ if (fs2.existsSync(dir)) return dir;
160
+ const legacy = path2.join(os.homedir(), ".pie", "concierge");
161
+ return fs2.existsSync(legacy) ? legacy : dir;
60
162
  }
61
163
  var migrationChecked = false;
62
164
  function migrateLegacyWorkspace(newDir) {
63
165
  if (migrationChecked) return;
64
166
  migrationChecked = true;
65
- const legacy = path.join(os.homedir(), ".pie", "concierge");
66
- if (!fs.existsSync(legacy)) return;
67
- if (fs.existsSync(newDir)) {
167
+ const legacy = path2.join(os.homedir(), ".pie", "concierge");
168
+ if (!fs2.existsSync(legacy)) return;
169
+ if (fs2.existsSync(newDir)) {
68
170
  console.warn(`Both ~/.pie/manager and the legacy ~/.pie/concierge exist; leaving the legacy directory untouched. Merge manually if needed.`);
69
171
  return;
70
172
  }
71
173
  try {
72
- fs.mkdirSync(path.dirname(newDir), { recursive: true });
73
- fs.renameSync(legacy, newDir);
74
- const legacyState = path.join(newDir, "concierge.json");
75
- if (fs.existsSync(legacyState)) {
174
+ fs2.mkdirSync(path2.dirname(newDir), { recursive: true });
175
+ fs2.renameSync(legacy, newDir);
176
+ const legacyState = path2.join(newDir, "concierge.json");
177
+ if (fs2.existsSync(legacyState)) {
76
178
  try {
77
- fs.renameSync(legacyState, path.join(newDir, "manager.json"));
179
+ fs2.renameSync(legacyState, path2.join(newDir, "manager.json"));
78
180
  } catch {
79
181
  }
80
182
  }
@@ -84,17 +186,17 @@ function migrateLegacyWorkspace(newDir) {
84
186
  }
85
187
  }
86
188
  function ensureSessionToken(dir) {
87
- const tokenFile = path.join(dir, "session-token");
189
+ const tokenFile = path2.join(dir, "session-token");
88
190
  for (let attempt = 0; attempt < 5; attempt += 1) {
89
191
  const mine = `manager-${os.hostname().split(".")[0]}-${Math.random().toString(36).slice(2, 8)}`;
90
192
  const tmp = `${tokenFile}.${process.pid}.${attempt}.tmp`;
91
193
  let tmpKept = false;
92
194
  try {
93
- fs.writeFileSync(tmp, mine);
195
+ fs2.writeFileSync(tmp, mine);
94
196
  tmpKept = true;
95
- fs.linkSync(tmp, tokenFile);
197
+ fs2.linkSync(tmp, tokenFile);
96
198
  try {
97
- fs.rmSync(tmp, { force: true });
199
+ fs2.rmSync(tmp, { force: true });
98
200
  tmpKept = false;
99
201
  } catch {
100
202
  }
@@ -102,7 +204,7 @@ function ensureSessionToken(dir) {
102
204
  if (error.code !== "EEXIST") {
103
205
  if (tmpKept) {
104
206
  try {
105
- fs.rmSync(tmp, { force: true });
207
+ fs2.rmSync(tmp, { force: true });
106
208
  } catch {
107
209
  }
108
210
  }
@@ -110,7 +212,7 @@ function ensureSessionToken(dir) {
110
212
  }
111
213
  const existing = (() => {
112
214
  try {
113
- return fs.readFileSync(tokenFile, "utf8").trim();
215
+ return fs2.readFileSync(tokenFile, "utf8").trim();
114
216
  } catch {
115
217
  return "";
116
218
  }
@@ -118,21 +220,21 @@ function ensureSessionToken(dir) {
118
220
  if (existing) {
119
221
  if (tmpKept) {
120
222
  try {
121
- fs.rmSync(tmp, { force: true });
223
+ fs2.rmSync(tmp, { force: true });
122
224
  } catch {
123
225
  }
124
226
  }
125
227
  return existing;
126
228
  }
127
229
  try {
128
- fs.renameSync(tmp, tokenFile);
230
+ fs2.renameSync(tmp, tokenFile);
129
231
  tmpKept = false;
130
232
  } catch {
131
233
  }
132
234
  }
133
235
  const settled = (() => {
134
236
  try {
135
- return fs.readFileSync(tokenFile, "utf8").trim();
237
+ return fs2.readFileSync(tokenFile, "utf8").trim();
136
238
  } catch {
137
239
  return "";
138
240
  }
@@ -140,7 +242,7 @@ function ensureSessionToken(dir) {
140
242
  if (settled) return settled;
141
243
  if (tmpKept) {
142
244
  try {
143
- fs.rmSync(tmp, { force: true });
245
+ fs2.rmSync(tmp, { force: true });
144
246
  } catch {
145
247
  }
146
248
  }
@@ -148,20 +250,20 @@ function ensureSessionToken(dir) {
148
250
  throw new Error("cannot establish the manager workspace token; retry");
149
251
  }
150
252
  function statePath(dir = workspaceDir()) {
151
- const current = path.join(dir, "manager.json");
152
- if (!fs.existsSync(current)) {
153
- const legacy = path.join(dir, "concierge.json");
154
- if (fs.existsSync(legacy)) return legacy;
253
+ const current = path2.join(dir, "manager.json");
254
+ if (!fs2.existsSync(current)) {
255
+ const legacy = path2.join(dir, "concierge.json");
256
+ if (fs2.existsSync(legacy)) return legacy;
155
257
  }
156
258
  return current;
157
259
  }
158
260
  function logPath(dir = workspaceDir()) {
159
- return path.join(dir, "log.jsonl");
261
+ return path2.join(dir, "log.jsonl");
160
262
  }
161
263
  function readState(dir = workspaceDir()) {
162
264
  try {
163
265
  const raw = JSON.parse(
164
- fs.readFileSync(statePath(dir), "utf8")
266
+ fs2.readFileSync(statePath(dir), "utf8")
165
267
  );
166
268
  return typeof raw.sessionId === "string" && raw.sessionId ? raw : void 0;
167
269
  } catch {
@@ -169,10 +271,10 @@ function readState(dir = workspaceDir()) {
169
271
  }
170
272
  }
171
273
  function writeState(state, dir = workspaceDir()) {
172
- fs.mkdirSync(dir, { recursive: true });
274
+ fs2.mkdirSync(dir, { recursive: true });
173
275
  const tmp = `${statePath(dir)}.${process.pid}.tmp`;
174
- fs.writeFileSync(tmp, JSON.stringify(state, null, " "));
175
- fs.renameSync(tmp, statePath(dir));
276
+ fs2.writeFileSync(tmp, JSON.stringify(state, null, " "));
277
+ fs2.renameSync(tmp, statePath(dir));
176
278
  }
177
279
  function managerLiveness(pid, state) {
178
280
  if (!pid || pid <= 0) return "dead";
@@ -196,51 +298,51 @@ function isConciergeAlive(pid, state) {
196
298
  return managerLiveness(pid, state) === "alive";
197
299
  }
198
300
  function seedWorkspace(dir) {
199
- fs.mkdirSync(path.join(dir, ".pie"), { recursive: true });
200
- const agents = path.join(dir, "AGENTS.md");
201
- if (!fs.existsSync(agents)) {
202
- fs.writeFileSync(agents, SEED_AGENTS_MD);
301
+ fs2.mkdirSync(path2.join(dir, ".pie"), { recursive: true });
302
+ const agents = path2.join(dir, "AGENTS.md");
303
+ if (!fs2.existsSync(agents)) {
304
+ fs2.writeFileSync(agents, SEED_AGENTS_MD);
203
305
  return;
204
306
  }
205
307
  let current;
206
308
  try {
207
- current = fs.readFileSync(agents, "utf8");
309
+ current = fs2.readFileSync(agents, "utf8");
208
310
  } catch {
209
311
  return;
210
312
  }
211
- if (!current.includes(CRON_SECTION_MARKER)) fs.appendFileSync(agents, CRON_SECTION);
313
+ if (!current.includes(CRON_SECTION_MARKER)) fs2.appendFileSync(agents, CRON_SECTION);
212
314
  const v1Marker = "\u4F60\u662F\u7528\u6237\u5728 IM \u4E0A\u7684\u552F\u4E00\u8054\u7EDC\u70B9\u3002\u9ED8\u8BA4\u6D3E\u6D3B";
213
315
  const v2Marker = "\u4F60\u662F\u88AB\u52A8\u8D77\u6B65\u7684";
214
316
  if (current.includes(v1Marker) && !current.includes(v2Marker)) {
215
- fs.writeFileSync(agents, SEED_AGENTS_MD);
317
+ fs2.writeFileSync(agents, SEED_AGENTS_MD);
216
318
  }
217
319
  const oldV2Intro = "\u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B\u7BA1\u5BB6 pie";
218
320
  const newV2Intro = "\u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B manager pie";
219
321
  if (current.includes(oldV2Intro) && !current.includes(newV2Intro)) {
220
- fs.writeFileSync(agents, SEED_AGENTS_MD);
322
+ fs2.writeFileSync(agents, SEED_AGENTS_MD);
221
323
  } else if (current.includes("\u7BA1\u5BB6") && current.includes(v2Marker) && !current.includes(newV2Intro)) {
222
- fs.appendFileSync(agents, "\n> \u6CE8\u610F\uFF1A\u5E38\u9A7B\u89D2\u8272\u5DF2\u66F4\u540D manager\uFF08\u539F\u300C\u7BA1\u5BB6\u300D\uFF09\u3002\u5982\u9700\u65B0\u7248\u89D2\u8272\u5361\u53EF\u624B\u52A8\u66F4\u65B0\u3002\n");
324
+ fs2.appendFileSync(agents, "\n> Note: the resident role is now named manager. Update the role card manually if you want the latest template.\n");
223
325
  }
224
326
  }
225
327
  function isTooBroadForWorkerSandbox(input) {
226
328
  let resolved;
227
329
  try {
228
- resolved = fs.realpathSync(input);
330
+ resolved = fs2.realpathSync(input);
229
331
  } catch {
230
332
  return true;
231
333
  }
232
- const root = path.parse(resolved).root;
334
+ const root = path2.parse(resolved).root;
233
335
  if (resolved === root || resolved === os.homedir()) return true;
234
336
  const forbidden = [os.tmpdir(), "/tmp", "/var/tmp", "/private/tmp", "/private/var/tmp"];
235
337
  for (const candidate of forbidden) {
236
338
  try {
237
- const real = fs.realpathSync(candidate);
339
+ const real = fs2.realpathSync(candidate);
238
340
  if (resolved === real) return true;
239
341
  } catch {
240
342
  }
241
343
  }
242
344
  try {
243
- const stat = fs.statSync(resolved);
345
+ const stat = fs2.statSync(resolved);
244
346
  if ((stat.mode & 2) !== 0 && (stat.mode & 512) === 0) return true;
245
347
  } catch {
246
348
  return true;
@@ -249,18 +351,23 @@ function isTooBroadForWorkerSandbox(input) {
249
351
  }
250
352
  function seedProcConfig(launchCwd) {
251
353
  const root = getConfigDir();
252
- const file = path.join(root, "pie-proc.json");
253
- const resolved = path.resolve(launchCwd);
354
+ const file = path2.join(root, "pie-proc.json");
355
+ const resolved = path2.resolve(launchCwd);
254
356
  try {
255
- if (fs.existsSync(file)) return { state: "exists", file, root };
357
+ if (fs2.existsSync(file)) return { state: "exists", file, root };
256
358
  } catch {
257
359
  return { state: "exists", file, root };
258
360
  }
361
+ const userLayer = path2.join(os.homedir(), ".pie", "pie-proc.json");
362
+ try {
363
+ if (fs2.existsSync(userLayer)) return { state: "user-layer", file: userLayer, root };
364
+ } catch {
365
+ }
259
366
  if (isTooBroadForWorkerSandbox(resolved)) {
260
367
  return { state: "too-broad", file, root };
261
368
  }
262
- fs.mkdirSync(root, { recursive: true });
263
- fs.writeFileSync(
369
+ fs2.mkdirSync(root, { recursive: true });
370
+ fs2.writeFileSync(
264
371
  file,
265
372
  `${JSON.stringify({ allowCwd: [resolved] }, null, " ")}
266
373
  `
@@ -268,15 +375,15 @@ function seedProcConfig(launchCwd) {
268
375
  return { state: "seeded", file, root };
269
376
  }
270
377
  function cliEntry() {
271
- return process.argv[1] ? path.resolve(process.argv[1]) : "";
378
+ return process.argv[1] ? path2.resolve(process.argv[1]) : "";
272
379
  }
273
380
  function resolveTsxLoaderUrl() {
274
381
  for (let i = 0; i < process.execArgv.length - 1; i += 1) {
275
382
  if (process.execArgv[i] === "--import") {
276
383
  const target = process.execArgv[i + 1];
277
- if (target && !path.isAbsolute(target) && !target.startsWith("file:")) {
384
+ if (target && !path2.isAbsolute(target) && !target.startsWith("file:")) {
278
385
  try {
279
- return require_.resolve(target, { paths: [path.dirname(cliEntry())] }) ? pathToFileURLResolved(target) : target;
386
+ return require_.resolve(target, { paths: [path2.dirname(cliEntry())] }) ? pathToFileURLResolved(target) : target;
280
387
  } catch {
281
388
  return target;
282
389
  }
@@ -288,12 +395,12 @@ function resolveTsxLoaderUrl() {
288
395
  }
289
396
  function pathToFileURLResolved(spec) {
290
397
  try {
291
- const pkgRoot = path.dirname(
398
+ const pkgRoot = path2.dirname(
292
399
  require_.resolve(`${spec}/package.json`, {
293
- paths: [path.dirname(cliEntry())]
400
+ paths: [path2.dirname(cliEntry())]
294
401
  })
295
402
  );
296
- return path.join(pkgRoot, "dist", "loader.mjs");
403
+ return path2.join(pkgRoot, "dist", "loader.mjs");
297
404
  } catch {
298
405
  return spec;
299
406
  }
@@ -301,7 +408,7 @@ function pathToFileURLResolved(spec) {
301
408
  function spawnResident(state, dir) {
302
409
  const entry = cliEntry();
303
410
  if (!entry) throw new Error("cannot resolve the pie entry point");
304
- const out = fs.openSync(logPath(dir), "a");
411
+ const out = fs2.openSync(logPath(dir), "a");
305
412
  const loaderAbs = resolveTsxLoaderUrl();
306
413
  const passthrough = loaderAbs ? ["--import", loaderAbs] : process.execArgv.filter(
307
414
  (a) => a !== "--import" && !a.startsWith("--import=")
@@ -332,13 +439,13 @@ async function waitForAgentReady(dir, timeoutMs, sinceOffset, expectedSessionId)
332
439
  const deadline = Date.now() + timeoutMs;
333
440
  while (Date.now() < deadline) {
334
441
  try {
335
- const size = fs.statSync(logPath(dir)).size;
442
+ const size = fs2.statSync(logPath(dir)).size;
336
443
  if (size > sinceOffset) {
337
- const fd = fs.openSync(logPath(dir), "r");
444
+ const fd = fs2.openSync(logPath(dir), "r");
338
445
  try {
339
446
  const length = Math.min(size - sinceOffset, 65536);
340
447
  const buffer = Buffer.alloc(length);
341
- fs.readSync(
448
+ fs2.readSync(
342
449
  fd,
343
450
  buffer,
344
451
  0,
@@ -349,7 +456,7 @@ async function waitForAgentReady(dir, timeoutMs, sinceOffset, expectedSessionId)
349
456
  if (slice.includes('"type":"agent.ready"') && slice.includes(expectedSessionId))
350
457
  return true;
351
458
  } finally {
352
- fs.closeSync(fd);
459
+ fs2.closeSync(fd);
353
460
  }
354
461
  }
355
462
  } catch {
@@ -360,12 +467,12 @@ async function waitForAgentReady(dir, timeoutMs, sinceOffset, expectedSessionId)
360
467
  }
361
468
  function imForwardConfigured(dir) {
362
469
  const layers = [
363
- path.join(dir, ".pie", "im-forward.json"),
364
- path.join(os.homedir(), ".pie", "im-forward.json")
470
+ path2.join(dir, ".pie", "im-forward.json"),
471
+ path2.join(os.homedir(), ".pie", "im-forward.json")
365
472
  ];
366
473
  for (const layer of layers) {
367
474
  try {
368
- const parsed = JSON.parse(fs.readFileSync(layer, "utf8"));
475
+ const parsed = JSON.parse(fs2.readFileSync(layer, "utf8"));
369
476
  if (typeof parsed.provider === "string") return true;
370
477
  } catch {
371
478
  }
@@ -387,8 +494,8 @@ To bind a separate app for the manager only, put a project-layer config at ~/.pi
387
494
  function managerSpawnEnv() {
388
495
  const env = { ...process.env, PIE_PROC_CURATED_NAME: "manager" };
389
496
  try {
390
- const configPath = path.join(workspaceDir(), "config.json");
391
- const parsed = JSON.parse(fs.readFileSync(configPath, "utf8"));
497
+ const configPath = path2.join(workspaceDir(), "config.json");
498
+ const parsed = JSON.parse(fs2.readFileSync(configPath, "utf8"));
392
499
  const provider = typeof parsed.provider === "string" ? parsed.provider.trim() : "";
393
500
  const modelId = typeof parsed.modelId === "string" ? parsed.modelId.trim() : "";
394
501
  if (provider && modelId) {
@@ -403,6 +510,14 @@ function managerSpawnEnv() {
403
510
  function platformServiceName() {
404
511
  return "dev.pie.manager";
405
512
  }
513
+ function requestWindowsServiceStart(dir) {
514
+ execFileSync2("schtasks", ["/Run", "/TN", platformServiceName()], {
515
+ stdio: ["ignore", "pipe", "pipe"],
516
+ windowsHide: true,
517
+ timeout: 2e4
518
+ });
519
+ console.log(`Manager service start requested (schtasks /Run). Log: ${logPath(dir)}`);
520
+ }
406
521
  function xmlEscape(value) {
407
522
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
408
523
  }
@@ -428,9 +543,9 @@ function installService(dir, state) {
428
543
  if (typeof value !== "string" || value.length === 0) return void 0;
429
544
  const home = os.homedir() || process.env.HOME || process.env.USERPROFILE || "/tmp";
430
545
  if (value === "~") return home;
431
- if (value.startsWith("~/")) return path.resolve(path.join(home, value.slice(2)));
432
- if (path.isAbsolute(value)) return value;
433
- return path.resolve(value);
546
+ if (value.startsWith("~/")) return path2.resolve(path2.join(home, value.slice(2)));
547
+ if (path2.isAbsolute(value)) return value;
548
+ return path2.resolve(value);
434
549
  };
435
550
  const serviceEnv = [
436
551
  ["PIE_PROC_CURATED_NAME", "manager"],
@@ -459,25 +574,25 @@ ${envPlist}
459
574
  <key>StandardOutPath</key><string>${xmlEscape(logFile)}</string>
460
575
  <key>StandardErrorPath</key><string>${xmlEscape(logFile)}</string>
461
576
  </dict></plist>`;
462
- const target = path.join(
577
+ const target = path2.join(
463
578
  os.homedir(),
464
579
  "Library",
465
580
  "LaunchAgents",
466
581
  `${platformServiceName()}.plist`
467
582
  );
468
- fs.mkdirSync(path.dirname(target), { recursive: true });
469
- fs.writeFileSync(target, plist);
583
+ fs2.mkdirSync(path2.dirname(target), { recursive: true });
584
+ fs2.writeFileSync(target, plist);
470
585
  try {
471
- execFileSync("launchctl", ["unload", target], { stdio: "ignore" });
586
+ execFileSync2("launchctl", ["unload", target], { stdio: "ignore" });
472
587
  } catch {
473
588
  }
474
- execFileSync("launchctl", ["load", target]);
589
+ execFileSync2("launchctl", ["load", target]);
475
590
  console.log(`Installed launchd service: ${target} (RunAtLoad + KeepAlive)`);
476
591
  return;
477
592
  }
478
593
  if (process.platform === "linux") {
479
- const unitDir = path.join(os.homedir(), ".config", "systemd", "user");
480
- fs.mkdirSync(unitDir, { recursive: true });
594
+ const unitDir = path2.join(os.homedir(), ".config", "systemd", "user");
595
+ fs2.mkdirSync(unitDir, { recursive: true });
481
596
  const unit = `[Unit]
482
597
  Description=Pie manager (resident im-forward host)
483
598
  After=network-online.target
@@ -497,10 +612,10 @@ StandardError=append:${systemdScalarPath(logFile)}
497
612
 
498
613
  [Install]
499
614
  WantedBy=default.target`;
500
- const unitPath = path.join(unitDir, `${platformServiceName()}.service`);
501
- fs.writeFileSync(unitPath, unit);
502
- execFileSync("systemctl", ["--user", "daemon-reload"]);
503
- execFileSync("systemctl", [
615
+ const unitPath = path2.join(unitDir, `${platformServiceName()}.service`);
616
+ fs2.writeFileSync(unitPath, unit);
617
+ execFileSync2("systemctl", ["--user", "daemon-reload"]);
618
+ execFileSync2("systemctl", [
504
619
  "--user",
505
620
  "enable",
506
621
  "--now",
@@ -510,22 +625,25 @@ WantedBy=default.target`;
510
625
  return;
511
626
  }
512
627
  if (process.platform === "win32") {
513
- const envSets = serviceEnv.filter(([, v]) => typeof v === "string" && v.length > 0).map(([k, v]) => `set "${k}=${v}" && `).join("");
514
- const cmd = `cd /d "${dir}" && ${envSets}"${process.execPath}" "${entry}" --json-events --idle --session-id ${state.sessionId} >> "${logFile}" 2>&1`;
515
- execFileSync("schtasks", [
628
+ const silentLauncher = installWindowsManagerLauncher(dir, process.execPath, entry, state.sessionId, [
629
+ ...serviceEnv,
630
+ ["PATH", servicePath]
631
+ ]);
632
+ const taskCmd = '"%USERPROFILE%\\.pie\\manager\\service-launcher.exe"';
633
+ execFileSync2("schtasks", [
516
634
  "/Create",
517
635
  "/TN",
518
636
  platformServiceName(),
519
637
  "/TR",
520
- cmd,
638
+ taskCmd,
521
639
  "/SC",
522
640
  "ONLOGON",
523
641
  "/RL",
524
642
  "LIMITED",
525
643
  "/F"
526
- ]);
644
+ ], { windowsHide: true });
527
645
  console.log(
528
- `Installed scheduled task: ${platformServiceName()} (runs at logon; set restart-on-failure in Task Scheduler)`
646
+ `Installed scheduled task: ${platformServiceName()} (runs at logon without a console via ${silentLauncher}; set restart-on-failure in Task Scheduler)`
529
647
  );
530
648
  return;
531
649
  }
@@ -535,7 +653,7 @@ WantedBy=default.target`;
535
653
  }
536
654
  function uninstallService() {
537
655
  if (process.platform === "darwin") {
538
- const target = path.join(
656
+ const target = path2.join(
539
657
  os.homedir(),
540
658
  "Library",
541
659
  "LaunchAgents",
@@ -543,14 +661,14 @@ function uninstallService() {
543
661
  );
544
662
  let unloaded = false;
545
663
  try {
546
- execFileSync("launchctl", ["unload", target], { stdio: "ignore" });
664
+ execFileSync2("launchctl", ["unload", target], { stdio: "ignore" });
547
665
  unloaded = true;
548
666
  } catch {
549
- unloaded = !fs.existsSync(target);
667
+ unloaded = !fs2.existsSync(target);
550
668
  }
551
669
  if (unloaded) {
552
670
  try {
553
- fs.rmSync(target);
671
+ fs2.rmSync(target);
554
672
  console.log(`Uninstalled launchd service: ${target}`);
555
673
  } catch {
556
674
  console.log("No installed service found (the plist is already gone).");
@@ -565,21 +683,21 @@ function uninstallService() {
565
683
  if (process.platform === "linux") {
566
684
  let ok = true;
567
685
  try {
568
- execFileSync("systemctl", [
686
+ execFileSync2("systemctl", [
569
687
  "--user",
570
688
  "disable",
571
689
  "--now",
572
690
  platformServiceName()
573
691
  ]);
574
692
  } catch {
575
- const unitPath2 = path.join(
693
+ const unitPath2 = path2.join(
576
694
  os.homedir(),
577
695
  ".config",
578
696
  "systemd",
579
697
  "user",
580
698
  `${platformServiceName()}.service`
581
699
  );
582
- ok = !fs.existsSync(unitPath2);
700
+ ok = !fs2.existsSync(unitPath2);
583
701
  if (!ok) {
584
702
  console.error(
585
703
  "systemctl disable failed; the service may still be running, so the unit file and its ownership are kept."
@@ -587,7 +705,7 @@ function uninstallService() {
587
705
  return false;
588
706
  }
589
707
  }
590
- const unitPath = path.join(
708
+ const unitPath = path2.join(
591
709
  os.homedir(),
592
710
  ".config",
593
711
  "systemd",
@@ -595,8 +713,8 @@ function uninstallService() {
595
713
  `${platformServiceName()}.service`
596
714
  );
597
715
  try {
598
- fs.rmSync(unitPath);
599
- execFileSync("systemctl", ["--user", "daemon-reload"]);
716
+ fs2.rmSync(unitPath);
717
+ execFileSync2("systemctl", ["--user", "daemon-reload"]);
600
718
  console.log(`Uninstalled systemd service.`);
601
719
  } catch {
602
720
  }
@@ -605,8 +723,9 @@ function uninstallService() {
605
723
  if (process.platform === "win32") {
606
724
  let endOutcome = "ended";
607
725
  try {
608
- execFileSync("schtasks", ["/End", "/TN", platformServiceName()], {
609
- stdio: ["ignore", "pipe", "pipe"]
726
+ execFileSync2("schtasks", ["/End", "/TN", platformServiceName()], {
727
+ stdio: ["ignore", "pipe", "pipe"],
728
+ windowsHide: true
610
729
  });
611
730
  } catch (endError) {
612
731
  const err = endError;
@@ -621,15 +740,15 @@ function uninstallService() {
621
740
  }
622
741
  let registrationGone = false;
623
742
  try {
624
- execFileSync("schtasks", ["/Delete", "/TN", platformServiceName(), "/F"]);
743
+ execFileSync2("schtasks", ["/Delete", "/TN", platformServiceName(), "/F"], { windowsHide: true });
625
744
  registrationGone = true;
626
745
  console.log("Uninstalled scheduled task.");
627
746
  } catch {
628
747
  try {
629
- const probe = execFileSync(
748
+ const probe = execFileSync2(
630
749
  "schtasks",
631
750
  ["/Query", "/TN", platformServiceName()],
632
- { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
751
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true }
633
752
  ).toString();
634
753
  registrationGone = /cannot find|does not exist|not found/i.test(probe) || probe.trim().length === 0;
635
754
  } catch (queryError) {
@@ -686,11 +805,11 @@ async function stopConcierge(state) {
686
805
  return 0;
687
806
  }
688
807
  function startLockDir(dir) {
689
- return path.join(dir, "start-locks");
808
+ return path2.join(dir, "start-locks");
690
809
  }
691
810
  function withStartLock(dir, fn) {
692
811
  const locks = startLockDir(dir);
693
- fs.mkdirSync(locks, { recursive: true });
812
+ fs2.mkdirSync(locks, { recursive: true });
694
813
  const deadline = Date.now() + 9e4;
695
814
  let mine;
696
815
  for (; ; ) {
@@ -700,7 +819,7 @@ function withStartLock(dir, fn) {
700
819
  );
701
820
  let latest = 0;
702
821
  try {
703
- for (const entry of fs.readdirSync(locks)) {
822
+ for (const entry of fs2.readdirSync(locks)) {
704
823
  const m = /^start\.r(\d+)\.json$/.exec(entry);
705
824
  if (m) latest = Math.max(latest, Number(m[1]));
706
825
  }
@@ -708,11 +827,11 @@ function withStartLock(dir, fn) {
708
827
  }
709
828
  if (latest > 0) {
710
829
  let holderBlocking = false;
711
- const latestPath = path.join(locks, `start.r${latest}.json`);
830
+ const latestPath = path2.join(locks, `start.r${latest}.json`);
712
831
  try {
713
- if (fs.existsSync(`${latestPath}.released`)) holderBlocking = false;
832
+ if (fs2.existsSync(`${latestPath}.released`)) holderBlocking = false;
714
833
  else {
715
- const content = JSON.parse(fs.readFileSync(latestPath, "utf8"));
834
+ const content = JSON.parse(fs2.readFileSync(latestPath, "utf8"));
716
835
  if (typeof content.pid === "number" && content.pid > 0) {
717
836
  try {
718
837
  process.kill(content.pid, 0);
@@ -730,26 +849,26 @@ function withStartLock(dir, fn) {
730
849
  }
731
850
  }
732
851
  const next = latest + 1;
733
- const target = path.join(locks, `start.r${next}.json`);
852
+ const target = path2.join(locks, `start.r${next}.json`);
734
853
  const tmp = `${target}.${process.pid}.${Date.now().toString(36)}.tmp`;
735
854
  try {
736
- fs.writeFileSync(
855
+ fs2.writeFileSync(
737
856
  tmp,
738
857
  JSON.stringify({ pid: process.pid, at: Date.now() })
739
858
  );
740
- fs.linkSync(tmp, target);
859
+ fs2.linkSync(tmp, target);
741
860
  mine = target;
742
861
  break;
743
862
  } catch (error) {
744
863
  try {
745
- fs.rmSync(tmp, { force: true });
864
+ fs2.rmSync(tmp, { force: true });
746
865
  } catch {
747
866
  }
748
867
  if (error.code === "EEXIST") continue;
749
868
  throw error;
750
869
  } finally {
751
870
  try {
752
- if (mine) fs.rmSync(tmp, { force: true });
871
+ if (mine) fs2.rmSync(tmp, { force: true });
753
872
  } catch {
754
873
  }
755
874
  }
@@ -757,16 +876,16 @@ function withStartLock(dir, fn) {
757
876
  return Promise.resolve(fn()).finally(() => {
758
877
  if (!mine) return;
759
878
  try {
760
- const content = JSON.parse(fs.readFileSync(mine, "utf8"));
879
+ const content = JSON.parse(fs2.readFileSync(mine, "utf8"));
761
880
  if (content.pid === process.pid) {
762
881
  const tmp = `${mine}.released.${process.pid}.tmp`;
763
- fs.writeFileSync(tmp, String(Date.now()));
882
+ fs2.writeFileSync(tmp, String(Date.now()));
764
883
  try {
765
- fs.linkSync(tmp, `${mine}.released`);
884
+ fs2.linkSync(tmp, `${mine}.released`);
766
885
  } catch {
767
886
  }
768
887
  try {
769
- fs.rmSync(tmp, { force: true });
888
+ fs2.rmSync(tmp, { force: true });
770
889
  } catch {
771
890
  }
772
891
  }
@@ -775,7 +894,7 @@ function withStartLock(dir, fn) {
775
894
  });
776
895
  }
777
896
  async function runUpgradeCommand(args) {
778
- const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-5CPKTRJ7.js");
897
+ const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-LSTOHBUV.js");
779
898
  const targetIdx = args.indexOf("--target");
780
899
  if (targetIdx >= 0 && typeof args[targetIdx + 1] !== "string") {
781
900
  console.error('--target expects "latest" or an x.y.z version (no value given)');
@@ -816,7 +935,7 @@ async function runManagerCommand(args) {
816
935
  let running = false;
817
936
  try {
818
937
  if (process.platform === "darwin") {
819
- const listing = execFileSync("launchctl", ["list"], {
938
+ const listing = execFileSync2("launchctl", ["list"], {
820
939
  encoding: "utf8",
821
940
  stdio: ["ignore", "pipe", "ignore"]
822
941
  });
@@ -833,7 +952,7 @@ async function runManagerCommand(args) {
833
952
  );
834
953
  }
835
954
  } else if (process.platform === "linux") {
836
- execFileSync("systemctl", [
955
+ execFileSync2("systemctl", [
837
956
  "--user",
838
957
  "is-active",
839
958
  "--quiet",
@@ -871,11 +990,11 @@ async function runManagerCommand(args) {
871
990
  if (state.service) {
872
991
  if (process.platform === "darwin") {
873
992
  try {
874
- execFileSync(
993
+ execFileSync2(
875
994
  "launchctl",
876
995
  [
877
996
  "unload",
878
- path.join(
997
+ path2.join(
879
998
  os.homedir(),
880
999
  "Library",
881
1000
  "LaunchAgents",
@@ -903,7 +1022,7 @@ async function runManagerCommand(args) {
903
1022
  }
904
1023
  } else if (process.platform === "linux") {
905
1024
  try {
906
- execFileSync("systemctl", [
1025
+ execFileSync2("systemctl", [
907
1026
  "--user",
908
1027
  "stop",
909
1028
  platformServiceName()
@@ -920,8 +1039,9 @@ async function runManagerCommand(args) {
920
1039
  }
921
1040
  } else if (process.platform === "win32") {
922
1041
  try {
923
- execFileSync("schtasks", ["/End", "/TN", platformServiceName()], {
924
- stdio: ["ignore", "pipe", "pipe"]
1042
+ execFileSync2("schtasks", ["/End", "/TN", platformServiceName()], {
1043
+ stdio: ["ignore", "pipe", "pipe"],
1044
+ windowsHide: true
925
1045
  });
926
1046
  console.log("Stopped (schtasks /End).");
927
1047
  } catch (endError) {
@@ -1022,7 +1142,7 @@ async function runManagerCommand(args) {
1022
1142
  tailN = Math.min(n, 1e4);
1023
1143
  }
1024
1144
  const file = logPath(dir);
1025
- if (!fs.existsSync(file)) {
1145
+ if (!fs2.existsSync(file)) {
1026
1146
  console.error(`No manager log yet (${file}). Run pie manager start first.`);
1027
1147
  process.exitCode = 2;
1028
1148
  return;
@@ -1055,21 +1175,21 @@ async function runManagerCommand(args) {
1055
1175
  const readFrom = (offset2) => {
1056
1176
  let fd;
1057
1177
  try {
1058
- fd = fs.openSync(file, "r");
1178
+ fd = fs2.openSync(file, "r");
1059
1179
  } catch {
1060
1180
  return { buf: Buffer.alloc(0), truncated: true, identity: void 0 };
1061
1181
  }
1062
1182
  try {
1063
- const st = fs.fstatSync(fd);
1183
+ const st = fs2.fstatSync(fd);
1064
1184
  const identity = { ino: st.ino, dev: st.dev };
1065
1185
  const size = st.size;
1066
1186
  if (size < offset2) return { buf: Buffer.alloc(0), truncated: true, identity };
1067
1187
  const len = Math.min(size - offset2, READ_CHUNK_BYTES);
1068
1188
  const buf = Buffer.alloc(len);
1069
- const bytesRead = fs.readSync(fd, buf, 0, len, offset2);
1189
+ const bytesRead = fs2.readSync(fd, buf, 0, len, offset2);
1070
1190
  return { buf: buf.subarray(0, bytesRead), truncated: false, identity };
1071
1191
  } finally {
1072
- fs.closeSync(fd);
1192
+ fs2.closeSync(fd);
1073
1193
  }
1074
1194
  };
1075
1195
  const emit = (buf, from) => {
@@ -1140,7 +1260,7 @@ async function runManagerCommand(args) {
1140
1260
  let carriedBuf = Buffer.alloc(0);
1141
1261
  const pump = () => {
1142
1262
  for (; ; ) {
1143
- if (fs.existsSync(file)) {
1263
+ if (fs2.existsSync(file)) {
1144
1264
  const { buf, truncated, identity } = readFrom(offset + carriedBuf.length);
1145
1265
  if (identity && lastInode && (identity.ino !== lastInode.ino || identity.dev !== lastInode.dev)) {
1146
1266
  offset = 0;
@@ -1171,8 +1291,8 @@ async function runManagerCommand(args) {
1171
1291
  };
1172
1292
  const startWatch = () => {
1173
1293
  try {
1174
- watcher = fs.watch(path.dirname(file), (event, filename) => {
1175
- if (!filename || filename === path.basename(file)) pump();
1294
+ watcher = fs2.watch(path2.dirname(file), (event, filename) => {
1295
+ if (!filename || filename === path2.basename(file)) pump();
1176
1296
  });
1177
1297
  watcher.on("error", () => {
1178
1298
  watcher?.close();
@@ -1199,7 +1319,16 @@ async function runManagerCommand(args) {
1199
1319
  process.exitCode = 2;
1200
1320
  return;
1201
1321
  }
1202
- const existing = readState();
1322
+ let existing = readState();
1323
+ if (existing?.service && process.platform === "win32") {
1324
+ const handled = await withStartLock(dir, async () => {
1325
+ existing = readState();
1326
+ if (!existing?.service) return false;
1327
+ requestWindowsServiceStart(dir);
1328
+ return true;
1329
+ });
1330
+ if (handled) return;
1331
+ }
1203
1332
  if (existing?.service) {
1204
1333
  console.log(
1205
1334
  "The manager is managed by a system service (launchd/systemd/scheduled task). To take over manually, run --uninstall-service first."
@@ -1229,18 +1358,23 @@ async function runManagerCommand(args) {
1229
1358
  const procSeed = seedProcConfig(process.cwd());
1230
1359
  if (procSeed.state === "seeded") {
1231
1360
  console.log(
1232
- `Seeded pie-proc config: allowCwd = ${path.resolve(process.cwd())} (dispatching works now; edit ${procSeed.file} to add roots \u2014 it applies on the next spawn)`
1361
+ `Seeded pie-proc config: allowCwd = ${path2.resolve(process.cwd())} (dispatching works now; edit ${procSeed.file} to add roots \u2014 it applies on the next spawn)`
1362
+ );
1363
+ } else if (procSeed.state === "user-layer") {
1364
+ console.log(
1365
+ `pie-proc config: using the user layer (${procSeed.file}) \u2014 worker roots and caps come from there; edit it to change what the manager may dispatch.`
1233
1366
  );
1234
1367
  } else if (procSeed.state === "too-broad") {
1235
1368
  console.log(
1236
- `Did not seed pie-proc config (the current directory ${path.resolve(process.cwd())} is too broad). To dispatch work, write ${procSeed.file}: {"allowCwd": ["/your/project"]}`
1369
+ `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"]}`
1237
1370
  );
1238
1371
  }
1239
1372
  let readinessReport;
1240
1373
  await withStartLock(dir, async () => {
1241
1374
  const lockedState = readState();
1242
1375
  if (lockedState?.service) {
1243
- console.log(
1376
+ if (process.platform === "win32") requestWindowsServiceStart(dir);
1377
+ else console.log(
1244
1378
  "The manager is managed by a system service (launchd/systemd/scheduled task). To take over manually, run --uninstall-service first."
1245
1379
  );
1246
1380
  return;
@@ -1256,14 +1390,15 @@ async function runManagerCommand(args) {
1256
1390
  const state = lockedState ?? { sessionId: token };
1257
1391
  let sinceOffset = 0;
1258
1392
  try {
1259
- sinceOffset = fs.statSync(logPath(dir)).size;
1393
+ sinceOffset = fs2.statSync(logPath(dir)).size;
1260
1394
  } catch {
1261
1395
  }
1262
1396
  const pid = spawnResident(state, dir);
1263
1397
  try {
1264
- const listing = execFileSync("ps", ["-eo", "pid,command"], {
1398
+ const listing = execFileSync2("ps", ["-eo", "pid,command"], {
1265
1399
  encoding: "utf8",
1266
- timeout: 3e3
1400
+ timeout: 3e3,
1401
+ windowsHide: true
1267
1402
  });
1268
1403
  const token2 = `--session-id ${state.sessionId}`;
1269
1404
  const rivals = String(listing).split("\n").map((line) => line.trim()).filter(