@pi-harness/cli 0.1.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/dist/args.d.ts +16 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +53 -0
- package/dist/args.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +40 -0
- package/dist/bin.js.map +1 -0
- package/dist/main.d.ts +14 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +148 -0
- package/dist/main.js.map +1 -0
- package/dist/node-stdio.d.ts +10 -0
- package/dist/node-stdio.d.ts.map +1 -0
- package/dist/node-stdio.js +34 -0
- package/dist/node-stdio.js.map +1 -0
- package/dist/relaunch.d.ts +5 -0
- package/dist/relaunch.d.ts.map +1 -0
- package/dist/relaunch.js +52 -0
- package/dist/relaunch.js.map +1 -0
- package/package.json +25 -0
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class CliUsageError extends Error {
|
|
2
|
+
readonly name = "CliUsageError";
|
|
3
|
+
}
|
|
4
|
+
export type LauncherInvocation = {
|
|
5
|
+
mode: "help";
|
|
6
|
+
} | {
|
|
7
|
+
mode: "version";
|
|
8
|
+
} | {
|
|
9
|
+
mode: "run";
|
|
10
|
+
profile?: string;
|
|
11
|
+
configPath?: string;
|
|
12
|
+
dumpConfig: boolean;
|
|
13
|
+
args: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare function parseLauncherArgs(args: readonly string[]): LauncherInvocation;
|
|
16
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,IAAI,mBAAmB;CAC1C;AAED,MAAM,MAAM,kBAAkB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAQtK,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAqC7E"}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class CliUsageError extends Error {
|
|
2
|
+
name = "CliUsageError";
|
|
3
|
+
}
|
|
4
|
+
function optionValue(args, index, option) {
|
|
5
|
+
const value = args[index + 1];
|
|
6
|
+
if (value === undefined || value === "--")
|
|
7
|
+
throw new CliUsageError(`${option} requires a value`);
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function parseLauncherArgs(args) {
|
|
11
|
+
let profile = "default";
|
|
12
|
+
let profileExplicit = false;
|
|
13
|
+
let configPath;
|
|
14
|
+
let dumpConfig = false;
|
|
15
|
+
const applicationArgs = [];
|
|
16
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
17
|
+
const arg = args[index];
|
|
18
|
+
if (arg === "--") {
|
|
19
|
+
applicationArgs.push(...args.slice(index + 1));
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
if (arg === "--help" || arg === "-h")
|
|
23
|
+
return { mode: "help" };
|
|
24
|
+
if (arg === "--version" || arg === "-v")
|
|
25
|
+
return { mode: "version" };
|
|
26
|
+
if (arg === "--dump-config") {
|
|
27
|
+
dumpConfig = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (arg === "--profile") {
|
|
31
|
+
if (profileExplicit)
|
|
32
|
+
throw new CliUsageError("--profile may only be specified once");
|
|
33
|
+
profile = optionValue(args, index, "--profile");
|
|
34
|
+
profileExplicit = true;
|
|
35
|
+
index += 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (arg === "--config") {
|
|
39
|
+
if (configPath !== undefined)
|
|
40
|
+
throw new CliUsageError("--config may only be specified once");
|
|
41
|
+
configPath = optionValue(args, index, "--config");
|
|
42
|
+
index += 1;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
applicationArgs.push(arg ?? "");
|
|
46
|
+
}
|
|
47
|
+
if (profileExplicit && configPath !== undefined)
|
|
48
|
+
throw new CliUsageError("--profile and --config cannot be used together");
|
|
49
|
+
return configPath === undefined
|
|
50
|
+
? { mode: "run", profile, dumpConfig, args: applicationArgs }
|
|
51
|
+
: { mode: "run", configPath, dumpConfig, args: applicationArgs };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpB,IAAI,GAAG,eAAe,CAAC;CAC1C;AAID,SAAS,WAAW,CAAC,IAAuB,EAAE,KAAa,EAAE,MAAc;IACzE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,aAAa,CAAC,GAAG,MAAM,mBAAmB,CAAC,CAAC;IACjG,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAuB;IACvD,IAAI,OAAO,GAAG,SAAS,CAAC;IACxB,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI,UAA8B,CAAC;IACnC,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAA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CAAC,CAAC;IAC3H,OAAO,UAAU,KAAK,SAAS;QAC7B,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE;QAC7D,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AACrE,CAAC"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { runCli } from "./main.js";
|
|
7
|
+
import { shouldRelaunchForDevelopmentProfile, superviseDevelopmentProcess } from "./relaunch.js";
|
|
8
|
+
const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
9
|
+
const environment = {
|
|
10
|
+
cwd: process.cwd(),
|
|
11
|
+
agentDir: process.env.PI_AGENT_DIR ?? join(homedir(), ".pi", "agent"),
|
|
12
|
+
version: packageJson.version,
|
|
13
|
+
stdin: process.stdin,
|
|
14
|
+
stdout: process.stdout,
|
|
15
|
+
stderr: process.stderr,
|
|
16
|
+
shutdownTimeoutMs: 5_000,
|
|
17
|
+
forceExit(code) {
|
|
18
|
+
process.exit(code);
|
|
19
|
+
},
|
|
20
|
+
onSignal(listener) {
|
|
21
|
+
const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
22
|
+
const handlers = signals.map((signal) => {
|
|
23
|
+
const handler = () => listener(signal);
|
|
24
|
+
process.on(signal, handler);
|
|
25
|
+
return { signal, handler };
|
|
26
|
+
});
|
|
27
|
+
return () => {
|
|
28
|
+
for (const { signal, handler } of handlers)
|
|
29
|
+
process.off(signal, handler);
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const args = process.argv.slice(2);
|
|
34
|
+
if (shouldRelaunchForDevelopmentProfile(args, process.execArgv)) {
|
|
35
|
+
process.exitCode = await superviseDevelopmentProcess(process.execPath, ["--expose-internals", ...process.execArgv, fileURLToPath(import.meta.url), ...args], { stdio: "inherit" });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
process.exitCode = await runCli(args, environment);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAuB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAEjG,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAwB,CAAC;AAEzH,MAAM,WAAW,GAAmB;IAClC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC;IACrE,OAAO,EAAE,WAAW,CAAC,OAA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IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACrL,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
export interface CliEnvironment {
|
|
3
|
+
readonly cwd: string;
|
|
4
|
+
readonly agentDir: string;
|
|
5
|
+
readonly version: string;
|
|
6
|
+
readonly stdin: Readable;
|
|
7
|
+
readonly stdout: Writable;
|
|
8
|
+
readonly stderr: Writable;
|
|
9
|
+
readonly shutdownTimeoutMs: number;
|
|
10
|
+
forceExit(code: number): void;
|
|
11
|
+
onSignal(listener: (signal: NodeJS.Signals) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function runCli(_args: readonly string[], _environment: CliEnvironment): Promise<number>;
|
|
14
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMtD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAClE;AAkBD,wBAAsB,MAAM,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,YAAY,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAuHpG"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { bootHarness, provideLaunchContext, provideStdioContext, resolveProfileConfig } from "@pi-harness/core";
|
|
3
|
+
import { CliUsageError, parseLauncherArgs } from "./args.js";
|
|
4
|
+
import { NodeStdio } from "./node-stdio.js";
|
|
5
|
+
import { PI_HARNESS_RESTART_EXIT_CODE } from "./relaunch.js";
|
|
6
|
+
async function settleWithin(promise, timeoutMs) {
|
|
7
|
+
let timer;
|
|
8
|
+
const timeout = new Promise((resolve) => {
|
|
9
|
+
timer = setTimeout(() => resolve({ settled: false }), timeoutMs);
|
|
10
|
+
});
|
|
11
|
+
const result = await Promise.race([promise.then((value) => ({ settled: true, value })), timeout]);
|
|
12
|
+
if (timer !== undefined)
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
function signalExitCode(signal) {
|
|
17
|
+
return signal === "SIGINT" ? 130 : signal === "SIGHUP" ? 129 : 143;
|
|
18
|
+
}
|
|
19
|
+
export async function runCli(_args, _environment) {
|
|
20
|
+
const args = _args;
|
|
21
|
+
const environment = _environment;
|
|
22
|
+
let invocation;
|
|
23
|
+
try {
|
|
24
|
+
invocation = parseLauncherArgs(args);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
environment.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
28
|
+
return error instanceof CliUsageError ? 2 : 1;
|
|
29
|
+
}
|
|
30
|
+
if (invocation.mode === "help") {
|
|
31
|
+
environment.stdout.write("Usage: pih [--profile <name> | --config <path>] [--dump-config] [--] [--prompt <text> | <prompt>]\n");
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
if (invocation.mode === "version") {
|
|
35
|
+
environment.stdout.write(`${environment.version}\n`);
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
let configPath;
|
|
39
|
+
try {
|
|
40
|
+
configPath = await resolveProfileConfig({
|
|
41
|
+
...(invocation.configPath === undefined ? { profile: invocation.profile ?? "default" } : { configPath: invocation.configPath }),
|
|
42
|
+
cwd: environment.cwd,
|
|
43
|
+
});
|
|
44
|
+
if (invocation.dumpConfig) {
|
|
45
|
+
environment.stdout.write(await readFile(configPath, "utf8"));
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
environment.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
53
|
+
let harness;
|
|
54
|
+
let resultCode;
|
|
55
|
+
let forcedExit = false;
|
|
56
|
+
const forceExit = (code) => {
|
|
57
|
+
if (forcedExit)
|
|
58
|
+
return;
|
|
59
|
+
forcedExit = true;
|
|
60
|
+
environment.forceExit(code);
|
|
61
|
+
};
|
|
62
|
+
let requestedExit;
|
|
63
|
+
const requestedExitPromise = new Promise((resolve) => {
|
|
64
|
+
requestedExit = resolve;
|
|
65
|
+
});
|
|
66
|
+
let signalledExit;
|
|
67
|
+
const signalPromise = new Promise((resolve) => {
|
|
68
|
+
signalledExit = resolve;
|
|
69
|
+
});
|
|
70
|
+
const startupAbort = new AbortController();
|
|
71
|
+
const removeSignals = environment.onSignal((signal) => {
|
|
72
|
+
const code = signalExitCode(signal);
|
|
73
|
+
signalledExit?.(code);
|
|
74
|
+
startupAbort.abort(new Error(`Received ${signal}`));
|
|
75
|
+
});
|
|
76
|
+
try {
|
|
77
|
+
const stdio = new NodeStdio(environment.stdin, environment.stdout, environment.stderr);
|
|
78
|
+
const bootOutcome = bootHarness({
|
|
79
|
+
configPath,
|
|
80
|
+
signal: startupAbort.signal,
|
|
81
|
+
onFullReload() {
|
|
82
|
+
requestedExit?.(PI_HARNESS_RESTART_EXIT_CODE);
|
|
83
|
+
},
|
|
84
|
+
prepare(context) {
|
|
85
|
+
provideLaunchContext(context, {
|
|
86
|
+
cwd: environment.cwd,
|
|
87
|
+
agentDir: environment.agentDir,
|
|
88
|
+
args: invocation.args,
|
|
89
|
+
requestExit(code) {
|
|
90
|
+
requestedExit?.(code);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
provideStdioContext(context, stdio);
|
|
94
|
+
},
|
|
95
|
+
}).then((booted) => ({ kind: "ready", harness: booted }), (error) => ({ kind: "error", error }));
|
|
96
|
+
const startup = await Promise.race([bootOutcome, signalPromise.then((code) => ({ kind: "signal", code }))]);
|
|
97
|
+
if (startup.kind === "signal") {
|
|
98
|
+
resultCode = startup.code;
|
|
99
|
+
const settled = await settleWithin(bootOutcome, environment.shutdownTimeoutMs);
|
|
100
|
+
if (!settled.settled) {
|
|
101
|
+
forceExit(startup.code);
|
|
102
|
+
return startup.code;
|
|
103
|
+
}
|
|
104
|
+
if (settled.value.kind === "ready")
|
|
105
|
+
harness = settled.value.harness;
|
|
106
|
+
return startup.code;
|
|
107
|
+
}
|
|
108
|
+
if (startup.kind === "error")
|
|
109
|
+
throw startup.error;
|
|
110
|
+
harness = startup.harness;
|
|
111
|
+
const application = harness.context.get("piApplication");
|
|
112
|
+
if (application === undefined)
|
|
113
|
+
throw new Error("Cordis profile did not provide a piApplication service");
|
|
114
|
+
const result = await Promise.race([
|
|
115
|
+
application.run().then((code) => ({ source: "application", code })),
|
|
116
|
+
requestedExitPromise.then((code) => ({ source: "request", code })),
|
|
117
|
+
signalPromise.then((code) => ({ source: "signal", code })),
|
|
118
|
+
]);
|
|
119
|
+
resultCode = result.code;
|
|
120
|
+
if (result.source !== "application") {
|
|
121
|
+
const runtime = harness.context.get("piRuntime");
|
|
122
|
+
if (runtime !== undefined) {
|
|
123
|
+
const aborted = await settleWithin(runtime.abort().then(() => undefined, (error) => {
|
|
124
|
+
environment.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
125
|
+
}), environment.shutdownTimeoutMs);
|
|
126
|
+
if (!aborted.settled)
|
|
127
|
+
forceExit(result.code);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return result.code;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
environment.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
134
|
+
resultCode = 1;
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
removeSignals();
|
|
139
|
+
if (harness !== undefined) {
|
|
140
|
+
const disposed = await settleWithin(harness.dispose().then(() => undefined, (error) => {
|
|
141
|
+
environment.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
142
|
+
}), environment.shutdownTimeoutMs);
|
|
143
|
+
if (!disposed.settled)
|
|
144
|
+
forceExit(resultCode ?? 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,oBAAoB,EAAsB,MAAM,kBAAkB,CAAC;AACpI,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAgB7D,KAAK,UAAU,YAAY,CAAI,OAAmB,EAAE,SAAiB;IACnE,I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AC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvG,UAAU,GAAG,CAAC,CAAC;QACf,OAAO,CAAC,CAAC;IACX,CAAC;YAAS,CAAC;QACT,aAAa,EAAE,CAAC;QAChB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC,KAAc,EAAE,EAAE;gBAC7F,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACzG,CAAC,CAAC,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAC;YACnC,IAAI,CAAC,QAAQ,CAAC,OAAO;gBAAE,SAAS,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import type { PiHarnessStdio } from "@pi-harness/core";
|
|
3
|
+
export declare class NodeStdio implements PiHarnessStdio {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(input: Readable, output: Writable, error: Writable);
|
|
6
|
+
readPrompt(): Promise<string>;
|
|
7
|
+
writeOutput(text: string): void;
|
|
8
|
+
writeError(text: string): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=node-stdio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-stdio.d.ts","sourceRoot":"","sources":["../src/node-stdio.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,qBAAa,SAAU,YAAW,cAAc;;gBAKlC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ;IAMxD,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAenC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI/B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAG/B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
export class NodeStdio {
|
|
3
|
+
#input;
|
|
4
|
+
#output;
|
|
5
|
+
#error;
|
|
6
|
+
constructor(input, output, error) {
|
|
7
|
+
this.#input = input;
|
|
8
|
+
this.#output = output;
|
|
9
|
+
this.#error = error;
|
|
10
|
+
}
|
|
11
|
+
async readPrompt() {
|
|
12
|
+
if (this.#input.isTTY === true) {
|
|
13
|
+
const readline = createInterface({ input: this.#input, output: this.#output });
|
|
14
|
+
try {
|
|
15
|
+
return await readline.question("> ");
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
readline.close();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
this.#input.setEncoding("utf8");
|
|
22
|
+
let content = "";
|
|
23
|
+
for await (const chunk of this.#input)
|
|
24
|
+
content += String(chunk);
|
|
25
|
+
return content.trimEnd();
|
|
26
|
+
}
|
|
27
|
+
writeOutput(text) {
|
|
28
|
+
this.#output.write(text);
|
|
29
|
+
}
|
|
30
|
+
writeError(text) {
|
|
31
|
+
this.#error.write(text);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=node-stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-stdio.js","sourceRoot":"","sources":["../src/node-stdio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAMzD,MAAM,OAAO,SAAS;IACX,MAAM,CAAmB;IACzB,OAAO,CAAW;IAClB,MAAM,CAAW;IAE1B,YAAY,KAAe,EAAE,MAAgB,EAAE,KAAe;QAC5D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;YAC/B,MAAM,QAAQ,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YAC/E,IAAI,CAAC;gBACH,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACvC,CAAC;oBAAS,CAAC;gBACT,QAAQ,CAAC,KAAK,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;QAChE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SpawnOptions } from "node:child_process";
|
|
2
|
+
export declare const PI_HARNESS_RESTART_EXIT_CODE = 75;
|
|
3
|
+
export declare function superviseDevelopmentProcess(command: string, args: readonly string[], options?: SpawnOptions): Promise<number>;
|
|
4
|
+
export declare function shouldRelaunchForDevelopmentProfile(args: readonly string[], execArgv: readonly string[]): boolean;
|
|
5
|
+
//# sourceMappingURL=relaunch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relaunch.d.ts","sourceRoot":"","sources":["../src/relaunch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG9D,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAS/C,wBAAsB,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyBvI;AAED,wBAAgB,mCAAmC,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAQjH"}
|
package/dist/relaunch.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { parseLauncherArgs } from "./args.js";
|
|
3
|
+
export const PI_HARNESS_RESTART_EXIT_CODE = 75;
|
|
4
|
+
function signalExitCode(signal) {
|
|
5
|
+
if (signal === "SIGINT")
|
|
6
|
+
return 130;
|
|
7
|
+
if (signal === "SIGHUP")
|
|
8
|
+
return 129;
|
|
9
|
+
if (signal === "SIGTERM")
|
|
10
|
+
return 143;
|
|
11
|
+
return 1;
|
|
12
|
+
}
|
|
13
|
+
export async function superviseDevelopmentProcess(command, args, options = {}) {
|
|
14
|
+
while (true) {
|
|
15
|
+
const result = await new Promise((resolve, reject) => {
|
|
16
|
+
const child = spawn(command, [...args], options);
|
|
17
|
+
const signals = process.platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
18
|
+
const handlers = signals.map((signal) => {
|
|
19
|
+
const handler = () => child.kill(signal);
|
|
20
|
+
process.on(signal, handler);
|
|
21
|
+
return { signal, handler };
|
|
22
|
+
});
|
|
23
|
+
const cleanup = () => {
|
|
24
|
+
for (const { signal, handler } of handlers)
|
|
25
|
+
process.off(signal, handler);
|
|
26
|
+
};
|
|
27
|
+
child.once("error", (error) => {
|
|
28
|
+
cleanup();
|
|
29
|
+
reject(error);
|
|
30
|
+
});
|
|
31
|
+
child.once("exit", (code, signal) => {
|
|
32
|
+
cleanup();
|
|
33
|
+
resolve({ code, signal });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
if (result.code === PI_HARNESS_RESTART_EXIT_CODE)
|
|
37
|
+
continue;
|
|
38
|
+
return result.code ?? signalExitCode(result.signal);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function shouldRelaunchForDevelopmentProfile(args, execArgv) {
|
|
42
|
+
if (execArgv.includes("--expose-internals"))
|
|
43
|
+
return false;
|
|
44
|
+
try {
|
|
45
|
+
const invocation = parseLauncherArgs(args);
|
|
46
|
+
return invocation.mode === "run" && invocation.configPath === undefined && invocation.profile === "development" && !invocation.dumpConfig;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=relaunch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relaunch.js","sourceRoot":"","sources":["../src/relaunch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,O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+
"main": "./dist/main.js",
|
|
10
|
+
"types": "./dist/main.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22.19.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc -p tsconfig.build.json",
|
|
19
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
20
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@pi-harness/core": "0.1.0"
|
|
24
|
+
}
|
|
25
|
+
}
|