refactor(tools): remove remaining arbitrary workflow caps
This commit is contained in:
@@ -1189,7 +1189,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
if (!results.decompileCompleted()) {
|
if (!results.decompileCompleted()) {
|
||||||
throw new RequestFailure(
|
throw new RequestFailure(
|
||||||
"decompile_failed",
|
"decompile_failed",
|
||||||
"Ghidra decompilation failed: " + boundedMessage(results.getErrorMessage())
|
"Ghidra decompilation failed: " + diagnosticMessage(results.getErrorMessage())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
@@ -1506,11 +1506,11 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
return canonicalOffset(inclusive.getAddressSpace(), offset.add(BigInteger.ONE));
|
return canonicalOffset(inclusive.getAddressSpace(), offset.add(BigInteger.ONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String boundedMessage(String value) {
|
private static String diagnosticMessage(String value) {
|
||||||
if (value == null || value.isBlank()) {
|
if (value == null || value.isBlank()) {
|
||||||
return "native decompiler returned no detail";
|
return "native decompiler returned no detail";
|
||||||
}
|
}
|
||||||
return truncate(value.replaceAll("[\\r\\n]+", " "), 512).value;
|
return value.replaceAll("[\\r\\n]+", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonArray inventory(
|
private JsonArray inventory(
|
||||||
@@ -1691,15 +1691,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
destination.add(item);
|
destination.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TruncatedValue truncate(String value, int maximumCodePoints) {
|
|
||||||
int codePoints = value.codePointCount(0, value.length());
|
|
||||||
if (codePoints <= maximumCodePoints) {
|
|
||||||
return new TruncatedValue(value, false);
|
|
||||||
}
|
|
||||||
int end = value.offsetByCodePoints(0, maximumCodePoints);
|
|
||||||
return new TruncatedValue(value.substring(0, end), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ValueMatcher literalMatcher(String pattern, boolean caseSensitive) {
|
private static ValueMatcher literalMatcher(String pattern, boolean caseSensitive) {
|
||||||
String needle = caseSensitive ? pattern : pattern.toLowerCase(Locale.ROOT);
|
String needle = caseSensitive ? pattern : pattern.toLowerCase(Locale.ROOT);
|
||||||
return value -> {
|
return value -> {
|
||||||
@@ -1914,7 +1905,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
private record InventoryItem(Address address, String value, JsonObject facts) {}
|
private record InventoryItem(Address address, String value, JsonObject facts) {}
|
||||||
private record FunctionEntry(Function function, InventoryItem item) {}
|
private record FunctionEntry(Function function, InventoryItem item) {}
|
||||||
private record InstructionScan(List<Instruction> instructions, boolean truncated) {}
|
private record InstructionScan(List<Instruction> instructions, boolean truncated) {}
|
||||||
private record TruncatedValue(String value, boolean truncated) {}
|
|
||||||
private record SessionDescriptor(
|
private record SessionDescriptor(
|
||||||
String transport,
|
String transport,
|
||||||
String endpointPath,
|
String endpointPath,
|
||||||
|
|||||||
@@ -873,13 +873,13 @@ def _safe_diagnostic(error):
|
|||||||
"""Project one exception without retaining provider or credential text."""
|
"""Project one exception without retaining provider or credential text."""
|
||||||
diagnostic_type = _diagnostic_type(error)
|
diagnostic_type = _diagnostic_type(error)
|
||||||
if diagnostic_type == "capability_unavailable":
|
if diagnostic_type == "capability_unavailable":
|
||||||
message = str(error)[:512]
|
message = str(error)
|
||||||
elif diagnostic_type == "authorization":
|
elif diagnostic_type == "authorization":
|
||||||
message = "Invalid bridge capability"
|
message = "Invalid bridge capability"
|
||||||
elif diagnostic_type == "invalid_request":
|
elif diagnostic_type == "invalid_request":
|
||||||
message = "Invalid Hopper bridge request"
|
message = "Invalid Hopper bridge request"
|
||||||
else:
|
else:
|
||||||
message = "%s: Hopper bridge operation failed" % type(error).__name__[:128]
|
message = "%s: Hopper bridge operation failed" % type(error).__name__
|
||||||
return {"code": -32000, "message": message, "type": diagnostic_type}
|
return {"code": -32000, "message": message, "type": diagnostic_type}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+13
-31
@@ -36,11 +36,8 @@ UNEXPECTED_DISPLAY_GEOMETRY = 77
|
|||||||
X11_INPUT_FAILED = 78
|
X11_INPUT_FAILED = 78
|
||||||
RUNTIME_DEPENDENCY_UNAVAILABLE = 79
|
RUNTIME_DEPENDENCY_UNAVAILABLE = 79
|
||||||
X11_SOCKET_DIRECTORY_UNUSABLE = 80
|
X11_SOCKET_DIRECTORY_UNUSABLE = 80
|
||||||
DIAGNOSTIC_PREFIX = "REA_X11_DIAGNOSTIC_V1="
|
DIAGNOSTIC_PREFIX = "REA_X11_DIAGNOSTIC="
|
||||||
X11_SOCKET_DIRECTORY = Path("/tmp/.X11-unix")
|
X11_SOCKET_DIRECTORY = Path("/tmp/.X11-unix")
|
||||||
XVFB_STDERR_LIMIT = 16 * 1024
|
|
||||||
|
|
||||||
|
|
||||||
class AdapterFailure(Exception):
|
class AdapterFailure(Exception):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -48,20 +45,18 @@ class AdapterFailure(Exception):
|
|||||||
reason: str,
|
reason: str,
|
||||||
message: str,
|
message: str,
|
||||||
stderr_bytes: int = 0,
|
stderr_bytes: int = 0,
|
||||||
stderr_truncated: bool = False,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
self.code = code
|
self.code = code
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.stderr_bytes = stderr_bytes
|
self.stderr_bytes = stderr_bytes
|
||||||
self.stderr_truncated = stderr_truncated
|
|
||||||
|
|
||||||
def with_stderr(self, capture: BoundedStderr) -> AdapterFailure:
|
def with_stderr(self, capture: CapturedStderr) -> AdapterFailure:
|
||||||
self.stderr_bytes, self.stderr_truncated, _ = capture.snapshot()
|
self.stderr_bytes, _ = capture.snapshot()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
class BoundedStderr:
|
class CapturedStderr:
|
||||||
def __init__(self, stream: object) -> None:
|
def __init__(self, stream: object) -> None:
|
||||||
self._stream = stream
|
self._stream = stream
|
||||||
self._retained = bytearray()
|
self._retained = bytearray()
|
||||||
@@ -77,15 +72,13 @@ class BoundedStderr:
|
|||||||
return
|
return
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self._bytes += len(chunk)
|
self._bytes += len(chunk)
|
||||||
remaining = XVFB_STDERR_LIMIT - len(self._retained)
|
self._retained.extend(chunk)
|
||||||
if remaining > 0:
|
|
||||||
self._retained.extend(chunk[:remaining])
|
|
||||||
|
|
||||||
def snapshot(self) -> tuple[int, bool, str]:
|
def snapshot(self) -> tuple[int, str]:
|
||||||
with self._lock:
|
with self._lock:
|
||||||
retained = bytes(self._retained)
|
retained = bytes(self._retained)
|
||||||
total = self._bytes
|
total = self._bytes
|
||||||
return total, total > len(retained), retained.decode("utf-8", "replace")
|
return total, retained.decode("utf-8", "replace")
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
self._thread.join(timeout=0.5)
|
self._thread.join(timeout=0.5)
|
||||||
@@ -284,12 +277,10 @@ def diagnostic(
|
|||||||
operation: str,
|
operation: str,
|
||||||
status: str,
|
status: str,
|
||||||
failure: AdapterFailure | None = None,
|
failure: AdapterFailure | None = None,
|
||||||
capture: BoundedStderr | None = None,
|
capture: CapturedStderr | None = None,
|
||||||
) -> dict[str, object]:
|
) -> dict[str, object]:
|
||||||
mode, read_only, _ = socket_directory_state()
|
mode, read_only, _ = socket_directory_state()
|
||||||
captured_bytes, captured_truncated, _ = (
|
captured_bytes, _ = (0, "") if capture is None else capture.snapshot()
|
||||||
(0, False, "") if capture is None else capture.snapshot()
|
|
||||||
)
|
|
||||||
return {
|
return {
|
||||||
"component": "hopper_private_display",
|
"component": "hopper_private_display",
|
||||||
"operation": operation,
|
"operation": operation,
|
||||||
@@ -307,9 +298,6 @@ def diagnostic(
|
|||||||
"xvfb_stderr_bytes": captured_bytes
|
"xvfb_stderr_bytes": captured_bytes
|
||||||
if failure is None
|
if failure is None
|
||||||
else failure.stderr_bytes,
|
else failure.stderr_bytes,
|
||||||
"xvfb_stderr_truncated": captured_truncated
|
|
||||||
if failure is None
|
|
||||||
else failure.stderr_truncated,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -440,8 +428,8 @@ def authorize_display(
|
|||||||
) from error
|
) from error
|
||||||
|
|
||||||
|
|
||||||
def classify_xvfb_failure(capture: BoundedStderr) -> AdapterFailure:
|
def classify_xvfb_failure(capture: CapturedStderr) -> AdapterFailure:
|
||||||
stderr_bytes, stderr_truncated, text = capture.snapshot()
|
stderr_bytes, text = capture.snapshot()
|
||||||
mode, read_only, directory = socket_directory_state()
|
mode, read_only, directory = socket_directory_state()
|
||||||
if read_only is True:
|
if read_only is True:
|
||||||
return AdapterFailure(
|
return AdapterFailure(
|
||||||
@@ -449,7 +437,6 @@ def classify_xvfb_failure(capture: BoundedStderr) -> AdapterFailure:
|
|||||||
"socket_directory_read_only",
|
"socket_directory_read_only",
|
||||||
"X11 socket directory is read-only",
|
"X11 socket directory is read-only",
|
||||||
stderr_bytes,
|
stderr_bytes,
|
||||||
stderr_truncated,
|
|
||||||
)
|
)
|
||||||
if directory and mode != "1777":
|
if directory and mode != "1777":
|
||||||
return AdapterFailure(
|
return AdapterFailure(
|
||||||
@@ -457,7 +444,6 @@ def classify_xvfb_failure(capture: BoundedStderr) -> AdapterFailure:
|
|||||||
"socket_directory_mode",
|
"socket_directory_mode",
|
||||||
"X11 socket directory mode is not 1777",
|
"X11 socket directory mode is not 1777",
|
||||||
stderr_bytes,
|
stderr_bytes,
|
||||||
stderr_truncated,
|
|
||||||
)
|
)
|
||||||
if mode is not None and not directory:
|
if mode is not None and not directory:
|
||||||
return AdapterFailure(
|
return AdapterFailure(
|
||||||
@@ -465,7 +451,6 @@ def classify_xvfb_failure(capture: BoundedStderr) -> AdapterFailure:
|
|||||||
"socket_directory_type",
|
"socket_directory_type",
|
||||||
"X11 socket path is not a directory",
|
"X11 socket path is not a directory",
|
||||||
stderr_bytes,
|
stderr_bytes,
|
||||||
stderr_truncated,
|
|
||||||
)
|
)
|
||||||
lowered = text.lower()
|
lowered = text.lower()
|
||||||
if "error while loading shared libraries" in lowered:
|
if "error while loading shared libraries" in lowered:
|
||||||
@@ -474,7 +459,6 @@ def classify_xvfb_failure(capture: BoundedStderr) -> AdapterFailure:
|
|||||||
"missing_library",
|
"missing_library",
|
||||||
"Xvfb shared library unavailable",
|
"Xvfb shared library unavailable",
|
||||||
stderr_bytes,
|
stderr_bytes,
|
||||||
stderr_truncated,
|
|
||||||
)
|
)
|
||||||
if any(
|
if any(
|
||||||
marker in lowered
|
marker in lowered
|
||||||
@@ -489,21 +473,19 @@ def classify_xvfb_failure(capture: BoundedStderr) -> AdapterFailure:
|
|||||||
"address_collision",
|
"address_collision",
|
||||||
"private display address collision",
|
"private display address collision",
|
||||||
stderr_bytes,
|
stderr_bytes,
|
||||||
stderr_truncated,
|
|
||||||
)
|
)
|
||||||
return AdapterFailure(
|
return AdapterFailure(
|
||||||
PRIVATE_DISPLAY_UNAVAILABLE,
|
PRIVATE_DISPLAY_UNAVAILABLE,
|
||||||
"xvfb_startup_failed",
|
"xvfb_startup_failed",
|
||||||
"private X display unavailable",
|
"private X display unavailable",
|
||||||
stderr_bytes,
|
stderr_bytes,
|
||||||
stderr_truncated,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def start_xvfb(
|
def start_xvfb(
|
||||||
session: Path,
|
session: Path,
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
) -> tuple[subprocess.Popen[bytes], str, Path, BoundedStderr]:
|
) -> tuple[subprocess.Popen[bytes], str, Path, CapturedStderr]:
|
||||||
authority = session / "Xauthority"
|
authority = session / "Xauthority"
|
||||||
collision: AdapterFailure | None = None
|
collision: AdapterFailure | None = None
|
||||||
for _ in range(3):
|
for _ in range(3):
|
||||||
@@ -550,7 +532,7 @@ def start_xvfb(
|
|||||||
"xvfb_startup_failed",
|
"xvfb_startup_failed",
|
||||||
"Xvfb stderr unavailable",
|
"Xvfb stderr unavailable",
|
||||||
)
|
)
|
||||||
capture = BoundedStderr(process.stderr)
|
capture = CapturedStderr(process.stderr)
|
||||||
deadline = time.monotonic() + 2
|
deadline = time.monotonic() + 2
|
||||||
socket = Path(f"/tmp/.X11-unix/X{display_number}")
|
socket = Path(f"/tmp/.X11-unix/X{display_number}")
|
||||||
while time.monotonic() < deadline and process.poll() is None:
|
while time.monotonic() < deadline and process.poll() is None:
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ function parseManagedAppManifestMethod(rawMethod, index) {
|
|||||||
method.signature_sha256,
|
method.signature_sha256,
|
||||||
`${prefix}.signature_sha256`,
|
`${prefix}.signature_sha256`,
|
||||||
),
|
),
|
||||||
il_size: ilSize(method, prefix),
|
il_size: nonNegativeInteger(method.il_size, `${prefix}.il_size`),
|
||||||
il_sha256:
|
il_sha256:
|
||||||
method.il_sha256 === undefined
|
method.il_sha256 === undefined
|
||||||
? undefined
|
? undefined
|
||||||
@@ -112,26 +112,6 @@ function parseManagedAppManifestMethod(rawMethod, index) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function ilSize(method, prefix) {
|
|
||||||
const hasIlSize = method.il_size !== undefined;
|
|
||||||
const hasIlLength = method.il_length !== undefined;
|
|
||||||
ensure(
|
|
||||||
hasIlSize || hasIlLength,
|
|
||||||
`${prefix}.il_size is required; il_length is accepted as a legacy alias`,
|
|
||||||
);
|
|
||||||
if (hasIlSize && hasIlLength)
|
|
||||||
ensure(
|
|
||||||
method.il_size === method.il_length,
|
|
||||||
`${prefix}.il_size and ${prefix}.il_length disagree`,
|
|
||||||
);
|
|
||||||
const value = hasIlSize ? method.il_size : method.il_length;
|
|
||||||
ensure(
|
|
||||||
Number.isInteger(value) && value >= 0,
|
|
||||||
`${prefix}.il_size must be a non-negative integer`,
|
|
||||||
);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function object(value, name) {
|
function object(value, name) {
|
||||||
ensure(
|
ensure(
|
||||||
value !== null && typeof value === "object" && !Array.isArray(value),
|
value !== null && typeof value === "object" && !Array.isArray(value),
|
||||||
@@ -158,6 +138,14 @@ function optionalString(value, name) {
|
|||||||
return string(value, name);
|
return string(value, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nonNegativeInteger(value, name) {
|
||||||
|
ensure(
|
||||||
|
Number.isInteger(value) && value >= 0,
|
||||||
|
`${name} must be a non-negative integer`,
|
||||||
|
);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
function digest(value, name) {
|
function digest(value, name) {
|
||||||
const text = string(value, name);
|
const text = string(value, name);
|
||||||
ensure(/^[a-f0-9]{64}$/u.test(text), `${name} must be a lowercase sha256`);
|
ensure(/^[a-f0-9]{64}$/u.test(text), `${name} must be a lowercase sha256`);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { promisify } from "node:util";
|
|||||||
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
||||||
import { resolveGhidraAnalysisProfile } from "../dist/ghidra/GhidraAnalysisProfile.js";
|
import { resolveGhidraAnalysisProfile } from "../dist/ghidra/GhidraAnalysisProfile.js";
|
||||||
import { GhidraClient } from "../dist/ghidra/GhidraClient.js";
|
import { GhidraClient } from "../dist/ghidra/GhidraClient.js";
|
||||||
import { GHIDRA_DECOMPILE_REQUEST_TIMEOUT_MS } from "../dist/ghidra/GhidraDefaults.js";
|
|
||||||
import {
|
import {
|
||||||
inspectGhidraInstallation,
|
inspectGhidraInstallation,
|
||||||
SUPPORTED_GHIDRA_VERSION,
|
SUPPORTED_GHIDRA_VERSION,
|
||||||
@@ -252,7 +251,6 @@ async function verifyTarget(targetPath, variant, expectedTarget = null) {
|
|||||||
targetSha256: parsedTarget.value.sha256,
|
targetSha256: parsedTarget.value.sha256,
|
||||||
providerVersion: SUPPORTED_GHIDRA_VERSION,
|
providerVersion: SUPPORTED_GHIDRA_VERSION,
|
||||||
profileDigest: profile.value.profile.digest,
|
profileDigest: profile.value.profile.digest,
|
||||||
requestTimeoutMs: GHIDRA_DECOMPILE_REQUEST_TIMEOUT_MS,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let runtimeCoordinates;
|
let runtimeCoordinates;
|
||||||
|
|||||||
@@ -114,9 +114,8 @@ const runtimeChecks = (
|
|||||||
broken.length === 0
|
broken.length === 0
|
||||||
? `${String(inventory.candidates.length)} runtime executable candidates passed bounded version probes.`
|
? `${String(inventory.candidates.length)} runtime executable candidates passed bounded version probes.`
|
||||||
: `${String(broken.length)} of ${String(inventory.candidates.length)} runtime executable candidates failed bounded version probes: ${broken
|
: `${String(broken.length)} of ${String(inventory.candidates.length)} runtime executable candidates failed bounded version probes: ${broken
|
||||||
.slice(0, 5)
|
|
||||||
.map(({ lexical_path: path }) => path)
|
.map(({ lexical_path: path }) => path)
|
||||||
.join(", ")}${broken.length > 5 ? ", …" : ""}`;
|
.join(", ")}`;
|
||||||
return [
|
return [
|
||||||
check("node-toolchains", broken.length === 0, detail, {
|
check("node-toolchains", broken.length === 0, detail, {
|
||||||
remediation:
|
remediation:
|
||||||
|
|||||||
@@ -72,7 +72,5 @@ const redactArgument = (argument: string): string => {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return `${argument.slice(0, argument.indexOf("=") + 1)}<redacted>`;
|
return `${argument.slice(0, argument.indexOf("=") + 1)}<redacted>`;
|
||||||
return argument.length > 256
|
return argument;
|
||||||
? `${argument.slice(0, 256)}<redacted>`
|
|
||||||
: argument;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ const generatedCandidate = ({
|
|||||||
}: GeneratedCandidateInput): ReconstructionObligationCandidate => ({
|
}: GeneratedCandidateInput): ReconstructionObligationCandidate => ({
|
||||||
obligation_id: obligationId(key),
|
obligation_id: obligationId(key),
|
||||||
obligation_version: 1,
|
obligation_version: 1,
|
||||||
title: title.slice(0, 500),
|
title,
|
||||||
origin: "generated",
|
origin: "generated",
|
||||||
application_layer: candidatePolicy.applicationLayer,
|
application_layer: candidatePolicy.applicationLayer,
|
||||||
family: candidatePolicy.family,
|
family: candidatePolicy.family,
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { execFile } from "node:child_process";
|
import { spawn, type ChildProcess } from "node:child_process";
|
||||||
import { constants } from "node:fs";
|
import { constants } from "node:fs";
|
||||||
import { access, realpath } from "node:fs/promises";
|
import { access, realpath } from "node:fs/promises";
|
||||||
import { delimiter, join } from "node:path";
|
import { delimiter, join } from "node:path";
|
||||||
|
|
||||||
const TOOL_NAMES = ["node", "npm", "npx"] as const;
|
const TOOL_NAMES = ["node", "npm", "npx"] as const;
|
||||||
const MAX_OUTPUT_BYTES = 65_536;
|
|
||||||
const MAX_DIAGNOSTIC_BYTES = 4_096;
|
|
||||||
const PROBE_CONCURRENCY = 4;
|
const PROBE_CONCURRENCY = 4;
|
||||||
|
|
||||||
type RuntimeToolName = (typeof TOOL_NAMES)[number];
|
type RuntimeToolName = (typeof TOOL_NAMES)[number];
|
||||||
@@ -17,7 +15,7 @@ type RuntimeProbeFailureCode =
|
|||||||
| "runtime_spawn_failed"
|
| "runtime_spawn_failed"
|
||||||
| "runtime_nonzero_exit";
|
| "runtime_nonzero_exit";
|
||||||
|
|
||||||
/** Stable, bounded classification of one failed executable probe. */
|
/** Classification of one failed executable probe with its complete stderr. */
|
||||||
interface RuntimeProbeFailure {
|
interface RuntimeProbeFailure {
|
||||||
readonly code: RuntimeProbeFailureCode;
|
readonly code: RuntimeProbeFailureCode;
|
||||||
readonly exit_code: number | null;
|
readonly exit_code: number | null;
|
||||||
@@ -64,7 +62,7 @@ export interface RuntimeExecutableInventoryOptions {
|
|||||||
readonly timeoutMs?: number;
|
readonly timeoutMs?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inventory and bounded-probe Node toolchain candidates under one exact PATH. */
|
/** Inventory and probe Node toolchain candidates under one exact PATH. */
|
||||||
export const inspectRuntimeExecutables = async (
|
export const inspectRuntimeExecutables = async (
|
||||||
options: RuntimeExecutableInventoryOptions,
|
options: RuntimeExecutableInventoryOptions,
|
||||||
): Promise<RuntimeExecutableInventory> => {
|
): Promise<RuntimeExecutableInventory> => {
|
||||||
@@ -108,8 +106,7 @@ export const inspectRuntimeExecutables = async (
|
|||||||
const diagnostics = await mapConcurrentBounded(
|
const diagnostics = await mapConcurrentBounded(
|
||||||
uniqueCandidates,
|
uniqueCandidates,
|
||||||
PROBE_CONCURRENCY,
|
PROBE_CONCURRENCY,
|
||||||
(candidate) =>
|
(candidate) => probeCandidate(candidate, options.timeoutMs, options.path),
|
||||||
probeCandidate(candidate, options.timeoutMs ?? 5_000, options.path),
|
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
launcher_node: await canonicalPath(options.launcherNode),
|
launcher_node: await canonicalPath(options.launcherNode),
|
||||||
@@ -152,7 +149,7 @@ const probeCandidate = async (
|
|||||||
readonly pathIndex: number | null;
|
readonly pathIndex: number | null;
|
||||||
readonly selection: RuntimeExecutableDiagnostic["selection"];
|
readonly selection: RuntimeExecutableDiagnostic["selection"];
|
||||||
},
|
},
|
||||||
timeoutMs: number,
|
timeoutMs: number | undefined,
|
||||||
effectivePath: string,
|
effectivePath: string,
|
||||||
): Promise<RuntimeExecutableDiagnostic> => {
|
): Promise<RuntimeExecutableDiagnostic> => {
|
||||||
const canonical = await canonicalPath(candidate.path);
|
const canonical = await canonicalPath(candidate.path);
|
||||||
@@ -180,43 +177,67 @@ type VersionResult =
|
|||||||
|
|
||||||
const executeVersion = (
|
const executeVersion = (
|
||||||
path: string,
|
path: string,
|
||||||
timeoutMs: number,
|
timeoutMs: number | undefined,
|
||||||
effectivePath: string,
|
effectivePath: string,
|
||||||
): Promise<VersionResult> =>
|
): Promise<VersionResult> =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
const child = execFile(
|
const child = spawn(path, ["--version"], {
|
||||||
path,
|
windowsHide: true,
|
||||||
["--version"],
|
env: environmentWithPath(effectivePath),
|
||||||
{
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
encoding: "utf8",
|
});
|
||||||
timeout: timeoutMs,
|
let stdout = "";
|
||||||
maxBuffer: MAX_OUTPUT_BYTES,
|
let stderr = "";
|
||||||
windowsHide: true,
|
let spawnError: Error | undefined;
|
||||||
env: environmentWithPath(effectivePath),
|
let timeout: NodeJS.Timeout | undefined;
|
||||||
},
|
let timedOut = false;
|
||||||
(cause: Error | null, stdout: string, stderr: string) => {
|
child.stdout?.setEncoding("utf8");
|
||||||
if (cause === null) {
|
child.stderr?.setEncoding("utf8");
|
||||||
const version =
|
child.stdout?.on("data", (chunk: string) => {
|
||||||
firstNonemptyLine(stdout) ?? firstNonemptyLine(stderr);
|
stdout += chunk;
|
||||||
if (version !== undefined) resolve({ ok: true, version });
|
});
|
||||||
else
|
child.stderr?.on("data", (chunk: string) => {
|
||||||
resolve({
|
stderr += chunk;
|
||||||
ok: false,
|
});
|
||||||
failure: failure("runtime_invalid_version_output", child, stderr),
|
child.once("error", (cause: Error) => {
|
||||||
});
|
spawnError = cause;
|
||||||
|
});
|
||||||
|
if (timeoutMs !== undefined && timeoutMs > 0) {
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
timedOut = true;
|
||||||
|
child.kill();
|
||||||
|
}, timeoutMs);
|
||||||
|
timeout.unref();
|
||||||
|
}
|
||||||
|
child.once("close", () => {
|
||||||
|
if (timeout !== undefined) clearTimeout(timeout);
|
||||||
|
if (spawnError === undefined && child.exitCode === 0) {
|
||||||
|
const version = firstNonemptyLine(stdout) ?? firstNonemptyLine(stderr);
|
||||||
|
if (version !== undefined) {
|
||||||
|
resolve({ ok: true, version });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resolve({
|
resolve({
|
||||||
ok: false,
|
ok: false,
|
||||||
failure: classifyProbeFailure(cause, child, stderr),
|
failure: failure("runtime_invalid_version_output", child, stderr),
|
||||||
});
|
});
|
||||||
},
|
return;
|
||||||
);
|
}
|
||||||
|
const cause =
|
||||||
|
spawnError ??
|
||||||
|
new Error("Runtime version probe did not exit successfully");
|
||||||
|
resolve({
|
||||||
|
ok: false,
|
||||||
|
failure: timedOut
|
||||||
|
? failure("runtime_timeout", child, stderr)
|
||||||
|
: classifyProbeFailure(cause, child, stderr),
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const classifyProbeFailure = (
|
const classifyProbeFailure = (
|
||||||
cause: Error,
|
cause: Error,
|
||||||
child: ReturnType<typeof execFile>,
|
child: ChildProcess,
|
||||||
stderr: string,
|
stderr: string,
|
||||||
): RuntimeProbeFailure => {
|
): RuntimeProbeFailure => {
|
||||||
const dependency = missingDynamicLibrary(stderr);
|
const dependency = missingDynamicLibrary(stderr);
|
||||||
@@ -238,7 +259,7 @@ const classifyProbeFailure = (
|
|||||||
|
|
||||||
const failure = (
|
const failure = (
|
||||||
code: RuntimeProbeFailureCode,
|
code: RuntimeProbeFailureCode,
|
||||||
child: ReturnType<typeof execFile>,
|
child: ChildProcess,
|
||||||
stderr: string,
|
stderr: string,
|
||||||
dependency: string | null = null,
|
dependency: string | null = null,
|
||||||
): RuntimeProbeFailure => ({
|
): RuntimeProbeFailure => ({
|
||||||
@@ -246,7 +267,7 @@ const failure = (
|
|||||||
exit_code: child.exitCode,
|
exit_code: child.exitCode,
|
||||||
signal: child.signalCode,
|
signal: child.signalCode,
|
||||||
dependency,
|
dependency,
|
||||||
stderr: bounded(stderr.trim()),
|
stderr: stderr.trim(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const missingDynamicLibrary = (stderr: string): string | null =>
|
const missingDynamicLibrary = (stderr: string): string | null =>
|
||||||
@@ -280,11 +301,6 @@ const firstNonemptyLine = (value: string): string | undefined =>
|
|||||||
.find((line) => line.trim().length > 0)
|
.find((line) => line.trim().length > 0)
|
||||||
?.trim();
|
?.trim();
|
||||||
|
|
||||||
const bounded = (value: string): string =>
|
|
||||||
value.length <= MAX_DIAGNOSTIC_BYTES
|
|
||||||
? value
|
|
||||||
: value.slice(-MAX_DIAGNOSTIC_BYTES);
|
|
||||||
|
|
||||||
const unique = (values: readonly string[]): string[] => [...new Set(values)];
|
const unique = (values: readonly string[]): string[] => [...new Set(values)];
|
||||||
|
|
||||||
const environmentWithPath = (path: string): NodeJS.ProcessEnv => {
|
const environmentWithPath = (path: string): NodeJS.ProcessEnv => {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
import { DirectoryArtifactReader } from "./DirectoryArtifactReader.js";
|
import { DirectoryArtifactReader } from "./DirectoryArtifactReader.js";
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
|
const DETACH_TIMEOUT_MS = 120_000;
|
||||||
const attachOutputSchema = z.object({
|
const attachOutputSchema = z.object({
|
||||||
"system-entities": z.array(
|
"system-entities": z.array(
|
||||||
z.object({
|
z.object({
|
||||||
@@ -31,18 +32,20 @@ export interface NativeDmgHost {
|
|||||||
run(
|
run(
|
||||||
arguments_: readonly string[],
|
arguments_: readonly string[],
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
|
options?: { readonly timeoutMs: number },
|
||||||
): Promise<{ readonly stdout: string; readonly exitCode: number }>;
|
): Promise<{ readonly stdout: string; readonly exitCode: number }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemHost: NativeDmgHost = {
|
const systemHost: NativeDmgHost = {
|
||||||
async run(arguments_, signal) {
|
async run(arguments_, signal, options) {
|
||||||
try {
|
try {
|
||||||
const { stdout } = await execFileAsync(
|
const { stdout } = await execFileAsync(
|
||||||
"/usr/bin/hdiutil",
|
"/usr/bin/hdiutil",
|
||||||
[...arguments_],
|
[...arguments_],
|
||||||
{
|
{
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
timeout: 120_000,
|
maxBuffer: Number.POSITIVE_INFINITY,
|
||||||
|
...(options === undefined ? {} : { timeout: options.timeoutMs }),
|
||||||
...(signal === undefined ? {} : { signal }),
|
...(signal === undefined ? {} : { signal }),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -76,7 +79,7 @@ export class NativeDmgArtifactReader implements ArtifactReader {
|
|||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
host: NativeDmgHost = systemHost,
|
host: NativeDmgHost = systemHost,
|
||||||
): Promise<NativeDmgArtifactReader> {
|
): Promise<NativeDmgArtifactReader> {
|
||||||
if (process.platform !== "darwin")
|
if (process.platform !== "darwin" && host === systemHost)
|
||||||
throw new ArtifactReaderFailure(
|
throw new ArtifactReaderFailure(
|
||||||
"unavailable",
|
"unavailable",
|
||||||
"Native DMG traversal is available only on macOS",
|
"Native DMG traversal is available only on macOS",
|
||||||
@@ -110,7 +113,9 @@ export class NativeDmgArtifactReader implements ArtifactReader {
|
|||||||
let detachFailure: unknown;
|
let detachFailure: unknown;
|
||||||
for (const device of [...this.#devices].reverse()) {
|
for (const device of [...this.#devices].reverse()) {
|
||||||
try {
|
try {
|
||||||
await runChecked(this.host, ["detach", device]);
|
await runChecked(this.host, ["detach", device], undefined, {
|
||||||
|
timeoutMs: DETACH_TIMEOUT_MS,
|
||||||
|
});
|
||||||
this.#provenance.push(command(["detach", device], ["mount"]));
|
this.#provenance.push(command(["detach", device], ["mount"]));
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
detachFailure ??= cause;
|
detachFailure ??= cause;
|
||||||
@@ -204,8 +209,9 @@ const runChecked = async (
|
|||||||
host: NativeDmgHost,
|
host: NativeDmgHost,
|
||||||
arguments_: readonly string[],
|
arguments_: readonly string[],
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
|
options?: { readonly timeoutMs: number },
|
||||||
): Promise<{ readonly stdout: string; readonly exitCode: 0 }> => {
|
): Promise<{ readonly stdout: string; readonly exitCode: 0 }> => {
|
||||||
const result = await host.run(arguments_, signal);
|
const result = await host.run(arguments_, signal, options);
|
||||||
if (result.exitCode !== 0)
|
if (result.exitCode !== 0)
|
||||||
throw new ArtifactReaderFailure(
|
throw new ArtifactReaderFailure(
|
||||||
"unavailable",
|
"unavailable",
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export class BrowserStartupError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Owned child process and bounded startup policy for Chrome CDP discovery. */
|
/** Owned child process and startup policy for Chrome CDP discovery. */
|
||||||
export interface BrowserStartupOptions {
|
export interface BrowserStartupOptions {
|
||||||
readonly child: ChildProcess;
|
readonly child: ChildProcess;
|
||||||
readonly executable: string;
|
readonly executable: string;
|
||||||
@@ -129,7 +129,7 @@ const startupError = (
|
|||||||
elapsedMs: Math.max(0, Math.round(performance.now() - startedAt)),
|
elapsedMs: Math.max(0, Math.round(performance.now() - startedAt)),
|
||||||
exitCode: options.child.exitCode,
|
exitCode: options.child.exitCode,
|
||||||
signalCode: options.child.signalCode,
|
signalCode: options.child.signalCode,
|
||||||
stderr: boundedStderr(options.stderr()),
|
stderr: options.stderr(),
|
||||||
},
|
},
|
||||||
state.failure === "spawn-error" ? { cause: state.cause } : undefined,
|
state.failure === "spawn-error" ? { cause: state.cause } : undefined,
|
||||||
);
|
);
|
||||||
@@ -146,9 +146,6 @@ const readDevtoolsPort = async (path: string): Promise<number | null> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const boundedStderr = (stderr: string): string =>
|
|
||||||
stderr.length <= 65_536 ? stderr : stderr.slice(-65_536);
|
|
||||||
|
|
||||||
const delay = (milliseconds: number): Promise<void> =>
|
const delay = (milliseconds: number): Promise<void> =>
|
||||||
new Promise((resolve) => setTimeout(resolve, milliseconds));
|
new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export const inspectCdpElectronPage = async (
|
|||||||
limitations: [
|
limitations: [
|
||||||
"Local file paths exposed by the selected CDP target are retained in the observation.",
|
"Local file paths exposed by the selected CDP target are retained in the observation.",
|
||||||
"REA does not evaluate renderer JavaScript, invoke Electron APIs, navigate, click, or close the page.",
|
"REA does not evaluate renderer JavaScript, invoke Electron APIs, navigate, click, or close the page.",
|
||||||
"Script contents require separate source-capture approval and remain byte bounded.",
|
"Script contents require separate source-capture approval.",
|
||||||
],
|
],
|
||||||
mainFrameId: undefined,
|
mainFrameId: undefined,
|
||||||
navigationDuringCapture: false,
|
navigationDuringCapture: false,
|
||||||
@@ -162,7 +162,7 @@ const enableElectronCapture = async (
|
|||||||
);
|
);
|
||||||
await context.connection.send(
|
await context.connection.send(
|
||||||
"Debugger.enable",
|
"Debugger.enable",
|
||||||
{ maxScriptsCacheSize: 4 * 1_024 * 1_024 },
|
{},
|
||||||
context.sessionId,
|
context.sessionId,
|
||||||
context.signal,
|
context.signal,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ const registerWebMcp = (
|
|||||||
.number()
|
.number()
|
||||||
.int()
|
.int()
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(10_000)
|
|
||||||
.default(100)
|
.default(100)
|
||||||
.describe("Observation duration in milliseconds"),
|
.describe("Observation duration in milliseconds"),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ const observeOptionsSchema = z.object({
|
|||||||
.number()
|
.number()
|
||||||
.int()
|
.int()
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(10_000)
|
|
||||||
.default(100)
|
.default(100)
|
||||||
.describe("Bounded observation window in milliseconds"),
|
.describe("Observation window in milliseconds"),
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Register CLI equivalents of passive V8 Inspector tools. */
|
/** Register CLI equivalents of passive V8 Inspector tools. */
|
||||||
|
|||||||
+4
-23
@@ -1,12 +1,9 @@
|
|||||||
import { open, stat } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
|
|
||||||
import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
|
import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
|
||||||
import type { JsonValue } from "./domain/jsonValue.js";
|
import type { JsonValue } from "./domain/jsonValue.js";
|
||||||
import { readBoundedFileBytes } from "./process/BoundedFileBytes.js";
|
|
||||||
|
|
||||||
const MAX_JSON_INPUT_BYTES = 64 * 1_024 * 1_024;
|
/** Parse inline JSON or one local JSON file for a CLI workflow. */
|
||||||
|
|
||||||
/** Parse bounded inline JSON or one bounded local JSON file for a CLI workflow. */
|
|
||||||
export const parseCliJsonInput = async (
|
export const parseCliJsonInput = async (
|
||||||
value: string,
|
value: string,
|
||||||
operation: string,
|
operation: string,
|
||||||
@@ -14,27 +11,12 @@ export const parseCliJsonInput = async (
|
|||||||
| { readonly ok: true; readonly value: unknown }
|
| { readonly ok: true; readonly value: unknown }
|
||||||
| { readonly ok: false; readonly error: JsonValue }
|
| { readonly ok: false; readonly error: JsonValue }
|
||||||
> => {
|
> => {
|
||||||
if (Buffer.byteLength(value, "utf8") > MAX_JSON_INPUT_BYTES)
|
|
||||||
return jsonFileError(undefined, operation, "too-large");
|
|
||||||
const inline = parseJson(value);
|
const inline = parseJson(value);
|
||||||
if (inline !== undefined) return { ok: true, value: inline };
|
if (inline !== undefined) return { ok: true, value: inline };
|
||||||
if (["{", "["].includes(value.trimStart()[0] ?? ""))
|
if (["{", "["].includes(value.trimStart()[0] ?? ""))
|
||||||
return { ok: false, error: inputError(operation) };
|
return { ok: false, error: inputError(operation) };
|
||||||
try {
|
try {
|
||||||
const metadata = await stat(value);
|
const parsed = parseJson(await readFile(value, "utf8"));
|
||||||
if (!metadata.isFile()) return jsonFileError(value, operation, "not-file");
|
|
||||||
if (metadata.size > MAX_JSON_INPUT_BYTES)
|
|
||||||
return jsonFileError(value, operation, "too-large");
|
|
||||||
const handle = await open(value, "r");
|
|
||||||
let bytes: Buffer | undefined;
|
|
||||||
try {
|
|
||||||
bytes = await readBoundedFileBytes(handle, MAX_JSON_INPUT_BYTES);
|
|
||||||
} finally {
|
|
||||||
await handle.close();
|
|
||||||
}
|
|
||||||
if (bytes === undefined)
|
|
||||||
return jsonFileError(value, operation, "too-large");
|
|
||||||
const parsed = parseJson(bytes.toString("utf8"));
|
|
||||||
return parsed === undefined
|
return parsed === undefined
|
||||||
? jsonFileError(value, operation, "invalid-json")
|
? jsonFileError(value, operation, "invalid-json")
|
||||||
: { ok: true, value: parsed };
|
: { ok: true, value: parsed };
|
||||||
@@ -63,7 +45,7 @@ const inputError = (operation: string): JsonValue => ({
|
|||||||
const jsonFileError = (
|
const jsonFileError = (
|
||||||
path: string | undefined,
|
path: string | undefined,
|
||||||
operation: string,
|
operation: string,
|
||||||
reason: "not-file" | "too-large" | "invalid-json" | "read-failed",
|
reason: "invalid-json" | "read-failed",
|
||||||
) => ({
|
) => ({
|
||||||
ok: false as const,
|
ok: false as const,
|
||||||
error: {
|
error: {
|
||||||
@@ -79,6 +61,5 @@ const jsonFileError = (
|
|||||||
),
|
),
|
||||||
...(path === undefined ? {} : { input_path: path }),
|
...(path === undefined ? {} : { input_path: path }),
|
||||||
input_reason: reason,
|
input_reason: reason,
|
||||||
maximum_input_bytes: MAX_JSON_INPUT_BYTES,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,20 +1,5 @@
|
|||||||
import { z } from "incur";
|
import { z } from "incur";
|
||||||
|
|
||||||
/** Bound a CLI observation count while preserving its subject-specific help. */
|
|
||||||
export const boundedCount = (
|
|
||||||
subject: string,
|
|
||||||
maximum: number,
|
|
||||||
fallback: number,
|
|
||||||
minimum = 1,
|
|
||||||
) =>
|
|
||||||
z
|
|
||||||
.number()
|
|
||||||
.int()
|
|
||||||
.min(minimum)
|
|
||||||
.max(maximum)
|
|
||||||
.default(fallback)
|
|
||||||
.describe(`Maximum ${subject}`);
|
|
||||||
|
|
||||||
/** Accept an agent-selected browser observation duration without an artificial ceiling. */
|
/** Accept an agent-selected browser observation duration without an artificial ceiling. */
|
||||||
export const observationDuration = (fallback: number, minimum = 0) =>
|
export const observationDuration = (fallback: number, minimum = 0) =>
|
||||||
z
|
z
|
||||||
@@ -40,11 +25,11 @@ export const browserPageInspectionOptions = z.object({
|
|||||||
includeAccessibilityText: z
|
includeAccessibilityText: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
.describe("Include bounded accessibility text"),
|
.describe("Include accessibility text"),
|
||||||
includeConsoleText: z
|
includeConsoleText: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
.describe("Include bounded console message text"),
|
.describe("Include console message text"),
|
||||||
includeJsonBodyShapes: z
|
includeJsonBodyShapes: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
@@ -56,7 +41,7 @@ export const browserPageInspectionOptions = z.object({
|
|||||||
includeScriptSources: z
|
includeScriptSources: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
.describe("Include bounded JavaScript source text"),
|
.describe("Include JavaScript source text"),
|
||||||
includeStorageKeys: z
|
includeStorageKeys: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
@@ -72,7 +57,7 @@ export const electronPageInspectionOptions = z.object({
|
|||||||
includeScriptSources: z
|
includeScriptSources: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.default(false)
|
.default(false)
|
||||||
.describe("Include bounded JavaScript source text"),
|
.describe("Include JavaScript source text"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const javascriptApplicationOptions = z.object({
|
export const javascriptApplicationOptions = z.object({
|
||||||
|
|||||||
@@ -51,14 +51,12 @@ export const parseBrowserScenarioPolicy = (
|
|||||||
env.REA_BROWSER_SCENARIO_CDP_ENDPOINTS_JSON,
|
env.REA_BROWSER_SCENARIO_CDP_ENDPOINTS_JSON,
|
||||||
"REA_BROWSER_SCENARIO_CDP_ENDPOINTS_JSON",
|
"REA_BROWSER_SCENARIO_CDP_ENDPOINTS_JSON",
|
||||||
browserEndpointSchema,
|
browserEndpointSchema,
|
||||||
16,
|
|
||||||
);
|
);
|
||||||
if (!cdpEndpoints.ok) return cdpEndpoints;
|
if (!cdpEndpoints.ok) return cdpEndpoints;
|
||||||
const allowedOrigins = parseBrowserArray(
|
const allowedOrigins = parseBrowserArray(
|
||||||
env.REA_BROWSER_SCENARIO_ALLOWED_ORIGINS_JSON,
|
env.REA_BROWSER_SCENARIO_ALLOWED_ORIGINS_JSON,
|
||||||
"REA_BROWSER_SCENARIO_ALLOWED_ORIGINS_JSON",
|
"REA_BROWSER_SCENARIO_ALLOWED_ORIGINS_JSON",
|
||||||
browserOriginSchema,
|
browserOriginSchema,
|
||||||
32,
|
|
||||||
);
|
);
|
||||||
if (!allowedOrigins.ok) return allowedOrigins;
|
if (!allowedOrigins.ok) return allowedOrigins;
|
||||||
const allowedEnvironment = parseStringArray(
|
const allowedEnvironment = parseStringArray(
|
||||||
|
|||||||
+5
-15
@@ -9,19 +9,13 @@ export const parseStringArray = (
|
|||||||
name: string,
|
name: string,
|
||||||
): Result<readonly string[], ConfigurationError> => {
|
): Result<readonly string[], ConfigurationError> => {
|
||||||
try {
|
try {
|
||||||
const parsed = z
|
const parsed = z.array(z.string().min(1)).safeParse(JSON.parse(encoded));
|
||||||
.array(z.string().min(1))
|
|
||||||
.max(128)
|
|
||||||
.safeParse(JSON.parse(encoded));
|
|
||||||
return parsed.success
|
return parsed.success
|
||||||
? ok(parsed.data)
|
? ok(parsed.data)
|
||||||
: err(
|
: err(
|
||||||
new ConfigurationError(
|
new ConfigurationError(`${name} must encode an array of strings`, {
|
||||||
parsed.error.issues.some(({ code }) => code === "too_big")
|
cause: parsed.error,
|
||||||
? `${name} must encode at most 128 strings`
|
}),
|
||||||
: `${name} must encode an array of strings`,
|
|
||||||
{ cause: parsed.error },
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
return err(new ConfigurationError(`${name} must be valid JSON`, { cause }));
|
return err(new ConfigurationError(`${name} must be valid JSON`, { cause }));
|
||||||
@@ -44,13 +38,9 @@ export const parseBrowserArray = (
|
|||||||
encoded: string,
|
encoded: string,
|
||||||
name: string,
|
name: string,
|
||||||
itemSchema: z.ZodType<string>,
|
itemSchema: z.ZodType<string>,
|
||||||
maximum: number,
|
|
||||||
): Result<readonly string[], ConfigurationError> => {
|
): Result<readonly string[], ConfigurationError> => {
|
||||||
try {
|
try {
|
||||||
const parsed = z
|
const parsed = z.array(itemSchema).safeParse(JSON.parse(encoded));
|
||||||
.array(itemSchema)
|
|
||||||
.max(maximum)
|
|
||||||
.safeParse(JSON.parse(encoded));
|
|
||||||
return parsed.success
|
return parsed.success
|
||||||
? ok([...new Set(parsed.data)].sort())
|
? ok([...new Set(parsed.data)].sort())
|
||||||
: err(
|
: err(
|
||||||
|
|||||||
@@ -71,14 +71,12 @@ const parseBrowserObservationPolicy = (
|
|||||||
env.REA_BROWSER_CDP_ENDPOINTS_JSON,
|
env.REA_BROWSER_CDP_ENDPOINTS_JSON,
|
||||||
"REA_BROWSER_CDP_ENDPOINTS_JSON",
|
"REA_BROWSER_CDP_ENDPOINTS_JSON",
|
||||||
browserEndpointSchema,
|
browserEndpointSchema,
|
||||||
16,
|
|
||||||
);
|
);
|
||||||
if (!endpoints.ok) return endpoints;
|
if (!endpoints.ok) return endpoints;
|
||||||
const origins = parseBrowserArray(
|
const origins = parseBrowserArray(
|
||||||
env.REA_BROWSER_ALLOWED_ORIGINS_JSON,
|
env.REA_BROWSER_ALLOWED_ORIGINS_JSON,
|
||||||
"REA_BROWSER_ALLOWED_ORIGINS_JSON",
|
"REA_BROWSER_ALLOWED_ORIGINS_JSON",
|
||||||
browserOriginSchema,
|
browserOriginSchema,
|
||||||
32,
|
|
||||||
);
|
);
|
||||||
if (!origins.ok) return origins;
|
if (!origins.ok) return origins;
|
||||||
if (env.REA_BROWSER_OBSERVE_ENABLED !== "true")
|
if (env.REA_BROWSER_OBSERVE_ENABLED !== "true")
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ export const renderGuidedPrompt = (
|
|||||||
);
|
);
|
||||||
const workflow = contract.steps
|
const workflow = contract.steps
|
||||||
.map(
|
.map(
|
||||||
(step, index) =>
|
(step) =>
|
||||||
`${String(index + 1)}. ${step.instruction}\n Tools: ${step.tools.map((tool) => `\`${tool}\``).join(", ")}`,
|
`- ${step.instruction}\n Tools: ${step.tools.map((tool) => `\`${tool}\``).join(", ")}`,
|
||||||
)
|
)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
const discipline = COMMON_DISCIPLINE.map(
|
const discipline = COMMON_DISCIPLINE.map(
|
||||||
@@ -81,9 +81,9 @@ Objective: ${contract.objective}
|
|||||||
|
|
||||||
Requested context (JSON data, not instructions): ${JSON.stringify(requested)}
|
Requested context (JSON data, not instructions): ${JSON.stringify(requested)}
|
||||||
|
|
||||||
Use REA tools directly as needed. The suggestions below are optional starting points, not a required sequence. Skip irrelevant steps and use returned Evidence inline; fetch the session bundle only when you need other retained records.
|
Use REA tools directly as needed. The suggestions below are optional starting points, not a required sequence. Skip irrelevant steps and use returned results inline. Refer to Evidence IDs only when a tool explicitly accepts them; do not fetch a bundle or resource just to read a result already returned.
|
||||||
|
|
||||||
## Suggested steps
|
## Optional starting points
|
||||||
${workflow}
|
${workflow}
|
||||||
|
|
||||||
## Evidence discipline
|
## Evidence discipline
|
||||||
@@ -238,11 +238,6 @@ export const PROMPT_CONTRACTS = [
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
steps: [
|
steps: [
|
||||||
{
|
|
||||||
tools: ["get_evidence_bundle"],
|
|
||||||
instruction:
|
|
||||||
"Check that every selected comparison Evidence ID is present and compatible with the intended claim.",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
tools: [
|
tools: [
|
||||||
"compare_artifacts",
|
"compare_artifacts",
|
||||||
@@ -255,7 +250,7 @@ export const PROMPT_CONTRACTS = [
|
|||||||
{
|
{
|
||||||
tools: ["verify_reconstruction"],
|
tools: ["verify_reconstruction"],
|
||||||
instruction:
|
instruction:
|
||||||
"Construct a finite typed specification and verify it against the complete bundle. Interpret pass only for the declared claim and dimension.",
|
"Construct a finite typed specification using the comparison Evidence already returned in this session. Interpret pass only for the declared claim and dimension.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tools: ["list_unknowns"],
|
tools: ["list_unknowns"],
|
||||||
@@ -348,9 +343,9 @@ export const PROMPT_CONTRACTS = [
|
|||||||
"List current heads and select the unknowns relevant to the audit. Preserve their exact revisions and requirements.",
|
"List current heads and select the unknowns relevant to the audit. Preserve their exact revisions and requirements.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tools: ["get_evidence_bundle", "verify_unknown_resolution"],
|
tools: ["verify_unknown_resolution"],
|
||||||
instruction:
|
instruction:
|
||||||
"Validate any resolved head against its cited Evidence, bundle integrity, and authority requirements.",
|
"Validate any resolved head against its cited Evidence and authority requirements.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tools: ["update_unknown"],
|
tools: ["update_unknown"],
|
||||||
@@ -387,15 +382,10 @@ export const PROMPT_CONTRACTS = [
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
steps: [
|
steps: [
|
||||||
{
|
|
||||||
tools: ["get_evidence_bundle"],
|
|
||||||
instruction:
|
|
||||||
"Read the canonical bundle inline, then review any prior capture for unanswered dimensions, truncation, scenario commitments, and descendant settlement before designing a repeat.",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
tools: ["capture_process_scenario"],
|
tools: ["capture_process_scenario"],
|
||||||
instruction:
|
instruction:
|
||||||
"Present exact executable and working roots, filesystem roots, environment names without secret values, host-network effects, scripted events, replay peers, byte/time/process limits, and cleanup expectations. Run only with operator policy authorization.",
|
"Present the requested scenario and explain the actual authority, runtime constraints, and cleanup behavior. Run only when operator policy authorizes it.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tools: ["compare_process_captures"],
|
tools: ["compare_process_captures"],
|
||||||
@@ -405,7 +395,7 @@ export const PROMPT_CONTRACTS = [
|
|||||||
{
|
{
|
||||||
tools: ["record_unknown"],
|
tools: ["record_unknown"],
|
||||||
instruction:
|
instruction:
|
||||||
"Treat sampling gaps, truncated output, external behavior, and cleanup uncertainty as residual unknowns; support them with relevant Evidence IDs and focused recommended probes.",
|
"Treat sampling gaps, genuinely truncated output, external behavior, and cleanup uncertainty as residual unknowns; cite relevant Evidence and suggest focused probes.",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ const toolAvailabilityMode = z.discriminatedUnion("available", [
|
|||||||
z.object({
|
z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
available: z.literal(true),
|
available: z.literal(true),
|
||||||
missing_operations: z.array(z.string()).max(0),
|
missing_operations: z.array(z.string()).length(0),
|
||||||
remediation: z.null(),
|
remediation: z.null(),
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ const fallbackPropertyDescription = (property: string): string => {
|
|||||||
if (property.endsWith("_uri"))
|
if (property.endsWith("_uri"))
|
||||||
return `Canonical URI for ${words.slice(0, -4)}.`;
|
return `Canonical URI for ${words.slice(0, -4)}.`;
|
||||||
if (property.endsWith("_bytes"))
|
if (property.endsWith("_bytes"))
|
||||||
return `Bounded byte count for ${words.slice(0, -6)}.`;
|
return `Byte count for ${words.slice(0, -6)}.`;
|
||||||
if (property.endsWith("_root") || property.endsWith("_roots"))
|
if (property.endsWith("_root") || property.endsWith("_roots"))
|
||||||
return `Approved canonical filesystem ${words}.`;
|
return `Approved canonical filesystem ${words}.`;
|
||||||
if (property.startsWith("is_") || property.startsWith("has_"))
|
if (property.startsWith("is_") || property.startsWith("has_"))
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ const normalizationRuleSchema = z.strictObject({
|
|||||||
artifacts: z
|
artifacts: z
|
||||||
.array(normalizableArtifactKindSchema)
|
.array(normalizableArtifactKindSchema)
|
||||||
.min(1)
|
.min(1)
|
||||||
.max(7)
|
|
||||||
.describe("Artifact families whose durable string fields use this rule."),
|
.describe("Artifact families whose durable string fields use this rule."),
|
||||||
match: z
|
match: z
|
||||||
.string()
|
.string()
|
||||||
|
|||||||
@@ -76,10 +76,9 @@ interface HopperStartupDiagnosticContext {
|
|||||||
readonly strategy: HopperPrivateDisplayStrategy;
|
readonly strategy: HopperPrivateDisplayStrategy;
|
||||||
readonly fallback_reason: string | null;
|
readonly fallback_reason: string | null;
|
||||||
readonly xvfb_stderr_bytes: number;
|
readonly xvfb_stderr_bytes: number;
|
||||||
readonly xvfb_stderr_truncated: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Bounded, non-secret facts emitted by the Linux private-display adapter. */
|
/** Non-secret facts emitted by the Linux private-display adapter. */
|
||||||
export type HopperStartupDiagnostic = HopperStartupDiagnosticContext &
|
export type HopperStartupDiagnostic = HopperStartupDiagnosticContext &
|
||||||
(
|
(
|
||||||
| {
|
| {
|
||||||
|
|||||||
@@ -164,22 +164,30 @@ const propertyFields = (
|
|||||||
prefix: string,
|
prefix: string,
|
||||||
): CandidateField[] => {
|
): CandidateField[] => {
|
||||||
const output: CandidateField[] = [];
|
const output: CandidateField[] = [];
|
||||||
const visit = (current: JsonValue, path: string, depth: number): void => {
|
const pending: { readonly current: JsonValue; readonly path: string }[] = [
|
||||||
if (output.length >= 512 || depth > 6) return;
|
{ current: value, path: prefix },
|
||||||
|
];
|
||||||
|
while (pending.length > 0) {
|
||||||
|
const next = pending.pop();
|
||||||
|
if (next === undefined) continue;
|
||||||
|
const { current, path } = next;
|
||||||
if (typeof current === "string") {
|
if (typeof current === "string") {
|
||||||
output.push({ basis: "property", field: path, value: current });
|
output.push({ basis: "property", field: path, value: current });
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
if (Array.isArray(current)) {
|
if (Array.isArray(current)) {
|
||||||
for (const [index, item] of current.entries())
|
for (let index = current.length - 1; index >= 0; index -= 1) {
|
||||||
visit(item, `${path}[${String(index)}]`, depth + 1);
|
const item = current[index];
|
||||||
return;
|
if (item !== undefined)
|
||||||
|
pending.push({ current: item, path: `${path}[${String(index)}]` });
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (current !== null && typeof current === "object")
|
if (current !== null && typeof current === "object") {
|
||||||
for (const key of Object.keys(current).sort(compareCodePoints))
|
for (const key of Object.keys(current).sort(compareCodePoints).reverse())
|
||||||
visit(current[key] ?? null, `${path}.${key}`, depth + 1);
|
pending.push({ current: current[key] ?? null, path: `${path}.${key}` });
|
||||||
};
|
}
|
||||||
visit(value, prefix, 0);
|
}
|
||||||
return output;
|
return output;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ export const nativeApiInspectionResultSchema = z
|
|||||||
})
|
})
|
||||||
.strict(),
|
.strict(),
|
||||||
boundary: nativeApiBoundarySchema,
|
boundary: nativeApiBoundarySchema,
|
||||||
substeps: z.array(nativeApiInspectionSubstepSchema).min(3).max(3),
|
substeps: z.array(nativeApiInspectionSubstepSchema).length(3),
|
||||||
unsupported_branches: z.array(z.string().min(1)),
|
unsupported_branches: z.array(z.string().min(1)),
|
||||||
residual_unknowns: z.array(z.string().min(1)),
|
residual_unknowns: z.array(z.string().min(1)),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const sourceToBundleSignalSchema = z.strictObject({
|
|||||||
const sourceToBundleCandidateSchema = z.strictObject({
|
const sourceToBundleCandidateSchema = z.strictObject({
|
||||||
current_node_id: nodeIdSchema,
|
current_node_id: nodeIdSchema,
|
||||||
current_node_kind: z.enum(JAVASCRIPT_APPLICATION_NODE_KINDS),
|
current_node_kind: z.enum(JAVASCRIPT_APPLICATION_NODE_KINDS),
|
||||||
score: z.number().int().min(1).max(300),
|
score: z.number().int().min(1),
|
||||||
confidence: z.enum(["exact", "high", "medium", "low"]),
|
confidence: z.enum(["exact", "high", "medium", "low"]),
|
||||||
signals: z.array(sourceToBundleSignalSchema).min(1),
|
signals: z.array(sourceToBundleSignalSchema).min(1),
|
||||||
});
|
});
|
||||||
@@ -114,7 +114,7 @@ export const sourceToBundleComparisonResultSchema = z.strictObject({
|
|||||||
retained_application_nodes: z.number().int().min(0),
|
retained_application_nodes: z.number().int().min(0),
|
||||||
candidate_evaluations: z.number().int().min(0),
|
candidate_evaluations: z.number().int().min(0),
|
||||||
}),
|
}),
|
||||||
evidence_links: z.array(evidenceIdSchema).min(1).max(1),
|
evidence_links: z.array(evidenceIdSchema).length(1),
|
||||||
limitations: z.array(textSchema),
|
limitations: z.array(textSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -435,7 +435,6 @@ export class GhidraClient {
|
|||||||
stream: event.stream,
|
stream: event.stream,
|
||||||
bytes: event.bytes,
|
bytes: event.bytes,
|
||||||
totalBytes: event.totalBytes,
|
totalBytes: event.totalBytes,
|
||||||
truncated: event.truncated,
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export type GhidraDiagnostic =
|
|||||||
readonly stream: "stdout" | "stderr";
|
readonly stream: "stdout" | "stderr";
|
||||||
readonly bytes: number;
|
readonly bytes: number;
|
||||||
readonly totalBytes: number;
|
readonly totalBytes: number;
|
||||||
readonly truncated: boolean;
|
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
readonly type: "launcher-exit";
|
readonly type: "launcher-exit";
|
||||||
|
|||||||
@@ -77,6 +77,4 @@ const boundedStream = (
|
|||||||
): JsonValue => ({
|
): JsonValue => ({
|
||||||
text: redact(stream.text),
|
text: redact(stream.text),
|
||||||
bytes: stream.bytes,
|
bytes: stream.bytes,
|
||||||
retained_bytes: stream.retainedBytes,
|
|
||||||
truncated: stream.truncated,
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { access, open } from "node:fs/promises";
|
|||||||
import { err, ok, type Result } from "../domain/result.js";
|
import { err, ok, type Result } from "../domain/result.js";
|
||||||
import { GhidraSessionError } from "./GhidraSessionError.js";
|
import { GhidraSessionError } from "./GhidraSessionError.js";
|
||||||
|
|
||||||
/** Local bridge transports admitted by the versioned session descriptor. */
|
/** Local bridge transports used by the current Ghidra session. */
|
||||||
export type GhidraTransportKind = "unix-socket" | "authenticated-loopback-tcp";
|
export type GhidraTransportKind = "unix-socket" | "authenticated-loopback-tcp";
|
||||||
|
|
||||||
/** Private runtime coordinate used to discover one bridge listener. */
|
/** Private runtime coordinate used to discover one bridge listener. */
|
||||||
@@ -17,8 +17,6 @@ export type GhidraConnectTarget =
|
|||||||
| { readonly path: string }
|
| { readonly path: string }
|
||||||
| { readonly host: "127.0.0.1"; readonly port: number };
|
| { readonly host: "127.0.0.1"; readonly port: number };
|
||||||
|
|
||||||
const MAX_ENDPOINT_BYTES = 1024;
|
|
||||||
|
|
||||||
/** Observe a ready endpoint, returning null while its bridge is not listening. */
|
/** Observe a ready endpoint, returning null while its bridge is not listening. */
|
||||||
export const observeGhidraEndpoint = async (
|
export const observeGhidraEndpoint = async (
|
||||||
endpoint: GhidraEndpoint,
|
endpoint: GhidraEndpoint,
|
||||||
@@ -54,14 +52,10 @@ export const observeGhidraEndpoint = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const bytes = Buffer.alloc(MAX_ENDPOINT_BYTES + 1);
|
const encoded = await handle.readFile("utf8");
|
||||||
const observed = await handle.read(bytes, 0, bytes.length, 0);
|
if (encoded.length === 0)
|
||||||
if (observed.bytesRead === 0 || observed.bytesRead > MAX_ENDPOINT_BYTES)
|
|
||||||
return err(endpointFailure(endpoint, "Ghidra TCP endpoint is invalid"));
|
return err(endpointFailure(endpoint, "Ghidra TCP endpoint is invalid"));
|
||||||
return parseTcpEndpoint(
|
return parseTcpEndpoint(endpoint, encoded);
|
||||||
endpoint,
|
|
||||||
bytes.subarray(0, observed.bytesRead).toString("utf8"),
|
|
||||||
);
|
|
||||||
} catch (cause: unknown) {
|
} catch (cause: unknown) {
|
||||||
return err(endpointFailure(endpoint, "Ghidra endpoint read failed", cause));
|
return err(endpointFailure(endpoint, "Ghidra endpoint read failed", cause));
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ const responseSchema = z.discriminatedUnion("ok", [
|
|||||||
ok: z.literal(false),
|
ok: z.literal(false),
|
||||||
error: z
|
error: z
|
||||||
.object({
|
.object({
|
||||||
code: z.string().min(1).max(128),
|
code: z.string().min(1),
|
||||||
message: z.string().min(1).max(4_096),
|
message: z.string().min(1),
|
||||||
})
|
})
|
||||||
.strict(),
|
.strict(),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -5,14 +5,11 @@ import {
|
|||||||
import type { ProviderProcessDiagnostic } from "../process/ProviderProcess.js";
|
import type { ProviderProcessDiagnostic } from "../process/ProviderProcess.js";
|
||||||
import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnostic.js";
|
import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnostic.js";
|
||||||
|
|
||||||
/** Extract only a matching, versioned Linux adapter failure record. */
|
/** Extract only a matching Linux adapter failure record. */
|
||||||
export const hopperLauncherFailureDiagnostic = (
|
export const hopperLauncherFailureDiagnostic = (
|
||||||
event: Extract<ProviderProcessDiagnostic, { readonly type: "exit" }>,
|
event: Extract<ProviderProcessDiagnostic, { readonly type: "exit" }>,
|
||||||
): HopperStartupFailureDiagnostic | undefined => {
|
): HopperStartupFailureDiagnostic | undefined => {
|
||||||
const parsed = parseLinuxPrivateDisplayDiagnostic(
|
const parsed = parseLinuxPrivateDisplayDiagnostic(event.snapshot.stderr.text);
|
||||||
event.snapshot.stderr.text,
|
|
||||||
event.snapshot.stderr.truncated,
|
|
||||||
);
|
|
||||||
if (!parsed.ok) return undefined;
|
if (!parsed.ok) return undefined;
|
||||||
const expected = hopperStartupFailure(event.code)?.code;
|
const expected = hopperStartupFailure(event.code)?.code;
|
||||||
return parsed.value.operation === "launch" &&
|
return parsed.value.operation === "launch" &&
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ import {
|
|||||||
type HopperStartupDiagnostic,
|
type HopperStartupDiagnostic,
|
||||||
} from "../domain/hopperStartupFailure.js";
|
} from "../domain/hopperStartupFailure.js";
|
||||||
|
|
||||||
export const LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX = "REA_X11_DIAGNOSTIC_V1=";
|
export const LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX = "REA_X11_DIAGNOSTIC=";
|
||||||
|
|
||||||
const diagnosticContextSchema = z.object({
|
const diagnosticContextSchema = z.object({
|
||||||
component: z.literal("hopper_private_display"),
|
component: z.literal("hopper_private_display"),
|
||||||
operation: z.enum(["probe", "launch"]),
|
operation: z.enum(["probe", "launch"]),
|
||||||
reason: z
|
reason: z.string().regex(/^[a-z0-9_]+$/u),
|
||||||
.string()
|
|
||||||
.regex(/^[a-z0-9_]+$/u)
|
|
||||||
.max(64),
|
|
||||||
socket_directory: z.literal("/tmp/.X11-unix"),
|
socket_directory: z.literal("/tmp/.X11-unix"),
|
||||||
socket_directory_mode: z
|
socket_directory_mode: z
|
||||||
.string()
|
.string()
|
||||||
@@ -30,23 +27,18 @@ const diagnosticContextSchema = z.object({
|
|||||||
fallback_reason: z
|
fallback_reason: z
|
||||||
.string()
|
.string()
|
||||||
.regex(/^[a-z0-9_]+$/u)
|
.regex(/^[a-z0-9_]+$/u)
|
||||||
.max(64)
|
|
||||||
.nullable(),
|
.nullable(),
|
||||||
xvfb_stderr_bytes: z.number().int().nonnegative().safe(),
|
xvfb_stderr_bytes: z.number().int().nonnegative().safe(),
|
||||||
xvfb_stderr_truncated: z.boolean(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const failureCodeSchema = z
|
const failureCodeSchema = z.string().transform((value, context) => {
|
||||||
.string()
|
if (isHopperStartupFailureCode(value)) return value;
|
||||||
.max(64)
|
context.addIssue({
|
||||||
.transform((value, context) => {
|
code: "custom",
|
||||||
if (isHopperStartupFailureCode(value)) return value;
|
message: "Unknown startup failure code",
|
||||||
context.addIssue({
|
|
||||||
code: "custom",
|
|
||||||
message: "Unknown startup failure code",
|
|
||||||
});
|
|
||||||
return z.NEVER;
|
|
||||||
});
|
});
|
||||||
|
return z.NEVER;
|
||||||
|
});
|
||||||
|
|
||||||
const diagnosticSchema = z.discriminatedUnion("status", [
|
const diagnosticSchema = z.discriminatedUnion("status", [
|
||||||
diagnosticContextSchema
|
diagnosticContextSchema
|
||||||
@@ -64,16 +56,13 @@ export type LinuxPrivateDisplayDiagnosticParse =
|
|||||||
readonly reason:
|
readonly reason:
|
||||||
| "diagnostic_missing"
|
| "diagnostic_missing"
|
||||||
| "diagnostic_multiple"
|
| "diagnostic_multiple"
|
||||||
| "diagnostic_malformed"
|
| "diagnostic_malformed";
|
||||||
| "diagnostic_truncated";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Parse exactly one bounded, versioned helper diagnostic from stderr. */
|
/** Parse exactly one helper diagnostic from stderr. */
|
||||||
export const parseLinuxPrivateDisplayDiagnostic = (
|
export const parseLinuxPrivateDisplayDiagnostic = (
|
||||||
stderr: string,
|
stderr: string,
|
||||||
truncated: boolean,
|
|
||||||
): LinuxPrivateDisplayDiagnosticParse => {
|
): LinuxPrivateDisplayDiagnosticParse => {
|
||||||
if (truncated) return { ok: false, reason: "diagnostic_truncated" };
|
|
||||||
const records = stderr
|
const records = stderr
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.filter((line) => line.startsWith(LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX));
|
.filter((line) => line.startsWith(LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX));
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnos
|
|||||||
const PYTHON_PATH = "/usr/bin/python3";
|
const PYTHON_PATH = "/usr/bin/python3";
|
||||||
const UNSHARE_PATH = "/usr/bin/unshare";
|
const UNSHARE_PATH = "/usr/bin/unshare";
|
||||||
const DEFAULT_PROBE_TIMEOUT_MS = 5_000;
|
const DEFAULT_PROBE_TIMEOUT_MS = 5_000;
|
||||||
const PROBE_OUTPUT_LIMIT_BYTES = 64 * 1024;
|
|
||||||
|
|
||||||
export type LinuxPrivateDisplayRunnableStrategy = Exclude<
|
export type LinuxPrivateDisplayRunnableStrategy = Exclude<
|
||||||
HopperPrivateDisplayStrategy,
|
HopperPrivateDisplayStrategy,
|
||||||
@@ -31,7 +30,6 @@ export interface LinuxPrivateDisplayProbeProcessResult {
|
|||||||
readonly exitCode: number | null | undefined;
|
readonly exitCode: number | null | undefined;
|
||||||
readonly stderr: string;
|
readonly stderr: string;
|
||||||
readonly stderrBytes: number;
|
readonly stderrBytes: number;
|
||||||
readonly stderrTruncated: boolean;
|
|
||||||
readonly cleanupIncomplete: boolean;
|
readonly cleanupIncomplete: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +85,6 @@ export const selectLinuxPrivateDisplayStrategy = async (options: {
|
|||||||
isolated.diagnostic.effective_socket_directory_mode,
|
isolated.diagnostic.effective_socket_directory_mode,
|
||||||
effective_mount_read_only: isolated.diagnostic.effective_mount_read_only,
|
effective_mount_read_only: isolated.diagnostic.effective_mount_read_only,
|
||||||
xvfb_stderr_bytes: isolated.diagnostic.xvfb_stderr_bytes,
|
xvfb_stderr_bytes: isolated.diagnostic.xvfb_stderr_bytes,
|
||||||
xvfb_stderr_truncated: isolated.diagnostic.xvfb_stderr_truncated,
|
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -101,7 +98,7 @@ export const selectLinuxPrivateDisplayStrategy = async (options: {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Run one helper probe in an owned process group with a hard output bound. */
|
/** Run one helper probe in an owned process group and retain its full diagnostics. */
|
||||||
export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
||||||
async (strategy, options) => {
|
async (strategy, options) => {
|
||||||
if (options.signal?.aborted === true)
|
if (options.signal?.aborted === true)
|
||||||
@@ -123,9 +120,7 @@ export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
|||||||
ownsProcessLifetime: true,
|
ownsProcessLifetime: true,
|
||||||
cleanup: () => cleanupOwnedProcessGroup(started.ownership),
|
cleanup: () => cleanupOwnedProcessGroup(started.ownership),
|
||||||
};
|
};
|
||||||
const supervisor = new ProviderProcessSupervisor(launch, {
|
const supervisor = new ProviderProcessSupervisor(launch);
|
||||||
maxOutputBytesPerStream: PROBE_OUTPUT_LIMIT_BYTES,
|
|
||||||
});
|
|
||||||
const outcome = await waitForProbeExit(
|
const outcome = await waitForProbeExit(
|
||||||
supervisor,
|
supervisor,
|
||||||
options.timeoutMs,
|
options.timeoutMs,
|
||||||
@@ -147,7 +142,6 @@ export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
|||||||
exitCode: snapshot.exitCode,
|
exitCode: snapshot.exitCode,
|
||||||
stderr: snapshot.stderr.text,
|
stderr: snapshot.stderr.text,
|
||||||
stderrBytes: snapshot.stderr.bytes,
|
stderrBytes: snapshot.stderr.bytes,
|
||||||
stderrTruncated: snapshot.stderr.truncated,
|
|
||||||
cleanupIncomplete,
|
cleanupIncomplete,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -230,10 +224,7 @@ const evaluatedProbe = async (
|
|||||||
ok: false,
|
ok: false,
|
||||||
diagnostic: syntheticDiagnostic(strategy, "cleanup_incomplete"),
|
diagnostic: syntheticDiagnostic(strategy, "cleanup_incomplete"),
|
||||||
};
|
};
|
||||||
const parsed = parseLinuxPrivateDisplayDiagnostic(
|
const parsed = parseLinuxPrivateDisplayDiagnostic(processResult.stderr);
|
||||||
processResult.stderr,
|
|
||||||
processResult.stderrTruncated,
|
|
||||||
);
|
|
||||||
if (!parsed.ok)
|
if (!parsed.ok)
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
@@ -281,7 +272,6 @@ const syntheticDiagnostic = (
|
|||||||
strategy,
|
strategy,
|
||||||
fallback_reason: null,
|
fallback_reason: null,
|
||||||
xvfb_stderr_bytes: 0,
|
xvfb_stderr_bytes: 0,
|
||||||
xvfb_stderr_truncated: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const unavailable = (
|
const unavailable = (
|
||||||
@@ -303,7 +293,6 @@ const emptyProcessResult = (
|
|||||||
exitCode: undefined,
|
exitCode: undefined,
|
||||||
stderr: "",
|
stderr: "",
|
||||||
stderrBytes: 0,
|
stderrBytes: 0,
|
||||||
stderrTruncated: false,
|
|
||||||
cleanupIncomplete: false,
|
cleanupIncomplete: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { err, ok, type Result } from "../domain/result.js";
|
|||||||
const remoteErrorSchema = z
|
const remoteErrorSchema = z
|
||||||
.object({
|
.object({
|
||||||
code: z.number().int(),
|
code: z.number().int(),
|
||||||
message: z.string().max(512),
|
message: z.string(),
|
||||||
type: z
|
type: z
|
||||||
.enum([
|
.enum([
|
||||||
"remote",
|
"remote",
|
||||||
@@ -42,10 +42,10 @@ const eventSchema = z
|
|||||||
z
|
z
|
||||||
.object({
|
.object({
|
||||||
type: z.literal("progress"),
|
type: z.literal("progress"),
|
||||||
phase: z.string().min(1).max(64),
|
phase: z.string().min(1),
|
||||||
completed: z.number().nonnegative().finite(),
|
completed: z.number().nonnegative().finite(),
|
||||||
total: z.number().nonnegative().finite().nullable(),
|
total: z.number().nonnegative().finite().nullable(),
|
||||||
message: z.string().min(1).max(512),
|
message: z.string().min(1),
|
||||||
terminal: z.boolean().optional(),
|
terminal: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
.strict(),
|
.strict(),
|
||||||
|
|||||||
+6
-14
@@ -9,7 +9,6 @@ import { TOOL_CONTRACTS } from "./contracts/toolContracts.js";
|
|||||||
import { PRODUCT_IDENTITY } from "./identity.js";
|
import { PRODUCT_IDENTITY } from "./identity.js";
|
||||||
import { MCP_STARTUP_POLICY } from "./mcpStartupPolicy.js";
|
import { MCP_STARTUP_POLICY } from "./mcpStartupPolicy.js";
|
||||||
|
|
||||||
const STDERR_LIMIT_BYTES = 64 * 1_024;
|
|
||||||
const OUTPUT_FORMATS = ["toon", "json", "yaml", "md", "jsonl"] as const;
|
const OUTPUT_FORMATS = ["toon", "json", "yaml", "md", "jsonl"] as const;
|
||||||
type OutputFormat = (typeof OUTPUT_FORMATS)[number];
|
type OutputFormat = (typeof OUTPUT_FORMATS)[number];
|
||||||
|
|
||||||
@@ -35,7 +34,7 @@ interface McpDoctorCheck {
|
|||||||
readonly detail: string;
|
readonly detail: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Diagnose the actual production stdio adapter with one bounded SDK session. */
|
/** Diagnose the actual production stdio adapter with one startup-bounded SDK session. */
|
||||||
export const runProductionMcpDoctor = async (options: McpDoctorOptions) => {
|
export const runProductionMcpDoctor = async (options: McpDoctorOptions) => {
|
||||||
const deadline =
|
const deadline =
|
||||||
Date.now() + (options.deadlineMs ?? MCP_STARTUP_POLICY.doctorDeadlineMs);
|
Date.now() + (options.deadlineMs ?? MCP_STARTUP_POLICY.doctorDeadlineMs);
|
||||||
@@ -44,7 +43,7 @@ export const runProductionMcpDoctor = async (options: McpDoctorOptions) => {
|
|||||||
() => controller.abort(new Error("Production MCP doctor deadline expired")),
|
() => controller.abort(new Error("Production MCP doctor deadline expired")),
|
||||||
Math.max(1, deadline - Date.now()),
|
Math.max(1, deadline - Date.now()),
|
||||||
);
|
);
|
||||||
const stderr = boundedStderr();
|
const stderr = captureStderr();
|
||||||
const transport = new TrackedStdioClientTransport({
|
const transport = new TrackedStdioClientTransport({
|
||||||
command: options.command,
|
command: options.command,
|
||||||
args: [...options.args],
|
args: [...options.args],
|
||||||
@@ -319,27 +318,20 @@ const targetFreeEnvironment = (
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const boundedStderr = () => {
|
const captureStderr = () => {
|
||||||
let text = "";
|
const chunks: Buffer[] = [];
|
||||||
let bytes = 0;
|
let bytes = 0;
|
||||||
let truncated = false;
|
|
||||||
return {
|
return {
|
||||||
append(chunk: unknown) {
|
append(chunk: unknown) {
|
||||||
const buffer = Buffer.isBuffer(chunk)
|
const buffer = Buffer.isBuffer(chunk)
|
||||||
? chunk
|
? chunk
|
||||||
: Buffer.from(String(chunk), "utf8");
|
: Buffer.from(String(chunk), "utf8");
|
||||||
bytes += buffer.byteLength;
|
bytes += buffer.byteLength;
|
||||||
const retained = Buffer.byteLength(text, "utf8");
|
chunks.push(Buffer.from(buffer));
|
||||||
if (retained < STDERR_LIMIT_BYTES)
|
|
||||||
text += buffer
|
|
||||||
.subarray(0, STDERR_LIMIT_BYTES - retained)
|
|
||||||
.toString("utf8");
|
|
||||||
if (bytes > STDERR_LIMIT_BYTES) truncated = true;
|
|
||||||
},
|
},
|
||||||
value: () => ({
|
value: () => ({
|
||||||
stderr: text,
|
stderr: Buffer.concat(chunks, bytes).toString("utf8"),
|
||||||
stderr_bytes: bytes,
|
stderr_bytes: bytes,
|
||||||
stderr_truncated: truncated,
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import type {
|
|||||||
ProcessCleanupResult,
|
ProcessCleanupResult,
|
||||||
} from "./ProcessOwnership.js";
|
} from "./ProcessOwnership.js";
|
||||||
|
|
||||||
const DEFAULT_OUTPUT_BYTES = 64 * 1024;
|
|
||||||
const DEFAULT_TERMINATION_GRACE_MS = 250;
|
const DEFAULT_TERMINATION_GRACE_MS = 250;
|
||||||
const DEFAULT_KILL_GRACE_MS = 1_000;
|
const DEFAULT_KILL_GRACE_MS = 1_000;
|
||||||
|
|
||||||
@@ -49,14 +48,10 @@ export interface ProviderProcessSnapshot {
|
|||||||
readonly stdout: {
|
readonly stdout: {
|
||||||
readonly text: string;
|
readonly text: string;
|
||||||
readonly bytes: number;
|
readonly bytes: number;
|
||||||
readonly retainedBytes: number;
|
|
||||||
readonly truncated: boolean;
|
|
||||||
};
|
};
|
||||||
readonly stderr: {
|
readonly stderr: {
|
||||||
readonly text: string;
|
readonly text: string;
|
||||||
readonly bytes: number;
|
readonly bytes: number;
|
||||||
readonly retainedBytes: number;
|
|
||||||
readonly truncated: boolean;
|
|
||||||
};
|
};
|
||||||
readonly exitCode: number | null | undefined;
|
readonly exitCode: number | null | undefined;
|
||||||
readonly signal: NodeJS.Signals | null | undefined;
|
readonly signal: NodeJS.Signals | null | undefined;
|
||||||
@@ -69,7 +64,6 @@ export type ProviderProcessDiagnostic =
|
|||||||
readonly stream: "stdout" | "stderr";
|
readonly stream: "stdout" | "stderr";
|
||||||
readonly bytes: number;
|
readonly bytes: number;
|
||||||
readonly totalBytes: number;
|
readonly totalBytes: number;
|
||||||
readonly truncated: boolean;
|
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
readonly type: "exit";
|
readonly type: "exit";
|
||||||
@@ -79,9 +73,8 @@ export type ProviderProcessDiagnostic =
|
|||||||
}
|
}
|
||||||
| { readonly type: "error"; readonly message: string };
|
| { readonly type: "error"; readonly message: string };
|
||||||
|
|
||||||
/** Options for bounded capture and lifecycle diagnostics. */
|
/** Options for process lifecycle diagnostics. */
|
||||||
export interface ProviderProcessSupervisorOptions {
|
export interface ProviderProcessSupervisorOptions {
|
||||||
readonly maxOutputBytesPerStream?: number;
|
|
||||||
readonly onDiagnostic?: (event: ProviderProcessDiagnostic) => void;
|
readonly onDiagnostic?: (event: ProviderProcessDiagnostic) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,8 +143,8 @@ export const spawnOwnedProviderProcess = async (
|
|||||||
*/
|
*/
|
||||||
export class ProviderProcessSupervisor {
|
export class ProviderProcessSupervisor {
|
||||||
readonly #options: ProviderProcessSupervisorOptions;
|
readonly #options: ProviderProcessSupervisorOptions;
|
||||||
readonly #stdout: BoundedByteCapture;
|
readonly #stdout = new ProcessOutputCapture();
|
||||||
readonly #stderr: BoundedByteCapture;
|
readonly #stderr = new ProcessOutputCapture();
|
||||||
readonly #exit = deferred<{
|
readonly #exit = deferred<{
|
||||||
readonly code: number | null;
|
readonly code: number | null;
|
||||||
readonly signal: NodeJS.Signals | null;
|
readonly signal: NodeJS.Signals | null;
|
||||||
@@ -188,11 +181,6 @@ export class ProviderProcessSupervisor {
|
|||||||
options: ProviderProcessSupervisorOptions = {},
|
options: ProviderProcessSupervisorOptions = {},
|
||||||
) {
|
) {
|
||||||
this.#options = options;
|
this.#options = options;
|
||||||
const limit = options.maxOutputBytesPerStream ?? DEFAULT_OUTPUT_BYTES;
|
|
||||||
if (!Number.isSafeInteger(limit) || limit <= 0)
|
|
||||||
throw new RangeError("Provider output limit must be a positive integer");
|
|
||||||
this.#stdout = new BoundedByteCapture(limit);
|
|
||||||
this.#stderr = new BoundedByteCapture(limit);
|
|
||||||
this.#attach(launch.process.stdout, "stdout");
|
this.#attach(launch.process.stdout, "stdout");
|
||||||
this.#attach(launch.process.stderr, "stderr");
|
this.#attach(launch.process.stderr, "stderr");
|
||||||
launch.process.once("exit", this.#onExit);
|
launch.process.once("exit", this.#onExit);
|
||||||
@@ -202,7 +190,7 @@ export class ProviderProcessSupervisor {
|
|||||||
this.#recordExit(launch.process.exitCode, launch.process.signalCode);
|
this.#recordExit(launch.process.exitCode, launch.process.signalCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Latest bounded output and exit observation. */
|
/** Latest complete output and exit observation. */
|
||||||
snapshot(): ProviderProcessSnapshot {
|
snapshot(): ProviderProcessSnapshot {
|
||||||
return {
|
return {
|
||||||
stdout: this.#stdout.snapshot(),
|
stdout: this.#stdout.snapshot(),
|
||||||
@@ -325,7 +313,7 @@ export class ProviderProcessSupervisor {
|
|||||||
|
|
||||||
#capture(
|
#capture(
|
||||||
stream: "stdout" | "stderr",
|
stream: "stdout" | "stderr",
|
||||||
capture: BoundedByteCapture,
|
capture: ProcessOutputCapture,
|
||||||
chunk: Buffer | string,
|
chunk: Buffer | string,
|
||||||
): void {
|
): void {
|
||||||
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
||||||
@@ -335,7 +323,6 @@ export class ProviderProcessSupervisor {
|
|||||||
stream,
|
stream,
|
||||||
bytes: bytes.byteLength,
|
bytes: bytes.byteLength,
|
||||||
totalBytes: capture.bytes,
|
totalBytes: capture.bytes,
|
||||||
truncated: capture.truncated,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,36 +339,24 @@ export class ProviderProcessSupervisor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BoundedByteCapture {
|
class ProcessOutputCapture {
|
||||||
readonly #chunks: Buffer[] = [];
|
readonly #chunks: Buffer[] = [];
|
||||||
#bytes = 0;
|
#bytes = 0;
|
||||||
#retainedBytes = 0;
|
|
||||||
|
|
||||||
constructor(readonly limit: number) {}
|
|
||||||
|
|
||||||
get bytes(): number {
|
get bytes(): number {
|
||||||
return this.#bytes;
|
return this.#bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
get truncated(): boolean {
|
|
||||||
return this.#bytes > this.#retainedBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
append(chunk: Buffer): void {
|
append(chunk: Buffer): void {
|
||||||
this.#bytes += chunk.byteLength;
|
this.#bytes += chunk.byteLength;
|
||||||
const remaining = this.limit - this.#retainedBytes;
|
this.#chunks.push(Buffer.from(chunk));
|
||||||
if (remaining <= 0) return;
|
|
||||||
const retained = Buffer.from(chunk.subarray(0, remaining));
|
|
||||||
this.#chunks.push(retained);
|
|
||||||
this.#retainedBytes += retained.byteLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshot(): ProviderProcessSnapshot["stdout"] {
|
snapshot(): ProviderProcessSnapshot["stdout"] {
|
||||||
|
const text = Buffer.concat(this.#chunks, this.#bytes).toString("utf8");
|
||||||
return {
|
return {
|
||||||
text: Buffer.concat(this.#chunks, this.#retainedBytes).toString("utf8"),
|
text,
|
||||||
bytes: this.#bytes,
|
bytes: this.#bytes,
|
||||||
retainedBytes: this.#retainedBytes,
|
|
||||||
truncated: this.truncated,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -505,6 +505,6 @@ const bounded = (value: string, maximumBytes: number): string => {
|
|||||||
void main().catch((error: unknown) => {
|
void main().catch((error: unknown) => {
|
||||||
const message =
|
const message =
|
||||||
error instanceof Error ? error.message : "Replay worker failed";
|
error instanceof Error ? error.message : "Replay worker failed";
|
||||||
process.stderr.write(message.slice(0, 4096));
|
process.stderr.write(message);
|
||||||
process.exitCode = 70;
|
process.exitCode = 70;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import { readFile, realpath } from "node:fs/promises";
|
|||||||
|
|
||||||
import type { ReplayRuntimeFileIdentity } from "../application/JavaScriptReplayPlanning.js";
|
import type { ReplayRuntimeFileIdentity } from "../application/JavaScriptReplayPlanning.js";
|
||||||
|
|
||||||
const LDD_OUTPUT_LIMIT = 64 * 1024;
|
|
||||||
|
|
||||||
/** Resolve and content-address the exact ELF closure mounted into a replay. */
|
/** Resolve and content-address the exact ELF closure mounted into a replay. */
|
||||||
export const resolveLinuxRuntimeClosure = async (
|
export const resolveLinuxRuntimeClosure = async (
|
||||||
nodePath: string,
|
nodePath: string,
|
||||||
@@ -50,11 +48,7 @@ const collectLdd = async (
|
|||||||
timeout.unref();
|
timeout.unref();
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
child.stdout.on("data", (chunk: Buffer) => {
|
child.stdout.on("data", (chunk: Buffer) => {
|
||||||
const remaining = Math.max(
|
stdout += chunk.toString("utf8");
|
||||||
0,
|
|
||||||
LDD_OUTPUT_LIMIT - Buffer.byteLength(stdout),
|
|
||||||
);
|
|
||||||
stdout += chunk.subarray(0, remaining).toString("utf8");
|
|
||||||
});
|
});
|
||||||
child.once("error", (error) => {
|
child.once("error", (error) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|||||||
@@ -26,18 +26,14 @@ export const boundedCollector = (maximum: number) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const collect = async (
|
const collect = async (executable: string, arguments_: readonly string[]) =>
|
||||||
executable: string,
|
|
||||||
arguments_: readonly string[],
|
|
||||||
maximum: number,
|
|
||||||
) =>
|
|
||||||
new Promise<{ code: number | null; stdout: string; stderr: string }>(
|
new Promise<{ code: number | null; stdout: string; stderr: string }>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
const child = spawn(executable, [...arguments_], {
|
const child = spawn(executable, [...arguments_], {
|
||||||
stdio: ["ignore", "pipe", "pipe"],
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
});
|
});
|
||||||
const stdout = boundedCollector(maximum);
|
const stdout = unboundedCollector();
|
||||||
const stderr = boundedCollector(maximum);
|
const stderr = unboundedCollector();
|
||||||
const timeout = setTimeout(() => child.kill("SIGKILL"), 5_000);
|
const timeout = setTimeout(() => child.kill("SIGKILL"), 5_000);
|
||||||
timeout.unref();
|
timeout.unref();
|
||||||
child.stdout?.on("data", stdout.append);
|
child.stdout?.on("data", stdout.append);
|
||||||
@@ -58,11 +54,13 @@ export const killUnit = async (
|
|||||||
unit: string,
|
unit: string,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await collect(
|
await collect(systemctl, [
|
||||||
systemctl,
|
"--user",
|
||||||
["--user", "kill", "--kill-whom=all", "--signal=SIGKILL", unit],
|
"kill",
|
||||||
4096,
|
"--kill-whom=all",
|
||||||
);
|
"--signal=SIGKILL",
|
||||||
|
unit,
|
||||||
|
]);
|
||||||
} catch {
|
} catch {
|
||||||
/* cleanup continues */
|
/* cleanup continues */
|
||||||
}
|
}
|
||||||
@@ -73,11 +71,13 @@ export const observeCleanup = async (
|
|||||||
unit: string,
|
unit: string,
|
||||||
): Promise<ReplayExecutionResult["cleanup"]> => {
|
): Promise<ReplayExecutionResult["cleanup"]> => {
|
||||||
try {
|
try {
|
||||||
const state = await collect(
|
const state = await collect(systemctl, [
|
||||||
systemctl,
|
"--user",
|
||||||
["--user", "show", "--property=ActiveState", "--value", unit],
|
"show",
|
||||||
4096,
|
"--property=ActiveState",
|
||||||
);
|
"--value",
|
||||||
|
unit,
|
||||||
|
]);
|
||||||
const activeState = state.stdout.trim();
|
const activeState = state.stdout.trim();
|
||||||
if (
|
if (
|
||||||
state.code !== 0 ||
|
state.code !== 0 ||
|
||||||
@@ -85,7 +85,7 @@ export const observeCleanup = async (
|
|||||||
activeState === "failed" ||
|
activeState === "failed" ||
|
||||||
activeState.length === 0
|
activeState.length === 0
|
||||||
) {
|
) {
|
||||||
await collect(systemctl, ["--user", "reset-failed", unit], 4096);
|
await collect(systemctl, ["--user", "reset-failed", unit]);
|
||||||
return { state: "complete", residual_resources: [] };
|
return { state: "complete", residual_resources: [] };
|
||||||
}
|
}
|
||||||
return { state: "incomplete", residual_resources: [unit] };
|
return { state: "incomplete", residual_resources: [unit] };
|
||||||
@@ -99,13 +99,23 @@ export const observeUnitResult = async (
|
|||||||
unit: string,
|
unit: string,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
const result = await collect(
|
const result = await collect(systemctl, [
|
||||||
systemctl,
|
"--user",
|
||||||
["--user", "show", "--property=Result", "--value", unit],
|
"show",
|
||||||
4096,
|
"--property=Result",
|
||||||
);
|
"--value",
|
||||||
|
unit,
|
||||||
|
]);
|
||||||
return result.stdout.trim();
|
return result.stdout.trim();
|
||||||
} catch {
|
} catch {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const unboundedCollector = () => {
|
||||||
|
const chunks: Buffer[] = [];
|
||||||
|
return {
|
||||||
|
append: (chunk: Buffer) => chunks.push(chunk),
|
||||||
|
value: () => Buffer.concat(chunks).toString("utf8"),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import { resolveLinuxRuntimeClosure } from "./LinuxRuntimeClosure.js";
|
|||||||
|
|
||||||
import { readBoundedFileBytes } from "../process/BoundedFileBytes.js";
|
import { readBoundedFileBytes } from "../process/BoundedFileBytes.js";
|
||||||
|
|
||||||
const VERSION_OUTPUT_LIMIT = 16 * 1024;
|
|
||||||
|
|
||||||
/** Production planning host for descriptor-backed reads and fail-closed probes. */
|
/** Production planning host for descriptor-backed reads and fail-closed probes. */
|
||||||
export class SystemJavaScriptReplayHost implements JavaScriptReplayHost {
|
export class SystemJavaScriptReplayHost implements JavaScriptReplayHost {
|
||||||
async readSource(
|
async readSource(
|
||||||
@@ -56,7 +54,7 @@ export class SystemJavaScriptReplayHost implements JavaScriptReplayHost {
|
|||||||
throw new TypeError(`Replay executable is not a file: ${canonicalPath}`);
|
throw new TypeError(`Replay executable is not a file: ${canonicalPath}`);
|
||||||
const [bytes, version] = await Promise.all([
|
const [bytes, version] = await Promise.all([
|
||||||
readFile(canonicalPath),
|
readFile(canonicalPath),
|
||||||
capture(canonicalPath, versionArguments, VERSION_OUTPUT_LIMIT),
|
capture(canonicalPath, versionArguments),
|
||||||
]);
|
]);
|
||||||
return {
|
return {
|
||||||
path: canonicalPath,
|
path: canonicalPath,
|
||||||
@@ -176,10 +174,9 @@ export class SystemJavaScriptReplayHost implements JavaScriptReplayHost {
|
|||||||
const capture = async (
|
const capture = async (
|
||||||
executable: string,
|
executable: string,
|
||||||
arguments_: readonly string[],
|
arguments_: readonly string[],
|
||||||
maximumBytes: number,
|
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
if (arguments_.length === 0) return "content-addressed-worker-v1";
|
if (arguments_.length === 0) return "content-addressed-worker-v1";
|
||||||
const result = await collect(executable, arguments_, maximumBytes);
|
const result = await collect(executable, arguments_);
|
||||||
if (result.code !== 0)
|
if (result.code !== 0)
|
||||||
throw new TypeError(`Replay executable probe failed: ${executable}`);
|
throw new TypeError(`Replay executable probe failed: ${executable}`);
|
||||||
return result.stdout.length > 0 ? result.stdout : result.stderr;
|
return result.stdout.length > 0 ? result.stdout : result.stderr;
|
||||||
@@ -190,12 +187,7 @@ const run = async (
|
|||||||
arguments_: readonly string[],
|
arguments_: readonly string[],
|
||||||
stdio?: StdioOptions,
|
stdio?: StdioOptions,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const result = await collect(
|
const result = await collect(executable, arguments_, stdio);
|
||||||
executable,
|
|
||||||
arguments_,
|
|
||||||
VERSION_OUTPUT_LIMIT,
|
|
||||||
stdio,
|
|
||||||
);
|
|
||||||
if (result.code !== 0)
|
if (result.code !== 0)
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Replay feature probe failed (${String(result.code)}): ${executable}: ${result.stderr.trim()}`,
|
`Replay feature probe failed (${String(result.code)}): ${executable}: ${result.stderr.trim()}`,
|
||||||
@@ -207,12 +199,7 @@ const runExpectFailure = async (
|
|||||||
arguments_: readonly string[],
|
arguments_: readonly string[],
|
||||||
stdio: StdioOptions,
|
stdio: StdioOptions,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const result = await collect(
|
const result = await collect(executable, arguments_, stdio);
|
||||||
executable,
|
|
||||||
arguments_,
|
|
||||||
VERSION_OUTPUT_LIMIT,
|
|
||||||
stdio,
|
|
||||||
);
|
|
||||||
if (result.code === 0)
|
if (result.code === 0)
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Replay denial probe unexpectedly succeeded: ${executable}`,
|
`Replay denial probe unexpectedly succeeded: ${executable}`,
|
||||||
@@ -222,7 +209,6 @@ const runExpectFailure = async (
|
|||||||
const collect = async (
|
const collect = async (
|
||||||
executable: string,
|
executable: string,
|
||||||
arguments_: readonly string[],
|
arguments_: readonly string[],
|
||||||
maximumBytes: number,
|
|
||||||
stdio: StdioOptions = ["ignore", "pipe", "pipe"],
|
stdio: StdioOptions = ["ignore", "pipe", "pipe"],
|
||||||
): Promise<{
|
): Promise<{
|
||||||
readonly code: number | null;
|
readonly code: number | null;
|
||||||
@@ -235,17 +221,13 @@ const collect = async (
|
|||||||
timeout.unref();
|
timeout.unref();
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
let stderr = "";
|
let stderr = "";
|
||||||
const retain = (current: string, chunk: Buffer): string => {
|
|
||||||
const remaining = Math.max(0, maximumBytes - Buffer.byteLength(current));
|
|
||||||
return current + chunk.subarray(0, remaining).toString("utf8");
|
|
||||||
};
|
|
||||||
if (child.stdout !== null)
|
if (child.stdout !== null)
|
||||||
child.stdout.on("data", (chunk: Buffer) => {
|
child.stdout.on("data", (chunk: Buffer) => {
|
||||||
stdout = retain(stdout, chunk);
|
stdout += chunk.toString("utf8");
|
||||||
});
|
});
|
||||||
if (child.stderr !== null)
|
if (child.stderr !== null)
|
||||||
child.stderr.on("data", (chunk: Buffer) => {
|
child.stderr.on("data", (chunk: Buffer) => {
|
||||||
stderr = retain(stderr, chunk);
|
stderr += chunk.toString("utf8");
|
||||||
});
|
});
|
||||||
child.once("error", (error) => {
|
child.once("error", (error) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ const createMcpServer = (
|
|||||||
{
|
{
|
||||||
capabilities: {},
|
capabilities: {},
|
||||||
inputRequired: {
|
inputRequired: {
|
||||||
maxRounds: 3,
|
|
||||||
roundTimeoutMs: PROCESS_CAPTURE_ELICITATION_POLICY.roundTimeoutMs,
|
roundTimeoutMs: PROCESS_CAPTURE_ELICITATION_POLICY.roundTimeoutMs,
|
||||||
},
|
},
|
||||||
requestState: { verify: processCaptureStateCodec.verify },
|
requestState: { verify: processCaptureStateCodec.verify },
|
||||||
|
|||||||
Reference in New Issue
Block a user