@cydm/pie 4.15.4 → 4.16.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.
- package/README.md +1 -1
- package/dist/builtin/extensions/im-forward/index.js +45 -9
- package/dist/builtin/extensions/memory/index.js +2 -2
- package/dist/builtin/extensions/pie-ipc/index.js +3 -2
- package/dist/builtin/extensions/pie-proc/README.md +14 -16
- package/dist/builtin/extensions/pie-proc/index.js +50 -7
- package/dist/builtin/extensions/subagent/index.js +1 -1
- package/dist/chunks/{chunk-Y6AVNVOD.js → chunk-7UFRZTQI.js} +290 -28
- package/dist/chunks/{chunk-Z2RT3P4F.js → chunk-JBBKYDYC.js} +9 -6
- package/dist/chunks/{chunk-NCO26FXT.js → chunk-MC5ZYWSP.js} +1 -1
- package/dist/chunks/{chunk-ZB5FVHI7.js → chunk-PGNZMD2E.js} +3 -1
- package/dist/chunks/{chunk-LIA52LJU.js → chunk-TFBXCEMG.js} +5 -1
- package/dist/chunks/{chunk-TYCKSYUF.js → chunk-XUXKF5ZK.js} +1 -0
- package/dist/chunks/{chunk-VWDCKHCC.js → chunk-ZSFE6N5J.js} +4 -2
- package/dist/chunks/{manager-allow-SF5ROGDM.js → manager-allow-5HYRKCCH.js} +1 -1
- package/dist/chunks/{manager-cli-ZV36YNPJ.js → manager-cli-KK3XG3DX.js} +11 -17
- package/dist/chunks/{manager-upgrade-DYRQ7YZ5.js → manager-upgrade-DGMMUQYY.js} +2 -2
- package/dist/chunks/{memory-git-BJMYZHIE.js → memory-git-LV7RTOMN.js} +1 -1
- package/dist/cli.js +85 -12
- package/package.json +3 -3
|
@@ -5,10 +5,255 @@ import {
|
|
|
5
5
|
|
|
6
6
|
// src/commands/manager-upgrade-windows.ts
|
|
7
7
|
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
9
|
+
import * as fs2 from "node:fs";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import * as path2 from "node:path";
|
|
12
|
+
|
|
13
|
+
// src/commands/manager-upgrade-launcher-windows.ts
|
|
14
|
+
import { execFileSync } from "node:child_process";
|
|
8
15
|
import { randomBytes } from "node:crypto";
|
|
9
16
|
import * as fs from "node:fs";
|
|
10
|
-
import * as os from "node:os";
|
|
11
17
|
import * as path from "node:path";
|
|
18
|
+
var WINDOWS_UPGRADE_LAUNCHER_FILENAME = "upgrade-launcher.v1.exe";
|
|
19
|
+
function quoteWindowsCommandArg(arg) {
|
|
20
|
+
let out = '"';
|
|
21
|
+
let backslashes = 0;
|
|
22
|
+
for (const ch of arg) {
|
|
23
|
+
if (ch === "\\") {
|
|
24
|
+
backslashes++;
|
|
25
|
+
} else if (ch === '"') {
|
|
26
|
+
out += "\\".repeat(backslashes * 2 + 1) + '"';
|
|
27
|
+
backslashes = 0;
|
|
28
|
+
} else {
|
|
29
|
+
if (backslashes > 0) {
|
|
30
|
+
out += "\\".repeat(backslashes);
|
|
31
|
+
backslashes = 0;
|
|
32
|
+
}
|
|
33
|
+
out += ch;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (backslashes > 0) out += "\\".repeat(backslashes * 2);
|
|
37
|
+
out += '"';
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function buildWindowsUpgradeLauncherSource() {
|
|
41
|
+
return `// Generated by Pie. GUI-subsystem silent launcher for Windows upgrade tasks.
|
|
42
|
+
using System;
|
|
43
|
+
using System.ComponentModel;
|
|
44
|
+
using System.IO;
|
|
45
|
+
using System.Runtime.InteropServices;
|
|
46
|
+
using System.Text;
|
|
47
|
+
|
|
48
|
+
internal static class PieUpgradeLauncher {
|
|
49
|
+
[StructLayout(LayoutKind.Sequential)] struct SECURITY_ATTRIBUTES { public int Length; public IntPtr Descriptor; public int Inherit; }
|
|
50
|
+
[StructLayout(LayoutKind.Sequential)] struct STARTUPINFO {
|
|
51
|
+
public int Size; public string Reserved, Desktop, Title;
|
|
52
|
+
public int X, Y, XSize, YSize, XCountChars, YCountChars, FillAttribute, Flags;
|
|
53
|
+
public short ShowWindow, ReservedSize; public IntPtr Reserved2, Input, Output, Error;
|
|
54
|
+
}
|
|
55
|
+
[StructLayout(LayoutKind.Sequential)] struct PROCESS_INFORMATION { public IntPtr Process, Thread; public uint ProcessId, ThreadId; }
|
|
56
|
+
[StructLayout(LayoutKind.Sequential)] struct BASIC_LIMITS {
|
|
57
|
+
public long ProcessTime, JobTime; public uint Flags; public UIntPtr MinWorkingSet, MaxWorkingSet;
|
|
58
|
+
public uint ActiveProcesses; public UIntPtr Affinity; public uint PriorityClass, SchedulingClass;
|
|
59
|
+
}
|
|
60
|
+
[StructLayout(LayoutKind.Sequential)] struct IO_COUNTERS { public ulong ReadOps, WriteOps, OtherOps, ReadBytes, WriteBytes, OtherBytes; }
|
|
61
|
+
[StructLayout(LayoutKind.Sequential)] struct EXTENDED_LIMITS {
|
|
62
|
+
public BASIC_LIMITS Basic; public IO_COUNTERS Io; public UIntPtr ProcessMemory, JobMemory, PeakProcess, PeakJob;
|
|
63
|
+
}
|
|
64
|
+
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern IntPtr CreateJobObject(IntPtr attributes, string name);
|
|
65
|
+
[DllImport("kernel32.dll", SetLastError=true)] static extern bool SetInformationJobObject(IntPtr job, int infoClass, ref EXTENDED_LIMITS info, uint length);
|
|
66
|
+
[DllImport("kernel32.dll", SetLastError=true)] static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
|
67
|
+
[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);
|
|
68
|
+
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern IntPtr CreateFile(string name, uint access, uint share, ref SECURITY_ATTRIBUTES sa, uint disposition, uint flags, IntPtr template);
|
|
69
|
+
[DllImport("kernel32.dll", SetLastError=true)] static extern uint ResumeThread(IntPtr thread);
|
|
70
|
+
[DllImport("kernel32.dll", SetLastError=true)] static extern uint WaitForSingleObject(IntPtr handle, uint milliseconds);
|
|
71
|
+
[DllImport("kernel32.dll", SetLastError=true)] static extern bool GetExitCodeProcess(IntPtr process, out uint code);
|
|
72
|
+
[DllImport("kernel32.dll", SetLastError=true)] static extern bool TerminateProcess(IntPtr process, uint code);
|
|
73
|
+
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr handle);
|
|
74
|
+
|
|
75
|
+
static void Check(bool ok) { if (!ok) throw new Win32Exception(Marshal.GetLastWin32Error()); }
|
|
76
|
+
static void Close(IntPtr handle) { if (handle != IntPtr.Zero && handle != new IntPtr(-1)) CloseHandle(handle); }
|
|
77
|
+
|
|
78
|
+
static string QuoteArg(string arg) {
|
|
79
|
+
StringBuilder sb = new StringBuilder();
|
|
80
|
+
sb.Append('"');
|
|
81
|
+
int backslashes = 0;
|
|
82
|
+
for (int i = 0; i < arg.Length; i++) {
|
|
83
|
+
char c = arg[i];
|
|
84
|
+
if (c == '\\\\') {
|
|
85
|
+
backslashes++;
|
|
86
|
+
} else if (c == '"') {
|
|
87
|
+
sb.Append('\\\\', backslashes * 2 + 1);
|
|
88
|
+
sb.Append('"');
|
|
89
|
+
backslashes = 0;
|
|
90
|
+
} else {
|
|
91
|
+
if (backslashes > 0) {
|
|
92
|
+
sb.Append('\\\\', backslashes);
|
|
93
|
+
backslashes = 0;
|
|
94
|
+
}
|
|
95
|
+
sb.Append(c);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (backslashes > 0) sb.Append('\\\\', backslashes * 2);
|
|
99
|
+
sb.Append('"');
|
|
100
|
+
return sb.ToString();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static void AppendLog(string logFile, string message) {
|
|
104
|
+
if (string.IsNullOrEmpty(logFile)) return;
|
|
105
|
+
try {
|
|
106
|
+
File.AppendAllText(logFile, "[pie-upgrade-launcher] " + DateTime.UtcNow.ToString("o") + " " + message + Environment.NewLine);
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static int Main(string[] args) {
|
|
111
|
+
if (args == null || args.Length < 2 || string.IsNullOrEmpty(args[0]) || string.IsNullOrEmpty(args[1])) {
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
|
114
|
+
string nodePath = args[0];
|
|
115
|
+
string bootstrapPath = args[1];
|
|
116
|
+
string logFile = args.Length >= 3 ? args[2] : "";
|
|
117
|
+
IntPtr job = IntPtr.Zero, input = IntPtr.Zero, output = IntPtr.Zero;
|
|
118
|
+
PROCESS_INFORMATION child = new PROCESS_INFORMATION();
|
|
119
|
+
bool assigned = false;
|
|
120
|
+
try {
|
|
121
|
+
job = CreateJobObject(IntPtr.Zero, null);
|
|
122
|
+
Check(job != IntPtr.Zero);
|
|
123
|
+
EXTENDED_LIMITS limits = new EXTENDED_LIMITS();
|
|
124
|
+
limits.Basic.Flags = 0x2000; // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
|
125
|
+
Check(SetInformationJobObject(job, 9, ref limits, (uint)Marshal.SizeOf(typeof(EXTENDED_LIMITS))));
|
|
126
|
+
|
|
127
|
+
SECURITY_ATTRIBUTES inherit = new SECURITY_ATTRIBUTES();
|
|
128
|
+
inherit.Length = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES));
|
|
129
|
+
inherit.Inherit = 1;
|
|
130
|
+
|
|
131
|
+
input = CreateFile("NUL", 0x80000000, 7, ref inherit, 3, 0, IntPtr.Zero);
|
|
132
|
+
Check(input != new IntPtr(-1));
|
|
133
|
+
|
|
134
|
+
output = new IntPtr(-1);
|
|
135
|
+
if (!string.IsNullOrEmpty(logFile)) {
|
|
136
|
+
try {
|
|
137
|
+
string logDir = Path.GetDirectoryName(logFile);
|
|
138
|
+
if (!string.IsNullOrEmpty(logDir)) Directory.CreateDirectory(logDir);
|
|
139
|
+
} catch {}
|
|
140
|
+
output = CreateFile(logFile, 4, 7, ref inherit, 4, 0, IntPtr.Zero); // FILE_APPEND_DATA, OPEN_ALWAYS
|
|
141
|
+
}
|
|
142
|
+
if (output == new IntPtr(-1)) {
|
|
143
|
+
output = CreateFile("NUL", 0x40000000, 7, ref inherit, 3, 0, IntPtr.Zero);
|
|
144
|
+
Check(output != new IntPtr(-1));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
STARTUPINFO startup = new STARTUPINFO();
|
|
148
|
+
startup.Size = Marshal.SizeOf(typeof(STARTUPINFO));
|
|
149
|
+
startup.Flags = 0x100; // STARTF_USESTDHANDLES
|
|
150
|
+
startup.Input = input;
|
|
151
|
+
startup.Output = output;
|
|
152
|
+
startup.Error = output;
|
|
153
|
+
|
|
154
|
+
string command = QuoteArg(nodePath) + " " + QuoteArg(bootstrapPath);
|
|
155
|
+
// CREATE_NO_WINDOW (0x08000000) | CREATE_SUSPENDED (0x00000004).
|
|
156
|
+
// Inherits Task Scheduler WorkingDirectory (lpCurrentDirectory = null)
|
|
157
|
+
// and creates a hidden console so child npm/cmd.exe processes stay silent.
|
|
158
|
+
Check(CreateProcess(nodePath, new StringBuilder(command), IntPtr.Zero, IntPtr.Zero, true, 0x08000004, IntPtr.Zero, null, ref startup, out child));
|
|
159
|
+
Check(AssignProcessToJobObject(job, child.Process));
|
|
160
|
+
assigned = true;
|
|
161
|
+
Check(ResumeThread(child.Thread) != UInt32.MaxValue);
|
|
162
|
+
Check(WaitForSingleObject(child.Process, UInt32.MaxValue) == 0);
|
|
163
|
+
uint code;
|
|
164
|
+
Check(GetExitCodeProcess(child.Process, out code));
|
|
165
|
+
return unchecked((int)code);
|
|
166
|
+
} catch (Exception error) {
|
|
167
|
+
AppendLog(logFile, error.ToString());
|
|
168
|
+
return 1;
|
|
169
|
+
} finally {
|
|
170
|
+
if (!assigned && child.Process != IntPtr.Zero) TerminateProcess(child.Process, 1);
|
|
171
|
+
Close(job);
|
|
172
|
+
Close(child.Thread);
|
|
173
|
+
Close(child.Process);
|
|
174
|
+
Close(input);
|
|
175
|
+
Close(output);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
181
|
+
function defaultFindWindowsDotNetCompiler() {
|
|
182
|
+
const systemRoot = process.env.SystemRoot || "C:\\Windows";
|
|
183
|
+
return ["Framework64", "Framework"].map((folder) => path.join(systemRoot, "Microsoft.NET", folder, "v4.0.30319", "csc.exe")).find((file) => fs.existsSync(file));
|
|
184
|
+
}
|
|
185
|
+
function isNonEmptyFile(filePath) {
|
|
186
|
+
try {
|
|
187
|
+
const st = fs.statSync(filePath);
|
|
188
|
+
return st.isFile() && st.size > 0;
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function ensureWindowsUpgradeLauncher(managerDir, deps = {}) {
|
|
194
|
+
const launcherPath = path.join(managerDir, WINDOWS_UPGRADE_LAUNCHER_FILENAME);
|
|
195
|
+
if (isNonEmptyFile(launcherPath)) {
|
|
196
|
+
return { ok: true, launcherPath, compiled: false };
|
|
197
|
+
}
|
|
198
|
+
const findCompiler = deps.findCompiler ?? defaultFindWindowsDotNetCompiler;
|
|
199
|
+
const compiler = findCompiler();
|
|
200
|
+
if (!compiler) {
|
|
201
|
+
return {
|
|
202
|
+
ok: false,
|
|
203
|
+
detail: "Windows .NET Framework compiler (csc.exe) is unavailable; refusing to launch a visible console upgrade task."
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const compile = deps.compile ?? ((bin, args) => {
|
|
207
|
+
execFileSync(bin, args, {
|
|
208
|
+
windowsHide: true,
|
|
209
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
210
|
+
timeout: 3e4
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
const nonce = `${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
214
|
+
const tmpSrc = path.join(managerDir, `upgrade-launcher.${nonce}.cs`);
|
|
215
|
+
const tmpExe = path.join(managerDir, `upgrade-launcher.${nonce}.exe`);
|
|
216
|
+
try {
|
|
217
|
+
fs.mkdirSync(managerDir, { recursive: true });
|
|
218
|
+
fs.writeFileSync(tmpSrc, buildWindowsUpgradeLauncherSource(), { encoding: "utf8", mode: 384 });
|
|
219
|
+
compile(compiler, [
|
|
220
|
+
"/nologo",
|
|
221
|
+
"/target:winexe",
|
|
222
|
+
"/platform:anycpu",
|
|
223
|
+
"/optimize+",
|
|
224
|
+
`/out:${tmpExe}`,
|
|
225
|
+
tmpSrc
|
|
226
|
+
]);
|
|
227
|
+
if (!isNonEmptyFile(tmpExe)) {
|
|
228
|
+
return { ok: false, detail: `csc.exe produced no output binary at ${tmpExe}` };
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
fs.renameSync(tmpExe, launcherPath);
|
|
232
|
+
} catch (renameError) {
|
|
233
|
+
if (isNonEmptyFile(launcherPath)) {
|
|
234
|
+
return { ok: true, launcherPath, compiled: false };
|
|
235
|
+
}
|
|
236
|
+
throw renameError;
|
|
237
|
+
}
|
|
238
|
+
return { ok: true, launcherPath, compiled: true };
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return {
|
|
241
|
+
ok: false,
|
|
242
|
+
detail: `failed to compile Windows silent upgrade launcher: ${error instanceof Error ? error.message : String(error)}`
|
|
243
|
+
};
|
|
244
|
+
} finally {
|
|
245
|
+
try {
|
|
246
|
+
fs.rmSync(tmpSrc, { force: true });
|
|
247
|
+
} catch {
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
fs.rmSync(tmpExe, { force: true });
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/commands/manager-upgrade-windows.ts
|
|
12
257
|
var WINDOWS_UPGRADE_TASK_NAME = "dev.pie.manager.upgrade";
|
|
13
258
|
function normalizePreInstallStopOutcome(raw) {
|
|
14
259
|
return typeof raw === "string" ? { status: raw } : raw;
|
|
@@ -23,12 +268,12 @@ function resolveDefaultTuiUsePidFile(env = process.env) {
|
|
|
23
268
|
const expandHome = (value) => {
|
|
24
269
|
if (value === "~") return os.homedir();
|
|
25
270
|
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
26
|
-
return
|
|
271
|
+
return path2.join(os.homedir(), value.slice(2).replace(/\\/g, "/"));
|
|
27
272
|
}
|
|
28
273
|
return value;
|
|
29
274
|
};
|
|
30
|
-
const stateDir = env.PIE_TUI_USE_STATE_DIR ?
|
|
31
|
-
return
|
|
275
|
+
const stateDir = env.PIE_TUI_USE_STATE_DIR ? path2.resolve(expandHome(env.PIE_TUI_USE_STATE_DIR)) : path2.resolve(path2.join(env.PIE_CODING_AGENT_DIR ? expandHome(env.PIE_CODING_AGENT_DIR) : path2.join(os.homedir(), ".pie"), "tui-use"));
|
|
276
|
+
return path2.join(stateDir, "daemon.pid");
|
|
32
277
|
}
|
|
33
278
|
function scanBlockingWindowsPeers(discoveryDir, managerSessionId, managerPid, opts = {}) {
|
|
34
279
|
const selfPid = opts.selfPid ?? process.pid;
|
|
@@ -45,14 +290,14 @@ function scanBlockingWindowsPeers(discoveryDir, managerSessionId, managerPid, op
|
|
|
45
290
|
const seenPids = /* @__PURE__ */ new Set();
|
|
46
291
|
let files = [];
|
|
47
292
|
try {
|
|
48
|
-
files =
|
|
293
|
+
files = fs2.readdirSync(discoveryDir).filter((f) => f.endsWith(".json"));
|
|
49
294
|
} catch {
|
|
50
295
|
files = [];
|
|
51
296
|
}
|
|
52
297
|
for (const file of files.slice(0, 256)) {
|
|
53
298
|
let parsed;
|
|
54
299
|
try {
|
|
55
|
-
const raw = JSON.parse(
|
|
300
|
+
const raw = JSON.parse(fs2.readFileSync(path2.join(discoveryDir, file), "utf8"));
|
|
56
301
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) continue;
|
|
57
302
|
parsed = raw;
|
|
58
303
|
} catch {
|
|
@@ -81,7 +326,7 @@ function scanBlockingWindowsPeers(discoveryDir, managerSessionId, managerPid, op
|
|
|
81
326
|
}
|
|
82
327
|
if (opts.tuiUsePidFile) {
|
|
83
328
|
try {
|
|
84
|
-
const rawPid =
|
|
329
|
+
const rawPid = fs2.readFileSync(opts.tuiUsePidFile, "utf8").trim();
|
|
85
330
|
const daemonPid = Number.parseInt(rawPid, 10);
|
|
86
331
|
if (Number.isInteger(daemonPid) && daemonPid > 0 && daemonPid !== selfPid && !seenPids.has(daemonPid) && isPidAlive(daemonPid) && cmdlineStillLooksLikePie(readCmdline(daemonPid))) {
|
|
87
332
|
seenPids.add(daemonPid);
|
|
@@ -381,7 +626,7 @@ function runWindowsPreInstallStop(state, deps) {
|
|
|
381
626
|
}
|
|
382
627
|
function isWindowsServiceManager(configRoot) {
|
|
383
628
|
try {
|
|
384
|
-
const raw = JSON.parse(
|
|
629
|
+
const raw = JSON.parse(fs2.readFileSync(path2.join(configRoot, "manager", "manager.json"), "utf8"));
|
|
385
630
|
return raw.service === true;
|
|
386
631
|
} catch {
|
|
387
632
|
return false;
|
|
@@ -403,9 +648,9 @@ function resolveAbsoluteActorEnv(env, cwd = process.cwd()) {
|
|
|
403
648
|
const trimmed = raw.trim();
|
|
404
649
|
if (trimmed === "~" || trimmed.startsWith("~/") || trimmed.startsWith("~\\")) continue;
|
|
405
650
|
if (key === "PIE_IPC_CONFIG_DIR" && trimmed.length === 0) {
|
|
406
|
-
out[key] =
|
|
407
|
-
} else if (trimmed.length > 0 && !
|
|
408
|
-
out[key] =
|
|
651
|
+
out[key] = path2.resolve(cwd);
|
|
652
|
+
} else if (trimmed.length > 0 && !path2.isAbsolute(trimmed)) {
|
|
653
|
+
out[key] = path2.resolve(cwd, trimmed);
|
|
409
654
|
}
|
|
410
655
|
}
|
|
411
656
|
return out;
|
|
@@ -424,7 +669,12 @@ function xmlEscapeText(value) {
|
|
|
424
669
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
425
670
|
}
|
|
426
671
|
function buildWindowsUpgradeTaskXml(params) {
|
|
427
|
-
const
|
|
672
|
+
const argv = [
|
|
673
|
+
params.nodePath,
|
|
674
|
+
params.bootstrapPath,
|
|
675
|
+
...params.logFile ? [params.logFile] : []
|
|
676
|
+
];
|
|
677
|
+
const args = argv.map(quoteWindowsCommandArg).join(" ");
|
|
428
678
|
return [
|
|
429
679
|
'<?xml version="1.0" encoding="UTF-16"?>',
|
|
430
680
|
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">',
|
|
@@ -459,7 +709,7 @@ function buildWindowsUpgradeTaskXml(params) {
|
|
|
459
709
|
" </Settings>",
|
|
460
710
|
' <Actions Context="Author">',
|
|
461
711
|
" <Exec>",
|
|
462
|
-
` <Command>${xmlEscapeText(params.
|
|
712
|
+
` <Command>${xmlEscapeText(params.launcherPath)}</Command>`,
|
|
463
713
|
` <Arguments>${xmlEscapeText(args)}</Arguments>`,
|
|
464
714
|
` <WorkingDirectory>${xmlEscapeText(params.workingDir)}</WorkingDirectory>`,
|
|
465
715
|
" </Exec>",
|
|
@@ -512,13 +762,13 @@ function buildWindowsUpgradeBootstrapScript(cfg) {
|
|
|
512
762
|
function sweepStaleUpgradeBootstrapFiles(managerDir, nowMs = Date.now()) {
|
|
513
763
|
const MAX_AGE_MS = 30 * 6e4;
|
|
514
764
|
try {
|
|
515
|
-
for (const name of
|
|
765
|
+
for (const name of fs2.readdirSync(managerDir)) {
|
|
516
766
|
if (!/^upgrade-actor-[\w-]+\.(?:mjs|xml)$/.test(name)) continue;
|
|
517
|
-
const full =
|
|
767
|
+
const full = path2.join(managerDir, name);
|
|
518
768
|
try {
|
|
519
|
-
const st =
|
|
769
|
+
const st = fs2.statSync(full);
|
|
520
770
|
if (nowMs - st.mtimeMs > MAX_AGE_MS) {
|
|
521
|
-
|
|
771
|
+
fs2.rmSync(full, { force: true });
|
|
522
772
|
}
|
|
523
773
|
} catch {
|
|
524
774
|
}
|
|
@@ -529,19 +779,19 @@ function sweepStaleUpgradeBootstrapFiles(managerDir, nowMs = Date.now()) {
|
|
|
529
779
|
function launchWindowsServiceUpgradeActor(params, runSchtasks = (args) => {
|
|
530
780
|
const res = spawnSync("schtasks", args, { encoding: "utf8", timeout: 2e4, windowsHide: true });
|
|
531
781
|
return { status: res.status, stdout: res.stdout, stderr: res.stderr, error: res.error };
|
|
532
|
-
}) {
|
|
533
|
-
const launchId = params.launchId ?? `${Date.now().toString(36)}-${
|
|
782
|
+
}, ensureLauncher = (dir) => ensureWindowsUpgradeLauncher(dir)) {
|
|
783
|
+
const launchId = params.launchId ?? `${Date.now().toString(36)}-${randomBytes2(4).toString("hex")}`;
|
|
534
784
|
const taskName = params.taskName ?? `${WINDOWS_UPGRADE_TASK_NAME}.${launchId}`;
|
|
535
785
|
const workingDir = params.workingDir ?? os.tmpdir();
|
|
536
|
-
const bootstrapPath =
|
|
537
|
-
const xmlPath =
|
|
786
|
+
const bootstrapPath = path2.join(params.managerDir, `upgrade-actor-${launchId}.mjs`);
|
|
787
|
+
const xmlPath = path2.join(params.managerDir, `upgrade-actor-${launchId}.xml`);
|
|
538
788
|
const cleanup = (deleteTask) => {
|
|
539
789
|
try {
|
|
540
|
-
|
|
790
|
+
fs2.rmSync(xmlPath, { force: true });
|
|
541
791
|
} catch {
|
|
542
792
|
}
|
|
543
793
|
try {
|
|
544
|
-
|
|
794
|
+
fs2.rmSync(bootstrapPath, { force: true });
|
|
545
795
|
} catch {
|
|
546
796
|
}
|
|
547
797
|
if (deleteTask) {
|
|
@@ -552,8 +802,12 @@ function launchWindowsServiceUpgradeActor(params, runSchtasks = (args) => {
|
|
|
552
802
|
}
|
|
553
803
|
};
|
|
554
804
|
try {
|
|
555
|
-
|
|
805
|
+
fs2.mkdirSync(params.managerDir, { recursive: true });
|
|
556
806
|
sweepStaleUpgradeBootstrapFiles(params.managerDir);
|
|
807
|
+
const launcher = ensureLauncher(params.managerDir);
|
|
808
|
+
if (!launcher.ok) {
|
|
809
|
+
return { ok: false, detail: launcher.detail };
|
|
810
|
+
}
|
|
557
811
|
const script = buildWindowsUpgradeBootstrapScript({
|
|
558
812
|
node: params.nodePath,
|
|
559
813
|
entry: params.entry,
|
|
@@ -564,10 +818,16 @@ function launchWindowsServiceUpgradeActor(params, runSchtasks = (args) => {
|
|
|
564
818
|
workingDir,
|
|
565
819
|
env: collectWindowsUpgradeEnv(params.env)
|
|
566
820
|
});
|
|
567
|
-
|
|
568
|
-
const xml = buildWindowsUpgradeTaskXml({
|
|
821
|
+
fs2.writeFileSync(bootstrapPath, script, { encoding: "utf8", mode: 384 });
|
|
822
|
+
const xml = buildWindowsUpgradeTaskXml({
|
|
823
|
+
launcherPath: launcher.launcherPath,
|
|
824
|
+
nodePath: params.nodePath,
|
|
825
|
+
bootstrapPath,
|
|
826
|
+
logFile: params.logFile,
|
|
827
|
+
workingDir
|
|
828
|
+
});
|
|
569
829
|
const xmlBytes = Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]);
|
|
570
|
-
|
|
830
|
+
fs2.writeFileSync(xmlPath, xmlBytes, { mode: 384 });
|
|
571
831
|
const created = runSchtasks(["/Create", "/TN", taskName, "/XML", xmlPath, "/F"]);
|
|
572
832
|
if (created.error || created.status !== 0) {
|
|
573
833
|
cleanup(false);
|
|
@@ -585,7 +845,8 @@ function launchWindowsServiceUpgradeActor(params, runSchtasks = (args) => {
|
|
|
585
845
|
detail: `scheduled task ${taskName} \xB7 log ${params.logFile}`,
|
|
586
846
|
taskName,
|
|
587
847
|
bootstrapPath,
|
|
588
|
-
xmlPath
|
|
848
|
+
xmlPath,
|
|
849
|
+
launcherPath: launcher.launcherPath
|
|
589
850
|
};
|
|
590
851
|
} catch (error) {
|
|
591
852
|
cleanup(false);
|
|
@@ -594,6 +855,7 @@ function launchWindowsServiceUpgradeActor(params, runSchtasks = (args) => {
|
|
|
594
855
|
}
|
|
595
856
|
|
|
596
857
|
export {
|
|
858
|
+
ensureWindowsUpgradeLauncher,
|
|
597
859
|
normalizePreInstallStopOutcome,
|
|
598
860
|
resolveDefaultTuiUsePidFile,
|
|
599
861
|
scanBlockingWindowsPeers,
|
|
@@ -190,19 +190,22 @@ function runManagerAllowCommand(args) {
|
|
|
190
190
|
if (list) {
|
|
191
191
|
const { file, exists } = resolveEffectiveProcConfigFile();
|
|
192
192
|
if (!exists) {
|
|
193
|
-
if (json) console.log(JSON.stringify({ ok: true, file, exists: false, allowCwd:
|
|
194
|
-
else console.log(`No pie-proc.json
|
|
193
|
+
if (json) console.log(JSON.stringify({ ok: true, file, exists: false, restricted: false, allowCwd: null }));
|
|
194
|
+
else console.log(`No pie-proc.json configured \u2014 standard working directories are allowed by default (OS/filesystem roots blocked). Run \`pie manager allow <dir>\` to enable explicit allowCwd narrowing at ${file}.`);
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
197
|
try {
|
|
198
198
|
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
199
|
-
const
|
|
200
|
-
|
|
199
|
+
const hasExplicitAllowCwd = Array.isArray(parsed.allowCwd);
|
|
200
|
+
const allowCwd = hasExplicitAllowCwd ? parsed.allowCwd.filter((v) => typeof v === "string") : null;
|
|
201
|
+
if (json) console.log(JSON.stringify({ ok: true, file, exists: true, restricted: hasExplicitAllowCwd, allowCwd, maxWorkers: parsed.maxWorkers ?? 50 }));
|
|
201
202
|
else {
|
|
202
203
|
console.log(`Policy file: ${file}`);
|
|
203
204
|
console.log(`maxWorkers: ${typeof parsed.maxWorkers === "number" ? parsed.maxWorkers : "50 (default)"}`);
|
|
204
|
-
console.log(
|
|
205
|
-
|
|
205
|
+
console.log(
|
|
206
|
+
allowCwd === null ? "allowCwd: (not set \u2014 open by default for standard directories)" : allowCwd.length ? `allowCwd:
|
|
207
|
+
${allowCwd.map((d) => ` - ${d}`).join("\n")}` : "allowCwd: (empty \u2014 fail-closed deny all)"
|
|
208
|
+
);
|
|
206
209
|
}
|
|
207
210
|
} catch (error) {
|
|
208
211
|
const detail = error instanceof Error ? error.message : String(error);
|
|
@@ -362,7 +362,7 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false, sessionsDi
|
|
|
362
362
|
const { getSessionsDir } = await import("./config-4EOI5NOU.js");
|
|
363
363
|
const { FileSessionStore } = await import("./src-DLAIQCKP.js");
|
|
364
364
|
const { WikiStore, runWikiBootstrap, runWikiDreamBatches, runWikiGc } = await import("./src-OP6LFLR6.js");
|
|
365
|
-
const { commitCuratedMemoryBestEffort } = await import("./memory-git-
|
|
365
|
+
const { commitCuratedMemoryBestEffort } = await import("./memory-git-LV7RTOMN.js");
|
|
366
366
|
const wiki = new WikiStore(memoryRoot);
|
|
367
367
|
wikiForError = wiki;
|
|
368
368
|
const inboxOnly = date === "__inbox__";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
+
ensureWindowsUpgradeLauncher,
|
|
3
4
|
isWindowsTaskAlreadyStoppedDetail,
|
|
4
5
|
isWindowsTaskNotFoundDetail,
|
|
5
6
|
queryWindowsServiceTaskState
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7UFRZTQI.js";
|
|
7
8
|
import {
|
|
8
9
|
isPositivelyDeadHolder,
|
|
9
10
|
withOwnershipMutex
|
|
@@ -226,6 +227,7 @@ function refreshWindowsManagerServiceOnUpgrade(params) {
|
|
|
226
227
|
serviceEnv,
|
|
227
228
|
{ keepAlive: true }
|
|
228
229
|
);
|
|
230
|
+
ensureWindowsUpgradeLauncher(params.workingDir);
|
|
229
231
|
installWindowsManagerScheduledTask({
|
|
230
232
|
taskName: params.taskName,
|
|
231
233
|
launcherPath,
|
|
@@ -1571,7 +1571,11 @@ function createCliWebResearchHealthStore(configDir) {
|
|
|
1571
1571
|
|
|
1572
1572
|
// src/capabilities/index.ts
|
|
1573
1573
|
function createCliHostCapabilities(cwd, options = {}) {
|
|
1574
|
-
const
|
|
1574
|
+
const bashOptions = options.getBashEnv || options.isYoloMode ? {
|
|
1575
|
+
...options.getBashEnv ? { getEnv: options.getBashEnv } : {},
|
|
1576
|
+
...options.isYoloMode ? { isYoloMode: options.isYoloMode } : {}
|
|
1577
|
+
} : void 0;
|
|
1578
|
+
const bashTool = createBashTool(cwd, bashOptions);
|
|
1575
1579
|
const healthStore = createCliWebResearchHealthStore(options.configDir ?? getConfigDir());
|
|
1576
1580
|
const webSearchTool = createSharedWebSearchTool({
|
|
1577
1581
|
getModel: options.getModel ?? (() => void 0),
|
|
@@ -301,6 +301,7 @@ function parseStatusFile(raw) {
|
|
|
301
301
|
if (Array.isArray(record.supportedThinkingLevels) && record.supportedThinkingLevels.length <= 8 && record.supportedThinkingLevels.every((l) => typeof l === "string" && thinkingRe.test(l))) {
|
|
302
302
|
file.supportedThinkingLevels = record.supportedThinkingLevels;
|
|
303
303
|
}
|
|
304
|
+
if (typeof record.yoloMode === "boolean") file.yoloMode = record.yoloMode;
|
|
304
305
|
if (typeof record.imBinding === "string" && record.imBinding.length <= 512 && !hasControlChars(record.imBinding)) file.imBinding = record.imBinding;
|
|
305
306
|
if (Array.isArray(record.allowPeers) && record.allowPeers.length <= 1e3 && record.allowPeers.every((id) => typeof id === "string" && (id === "*" || isValidInstanceId(id)))) file.allowPeers = record.allowPeers;
|
|
306
307
|
if (typeof record.secret === "string" && /^[a-f0-9]{64}$/.test(record.secret)) file.secret = record.secret;
|
|
@@ -58,7 +58,8 @@ function runGit(cwd, args) {
|
|
|
58
58
|
env: isolatedGitEnv(),
|
|
59
59
|
encoding: "utf8",
|
|
60
60
|
timeout: GIT_TIMEOUT_MS,
|
|
61
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
61
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
62
|
+
windowsHide: true
|
|
62
63
|
}).trim();
|
|
63
64
|
}
|
|
64
65
|
var SymlinkContainmentError = class extends Error {
|
|
@@ -204,7 +205,8 @@ function assertSafeStandaloneGitDir(realRoot) {
|
|
|
204
205
|
env: isolatedGitEnv(),
|
|
205
206
|
encoding: "utf8",
|
|
206
207
|
timeout: GIT_TIMEOUT_MS,
|
|
207
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
208
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
209
|
+
windowsHide: true
|
|
208
210
|
});
|
|
209
211
|
} catch (error) {
|
|
210
212
|
throw new SymlinkContainmentError(
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
isTooBroadForWorkerSandbox,
|
|
4
|
-
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
resolveEffectiveProcConfigFile
|
|
5
|
+
} from "./chunk-JBBKYDYC.js";
|
|
6
6
|
import {
|
|
7
7
|
installWindowsManagerLauncher,
|
|
8
8
|
installWindowsManagerScheduledTask,
|
|
9
9
|
queryLaunchdServicePresence,
|
|
10
10
|
queryPlatformServiceState,
|
|
11
11
|
uninstallMacosLaunchdService
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-PGNZMD2E.js";
|
|
13
13
|
import {
|
|
14
|
+
ensureWindowsUpgradeLauncher,
|
|
14
15
|
isWindowsTaskAlreadyStoppedDetail,
|
|
15
16
|
isWindowsTaskNotFoundDetail,
|
|
16
17
|
queryWindowsServiceTaskPresence,
|
|
17
18
|
queryWindowsServiceTaskState
|
|
18
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-7UFRZTQI.js";
|
|
19
20
|
import {
|
|
20
21
|
readProcessCommandLine
|
|
21
22
|
} from "./chunk-7RJXKN7N.js";
|
|
@@ -701,6 +702,7 @@ WantedBy=default.target`;
|
|
|
701
702
|
...serviceEnv,
|
|
702
703
|
["PATH", servicePath]
|
|
703
704
|
], { keepAlive: true });
|
|
705
|
+
ensureWindowsUpgradeLauncher(dir);
|
|
704
706
|
const startResult = installWindowsManagerScheduledTask({
|
|
705
707
|
taskName: platformServiceName(),
|
|
706
708
|
launcherPath: silentLauncher,
|
|
@@ -836,7 +838,7 @@ async function runUpgradeCommand(args) {
|
|
|
836
838
|
console.log("Usage: pie manager upgrade [--target <latest|x.y.z>] [--force]");
|
|
837
839
|
return;
|
|
838
840
|
}
|
|
839
|
-
const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-
|
|
841
|
+
const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-DGMMUQYY.js");
|
|
840
842
|
let targetRaw;
|
|
841
843
|
let force = false;
|
|
842
844
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -1091,7 +1093,7 @@ async function runManagerCommand(args) {
|
|
|
1091
1093
|
return;
|
|
1092
1094
|
}
|
|
1093
1095
|
if (sub === "allow") {
|
|
1094
|
-
const { runManagerAllowCommand } = await import("./manager-allow-
|
|
1096
|
+
const { runManagerAllowCommand } = await import("./manager-allow-5HYRKCCH.js");
|
|
1095
1097
|
runManagerAllowCommand(args.slice(1));
|
|
1096
1098
|
return;
|
|
1097
1099
|
}
|
|
@@ -1323,18 +1325,10 @@ async function runManagerCommand(args) {
|
|
|
1323
1325
|
return;
|
|
1324
1326
|
}
|
|
1325
1327
|
seedWorkspace(dir);
|
|
1326
|
-
const
|
|
1327
|
-
if (
|
|
1328
|
+
const effectiveProc = resolveEffectiveProcConfigFile();
|
|
1329
|
+
if (effectiveProc.exists && path3.dirname(effectiveProc.file) !== path3.resolve(dir)) {
|
|
1328
1330
|
console.log(
|
|
1329
|
-
`
|
|
1330
|
-
);
|
|
1331
|
-
} else if (procSeed.state === "user-layer") {
|
|
1332
|
-
console.log(
|
|
1333
|
-
`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.`
|
|
1334
|
-
);
|
|
1335
|
-
} else if (procSeed.state === "too-broad") {
|
|
1336
|
-
console.log(
|
|
1337
|
-
`Did not seed pie-proc config (the current directory ${path3.resolve(process.cwd())} is too broad). To dispatch work, run: pie manager allow /your/project (writes ${procSeed.file})`
|
|
1331
|
+
`pie-proc config: using ${effectiveProc.file} \u2014 worker caps and optional allowCwd come from there.`
|
|
1338
1332
|
);
|
|
1339
1333
|
}
|
|
1340
1334
|
let readinessReport;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
queryPlatformServiceState,
|
|
7
7
|
scanLinuxServiceBlockingWorkers,
|
|
8
8
|
stopAndRefreshWindowsServiceForUpgrade
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PGNZMD2E.js";
|
|
10
10
|
import {
|
|
11
11
|
normalizePreInstallStopOutcome,
|
|
12
12
|
parseWindowsTaskNumericState,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
resolveDefaultTuiUsePidFile,
|
|
15
15
|
runWindowsPreInstallStop,
|
|
16
16
|
scanBlockingWindowsPeers
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-7UFRZTQI.js";
|
|
18
18
|
import {
|
|
19
19
|
readProcessCommandLine
|
|
20
20
|
} from "./chunk-7RJXKN7N.js";
|