* fix(comparisons)!: preserve unknowns across partial observations Share absence and digest semantics, keep unobserved managed bodies unknown, and match unique managed type/name/signatures before structural fallback. BREAKING CHANGE: Managed comparison metadata adds exact-signature matching and its count, and name_matching now reports exact-signature-fallback. * fix(javascript): preserve projected result binding semantics Share syntax-aware property reads and assigned-result resolution. Retain destructuring paths and downgrade downstream whole-result relationships instead of resolving nested or wrapped calls as aliases. * fix(native)!: admit complete parser values and preserve typed failures Decode Mach headers by named columns, validate complete slice keys and lipo alignment, and preserve codesign runtime flags and tagged parser errors. Rename the Ghidra test dossier fixture and connect fake-backed suites to real verification lanes. BREAKING CHANGE: Native load-command results no longer contain the unused, always-null file_offset field. * fix(process): preserve host identity and actionable boundary failures Thread selected platform and environment through process and Doctor seams, stamp observed producer identity in Evidence, and retain PTY, filesystem, lease and lazy-provider failure causes. Drain cancelled lazy loads and omit exited descendants from verified lineage. * fix(browser): preserve cleanup and document-transition evidence Make V8 and Playwright teardown cancellation-aware, expose primary failures alongside incomplete cleanup, share frame-tree and navigation rules, and clear stale WebMCP registrations without pruning unrelated child frames. * fix(adapters): align managed targets and typed CLI outcomes Inspect managed PE/CLI targets independently of native provider selection, reuse successful managed selections, and keep evidence bound to the actual inspected target. Classify canonical CLI error envelopes and exhaustive setup/update/uninstall outcomes, audit registered CLI coverage, and assert platform-specific runtime results. * docs: refresh boundary contracts and shipped roadmap behavior
123 lines
3.9 KiB
TypeScript
123 lines
3.9 KiB
TypeScript
const SAFE_VALIDATION_MESSAGE =
|
|
"REA could not read the command arguments. Run `rea --help`, correct the arguments, then try again.";
|
|
const UNSUPPORTED_OUTPUT_COMBINATION_MESSAGE =
|
|
"Token windows cannot preserve structured output. Remove --token-limit/--token-offset and use --filter-output or command pagination.";
|
|
|
|
type StructuredOutputFormat = "json" | "jsonl" | "yaml";
|
|
|
|
export type CliOutputArgumentValidation =
|
|
| { readonly ok: true }
|
|
| {
|
|
readonly ok: false;
|
|
readonly format: StructuredOutputFormat;
|
|
readonly code: "UNSUPPORTED_OUTPUT_COMBINATION";
|
|
readonly message: string;
|
|
};
|
|
|
|
type JsonRecord = Record<string, unknown>;
|
|
|
|
const isRecord = (value: unknown): value is JsonRecord =>
|
|
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
|
|
const validationError = (value: JsonRecord): JsonRecord | undefined => {
|
|
if (value.code === "VALIDATION_ERROR") return value;
|
|
if (value.ok === false && isRecord(value.error))
|
|
return value.error.code === "VALIDATION_ERROR" ? value.error : undefined;
|
|
return undefined;
|
|
};
|
|
|
|
/** Reject text-window controls that would corrupt a structured document. */
|
|
export const validateCliOutputArguments = (
|
|
arguments_: readonly string[],
|
|
): CliOutputArgumentValidation => {
|
|
let format: string = "toon";
|
|
let tokenWindow = false;
|
|
for (let index = 0; index < arguments_.length; index += 1) {
|
|
const argument = arguments_[index];
|
|
if (argument === "--") break;
|
|
if (argument === "--json") {
|
|
format = "json";
|
|
continue;
|
|
}
|
|
if (argument === "--format") {
|
|
const value = arguments_[index + 1];
|
|
if (value !== undefined) {
|
|
format = value;
|
|
index += 1;
|
|
}
|
|
continue;
|
|
}
|
|
if (argument?.startsWith("--format=")) {
|
|
format = argument.slice("--format=".length);
|
|
continue;
|
|
}
|
|
if (argument === "--token-limit" || argument === "--token-offset") {
|
|
if (arguments_[index + 1] !== undefined) {
|
|
tokenWindow = true;
|
|
index += 1;
|
|
}
|
|
continue;
|
|
}
|
|
if (
|
|
argument?.startsWith("--token-limit=") ||
|
|
argument?.startsWith("--token-offset=")
|
|
)
|
|
tokenWindow = true;
|
|
}
|
|
if (
|
|
tokenWindow &&
|
|
(format === "json" || format === "jsonl" || format === "yaml")
|
|
)
|
|
return {
|
|
ok: false,
|
|
format,
|
|
code: "UNSUPPORTED_OUTPUT_COMBINATION",
|
|
message: UNSUPPORTED_OUTPUT_COMBINATION_MESSAGE,
|
|
};
|
|
return { ok: true };
|
|
};
|
|
|
|
/** Render one complete structured error before command execution. */
|
|
export const renderCliOutputArgumentError = (
|
|
error: Exclude<CliOutputArgumentValidation, { readonly ok: true }>,
|
|
): string => {
|
|
const value = {
|
|
ok: false,
|
|
error: { code: error.code, message: error.message },
|
|
};
|
|
if (error.format === "yaml")
|
|
return `ok: false\nerror:\n code: ${error.code}\n message: ${JSON.stringify(error.message)}\n`;
|
|
return `${JSON.stringify(value)}\n`;
|
|
};
|
|
|
|
/** Remove validator internals from Incur's caller-visible CLI output. */
|
|
export const sanitizeCliOutput = (output: string): string => {
|
|
const trimmed = output.trimStart();
|
|
if (trimmed.startsWith("{")) {
|
|
try {
|
|
const parsed: unknown = JSON.parse(trimmed);
|
|
if (!isRecord(parsed)) return output;
|
|
const error = validationError(parsed);
|
|
if (error !== undefined) {
|
|
const safeError = {
|
|
code: "VALIDATION_ERROR",
|
|
message: SAFE_VALIDATION_MESSAGE,
|
|
};
|
|
if (error === parsed) return `${JSON.stringify(safeError)}\n`;
|
|
return `${JSON.stringify({ ...parsed, error: safeError })}\n`;
|
|
}
|
|
} catch {
|
|
return output;
|
|
}
|
|
return output;
|
|
}
|
|
if (
|
|
/^ok: false\r?\nerror:\r?\n code: VALIDATION_ERROR(?:\r?\n|$)/u.test(
|
|
trimmed,
|
|
)
|
|
)
|
|
return `ok: false\nerror:\n code: VALIDATION_ERROR\n message: "${SAFE_VALIDATION_MESSAGE}"\n`;
|
|
if (!/^code: VALIDATION_ERROR(?:\r?\n|$)/u.test(trimmed)) return output;
|
|
return `code: VALIDATION_ERROR\nmessage: "${SAFE_VALIDATION_MESSAGE}"\n`;
|
|
};
|