@cydm/pie 2.8.0 → 3.0.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 +18 -0
- package/dist/builtin/extensions/ask-user/index.js +4 -3
- package/dist/builtin/extensions/changelog/index.js +2 -2
- package/dist/builtin/extensions/cron/index.js +430 -43
- package/dist/builtin/extensions/document-attachments/index.js +1 -1
- package/dist/builtin/extensions/herdr-agent-state/index.js +2 -2
- package/dist/builtin/extensions/im-forward/index.js +13 -2
- package/dist/builtin/extensions/memory/index.js +277 -83
- package/dist/builtin/extensions/memory/package.json +2 -1
- package/dist/builtin/extensions/plan-mode/index.js +4 -3
- package/dist/builtin/extensions/subagent/index.js +7 -6
- package/dist/builtin/extensions/todo/index.js +4 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +106 -2
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +1 -0
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{chunk-BNSAEVRT.js → chunk-WOGAQ4P5.js} +2 -2
- package/dist/builtin/skills/chrome-devtools-axi/{cli-AO2ZTPRM.js → cli-CHC7XYFU.js} +27 -3
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +8 -3
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-cli.js +1 -0
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +6 -1
- package/dist/builtin/skills/computer-use-axi/scripts/setup-helper.mjs +6 -2
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +130 -9
- package/dist/chunks/auth-storage-3EGM3VTK.js +13 -0
- package/dist/chunks/{chunk-JNOFHHLZ.js → chunk-3BC5KGDQ.js} +383 -185
- package/dist/chunks/chunk-3FRKOFSP.js +9667 -0
- package/dist/chunks/chunk-6DNYGVZP.js +278 -0
- package/dist/chunks/{chunk-LJXHECZ7.js → chunk-7FEPQHYX.js} +13867 -19759
- package/dist/chunks/{chunk-NEES4EBX.js → chunk-BUDXV3TR.js} +28 -18
- package/dist/chunks/{chunk-HGC25NYB.js → chunk-GH4VW2OT.js} +1 -1
- package/dist/chunks/{chunk-5353DEEC.js → chunk-ILUHTKF3.js} +20 -1
- package/dist/chunks/chunk-OEQYEYB3.js +299 -0
- package/dist/chunks/chunk-YRR6C43W.js +1740 -0
- package/dist/chunks/config-74AUVDLT.js +46 -0
- package/dist/chunks/model-registry-LI5THXV4.js +17 -0
- package/dist/chunks/src-66XSMIAM.js +134 -0
- package/dist/chunks/src-AE3OCAE6.js +431 -0
- package/dist/chunks/src-RVTDUSPJ.js +293 -0
- package/dist/chunks/{src-5XOKRS6F.js → src-YG5M2H44.js} +2 -2
- package/dist/chunks/{test-stream-5SDHKKDB.js → test-stream-JBWXKOQA.js} +1 -1
- package/dist/cli.js +1455 -2358
- package/package.json +4 -4
|
@@ -4,11 +4,12 @@ import {
|
|
|
4
4
|
BRIDGE_PORT_IN_USE_EXIT_CODE,
|
|
5
5
|
PAGE_IDENTITY_CHANGED_ERROR,
|
|
6
6
|
clearSelectedPageId,
|
|
7
|
+
inspectProcessIdentity,
|
|
7
8
|
readSelfStartTime,
|
|
8
9
|
resolveSessionName,
|
|
9
10
|
resolveSessionPidFile,
|
|
10
11
|
resolveSessionPort
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WOGAQ4P5.js";
|
|
12
13
|
import {
|
|
13
14
|
__commonJS,
|
|
14
15
|
__export,
|
|
@@ -19571,6 +19572,36 @@ import {
|
|
|
19571
19572
|
} from "node:fs";
|
|
19572
19573
|
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
19573
19574
|
import { pathToFileURL } from "node:url";
|
|
19575
|
+
|
|
19576
|
+
// vendor/chrome-devtools-axi/src/supervisor-anchor-shared.ts
|
|
19577
|
+
var SUPERVISOR_PID_ENV = "PIE_SUPERVISOR_PID";
|
|
19578
|
+
var SUPERVISOR_START_TIME_ENV = "PIE_SUPERVISOR_START_TIME";
|
|
19579
|
+
function parseSupervisorAnchor(env = process.env) {
|
|
19580
|
+
const pidText = env[SUPERVISOR_PID_ENV]?.trim();
|
|
19581
|
+
if (!pidText || !/^\d+$/.test(pidText)) return void 0;
|
|
19582
|
+
const pid = Number(pidText);
|
|
19583
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
|
|
19584
|
+
const startTime = env[SUPERVISOR_START_TIME_ENV]?.trim();
|
|
19585
|
+
return startTime ? { pid, startTime } : { pid };
|
|
19586
|
+
}
|
|
19587
|
+
function isSupervisorGone(anchor2, readIdentity) {
|
|
19588
|
+
try {
|
|
19589
|
+
process.kill(anchor2.pid, 0);
|
|
19590
|
+
} catch (error2) {
|
|
19591
|
+
return error2.code === "ESRCH";
|
|
19592
|
+
}
|
|
19593
|
+
let identity;
|
|
19594
|
+
try {
|
|
19595
|
+
identity = readIdentity(anchor2.pid);
|
|
19596
|
+
} catch {
|
|
19597
|
+
return false;
|
|
19598
|
+
}
|
|
19599
|
+
if (identity.startTime === void 0) return false;
|
|
19600
|
+
if (anchor2.startTime === void 0) return false;
|
|
19601
|
+
return identity.startTime !== anchor2.startTime;
|
|
19602
|
+
}
|
|
19603
|
+
|
|
19604
|
+
// vendor/chrome-devtools-axi/src/bridge.ts
|
|
19574
19605
|
async function isBridgeClientConnected(client) {
|
|
19575
19606
|
try {
|
|
19576
19607
|
await client.listTools();
|
|
@@ -19849,6 +19880,72 @@ function handleBridgeServerError(error2, port, exit = process.exit) {
|
|
|
19849
19880
|
function writeReadySignal() {
|
|
19850
19881
|
process.stdout.write("READY\n");
|
|
19851
19882
|
}
|
|
19883
|
+
var LAUNCHER_HEADER = "x-axi-launcher";
|
|
19884
|
+
var DEFAULT_HEARTBEAT_MS = 3e4;
|
|
19885
|
+
var DEFAULT_IDLE_SHUTDOWN_MS = 30 * 6e4;
|
|
19886
|
+
var parseSupervisorAnchor2 = parseSupervisorAnchor;
|
|
19887
|
+
var isSupervisorGone2 = (supervisor) => isSupervisorGone(supervisor, inspectProcessIdentity);
|
|
19888
|
+
function parseLauncherHeader(value) {
|
|
19889
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
19890
|
+
if (!raw) return void 0;
|
|
19891
|
+
const colon = raw.indexOf(":");
|
|
19892
|
+
const pidText = colon === -1 ? raw : raw.slice(0, colon);
|
|
19893
|
+
if (!/^\d+$/.test(pidText)) return void 0;
|
|
19894
|
+
const pid = Number(pidText);
|
|
19895
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
|
|
19896
|
+
const startTime = colon === -1 ? void 0 : raw.slice(colon + 1);
|
|
19897
|
+
return startTime ? { pid, startTime } : { pid };
|
|
19898
|
+
}
|
|
19899
|
+
function createBridgeLifecycle(shutdown, opts = {}) {
|
|
19900
|
+
const heartbeatMs = opts.heartbeatMs ?? DEFAULT_HEARTBEAT_MS;
|
|
19901
|
+
const idleShutdownMs = opts.idleShutdownMs ?? DEFAULT_IDLE_SHUTDOWN_MS;
|
|
19902
|
+
const now = opts.now ?? Date.now;
|
|
19903
|
+
let supervisor;
|
|
19904
|
+
let supervisorFromEnv = false;
|
|
19905
|
+
if (opts.anchor) {
|
|
19906
|
+
supervisor = opts.anchor;
|
|
19907
|
+
supervisorFromEnv = true;
|
|
19908
|
+
}
|
|
19909
|
+
let lastRequestAt = now();
|
|
19910
|
+
let disposed = false;
|
|
19911
|
+
const fire = (reason) => {
|
|
19912
|
+
disposed = true;
|
|
19913
|
+
clearInterval(timer);
|
|
19914
|
+
logBridgeMessage(reason);
|
|
19915
|
+
try {
|
|
19916
|
+
void shutdown();
|
|
19917
|
+
} catch {
|
|
19918
|
+
}
|
|
19919
|
+
};
|
|
19920
|
+
const tick = () => {
|
|
19921
|
+
if (disposed) return;
|
|
19922
|
+
const t = now();
|
|
19923
|
+
if (t - lastRequestAt >= idleShutdownMs) {
|
|
19924
|
+
fire(`idle ${Math.round((t - lastRequestAt) / 1e3)}s \u2265 ${Math.round(idleShutdownMs / 1e3)}s with no requests; shutting down`);
|
|
19925
|
+
return;
|
|
19926
|
+
}
|
|
19927
|
+
if (supervisor && isSupervisorGone2(supervisor)) {
|
|
19928
|
+
fire(`supervisor pid ${supervisor.pid} is gone and no requests since; shutting down`);
|
|
19929
|
+
return;
|
|
19930
|
+
}
|
|
19931
|
+
};
|
|
19932
|
+
const timer = setInterval(tick, heartbeatMs);
|
|
19933
|
+
timer.unref?.();
|
|
19934
|
+
return {
|
|
19935
|
+
observeRequest(req) {
|
|
19936
|
+
lastRequestAt = now();
|
|
19937
|
+
if (supervisorFromEnv) return;
|
|
19938
|
+
const next = parseLauncherHeader(req.headers[LAUNCHER_HEADER]);
|
|
19939
|
+
if (!next) return;
|
|
19940
|
+
if (supervisor?.startTime && !next.startTime) return;
|
|
19941
|
+
supervisor = next;
|
|
19942
|
+
},
|
|
19943
|
+
dispose() {
|
|
19944
|
+
disposed = true;
|
|
19945
|
+
clearInterval(timer);
|
|
19946
|
+
}
|
|
19947
|
+
};
|
|
19948
|
+
}
|
|
19852
19949
|
var KEYCHAIN_ISOLATION_CHROME_ARGS = [
|
|
19853
19950
|
"--use-mock-keychain",
|
|
19854
19951
|
"--password-store=basic"
|
|
@@ -19913,7 +20010,8 @@ var DEFAULT_MCP_PATH_PROBE = {
|
|
|
19913
20010
|
try {
|
|
19914
20011
|
return execSync("npm prefix -g", {
|
|
19915
20012
|
encoding: "utf8",
|
|
19916
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
20013
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
20014
|
+
windowsHide: true
|
|
19917
20015
|
}).trim();
|
|
19918
20016
|
} catch {
|
|
19919
20017
|
return null;
|
|
@@ -19954,6 +20052,7 @@ function resolveTransportSpec(probe = DEFAULT_MCP_PATH_PROBE) {
|
|
|
19954
20052
|
help = execFileSync(process.execPath, [explicitPath, "--help"], {
|
|
19955
20053
|
encoding: "utf8",
|
|
19956
20054
|
stdio: ["ignore", "pipe", "pipe"],
|
|
20055
|
+
windowsHide: true,
|
|
19957
20056
|
timeout: 5e3,
|
|
19958
20057
|
killSignal: "SIGKILL"
|
|
19959
20058
|
});
|
|
@@ -20152,6 +20251,10 @@ async function runBridge(port = resolveSessionPort()) {
|
|
|
20152
20251
|
logBridgeMessage("Connected to chrome-devtools-mcp");
|
|
20153
20252
|
const sessionName = resolveSessionName();
|
|
20154
20253
|
const server = createBridgeServer(bridgeClient, sessionName);
|
|
20254
|
+
const lifecycle = createBridgeLifecycle(() => shutdown(), {
|
|
20255
|
+
anchor: parseSupervisorAnchor2()
|
|
20256
|
+
});
|
|
20257
|
+
server.on("request", (req) => lifecycle.observeRequest(req));
|
|
20155
20258
|
server.on("error", (error2) => {
|
|
20156
20259
|
handleBridgeServerError(error2, port);
|
|
20157
20260
|
});
|
|
@@ -20164,6 +20267,7 @@ async function runBridge(port = resolveSessionPort()) {
|
|
|
20164
20267
|
const shutdown = async () => {
|
|
20165
20268
|
if (shuttingDown) return;
|
|
20166
20269
|
shuttingDown = true;
|
|
20270
|
+
lifecycle.dispose();
|
|
20167
20271
|
removePidFile();
|
|
20168
20272
|
await closeServer(server);
|
|
20169
20273
|
await closeBridgeTransport(bridgeTransport);
|
|
@@ -39,6 +39,7 @@ export function resolveChromeDevtoolsMcpScript() {
|
|
|
39
39
|
export function runChromeDevtoolsAxiCli(args = process.argv.slice(2), options = {}) {
|
|
40
40
|
const bin = resolveChromeDevtoolsAxiCli();
|
|
41
41
|
return spawnSync(process.execPath, [bin, ...args], {
|
|
42
|
+
windowsHide: true,
|
|
42
43
|
stdio: "inherit",
|
|
43
44
|
shell: false,
|
|
44
45
|
...options,
|
|
@@ -21,6 +21,6 @@ function tryFastPath(argv, options) {
|
|
|
21
21
|
|
|
22
22
|
// vendor/chrome-devtools-axi/bin/chrome-devtools-axi.ts
|
|
23
23
|
if (!tryFastPath(process.argv.slice(2), { version: VERSION })) {
|
|
24
|
-
const { main } = await import("./cli-
|
|
24
|
+
const { main } = await import("./cli-CHC7XYFU.js");
|
|
25
25
|
await main(process.argv.slice(2));
|
|
26
26
|
}
|
|
@@ -334,7 +334,7 @@ function inspectProcessIdentity(pid) {
|
|
|
334
334
|
"-Command",
|
|
335
335
|
`$p = Get-CimInstance Win32_Process -Filter "ProcessId=<pid>"; if ($p) { $p.CommandLine; $p.CreationDate.ToString('o') }`.replace("<pid>", String(pid))
|
|
336
336
|
],
|
|
337
|
-
{ encoding: "utf-8", timeout: 4e3 }
|
|
337
|
+
{ encoding: "utf-8", timeout: 4e3, windowsHide: true }
|
|
338
338
|
);
|
|
339
339
|
const lines = output.split(/\r?\n/).filter((line) => line.length > 0);
|
|
340
340
|
if (lines.length === 0) return {};
|
|
@@ -345,7 +345,7 @@ function inspectProcessIdentity(pid) {
|
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
try {
|
|
348
|
-
const psEnv = { ...process.env, LC_ALL: "C", LANG: "C" };
|
|
348
|
+
const psEnv = { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC0" };
|
|
349
349
|
const output = execFileSync(
|
|
350
350
|
"ps",
|
|
351
351
|
["-p", String(pid), "-o", "lstart=", "-o", "command="],
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
needsPageId,
|
|
13
13
|
overlaySessionSelected,
|
|
14
14
|
parsePagesList,
|
|
15
|
+
readSelfStartTime,
|
|
15
16
|
rememberToolRouting,
|
|
16
17
|
resolveBridgeScript,
|
|
17
18
|
resolveSessionName,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
resolveSessionPort,
|
|
20
21
|
resolveSessionStateDir,
|
|
21
22
|
setSelectedPageId
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-WOGAQ4P5.js";
|
|
23
24
|
import "./chunk-OJ6N23UZ.js";
|
|
24
25
|
|
|
25
26
|
// ../../node_modules/chrome-devtools-axi/node_modules/@toon-format/toon/dist/index.mjs
|
|
@@ -1661,10 +1662,31 @@ function isProcessAlive(pid) {
|
|
|
1661
1662
|
return error?.code !== "ESRCH";
|
|
1662
1663
|
}
|
|
1663
1664
|
}
|
|
1665
|
+
var cachedLauncherHeader;
|
|
1666
|
+
function launcherHeader() {
|
|
1667
|
+
cachedLauncherHeader ??= (() => {
|
|
1668
|
+
const pid = process.env.PIE_SUPERVISOR_PID?.trim();
|
|
1669
|
+
if (pid && Number.isInteger(Number(pid)) && Number(pid) > 0) {
|
|
1670
|
+
const startTime = process.env.PIE_SUPERVISOR_START_TIME?.trim() ?? "";
|
|
1671
|
+
return `${pid}:${startTime}`;
|
|
1672
|
+
}
|
|
1673
|
+
return `${process.pid}:${readSelfStartTime() ?? ""}`;
|
|
1674
|
+
})();
|
|
1675
|
+
return cachedLauncherHeader;
|
|
1676
|
+
}
|
|
1664
1677
|
function httpGet(port, path, timeoutMs = 2e3) {
|
|
1665
1678
|
return new Promise((resolve3, reject) => {
|
|
1666
1679
|
const req = request(
|
|
1667
|
-
{
|
|
1680
|
+
{
|
|
1681
|
+
hostname: "127.0.0.1",
|
|
1682
|
+
port,
|
|
1683
|
+
path,
|
|
1684
|
+
method: "GET",
|
|
1685
|
+
timeout: timeoutMs,
|
|
1686
|
+
// Identify this launcher to the bridge so it can supervise our
|
|
1687
|
+
// liveness and reap its detached tree when we die (leak fix).
|
|
1688
|
+
headers: { "x-axi-launcher": launcherHeader() }
|
|
1689
|
+
},
|
|
1668
1690
|
(res) => {
|
|
1669
1691
|
res.setEncoding("utf8");
|
|
1670
1692
|
let data = "";
|
|
@@ -1829,7 +1851,7 @@ function isBridgeProcess(pid, expectedStartTime) {
|
|
|
1829
1851
|
"-Command",
|
|
1830
1852
|
`(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CommandLine`
|
|
1831
1853
|
],
|
|
1832
|
-
{ encoding: "utf-8", timeout: 4e3 }
|
|
1854
|
+
{ encoding: "utf-8", timeout: 4e3, windowsHide: true }
|
|
1833
1855
|
);
|
|
1834
1856
|
if (!commandLineLooksLikeBridge(command)) return false;
|
|
1835
1857
|
} catch {
|
|
@@ -1905,6 +1927,7 @@ function taskkillTree(pid) {
|
|
|
1905
1927
|
try {
|
|
1906
1928
|
execFileSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
1907
1929
|
stdio: "ignore",
|
|
1930
|
+
windowsHide: true,
|
|
1908
1931
|
timeout: 1e4
|
|
1909
1932
|
});
|
|
1910
1933
|
return true;
|
|
@@ -1964,6 +1987,7 @@ function spawnBridgeProcess(port, sessionName) {
|
|
|
1964
1987
|
runner === "tsx" ? ["tsx", script] : [script],
|
|
1965
1988
|
{
|
|
1966
1989
|
stdio: "ignore",
|
|
1990
|
+
windowsHide: true,
|
|
1967
1991
|
env: {
|
|
1968
1992
|
...process.env,
|
|
1969
1993
|
CHROME_DEVTOOLS_AXI_PORT: String(port),
|
|
@@ -4396,9 +4396,14 @@ var VERSION = pkg.version;
|
|
|
4396
4396
|
var ENV_AGENT_DIR = "PIE_CODING_AGENT_DIR";
|
|
4397
4397
|
function getConfigDir() {
|
|
4398
4398
|
const envDir = process.env[ENV_AGENT_DIR];
|
|
4399
|
-
if (envDir) {
|
|
4399
|
+
if (envDir !== void 0 && envDir !== "") {
|
|
4400
4400
|
if (envDir === "~") return homedir();
|
|
4401
4401
|
if (envDir.startsWith("~/")) return homedir() + envDir.slice(1);
|
|
4402
|
+
if (envDir === "undefined" || envDir === "null") {
|
|
4403
|
+
throw new Error(
|
|
4404
|
+
`${ENV_AGENT_DIR} is set to the literal string "${envDir}"; unset it or point it at a real directory`
|
|
4405
|
+
);
|
|
4406
|
+
}
|
|
4402
4407
|
return envDir;
|
|
4403
4408
|
}
|
|
4404
4409
|
return join(homedir(), CONFIG_DIR_NAME);
|
|
@@ -7568,7 +7573,7 @@ async function runProcess3(command, args, timeoutMs, signal, env) {
|
|
|
7568
7573
|
if (signal?.aborted) throw new Error("Operation aborted.");
|
|
7569
7574
|
await new Promise((resolve2, reject) => {
|
|
7570
7575
|
assertNativeBackendAllowed();
|
|
7571
|
-
const child = spawn3(command, args, { stdio: ["ignore", "pipe", "pipe"], env });
|
|
7576
|
+
const child = spawn3(command, args, { stdio: ["ignore", "pipe", "pipe"], env, windowsHide: true });
|
|
7572
7577
|
let stdout = "";
|
|
7573
7578
|
let stderr = "";
|
|
7574
7579
|
const cleanup = () => {
|
|
@@ -7638,7 +7643,7 @@ var WindowsHelperClient = class {
|
|
|
7638
7643
|
await this.ensureInstalled(signal);
|
|
7639
7644
|
if (this.child && this.child.exitCode === null && !this.child.killed) return this.child;
|
|
7640
7645
|
assertNativeBackendAllowed();
|
|
7641
|
-
const child = spawn3(WINDOWS_HELPER_PATH, [], { stdio: ["pipe", "pipe", "pipe"] });
|
|
7646
|
+
const child = spawn3(WINDOWS_HELPER_PATH, [], { stdio: ["pipe", "pipe", "pipe"], windowsHide: true });
|
|
7642
7647
|
child.stdout.setEncoding("utf8");
|
|
7643
7648
|
child.stderr.setEncoding("utf8");
|
|
7644
7649
|
child.stdin.setDefaultEncoding("utf8");
|
|
@@ -27,6 +27,7 @@ export function resolveComputerUseAxiCli() {
|
|
|
27
27
|
function main() {
|
|
28
28
|
const runtime = resolveComputerUseAxiCli();
|
|
29
29
|
const result = spawnSync(process.execPath, [runtime, ...process.argv.slice(2)], {
|
|
30
|
+
windowsHide: true,
|
|
30
31
|
stdio: "inherit",
|
|
31
32
|
shell: false,
|
|
32
33
|
env: process.env,
|
|
@@ -71,9 +71,14 @@ var VERSION = pkg.version;
|
|
|
71
71
|
var ENV_AGENT_DIR = "PIE_CODING_AGENT_DIR";
|
|
72
72
|
function getConfigDir() {
|
|
73
73
|
const envDir = process.env[ENV_AGENT_DIR];
|
|
74
|
-
if (envDir) {
|
|
74
|
+
if (envDir !== void 0 && envDir !== "") {
|
|
75
75
|
if (envDir === "~") return homedir();
|
|
76
76
|
if (envDir.startsWith("~/")) return homedir() + envDir.slice(1);
|
|
77
|
+
if (envDir === "undefined" || envDir === "null") {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`${ENV_AGENT_DIR} is set to the literal string "${envDir}"; unset it or point it at a real directory`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
77
82
|
return envDir;
|
|
78
83
|
}
|
|
79
84
|
return join(homedir(), CONFIG_DIR_NAME);
|
|
@@ -123,7 +123,11 @@ async function copyIfChanged(sourcePath, destinationPath) {
|
|
|
123
123
|
|
|
124
124
|
async function run(command, commandArgs) {
|
|
125
125
|
await new Promise((resolve, reject) => {
|
|
126
|
-
|
|
126
|
+
// windowsHide: console-less hosts (Node spawning this script on Windows,
|
|
127
|
+
// e.g. the helper auto-install path) must not flash conhost windows at
|
|
128
|
+
// the user; when run interactively from a real terminal the flag is a
|
|
129
|
+
// no-op (the child still inherits stdio below).
|
|
130
|
+
const child = spawn(command, commandArgs, { stdio: "inherit", windowsHide: true });
|
|
127
131
|
child.on("error", reject);
|
|
128
132
|
child.on("close", (code) => {
|
|
129
133
|
if (code === 0) {
|
|
@@ -140,7 +144,7 @@ function moduleCachePath(arch) {
|
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
async function commandOutput(command, commandArgs) {
|
|
143
|
-
const { stdout } = await execFile(command, commandArgs, { encoding: "utf8" });
|
|
147
|
+
const { stdout } = await execFile(command, commandArgs, { encoding: "utf8", windowsHide: true });
|
|
144
148
|
return stdout;
|
|
145
149
|
}
|
|
146
150
|
|
|
@@ -7476,10 +7476,20 @@ Supported keys: ${supported}`
|
|
|
7476
7476
|
async killProcess() {
|
|
7477
7477
|
if (this._status === "running") {
|
|
7478
7478
|
this.ptyProcess.kill();
|
|
7479
|
-
|
|
7479
|
+
let deadline = Date.now() + 1e3;
|
|
7480
7480
|
while (this._status === "running" && Date.now() < deadline) {
|
|
7481
7481
|
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
7482
7482
|
}
|
|
7483
|
+
if (this._status === "running") {
|
|
7484
|
+
try {
|
|
7485
|
+
this.ptyProcess.kill("SIGKILL");
|
|
7486
|
+
} catch {
|
|
7487
|
+
}
|
|
7488
|
+
deadline = Date.now() + 2e3;
|
|
7489
|
+
while (this._status === "running" && Date.now() < deadline) {
|
|
7490
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
7491
|
+
}
|
|
7492
|
+
}
|
|
7483
7493
|
if (this._status === "running") {
|
|
7484
7494
|
throw new Error(`Session ${this.id} did not exit after kill.`);
|
|
7485
7495
|
}
|
|
@@ -7674,6 +7684,59 @@ var PID_PATH = import_node_path3.default.join(STATE_DIR, "daemon.pid");
|
|
|
7674
7684
|
var LOCK_PATH = import_node_path3.default.join(STATE_DIR, "startup.lock");
|
|
7675
7685
|
var SOCKET_PATH = process.platform === "win32" ? `\\\\.\\pipe\\pie-tui-${(0, import_node_crypto.createHash)("sha256").update(STATE_DIR.toLowerCase()).digest("hex").slice(0, 24)}` : import_node_path3.default.join(STATE_DIR, "daemon.sock");
|
|
7676
7686
|
|
|
7687
|
+
// vendor/tui-use/src/supervisor-anchor-shared.ts
|
|
7688
|
+
var SUPERVISOR_PID_ENV = "PIE_SUPERVISOR_PID";
|
|
7689
|
+
var SUPERVISOR_START_TIME_ENV = "PIE_SUPERVISOR_START_TIME";
|
|
7690
|
+
function parseSupervisorAnchor(env = process.env) {
|
|
7691
|
+
const pidText = env[SUPERVISOR_PID_ENV]?.trim();
|
|
7692
|
+
if (!pidText || !/^\d+$/.test(pidText)) return void 0;
|
|
7693
|
+
const pid = Number(pidText);
|
|
7694
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
|
|
7695
|
+
const startTime = env[SUPERVISOR_START_TIME_ENV]?.trim();
|
|
7696
|
+
return startTime ? { pid, startTime } : { pid };
|
|
7697
|
+
}
|
|
7698
|
+
function readStartTime(pid) {
|
|
7699
|
+
if (!Number.isInteger(pid) || pid <= 0) return void 0;
|
|
7700
|
+
if (process.platform === "win32") {
|
|
7701
|
+
try {
|
|
7702
|
+
const { execFileSync } = require("node:child_process");
|
|
7703
|
+
return execFileSync(
|
|
7704
|
+
"powershell",
|
|
7705
|
+
[
|
|
7706
|
+
"-NoProfile",
|
|
7707
|
+
"-NonInteractive",
|
|
7708
|
+
"-Command",
|
|
7709
|
+
`$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; if ($p) { $p.CreationDate.ToString('o') }`
|
|
7710
|
+
],
|
|
7711
|
+
{ timeout: 5e3, encoding: "utf8", windowsHide: true }
|
|
7712
|
+
).trim() || void 0;
|
|
7713
|
+
} catch {
|
|
7714
|
+
return void 0;
|
|
7715
|
+
}
|
|
7716
|
+
}
|
|
7717
|
+
try {
|
|
7718
|
+
const { execFileSync } = require("node:child_process");
|
|
7719
|
+
return execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
7720
|
+
timeout: 5e3,
|
|
7721
|
+
env: { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC0" },
|
|
7722
|
+
encoding: "utf8"
|
|
7723
|
+
}).trim() || void 0;
|
|
7724
|
+
} catch {
|
|
7725
|
+
return void 0;
|
|
7726
|
+
}
|
|
7727
|
+
}
|
|
7728
|
+
function isSupervisorGone(anchor) {
|
|
7729
|
+
try {
|
|
7730
|
+
process.kill(anchor.pid, 0);
|
|
7731
|
+
} catch (error) {
|
|
7732
|
+
return error.code === "ESRCH";
|
|
7733
|
+
}
|
|
7734
|
+
const identity = { startTime: readStartTime(anchor.pid) };
|
|
7735
|
+
if (identity.startTime === void 0) return false;
|
|
7736
|
+
if (anchor.startTime === void 0) return false;
|
|
7737
|
+
return identity.startTime !== anchor.startTime;
|
|
7738
|
+
}
|
|
7739
|
+
|
|
7677
7740
|
// vendor/tui-use/package.json
|
|
7678
7741
|
var version = "0.1.18-pie.3";
|
|
7679
7742
|
|
|
@@ -7681,6 +7744,9 @@ var version = "0.1.18-pie.3";
|
|
|
7681
7744
|
var sessions = /* @__PURE__ */ new Map();
|
|
7682
7745
|
var exitedAt = /* @__PURE__ */ new Map();
|
|
7683
7746
|
var busy = /* @__PURE__ */ new Map();
|
|
7747
|
+
var sessionAnchors = /* @__PURE__ */ new Map();
|
|
7748
|
+
var lastSessionActivity = /* @__PURE__ */ new Map();
|
|
7749
|
+
var SESSION_MAX_IDLE_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
7684
7750
|
var instanceId = (0, import_node_crypto2.randomUUID)();
|
|
7685
7751
|
var idleSetting = Number(process.env.PIE_TUI_USE_IDLE_TIMEOUT_MS);
|
|
7686
7752
|
var idleTimeout = Number.isInteger(idleSetting) && idleSetting >= 100 && idleSetting <= 3e5 ? idleSetting : 3e5;
|
|
@@ -7694,9 +7760,53 @@ function pruneExited() {
|
|
|
7694
7760
|
sessions.get(id)?.dispose();
|
|
7695
7761
|
sessions.delete(id);
|
|
7696
7762
|
exitedAt.delete(id);
|
|
7763
|
+
sessionAnchors.delete(id);
|
|
7764
|
+
lastSessionActivity.delete(id);
|
|
7697
7765
|
if (currentSession === id) currentSession = null;
|
|
7698
7766
|
}
|
|
7699
7767
|
}
|
|
7768
|
+
function reapOrphanedSessions() {
|
|
7769
|
+
if (shuttingDown) return;
|
|
7770
|
+
for (const id of [...sessionAnchors.keys()]) {
|
|
7771
|
+
if (!sessions.has(id)) sessionAnchors.delete(id);
|
|
7772
|
+
}
|
|
7773
|
+
for (const [id, anchor] of sessionAnchors) {
|
|
7774
|
+
if (!anchor || busy.get(id)) continue;
|
|
7775
|
+
const session = sessions.get(id);
|
|
7776
|
+
if (!session || session.status !== "running") continue;
|
|
7777
|
+
if (!isSupervisorGone(anchor)) continue;
|
|
7778
|
+
try {
|
|
7779
|
+
import_node_fs2.default.appendFileSync(LOG_PATH, `[reap] session ${id} creator pid ${anchor.pid} is gone; killing PTY tree
|
|
7780
|
+
`);
|
|
7781
|
+
} catch {
|
|
7782
|
+
}
|
|
7783
|
+
void session.kill().then(() => {
|
|
7784
|
+
exitedAt.set(id, Date.now());
|
|
7785
|
+
sessionAnchors.delete(id);
|
|
7786
|
+
pruneExited();
|
|
7787
|
+
updateIdleTimer();
|
|
7788
|
+
}).catch(() => {
|
|
7789
|
+
});
|
|
7790
|
+
}
|
|
7791
|
+
for (const [id, session] of sessions) {
|
|
7792
|
+
if (busy.get(id) || session.status !== "running") continue;
|
|
7793
|
+
const anchor = sessionAnchors.get(id);
|
|
7794
|
+
if (anchor && !isSupervisorGone(anchor)) continue;
|
|
7795
|
+
const last = lastSessionActivity.get(id) ?? session.startTime;
|
|
7796
|
+
if (Date.now() - last < SESSION_MAX_IDLE_AGE_MS) continue;
|
|
7797
|
+
try {
|
|
7798
|
+
import_node_fs2.default.appendFileSync(LOG_PATH, `[reap] session ${id} exceeded max idle age (${Math.round((Date.now() - last) / 6e4)}min, no live anchor); killing PTY tree
|
|
7799
|
+
`);
|
|
7800
|
+
} catch {
|
|
7801
|
+
}
|
|
7802
|
+
void session.kill().then(() => {
|
|
7803
|
+
exitedAt.set(id, Date.now());
|
|
7804
|
+
pruneExited();
|
|
7805
|
+
updateIdleTimer();
|
|
7806
|
+
}).catch(() => {
|
|
7807
|
+
});
|
|
7808
|
+
}
|
|
7809
|
+
}
|
|
7700
7810
|
function updateIdleTimer() {
|
|
7701
7811
|
clearTimeout(idleTimer);
|
|
7702
7812
|
if (shuttingDown || [...sessions.values()].some((session) => session.status === "running") || busy.size) return;
|
|
@@ -7705,6 +7815,8 @@ function updateIdleTimer() {
|
|
|
7705
7815
|
}, idleTimeout);
|
|
7706
7816
|
idleTimer.unref();
|
|
7707
7817
|
}
|
|
7818
|
+
var reapTimer = setInterval(() => reapOrphanedSessions(), 3e4);
|
|
7819
|
+
reapTimer.unref?.();
|
|
7708
7820
|
async function shutdown() {
|
|
7709
7821
|
if (shuttingDown) throw new Error("Daemon is already stopping.");
|
|
7710
7822
|
shuttingDown = true;
|
|
@@ -7734,14 +7846,22 @@ async function handleRequest(req, signal) {
|
|
|
7734
7846
|
do {
|
|
7735
7847
|
id2 = (0, import_node_crypto2.randomUUID)();
|
|
7736
7848
|
} while (sessions.has(id2));
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
7849
|
+
sessionAnchors.set(id2, parseSupervisorAnchor(req.env ?? process.env));
|
|
7850
|
+
let session2;
|
|
7851
|
+
try {
|
|
7852
|
+
session2 = new Session(id2, req.command, {
|
|
7853
|
+
...req,
|
|
7854
|
+
onExit: () => {
|
|
7855
|
+
exitedAt.set(id2, Date.now());
|
|
7856
|
+
sessionAnchors.delete(id2);
|
|
7857
|
+
pruneExited();
|
|
7858
|
+
updateIdleTimer();
|
|
7859
|
+
}
|
|
7860
|
+
});
|
|
7861
|
+
} catch (error) {
|
|
7862
|
+
sessionAnchors.delete(id2);
|
|
7863
|
+
throw error;
|
|
7864
|
+
}
|
|
7745
7865
|
sessions.set(id2, session2);
|
|
7746
7866
|
currentSession = id2;
|
|
7747
7867
|
updateIdleTimer();
|
|
@@ -7765,6 +7885,7 @@ async function handleRequest(req, signal) {
|
|
|
7765
7885
|
const session = sessions.get(id);
|
|
7766
7886
|
if (!session) throw new Error(`Session not found: ${id}`);
|
|
7767
7887
|
busy.set(id, (busy.get(id) ?? 0) + 1);
|
|
7888
|
+
lastSessionActivity.set(id, Date.now());
|
|
7768
7889
|
updateIdleTimer();
|
|
7769
7890
|
try {
|
|
7770
7891
|
switch (req.type) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
AuthStorage,
|
|
4
|
+
FileAuthStorageBackend,
|
|
5
|
+
InMemoryAuthStorageBackend
|
|
6
|
+
} from "./chunk-6DNYGVZP.js";
|
|
7
|
+
import "./chunk-ILUHTKF3.js";
|
|
8
|
+
import "./chunk-LZQXQOPJ.js";
|
|
9
|
+
export {
|
|
10
|
+
AuthStorage,
|
|
11
|
+
FileAuthStorageBackend,
|
|
12
|
+
InMemoryAuthStorageBackend
|
|
13
|
+
};
|