Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6de554e2a | ||
|
|
1a322ab75b | ||
|
|
9d8e42bdd6 | ||
|
|
d28b41ea4e | ||
|
|
e8491e023a | ||
|
|
097f0d54af | ||
|
|
e4ac7bbfc2 | ||
|
|
0b7fc40eee | ||
|
|
7a0140b4aa | ||
|
|
9b3e59804d | ||
|
|
1769417001 | ||
|
|
898d5096f9 | ||
|
|
38539a2f4a | ||
|
|
23d50ea3be | ||
|
|
7c207c7951 | ||
|
|
d3e83b0899 | ||
|
|
29d2624b34 | ||
|
|
fa9a7e5ec0 | ||
|
|
efbc25fbea | ||
|
|
ea40f717b2 |
@@ -2,7 +2,7 @@
|
||||
name: reverse-engineer-anything
|
||||
description: Reverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.
|
||||
metadata:
|
||||
version: "38"
|
||||
version: "39"
|
||||
---
|
||||
|
||||
# REA
|
||||
|
||||
@@ -9,7 +9,10 @@ provenance; inputs and recovered code are never executed. Recovery requires a
|
||||
caller-supplied Wakaru on Linux x64; see [the recovery guide](https://github.com/morluto/rea/blob/main/docs/javascript-recovery.md).
|
||||
|
||||
Use `analyze_javascript_application` directly on the operator-supplied ASAR or
|
||||
extracted tree. When size is unknown or large and the connected schema advertises
|
||||
extracted tree. Exact `#alias` specifiers resolve through the importer's
|
||||
enclosing package `imports` map to package-local files; nested `node_modules`
|
||||
packages use their own map. Wildcard, recursive, and external-package import
|
||||
targets stay unresolved with that limitation. When size is unknown or large and the connected schema advertises
|
||||
`detail`, request `detail: "summary"`. This returns an `inspect_analysis_view`
|
||||
Evidence record with a distinct ID and a `normalized_result.parent_evidence_id`
|
||||
for the complete retained application analysis. Source-map contents are part of
|
||||
|
||||
@@ -150,6 +150,13 @@ For headerless DOS COM, explicitly open with `format: "dos-com"` (CLI
|
||||
analysis: the entry is `0x10100`, file offset zero, with imposed real-mode segment
|
||||
context. PSP/stack/device state remains unmodeled. See [DOS guide](https://github.com/morluto/rea/blob/main/docs/ghidra-dos.md).
|
||||
|
||||
For other headerless images (embedded firmware without ELF/Mach-O/PE/MZ
|
||||
headers), open with `format: "raw-binary"`, `architecture` (`x86`, `x86_64`,
|
||||
`arm`, or `arm64`), and `entry_point` (`0x` hex). File offset 0 is mapped at
|
||||
that address. Hopper and IDA refuse this interpretation; Ghidra uses
|
||||
`BinaryLoader` with a little-endian generic language. Big-endian, Thumb-only,
|
||||
and Cortex-M variants are unsupported. See [raw binary guide](https://github.com/morluto/rea/blob/main/docs/raw-binary.md).
|
||||
|
||||
### Function annotations in Ghidra
|
||||
|
||||
Use `annotate_native_function` for one function name and/or entry comments, with at least one explicit change. Review its annotation readback and refreshed dossier inline. Changes are atomic and session-scoped; empty comments clear them, omitted fields preserve them. Later MCP calls observe edits until close. CLI `annotate-native-function` returns the updated analysis before discarding the session. Original executable bytes are unchanged; edits invalidate immutable snapshots. Windows P0 does not admit database mutations. For naming only, `set_address_name` / `set_addresses_names` also work with Ghidra: they name function entries or data addresses (primary labels) and return compact per-address success booleans instead of a dossier.
|
||||
|
||||
@@ -126,6 +126,20 @@ class ReaJadxBridge {
|
||||
return result;
|
||||
}
|
||||
|
||||
private JadxSession.SmartCode methodBody(JadxSession current, ClassSnapshot cls,
|
||||
MethodSnapshot selected, JavaMethod method) {
|
||||
if (!selected.shortId().equals("<clinit>()V"))
|
||||
return current.getMethodBodySmart(method, current.getMaxSourceBytes(), true);
|
||||
// Java code generation can fold all or part of <clinit> into field declarations.
|
||||
// Its method text cannot establish coverage, even when a static block remains.
|
||||
JadxSession.MethodSmali smali = current.getMethodSmali(cls.node(), method.getName());
|
||||
if (!smali.getFound() || smali.getBlocks().size() != 1)
|
||||
throw new IllegalArgumentException("Static initializer disassembly requires one exact method: " + selected.shortId());
|
||||
return new JadxSession.SmartCode(
|
||||
TextUtilKt.truncateToBytes(smali.getBlocks().get(0), current.getMaxSourceBytes()),
|
||||
"smali", true, List.of("static_initializer_disassembly"));
|
||||
}
|
||||
|
||||
private CallToolResult handle(String name, JsonObject args) {
|
||||
if (name.equals("rea_jvm_status")) return json(Map.of(
|
||||
"engine_reported_version", BuildInfo.VERSION,
|
||||
@@ -150,7 +164,7 @@ class ReaJadxBridge {
|
||||
int index = integer(args, "overload_index", 0);
|
||||
if (index >= overloads.size()) throw new InputFailure("overload_index", "overload_index out of range: " + index);
|
||||
JavaMethod method = method(cls, overloads.get(index));
|
||||
JadxSession.SmartCode code = current.getMethodBodySmart(method, current.getMaxSourceBytes(), true);
|
||||
JadxSession.SmartCode code = methodBody(current, cls, overloads.get(index), method);
|
||||
return json(Map.of("class_name", cls.summary().get("full_name"),
|
||||
"method_name", overloads.get(index).name(), "full_name", method.getFullName(),
|
||||
"overload_index", index, "overload_count", overloads.size(),
|
||||
@@ -211,7 +225,7 @@ class ReaJadxBridge {
|
||||
String description = switch (name) {
|
||||
case "list_classes" -> "Indexed pages of all top-level class names, with offset and limit.";
|
||||
case "get_class_summary" -> "Parsed member metadata for one exact class name; no source generation.";
|
||||
case "get_method_body" -> "Source for an exact class and stable same-name overload index, with smali fallback.";
|
||||
case "get_method_body" -> "Source for an exact class and stable same-name overload index; static initializers use smali to preserve folded field initialization.";
|
||||
default -> "Complete static references to an exact class or unique method; source lines are unresolved.";
|
||||
};
|
||||
Tool narrowed = new Tool(name, new ToolSchema(null, new JsonObject(properties),
|
||||
|
||||
@@ -182,10 +182,17 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
}
|
||||
sessionDefaultAddressSpace =
|
||||
currentProgram.getAddressFactory().getDefaultAddressSpace();
|
||||
if (currentProgram.getExecutableFormat().equals("Raw Binary") &&
|
||||
!currentProgram.getOptions(ghidra.program.model.listing.Program.PROGRAM_INFO)
|
||||
.getBoolean("REA DOS COM prepared", false)) {
|
||||
throw new IllegalStateException("REA DOS COM entry/context preparation failed");
|
||||
if (currentProgram.getExecutableFormat().equals("Raw Binary")) {
|
||||
boolean dosCom = currentProgram.getLanguageID().getIdAsString()
|
||||
.equals("x86:LE:16:Real Mode");
|
||||
String preparation = dosCom ? "REA DOS COM prepared" : "REA raw binary prepared";
|
||||
if (!currentProgram.getOptions(ghidra.program.model.listing.Program.PROGRAM_INFO)
|
||||
.getBoolean(preparation, false)) {
|
||||
throw new IllegalStateException(
|
||||
dosCom ? "REA DOS COM entry/context preparation failed" :
|
||||
"REA raw binary entry preparation failed"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!Application.getApplicationVersion().equals(descriptor.providerVersion)) {
|
||||
throw new IllegalStateException("Ghidra provider version does not match the session");
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
||||
/** Seed the caller-supplied raw-binary entry before default auto-analysis. */
|
||||
public final class ReaGhidraPrepareRaw extends GhidraScript {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
String[] arguments = getScriptArgs();
|
||||
if (arguments.length != 2) {
|
||||
throw new IllegalArgumentException(
|
||||
"Raw binary preparation requires the committed language and entry address"
|
||||
);
|
||||
}
|
||||
String expectedLanguage = arguments[0];
|
||||
String entryHex = arguments[1];
|
||||
if (!currentProgram.getLanguageID().getIdAsString().equals(expectedLanguage) ||
|
||||
!currentProgram.getExecutableFormat().equals("Raw Binary")) {
|
||||
throw new IllegalArgumentException(
|
||||
"Raw binary preparation requires the committed language and BinaryLoader import"
|
||||
);
|
||||
}
|
||||
Address entry = currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(entryHex);
|
||||
Address start = currentProgram.getMinAddress();
|
||||
if (entry == null || !entry.equals(start)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Raw binary import must map file offset 0 at the caller-supplied entry"
|
||||
);
|
||||
}
|
||||
addEntryPoint(entry);
|
||||
if (!disassemble(entry) || createFunction(entry, "entry") == null) {
|
||||
throw new IllegalStateException("Raw binary entry cannot be decoded as a function");
|
||||
}
|
||||
currentProgram.getOptions(Program.PROGRAM_INFO).setBoolean("REA raw binary prepared", true);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ export default defineConfig({
|
||||
{ text: "IDA", link: "/ida-provider" },
|
||||
{ text: "Ghidra on Windows", link: "/windows-ghidra-p0" },
|
||||
{ text: "Ghidra DOS analysis", link: "/ghidra-dos" },
|
||||
{ text: "Ghidra raw binary", link: "/raw-binary" },
|
||||
{ text: "Ghidra NativeAOT", link: "/ghidra-nativeaot" },
|
||||
{ text: "Ghidra semantics", link: "/ghidra-provider" },
|
||||
],
|
||||
|
||||
@@ -94,6 +94,12 @@ fallback for an overloaded method instead of attributing all bodies to one
|
||||
selected overload. Native/abstract methods with no decompiled body report
|
||||
`body_status: "not_available"` without inferring which implementation flag caused it.
|
||||
|
||||
Static initializers (`<clinit>`) return smali with the
|
||||
`static_initializer_disassembly` marker. Java decompilation can move their
|
||||
instructions into field declarations, leaving an empty or incomplete method
|
||||
body. The selected method's disassembly preserves those instructions and retains
|
||||
the same source byte limit and explicit truncation reporting.
|
||||
|
||||
## Interpret the result
|
||||
|
||||
- Package inspection retains decoded manifest XML, summary declarations,
|
||||
|
||||
+2
-1
@@ -59,7 +59,8 @@ alone, use `rea instructions`. A macOS `.app` bundle can be supplied directly.
|
||||
Run `rea --help` or a command's `--help` for arguments and output options.
|
||||
The [generated catalog](product-catalog.json) lists all CLI commands and MCP
|
||||
tools. Provider-specific target support is described in the
|
||||
[native guide](native-investigation.md), [DOS guide](ghidra-dos.md), and
|
||||
[native guide](native-investigation.md), [DOS guide](ghidra-dos.md),
|
||||
[raw binary guide](raw-binary.md), and
|
||||
[Windows Ghidra guide](windows-ghidra-p0.md).
|
||||
|
||||
## Choose a provider
|
||||
|
||||
@@ -323,15 +323,48 @@ substitute version-dependent Electron defaults for omitted `webPreferences`.
|
||||
Dynamic option objects, bridge keys, API objects, and IPC channel expressions
|
||||
remain unknown and make coverage partial.
|
||||
|
||||
Electron API identity follows proven lexical module aliases. Bundled CommonJS
|
||||
namespace imports are also followed through the interop helpers that bundlers
|
||||
and compilers emit (`__toESM`, `__importStar`, `_interopRequireWildcard`),
|
||||
including the `electron = __toESM(electron)` rewrap that Rolldown emits. This
|
||||
step is inferred: a helper is recognized by its emitted name and a single
|
||||
program-scope function definition, and its body is not evaluated, so a local
|
||||
function that reuses one of these names is trusted to pass the module through.
|
||||
Other reassigned bindings, dynamic selections, and visibly overwritten namespace
|
||||
members are unresolved.
|
||||
Electron API identity follows proven lexical module aliases. Namespace interop
|
||||
also preserves identity when the complete Rolldown helper operations, lexical
|
||||
roles, live getters, and captured intrinsic origins match, or when a stable
|
||||
helper simply returns its module parameter. Harmless single-statement control
|
||||
blocks preserve recognition; added operations still require proof. Literal
|
||||
member and destructuring projections are retained from proven results.
|
||||
Omitted or literal node-mode arguments preserve named exports; a module-valued
|
||||
default projection requires a truthy literal node mode. Computed or extra
|
||||
arguments remain unresolved.
|
||||
Recognition uses structure rather than emitted names; other helper bodies and ambiguous
|
||||
runtime fallbacks remain unresolved. Captured function identities survive later global-property
|
||||
replacement, including copies through initialized aliases. Reads before an
|
||||
alias initializer remain unresolved. Visible intrinsic writes before capture or
|
||||
conversion are checked in their owning callable scope, including identifier leaves in nested/default/rest
|
||||
destructuring and loop targets. Property keys and shadowed local bindings do not
|
||||
overwrite the global intrinsic identity. Cross-call side effects, including
|
||||
writes inside directly invoked local functions, are not evaluated. Other
|
||||
reassignments, dynamic selections, and visibly overwritten namespace members
|
||||
are unresolved.
|
||||
Known Object/Reflect mutators remain recognizable through literal destructuring
|
||||
of intrinsic objects and stable bound-function aliases. Calls retain bound
|
||||
argument prefixes and the original bound receiver through `call`, `apply`, and
|
||||
`Reflect.apply`, including generic `Function.prototype` invocation and binding
|
||||
creation. Arguments follow each actual callable invocation rather than property
|
||||
chain depth; rebinding retains the original bound receiver.
|
||||
Visibly replaced invocation intrinsics produce unknown effects instead
|
||||
of using their former call semantics; captured function aliases retain their
|
||||
earlier identity. Invocation member reads are checked separately from the earlier
|
||||
function capture. Comma-expression callees use their final value while all
|
||||
preceding expressions remain in the effect traversal. Call effects are
|
||||
classified after callee and argument effects have been collected. Unexamined
|
||||
targets remain unresolved. `Reflect.set` examines its explicit receiver as well
|
||||
as its target, retaining unknown receiver effects. Creating an unused binding
|
||||
does not itself mutate an intrinsic. Variable redeclarations retain a single
|
||||
unconditional initializer
|
||||
when they introduce no assignment or second initializer.
|
||||
Stable identifier chains to fresh object, array, function,
|
||||
undecorated class or RegExp syntax keep those targets separate from intrinsic
|
||||
objects when initialized before use; opaque, decorated, reassigned or
|
||||
not-yet-initialized targets remain unresolved. Writes during class initialization
|
||||
are still retained. Function declarations are available before their textual
|
||||
position; variable and class initializers must precede use.
|
||||
Direct and destructuring assignment, loop, update, and delete targets are checked
|
||||
through namespace aliases; unrelated member writes do not discard observed API
|
||||
identity. This static check does
|
||||
@@ -425,9 +458,29 @@ such as `./web3:app.js` still names a local artifact.
|
||||
Package `exports` fallback arrays are supported both at the top level and under
|
||||
the root `"."` entry. The resolver selects targets in declared order using the
|
||||
same conditional and invalid-entry handling as nested exports arrays.
|
||||
Nonempty arrays containing only inactive conditions remain unmatched, allowing
|
||||
the enclosing condition object to continue to a later active condition.
|
||||
Empty arrays and explicit null targets keep their blocking outcome.
|
||||
Refusal evidence distinguishes those source values and retains condition names
|
||||
from unmatched nested targets rather than reporting array indices.
|
||||
For imports and requires, the active Node conditions include `module-sync`;
|
||||
earlier active conditions retain precedence over later ones.
|
||||
|
||||
Exact package-private `#alias` specifiers resolve against the importer's
|
||||
enclosing `package.json` `imports` map — the nearest same-container package
|
||||
scope, stopping at a `node_modules` directory so a nested package cannot inherit
|
||||
an ancestor's aliases. Selected targets are package-local `./` files with no
|
||||
extension or index fallback, using the same condition, array, and null selection
|
||||
as exports subpaths. A missing key, explicit null, or out-of-scope alias keeps
|
||||
an unresolved edge with that reason. Wildcard keys (`#internal/*`), recursive
|
||||
`#` targets, and external-package import targets remain unresolved.
|
||||
|
||||
Exact keys such as `#/x` are literal lookup identities. `#` and names ending
|
||||
in `/` are invalid. Imports arrays skip invalid parent-relative, absolute, and
|
||||
URL targets before selecting a later package-local file; an unsupported bare
|
||||
package or recursive alias keeps its unresolved outcome rather than selecting
|
||||
a later fallback.
|
||||
|
||||
ESM relative module paths and selected package exports targets use URL suffix handling
|
||||
and one percent-decoding pass. CommonJS relative paths and legacy package main
|
||||
fields retain literal filename punctuation. Exports targets must start with
|
||||
|
||||
+30
-9
@@ -150,13 +150,15 @@ structured data and matching text projection. Oversized errors are retained
|
||||
as Evidence before delivery of a bounded diagnostic with an export reference;
|
||||
if retention is unavailable or fails, the diagnostic reports that reason.
|
||||
|
||||
REA accepts ordinary `tools/call` progress tokens. Updates are monotonic,
|
||||
rate-bounded to at most one intermediate update per 100 ms, and always allow a
|
||||
terminal update. Unknown totals are omitted; REA does not fabricate percentages.
|
||||
REA accepts ordinary `tools/call` progress tokens. The numeric `progress` counts
|
||||
emitted status observations and strictly increases, including when a waiting
|
||||
phase has completed no additional work. Updates are rate-bounded to at most one
|
||||
intermediate update per 100 ms and always allow a terminal update. `total` is
|
||||
omitted because the number of future status observations is unknown. Read
|
||||
`message` for the phase and observed work; REA does not fabricate percentages.
|
||||
`capture_process_scenario` uses that boundary only when the client supplies a
|
||||
progress token. Notifications set `progress` to the count of collected terminal
|
||||
frames, process samples, and interaction events, omit `total`, and put the
|
||||
lifecycle phase, elapsed time, and final cleanup status in `message`. A client
|
||||
progress token. Notifications put the lifecycle phase, elapsed time, and final
|
||||
cleanup status in `message`. A client
|
||||
that does not send a progress token receives no progress notifications. The
|
||||
tool result is unchanged either way.
|
||||
Provider calls receive the request cancellation signal. Artifact traversal,
|
||||
@@ -230,6 +232,18 @@ engine readiness or a percentage of Ghidra auto-analysis. A longer server
|
||||
startup allowance does not extend the client's deadline; progress also does not
|
||||
extend it unless the client explicitly implements that policy.
|
||||
|
||||
While Ghidra startup is pending, REA sends a waiting notification every ten
|
||||
seconds when the request has a progress token. Its message gives elapsed waiting
|
||||
time; import, auto-analysis and bridge readiness may all still be pending.
|
||||
Waiting notifications stop when startup settles or the caller cancels. They do
|
||||
not measure engine work completed.
|
||||
|
||||
The pinned SDK can reset the request's inactivity timeout on progress with
|
||||
`resetTimeoutOnProgress: true`. Also set `maxTotalTimeout` to bound the complete
|
||||
request; the provider's startup deadline still applies. These options belong in
|
||||
the same second argument of `callTool`. Without that explicit client policy, the
|
||||
default 60-second request deadline still expires despite waiting notifications.
|
||||
|
||||
The 240-second setting is a measured example, not a universal timeout: a
|
||||
controlled Linux x64/WSL2 fixture took about 64 seconds for its first overview
|
||||
with Ghidra 12.1.4 on a mounted NTFS installation, native JDK 21, two CPUs, and a
|
||||
@@ -265,9 +279,10 @@ observed process-family member remained after final close. This was a small
|
||||
1,024-byte fixture, so the longer request setting remains an example, not a
|
||||
guarantee for larger targets. No macOS cold-start recovery was exercised.
|
||||
|
||||
With a supplied progress token, the Windows run received an operation-start
|
||||
With a supplied progress token, that earlier Windows run received an operation-start
|
||||
notification before timeout and start/completion notifications for the
|
||||
successful retry. It received no intermediate import or auto-analysis progress.
|
||||
successful retry, before startup waiting notifications were added. It received
|
||||
no intermediate import or auto-analysis progress.
|
||||
These operation markers do not measure analysis work completed or extend the
|
||||
client's deadline. Each new provider session still imports the target into a
|
||||
fresh temporary project.
|
||||
@@ -435,7 +450,13 @@ Tool annotations describe effects and are hints, not authorization controls
|
||||
([MCP ToolAnnotations](https://modelcontextprotocol.io/specification/2025-06-18/schema#toolannotations)).
|
||||
`readOnlyHint` includes session state: an analysis call that records additive
|
||||
Evidence is marked non-read-only even when it leaves the target unchanged.
|
||||
`destructiveHint` describes possible data loss, not ordinary Evidence recording.
|
||||
`destructiveHint` is true when a tool may discard data (overwriting or clearing
|
||||
analyst metadata, replacing files, dropping session state), runs or drives code
|
||||
REA does not own (`executesForeignCode`: process, LLDB, Electron, browser, and
|
||||
native UI scenarios), or changes an attached Android device (`mutatesDevice`:
|
||||
push, install, uninstall, start, and stop). Ordinary Evidence recording is not
|
||||
destructive. The effect record in `binary_session` and the generated catalog
|
||||
carries each flag separately.
|
||||
Effect metadata covers possible behavior across supported inputs: DMG inventory
|
||||
can launch `hdiutil` and create an owned temporary mount directory; extraction
|
||||
creates a fresh output directory on every call. Comparing supplied web captures
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Headerless raw-binary analysis with Ghidra
|
||||
|
||||
REA admits a headerless executable when the caller supplies the CPU family and
|
||||
the address where file offset 0 should be mapped. That interpretation is not
|
||||
inferred from a `.bin` suffix or from unrecognized bytes.
|
||||
|
||||
## Open and inspect
|
||||
|
||||
```bash
|
||||
rea inspect /absolute/path/to/ecu.bin --target-format raw-binary --architecture arm --entry-point 0x8000000 --provider ghidra --json
|
||||
rea function /absolute/path/to/ecu.bin 0x8000000 --target-format raw-binary --architecture arm --entry-point 0x8000000 --provider ghidra --json
|
||||
rea inspect-native-load-image /absolute/path/to/ecu.bin --target-format raw-binary --architecture arm --entry-point 0x8000000 --provider ghidra --json
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "open_binary",
|
||||
"arguments": {
|
||||
"path": "/absolute/path/to/ecu.bin",
|
||||
"format": "raw-binary",
|
||||
"architecture": "arm",
|
||||
"entry_point": "0x8000000",
|
||||
"provider_id": "ghidra"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`architecture` is one of `x86`, `x86_64`, `arm`, or `arm64`. `entry_point` is a
|
||||
hexadecimal address of the form `0x…`. The complete file is mapped starting at
|
||||
that address, and Ghidra seeds an `entry` function there before auto-analysis.
|
||||
ARM and AArch64 entries must be 4-byte aligned; x86 entries may be byte-aligned.
|
||||
`open_binary` and an open `binary_session` return the canonical `entry_point`
|
||||
for raw targets so callers can verify the selected mapping directly.
|
||||
Omitted `format` keeps header-based detection; architecture and entry without
|
||||
`format=raw-binary` are rejected.
|
||||
|
||||
Ghidra imports a private snapshot with `BinaryLoader` and these little-endian
|
||||
generic languages:
|
||||
|
||||
| architecture | language_id |
|
||||
| ------------ | ------------------- |
|
||||
| x86 | `x86:LE:32:default` |
|
||||
| x86_64 | `x86:LE:64:default` |
|
||||
| arm | `ARM:LE:32:v7` |
|
||||
| arm64 | `AARCH64:LE:64:v8A` |
|
||||
|
||||
Those settings, the caller-supplied entry, and `language_selection:
|
||||
caller-supplied-v1` are committed in the analysis profile. A different entry
|
||||
or architecture is a different profile; snapshots from header-detected targets
|
||||
do not replay.
|
||||
|
||||
The mapped start is independent of Ghidra's program image base, which remains
|
||||
`0x0` for BinaryLoader. Ghidra may report additional language-defined entry
|
||||
points, including unmapped ARM vectors. Load-image verification requires the
|
||||
caller-supplied entry and preserves those other entries as observations.
|
||||
Independent raw verification streams the complete private snapshot digest and
|
||||
extent with bounded memory and supports cancellation during the read.
|
||||
|
||||
Hopper and IDA refuse raw-binary targets. Windows Ghidra P0 continues to admit
|
||||
PE applications only.
|
||||
|
||||
## Limitations
|
||||
|
||||
- Headers are not discovered from file bytes. This increment does not guess
|
||||
load addresses, vector tables, or memory maps.
|
||||
- Big-endian, Thumb-only, Cortex-M, and other Ghidra processor variants are
|
||||
unsupported.
|
||||
- Reset vectors, memory-mapped I/O, and firmware boot sequences are not
|
||||
emulated.
|
||||
- Independent load-image verification covers source identity, mapped file
|
||||
bytes, the bound language, and the caller-supplied entry. Original bytes
|
||||
stay unchanged.
|
||||
@@ -793,6 +793,14 @@ truncation constraint, while leading-zero coordinates still resolve correctly.
|
||||
It has the same Ghidra/JDK prerequisites as the MZ lane. Neither lane claims DOS
|
||||
runtime or PC-98 device execution.
|
||||
|
||||
`npm run verify:ghidra:raw` uses a generated ARM little-endian headerless image
|
||||
through the compiled CLI and stdio MCP server. With the same Ghidra/JDK
|
||||
prerequisites, it checks preparation and bridge startup, verified load mappings,
|
||||
instruction and byte readback, canonical-entry session reuse, replacement when
|
||||
the entry changes without `provider_id`, unchanged source bytes, and owned
|
||||
cleanup. Other raw CPU families remain covered by deterministic tests rather
|
||||
than this real-provider lane. See [raw binary analysis](raw-binary.md).
|
||||
|
||||
## Apple Interface Builder archives
|
||||
|
||||
`npm run verify:interface-builder` compiles the source-owned AppKit XIB into a
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
# REA Code Mode experiment
|
||||
|
||||
Frozen baseline: `fb94d9dde0ccda83ae520ac6fb22b1d283562cf3`, fetched from
|
||||
`origin/main` on 2026-10-11. Branch: `experiment/codemode-bridge-20261011`.
|
||||
This is a local experiment, not a change to the published CLI or MCP API.
|
||||
|
||||
The analyst question is whether composing REA's existing named tools in code
|
||||
improves investigation efficiency enough to justify an optional bridge. Existing
|
||||
users must keep their current names, input schemas, Evidence and session behavior.
|
||||
Provider analysis settings must stay identical between comparison profiles.
|
||||
|
||||
The bridge owns one upstream stdio MCP connection and discovers its complete live
|
||||
catalog. Only discovery and JavaScript execution are exposed downstream. Code
|
||||
calls `tools.<original_name>(original_arguments)` and receives the original MCP
|
||||
result envelope. REA still validates input, chooses providers, retains Evidence,
|
||||
and owns analysis resources. There is no second tool implementation or schema
|
||||
catalog to keep synchronized. A fresh QuickJS WASM context exposes only those
|
||||
tool calls, JSON helpers and explicit output; it has no host filesystem, network,
|
||||
process or module loader.
|
||||
|
||||
Start the bridge without changing an existing registration:
|
||||
|
||||
```bash
|
||||
node bridge.mjs /absolute/path/to/node /absolute/path/to/rea/scripts/rea.mjs mcp
|
||||
```
|
||||
|
||||
Register that command as a separate, temporary MCP server for a trial. Existing
|
||||
REA registrations keep their original tools. `rea_search` accepts a query or exact
|
||||
names; use `schemas: false` for the complete lightweight name/description list.
|
||||
Query discovery returns names/descriptions by default; exact-name discovery
|
||||
returns original input schemas and derived input/output TypeScript declarations.
|
||||
These declarations help write code; they do not replace JSON validation contracts.
|
||||
`schemas` explicitly overrides that choice.
|
||||
Start with one domain word and request all selected exact names in one call.
|
||||
Request `output_schemas: true` when a
|
||||
result contract is needed; the original output schema is then returned unchanged.
|
||||
`catalog_sha256` identifies the SDK catalog; it must not be substituted for REA's
|
||||
`server_identity.catalog.digests` fields.
|
||||
`rea_execute` accepts a JavaScript async function body. For example:
|
||||
|
||||
```js
|
||||
const session = json(await tools.binary_session({})).result;
|
||||
return { open: session.open, identity: session.server_identity };
|
||||
```
|
||||
|
||||
The returned projection is not a new Evidence record. `calls` preserves operation,
|
||||
argument/result digests, upstream errors and actual producer Evidence IDs when
|
||||
provided, including original `evidence_links`. The upstream ledger retains complete original Evidence for later views
|
||||
and exports. Non-Evidence session responses have no invented Evidence ID.
|
||||
Calls and executions sharing one active target are serialized; `Promise.all`
|
||||
currently provides composition rather than parallel provider execution.
|
||||
|
||||
`npm test` runs actual upstream and downstream stdio MCP against this checkout's
|
||||
compiled runtime. The standalone experiment's twelve tests cover discovery parity,
|
||||
original results/errors, bulk promise settlement, host capability absence, CPU
|
||||
deadline recovery, retained Evidence after an error or provider timeout,
|
||||
queued-call cancellation, unresolved promises and the
|
||||
two-tool downstream boundary, guest heap exhaustion/reuse, and SDK-converted
|
||||
schemas validated as [JSON Schema 2020-12](https://modelcontextprotocol.io/specification/2025-11-25/basic/index#schema-dialect).
|
||||
Execution rejects delays above Node's signed 32-bit timer range instead of
|
||||
allowing Node to coerce them to 1 ms. These tests do not establish real native/Android/
|
||||
firmware provider behavior. A lifecycle regression revealed that the QuickJS job
|
||||
pump can allocate an additional context: the execution scope now owns every
|
||||
context at creation and releases them before the runtime. Increasing memory did
|
||||
not fix that regression.
|
||||
|
||||
Install experimental dependencies separately with `npm ci` in this directory.
|
||||
They do not change the production package or lockfile. Use the repository's pinned
|
||||
Node and npm versions. No binary, provider database or raw third-party source is
|
||||
committed. Corpus identities and upstream download locations are in `corpus.json`.
|
||||
|
||||
Measure three baselines: normal full-catalog MCP, discovery-only MCP, and Code
|
||||
Mode. Count discovery, input code, intermediate results, final output, errors and
|
||||
retries. Report actual wall time separately from model-facing turns and local
|
||||
token estimates. Existing summary/page/workflow tools are fair alternatives;
|
||||
do not manufacture a gain by forcing full output on the direct-tool baseline.
|
||||
Replay measurements establish mechanism costs, not model task accuracy or
|
||||
inference latency. Real-agent trials must additionally verify supported facts,
|
||||
source identity, omissions and preserved Evidence references.
|
||||
|
||||
`benchmark.mjs` replays a fixed question against real providers with identical
|
||||
original arguments. For example:
|
||||
|
||||
```bash
|
||||
python3 resource-run.py -- node benchmark.mjs --artifact newpipe.apk \
|
||||
--mode bridge --artifact-root /absolute/path/artifacts \
|
||||
--providers /absolute/path/selected-provider-settings.json \
|
||||
--output /absolute/path/new-result-directory
|
||||
```
|
||||
|
||||
Modes are `direct`, `discovery` and `bridge`. The discovery mode isolates catalog
|
||||
cost while retaining original results; it is not a new production MCP client.
|
||||
Raw responses remain outside Git. Result summaries separate complete envelopes
|
||||
from single text content and count code explicitly. Measured findings and failures
|
||||
are recorded in [results.md](results.md).
|
||||
|
||||
`--artifact obsidian.asar --workflow obsidian-inventory` asks a distinct package
|
||||
inventory question using existing tools. It must not be compared as an equivalent
|
||||
completion of the JavaScript AST question. Workflow names and original arguments
|
||||
are retained in replay summaries.
|
||||
|
||||
`agent-trial.py` runs a real local Codex CLI with a disposable account/config and
|
||||
one MCP registration. It copies authentication only, removes the profile on normal
|
||||
completion, timeout and handled termination, and retains JSONL events, the answer
|
||||
and measured API usage outside the repo.
|
||||
It defaults to `gpt-5.6-terra` with high reasoning, as requested. Run one task under
|
||||
the resource wrapper:
|
||||
|
||||
```bash
|
||||
python3 resource-run.py -- python3 agent-trial.py \
|
||||
--mode direct --prompt /absolute/path/question.txt \
|
||||
--output /absolute/path/new-trial-directory
|
||||
```
|
||||
|
||||
Reproducible questions are in [questions/](questions/). Supply a template with
|
||||
`--prompt questions/android.txt --artifact-path /absolute/path/NewPipe_v0.29.1.apk`
|
||||
(or another matching corpus target). The runner preserves the supplied path in
|
||||
the rendered prompt and records template and rendered-prompt digests. Native's
|
||||
entry-address seed is derived from this corpus's jq header and is not reusable
|
||||
for another build. Run comparisons serially with the same question and provider
|
||||
settings; retain failures as well as successful repetitions.
|
||||
|
||||
Use `--mode bridge` for the experimental server; `--mode client-code` requests
|
||||
Codex's own Code Mode. Optional `--providers` selects a JSON object of explicit
|
||||
provider settings. No ambient environment snapshot is retained. A configured flag
|
||||
or a model's `tool_mode` does not prove the model actually composed tools or
|
||||
filtered an intermediate result. Inspect the transcript, and mark accuracy as
|
||||
unassessed until the requested facts and source support have been reviewed.
|
||||
`grade-trial.py` checks Android (default), managed, native, firmware or
|
||||
electron-inventory (`--task NAME`) against a successful
|
||||
real-provider replay and verifies cited IDs in producer values, their original
|
||||
Evidence links or the bridge audit. This verifies references observed in the
|
||||
transcript; the grader does not resolve every cited payload. It accepts
|
||||
JSON or one complete JSON fence, without repairing prose or partial values. This
|
||||
checks requested producer facts and reference existence, not runtime behavior or
|
||||
independent decompiler correctness. Unparseable result text is reported explicitly;
|
||||
IDs in a truncated JSON fragment cannot satisfy the automated reference check.
|
||||
The Android projection includes the provider's overload index, so a supported
|
||||
signature with that field omitted fails this stronger assertion.
|
||||
An omitted DEX descriptor differs from an explicit null, and booleans differ from
|
||||
numeric counts. Native containing-procedure reports compare resolved identity;
|
||||
the full analyzed procedure is verified separately.
|
||||
Firmware's run-local region UUIDs remain in answers but are excluded from parity
|
||||
against an independently acquired report. Classification evidence, explicit
|
||||
unknowns and coverage remain part of the requested fact checks.
|
||||
The question comparison accepts grouped original path records, extra known
|
||||
coverage counts and explicitly named firmware length/coverage report fields.
|
||||
Derived extent ends must agree with offset plus reported length. It verifies
|
||||
engine version and executable digest rather than display capitalization; a manual
|
||||
review is still needed for limitations and claims beyond these assertions.
|
||||
Grades record the grader source digest, and earlier strict grades are retained
|
||||
when the comparison changes. These are report parsers, not REA API aliases.
|
||||
|
||||
The completed serial cohort is in [agent-results.json](agent-results.json), with
|
||||
source/configuration fingerprints, measured API usage and sampled cgroup stats.
|
||||
The recommendation and migration boundaries are in [decision.md](decision.md).
|
||||
Raw transcripts and original replay replies remain outside Git.
|
||||
|
||||
The supplied feedback is a research lead. Its Ghidra timing claim also changed
|
||||
auto-analysis options, so it does not isolate Code Mode's effect. Relevant primary
|
||||
sources: [Cloudflare Code Mode](https://blog.cloudflare.com/code-mode/),
|
||||
[MCP patterns](https://developers.cloudflare.com/agents/model-context-protocol/codemode/),
|
||||
[Anthropic code execution](https://www.anthropic.com/engineering/code-execution-with-mcp),
|
||||
and [QuickJS WASM](https://github.com/justjake/quickjs-emscripten).
|
||||
|
||||
Run expensive commands with `python3 resource-run.py -- COMMAND ARGS...` on Linux
|
||||
with a user systemd manager. It uses a transient scope with one CPU, a 4 GiB hard
|
||||
memory ceiling, a 3 GiB early-stop threshold, no swap, and a task ceiling. It
|
||||
refuses to start when less than 8 GiB is available and stops if host available
|
||||
memory drops below 4 GiB. These limits protect the host; a resource abort is a
|
||||
failed measurement, never a successful benchmark. Also cap Node and Java heaps.
|
||||
The task ceiling is 192. The wrapper records observed memory/task events and
|
||||
stops a trial that touches the task limit. A limit event invalidates a measurement
|
||||
even when the application later returns successfully.
|
||||
@@ -1,995 +0,0 @@
|
||||
{
|
||||
"baseline_sha": "fb94d9dde0ccda83ae520ac6fb22b1d283562cf3",
|
||||
"scope": "real_cli_requested_fact_parity_and_observed_references_not_independent_runtime_truth",
|
||||
"runtime_source_commit": "22326e8199975f31d8b7c99aaf5fd64140fbe00e",
|
||||
"artifact_ids": "corpus.json",
|
||||
"resource_limits": {
|
||||
"cpu_affinity": [15],
|
||||
"cpu_quota_percent": 100,
|
||||
"hard_memory_bytes": 4294967296,
|
||||
"early_stop_bytes": 3221225472,
|
||||
"tasks_max": 192
|
||||
},
|
||||
"notes": [
|
||||
"Profiles differ in required mode-specific instructions; original model-selected arguments may differ.",
|
||||
"Two Android/managed repetitions are descriptive samples, without confidence intervals or a causal speed claim.",
|
||||
"Managed classification container omissions fail a stronger complete-object assertion; remaining requested facts match.",
|
||||
"Normal-MCP managed JSONL truncation leaves one ID unavailable to the complete-envelope reference parser.",
|
||||
"Uncached input is input minus cached input, not a currency cost estimate."
|
||||
],
|
||||
"trials": [
|
||||
{
|
||||
"trial": "android-direct-5",
|
||||
"task": "android",
|
||||
"mode": "direct",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 67.329,
|
||||
"input_tokens": 107007,
|
||||
"cached_input_tokens": 83712,
|
||||
"uncached_input_tokens": 23295,
|
||||
"output_tokens": 1670,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "3424dd6ba375f96d88fd0ac38102998948fa0fc46e08af8fae414572ba97a62f",
|
||||
"peak_memory_bytes_sampled": 1336168448,
|
||||
"peak_tasks_sampled": 108,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 23974584,
|
||||
"user_usec": 21485565,
|
||||
"system_usec": 2489019,
|
||||
"nr_periods": 636,
|
||||
"nr_throttled": 45,
|
||||
"throttled_usec": 67840,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "android-bridge-7",
|
||||
"task": "android",
|
||||
"mode": "bridge",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 48.231,
|
||||
"input_tokens": 113256,
|
||||
"cached_input_tokens": 91648,
|
||||
"uncached_input_tokens": 21608,
|
||||
"output_tokens": 1456,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "27e234285e493b50929c0f98938284771d0d4a3787045872f2f517b2297aefeb",
|
||||
"peak_memory_bytes_sampled": 1659629568,
|
||||
"peak_tasks_sampled": 126,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 27717810,
|
||||
"user_usec": 25042151,
|
||||
"system_usec": 2675658,
|
||||
"nr_periods": 458,
|
||||
"nr_throttled": 50,
|
||||
"throttled_usec": 73614,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-bridge-2",
|
||||
"task": "managed",
|
||||
"mode": "bridge",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 73.145,
|
||||
"input_tokens": 116974,
|
||||
"cached_input_tokens": 92672,
|
||||
"uncached_input_tokens": 24302,
|
||||
"output_tokens": 2065,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": ["classification"],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "06cbdda60ac930d00ade7e115cd4ba234527e297e6cfd931eedc175e00efa1c7",
|
||||
"peak_memory_bytes_sampled": 939290624,
|
||||
"peak_tasks_sampled": 103,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 12114716,
|
||||
"user_usec": 9701516,
|
||||
"system_usec": 2413200,
|
||||
"nr_periods": 630,
|
||||
"nr_throttled": 16,
|
||||
"throttled_usec": 15944,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-direct-2",
|
||||
"task": "managed",
|
||||
"mode": "direct",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 33.15,
|
||||
"input_tokens": 108096,
|
||||
"cached_input_tokens": 75776,
|
||||
"uncached_input_tokens": 32320,
|
||||
"output_tokens": 2315,
|
||||
"completed_mcp_calls": 2,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": false,
|
||||
"unreadable_result_texts": 1,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "5d6957541bd979252d019817e631f5d889ff2dc3efb7f03b9de1033fe34d8430",
|
||||
"peak_memory_bytes_sampled": 688373760,
|
||||
"peak_tasks_sampled": 108,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 5863642,
|
||||
"user_usec": 4359666,
|
||||
"system_usec": 1503976,
|
||||
"nr_periods": 282,
|
||||
"nr_throttled": 4,
|
||||
"throttled_usec": 6216,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-direct-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "direct",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 89.494,
|
||||
"input_tokens": 266121,
|
||||
"cached_input_tokens": 238848,
|
||||
"uncached_input_tokens": 27273,
|
||||
"output_tokens": 3215,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "22941dc5d77ce06824e40b01abd3f725aa773d131648d7bba2e607b410ccbef9",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "fcd0df1a3ae0b5103143addaa4922323354ddee7ba3d0e3020de64f05b6fe3d3",
|
||||
"peak_memory_bytes_sampled": 703275008,
|
||||
"peak_tasks_sampled": 115,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 7720494,
|
||||
"user_usec": 5691854,
|
||||
"system_usec": 2028640,
|
||||
"nr_periods": 782,
|
||||
"nr_throttled": 7,
|
||||
"throttled_usec": 15453,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-bridge-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "bridge",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 145.577,
|
||||
"input_tokens": 462809,
|
||||
"cached_input_tokens": 407040,
|
||||
"uncached_input_tokens": 55769,
|
||||
"output_tokens": 5624,
|
||||
"completed_mcp_calls": 8,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary",
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "22941dc5d77ce06824e40b01abd3f725aa773d131648d7bba2e607b410ccbef9",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "ab7e25e4345a0e9bba6a06bb0a79aa39e1bf1308b6a66f8173a62bbc9e2d9fc9",
|
||||
"peak_memory_bytes_sampled": 1029238784,
|
||||
"peak_tasks_sampled": 112,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 14650718,
|
||||
"user_usec": 12106416,
|
||||
"system_usec": 2544302,
|
||||
"nr_periods": 1224,
|
||||
"nr_throttled": 24,
|
||||
"throttled_usec": 30318,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "firmware-bridge-1",
|
||||
"task": "firmware",
|
||||
"mode": "bridge",
|
||||
"artifact": "openwrt.bin",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 81.944,
|
||||
"input_tokens": 152886,
|
||||
"cached_input_tokens": 126976,
|
||||
"uncached_input_tokens": 25910,
|
||||
"output_tokens": 2192,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": ["inspect_firmware_regions"],
|
||||
"fact_assertions": 5,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "93c94e26dc4a4b1985b3f8c4246ca5aff886f75dc2349a717ee940243dc73b80",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "a5604d0d3140f6232851a81a952e51daf43c8e7f12ba062fac68a8fae0bef708",
|
||||
"peak_memory_bytes_sampled": 927666176,
|
||||
"peak_tasks_sampled": 104,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 11575373,
|
||||
"user_usec": 9366624,
|
||||
"system_usec": 2208749,
|
||||
"nr_periods": 744,
|
||||
"nr_throttled": 18,
|
||||
"throttled_usec": 26000,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "firmware-direct-1",
|
||||
"task": "firmware",
|
||||
"mode": "direct",
|
||||
"artifact": "openwrt.bin",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 30.161,
|
||||
"input_tokens": 103224,
|
||||
"cached_input_tokens": 74752,
|
||||
"uncached_input_tokens": 28472,
|
||||
"output_tokens": 1761,
|
||||
"completed_mcp_calls": 1,
|
||||
"original_operations": ["inspect_firmware_regions"],
|
||||
"fact_assertions": 5,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "93c94e26dc4a4b1985b3f8c4246ca5aff886f75dc2349a717ee940243dc73b80",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "c0bbd1aec08c9c30061f92064355c3213f680fab545a050271096e85db771a71",
|
||||
"peak_memory_bytes_sampled": 686739456,
|
||||
"peak_tasks_sampled": 109,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 5700866,
|
||||
"user_usec": 4167696,
|
||||
"system_usec": 1533169,
|
||||
"nr_periods": 266,
|
||||
"nr_throttled": 6,
|
||||
"throttled_usec": 3978,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "native-direct-1",
|
||||
"task": "native",
|
||||
"mode": "direct",
|
||||
"artifact": "jq",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 327.15,
|
||||
"input_tokens": 151343,
|
||||
"cached_input_tokens": 122368,
|
||||
"uncached_input_tokens": 28975,
|
||||
"output_tokens": 2458,
|
||||
"completed_mcp_calls": 4,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"resolve_containing_procedure",
|
||||
"analyze_function",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "234bfe93d09f9c76c1a64383c11cf7c174eafa4e4ad563124f705a7d5c8920aa",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "681f38e4ba9b441e7816e868b30e347005fe074907349cd0022fc44302c5b14a",
|
||||
"peak_memory_bytes_sampled": 1328496640,
|
||||
"peak_tasks_sampled": 109,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 263737951,
|
||||
"user_usec": 256864795,
|
||||
"system_usec": 6873156,
|
||||
"nr_periods": 3192,
|
||||
"nr_throttled": 456,
|
||||
"throttled_usec": 756678,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "native-bridge-1",
|
||||
"task": "native",
|
||||
"mode": "bridge",
|
||||
"artifact": "jq",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 334.642,
|
||||
"input_tokens": 285961,
|
||||
"cached_input_tokens": 245504,
|
||||
"uncached_input_tokens": 40457,
|
||||
"output_tokens": 2129,
|
||||
"completed_mcp_calls": 4,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"analyze_function",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "234bfe93d09f9c76c1a64383c11cf7c174eafa4e4ad563124f705a7d5c8920aa",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "6c64953708df4a06b69fb57e5d70141147e4495adabd7340e87e727fcd340742",
|
||||
"peak_memory_bytes_sampled": 1441775616,
|
||||
"peak_tasks_sampled": 123,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 271095966,
|
||||
"user_usec": 263888347,
|
||||
"system_usec": 7207618,
|
||||
"nr_periods": 3267,
|
||||
"nr_throttled": 450,
|
||||
"throttled_usec": 784719,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "android-bridge-8",
|
||||
"task": "android",
|
||||
"mode": "bridge",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 134.555,
|
||||
"input_tokens": 159370,
|
||||
"cached_input_tokens": 134400,
|
||||
"uncached_input_tokens": 24970,
|
||||
"output_tokens": 3250,
|
||||
"completed_mcp_calls": 7,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class",
|
||||
"inspect_android_package",
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "f1743a341d334bd41760b54980aa70d5f3c8c1aed57c3ae9e470be63449c594d",
|
||||
"peak_memory_bytes_sampled": 1659744256,
|
||||
"peak_tasks_sampled": 115,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 29619173,
|
||||
"user_usec": 26495167,
|
||||
"system_usec": 3124005,
|
||||
"nr_periods": 1229,
|
||||
"nr_throttled": 60,
|
||||
"throttled_usec": 84762,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "android-direct-6",
|
||||
"task": "android",
|
||||
"mode": "direct",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 71.624,
|
||||
"input_tokens": 153031,
|
||||
"cached_input_tokens": 117504,
|
||||
"uncached_input_tokens": 35527,
|
||||
"output_tokens": 1501,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "b8d0422eec6bfd31a9a6ed79ac29e9487c2e68c47ff200904ec239daee9720c3",
|
||||
"peak_memory_bytes_sampled": 1348767744,
|
||||
"peak_tasks_sampled": 115,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 23033331,
|
||||
"user_usec": 20566262,
|
||||
"system_usec": 2467069,
|
||||
"nr_periods": 674,
|
||||
"nr_throttled": 40,
|
||||
"throttled_usec": 61573,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-direct-3",
|
||||
"task": "managed",
|
||||
"mode": "direct",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 75.229,
|
||||
"input_tokens": 108593,
|
||||
"cached_input_tokens": 75776,
|
||||
"uncached_input_tokens": 32817,
|
||||
"output_tokens": 2774,
|
||||
"completed_mcp_calls": 2,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": false,
|
||||
"unreadable_result_texts": 1,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "64f0769b7ad83f8d86c005a48de7a0cf397043d77378983fabfaa226dcb70f87",
|
||||
"peak_memory_bytes_sampled": 651026432,
|
||||
"peak_tasks_sampled": 110,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 6252846,
|
||||
"user_usec": 4688766,
|
||||
"system_usec": 1564079,
|
||||
"nr_periods": 635,
|
||||
"nr_throttled": 7,
|
||||
"throttled_usec": 11469,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-bridge-3",
|
||||
"task": "managed",
|
||||
"mode": "bridge",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 40.609,
|
||||
"input_tokens": 125519,
|
||||
"cached_input_tokens": 96000,
|
||||
"uncached_input_tokens": 29519,
|
||||
"output_tokens": 2274,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": ["classification"],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "5fbc3cf0b41224f2ef44ab996b174c8a48fe07a818ac2ad334ef59e5ddf26de6",
|
||||
"peak_memory_bytes_sampled": 1005625344,
|
||||
"peak_tasks_sampled": 113,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 11185145,
|
||||
"user_usec": 9300437,
|
||||
"system_usec": 1884707,
|
||||
"nr_periods": 366,
|
||||
"nr_throttled": 21,
|
||||
"throttled_usec": 24147,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-guided-bridge-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "bridge",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 85.909,
|
||||
"input_tokens": 101994,
|
||||
"cached_input_tokens": 61440,
|
||||
"uncached_input_tokens": 40554,
|
||||
"output_tokens": 2563,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "f070cdf721805d590c1bd5255ecf1f647ea165885cd5052af35c30ba531da815",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "566391b8a6db73228fec00dc7cbf0eaf56ed899178a405d5d8f0c8002fb05d89",
|
||||
"peak_memory_bytes_sampled": 1007996928,
|
||||
"peak_tasks_sampled": 109,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 13304542,
|
||||
"user_usec": 10842042,
|
||||
"system_usec": 2462499,
|
||||
"nr_periods": 787,
|
||||
"nr_throttled": 19,
|
||||
"throttled_usec": 27407,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-guided-direct-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "direct",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 67.54,
|
||||
"input_tokens": 263484,
|
||||
"cached_input_tokens": 221952,
|
||||
"uncached_input_tokens": 41532,
|
||||
"output_tokens": 2499,
|
||||
"completed_mcp_calls": 4,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "f070cdf721805d590c1bd5255ecf1f647ea165885cd5052af35c30ba531da815",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "564711cf28211bb7059a04b919f1b6925a816ded3e2dbeb9678382568f700e58",
|
||||
"peak_memory_bytes_sampled": 728817664,
|
||||
"peak_tasks_sampled": 114,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 8708686,
|
||||
"user_usec": 6609914,
|
||||
"system_usec": 2098771,
|
||||
"nr_periods": 597,
|
||||
"nr_throttled": 12,
|
||||
"throttled_usec": 19564,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
"""Evaluate one real Codex CLI task with an isolated REA MCP registration."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--mode', choices=['direct', 'client-code', 'bridge'], required=True)
|
||||
parser.add_argument('--prompt', type=Path, required=True)
|
||||
parser.add_argument('--artifact-path', help='Replace {{artifact_path}} in a question template')
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
parser.add_argument('--model', default='gpt-5.6-terra')
|
||||
parser.add_argument('--reasoning', default='high')
|
||||
parser.add_argument('--timeout', type=int, default=900)
|
||||
parser.add_argument('--codex', default='/usr/bin/codex')
|
||||
parser.add_argument('--providers', type=Path)
|
||||
args = parser.parse_args()
|
||||
def terminate(signum, _frame):
|
||||
# The outer resource scope terminates descendants together. Ensure the
|
||||
# runner's copied credentials are also removed on a resource abort.
|
||||
raise SystemExit(128 + signum)
|
||||
signal.signal(signal.SIGTERM, terminate)
|
||||
repository = Path(__file__).resolve().parents[2]
|
||||
experiment = Path(__file__).resolve().parent
|
||||
node = shutil.which('node')
|
||||
if subprocess.check_output([node, '--version'], text=True).strip() != 'v24.18.0':
|
||||
raise SystemExit('Use pinned Node 24.18.0 on PATH')
|
||||
args.output.mkdir(parents=True, exist_ok=False, mode=0o700)
|
||||
profile = Path(tempfile.mkdtemp(prefix='profile-', dir=args.output))
|
||||
trial_codex_home = profile / 'codex'
|
||||
account = profile / 'account'
|
||||
workspace = profile / 'workspace'
|
||||
for directory in [trial_codex_home, account, workspace]:
|
||||
directory.mkdir(mode=0o700)
|
||||
source_auth = Path(os.environ.get('CODEX_HOME', str(Path.home() / '.codex'))) / 'auth.json'
|
||||
auth = trial_codex_home / 'auth.json'
|
||||
started = time.monotonic()
|
||||
timeout = False
|
||||
exit_code = None
|
||||
environment = dict(os.environ)
|
||||
environment.update({
|
||||
'CODEX_HOME': str(trial_codex_home), 'HOME': str(account),
|
||||
'XDG_CONFIG_HOME': str(account / '.config'),
|
||||
'XDG_CACHE_HOME': str(account / '.cache'),
|
||||
'XDG_DATA_HOME': str(account / '.local/share'),
|
||||
'NODE_OPTIONS': '--max-old-space-size=512',
|
||||
})
|
||||
provider_env = {'REA_LOG_LEVEL': 'silent', 'NODE_OPTIONS': '--max-old-space-size=512'}
|
||||
if args.providers:
|
||||
# This explicit caller file supplies only selected provider settings.
|
||||
provider_env.update(json.loads(args.providers.read_text()))
|
||||
command_args = [str(repository / 'scripts/rea.mjs'), 'mcp']
|
||||
if args.mode == 'bridge':
|
||||
command_args = [str(experiment / 'bridge.mjs'), node, *command_args]
|
||||
instruction = (
|
||||
'Use the registered REA MCP server for this investigation. Static analysis '
|
||||
'only: do not execute target code, fetch URLs, launch a GUI, or modify targets. '
|
||||
'Preserve observations, derivations, inferences, limitations, and real Evidence IDs. '
|
||||
'An Evidence value has evidence_id, normalized_result and limitations; '
|
||||
'non-Evidence session values have result. '
|
||||
'The analyzed target digest is Evidence.subject.digest.sha256. '
|
||||
'normalized_result.engine.artifact_sha256 identifies the analysis engine '
|
||||
'artifact and must never be substituted for the target digest. '
|
||||
'Prefer summary/focused views where appropriate. Do not invent successful facts '
|
||||
'after a tool error. No other agents. Stop once the requested facts are supported.'
|
||||
)
|
||||
if args.mode == 'bridge':
|
||||
instruction += (
|
||||
' Original REA operations are available through rea_search and rea_execute. '
|
||||
'Discover tool names/schemas on demand. Execute JavaScript bodies using '
|
||||
'tools.<original_name>(original_arguments), json(reply) to parse the original '
|
||||
'MCP result, and return only the needed facts plus their Evidence IDs and '
|
||||
'limitations. Compose known dependent calls in one script when useful. '
|
||||
'Select needed fields from normalized_result inside the script; do not '
|
||||
'return entire Evidence, raw_result or full method/class inventories when '
|
||||
'the question requests a subset. '
|
||||
'Await every call; the upstream session persists across scripts.'
|
||||
)
|
||||
if args.mode == 'client-code':
|
||||
instruction += (
|
||||
' Use the client JavaScript executor to compose registered MCP calls when '
|
||||
'possible and select the requested normalized_result fields before returning '
|
||||
'intermediate output to model context. Keep real Evidence IDs and limitations.'
|
||||
)
|
||||
quote = json.dumps
|
||||
config = '\n'.join([
|
||||
'approval_policy = "never"', 'sandbox_mode = "read-only"',
|
||||
'web_search = "disabled"', 'model = ' + quote(args.model),
|
||||
'model_reasoning_effort = ' + quote(args.reasoning),
|
||||
'developer_instructions = ' + quote(instruction),
|
||||
'[features]', 'multi_agent = false', 'shell_snapshot = false',
|
||||
'shell_tool = false', 'unified_exec = false',
|
||||
'code_mode = ' + ('true' if args.mode == 'client-code' else 'false'),
|
||||
'code_mode_only = ' + ('true' if args.mode == 'client-code' else 'false'),
|
||||
'[history]', 'persistence = "none"',
|
||||
'[mcp_servers.rea]', 'command = ' + quote(node),
|
||||
'args = ' + quote(command_args), 'startup_timeout_sec = 60',
|
||||
'tool_timeout_sec = 600', '[mcp_servers.rea.env]',
|
||||
*[key + ' = ' + quote(value) for key, value in provider_env.items()],
|
||||
'[mcp_servers.rea.tools.rea_execute]', 'approval_mode = "approve"',
|
||||
]) + '\n'
|
||||
# MCP read-only hints cover normal static tools. Explicitly authorize only
|
||||
# the session-opening primitive needed by the requested native tasks.
|
||||
config += '[mcp_servers.rea.tools.open_binary]\napproval_mode = "approve"\n'
|
||||
for tool in ['analyze_javascript_application', 'inspect_analysis_view',
|
||||
'inspect_android_package', 'search_android_classes',
|
||||
'inspect_android_class', 'inspect_android_method',
|
||||
'inspect_firmware_regions', 'inspect_managed_artifact',
|
||||
'inspect_managed_members', 'inspect_managed_native_boundaries',
|
||||
'inspect_artifact', 'inspect_wasm_artifact',
|
||||
'resolve_containing_procedure', 'analyze_function', 'close_binary']:
|
||||
config += '[mcp_servers.rea.tools.' + tool + ']\napproval_mode = "approve"\n'
|
||||
try:
|
||||
if source_auth.exists():
|
||||
shutil.copyfile(source_auth, auth)
|
||||
auth.chmod(0o600)
|
||||
(trial_codex_home / 'config.toml').write_text(config)
|
||||
(trial_codex_home / 'config.toml').chmod(0o600)
|
||||
prompt = args.prompt.read_text()
|
||||
template_digest = hashlib.sha256(prompt.encode()).hexdigest()
|
||||
if '{{artifact_path}}' in prompt:
|
||||
if not args.artifact_path or not os.path.isabs(args.artifact_path):
|
||||
raise ValueError('A question template requires an absolute --artifact-path')
|
||||
prompt = prompt.replace('{{artifact_path}}', args.artifact_path)
|
||||
elif args.artifact_path:
|
||||
raise ValueError('--artifact-path requires the literal template marker')
|
||||
(args.output / 'prompt.txt').write_text(prompt)
|
||||
(args.output / 'trial-settings.json').write_text(json.dumps({
|
||||
'mode': args.mode, 'model': args.model, 'reasoning': args.reasoning,
|
||||
'experiment_commit': subprocess.check_output(
|
||||
['git', 'rev-parse', 'HEAD'], cwd=repository, text=True).strip(),
|
||||
'experiment_sources_sha256': {
|
||||
name: hashlib.sha256((experiment / name).read_bytes()).hexdigest()
|
||||
for name in ['agent-trial.py', 'bridge.mjs', 'package-lock.json']
|
||||
},
|
||||
'developer_instructions': instruction,
|
||||
'developer_instructions_sha256': hashlib.sha256(instruction.encode()).hexdigest(),
|
||||
'prompt_sha256': hashlib.sha256(prompt.encode()).hexdigest(),
|
||||
'question_template_sha256': template_digest,
|
||||
'provider_settings_sha256': hashlib.sha256(
|
||||
json.dumps(provider_env, sort_keys=True).encode()).hexdigest(),
|
||||
'features': {'shell_tool': False, 'unified_exec': False,
|
||||
'multi_agent': False, 'code_mode': args.mode == 'client-code',
|
||||
'code_mode_only': args.mode == 'client-code'},
|
||||
}, indent=2) + '\n')
|
||||
invocation = [args.codex, '--no-daemon', 'exec', '--ephemeral',
|
||||
'--skip-git-repo-check', '--ignore-rules', '--json',
|
||||
'--color', 'never', '-C', str(workspace),
|
||||
'--output-last-message', str(args.output.resolve() / 'answer.txt'), '-']
|
||||
with (args.output / 'events.jsonl').open('w') as events, (args.output / 'stderr.log').open('w') as errors:
|
||||
child = subprocess.Popen(invocation, env=environment, cwd=workspace,
|
||||
stdin=subprocess.PIPE, stdout=events, stderr=errors, text=True)
|
||||
child.stdin.write(prompt)
|
||||
child.stdin.close()
|
||||
try:
|
||||
exit_code = child.wait(timeout=args.timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
timeout = True
|
||||
child.terminate()
|
||||
try:
|
||||
exit_code = child.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
child.kill()
|
||||
exit_code = child.wait()
|
||||
usage = []
|
||||
tools = []
|
||||
event_types = {}
|
||||
for line in (args.output / 'events.jsonl').read_text().splitlines():
|
||||
event = json.loads(line)
|
||||
kind = event.get('type', 'unknown')
|
||||
event_types[kind] = event_types.get(kind, 0) + 1
|
||||
if 'usage' in event:
|
||||
usage.append(event['usage'])
|
||||
item = event.get('item', {})
|
||||
if item.get('type') == 'mcp_tool_call' and kind == 'item.completed':
|
||||
tools.append({k: item.get(k) for k in ['server', 'tool', 'arguments', 'status', 'error']})
|
||||
summary = {
|
||||
'mode': args.mode, 'requested_model': args.model, 'reasoning': args.reasoning,
|
||||
'baseline_sha': 'fb94d9dde0ccda83ae520ac6fb22b1d283562cf3',
|
||||
'codex_version': subprocess.check_output([args.codex, '--version'], text=True).strip(),
|
||||
'exit_code': exit_code, 'timeout': timeout,
|
||||
'wall_seconds': round(time.monotonic() - started, 3),
|
||||
'usage': usage, 'completed_mcp_calls': tools, 'event_types': event_types,
|
||||
'factual_correctness': 'not_assessed',
|
||||
'scope': 'real_cli_trial_requires_transcript_and_fact_review',
|
||||
}
|
||||
(args.output / 'summary.json').write_text(json.dumps(summary, indent=2) + '\n')
|
||||
print(json.dumps(summary))
|
||||
finally:
|
||||
# Always remove copied credentials, config, caches and profile state.
|
||||
shutil.rmtree(profile)
|
||||
raise SystemExit(124 if timeout else exit_code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,369 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { parseArgs } from "node:util";
|
||||
import { getEncoding } from "js-tiktoken";
|
||||
import { CodeModeBridge, connectUpstream, json } from "./bridge.mjs";
|
||||
|
||||
// Replay isolates transport/discovery costs. It does not simulate model reasoning.
|
||||
const workflows = {
|
||||
"sharex.dll": {
|
||||
tools: ["inspect_managed_artifact", "inspect_managed_native_boundaries"],
|
||||
question:
|
||||
"Report assembly/module identity, target framework and declared P/Invoke libraries with their uncertainty.",
|
||||
code: `
|
||||
const artifact = await call("inspect_managed_artifact", {path: input.path});
|
||||
const boundaries = await call("inspect_managed_native_boundaries", {});
|
||||
const n = artifact.normalized_result;
|
||||
return {artifact_sha256: artifact.subject?.digest.sha256,
|
||||
classification: n.classification, assembly: n.assembly, module: n.module,
|
||||
target_frameworks: n.target_frameworks, coverage: n.coverage,
|
||||
native_boundaries: boundaries.normalized_result,
|
||||
evidence_ids: [artifact.evidence_id, boundaries.evidence_id],
|
||||
limitations: [...artifact.limitations, ...boundaries.limitations]};`,
|
||||
},
|
||||
"sqlite.wasm": {
|
||||
tools: ["inspect_wasm_artifact"],
|
||||
question:
|
||||
"Report exact WASM validation, all exported names and runtime/network observation states without executing it.",
|
||||
code: `
|
||||
const wasm = await call("inspect_wasm_artifact", {path: input.path});
|
||||
const n = wasm.normalized_result;
|
||||
return {artifact_sha256: wasm.subject?.digest.sha256,
|
||||
validation: n.validation, sections: n.sections, exports: n.exports,
|
||||
runtime_execution: n.runtime_execution, network_fetch: n.network_fetch,
|
||||
evidence_ids: [wasm.evidence_id], limitations: [...wasm.limitations, ...n.limitations]};`,
|
||||
},
|
||||
"obsidian.asar": {
|
||||
tools: ["analyze_javascript_application", "inspect_analysis_view"],
|
||||
question:
|
||||
"Report application identity, analysis coverage/counts and the first eight module identities.",
|
||||
code: `
|
||||
const summary = await call("analyze_javascript_application", {
|
||||
input_path: input.path, detail: "summary", max_heap_mb: 1024,
|
||||
analysis_timeout_ms: 300000, integrity_policy: "fail"
|
||||
});
|
||||
const parent = summary.normalized_result.parent_evidence_id;
|
||||
const page = await call("inspect_analysis_view", {
|
||||
source: {kind: "retained-evidence", evidence_id: parent},
|
||||
view: {kind: "page", collection: "modules", offset: 0, limit: 8}
|
||||
});
|
||||
return {artifact_sha256: summary.subject?.digest.sha256,
|
||||
summary: summary.normalized_result, modules: page.normalized_result,
|
||||
evidence_ids: [summary.evidence_id, parent, page.evidence_id],
|
||||
limitations: [...summary.limitations, ...page.limitations]};`,
|
||||
},
|
||||
"obsidian-inventory": {
|
||||
artifact: "obsidian.asar",
|
||||
tools: ["open_binary", "inspect_artifact", "close_binary"],
|
||||
question:
|
||||
"Report ASAR identity, complete inventory manifest, entry-kind counts, root package/main/preload occurrences, integrity contradictions and inventory coverage; do not claim AST or runtime analysis.",
|
||||
code: `
|
||||
await call("open_binary", {path: input.path});
|
||||
try {
|
||||
const inspected = await call("inspect_artifact", {integrity_policy: "fail"});
|
||||
const n = inspected.normalized_result;
|
||||
const inventory = n.substeps.find(x => x.operation === "inventory_artifact").evidence;
|
||||
const graph = inventory.normalized_result;
|
||||
const counts = {};
|
||||
for (const row of graph.occurrences)
|
||||
counts[row.entry_kind] = (counts[row.entry_kind] ?? 0) + 1;
|
||||
return {artifact_sha256: inspected.subject.digest.sha256,
|
||||
manifest: graph.manifest, entry_kind_counts: counts,
|
||||
requested_paths: graph.occurrences.filter(x => ["package.json", "main.js", "preload.js"].includes(x.logical_path)),
|
||||
integrity_contradictions: graph.integrity_contradictions,
|
||||
coverage: n.coverage, unexplored_branches: n.unexplored_branches,
|
||||
evidence_ids: [inspected.evidence_id, inventory.evidence_id],
|
||||
limitations: [...inspected.limitations, ...n.limitations, ...inventory.limitations]};
|
||||
} finally { await call("close_binary", {}); }`,
|
||||
},
|
||||
"newpipe.apk": {
|
||||
tools: [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class",
|
||||
],
|
||||
question:
|
||||
"Report package/version, exact MainActivity matches and its onCreate method descriptors.",
|
||||
code: `
|
||||
const pkg = await call("inspect_android_package", {path: input.path});
|
||||
const found = await call("search_android_classes", {path: input.path, query: "MainActivity"});
|
||||
if (!found.normalized_result.matches.includes("org.schabi.newpipe.MainActivity"))
|
||||
throw new Error("Requested shipped MainActivity was not found");
|
||||
const cls = await call("inspect_android_class", {
|
||||
path: input.path, class_name: "org.schabi.newpipe.MainActivity"
|
||||
});
|
||||
return {artifact_sha256: pkg.subject?.digest.sha256,
|
||||
package_name: pkg.normalized_result.package_name,
|
||||
version_name: pkg.normalized_result.version_name,
|
||||
version_code: pkg.normalized_result.version_code,
|
||||
matches: found.normalized_result.matches, coverage: found.normalized_result.coverage,
|
||||
onCreate: cls.normalized_result.methods.filter(x => x.name === "onCreate"),
|
||||
evidence_ids: [pkg.evidence_id, found.evidence_id, cls.evidence_id],
|
||||
limitations: [...pkg.limitations, ...found.limitations, ...cls.limitations]};`,
|
||||
},
|
||||
"openwrt.bin": {
|
||||
tools: ["inspect_firmware_regions"],
|
||||
question:
|
||||
"Report firmware identity, every reported region offset/signature and examined coverage.",
|
||||
code: `
|
||||
const inspected = await call("inspect_firmware_regions", {path: input.path});
|
||||
return {artifact_sha256: inspected.subject?.digest.sha256,
|
||||
result: inspected.normalized_result, evidence_ids: [inspected.evidence_id],
|
||||
limitations: inspected.limitations};`,
|
||||
},
|
||||
jq: {
|
||||
tools: [
|
||||
"open_binary",
|
||||
"resolve_containing_procedure",
|
||||
"analyze_function",
|
||||
"close_binary",
|
||||
],
|
||||
question:
|
||||
"Resolve the observed ELF entry address and report the recovered function's first 512 pseudocode units and caller/callee counts.",
|
||||
code: `
|
||||
await call("open_binary", {path: input.path, provider_id: "ghidra"});
|
||||
try {
|
||||
const found = await call("resolve_containing_procedure", {address: input.entry_address});
|
||||
const fn = await call("analyze_function", {procedure: input.entry_address});
|
||||
const n = fn.normalized_result;
|
||||
return {artifact_sha256: fn.subject?.digest.sha256,
|
||||
entry_address: input.entry_address, containing_procedure: found.normalized_result, procedure: n.procedure,
|
||||
pseudocode_prefix: n.pseudocode.slice(0, 512),
|
||||
caller_count: n.callers.length, callee_count: n.callees.length,
|
||||
evidence_ids: [found.evidence_id, fn.evidence_id],
|
||||
limitations: [...found.limitations, ...fn.limitations, ...n.limitations]};
|
||||
} finally { await call("close_binary", {}); }`,
|
||||
},
|
||||
};
|
||||
|
||||
const { values } = parseArgs({
|
||||
options: {
|
||||
artifact: { type: "string" },
|
||||
workflow: { type: "string" },
|
||||
mode: { type: "string", default: "direct" },
|
||||
"artifact-root": { type: "string" },
|
||||
providers: { type: "string" },
|
||||
output: { type: "string" },
|
||||
},
|
||||
});
|
||||
if (
|
||||
!workflows[values.workflow ?? values.artifact] ||
|
||||
!["direct", "discovery", "bridge"].includes(values.mode) ||
|
||||
!values["artifact-root"] ||
|
||||
!values.output
|
||||
)
|
||||
throw new Error(
|
||||
"Use --artifact ID [--workflow NAME] --mode direct|discovery|bridge --artifact-root ABS --output NEW_DIR [--providers JSON]",
|
||||
);
|
||||
const experiment = dirname(fileURLToPath(import.meta.url));
|
||||
const repository = resolve(experiment, "../..");
|
||||
const corpus = JSON.parse(
|
||||
await readFile(resolve(experiment, "corpus.json"), "utf8"),
|
||||
);
|
||||
const artifact = corpus.artifacts.find((x) => x.id === values.artifact);
|
||||
const workflowName = values.workflow ?? values.artifact;
|
||||
const workflow = workflows[workflowName];
|
||||
if (!artifact || artifact.id !== (workflow.artifact ?? workflowName))
|
||||
throw new Error(
|
||||
"Selected workflow does not match the frozen corpus artifact",
|
||||
);
|
||||
const artifactPath = resolve(values["artifact-root"], artifact.file);
|
||||
const bytes = await readFile(artifactPath);
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
if (sha256 !== artifact.sha256 || bytes.length !== artifact.bytes)
|
||||
throw new Error("Artifact identity differs from frozen corpus");
|
||||
await mkdir(values.output, { recursive: false, mode: 0o700 });
|
||||
const encoding = getEncoding("cl100k_base");
|
||||
const measure = (value) => {
|
||||
const text = typeof value === "string" ? value : JSON.stringify(value);
|
||||
return {
|
||||
bytes: Buffer.byteLength(text),
|
||||
cl100k_estimated_tokens: encoding.encode(text).length,
|
||||
};
|
||||
};
|
||||
const modelText = (reply) =>
|
||||
reply.content
|
||||
.filter((item) => item.type === "text")
|
||||
.map((item) => item.text)
|
||||
.join("\n");
|
||||
const environment = values.providers
|
||||
? JSON.parse(await readFile(values.providers, "utf8"))
|
||||
: {};
|
||||
const started = performance.now();
|
||||
const upstream = await connectUpstream({
|
||||
command: process.execPath,
|
||||
args: [resolve(repository, "scripts/rea.mjs"), "mcp"],
|
||||
env: environment,
|
||||
});
|
||||
const connected = performance.now();
|
||||
const records = [];
|
||||
const realCall = upstream.call;
|
||||
upstream.call = async (name, args, options) => {
|
||||
const began = performance.now();
|
||||
try {
|
||||
const reply = await realCall(name, args, { timeout: 600_000, ...options });
|
||||
const parsed = json(reply);
|
||||
records.push({
|
||||
name,
|
||||
arguments: args,
|
||||
elapsed_ms: performance.now() - began,
|
||||
is_error: reply.isError === true,
|
||||
input: measure(args),
|
||||
output: measure(reply),
|
||||
text_output: measure(modelText(reply)),
|
||||
evidence_id: parsed.evidence_id,
|
||||
reply,
|
||||
});
|
||||
return reply;
|
||||
} catch (error) {
|
||||
records.push({
|
||||
name,
|
||||
arguments: args,
|
||||
elapsed_ms: performance.now() - began,
|
||||
failure: String(error),
|
||||
input: measure(args),
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
const bridge = new CodeModeBridge(upstream);
|
||||
const input = { path: artifactPath };
|
||||
if (artifact.id === "jq") {
|
||||
if (bytes.subarray(0, 6).toString("hex") !== "7f454c460201")
|
||||
throw new Error("Expected ELF64 little-endian header for entry seed");
|
||||
input.entry_address = `0x${bytes.readBigUInt64LE(24).toString(16)}`;
|
||||
}
|
||||
const code = `const input = ${JSON.stringify(input)};
|
||||
async function call(name, args) {
|
||||
const reply = await tools[name](args);
|
||||
const parsed = json(reply);
|
||||
if (reply.isError) throw new Error(JSON.stringify(parsed));
|
||||
return parsed;
|
||||
}
|
||||
${workflow.code}`;
|
||||
let discovery;
|
||||
let value;
|
||||
let failure;
|
||||
let bridgeReply;
|
||||
const recovery = [];
|
||||
const operationStarted = performance.now();
|
||||
try {
|
||||
if (values.mode !== "direct")
|
||||
discovery = await bridge.search({ names: workflow.tools });
|
||||
if (values.mode === "bridge") {
|
||||
bridgeReply = await bridge.execute({ code, timeout_ms: 900_000 });
|
||||
value = bridgeReply.value;
|
||||
failure = bridgeReply.bridge_error;
|
||||
} else {
|
||||
const tools = Object.fromEntries(
|
||||
upstream.catalog.map((tool) => [
|
||||
tool.name,
|
||||
(args) => upstream.call(tool.name, args),
|
||||
]),
|
||||
);
|
||||
const AsyncFunction = Object.getPrototypeOf(
|
||||
async function () {},
|
||||
).constructor;
|
||||
value = await new AsyncFunction("tools", "json", code)(tools, json);
|
||||
}
|
||||
} catch (error) {
|
||||
failure = String(error);
|
||||
} finally {
|
||||
const partials = new Set(
|
||||
records.flatMap((record) => {
|
||||
if (!record.reply?.isError) return [];
|
||||
try {
|
||||
const partial = json(record.reply).error?.details?.partial_observation;
|
||||
return partial?.kind === "retained-evidence"
|
||||
? [partial.evidence_id]
|
||||
: [];
|
||||
} catch {
|
||||
return []; // Preserve non-JSON failures in calls.json, without inventing IDs.
|
||||
}
|
||||
}),
|
||||
);
|
||||
for (const evidence_id of partials) {
|
||||
// Capture already retained partial facts before disposing the replay session.
|
||||
// Recovery is not a successful completion of the failed analyst workflow.
|
||||
try {
|
||||
const reply = await realCall(
|
||||
"inspect_analysis_view",
|
||||
{
|
||||
source: { kind: "retained-evidence", evidence_id },
|
||||
view: { kind: "summary" },
|
||||
},
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
recovery.push({ parent_evidence_id: evidence_id, reply });
|
||||
} catch (error) {
|
||||
recovery.push({
|
||||
parent_evidence_id: evidence_id,
|
||||
failure: String(error),
|
||||
});
|
||||
}
|
||||
}
|
||||
await upstream.close();
|
||||
}
|
||||
const catalogExposure = values.mode === "direct" ? upstream.catalog : discovery;
|
||||
const summary = {
|
||||
scope: "deterministic_real_provider_replay_not_model_accuracy",
|
||||
baseline_sha: "fb94d9dde0ccda83ae520ac6fb22b1d283562cf3",
|
||||
artifact: artifact.id,
|
||||
workflow: workflowName,
|
||||
artifact_sha256: sha256,
|
||||
mode: values.mode,
|
||||
question: workflow.question,
|
||||
startup_ms: connected - started,
|
||||
operation_ms: performance.now() - operationStarted,
|
||||
original_calls: records.map(({ reply: _reply, ...metadata }) => metadata),
|
||||
exposed_catalog: catalogExposure ? measure(catalogExposure) : null,
|
||||
direct_input_definitions: measure(
|
||||
upstream.catalog.map((tool) => ({
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
inputSchema: tool.inputSchema,
|
||||
})),
|
||||
),
|
||||
execution_code: values.mode === "bridge" ? measure(code) : null,
|
||||
exposed_tool_results:
|
||||
values.mode === "bridge"
|
||||
? [measure(bridgeReply)]
|
||||
: records.filter((x) => x.output).map((x) => x.output),
|
||||
exposed_text_results:
|
||||
values.mode === "bridge"
|
||||
? [measure(bridgeReply)]
|
||||
: records.filter((x) => x.text_output).map((x) => x.text_output),
|
||||
projection: value,
|
||||
failure: failure ?? null,
|
||||
partial_recovery: recovery,
|
||||
correctness: failure
|
||||
? "failed_workflow"
|
||||
: "requires_cross_profile_fact_review",
|
||||
estimator:
|
||||
"cl100k_base_compact_MCP_JSON_including_envelope_not_actual_model_tokens",
|
||||
};
|
||||
await writeFile(
|
||||
resolve(values.output, "summary.json"),
|
||||
JSON.stringify(summary, null, 2),
|
||||
);
|
||||
await writeFile(resolve(values.output, "calls.json"), JSON.stringify(records));
|
||||
await writeFile(resolve(values.output, "code.js"), code);
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
artifact: artifact.id,
|
||||
mode: values.mode,
|
||||
calls: records.length,
|
||||
startup_ms: summary.startup_ms,
|
||||
operation_ms: summary.operation_ms,
|
||||
failure: summary.failure
|
||||
? String(
|
||||
typeof summary.failure === "object"
|
||||
? summary.failure.message
|
||||
: summary.failure,
|
||||
).slice(0, 1000)
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
if (failure) process.exitCode = 1;
|
||||
@@ -1,426 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
||||
import { compile } from "json-schema-to-typescript";
|
||||
import { newQuickJSWASMModule, Scope } from "quickjs-emscripten";
|
||||
import { z } from "zod";
|
||||
|
||||
// Node maps larger delays to 1 ms. Reject them before creating a timer.
|
||||
const executeInputSchema = z.strictObject({
|
||||
code: z.string(),
|
||||
timeout_ms: z.number().int().positive().max(2_147_483_647).optional(),
|
||||
memory_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.positive()
|
||||
.max(128 * 1024 * 1024)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const digest = (value) =>
|
||||
createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
||||
|
||||
export const json = (reply) => {
|
||||
if (reply.structuredContent !== undefined) return reply.structuredContent;
|
||||
const texts = reply.content.filter((item) => item.type === "text");
|
||||
if (texts.length !== 1) throw new Error("Expected one REA JSON text block");
|
||||
return JSON.parse(texts[0].text);
|
||||
};
|
||||
|
||||
/** One upstream session, original tool names, complete live catalog. */
|
||||
export async function connectUpstream({
|
||||
command,
|
||||
args,
|
||||
env,
|
||||
stderr = "inherit",
|
||||
}) {
|
||||
const transport = new StdioClientTransport({ command, args, env, stderr });
|
||||
const client = new Client({
|
||||
name: "rea-codemode-experiment",
|
||||
version: "0.0.0",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport, { timeout: 60_000 });
|
||||
const catalog = [];
|
||||
let cursor;
|
||||
do {
|
||||
const page = await client.listTools(cursor ? { cursor } : undefined);
|
||||
catalog.push(...page.tools);
|
||||
cursor = page.nextCursor;
|
||||
} while (cursor !== undefined);
|
||||
if (new Set(catalog.map((tool) => tool.name)).size !== catalog.length)
|
||||
throw new Error("Duplicate upstream tool names");
|
||||
return {
|
||||
client,
|
||||
catalog,
|
||||
call: (name, args, options) =>
|
||||
client.callTool({ name, arguments: args }, options),
|
||||
close: () => client.close(),
|
||||
};
|
||||
} catch (error) {
|
||||
await client.close();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export class CodeModeBridge {
|
||||
constructor(upstream) {
|
||||
this.upstream = upstream;
|
||||
this.byName = new Map(upstream.catalog.map((tool) => [tool.name, tool]));
|
||||
this.catalogDigest = digest(upstream.catalog);
|
||||
this.declarations = new Map();
|
||||
this.queue = Promise.resolve();
|
||||
}
|
||||
|
||||
/** The live catalog is immutable for this connection; derive each type once. */
|
||||
declarationsFor(tool) {
|
||||
if (!this.declarations.has(tool.name)) {
|
||||
const options = { bannerComment: "", format: false, unknownAny: true };
|
||||
const pending = Promise.all([
|
||||
compile(tool.inputSchema, `${tool.name}_Input`, options),
|
||||
tool.outputSchema
|
||||
? compile(
|
||||
{ ...tool.outputSchema, title: `${tool.name}_Output` },
|
||||
`${tool.name}_Output`,
|
||||
options,
|
||||
)
|
||||
: undefined,
|
||||
]);
|
||||
this.declarations.set(tool.name, pending);
|
||||
}
|
||||
return this.declarations.get(tool.name);
|
||||
}
|
||||
|
||||
/** Search exposes original schemas and generated input types on demand. */
|
||||
async search({ query = "", names = [], schemas, output_schemas = false }) {
|
||||
const includeSchemas = schemas ?? (names.length > 0 || output_schemas);
|
||||
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
||||
const selected = this.upstream.catalog.filter((tool) =>
|
||||
names.length
|
||||
? names.includes(tool.name)
|
||||
: terms.every((term) =>
|
||||
`${tool.name} ${tool.description ?? ""}`
|
||||
.toLowerCase()
|
||||
.includes(term),
|
||||
),
|
||||
);
|
||||
// Failed all-word searches keep their original semantics. Offer only the
|
||||
// best positive lexical matches as names, without expanding their schemas.
|
||||
const ranked =
|
||||
selected.length || !terms.length || names.length
|
||||
? []
|
||||
: this.upstream.catalog.map((tool) => ({
|
||||
tool,
|
||||
score: terms.filter((term) =>
|
||||
`${tool.name} ${tool.description ?? ""}`
|
||||
.toLowerCase()
|
||||
.includes(term),
|
||||
).length,
|
||||
}));
|
||||
const bestScore = Math.max(0, ...ranked.map((row) => row.score));
|
||||
const suggestions = ranked
|
||||
.filter((row) => row.score === bestScore && bestScore > 0)
|
||||
.map(({ tool }) => ({ name: tool.name, description: tool.description }));
|
||||
const tools = [];
|
||||
for (const tool of selected) {
|
||||
const [inputType, outputType] = includeSchemas
|
||||
? await this.declarationsFor(tool)
|
||||
: [];
|
||||
tools.push(
|
||||
includeSchemas
|
||||
? {
|
||||
...tool,
|
||||
...(!output_schemas ? { outputSchema: undefined } : {}),
|
||||
typescript: inputType,
|
||||
output_typescript: outputType,
|
||||
}
|
||||
: {
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
annotations: tool.annotations,
|
||||
},
|
||||
);
|
||||
}
|
||||
return {
|
||||
catalog_sha256: this.catalogDigest,
|
||||
total_tools: this.byName.size,
|
||||
matched_tools: tools.length,
|
||||
tools,
|
||||
...(suggestions.length ? { suggestions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Serialize scripts sharing the active target; no implicit batch races. */
|
||||
execute(input, options = {}) {
|
||||
const parsed = executeInputSchema.parse(input);
|
||||
const work = this.queue.then(() => this.run(parsed, options));
|
||||
this.queue = work.catch(() => undefined);
|
||||
return work;
|
||||
}
|
||||
|
||||
async run(
|
||||
{ code, timeout_ms = 120_000, memory_bytes = 128 * 1024 * 1024 },
|
||||
options,
|
||||
) {
|
||||
const controller = new AbortController();
|
||||
const signal = options.signal
|
||||
? AbortSignal.any([controller.signal, options.signal])
|
||||
: controller.signal;
|
||||
signal.throwIfAborted();
|
||||
const deadline = Date.now() + timeout_ms;
|
||||
const timer = setTimeout(
|
||||
() => controller.abort(new Error("Code Mode deadline exceeded")),
|
||||
timeout_ms,
|
||||
);
|
||||
const QuickJS = await newQuickJSWASMModule();
|
||||
const runtime = QuickJS.newRuntime();
|
||||
// Pending-job execution can create another context in the runtime.
|
||||
// Own contexts at creation, including those allocated by the job pump.
|
||||
const contexts = new Scope();
|
||||
const newContext = runtime.newContext.bind(runtime);
|
||||
runtime.newContext = (options) => contexts.manage(newContext(options));
|
||||
runtime.setMemoryLimit(memory_bytes);
|
||||
runtime.setMaxStackSize(1024 * 1024);
|
||||
runtime.setInterruptHandler(() => signal.aborted || Date.now() > deadline);
|
||||
const vm = runtime.newContext();
|
||||
const pending = new Set();
|
||||
const calls = [];
|
||||
let toolQueue = Promise.resolve();
|
||||
let finished = false;
|
||||
let promise;
|
||||
let value;
|
||||
let failure;
|
||||
const checkedEval = (source) => {
|
||||
const result = vm.evalCode(source);
|
||||
if (result.error) {
|
||||
const error = vm.dump(result.error);
|
||||
result.error.dispose();
|
||||
throw new Error(JSON.stringify(error));
|
||||
}
|
||||
return result.value;
|
||||
};
|
||||
const pump = () => {
|
||||
const result = runtime.executePendingJobs();
|
||||
if (result.error) {
|
||||
failure = vm.dump(result.error);
|
||||
result.error.dispose();
|
||||
finished = true;
|
||||
}
|
||||
};
|
||||
const fromJson = (data) =>
|
||||
checkedEval(`JSON.parse(${JSON.stringify(JSON.stringify(data))})`);
|
||||
const callHandle = vm.newFunction("call", (nameHandle, argumentsHandle) => {
|
||||
const name = vm.getString(nameHandle);
|
||||
const args = JSON.parse(vm.getString(argumentsHandle));
|
||||
if (!this.byName.has(name))
|
||||
throw new Error(`Unknown upstream tool: ${name}`);
|
||||
signal.throwIfAborted();
|
||||
const deferred = vm.newPromise();
|
||||
const audit = { name, arguments_sha256: digest(args) };
|
||||
calls.push(audit);
|
||||
const work = toolQueue.then(async () => {
|
||||
const started = performance.now();
|
||||
try {
|
||||
signal.throwIfAborted();
|
||||
const reply = await this.upstream.call(name, args, {
|
||||
signal,
|
||||
timeout: Math.max(1, deadline - Date.now()),
|
||||
onprogress: options.onprogress,
|
||||
});
|
||||
audit.elapsed_ms = performance.now() - started;
|
||||
audit.result_sha256 = digest(reply);
|
||||
audit.is_error = reply.isError === true;
|
||||
try {
|
||||
const record = json(reply);
|
||||
if (record.evidence_id) audit.evidence_id = record.evidence_id;
|
||||
if (Array.isArray(record.evidence_links))
|
||||
audit.evidence_links = record.evidence_links;
|
||||
const partial = record.error?.details?.partial_observation;
|
||||
if (partial?.kind === "retained-evidence")
|
||||
audit.partial_evidence_id = partial.evidence_id;
|
||||
} catch {
|
||||
/* Non-JSON MCP content is still preserved in reply. */
|
||||
}
|
||||
const handle = fromJson(reply);
|
||||
deferred.resolve(handle);
|
||||
handle.dispose();
|
||||
} catch (error) {
|
||||
audit.transport_error = error.message;
|
||||
const handle = fromJson({ name: error.name, message: error.message });
|
||||
deferred.reject(handle);
|
||||
handle.dispose();
|
||||
} finally {
|
||||
deferred.dispose();
|
||||
pump();
|
||||
}
|
||||
});
|
||||
const settled = work.catch((error) => {
|
||||
failure = { message: error.message };
|
||||
finished = true;
|
||||
});
|
||||
toolQueue = settled;
|
||||
pending.add(settled);
|
||||
void settled.then(() => pending.delete(settled));
|
||||
// The callback transfers its returned handle to QuickJS. Keep the
|
||||
// deferred's original host handle until settlement, with a separate
|
||||
// guest handle; otherwise bulk promise cleanup shares one lifetime.
|
||||
return deferred.handle.dup();
|
||||
});
|
||||
const doneHandle = vm.newFunction("done", (data) => {
|
||||
value = JSON.parse(vm.getString(data));
|
||||
finished = true;
|
||||
});
|
||||
const failHandle = vm.newFunction("fail", (error) => {
|
||||
failure = vm.dump(error);
|
||||
finished = true;
|
||||
});
|
||||
try {
|
||||
vm.setProp(vm.global, "__call", callHandle);
|
||||
vm.setProp(vm.global, "__done", doneHandle);
|
||||
vm.setProp(vm.global, "__fail", failHandle);
|
||||
checkedEval(`
|
||||
const tools = Object.freeze(Object.fromEntries(${JSON.stringify([...this.byName.keys()])}.map(
|
||||
name => [name, args => __call(name, JSON.stringify(args))]
|
||||
)));
|
||||
const json = reply => {
|
||||
if (reply.structuredContent !== undefined) return reply.structuredContent;
|
||||
const texts = reply.content.filter(item => item.type === 'text');
|
||||
if (texts.length !== 1) throw new Error('Expected one REA JSON text block');
|
||||
return JSON.parse(texts[0].text);
|
||||
};
|
||||
`).dispose();
|
||||
promise = checkedEval(`(async () => {\n${code}\n})().then(
|
||||
value => __done(JSON.stringify(value === undefined ? null : value)),
|
||||
error => __fail({name: error?.name, message: error?.message ?? String(error)})
|
||||
)`);
|
||||
pump();
|
||||
while (!finished && !signal.aborted) {
|
||||
if (pending.size) await Promise.race(pending);
|
||||
else
|
||||
throw new Error(
|
||||
"Guest promise cannot progress: no pending tool calls",
|
||||
);
|
||||
pump();
|
||||
}
|
||||
signal.throwIfAborted();
|
||||
if (calls.some((call) => !call.result_sha256 && !call.transport_error)) {
|
||||
controller.abort(
|
||||
new Error("Code returned before awaiting all tool calls"),
|
||||
);
|
||||
await Promise.allSettled(pending);
|
||||
failure = {
|
||||
message:
|
||||
"Code returned before awaiting all tool calls; calls were cancelled",
|
||||
};
|
||||
} else await Promise.allSettled(pending);
|
||||
} catch (error) {
|
||||
failure = { name: error.name, message: error.message };
|
||||
controller.abort(error);
|
||||
await Promise.allSettled(pending);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
promise?.dispose();
|
||||
callHandle.dispose();
|
||||
doneHandle.dispose();
|
||||
failHandle.dispose();
|
||||
contexts.dispose();
|
||||
runtime.dispose();
|
||||
}
|
||||
return {
|
||||
catalog_sha256: this.catalogDigest,
|
||||
calls,
|
||||
...(failure ? { bridge_error: failure } : { value }),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function createBridgeServer(bridge) {
|
||||
const server = new McpServer({
|
||||
name: "rea-codemode-experiment",
|
||||
version: "0.0.0",
|
||||
});
|
||||
const reply = (result) => ({
|
||||
content: [{ type: "text", text: JSON.stringify(result) }],
|
||||
...(result.bridge_error ? { isError: true } : {}),
|
||||
});
|
||||
server.registerTool(
|
||||
"rea_search",
|
||||
{
|
||||
description:
|
||||
"Discover original upstream REA tools. Start with one domain word, e.g. query=android; query words must all occur. Query/empty discovery defaults to names and descriptions. Then supply all selected exact names together to obtain exact input schemas plus derived input/output TypeScript for code authoring. schemas=true/false overrides this choice. Request output_schemas=true only for original JSON validation contracts. rea_search and rea_execute are already declared bridge tools, not upstream catalog entries. catalog_sha256 hashes the SDK catalog, not REA server_identity.catalog.digests. Code calls tools.<name>(original_arguments); json(reply) parses the original MCP value.",
|
||||
inputSchema: z.strictObject({
|
||||
query: z.string().default(""),
|
||||
names: z.array(z.string()).default([]),
|
||||
schemas: z.boolean().optional(),
|
||||
output_schemas: z.boolean().default(false),
|
||||
}),
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: false,
|
||||
},
|
||||
},
|
||||
async (input) => reply(await bridge.search(input)),
|
||||
);
|
||||
server.registerTool(
|
||||
"rea_execute",
|
||||
{
|
||||
description:
|
||||
"Run a JavaScript async function body with tools.<original_REA_name>(original_arguments), json(reply) and return. Await every call. json(reply) returns the original REA value: Evidence has normalized_result, evidence_id and limitations; session values have result. Select the needed normalized_result fields inside code before returning them with Evidence IDs and limitations. One upstream session persists. Calls run in order, including Promise.all. All original REA effects, validation and retention apply; projections are caller selections, not new Evidence. No host IO or imports. Call audit and Evidence IDs survive script errors. Default deadline 120s and guest memory 128 MiB; use longer deadline for native analysis.",
|
||||
inputSchema: executeInputSchema,
|
||||
annotations: {
|
||||
readOnlyHint: false,
|
||||
destructiveHint: true,
|
||||
idempotentHint: false,
|
||||
openWorldHint: true,
|
||||
},
|
||||
},
|
||||
async (input, context) =>
|
||||
reply(
|
||||
await bridge.execute(input, {
|
||||
signal: context.mcpReq.signal,
|
||||
onprogress:
|
||||
context.mcpReq._meta?.progressToken === undefined
|
||||
? undefined
|
||||
: (progress) =>
|
||||
context.mcpReq.notify({
|
||||
method: "notifications/progress",
|
||||
params: {
|
||||
...progress,
|
||||
progressToken: context.mcpReq._meta.progressToken,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
),
|
||||
);
|
||||
return server;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const [command, ...args] = process.argv.slice(2);
|
||||
if (!command) throw new Error("Usage: node bridge.mjs COMMAND [ARG...]");
|
||||
const upstream = await connectUpstream({ command, args, env: process.env });
|
||||
const server = createBridgeServer(new CodeModeBridge(upstream));
|
||||
let closing = false;
|
||||
const close = async () => {
|
||||
if (closing) return;
|
||||
closing = true;
|
||||
await server.close();
|
||||
await upstream.close();
|
||||
};
|
||||
process.once("SIGINT", () => void close());
|
||||
process.once("SIGTERM", () => void close());
|
||||
const transport = new StdioServerTransport();
|
||||
transport.onclose = () => void close();
|
||||
await server.connect(transport);
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -1,313 +0,0 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import Ajv2020 from "ajv/dist/2020.js";
|
||||
import { CodeModeBridge, connectUpstream, json } from "./bridge.mjs";
|
||||
|
||||
const entrypoint = fileURLToPath(
|
||||
new URL("../../scripts/rea.mjs", import.meta.url),
|
||||
);
|
||||
const fixture = fileURLToPath(
|
||||
new URL("../../tests/conformance/readiness/javascript-cli", import.meta.url),
|
||||
);
|
||||
const analysisArgs = {
|
||||
input_path: fixture,
|
||||
detail: "summary",
|
||||
max_heap_mb: 128,
|
||||
};
|
||||
let upstream;
|
||||
let bridge;
|
||||
before(async () => {
|
||||
upstream = await connectUpstream({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: { ...process.env, REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
bridge = new CodeModeBridge(upstream);
|
||||
});
|
||||
after(async () => {
|
||||
await upstream?.close();
|
||||
});
|
||||
|
||||
test("discovery preserves exact current REA schemas and names", async () => {
|
||||
const result = await bridge.search({
|
||||
names: ["binary_session"],
|
||||
output_schemas: true,
|
||||
});
|
||||
assert.equal(result.total_tools, upstream.catalog.length);
|
||||
const original = upstream.catalog.find(
|
||||
(tool) => tool.name === "binary_session",
|
||||
);
|
||||
const { typescript, output_typescript, ...discovered } = result.tools[0];
|
||||
assert.deepEqual(discovered, original);
|
||||
assert.match(typescript, /export interface BinarySession_Input/);
|
||||
assert.match(output_typescript, /export interface BinarySession_Output/);
|
||||
const inputOnly = await bridge.search({ names: ["binary_session"] });
|
||||
assert.deepEqual(inputOnly.tools[0].inputSchema, original.inputSchema);
|
||||
assert.equal(inputOnly.tools[0].outputSchema, undefined);
|
||||
assert.equal(inputOnly.tools[0].output_typescript, output_typescript);
|
||||
const all = await bridge.search({ schemas: false });
|
||||
assert.deepEqual(
|
||||
all.tools.map((tool) => tool.name),
|
||||
upstream.catalog.map((tool) => tool.name),
|
||||
);
|
||||
const query = await bridge.search({ query: "android" });
|
||||
assert.ok(query.tools.length > 0);
|
||||
assert.ok(query.tools.every((tool) => tool.inputSchema === undefined));
|
||||
const querySchemas = await bridge.search({ query: "android", schemas: true });
|
||||
assert.ok(querySchemas.tools.every((tool) => tool.inputSchema !== undefined));
|
||||
const outputRequested = await bridge.search({
|
||||
query: "android",
|
||||
output_schemas: true,
|
||||
});
|
||||
assert.ok(
|
||||
outputRequested.tools.every((tool) => tool.outputSchema !== undefined),
|
||||
);
|
||||
const missed = await bridge.search({
|
||||
query: "android impossible_query_word",
|
||||
});
|
||||
assert.equal(missed.matched_tools, 0);
|
||||
assert.ok(
|
||||
missed.suggestions.some((tool) => tool.name === "inspect_android_package"),
|
||||
);
|
||||
assert.ok(missed.suggestions.every((tool) => tool.inputSchema === undefined));
|
||||
});
|
||||
|
||||
test("raw original result and parsed result survive a real MCP call", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "const r = await tools.binary_session({}); return {raw:r, parsed:json(r)};",
|
||||
});
|
||||
assert.equal(result.bridge_error, undefined);
|
||||
assert.deepEqual(json(result.value.raw), result.value.parsed);
|
||||
assert.equal(result.calls[0].name, "binary_session");
|
||||
assert.match(result.calls[0].result_sha256, /^[a-f0-9]{64}$/);
|
||||
assert.equal(result.calls[0].is_error, false);
|
||||
});
|
||||
|
||||
test("Promise.all calls settle in order without losing pending work", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return await Promise.all([tools.binary_session({}), tools.binary_session({}), tools.binary_session({})]);",
|
||||
});
|
||||
assert.equal(result.bridge_error, undefined);
|
||||
assert.equal(result.value.length, 3);
|
||||
assert.equal(result.calls.length, 3);
|
||||
assert.ok(result.calls.every((call) => call.result_sha256));
|
||||
});
|
||||
|
||||
test("upstream invalid-input result remains an original MCP error envelope", async () => {
|
||||
const args = {
|
||||
input_path: "/nonexistent/rea-codemode-artifact",
|
||||
detail: "summary",
|
||||
};
|
||||
const direct = await upstream.call("analyze_javascript_application", args);
|
||||
const result = await bridge.execute({
|
||||
code: `return await tools.analyze_javascript_application(${JSON.stringify(args)});`,
|
||||
});
|
||||
assert.equal(result.bridge_error, undefined);
|
||||
assert.equal(result.value.isError, true);
|
||||
assert.deepEqual(json(result.value).error, json(direct).error);
|
||||
assert.equal(result.calls[0].is_error, true);
|
||||
});
|
||||
|
||||
test("guest has no Node, filesystem, fetch or module-loading capabilities", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return [typeof process,typeof require,typeof fetch,typeof Deno,Function('return typeof process')()];",
|
||||
});
|
||||
assert.deepEqual(result.value, Array(5).fill("undefined"));
|
||||
const imported = await bridge.execute({
|
||||
code: "return await import('node:fs');",
|
||||
});
|
||||
assert.ok(imported.bridge_error);
|
||||
});
|
||||
|
||||
test("CPU deadline interrupts runaway code and the next execution works", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "while(true) {}",
|
||||
timeout_ms: 20,
|
||||
});
|
||||
assert.ok(result.bridge_error);
|
||||
assert.deepEqual(result.calls, []);
|
||||
assert.equal((await bridge.execute({ code: "return 42;" })).value, 42);
|
||||
});
|
||||
|
||||
test("guest allocation pressure fails within its heap budget and permits reuse", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return new Array(1_000_000).fill('x');",
|
||||
memory_bytes: 2 * 1024 * 1024,
|
||||
});
|
||||
assert.match(result.bridge_error.message, /memory/i);
|
||||
assert.deepEqual(result.calls, []);
|
||||
assert.equal((await bridge.execute({ code: "return 42;" })).value, 42);
|
||||
assert.throws(() =>
|
||||
bridge.execute({ code: "return 1;", timeout_ms: 2_147_483_648 }),
|
||||
);
|
||||
});
|
||||
|
||||
test("error after successful call preserves original Evidence reference", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: `await tools.analyze_javascript_application(${JSON.stringify(analysisArgs)}); throw new Error('after-call');`,
|
||||
});
|
||||
assert.match(result.bridge_error.message, /after-call/);
|
||||
assert.ok(result.calls[0].evidence_id);
|
||||
assert.ok(result.calls[0].evidence_links.length > 0);
|
||||
const readback = await upstream.call("get_evidence_bundle", {
|
||||
detail: "summary",
|
||||
});
|
||||
assert.equal(readback.isError, undefined);
|
||||
assert.ok(
|
||||
JSON.stringify(json(readback)).includes(result.calls[0].evidence_id),
|
||||
);
|
||||
for (const evidence_id of result.calls[0].evidence_links) {
|
||||
const view = json(
|
||||
await upstream.call("inspect_analysis_view", {
|
||||
source: { kind: "retained-evidence", evidence_id },
|
||||
view: { kind: "summary" },
|
||||
}),
|
||||
);
|
||||
assert.equal(view.normalized_result.parent_evidence_id, evidence_id);
|
||||
}
|
||||
});
|
||||
|
||||
test("provider timeout retains its actual partial Evidence reference", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: `const reply = await tools.analyze_javascript_application(${JSON.stringify({ ...analysisArgs, analysis_timeout_ms: 1 })}); return json(reply);`,
|
||||
});
|
||||
const partial = result.value.error.details.partial_observation;
|
||||
assert.equal(partial.kind, "retained-evidence");
|
||||
assert.equal(result.calls[0].is_error, true);
|
||||
assert.equal(result.calls[0].partial_evidence_id, partial.evidence_id);
|
||||
const view = json(
|
||||
await upstream.call("inspect_analysis_view", {
|
||||
source: partial,
|
||||
view: { kind: "summary" },
|
||||
}),
|
||||
);
|
||||
assert.equal(view.normalized_result.parent_evidence_id, partial.evidence_id);
|
||||
});
|
||||
|
||||
test("cancelling queued calls releases deferred handles and permits reuse", async () => {
|
||||
let callStarted;
|
||||
const started = new Promise((resolve) => {
|
||||
callStarted = resolve;
|
||||
});
|
||||
const cancelled = new AbortController();
|
||||
const controlled = new CodeModeBridge({
|
||||
catalog: upstream.catalog,
|
||||
async call(name, args, options) {
|
||||
const reply = await upstream.call(name, args, options);
|
||||
callStarted();
|
||||
// A controlled delivery delay after a real result makes the queued
|
||||
// cancellation deterministic, without simulating provider behavior.
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
return reply;
|
||||
},
|
||||
});
|
||||
const execution = controlled.execute(
|
||||
{
|
||||
code: "return await Promise.all([tools.binary_session({}), tools.binary_session({})]);",
|
||||
},
|
||||
{ signal: cancelled.signal },
|
||||
);
|
||||
await started;
|
||||
cancelled.abort(new Error("controlled queued cancellation"));
|
||||
const result = await execution;
|
||||
assert.ok(result.bridge_error);
|
||||
assert.equal(result.calls.length, 2);
|
||||
assert.match(
|
||||
result.calls[1].transport_error,
|
||||
/controlled queued cancellation/,
|
||||
);
|
||||
assert.equal((await controlled.execute({ code: "return 42;" })).value, 42);
|
||||
});
|
||||
|
||||
test("a guest promise without any producer fails without hanging", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return await new Promise(() => {});",
|
||||
});
|
||||
assert.match(result.bridge_error.message, /cannot progress/);
|
||||
});
|
||||
|
||||
test("bridge's two tools are usable through actual downstream stdio MCP", async () => {
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [
|
||||
fileURLToPath(new URL("./bridge.mjs", import.meta.url)),
|
||||
process.execPath,
|
||||
entrypoint,
|
||||
"mcp",
|
||||
],
|
||||
env: { ...process.env, REA_LOG_LEVEL: "silent" },
|
||||
stderr: "inherit",
|
||||
});
|
||||
const client = new Client({ name: "codemode-boundary-test", version: "1" });
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const catalog = await client.listTools();
|
||||
assert.deepEqual(
|
||||
catalog.tools.map((tool) => tool.name),
|
||||
["rea_search", "rea_execute"],
|
||||
);
|
||||
const ajv = new Ajv2020({ strict: true });
|
||||
const byName = new Map(catalog.tools.map((tool) => [tool.name, tool]));
|
||||
for (const tool of catalog.tools) {
|
||||
assert.equal(
|
||||
tool.inputSchema.$schema ??
|
||||
"https://json-schema.org/draft/2020-12/schema",
|
||||
"https://json-schema.org/draft/2020-12/schema",
|
||||
);
|
||||
assert.equal(
|
||||
ajv.validateSchema(tool.inputSchema),
|
||||
true,
|
||||
ajv.errorsText(),
|
||||
);
|
||||
}
|
||||
const validate = ajv.compile(byName.get("rea_execute").inputSchema);
|
||||
assert.equal(
|
||||
validate({ code: "return 1;", timeout_ms: 2_147_483_647 }),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
validate({ code: "return 1;", timeout_ms: 2_147_483_648 }),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
validate({ code: "return 1;", memory_bytes: 128 * 1024 * 1024 + 1 }),
|
||||
false,
|
||||
);
|
||||
const found = json(
|
||||
await client.callTool({
|
||||
name: "rea_search",
|
||||
arguments: { names: ["binary_session"] },
|
||||
}),
|
||||
);
|
||||
assert.equal(found.matched_tools, 1);
|
||||
const result = json(
|
||||
await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: {
|
||||
code: "return json(await tools.binary_session({}));",
|
||||
},
|
||||
}),
|
||||
);
|
||||
assert.equal(result.value.result.open, false);
|
||||
const invalid = await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: { code: 7 },
|
||||
});
|
||||
assert.equal(invalid.isError, true);
|
||||
const oversized = await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: { code: "return 1;", timeout_ms: 2_147_483_648 },
|
||||
});
|
||||
assert.equal(oversized.isError, true);
|
||||
const oversizedMemory = await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: { code: "return 1;", memory_bytes: 128 * 1024 * 1024 + 1 },
|
||||
});
|
||||
assert.equal(oversizedMemory.isError, true);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
});
|
||||
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"artifacts": [
|
||||
{
|
||||
"id": "sharex.dll",
|
||||
"file": "ShareX.dll",
|
||||
"bytes": 2162688,
|
||||
"sha256": "191a191be964e434daf0f9d76d1e0d8ddce90d7e248cba2a6b5ac9577f288d53",
|
||||
"provenance": {
|
||||
"project": "ShareX",
|
||||
"version": "19.0.2",
|
||||
"upstreamFile": "ShareX-19.0.2-portable.zip",
|
||||
"url": "https://github.com/ShareX/ShareX/releases/download/v19.0.2/ShareX-19.0.2-portable.zip",
|
||||
"transport_sha256": "967b5d838df5ce25fb5fd7cbd16f1bd797427e2df16907b022b74a4bc0fb9d54",
|
||||
"transport_bytes": 168796487,
|
||||
"derivation": "selected regular ZIP member ShareX.dll"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "sqlite.wasm",
|
||||
"file": "sqlite3.wasm",
|
||||
"bytes": 868907,
|
||||
"sha256": "2ee8f3dab694532afc8840e07703127287662d08b74e6ff50491ce63f00d5752",
|
||||
"provenance": {
|
||||
"project": "SQLite Wasm",
|
||||
"version": "3.53.4-build1",
|
||||
"upstreamFile": "sqlite-wasm-3.53.4-build1.tgz",
|
||||
"url": "https://registry.npmjs.org/@sqlite.org/sqlite-wasm/-/sqlite-wasm-3.53.4-build1.tgz",
|
||||
"transport_sha256": "24f46db4ce5248fa8f8f24b67e81909ab1a9c152f42a4796a32c6d385a6fb62b",
|
||||
"transport_bytes": 977616,
|
||||
"transport_integrity": "sha512-U8pvL0patYHMgieD8JxxYJTlh9m1LUX8+BDYb7MiKQzBI89f2qbdmdcG/PvnPaLm9wsBbv4VlVG453ixnxBOnA==",
|
||||
"derivation": "selected regular tar member package/dist/sqlite3.wasm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "obsidian.asar",
|
||||
"file": "obsidian-1.14.4.asar",
|
||||
"bytes": 27477966,
|
||||
"sha256": "146ef8470d8cbb4a6db209bdc19bf2bad13350444186c0fd93c31087b142b92f",
|
||||
"provenance": {
|
||||
"project": "Obsidian",
|
||||
"version": "1.14.4",
|
||||
"upstreamFile": "obsidian-1.14.4.asar",
|
||||
"transport": {
|
||||
"file": "obsidian-1.14.4.asar.gz",
|
||||
"url": "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.14.4/obsidian-1.14.4.asar.gz",
|
||||
"sha256": "d1ed428c363968774f0f3906e67d8a53a058ece0b6cdd924b07865977b2ada21",
|
||||
"bytes": 9200670
|
||||
},
|
||||
"derivation": "gzip decompression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "newpipe.apk",
|
||||
"file": "NewPipe_v0.29.1.apk",
|
||||
"bytes": 11507122,
|
||||
"sha256": "18447bfb1e06d113edc88df93f471827280de06f6f3d4dc42f56f28b9c1bab79",
|
||||
"provenance": {
|
||||
"project": "NewPipe",
|
||||
"version": "0.29.1",
|
||||
"upstreamFile": "NewPipe_v0.29.1.apk",
|
||||
"url": "https://github.com/TeamNewPipe/NewPipe/releases/download/v0.29.1/NewPipe_v0.29.1.apk"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "jq",
|
||||
"file": "jq-linux-amd64",
|
||||
"bytes": 2267912,
|
||||
"sha256": "b1c22172dd303f3be49e935aa56aa48a8b7a46e0bc838b4997d3bb451495870f",
|
||||
"provenance": {
|
||||
"project": "jq",
|
||||
"version": "1.8.2",
|
||||
"upstreamFile": "jq-linux-amd64",
|
||||
"url": "https://github.com/jqlang/jq/releases/download/jq-1.8.2/jq-linux-amd64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "openwrt.bin",
|
||||
"file": "openwrt-25.12.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin",
|
||||
"bytes": 7405862,
|
||||
"sha256": "f15b16b36df7fce8a5cf1302320fdb428c3bb6fbc2949a4858afa257f4f364a2",
|
||||
"provenance": {
|
||||
"project": "OpenWrt Archer C7 v5",
|
||||
"version": "25.12.5",
|
||||
"upstreamFile": "openwrt-25.12.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin",
|
||||
"url": "https://downloads.openwrt.org/releases/25.12.5/targets/ath79/generic/openwrt-25.12.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
# Decision from the frozen Code Mode experiment
|
||||
|
||||
Keep REA's existing CLI/MCP contracts as the default. Improve Evidence-aware
|
||||
workflow guidance and retain this two-tool bridge as an optional experiment.
|
||||
The measured Codex profiles do not justify a broad API refactor or a default
|
||||
switch to the external executor.
|
||||
|
||||
## What supports that choice
|
||||
|
||||
The [serial cohort](agent-results.json) contains sixteen real Codex CLI trials,
|
||||
configured with `gpt-5.6-terra` high, across Android, managed PE/CLI, Electron ASAR
|
||||
inventory, firmware and native Ghidra analysis. Twelve pass the strict requested
|
||||
fact/reference checks. Two bridge managed answers omit the classification's
|
||||
container field; two normal-MCP managed transcripts truncate a large producer
|
||||
envelope, preventing complete-envelope verification of one cited ID. Their
|
||||
remaining requested facts match the real-provider oracle. The complete-container
|
||||
assertion is stronger than the question's general classification wording.
|
||||
|
||||
The bridge's Android repetitions take 48.231 and 134.555 seconds, compared with
|
||||
67.329 and 71.624 for normal MCP. The faster bridge trial composes three original
|
||||
operations once; the slower one performs seven original calls across five scripts.
|
||||
The faster trial uses typed discovery; this does not make the model reliably
|
||||
choose that workflow. Uncached input is lower in both bridge repetitions;
|
||||
output and latency vary. This is not a stable overall efficiency win.
|
||||
|
||||
Managed bridge latency also varies, and its two answers omit the same field.
|
||||
Firmware's one-operation question takes 81.944 seconds with the bridge versus
|
||||
30.161 directly. Ghidra takes 334.642 versus 327.150 seconds, with sampled aggregate
|
||||
CPU times of 271.096 and 263.738 seconds. The bridge performs three original
|
||||
operations versus four directly, deriving containing identity from the analyzed
|
||||
procedure. Native analysis cost remains dominant with unchanged default settings.
|
||||
|
||||
Obsidian inventory exposes a useful contract boundary: nested Evidence types leave
|
||||
their normalized payload generic. The model initially returns the whole inventory
|
||||
and repeats analysis. Giving both profiles the concrete manifest/occurrences
|
||||
layout yields a single focused bridge workflow: 101994 total input tokens versus
|
||||
263484 directly, but 40554 versus 41532 uncached tokens and 85.909 versus 67.540
|
||||
seconds. Clear producer/layout guidance matters; total context compression alone
|
||||
does not establish lower cost or latency. Cache pricing is not estimated here.
|
||||
|
||||
Deterministic replays demonstrate large projection savings across real providers.
|
||||
They measure a known script, not the model's ability to discover and write it.
|
||||
SQLite WASM fails the frozen WABT parser on an unpadded DataCount row; Obsidian's
|
||||
full AST analysis times out with a retained partial reference. Inventory does not
|
||||
replace AST analysis. Neither failure is counted as a Code Mode success.
|
||||
|
||||
## Migration scope
|
||||
|
||||
Current users retain original operation names, arguments, provider choices,
|
||||
Evidence and session behavior. A client with equivalent execution support can use
|
||||
the existing registration and focused workflows. The installed Codex transcript
|
||||
does not expose its executor source, so its exact internal composition is unknown.
|
||||
|
||||
For clients that need the bridge, use a separate opt-in profile for an investigation.
|
||||
The bridge owns one original REA connection and looks up live contracts by name.
|
||||
Its session and Evidence ledger are separate from another REA registration; do
|
||||
not mix target lifecycle calls or same-session IDs across those registrations.
|
||||
Derived TypeScript assists code authoring; original JSON schemas remain available.
|
||||
Original producer IDs, links, errors and partial-reference IDs survive auditing;
|
||||
caller projections do not become new Evidence records.
|
||||
|
||||
The outer execution tool combines original effects and client requirements.
|
||||
This prototype has not forwarded roots/elicitation/sampling or preserved a client's
|
||||
per-original-operation approval flow. That capability boundary must be addressed
|
||||
before offering it as a production replacement. The guest's lack of host IO does
|
||||
not remove effects reachable through original REA tools.
|
||||
|
||||
An additive producer-description improvement explaining nested payload layout is
|
||||
a smaller next candidate than changing names or inventing another workflow API.
|
||||
Original inputs and output defaults should remain intact. Provider analysis
|
||||
settings must be evaluated separately from discovery and projection improvements.
|
||||
|
||||
## Verification limits
|
||||
|
||||
These are descriptive samples with matching questions/provider settings per pair,
|
||||
mode-specific instructions and model-selected arguments. They do not provide
|
||||
confidence intervals, independent decompiler truth, Android/.NET runtime behavior,
|
||||
full native-function coverage, complete firmware reconstruction or Windows/IDA
|
||||
provider verification. Citations are checked against observed producer values and
|
||||
links, not resolved individually after session exit.
|
||||
|
||||
Sixteen trials finish without sampled memory/task-limit events or resource aborts.
|
||||
Their maximum sampled memory is 1659744256 bytes (about 1.55 GiB), with at most
|
||||
126 tasks, under one CPU and a 4 GiB hard ceiling/3 GiB early stop. Copied profiles
|
||||
are removed. Twelve actual stdio tests additionally cover cancellation, partial
|
||||
Evidence readback, guest allocation failure/recovery, and advertised schema
|
||||
validation. The earlier 2 GiB build-scope kill remains a documented failed build.
|
||||
@@ -1,249 +0,0 @@
|
||||
"""Check requested JSON facts and real Evidence references against a replay oracle."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def required_field(row, key):
|
||||
return row[key] if key in row else {'missing_field': key}
|
||||
|
||||
|
||||
def same_fact(actual, expected):
|
||||
if isinstance(actual, bool) or isinstance(expected, bool):
|
||||
return type(actual) is type(expected) and actual == expected
|
||||
if isinstance(expected, dict):
|
||||
return isinstance(actual, dict) and actual.keys() == expected.keys() and all(
|
||||
same_fact(actual[key], value) for key, value in expected.items())
|
||||
if isinstance(expected, list):
|
||||
return isinstance(actual, list) and len(actual) == len(expected) and all(
|
||||
same_fact(a, b) for a, b in zip(actual, expected))
|
||||
return actual == expected
|
||||
|
||||
|
||||
def evidence_ids(value):
|
||||
if isinstance(value, str):
|
||||
return {value} if value.startswith('ev_') and len(value) == 67 else set()
|
||||
if isinstance(value, dict):
|
||||
return set().union(*(evidence_ids(v) for v in value.values()))
|
||||
if isinstance(value, list):
|
||||
return set().union(*(evidence_ids(v) for v in value))
|
||||
return set()
|
||||
|
||||
|
||||
def read_answer(path):
|
||||
source = path.read_text().strip()
|
||||
lines = source.splitlines()
|
||||
# Accept a single complete JSON fence, never repair prose or partial JSON.
|
||||
if len(lines) >= 3 and lines[0] == '```json' and lines[-1] == '```':
|
||||
source = '\n'.join(lines[1:-1])
|
||||
answer_format = 'markdown_json'
|
||||
else:
|
||||
answer_format = 'json'
|
||||
answer = json.loads(source)
|
||||
if not isinstance(answer, dict):
|
||||
raise ValueError('Answer is not a JSON object')
|
||||
return answer, answer_format
|
||||
|
||||
|
||||
def requested_facts(value, task):
|
||||
if task == 'native':
|
||||
facts = {field: value.get(field) for field in [
|
||||
'artifact_sha256', 'entry_address', 'containing_procedure',
|
||||
'procedure', 'pseudocode_prefix', 'caller_count', 'callee_count']}
|
||||
containing = facts['containing_procedure']
|
||||
if isinstance(containing, dict) and containing.get('found', True) is True and \
|
||||
containing.get('query_address', facts['entry_address']) == facts['entry_address']:
|
||||
identity = containing.get('procedure', containing)
|
||||
if isinstance(identity, dict):
|
||||
facts['containing_procedure'] = {key: identity.get(key) for key in ['address', 'name']}
|
||||
return facts
|
||||
if task == 'electron-inventory':
|
||||
facts = {field: value.get(field) for field in [
|
||||
'artifact_sha256', 'manifest', 'entry_kind_counts', 'requested_paths',
|
||||
'integrity_contradictions', 'coverage', 'unexplored_branches']}
|
||||
paths = facts['requested_paths']
|
||||
if isinstance(paths, dict) and set(paths) == {'package.json', 'main.js', 'preload.js'}:
|
||||
if all(isinstance(rows, list) and all(isinstance(row, dict) and
|
||||
row.get('logical_path') == name for row in rows)
|
||||
for name, rows in paths.items()):
|
||||
paths = [row for rows in paths.values() for row in rows]
|
||||
if isinstance(paths, list) and all(isinstance(row, dict) and
|
||||
isinstance(row.get('logical_path'), str) for row in paths):
|
||||
paths = sorted(paths, key=lambda row: row['logical_path'])
|
||||
facts['requested_paths'] = paths
|
||||
contradictions = facts['integrity_contradictions']
|
||||
if isinstance(contradictions, dict) and set(contradictions) == {'inspection', 'inventory'}:
|
||||
if all(rows == [] for rows in contradictions.values()):
|
||||
facts['integrity_contradictions'] = []
|
||||
branches = facts['unexplored_branches']
|
||||
if isinstance(branches, list) and all(isinstance(row, dict) for row in branches):
|
||||
# Branch identity includes the source Evidence identity. Compare its
|
||||
# reported meaning here and verify its actual source reference below.
|
||||
facts['unexplored_branches'] = [{key: row.get(key) for key in [
|
||||
'reason', 'detail', 'next_probe']} for row in branches]
|
||||
return facts
|
||||
if task == 'firmware':
|
||||
result = value.get('result')
|
||||
if not isinstance(result, dict):
|
||||
result = {}
|
||||
engine = result.get('engine', result.get('provider'))
|
||||
if isinstance(engine, dict):
|
||||
engine = {'version': engine.get('version'),
|
||||
'executable_sha256': engine.get('executable_sha256',
|
||||
engine.get('engine_artifact_sha256'))}
|
||||
regions = result.get('regions')
|
||||
if isinstance(regions, list) and all(isinstance(row, dict) for row in regions):
|
||||
# Binwalk's UUID is run-local; preserve it in the answer but do not
|
||||
# compare it with the independent replay's different occurrence ID.
|
||||
selected_regions = []
|
||||
for row in regions:
|
||||
selected = {key: row.get(key) for key in [
|
||||
'offset', 'signature', 'description', 'reported_confidence']}
|
||||
if 'reported_size' in row:
|
||||
size = row['reported_size']
|
||||
elif 'reported_extent_bytes' in row:
|
||||
size = row['reported_extent_bytes']
|
||||
else:
|
||||
extent = row.get('reported_extent')
|
||||
size = None
|
||||
if isinstance(extent, dict) and extent.get('offset') == row.get('offset'):
|
||||
length = extent.get('length')
|
||||
offset = row.get('offset')
|
||||
if isinstance(length, int) and isinstance(offset, int) and \
|
||||
extent.get('end_exclusive') == offset + length:
|
||||
size = length
|
||||
selected['reported_size'] = size
|
||||
selected_regions.append(selected)
|
||||
regions = selected_regions
|
||||
return {'artifact_sha256': value.get('artifact_sha256'),
|
||||
'engine': engine, 'input_size': result.get('input_size', result.get('input_size_bytes')),
|
||||
'regions': regions, 'coverage': result.get('coverage', result.get('examined_coverage'))}
|
||||
if task == 'managed':
|
||||
def selected(field, keys):
|
||||
row = value.get(field)
|
||||
return {key: required_field(row, key) for key in keys} if isinstance(row, dict) else row
|
||||
coverage = value.get('coverage')
|
||||
if isinstance(coverage, dict):
|
||||
coverage = {'managed_artifact': coverage.get('managed_artifact'),
|
||||
'native_boundaries': coverage.get('native_boundaries',
|
||||
coverage.get('managed_native_boundaries'))}
|
||||
coverage = {key: {field: row.get(field) for field in ['state', 'issues']}
|
||||
if isinstance(row, dict) else row
|
||||
for key, row in coverage.items() if key in ['managed_artifact', 'native_boundaries']}
|
||||
return {
|
||||
'artifact_sha256': value.get('artifact_sha256'),
|
||||
'assembly': selected('assembly', ['name', 'version']),
|
||||
'module': selected('module', ['name', 'mvid']),
|
||||
'classification': value.get('classification'),
|
||||
'target_frameworks': value.get('target_frameworks'),
|
||||
'native_boundaries': selected('native_boundaries', ['module_refs', 'pinvoke_imports']),
|
||||
'coverage': coverage,
|
||||
}
|
||||
facts = {field: value.get(field) for field in [
|
||||
'artifact_sha256', 'package_name', 'version_name', 'version_code', 'matches', 'onCreate']}
|
||||
methods = facts['onCreate']
|
||||
if isinstance(methods, list) and all(isinstance(row, dict) for row in methods):
|
||||
facts['onCreate'] = [{key: required_field(row, key) for key in [
|
||||
'reported_signature', 'overload_index', 'dex_descriptor']} for row in methods]
|
||||
return facts
|
||||
|
||||
|
||||
def producer_ids(reply):
|
||||
if not isinstance(reply, dict):
|
||||
return set(), 0
|
||||
ids = evidence_ids(reply.get('evidence_id'))
|
||||
ids |= evidence_ids(reply.get('evidence_links'))
|
||||
for call in reply.get('calls', []):
|
||||
ids |= evidence_ids(call.get('evidence_id'))
|
||||
ids |= evidence_ids(call.get('evidence_links'))
|
||||
ids |= evidence_ids(call.get('partial_evidence_id'))
|
||||
unreadable = 0
|
||||
# SDK envelopes and Codex JSONL use distinct declared field spellings.
|
||||
for field in ['structuredContent', 'structured_content']:
|
||||
nested_ids, nested_unreadable = producer_ids(reply.get(field))
|
||||
ids |= nested_ids
|
||||
unreadable += nested_unreadable
|
||||
for content in reply.get('content', []):
|
||||
if content.get('type') != 'text':
|
||||
continue
|
||||
try:
|
||||
value = json.loads(content['text'])
|
||||
except ValueError:
|
||||
unreadable += 1
|
||||
continue
|
||||
nested_ids, nested_unreadable = producer_ids(value)
|
||||
ids |= nested_ids
|
||||
unreadable += nested_unreadable
|
||||
return ids, unreadable
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--trial', type=Path, required=True)
|
||||
parser.add_argument('--oracle', type=Path, required=True)
|
||||
parser.add_argument('--task', choices=[
|
||||
'android', 'managed', 'native', 'firmware', 'electron-inventory'], default='android')
|
||||
args = parser.parse_args()
|
||||
oracle = json.loads(args.oracle.read_text())
|
||||
if oracle.get('failure') or not oracle.get('projection'):
|
||||
raise SystemExit('A failed replay is not a factual oracle')
|
||||
projection = oracle['projection']
|
||||
if args.task == 'managed':
|
||||
projection = {**projection, 'coverage': {
|
||||
'managed_artifact': projection['coverage'],
|
||||
'native_boundaries': projection['native_boundaries']['coverage'],
|
||||
}}
|
||||
expected = requested_facts(projection, args.task)
|
||||
# A task explicitly chooses these assertions; do not grade unrequested fields.
|
||||
if any(value is None for value in expected.values()):
|
||||
raise SystemExit('Replay does not contain the selected task facts')
|
||||
failures = []
|
||||
answer_format = None
|
||||
answer_path = args.trial / 'answer.txt'
|
||||
try:
|
||||
answer, answer_format = read_answer(answer_path)
|
||||
except (FileNotFoundError, ValueError) as error:
|
||||
answer = {}
|
||||
failures.append({'kind': 'answer_parse_failure', 'reason': str(error)})
|
||||
actual_facts = requested_facts(answer, args.task)
|
||||
for field, wanted in expected.items():
|
||||
actual = actual_facts[field]
|
||||
if not same_fact(actual, wanted):
|
||||
failures.append({'kind': 'fact_mismatch', 'field': field,
|
||||
'expected': wanted, 'actual': actual})
|
||||
observed = set()
|
||||
unreadable = 0
|
||||
for line in (args.trial / 'events.jsonl').read_text().splitlines():
|
||||
event = json.loads(line)
|
||||
item = event.get('item', {})
|
||||
if event.get('type') != 'item.completed' or item.get('type') != 'mcp_tool_call':
|
||||
continue
|
||||
# Only producer envelopes and bridge audit IDs establish retention.
|
||||
ids, skipped = producer_ids(item.get('result') or {})
|
||||
observed |= ids
|
||||
unreadable += skipped
|
||||
cited = evidence_ids(answer.get('evidence_ids'))
|
||||
if args.task == 'electron-inventory':
|
||||
for branch in answer.get('unexplored_branches', []):
|
||||
if isinstance(branch, dict):
|
||||
cited |= evidence_ids(branch.get('evidence_id'))
|
||||
if not cited:
|
||||
failures.append({'kind': 'missing_evidence_references'})
|
||||
if cited - observed:
|
||||
failures.append({'kind': 'unobserved_evidence_ids', 'ids': sorted(cited - observed)})
|
||||
result = {'task': args.task,
|
||||
'grader_sha256': hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
|
||||
'scope': 'producer_fact_parity_and_reference_existence_not_runtime_accuracy',
|
||||
'passed': not failures, 'fact_assertions': len(expected),
|
||||
'answer_format': answer_format,
|
||||
'unreadable_result_texts': unreadable,
|
||||
'cited_evidence_ids': sorted(cited), 'failures': failures}
|
||||
(args.trial / 'grade.json').write_text(json.dumps(result, indent=2) + '\n')
|
||||
print(json.dumps(result))
|
||||
raise SystemExit(0 if result['passed'] else 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Generated
-518
@@ -1,518 +0,0 @@
|
||||
{
|
||||
"name": "rea-codemode-experiment",
|
||||
"version": "0.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rea-codemode-experiment",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/client": "2.3.1",
|
||||
"@modelcontextprotocol/server": "2.3.1",
|
||||
"js-tiktoken": "1.0.21",
|
||||
"json-schema-to-typescript": "16.0.0",
|
||||
"quickjs-emscripten": "0.32.0",
|
||||
"zod": "4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ajv": "8.20.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "24.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@apidevtools/json-schema-ref-parser": {
|
||||
"version": "11.9.3",
|
||||
"resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.9.3.tgz",
|
||||
"integrity": "sha512-60vepv88RwcJtSHrD6MjIL6Ta3SOYbgfnkHb+ppAVK+o9mXprRtulx7VlRl3lN3bbvysAfCS7WMVfhUYemB0IQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jsdevtools/ono": "^7.1.3",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/philsturgeon"
|
||||
}
|
||||
},
|
||||
"node_modules/@apidevtools/json-schema-ref-parser/node_modules/js-yaml": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
|
||||
"integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/puzrin"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nodeca"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
},
|
||||
"bin": {
|
||||
"js-yaml": "bin/js-yaml.js"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-ffi-types": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-ffi-types/-/quickjs-ffi-types-0.32.0.tgz",
|
||||
"integrity": "sha512-v9T+GQpmk43VDJ7d72sf0Nexhk+ArvtUihW27dy7lqAl0zBObFKtSBBIm5RBjwIhE8VwsPPm9PNuvPvNqLWUEg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-debug-asyncify": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-debug-asyncify/-/quickjs-wasmfile-debug-asyncify-0.32.0.tgz",
|
||||
"integrity": "sha512-EX8zbXwGqCgAE764M+qvkHtyXDi/FUoMBea0JnES7vCM3P7a2+EOZOjGv85wtZ2sJhI1oJ+nekmqpOODFDY+hw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-debug-sync": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-debug-sync/-/quickjs-wasmfile-debug-sync-0.32.0.tgz",
|
||||
"integrity": "sha512-LeYWrPGC1uNCTBWvibo3ZLJj0CSVNYUXvJpXMCmuQ5Sap2cCACc3uvGvYV4homHHBAzfw5akoTqMMS4YFRtw+Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-release-asyncify": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-release-asyncify/-/quickjs-wasmfile-release-asyncify-0.32.0.tgz",
|
||||
"integrity": "sha512-3oSwPfja12ICz4aIblB58cuY8JlEq5Txt8Cut4VLo+LH47QN+mzCnSgnbB03hWzg1LBcc+VyyI9UOag7a1NF+Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-release-sync": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-release-sync/-/quickjs-wasmfile-release-sync-0.32.0.tgz",
|
||||
"integrity": "sha512-BKNDI/TPBfGlLNGYpLrhcDGXmIk4xHm4MRAisOBnOzpXVn9HZWsfmMAc9WMBrAHjvvds6HOikKeaOBKdPdpVrg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jsdevtools/ono": {
|
||||
"version": "7.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz",
|
||||
"integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@modelcontextprotocol/client": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/client/-/client-2.3.1.tgz",
|
||||
"integrity": "sha512-mIGZXpHsjnZ6lD+gD/WCMpR5k8yVQQ8nNFH1N0Srf7AvnwTUMYD6pvTY8ng2+He5FfV7YMZLmrjL7cLa/cc3dQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/core": "2.3.1",
|
||||
"cross-spawn": "^7.0.5",
|
||||
"eventsource": "^3.0.2",
|
||||
"eventsource-parser": "^3.0.8",
|
||||
"jose": "^6.1.3",
|
||||
"pkce-challenge": "^5.0.0",
|
||||
"zod": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@modelcontextprotocol/core": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-laVmIhPGpWi7rG9q+0UigblRN0Hws/Yjlb6qLFtVqryXVLkc4h+yN8z731POD2LnAGQlFe7/tXhUm7Bi0YB91g==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"zod": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@modelcontextprotocol/server": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/server/-/server-2.3.1.tgz",
|
||||
"integrity": "sha512-e59MfWuSssj6DoQ96JCTqdW1AXT5/XtnTl0WWd6MU1Ka434fFUGGosCLJbGNySDhHGvxQWoRWK137FXYFkYNWw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/core": "2.3.1",
|
||||
"zod": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.17.26",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.26.tgz",
|
||||
"integrity": "sha512-48NWfiY6oNcKOh47Z4h+sIvwcQR91h6KPhaYKgeMIrkT2jV82Gy90SErj60vW8jQbeMSOSbhIv3bZ7JoqPPVhA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/ajv": {
|
||||
"version": "8.20.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
|
||||
"integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"fast-uri": "^3.0.1",
|
||||
"json-schema-traverse": "^1.0.0",
|
||||
"require-from-string": "^2.0.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/epoberezkin"
|
||||
}
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||
"license": "Python-2.0"
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"path-key": "^3.1.0",
|
||||
"shebang-command": "^2.0.0",
|
||||
"which": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/eventsource": {
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz",
|
||||
"integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"eventsource-parser": "^3.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eventsource-parser": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz",
|
||||
"integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-uri": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz",
|
||||
"integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fastify"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/fdir": {
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
|
||||
"integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"picomatch": "^3 || ^4"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"picomatch": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/jose": {
|
||||
"version": "6.2.12",
|
||||
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.12.tgz",
|
||||
"integrity": "sha512-9NiFmJEex0sy2Dk58j2UGBSHgUs2ypF9eZSu4L6vjOX3Dp96Sw1F3uL+H+D1sx02jZZdzUT0HgvCy59CuvXcWw==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/panva"
|
||||
}
|
||||
},
|
||||
"node_modules/js-tiktoken": {
|
||||
"version": "1.0.21",
|
||||
"resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.21.tgz",
|
||||
"integrity": "sha512-biOj/6M5qdgx5TKjDnFT1ymSpM5tbd3ylwDtrQvFQSu0Z7bBYko2dF+W/aUkXUPuk6IVpRxk/3Q2sHOzGlS36g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.5.1"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "5.4.3",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.4.3.tgz",
|
||||
"integrity": "sha512-yzzNtgczwgoVHNigCyKTXcQJU4Y8t/ikU4UxXW0BvrLfHTGWZhsNcOT2s/a7vn81/4KqVnNmHjaUEPlvWnNwVw==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/puzrin"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nodeca"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
},
|
||||
"bin": {
|
||||
"js-yaml": "bin/js-yaml.mjs"
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-to-typescript": {
|
||||
"version": "16.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-to-typescript/-/json-schema-to-typescript-16.0.0.tgz",
|
||||
"integrity": "sha512-Ah6kK4q6SjlMzWBH1eNOQkdRh5Qhr5T/RCFwfjQqWZA7UDW+N47A8wfyoiN0L884s4L4bAEI54IjIuN3/u0B/A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apidevtools/json-schema-ref-parser": "^11.9.3",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/lodash": "^4.17.25",
|
||||
"js-yaml": "^5.2.3",
|
||||
"lodash": "^4.18.1",
|
||||
"minimist": "^1.2.8",
|
||||
"prettier": "^3.9.6",
|
||||
"tinyglobby": "^0.2.17"
|
||||
},
|
||||
"bin": {
|
||||
"json2ts": "dist/src/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-traverse": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.18.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz",
|
||||
"integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/path-key": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
||||
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/picomatch": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
|
||||
"integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/pkce-challenge": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz",
|
||||
"integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=16.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.9.10",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.10.tgz",
|
||||
"integrity": "sha512-skGHTH1Yb9QvaTC4hWnRTzEYtCpApF0UMBPz+t/0ZPzP8ihefo/btKd+QA7pUE0fEwA1SbS/NmhyEcstdXOIdA==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/quickjs-emscripten": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/quickjs-emscripten/-/quickjs-emscripten-0.32.0.tgz",
|
||||
"integrity": "sha512-So0Sqw869y/S2oE3Nuc0uT3Dhqgvsj8FSrwBdsuTosVsG8ME5/OcudU1GxsrIFdFABgy17GHnTVO9TYV/bLQcA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-wasmfile-debug-asyncify": "0.32.0",
|
||||
"@jitl/quickjs-wasmfile-debug-sync": "0.32.0",
|
||||
"@jitl/quickjs-wasmfile-release-asyncify": "0.32.0",
|
||||
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
||||
"quickjs-emscripten-core": "0.32.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/quickjs-emscripten-core": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/quickjs-emscripten-core/-/quickjs-emscripten-core-0.32.0.tgz",
|
||||
"integrity": "sha512-QFnPfjFey8EqknSrSxe1hZrf1/8z7/6s1QzGOmKo6++02r7QRRX7ZoyNaZh7JuVjWsVW87KnQrbZqnHkOAzUyg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-from-string": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
||||
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"shebang-regex": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-regex": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.17",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
|
||||
"integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fdir": "^6.5.0",
|
||||
"picomatch": "^4.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isexe": "^2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"node-which": "bin/node-which"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"name": "rea-codemode-experiment",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "24.18.0"
|
||||
},
|
||||
"packageManager": "npm@11.16.0",
|
||||
"scripts": {
|
||||
"test": "node --test bridge.test.mjs",
|
||||
"start": "node bridge.mjs",
|
||||
"bench": "node benchmark.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/client": "2.3.1",
|
||||
"@modelcontextprotocol/server": "2.3.1",
|
||||
"js-tiktoken": "1.0.21",
|
||||
"json-schema-to-typescript": "16.0.0",
|
||||
"quickjs-emscripten": "0.32.0",
|
||||
"zod": "4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ajv": "8.20.0"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
Statically investigate the actual shipped APK at {{artifact_path}} using only the registered REA tools. Report the exact artifact SHA-256, package name, version name/code, every class-name match for the case-sensitive substring MainActivity, and all onCreate method descriptors reported for org.schabi.newpipe.MainActivity. Preserve reported signatures and explicit unknowns. For each onCreate entry include reported_signature, overload_index and dex_descriptor exactly as reported, preserving null. Final answer must be JSON with artifact_sha256, package_name, version_name, version_code, matches, onCreate, evidence_ids, limitations. Include real Evidence IDs supporting each result. Do not execute the APK or use shell, host file tools, network or other agents. Stop once these facts are supported.
|
||||
|
||||
When a client JavaScript executor is available, compose the required REA calls in one execution and return only selected facts from normalized_result, real Evidence IDs, target identity from subject.digest.sha256 and limitations. Parse original MCP text content if necessary. Do not return raw_result, whole Evidence or unrelated inventories. All matching classes and onCreate overloads must still be included.
|
||||
@@ -1 +0,0 @@
|
||||
Statically inventory {{artifact_path}} using only the registered REA tools. Open this ASAR as an archive, inspect its artifact inventory, and close the session. Report exact target SHA-256, the complete inventory manifest, counts of every entry_kind across all occurrences, the original occurrence records for root paths package.json, main.js and preload.js if present, all integrity contradictions, inspection coverage, unexplored branches, real Evidence IDs and limitations. This question asks about package bytes and inventory, not AST interpretation or runtime behavior. Do not execute target code, analyze all JavaScript, extract files, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose original calls in dependency order and return only requested fields from normalized_result; the full inventory is the Evidence nested in the inspect_artifact inventory_artifact substep. Use Evidence.subject.digest.sha256 for the target identity and retain both inspection and inventory Evidence IDs. Final JSON fields: artifact_sha256, manifest, entry_kind_counts, requested_paths, integrity_contradictions, coverage, unexplored_branches, evidence_ids, limitations. Stop when these facts and cleanup are supported. Use the original open_binary, inspect_artifact and close_binary operations, with integrity_policy=fail. The inventory Evidence has normalized_result.manifest and normalized_result.occurrences; each occurrence has entry_kind and logical_path. Count the complete occurrences array and filter those three exact root logical_path values. Keep the complete inventory inside the executor when one is available; return the requested projection.
|
||||
@@ -1 +0,0 @@
|
||||
Statically inventory {{artifact_path}} using only the registered REA tools. Open this ASAR as an archive, inspect its artifact inventory, and close the session. Report exact target SHA-256, the complete inventory manifest, counts of every entry_kind across all occurrences, the original occurrence records for root paths package.json, main.js and preload.js if present, all integrity contradictions, inspection coverage, unexplored branches, real Evidence IDs and limitations. This question asks about package bytes and inventory, not AST interpretation or runtime behavior. Do not execute target code, analyze all JavaScript, extract files, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose original calls in dependency order and return only requested fields from normalized_result; the full inventory is the Evidence nested in the inspect_artifact inventory_artifact substep. Use Evidence.subject.digest.sha256 for the target identity and retain both inspection and inventory Evidence IDs. Final JSON fields: artifact_sha256, manifest, entry_kind_counts, requested_paths, integrity_contradictions, coverage, unexplored_branches, evidence_ids, limitations. Stop when these facts and cleanup are supported.
|
||||
@@ -1 +0,0 @@
|
||||
Statically inspect {{artifact_path}} using only the registered REA tools. Report exact target SHA-256 and every reported firmware region with offsets, signatures, reported extents, provider provenance and examined coverage. Preserve unknowns and limitations; a signature scan does not prove partition boundaries or boot/runtime validity. Do not execute target code, extract files, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, select the requested normalized_result fields, Evidence.subject.digest.sha256 and real Evidence IDs before returning output. Final JSON fields: artifact_sha256, result, evidence_ids, limitations. Stop when the requested facts are supported.
|
||||
@@ -1 +0,0 @@
|
||||
Statically inspect {{artifact_path}} using only the registered REA tools. Report exact target SHA-256, assembly name/version, module name/MVID, managed classification and architecture with its evidence, every reported target framework, and all declared native ModuleRef/PInvoke boundaries with coverage and limitations. Do not load or execute the assembly, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose the required original MCP calls and return only requested normalized_result fields, target identity from subject.digest.sha256 and real Evidence IDs. Do not return whole Evidence, raw_result or unrelated resources/custom-attribute inventories. Preserve dependency order for operations sharing the selected managed target. Final JSON fields: artifact_sha256, assembly, module, classification, target_frameworks, native_boundaries, coverage, evidence_ids, limitations. Stop when these facts are supported.
|
||||
@@ -1 +0,0 @@
|
||||
Statically inspect {{artifact_path}} using only the registered REA tools and Ghidra. The pinned ELF header was independently observed to report entry address 0x403a50; treat that address as the analyst's seed, not as a function-name assumption. Keep default auto-analysis enabled and allow at least 600 seconds for native analysis (including the script deadline if using a bridge). Open the target with provider_id ghidra, resolve the containing procedure for that address, analyze it, and close the ephemeral session in a finally block or a subsequent cleanup call. Report exact target SHA-256, the entry_address, containing_procedure, procedure metadata, the first 512 UTF-16 units of pseudocode, caller_count, callee_count, real Evidence IDs and limitations. Do not execute target code, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose the original calls in dependency order and select requested fields before returning output; use Evidence.subject.digest.sha256 for the target identity. Final JSON fields: artifact_sha256, entry_address, containing_procedure, procedure, pseudocode_prefix, caller_count, callee_count, evidence_ids, limitations. The address seed applies only to the pinned jq artifact in corpus.json. Stop when these facts and cleanup are supported.
|
||||
@@ -1,127 +0,0 @@
|
||||
"""Run one owned experiment in a bounded, transient Linux systemd scope."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
|
||||
|
||||
def available_bytes():
|
||||
for line in Path('/proc/meminfo').read_text().splitlines():
|
||||
if line.startswith('MemAvailable:'):
|
||||
return int(line.split()[1]) * 1024
|
||||
raise RuntimeError('MemAvailable unavailable')
|
||||
|
||||
|
||||
def scope_has_processes(group):
|
||||
if group is None:
|
||||
return False
|
||||
try:
|
||||
return bool((group / 'cgroup.procs').read_text().strip())
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
|
||||
def stop_owned_scope(unit, process, group):
|
||||
subprocess.run(['systemctl', '--user', 'stop', '--no-block', unit],
|
||||
check=False, timeout=5)
|
||||
for attempt in range(2):
|
||||
deadline = time.monotonic() + 10
|
||||
while process.poll() is None or scope_has_processes(group):
|
||||
if time.monotonic() >= deadline:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
return
|
||||
if attempt == 1:
|
||||
raise RuntimeError('Cleanup unverified; retain owned scope ' + unit)
|
||||
subprocess.run(['systemctl', '--user', 'kill', '--kill-who=all',
|
||||
'--signal=SIGKILL', unit], check=False, timeout=5)
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if args and args[0] == '--':
|
||||
args = args[1:]
|
||||
if not args:
|
||||
raise SystemExit('Usage: resource-run.py -- COMMAND ARGS...')
|
||||
gib = 1024 ** 3
|
||||
if available_bytes() < 8 * gib:
|
||||
raise SystemExit('Refusing experiment: less than 8 GiB available')
|
||||
unit = 'rea-codemode-' + uuid.uuid4().hex + '.scope'
|
||||
cpu = max(os.sched_getaffinity(0))
|
||||
command = [
|
||||
'systemd-run', '--user', '--scope', '--unit=' + unit,
|
||||
'-p', 'MemoryMax=4G', '-p', 'MemoryHigh=3G', '-p', 'MemorySwapMax=0',
|
||||
'-p', 'CPUQuota=100%', '-p', 'TasksMax=192',
|
||||
'taskset', '-c', str(cpu), *args,
|
||||
]
|
||||
process = subprocess.Popen(command)
|
||||
peak = 0
|
||||
peak_tasks = 0
|
||||
events = {}
|
||||
cpu_stats = {}
|
||||
abort = None
|
||||
started = time.monotonic()
|
||||
try:
|
||||
group = None
|
||||
while process.poll() is None:
|
||||
if group is None:
|
||||
reply = subprocess.run(
|
||||
['systemctl', '--user', 'show', unit, '--value',
|
||||
'--property=ControlGroup'],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
path = reply.stdout.strip()
|
||||
if path:
|
||||
group = Path('/sys/fs/cgroup') / path.lstrip('/')
|
||||
current = group / 'memory.current' if group else None
|
||||
if current and current.exists():
|
||||
try:
|
||||
peak = max(peak, int(current.read_text()))
|
||||
peak_tasks = max(peak_tasks, int((group / 'pids.current').read_text()))
|
||||
cpu_stats = dict((key, int(value)) for key, value in
|
||||
(line.split() for line in (group / 'cpu.stat').read_text().splitlines()))
|
||||
for event_file in ['memory.events', 'pids.events']:
|
||||
events[event_file] = dict(
|
||||
(key, int(value)) for key, value in
|
||||
(line.split() for line in (group / event_file).read_text().splitlines())
|
||||
)
|
||||
except FileNotFoundError:
|
||||
# A completed transient scope can disappear between reads.
|
||||
pass
|
||||
if peak > 3 * gib:
|
||||
abort = 'scope_memory_early_stop'
|
||||
elif available_bytes() < 4 * gib:
|
||||
abort = 'host_available_memory_early_stop'
|
||||
elif events.get('pids.events', {}).get('max', 0):
|
||||
abort = 'scope_task_limit_observed'
|
||||
if abort:
|
||||
stop_owned_scope(unit, process, group)
|
||||
break
|
||||
time.sleep(0.1)
|
||||
code = process.wait()
|
||||
except BaseException:
|
||||
stop_owned_scope(unit, process, group)
|
||||
raise
|
||||
finally:
|
||||
if scope_has_processes(group):
|
||||
stop_owned_scope(unit, process, group)
|
||||
print(json.dumps({
|
||||
'resource_scope': unit, 'peak_cgroup_bytes_sampled': peak,
|
||||
'elapsed_seconds': round(time.monotonic() - started, 3),
|
||||
'abort': abort, 'hard_memory_bytes': 4 * gib,
|
||||
'early_stop_bytes': 3 * gib, 'cpu_quota_percent': 100,
|
||||
'cpu_affinity': [cpu],
|
||||
'task_ceiling': 192, 'peak_tasks_sampled': peak_tasks,
|
||||
'resource_events_last_observed': events,
|
||||
'cpu_stat_last_observed': cpu_stats,
|
||||
}), file=sys.stderr)
|
||||
raise SystemExit(125 if abort else code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,367 +0,0 @@
|
||||
# Preliminary measurements
|
||||
|
||||
These are real Codex CLI 0.161.0 trials on the frozen checkout, using
|
||||
`gpt-5.6-terra`, high reasoning, one CPU and a guarded memory scope. The task
|
||||
called `binary_session` once and requested open state and server identity. This
|
||||
is a health probe, not an investigation benchmark. API input tokens are cumulative
|
||||
across model steps; cached tokens are a subset, not an additional cost.
|
||||
|
||||
| Profile | Seconds | Input tokens | Cached input | Output tokens | Outcome |
|
||||
| ---------------------------------- | ------: | -----------: | -----------: | ------------: | --------------------------------------------------------------- |
|
||||
| Direct MCP | 47.635 | 103154 | 70656 | 940 | Correct closed state; identity omitted after preview truncation |
|
||||
| Client Code Mode flag | 67.345 | 197315 | 157696 | 1458 | Correct closed state; extra failed resource lookup |
|
||||
| Client Code Mode only flag | 54.276 | 126609 | 84992 | 939 | Correct closed state; identity omitted |
|
||||
| Bridge, original prompt | 300.173 | unavailable | unavailable | unavailable | Timeout before any completed tool call |
|
||||
| Bridge, explicit projection prompt | 84.790 | 209248 | 175616 | 2125 | Correct closed state/version; conflated catalog identities |
|
||||
|
||||
These prompts and flags do not establish a controlled comparison. The projection
|
||||
trial used a more explicit prompt. The client trials expose nested original MCP
|
||||
calls in their transcripts; the flags alone do not establish code composition or
|
||||
intermediate-result filtering. The timeout is retained as a failed trial without
|
||||
an attributed root cause.
|
||||
|
||||
The direct tool delivered the original session result, including package version
|
||||
6.4.0 and REA's catalog digests. In the bridge projection trial the script selected
|
||||
the nonexistent `server_identity.catalog.digest`, which JavaScript omitted. The
|
||||
answer instead used the bridge's SDK catalog hash. That is not the requested REA
|
||||
identity and must fail that factual check. No unsupported digest is used as an
|
||||
oracle for subsequent trials.
|
||||
|
||||
Discovery was unnecessarily returning entire output schemas. For example, the
|
||||
live `binary_session` output schema occupies 18039 compact JSON bytes, compared
|
||||
with 859 for its input schema. `analyze_javascript_application` uses 41662 and
|
||||
2863 bytes respectively. The complete SDK catalog contains 172 tools and 1986857
|
||||
compact JSON bytes. The bridge now defaults to input schemas and makes unchanged
|
||||
output schemas available explicitly. Actual model savings from this change remain
|
||||
unmeasured.
|
||||
|
||||
The upstream/downstream stdio boundary suite passed all nine tests. The repository
|
||||
typecheck and lint passed under a one-CPU resource scope with a sampled peak of
|
||||
2934038528 bytes. A 2 GiB soft limit caused heavy reclaim during native TypeScript
|
||||
checking; the wrapper's soft limit is now aligned with its 3 GiB early-stop
|
||||
threshold. Its 4 GiB hard ceiling and host-available-memory checks remain in force.
|
||||
An earlier cached-build attempt was killed inside its 2 GiB scope; that is a
|
||||
failed build attempt, not evidence of a host OOM or a benchmark result.
|
||||
|
||||
## Real shipped artifacts
|
||||
|
||||
All acquired bytes match `corpus.json`; ShareX's archive also matches the GitHub
|
||||
asset digest and SQLite's npm archive matches its published SHA-512 integrity.
|
||||
No target was executed. These measurements use real REA providers and SDK stdio,
|
||||
with the same analysis arguments in each compared profile.
|
||||
|
||||
NewPipe's direct, discovery-only replay and bridge replay produce equal selected
|
||||
facts, including exact target digest, package/version, two MainActivity matches,
|
||||
reported `onCreate` signature, overload index and unavailable DEX descriptor. The
|
||||
bridge retains all three real producer IDs. Discovery-only here is a replay cost
|
||||
decomposition, not an implemented new MCP client protocol.
|
||||
|
||||
| Replay delivery | Discovery estimate | Intermediate/final result estimate |
|
||||
| -------------------------------------------------- | -----------------: | ---------------------------------: |
|
||||
| Direct: input definitions only, text content once | 107076 | 94945 |
|
||||
| On-demand input definitions, original text content | 877 | 94945 |
|
||||
| On-demand definitions, one composed projection | 877 | 1057 |
|
||||
|
||||
The bridge also sends 290 estimated tokens of code. Estimates use `cl100k_base`;
|
||||
they are not Terra API tokens, latency or model task success. The direct baseline
|
||||
uses input definitions and single text content, avoiding an inflated comparison
|
||||
against duplicated MCP envelopes or unused output schemas. The full SDK envelope
|
||||
figures, where useful for local transport, are recorded separately.
|
||||
|
||||
ShareX's real PE/CLI metadata and native-boundary workflows agree across direct
|
||||
and bridge: assembly ShareX 19.0.2.0, modern .NET, x86_64, framework
|
||||
`.NETCoreApp,Version=v9.0`, declared native boundaries and explicit coverage.
|
||||
Single text-content estimates are 204766 tokens for the two original results and
|
||||
4148 for the bridge projection. No .NET runtime behavior was verified.
|
||||
|
||||
jq's original trial failed because the stripped shipped executable has no
|
||||
`jq_compile` symbol. The corrected direct trial uses the observed ELF entry
|
||||
`0x403a50`, resolves it to Ghidra's `entry` function and analyzes that function.
|
||||
It succeeds with retained Evidence and a closed ephemeral provider session.
|
||||
The corrected bridge returns identical selected facts and limitations. Its final
|
||||
result estimate is 1544 tokens versus 10189 for direct single-text results, plus
|
||||
1610 for discovery and 267 for code. This small entry function
|
||||
does not establish large-function or complete native-analysis coverage.
|
||||
|
||||
OpenWrt's original direct trial returned `unreadable_output` without the expected
|
||||
report. Twelve independent bounded Binwalk invocations produced reports. An
|
||||
observer launcher and a subsequent unchanged real Binwalk bridge trial succeeded,
|
||||
reporting uImage at offset 0 and SquashFS at 2741985 with `signature_scan` coverage.
|
||||
The observer is a diagnostic with a different launcher identity, not a benchmark
|
||||
baseline. The original failure remains unexplained. Subsequent direct and bridge
|
||||
workflows agree on all region facts and coverage; random upstream region IDs vary
|
||||
and are preserved. Single-text estimates are 1387 tokens direct and 827 projected,
|
||||
so this one-operation task provides much less composition benefit than Android.
|
||||
|
||||
SQLite's actual WASM fails the frozen REA WABT output parser with `Unrecognized
|
||||
WABT section row`. WABT 1.0.42 prints the nine-character DataCount label without
|
||||
leading padding; the owning parser currently requires leading whitespace. No
|
||||
downstream shim is used, and no successful WASM provider claim is made.
|
||||
Obsidian's initial real-model analysis ended without Evidence after Codex's host
|
||||
closed stdout. Its standalone SDK replay returns a real provider timeout with a
|
||||
retained partial Evidence ID. This was observed before automatic partial-summary
|
||||
recovery was added, so the transcript retains that reference but does not export
|
||||
its payload. A source-fixture production-boundary test now verifies that provider
|
||||
timeout IDs survive auditing and resolve through the retained-evidence view.
|
||||
Neither failure is a Code Mode speedup.
|
||||
|
||||
## Real Android agents
|
||||
|
||||
After raising the task ceiling, a direct Terra trial completes in 107.478 seconds
|
||||
with 348556 API input tokens (292608 cached), 1815 output tokens and five completed
|
||||
MCP calls. All six strict producer-fact assertions and cited-ID checks pass. Its
|
||||
sampled peak is 1349251072 bytes and 127 tasks, with zero observed limit events.
|
||||
|
||||
A client Code Mode trial passes the same assertions in 183.361 seconds with
|
||||
414869 input tokens (372480 cached), 3618 output tokens. The transcript must still
|
||||
be inspected before attributing native composition or filtering to that flag.
|
||||
|
||||
The bridge trial before explicit projection guidance takes 84.754 seconds,
|
||||
292063 input tokens (244992 cached) and 1661 output tokens. It returns whole
|
||||
Evidence instead of filtering most intermediates. Requested facts and IDs are
|
||||
supported, but its stronger exact-projection check fails because overload index
|
||||
was omitted. A clarified question explicitly requires that index in later trials.
|
||||
|
||||
The next bridge trial composes three calls and filters their results, but selects
|
||||
`normalized_result.engine.artifact_sha256` as the target hash. This is the Jadx
|
||||
bridge JAR identity, not the APK identity. The strict hash check fails. It takes
|
||||
166.411 seconds and 324417 input tokens (279040 cached), 2362 output tokens.
|
||||
This confirms a real provenance risk in model-written projections. Trial
|
||||
instructions now identify `Evidence.subject.digest.sha256` explicitly. This
|
||||
change has not yet established a reliable repeated model efficiency gain.
|
||||
|
||||
The following bridge trial passes all six assertions and cited-ID checks, using
|
||||
one execution script for all three original operations. It takes 137.966 seconds,
|
||||
190313 input tokens (156672 cached) and 1695 output tokens. Four discovery calls
|
||||
precede the script. This is an encouraging token result, but its revised prompt,
|
||||
instructions and concurrent host workload prevent a controlled speed comparison.
|
||||
Instructions and prompt digests are now retained without authentication or an
|
||||
ambient environment snapshot, so future equal-task repetitions can be audited.
|
||||
|
||||
The 6.1 sol diagnostic touched the 96-task limit; it is invalid as a comparison
|
||||
and was interrupted, with its copied profile removed. The wrapper now allows 192
|
||||
tasks, records task/memory limit events and rejects capacity-limited trials. A
|
||||
real thread-creation probe hit exactly 192 tasks, was stopped with exit 125 and
|
||||
retained its limit reason; it used about 12 MiB and caused no memory-limit event.
|
||||
The nine actual stdio boundary tests pass after discovery changes.
|
||||
|
||||
Wall times above include contention on the same pinned CPU during exploratory
|
||||
work and differing prompts/instructions. They cannot support a controlled speed
|
||||
ratio. A reproducible efficiency conclusion requires successful equal-task trials
|
||||
and serial repetitions with the strongest existing-client baseline.
|
||||
|
||||
The stronger client trial uses an explicit instruction to compose and project the
|
||||
existing operations, and passes all six checks: 72.341 seconds, 161370 input
|
||||
tokens (120576 cached), 1664 output tokens and three completed MCP calls. An
|
||||
equivalent question with the bridge passes in 115.962 seconds, 321295 input tokens
|
||||
(283648 cached), 2274 output tokens, five discovery calls and one execution. The
|
||||
native transcript does not expose executor source, so exact internal composition
|
||||
is unverified. Nevertheless, this measured client profile is a materially stronger
|
||||
baseline than the original repeated-call trial. Total input, uncached input,
|
||||
output and wall time must be considered separately; cached-token differences make
|
||||
total input an incomplete cost metric.
|
||||
|
||||
This reverses the preliminary temptation to equate replay compression with the
|
||||
best Codex experience. Existing client support with explicit Evidence-aware
|
||||
recipes may be enough. An optional bridge needs to justify discovery overhead and
|
||||
remains useful to test for clients without equivalent execution support.
|
||||
|
||||
Eleven actual SDK/stdio tests pass, including a controlled delivery delay after a
|
||||
real upstream result to exercise queued cancellation. Both the delayed call and
|
||||
its queued successor release deferred guest handles before runtime disposal.
|
||||
This test does not simulate or establish new provider behavior.
|
||||
|
||||
The bridge remains an experiment and has not changed any published REA contract.
|
||||
|
||||
## Existing-client and managed follow-up
|
||||
|
||||
The same Android v3 question with normal MCP, without the experimental Code Mode
|
||||
feature flags, passes all six fact assertions and reference checks: 75.117 seconds,
|
||||
103471 API input tokens (73728 cached), 1538 output tokens and three original MCP
|
||||
calls. This is the strongest measured Android baseline so far. Its wall time also
|
||||
includes a short boundary-test overlap, so it is not a controlled latency ratio.
|
||||
The installed model catalog requests code-mode-only tool delivery; flag settings
|
||||
and nested MCP events alone cannot establish the internal executor's behavior.
|
||||
|
||||
The first real ShareX managed-agent comparison uses the same question with Terra
|
||||
high and identical provider settings. Normal MCP takes 81.578 seconds, 217573 input
|
||||
tokens (186368 cached), 2647 output tokens and two original calls. The bridge takes
|
||||
96.930 seconds, 218089 input tokens (155904 cached), 3247 output tokens, four
|
||||
searches and two executions. Its first script uses an expression instead of the
|
||||
required async-body `return`, yielding no projection; it repeats both operations.
|
||||
Query discovery now defaults to lightweight names/descriptions, while exact-name
|
||||
discovery supplies input schemas. This run still requested full output schemas
|
||||
individually and therefore does not establish an efficiency gain from that change.
|
||||
|
||||
Both answers match all seven requested managed fact groups, including exact target
|
||||
SHA-256, assembly/module identities, classification evidence, framework, declared
|
||||
ModuleRef/PInvoke arrays and coverage. Those empty arrays concern ShareX.dll only.
|
||||
The bridge passes cited-reference verification. Codex truncated the original
|
||||
managed-artifact response in its normal-MCP JSONL at roughly one MiB, leaving an
|
||||
invalid JSON fragment; the automated grader cannot validate that one reference
|
||||
from a complete producer envelope. Its reference-failure result is retained,
|
||||
despite the matching ID being visible in the transcript prefix and replay. This
|
||||
is a verification limitation, not a demonstrated fabricated ID.
|
||||
|
||||
The runner now handles SIGTERM so copied trial credentials are removed during a
|
||||
resource abort. A controlled non-model launcher received owned-scope SIGTERM,
|
||||
exited 143 and left no trial profile while preserving the dummy source auth file.
|
||||
This verifies credential cleanup only. The eleven actual stdio tests pass after
|
||||
the adaptive discovery change, with a sampled peak of 1365106688 bytes, 42 tasks
|
||||
and zero observed memory/task limit events.
|
||||
|
||||
## Serial comparison and package inventory
|
||||
|
||||
A serial Android v3 pair, without concurrent provider/build work, passes every
|
||||
fact and cited-reference check. Normal MCP uses 56.962 seconds, 105861 input
|
||||
(75776 cached, 30085 uncached), 1106 output tokens and three original calls. The
|
||||
adaptive-discovery bridge uses 106.134 seconds, 200537 input (175872 cached,
|
||||
24665 uncached), 2177 output tokens, four searches and one execution. Its smaller
|
||||
uncached input does not imply lower overall cost: output, cache rates and latency
|
||||
also matter. It still requests original output schemas and mistakenly searches
|
||||
for the already exposed bridge executor. Sampled memory peaks are 1333710848 and
|
||||
1656098816 bytes respectively; neither run touches memory/task limits. One pair
|
||||
is insufficient for a statistical latency or reliability claim.
|
||||
|
||||
A separate Obsidian package-inventory replay succeeds with existing REA tools.
|
||||
Direct and bridge return byte-for-byte equal selected facts: 397 graph nodes and
|
||||
occurrences, 369 files, 28 directories, root main.js/package.json occurrences,
|
||||
no root preload.js, no observed integrity contradiction, complete-within-substeps
|
||||
coverage and an explicit unexplored JavaScript analysis branch. Both original
|
||||
Evidence IDs are preserved. Direct/bridge operations take 6.267/6.618 seconds;
|
||||
original single-text results total 178958 estimated tokens versus a 1404-token
|
||||
bridge result, 1305 for discovery and 322 for code. These are replay estimates,
|
||||
not model latency or success. Inventory does not complete the timed-out AST task.
|
||||
|
||||
An output-type discovery probe compiles seven real SDK schemas successfully.
|
||||
Derived TypeScript estimates are 784/719/751 tokens for Android package/search/
|
||||
class, 1558/1420 for managed artifact/native boundaries, 1264 for artifact inventory
|
||||
and 2289 for function analysis. Their original JSON schemas use 1666/1480/1576,
|
||||
3524/2932, 2812 and 5091 respectively. These declarations describe code values;
|
||||
they do not preserve every JSON Schema validation rule. Exact-name discovery now
|
||||
includes them without replacing explicitly requested original JSON schemas. Real
|
||||
model benefit from this addition remains to be tested. The audit also carries
|
||||
original Evidence links; a real retained-view readback verifies linked IDs rather
|
||||
than trusting references invented by a projection.
|
||||
|
||||
The output-declaration boundary suite first failed its type-name assertion because
|
||||
the compiler preferred the schema's URN identity as a display name. The derived
|
||||
compilation now supplies a descriptive title while returning the original schema
|
||||
unchanged. All eleven tests then pass, including original-link readback, at a
|
||||
sampled peak of 1399996416 bytes and zero observed limit events. Declarations are
|
||||
cached per exact tool name for this immutable live-catalog connection; repeated
|
||||
discovery does not regenerate them. No provider implementation or published
|
||||
REA API has changed.
|
||||
|
||||
## Typed-discovery serial agent checkpoint
|
||||
|
||||
All rows below use real Codex CLI 0.161.0, Terra high, the same rendered question
|
||||
within each pair, and the same provider settings. The bridge/runtime/runner source
|
||||
fingerprints match commit `22326e819`; model-written original arguments can differ.
|
||||
Comparisons include required mode-specific instructions and are not a controlled
|
||||
causal decomposition of inference, caching and provider time.
|
||||
|
||||
| Case | Profile | Wall seconds | Input | Cached | Uncached | Output | MCP calls | Fact/reference check |
|
||||
| ------------------ | ------- | -----------: | -----: | -----: | -------: | -----: | --------: | --------------------------------- |
|
||||
| android | direct | 67.329 | 107007 | 83712 | 23295 | 1670 | 3 | pass |
|
||||
| android | bridge | 48.231 | 113256 | 91648 | 21608 | 1456 | 3 | pass |
|
||||
| managed | bridge | 73.145 | 116974 | 92672 | 24302 | 2065 | 3 | classification field omitted |
|
||||
| managed | direct | 33.15 | 108096 | 75776 | 32320 | 2315 | 2 | facts match; reference unverified |
|
||||
| electron-inventory | direct | 89.494 | 266121 | 238848 | 27273 | 3215 | 3 | pass |
|
||||
| electron-inventory | bridge | 145.577 | 462809 | 407040 | 55769 | 5624 | 8 | pass |
|
||||
| firmware | bridge | 81.944 | 152886 | 126976 | 25910 | 2192 | 3 | pass |
|
||||
| firmware | direct | 30.161 | 103224 | 74752 | 28472 | 1761 | 1 | pass |
|
||||
|
||||
The managed bridge omits the producer classification container field (`pe`) while
|
||||
preserving status/runtime/implementation/architecture and all classification
|
||||
evidence. Its strict complete-classification assertion fails; this is an omission,
|
||||
not an incorrect architecture claim. Normal MCP matches requested facts but its
|
||||
large-result JSONL truncation again prevents automated verification of one ID.
|
||||
|
||||
The initial grader treated grouped path records, extra known coverage counts and
|
||||
an empty per-source contradiction object as mismatches. Task-specific comparison
|
||||
now accepts those lossless report forms. Firmware compares observed offset/length
|
||||
facts, checks any supplied derived end arithmetically, and verifies engine version
|
||||
and executable digest. Run-local UUIDs and differently named display fields are
|
||||
not compared as if they were stable source identity. Original strict grades and
|
||||
pre-equivalence grades remain outside Git, and new grades include a grader digest.
|
||||
These report-format comparisons do not add aliases to any REA tool contract.
|
||||
|
||||
Obsidian bridge discovery takes six searches and two executions. The first returns
|
||||
the entire nested inventory; the second repeats it and computes a focused answer.
|
||||
The live nested Evidence schema describes normalized_result as generic JSON, so
|
||||
derived types alone cannot teach its concrete manifest/occurrences layout. Its
|
||||
recursive record walk happens to match this corpus, but format-specific field
|
||||
selection is the stronger recipe. Both model profiles choose record-and-continue
|
||||
for integrity; deterministic inventory replays used fail. No contradictions were
|
||||
observed, and the exact caller-selected arguments are retained.
|
||||
|
||||
## Completed serial cohort
|
||||
|
||||
The final sixteen-row cohort, raw-event digests, exact runner/bridge/lockfile
|
||||
fingerprints, prompt/instruction/provider digests and sampled resource stats are
|
||||
in [agent-results.json](agent-results.json). The requested model configuration is
|
||||
Terra high. Two managed bridge answers omit the classification container field
|
||||
under the stronger full-object check; two normal-MCP managed logs have a truncated
|
||||
producer envelope. The twelve other rows pass requested fact and observed-reference
|
||||
checks. This is producer parity, not independent runtime truth or a per-fact
|
||||
citation-association proof. Earlier stricter report-form grades remain retained.
|
||||
|
||||
| Trial | Wall seconds | Input | Cached | Uncached | Output | MCP calls | Check |
|
||||
| ---------------------------------- | -----------: | -----: | -----: | -------: | -----: | --------: | --------------------------------- |
|
||||
| android-direct-5 | 67.329 | 107007 | 83712 | 23295 | 1670 | 3 | pass |
|
||||
| android-bridge-7 | 48.231 | 113256 | 91648 | 21608 | 1456 | 3 | pass |
|
||||
| managed-bridge-2 | 73.145 | 116974 | 92672 | 24302 | 2065 | 3 | classification container omitted |
|
||||
| managed-direct-2 | 33.150 | 108096 | 75776 | 32320 | 2315 | 2 | facts match; reference unverified |
|
||||
| electron-inventory-direct-1 | 89.494 | 266121 | 238848 | 27273 | 3215 | 3 | pass |
|
||||
| electron-inventory-bridge-1 | 145.577 | 462809 | 407040 | 55769 | 5624 | 8 | pass |
|
||||
| firmware-bridge-1 | 81.944 | 152886 | 126976 | 25910 | 2192 | 3 | pass |
|
||||
| firmware-direct-1 | 30.161 | 103224 | 74752 | 28472 | 1761 | 1 | pass |
|
||||
| native-direct-1 | 327.150 | 151343 | 122368 | 28975 | 2458 | 4 | pass |
|
||||
| native-bridge-1 | 334.642 | 285961 | 245504 | 40457 | 2129 | 4 | pass |
|
||||
| android-bridge-8 | 134.555 | 159370 | 134400 | 24970 | 3250 | 7 | pass |
|
||||
| android-direct-6 | 71.624 | 153031 | 117504 | 35527 | 1501 | 3 | pass |
|
||||
| managed-direct-3 | 75.229 | 108593 | 75776 | 32817 | 2774 | 2 | facts match; reference unverified |
|
||||
| managed-bridge-3 | 40.609 | 125519 | 96000 | 29519 | 2274 | 3 | classification container omitted |
|
||||
| electron-inventory-guided-bridge-1 | 85.909 | 101994 | 61440 | 40554 | 2563 | 3 | pass |
|
||||
| electron-inventory-guided-direct-1 | 67.540 | 263484 | 221952 | 41532 | 2499 | 4 | pass |
|
||||
|
||||
Ghidra's aggregate sampled CPU time is 263.738 seconds directly and 271.096 with
|
||||
the bridge. The bridge uses three original operations versus four directly,
|
||||
obtaining containing identity from the analyzed procedure. Both close the session
|
||||
successfully. The native comparison uses the same default analysis settings;
|
||||
these data do not establish a meaningful native speedup.
|
||||
|
||||
The second Android bridge repetition completes seven original calls across five
|
||||
scripts, without tool errors, before its final composed answer. Its 134.555-second
|
||||
result reverses the first repetition's latency advantage. The model did not
|
||||
reliably choose one composed execution even with explicit guidance. Uncached
|
||||
input is lower in both bridge repetitions, while output and latency vary.
|
||||
|
||||
The guided Electron question explicitly names the existing operations and the
|
||||
nested inventory's manifest/occurrences layout for both profiles. Both pass, with
|
||||
integrity_policy=fail. The bridge composes open/inspect/close once; the normal-MCP
|
||||
profile repeats inspect_artifact. The total-input reduction from 263484 to 101994
|
||||
is large, but uncached input differs by only 978 tokens and bridge latency is
|
||||
higher. Earlier non-guided profiles are a different question and cannot support
|
||||
a causal prompt-improvement ratio. Unknown nested payload types remain an observed
|
||||
contract-discovery problem; caller-selected values and identities are preserved.
|
||||
|
||||
All sixteen runs stay below memory/task ceilings, with maximum sampled memory
|
||||
1659744256 bytes and 126 tasks; no observed memory/task limit event or resource
|
||||
abort occurs. Copied profile count is zero at completion. Runtime measurements
|
||||
belong to the recorded source fingerprint at 22326e819; subsequent timer-range
|
||||
validation and test-only Ajv installation are not new model measurements.
|
||||
|
||||
Final boundary verification passes twelve actual SDK/stdio tests. A 2 MiB guest
|
||||
budget rejects allocation pressure and the next execution succeeds. This is a
|
||||
guest-budget failure, not an OS OOM or provider behavior claim. A local pinned-Node
|
||||
probe shows a 2147483648-ms timeout becomes 1 ms; the owning named execution
|
||||
contract now rejects that range before allocation. After SDK conversion, both
|
||||
advertised bridge input schemas validate under JSON Schema 2020-12, and the actual
|
||||
stdio client rejects invalid code, oversized memory and timer values. Sampled
|
||||
suite memory peaks at 1387433984 bytes, with zero observed memory/task limit events.
|
||||
|
||||
See [decision.md](decision.md) for the recommendation: keep current REA contracts,
|
||||
improve focused Evidence-aware workflow guidance, and retain the bridge as an
|
||||
opt-in candidate. A broad default switch is not justified by these samples.
|
||||
@@ -55,6 +55,7 @@
|
||||
"bridge/ghidra/ReaGhidraPrepareCom.java",
|
||||
"bridge/ghidra/ReaGhidraApplySeeds.java",
|
||||
"bridge/ghidra/ReaGhidraNoReturnFix.java",
|
||||
"bridge/ghidra/ReaGhidraPrepareRaw.java",
|
||||
"bridge/android/ReaJadxBridge.java",
|
||||
"bridge/mitmproxy/capture.py",
|
||||
"scripts/rea.mjs",
|
||||
@@ -166,6 +167,7 @@
|
||||
"verify:ghidra:switch": "npm run build:cached && node scripts/verify-real-ghidra-switch.mjs",
|
||||
"verify:ghidra:dos": "npm run build:cached && node scripts/verify-real-ghidra-dos.mjs",
|
||||
"verify:ghidra:com": "npm run build:cached && node scripts/verify-real-ghidra-com.mjs",
|
||||
"verify:ghidra:raw": "npm run build:cached && node scripts/verify-real-ghidra-raw.mjs",
|
||||
"verify:ghidra:aarch64-jump-table": "npm run build:cached && node scripts/verify-real-ghidra.mjs --aarch64-jump-table",
|
||||
"verify:interface-builder": "npm run build:cached && node scripts/verify/apple/interface-builder.mjs",
|
||||
"verify:ghidra:cross-format": "npm run build:cached && node scripts/verify-real-ghidra.mjs --cross-format",
|
||||
|
||||
@@ -177,6 +177,7 @@ const scriptCollisions = [
|
||||
"ReaGhidraPrepareCom.java",
|
||||
"ReaGhidraApplySeeds.java",
|
||||
"ReaGhidraNoReturnFix.java",
|
||||
"ReaGhidraPrepareRaw.java",
|
||||
];
|
||||
await mkdir(callerDirectory);
|
||||
for (const name of scriptCollisions) await mkdir(join(callerDirectory, name));
|
||||
@@ -394,15 +395,15 @@ try {
|
||||
return evidence.normalized_result;
|
||||
},
|
||||
);
|
||||
const expected = (
|
||||
const { GHIDRA_MUTATING_OPERATIONS, GHIDRA_SESSION_CAPABILITIES } =
|
||||
await import(
|
||||
pathToFileURL(join(packageRoot, "dist/ghidra/GhidraSessionValues.js"))
|
||||
)
|
||||
).GHIDRA_SESSION_CAPABILITIES.filter(
|
||||
);
|
||||
const expected = GHIDRA_SESSION_CAPABILITIES.filter(
|
||||
(name) =>
|
||||
name !== "ping" &&
|
||||
name !== "shutdown" &&
|
||||
name !== "annotate_native_function",
|
||||
!GHIDRA_MUTATING_OPERATIONS.has(name),
|
||||
);
|
||||
assert.ok(
|
||||
expected.every((name) => report.mcpOperations.includes(name)),
|
||||
@@ -440,7 +441,10 @@ try {
|
||||
token,
|
||||
"Analysis changed caller token authority.",
|
||||
);
|
||||
assert.deepEqual((await readdir(callerDirectory)).sort(), scriptCollisions);
|
||||
assert.deepEqual(
|
||||
(await readdir(callerDirectory)).sort(),
|
||||
[...scriptCollisions].sort(),
|
||||
);
|
||||
for (const name of scriptCollisions)
|
||||
assert.deepEqual(await readdir(join(callerDirectory, name)), []);
|
||||
report.callerScriptCollisionsPreserved = true;
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { inspectGhidraInstallation } from "../dist/ghidra/GhidraInstallation.js";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.argv.length !== 2)
|
||||
throw new Error("Usage: node scripts/verify-real-ghidra-raw.mjs");
|
||||
if (!["linux", "darwin"].includes(process.platform))
|
||||
throw new Error(
|
||||
"Raw-binary verification requires a Linux or macOS Ghidra host.",
|
||||
);
|
||||
if (process.env.GHIDRA_INSTALL_DIR === undefined)
|
||||
throw new Error(
|
||||
"Set GHIDRA_INSTALL_DIR to a bring-your-own Ghidra installation.",
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { javaHome: process.env.JAVA_HOME }),
|
||||
});
|
||||
assert.equal(installation.status, "available", JSON.stringify(installation));
|
||||
|
||||
const run = createVerifierRun();
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-raw-proof-"));
|
||||
const runtime = join(workspace, "runtime");
|
||||
await mkdir(runtime);
|
||||
const bytes = Buffer.from("1eff2fe1", "hex"); // ARM little-endian bx lr.
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
const path = join(workspace, "image.bin");
|
||||
await writeFile(path, bytes);
|
||||
const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const env = {
|
||||
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
||||
TMPDIR: runtime,
|
||||
REA_LOG_LEVEL: "silent",
|
||||
REA_ANALYSIS_PROVIDER: "ghidra",
|
||||
REA_PROCESS_RUN_ID: run.run_id,
|
||||
GHIDRA_INSTALL_DIR: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { JAVA_HOME: process.env.JAVA_HOME }),
|
||||
};
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "rea-real-raw-proof", version: "1" });
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-65536);
|
||||
});
|
||||
let report;
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const profiles = [];
|
||||
const sessions = [];
|
||||
for (const entryPoint of ["0x08000000", "0x8000000", "0x09000000"]) {
|
||||
// Omit provider_id to exercise reuse of the current provider route.
|
||||
const opened = await call("open_binary", {
|
||||
path,
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entry_point: entryPoint,
|
||||
});
|
||||
const entry = `0x${BigInt(entryPoint).toString(16)}`;
|
||||
assert.equal(opened.entry_point, entry);
|
||||
const image = await call("inspect_native_load_image");
|
||||
assert.equal(
|
||||
image.normalized_result.status,
|
||||
"verified",
|
||||
JSON.stringify(image),
|
||||
);
|
||||
assert.equal(image.normalized_result.base_address, entry);
|
||||
assert.equal(image.normalized_result.entry.address, entry);
|
||||
assert.equal(
|
||||
image.normalized_result.observations.language_id,
|
||||
"ARM:LE:32:v7",
|
||||
);
|
||||
assert.ok(
|
||||
image.normalized_result.observations.entry_points.includes(entry),
|
||||
);
|
||||
assert.equal(image.analysis_profile.parameters.entry_point, entry);
|
||||
profiles.push(image.analysis_profile.digest);
|
||||
const status = await call("binary_session");
|
||||
assert.equal(status.entry_point, entry);
|
||||
sessions.push(status.analysis_run.run_id);
|
||||
const memory = await call("read_bytes", {
|
||||
address: entry,
|
||||
length: bytes.length,
|
||||
});
|
||||
assert.equal(memory.normalized_result.bytes_hex, bytes.toString("hex"));
|
||||
const procedures = await call("list_procedures");
|
||||
assert.ok(
|
||||
procedures.normalized_result.some(
|
||||
(procedure) => procedure.address === entry,
|
||||
),
|
||||
);
|
||||
const instruction = await call("inspect_native_instruction", {
|
||||
address: entry,
|
||||
});
|
||||
assert.equal(instruction.normalized_result.address, entry);
|
||||
}
|
||||
assert.equal(profiles[0], profiles[1]);
|
||||
assert.notEqual(profiles[1], profiles[2]);
|
||||
assert.equal(sessions[0], sessions[1]);
|
||||
assert.notEqual(sessions[1], sessions[2]);
|
||||
const rejected = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: {
|
||||
path,
|
||||
format: "raw-binary",
|
||||
architecture: "arm64",
|
||||
entry_point: "0x8000001",
|
||||
},
|
||||
});
|
||||
assert.equal(rejected.isError, true);
|
||||
assert.match(JSON.stringify(rejected.content), /must be 4-byte aligned/);
|
||||
const unchanged = await call("binary_session");
|
||||
assert.equal(unchanged.analysis_run.run_id, sessions[2]);
|
||||
assert.equal(unchanged.entry_point, "0x9000000");
|
||||
await call("close_binary");
|
||||
|
||||
const { stdout } = await promisify(execFile)(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"inspect-native-load-image",
|
||||
path,
|
||||
"--target-format",
|
||||
"raw-binary",
|
||||
"--architecture",
|
||||
"arm",
|
||||
"--entry-point",
|
||||
"0x08000000",
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
{ env, timeout: 240000, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
const cli = parseEvidence(JSON.parse(stdout));
|
||||
assert.equal(cli.subject.digest.sha256, sha256);
|
||||
assert.equal(cli.normalized_result.status, "verified");
|
||||
assert.equal(cli.normalized_result.base_address, "0x8000000");
|
||||
assert.equal(cli.analysis_profile.digest, profiles[0]);
|
||||
assert.deepEqual(await readFile(path), bytes);
|
||||
report = {
|
||||
ok: true,
|
||||
mocked: false,
|
||||
lane: "ghidra-raw",
|
||||
host: process.platform,
|
||||
provider: { id: "ghidra", version: installation.providerVersion },
|
||||
target: {
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
sha256,
|
||||
bytes: bytes.length,
|
||||
},
|
||||
transport: { cli: true, stdio_mcp: true },
|
||||
canonical_entry_reuses_session: true,
|
||||
changed_entry_replaces_session: true,
|
||||
lifecycle_entry_preserved: true,
|
||||
invalid_entry_preserves_active_session: true,
|
||||
load_images_verified: true,
|
||||
original_unchanged: true,
|
||||
};
|
||||
} catch (error) {
|
||||
if (stderr.trim()) process.stderr.write(stderr);
|
||||
throw error;
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
}
|
||||
const verifierRun = await completeVerifierRun(run);
|
||||
assert.equal(verifierRun.process_lineage.status, "verified");
|
||||
assert.deepEqual(verifierRun.process_lineage.descendants, []);
|
||||
process.stdout.write(
|
||||
JSON.stringify({
|
||||
verifier_run: verifierRun,
|
||||
...report,
|
||||
cleanup: "complete",
|
||||
}) + "\n",
|
||||
);
|
||||
|
||||
async function call(name, args = {}) {
|
||||
const result = await client.callTool(
|
||||
{ name, arguments: args },
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
const projected = requireMcpOperationResult(result, name);
|
||||
if (
|
||||
name === "open_binary" ||
|
||||
name === "close_binary" ||
|
||||
name === "binary_session"
|
||||
)
|
||||
return projected;
|
||||
const evidence = parseEvidence(result.structuredContent);
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.equal(evidence.subject.format, "raw-binary");
|
||||
return evidence;
|
||||
}
|
||||
@@ -21,14 +21,17 @@ import { SUPPORTED_GHIDRA_VERSION } from "../dist/ghidra/GhidraInstallationPolic
|
||||
import { GhidraHeadlessLauncher } from "../dist/ghidra/GhidraLauncher.js";
|
||||
import { GHIDRA_PROVIDER_IDENTITY } from "../dist/ghidra/GhidraProviderCapabilities.js";
|
||||
import { windowsP0Capabilities } from "../dist/ghidra/GhidraProviderCapabilities.js";
|
||||
import { GHIDRA_SESSION_CAPABILITIES } from "../dist/ghidra/GhidraSessionValues.js";
|
||||
import {
|
||||
GHIDRA_MUTATING_OPERATIONS,
|
||||
GHIDRA_SESSION_CAPABILITIES,
|
||||
} from "../dist/ghidra/GhidraSessionValues.js";
|
||||
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
||||
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { verifyGhidraCompactReferences } from "./lib/real-ghidra-compact-references.mjs";
|
||||
|
||||
const verifierRun = createVerifierRun();
|
||||
const SESSION_CAPABILITIES = GHIDRA_SESSION_CAPABILITIES.filter(
|
||||
(name) => name !== "annotate_native_function",
|
||||
(name) => !GHIDRA_MUTATING_OPERATIONS.has(name),
|
||||
);
|
||||
|
||||
if (process.platform !== "win32" || process.arch !== "x64")
|
||||
@@ -236,10 +239,8 @@ try {
|
||||
|
||||
const expected = [
|
||||
...GHIDRA_INVENTORY_OPERATIONS,
|
||||
...GHIDRA_FUNCTION_OPERATIONS.filter(
|
||||
(name) => name !== "annotate_native_function",
|
||||
),
|
||||
];
|
||||
...GHIDRA_FUNCTION_OPERATIONS,
|
||||
].filter((name) => !GHIDRA_MUTATING_OPERATIONS.has(name));
|
||||
if (
|
||||
observed.size !== expected.length ||
|
||||
expected.some((operation) => !observed.has(operation))
|
||||
|
||||
@@ -7,13 +7,16 @@ import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../../dist/domain/evidence.js";
|
||||
import { hashAndroidFile } from "../../../dist/android/AndroidTargetSnapshot.js";
|
||||
import { hashAndroidFile } from "./digest.mjs";
|
||||
import { JADX_RELEASE } from "../../../dist/android/JadxRelease.js";
|
||||
import fixture from "../../fixtures/android/apidemos.json" with { type: "json" };
|
||||
import { verifyAndroidCliCancellation } from "./cli-cancellation.mjs";
|
||||
import { verifyAndroidMetadata } from "./metadata.mjs";
|
||||
import { verifyAndroidFailureRecovery } from "./failure-recovery.mjs";
|
||||
import { resolveJadxConfiguration } from "../../../dist/android/JadxConfiguration.js";
|
||||
import {
|
||||
resolveJadxConfigurationInputs,
|
||||
validateJadxConfiguration,
|
||||
} from "../../../dist/android/JadxConfiguration.js";
|
||||
import { verifyWindowsAndroidLifecycle } from "./windows-lifecycle.mjs";
|
||||
|
||||
const repository = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
@@ -35,10 +38,16 @@ assert.equal(
|
||||
JADX_RELEASE.sha256,
|
||||
"Real Android lane requires the audited headless JADX release JAR",
|
||||
);
|
||||
const { java, jvmArguments } = await resolveJadxConfiguration(
|
||||
const configuration = await resolveJadxConfigurationInputs(
|
||||
process.env,
|
||||
"inspect_android_package",
|
||||
);
|
||||
await validateJadxConfiguration(
|
||||
configuration,
|
||||
process.env,
|
||||
"inspect_android_package",
|
||||
);
|
||||
const { java, jvmArguments } = configuration;
|
||||
const execute = promisify(execFile);
|
||||
await execute(java, ["-version"], { timeout: 10_000 });
|
||||
const entrypoint =
|
||||
@@ -52,6 +61,8 @@ await verifyAndroidMetadata({
|
||||
repository,
|
||||
execute,
|
||||
jvmArguments,
|
||||
entrypoint,
|
||||
environment,
|
||||
bridge: resolve(dirname(entrypoint), "../bridge/android/ReaJadxBridge.java"),
|
||||
});
|
||||
const tasks = [
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { createReadStream } from "node:fs";
|
||||
|
||||
/** Verify artifact identity without depending on private runtime snapshot helpers. */
|
||||
export const hashAndroidFile = async (path) => {
|
||||
const hash = createHash("sha256");
|
||||
for await (const bytes of createReadStream(path)) hash.update(bytes);
|
||||
return hash.digest("hex");
|
||||
};
|
||||
@@ -0,0 +1,130 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../../dist/domain/evidence.js";
|
||||
import { hashAndroidFile } from "./digest.mjs";
|
||||
|
||||
/** Verify folded field assignments and remaining static-block calls through both public adapters. */
|
||||
export const verifyAndroidInitializers = async ({
|
||||
apk,
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
}) => {
|
||||
const digest = await hashAndroidFile(apk);
|
||||
const cases = [
|
||||
{
|
||||
class_name: "fixture.InitializationPolicy",
|
||||
witnesses: [
|
||||
"declared-policy",
|
||||
"->singletonList",
|
||||
"->POLICY:Ljava/util/List;",
|
||||
],
|
||||
},
|
||||
{
|
||||
class_name: "fixture.MixedInitialization",
|
||||
witnesses: ["field-value", "->LABEL:Ljava/lang/String;", "->touch()V"],
|
||||
},
|
||||
];
|
||||
const check = (value, scenario) => {
|
||||
const evidence = parseEvidence(value);
|
||||
assert.equal(evidence.subject.digest.sha256, digest);
|
||||
const result = evidence.normalized_result;
|
||||
assert.equal(result.class_name, scenario.class_name);
|
||||
assert.equal(result.method.name, "<clinit>");
|
||||
assert.equal(result.overload_count, 1);
|
||||
assert.equal(result.body_status, "available");
|
||||
assert.equal(result.representation, "smali");
|
||||
assert.equal(result.fell_back, true);
|
||||
assert.ok(result.markers.includes("static_initializer_disassembly"));
|
||||
assert.equal(result.source.status, "complete");
|
||||
for (const witness of scenario.witnesses)
|
||||
assert.ok(
|
||||
result.source.text.includes(witness),
|
||||
`Missing initializer evidence: ${witness}`,
|
||||
);
|
||||
return evidence;
|
||||
};
|
||||
const cli = new Map();
|
||||
for (const scenario of cases) {
|
||||
const response = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"inspect-android-method",
|
||||
apk,
|
||||
scenario.class_name,
|
||||
"<clinit>",
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
timeout: 150_000,
|
||||
maxBuffer: 8 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
cli.set(scenario.class_name, check(JSON.parse(response.stdout), scenario));
|
||||
}
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr += chunk.toString();
|
||||
});
|
||||
const client = new Client({
|
||||
name: "rea-real-android-initializers",
|
||||
version: "1",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport, { timeout: 30_000 });
|
||||
for (const scenario of cases) {
|
||||
const response = await client.callTool(
|
||||
{
|
||||
name: "inspect_android_method",
|
||||
arguments: {
|
||||
path: apk,
|
||||
class_name: scenario.class_name,
|
||||
method_name: "<clinit>",
|
||||
},
|
||||
},
|
||||
{ timeout: 150_000 },
|
||||
);
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
const evidence = check(response.structuredContent, scenario);
|
||||
assert.deepEqual(
|
||||
evidence.normalized_result,
|
||||
cli.get(scenario.class_name).normalized_result,
|
||||
);
|
||||
assert.deepEqual(
|
||||
evidence.parameters,
|
||||
cli.get(scenario.class_name).parameters,
|
||||
);
|
||||
assert.deepEqual(
|
||||
evidence.provider,
|
||||
cli.get(scenario.class_name).provider,
|
||||
);
|
||||
}
|
||||
await client.ping();
|
||||
} catch (cause) {
|
||||
process.stderr.write(stderr);
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
assert.equal(
|
||||
await hashAndroidFile(apk),
|
||||
digest,
|
||||
"Static inspection changed fixture bytes",
|
||||
);
|
||||
console.log(
|
||||
"PASS real CLI/MCP static initializer evidence, identity, parity and unchanged APK",
|
||||
);
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { delimiter, join, resolve } from "node:path";
|
||||
import { verifyAndroidInitializers } from "./initializers.mjs";
|
||||
|
||||
/** Prove cold metadata stays unmaterialized and overload identities survive code generation. */
|
||||
export const verifyAndroidMetadata = async ({
|
||||
@@ -11,6 +12,8 @@ export const verifyAndroidMetadata = async ({
|
||||
bridge,
|
||||
repository,
|
||||
execute,
|
||||
entrypoint,
|
||||
environment,
|
||||
jvmArguments = [],
|
||||
}) => {
|
||||
const javac =
|
||||
@@ -55,6 +58,8 @@ export const verifyAndroidMetadata = async ({
|
||||
`${classes}${delimiter}${jar}`,
|
||||
"ReaJadxMetadataRegression",
|
||||
apk,
|
||||
resolve(repository, "tests/fixtures/android/static-initializers"),
|
||||
classes,
|
||||
],
|
||||
{ timeout: 120_000, maxBuffer: 8 * 1024 * 1024 },
|
||||
);
|
||||
@@ -62,9 +67,23 @@ export const verifyAndroidMetadata = async ({
|
||||
result.stdout,
|
||||
/METADATA_REGRESSION_PASS classes=\d+ overloads=3/u,
|
||||
);
|
||||
assert.match(
|
||||
result.stdout,
|
||||
/INITIALIZER_REGRESSION_PASS folded=2 bounded=true/u,
|
||||
);
|
||||
console.log(
|
||||
"PASS real cold metadata, full generic types and stable overloaded method selection",
|
||||
);
|
||||
console.log(
|
||||
"PASS real folded and mixed static initializers, absent bodies and bounded smali",
|
||||
);
|
||||
await verifyAndroidInitializers({
|
||||
apk: resolve(classes, "initializers.apk"),
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
});
|
||||
} finally {
|
||||
await rm(classes, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@ import { dirname, join } from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { resolveJadxConfiguration } from "../../../dist/android/JadxConfiguration.js";
|
||||
import {
|
||||
resolveJadxConfigurationInputs,
|
||||
validateJadxConfiguration,
|
||||
} from "../../../dist/android/JadxConfiguration.js";
|
||||
|
||||
/** Verify real Windows cancellation, disconnect and abrupt CLI owner exit. */
|
||||
export async function verifyWindowsAndroidLifecycle(options) {
|
||||
@@ -36,7 +39,12 @@ export async function verifyWindowsAndroidLifecycle(options) {
|
||||
}
|
||||
|
||||
async function verifyJavaSelection(environment) {
|
||||
const selected = await resolveJadxConfiguration(
|
||||
const selected = await resolveJadxConfigurationInputs(
|
||||
environment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
await validateJadxConfiguration(
|
||||
selected,
|
||||
environment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
@@ -51,7 +59,12 @@ async function verifyJavaSelection(environment) {
|
||||
// The owned junction borrows the selected JDK directory without copying it.
|
||||
await symlink(dirname(selected.java), alias, "junction");
|
||||
pathEnvironment.Path = `"${alias}"`;
|
||||
const onPath = await resolveJadxConfiguration(
|
||||
const onPath = await resolveJadxConfigurationInputs(
|
||||
pathEnvironment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
await validateJadxConfiguration(
|
||||
onPath,
|
||||
pathEnvironment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
|
||||
@@ -26,6 +26,8 @@ import {
|
||||
validateDosComLength,
|
||||
type ExecutableFormatHint,
|
||||
} from "../domain/dosCom.js";
|
||||
import { admitRawBinary } from "../domain/rawBinary.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import { mzWindowsHeaderOffset } from "../domain/dosMz.js";
|
||||
import {
|
||||
hasZipSignature,
|
||||
@@ -45,6 +47,8 @@ export interface BinaryTargetResolverOptions {
|
||||
readonly hostArchitecture?: NodeJS.Architecture;
|
||||
readonly targetKind?: BinaryTarget["kind"];
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly signal?: AbortSignal;
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ export const parseBinaryTarget = async (
|
||||
> => {
|
||||
const cwd = options.cwd ?? process.cwd();
|
||||
const hostArchitecture = options.hostArchitecture ?? process.arch;
|
||||
const { targetKind, formatHint, signal } = options;
|
||||
const { targetKind, formatHint, signal, architecture, entryPoint } = options;
|
||||
const candidate = isAbsolute(input) ? input : resolve(cwd, input);
|
||||
try {
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
@@ -83,6 +87,40 @@ export const parseBinaryTarget = async (
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
const metadata = await handle.stat();
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
if (formatHint === "raw-binary") {
|
||||
if (targetKind !== undefined && targetKind !== "executable")
|
||||
return err(
|
||||
new BinaryTargetError(
|
||||
path,
|
||||
"raw-binary format requires an executable target kind",
|
||||
),
|
||||
);
|
||||
const admitted = admitRawBinary({
|
||||
architecture,
|
||||
entryPoint,
|
||||
fileBytes: metadata.size,
|
||||
});
|
||||
if (!admitted.ok)
|
||||
return err(new BinaryTargetError(path, admitted.error));
|
||||
return ok({
|
||||
path,
|
||||
sourcePath: canonical,
|
||||
sha256: await sha256Handle(handle, path, metadata, signal),
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: admitted.value.architecture,
|
||||
availableArchitectures: [admitted.value.architecture],
|
||||
entryPoint: admitted.value.entryPoint,
|
||||
entryPointSource: admitted.value.entryPointSource,
|
||||
});
|
||||
}
|
||||
if (architecture !== undefined || entryPoint !== undefined)
|
||||
return err(
|
||||
new BinaryTargetError(
|
||||
path,
|
||||
"architecture and entry_point apply only with format=raw-binary",
|
||||
),
|
||||
);
|
||||
if (formatHint === "dos-com") {
|
||||
if (targetKind !== undefined && targetKind !== "executable")
|
||||
return err(
|
||||
@@ -194,7 +232,13 @@ const detectArtifactFormat = async (
|
||||
): Promise<
|
||||
| Exclude<
|
||||
BinaryTarget["format"],
|
||||
"analysis-database" | "mach-o" | "elf" | "pe" | "dos-mz" | "dos-com"
|
||||
| "analysis-database"
|
||||
| "mach-o"
|
||||
| "elf"
|
||||
| "pe"
|
||||
| "dos-mz"
|
||||
| "dos-com"
|
||||
| "raw-binary"
|
||||
>
|
||||
| undefined
|
||||
> => {
|
||||
@@ -244,7 +288,13 @@ const namedArtifactFormat = (
|
||||
const isArchiveFormat = (
|
||||
format: Exclude<
|
||||
BinaryTarget["format"],
|
||||
"analysis-database" | "mach-o" | "elf" | "pe" | "dos-mz" | "dos-com"
|
||||
| "analysis-database"
|
||||
| "mach-o"
|
||||
| "elf"
|
||||
| "pe"
|
||||
| "dos-mz"
|
||||
| "dos-com"
|
||||
| "raw-binary"
|
||||
>,
|
||||
): format is Extract<BinaryTarget, { kind: "archive" }>["format"] =>
|
||||
isZipPackageFormat(format) || ["asar", "dmg", "pkg"].includes(format);
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
clientRequirementsFor,
|
||||
NO_CLIENT_FEATURES,
|
||||
} from "./CapabilityClientRequirements.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
const statusSchema = z.object({
|
||||
open: z.boolean(),
|
||||
@@ -210,7 +211,7 @@ export const buildCapabilityInventory = (
|
||||
reason: availability.reason,
|
||||
remediation: availability.remediation,
|
||||
};
|
||||
}).sort((left, right) => left.name.localeCompare(right.name));
|
||||
}).sort((left, right) => compareUnicodeCodePoints(left.name, right.name));
|
||||
};
|
||||
|
||||
const availabilityFor = (context: AvailabilityContext): Availability => {
|
||||
|
||||
@@ -18,6 +18,7 @@ import { z } from "zod";
|
||||
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
import type { SetupClient } from "./SupportedClients.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
export type ClientConfigurationFormat = NonNullable<SetupClient["format"]>;
|
||||
export type ClientServersKey = "mcp_servers" | "mcpServers" | "mcp" | "servers";
|
||||
@@ -63,7 +64,7 @@ const normalizeConfigurationValue = (value: unknown): unknown => {
|
||||
return value;
|
||||
return Object.fromEntries(
|
||||
Object.entries(value)
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
.sort(([left], [right]) => compareUnicodeCodePoints(left, right))
|
||||
.map(([key, nested]) => [key, normalizeConfigurationValue(nested)]),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type ClientConfigurationDocument,
|
||||
} from "./ClientConfigurationDocument.js";
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Read explicit REA overrides without dropping peers when one value is invalid. */
|
||||
export const clientRegistrationEnvironment = (
|
||||
@@ -47,7 +48,7 @@ export const clientRegistrationEnvironment = (
|
||||
return ok(
|
||||
Object.fromEntries(
|
||||
Object.entries(environment).sort(([left], [right]) =>
|
||||
left.localeCompare(right),
|
||||
compareUnicodeCodePoints(left, right),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
supportedClients,
|
||||
} from "./SupportedClients.js";
|
||||
import type { SetupClient } from "./SupportedClients.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
interface ClientRegistrationStatusBase {
|
||||
readonly client: string;
|
||||
@@ -184,7 +185,7 @@ export const readClientRegistrationStatuses = async (
|
||||
}
|
||||
}
|
||||
return statuses.sort((left, right) =>
|
||||
left.client.localeCompare(right.client),
|
||||
compareUnicodeCodePoints(left.client, right.client),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ExecutableFormatHint } from "../domain/dosCom.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { DirectAnalysisDependencies } from "./DirectAnalysisDependencies.js";
|
||||
import type { BinarySession } from "./binary/BinarySession.js";
|
||||
@@ -91,6 +92,8 @@ export const runDirectAnalysis = async (
|
||||
readonly signal?: AbortSignal;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
} = {},
|
||||
): Promise<JsonValue> =>
|
||||
withProcessCancellation(options.signal, (signal) =>
|
||||
@@ -101,6 +104,12 @@ export const runDirectAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(options.providerId === undefined
|
||||
? {}
|
||||
: { providerId: options.providerId }),
|
||||
@@ -187,6 +196,8 @@ const runAnalysis = async (
|
||||
readonly signal: AbortSignal;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
},
|
||||
): Promise<JsonValue> => {
|
||||
const { logger, signal, snapshotPath } = options;
|
||||
@@ -203,6 +214,12 @@ const runAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
});
|
||||
if (!prepared.ok) return cliError(prepared.error);
|
||||
const { snapshot } = prepared.value;
|
||||
@@ -214,6 +231,12 @@ const runAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(options.providerId === undefined
|
||||
? {}
|
||||
: { providerId: options.providerId }),
|
||||
@@ -246,6 +269,12 @@ const runAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(snapshot === undefined ? {} : { snapshot }),
|
||||
...(options.providerId === undefined
|
||||
? {}
|
||||
@@ -440,6 +469,8 @@ const withProcessCancellation = async <Value>(
|
||||
const prepareSnapshot = async (options: {
|
||||
readonly path: string;
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly snapshotPath: string | undefined;
|
||||
readonly signal: AbortSignal;
|
||||
}): Promise<
|
||||
@@ -458,6 +489,12 @@ const prepareSnapshot = async (options: {
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
});
|
||||
if (!target.ok) return target;
|
||||
if (!snapshotMatchesTarget(loaded.value.target, target.value))
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
semanticObligationPolicy,
|
||||
type ReconstructionObligationCandidatePolicy,
|
||||
} from "./ReconstructionObligationPolicies.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
type CandidateFields = Omit<
|
||||
ReconstructionObligation,
|
||||
@@ -54,7 +55,7 @@ export const deriveReconstructionObligationCandidates = (
|
||||
addCandidate(candidates, reviewedCandidate(obligation, records));
|
||||
return {
|
||||
candidates: [...candidates.values()].sort((left, right) =>
|
||||
left.obligation_id.localeCompare(right.obligation_id),
|
||||
compareUnicodeCodePoints(left.obligation_id, right.obligation_id),
|
||||
),
|
||||
limitations: [...limitations].sort(),
|
||||
};
|
||||
@@ -430,7 +431,7 @@ const uniqueBy = <Value>(
|
||||
key: (value: Value) => string,
|
||||
): Value[] =>
|
||||
[...new Map(values.map((value) => [key(value), value])).values()].sort(
|
||||
(left, right) => key(left).localeCompare(key(right)),
|
||||
(left, right) => compareUnicodeCodePoints(key(left), key(right)),
|
||||
);
|
||||
|
||||
const obligationId = (key: string): string =>
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
ReconstructionObligationManifest,
|
||||
} from "../domain/reconstructionObligationLedgerSchemas.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
type Diagnostic = ReconstructionObligation["diagnostics"][number];
|
||||
type Binding = NonNullable<ReconstructionObligation["binding"]>;
|
||||
@@ -50,7 +51,8 @@ export const uniqueObligationDiagnostics = (
|
||||
]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
`${left.code}:${left.detail}`.localeCompare(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.code}:${left.detail}`,
|
||||
`${right.code}:${right.detail}`,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
obligationReports,
|
||||
summarizeObligations,
|
||||
} from "./ReconstructionObligationLedgerProjection.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
type Diagnostic = ReconstructionObligation["diagnostics"][number];
|
||||
type Binding = NonNullable<ReconstructionObligation["binding"]>;
|
||||
@@ -60,7 +61,7 @@ export const evaluateReconstructionObligationLedger = ({
|
||||
}): ReconstructionObligationLedger => {
|
||||
const bundle = parseEvidenceBundle(bundleInput);
|
||||
const allCandidates = [...candidatesInput].sort((left, right) =>
|
||||
left.obligation_id.localeCompare(right.obligation_id),
|
||||
compareUnicodeCodePoints(left.obligation_id, right.obligation_id),
|
||||
);
|
||||
const orphanManifestIds = findOrphanManifestIds(allCandidates, manifest);
|
||||
const candidates = allCandidates;
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Evidence } from "../domain/evidence.js";
|
||||
import type { ReconstructionObligation } from "../domain/reconstructionObligationLedgerSchemas.js";
|
||||
import { evidenceSupportsOriginalAuthority } from "./ReconstructionObligationAuthority.js";
|
||||
import type { ReconstructionObligationCandidate } from "./ReconstructionObligationCandidates.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
type Binding = NonNullable<ReconstructionObligation["binding"]>;
|
||||
type Diagnostic = ReconstructionObligation["diagnostics"][number];
|
||||
@@ -21,7 +22,8 @@ export const originalCasesFor = (
|
||||
),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
`${left.kind}:${left.evidence_id}:${left.location}`.localeCompare(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.kind}:${left.evidence_id}:${left.location}`,
|
||||
`${right.kind}:${right.evidence_id}:${right.location}`,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -15,6 +15,7 @@ import type {
|
||||
} from "./SetupTypes.js";
|
||||
import type { SetupClient } from "./SupportedClients.js";
|
||||
import type { DoctorReport } from "./Doctor.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Read-only setup facts shared by client selection and preflight. */
|
||||
export interface SetupDiscovery {
|
||||
@@ -308,7 +309,7 @@ const clientConfigurationDetail = (
|
||||
installHopper: boolean,
|
||||
): string => {
|
||||
const entries = Object.entries(environment)
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
.sort(([left], [right]) => compareUnicodeCodePoints(left, right))
|
||||
.map(([name, value]) => `${name}=${value}`);
|
||||
const environmentDetail =
|
||||
entries.length === 0
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { DoctorProviderInspection } from "./Doctor.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Preserve adapter-published settings independently of runtime readiness. */
|
||||
export const providerRegistrationEnvironment = (
|
||||
@@ -9,5 +10,5 @@ export const providerRegistrationEnvironment = (
|
||||
.flatMap(({ registrationEnvironment }) =>
|
||||
Object.entries(registrationEnvironment),
|
||||
)
|
||||
.sort(([left], [right]) => left.localeCompare(right)),
|
||||
.sort(([left], [right]) => compareUnicodeCodePoints(left, right)),
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
HermesClientPathError,
|
||||
resolveHermesClientHome,
|
||||
} from "./HermesClientHome.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** One supported client configuration location. */
|
||||
export interface SetupClient {
|
||||
@@ -642,6 +643,6 @@ export const clientSkillDirectories = (
|
||||
});
|
||||
}
|
||||
return [...destinations.values()].sort((left, right) =>
|
||||
left.directory.localeCompare(right.directory),
|
||||
compareUnicodeCodePoints(left.directory, right.directory),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import type { EvidenceWriter } from "../investigation/InvestigationRecordPort.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import { ok, type Result } from "../../domain/result.js";
|
||||
|
||||
/**
|
||||
* Complete class-inventory pages dominate raw-call provenance for focused
|
||||
* searches: one traversal embeds every examined class name regardless of the
|
||||
* match count. The summary keeps the pagination audit inline (totals, page
|
||||
* offsets and sizes, elided item counts) and links the retained record that
|
||||
* still carries the complete inventory.
|
||||
*/
|
||||
const elideInventoryText = (text: string): string | undefined => {
|
||||
let page: JsonValue;
|
||||
try {
|
||||
page = JSON.parse(text) as JsonValue;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
if (
|
||||
typeof page !== "object" ||
|
||||
page === null ||
|
||||
Array.isArray(page) ||
|
||||
!Array.isArray(page.items)
|
||||
)
|
||||
return undefined;
|
||||
const { items, ...audited } = page;
|
||||
return JSON.stringify({ ...audited, items_omitted: items.length });
|
||||
};
|
||||
|
||||
/** Replace inventoried page bodies with their pagination audit. */
|
||||
const summarizeInventoryCall = (call: JsonValue): JsonValue => {
|
||||
if (
|
||||
typeof call !== "object" ||
|
||||
call === null ||
|
||||
Array.isArray(call) ||
|
||||
call.operation !== "list_classes"
|
||||
)
|
||||
return call;
|
||||
const response = call.response;
|
||||
if (
|
||||
typeof response !== "object" ||
|
||||
response === null ||
|
||||
Array.isArray(response) ||
|
||||
!Array.isArray(response.content)
|
||||
)
|
||||
return call;
|
||||
let elided = false;
|
||||
const content = response.content.map((entry: JsonValue) => {
|
||||
if (
|
||||
typeof entry !== "object" ||
|
||||
entry === null ||
|
||||
Array.isArray(entry) ||
|
||||
typeof entry.text !== "string"
|
||||
)
|
||||
return entry;
|
||||
const summarized = elideInventoryText(entry.text);
|
||||
if (summarized === undefined) return entry;
|
||||
elided = true;
|
||||
return { ...entry, text: summarized };
|
||||
});
|
||||
return elided
|
||||
? { ...call, inventory_elided: true, response: { ...response, content } }
|
||||
: call;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retain the complete search Evidence — full raw provider calls included —
|
||||
* in the session record, then deliver a bounded summary Evidence inline.
|
||||
* Callers without a retaining session keep the complete inline delivery, so
|
||||
* complete CLI JSON output is unchanged. Coverage metadata stays truthful in
|
||||
* both copies: the examined inventory is never rewritten to matched-only.
|
||||
*/
|
||||
export const summarizeRetainedAndroidSearch = (
|
||||
evidence: Evidence,
|
||||
recordEvidence: EvidenceWriter["recordEvidence"] | undefined,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
if (recordEvidence === undefined) return ok(evidence);
|
||||
const recorded = recordEvidence(evidence);
|
||||
if (!recorded.ok) return recorded;
|
||||
const subject = evidence.subject;
|
||||
const raw = evidence.raw_result;
|
||||
const summarized: JsonValue =
|
||||
raw === null ||
|
||||
typeof raw !== "object" ||
|
||||
Array.isArray(raw) ||
|
||||
!Array.isArray(raw.calls)
|
||||
? raw
|
||||
: {
|
||||
...raw,
|
||||
complete_evidence_id: evidence.evidence_id,
|
||||
calls: raw.calls.map(summarizeInventoryCall),
|
||||
};
|
||||
return ok(
|
||||
createEvidence(
|
||||
subject === null
|
||||
? undefined
|
||||
: {
|
||||
path: subject.local_path,
|
||||
sha256: subject.digest.sha256,
|
||||
format: subject.format,
|
||||
...(subject.architecture === null
|
||||
? {}
|
||||
: { architecture: subject.architecture }),
|
||||
},
|
||||
evidence.provider,
|
||||
{
|
||||
operation: evidence.operation,
|
||||
parameters: evidence.parameters,
|
||||
result: evidence.normalized_result,
|
||||
rawResult: summarized,
|
||||
confidence: evidence.confidence,
|
||||
limitations: evidence.limitations,
|
||||
locations: evidence.locations,
|
||||
evidenceLinks: [evidence.evidence_id],
|
||||
},
|
||||
),
|
||||
);
|
||||
};
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
evaluateAnalysisProviderCandidate,
|
||||
type AnalysisProviderCandidateEvaluation,
|
||||
} from "./AnalysisProviderEvaluation.js";
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Deterministic discovery truth for one configured deep provider. */
|
||||
export interface AnalysisProviderCandidateStatus {
|
||||
@@ -109,12 +110,14 @@ export class AnalysisProviderRegistry {
|
||||
}
|
||||
this.#providers = Object.freeze(
|
||||
[...providers].sort((left, right) =>
|
||||
left.identity().id.localeCompare(right.identity().id),
|
||||
compareUnicodeCodePoints(left.identity().id, right.identity().id),
|
||||
),
|
||||
);
|
||||
this.#byId = byId;
|
||||
this.#declaredOperations = Object.freeze(
|
||||
[...declaredOperations].sort((left, right) => left.localeCompare(right)),
|
||||
[...declaredOperations].sort((left, right) =>
|
||||
compareUnicodeCodePoints(left, right),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ExecutableFormatHint } from "../../domain/dosCom.js";
|
||||
import type { BinaryArchitecture } from "../../domain/binaryTargetTypes.js";
|
||||
import type { AnalysisProviderSelector } from "../../contracts/providerSelection.js";
|
||||
import type { AnalysisProfileCommitment } from "../../domain/analysisProfile.js";
|
||||
import {
|
||||
@@ -22,6 +23,8 @@ export interface BinarySessionOpenOptions {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly targetKind?: BinaryTarget["kind"];
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly snapshot?: AnalysisSnapshot;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
}
|
||||
@@ -72,6 +75,12 @@ export const resolveSessionOpen = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(options.signal === undefined ? {} : { signal: options.signal }),
|
||||
});
|
||||
if (!parsed.ok) return parsed;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { InvestigationRecordPort } from "../investigation/InvestigationRecordPort.js";
|
||||
import type { ExecutableFormatHint } from "../../domain/dosCom.js";
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import type {
|
||||
BinaryArchitecture,
|
||||
BinaryTarget,
|
||||
} from "../../domain/binaryTargetTypes.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import type { AnalysisSnapshot } from "../../domain/analysisSnapshot.js";
|
||||
import type { AnalysisProfileCommitment } from "../../domain/analysisProfile.js";
|
||||
@@ -44,6 +47,8 @@ export interface BinarySessionPort
|
||||
readonly signal?: AbortSignal;
|
||||
readonly targetKind?: BinaryTarget["kind"];
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly snapshot?: AnalysisSnapshot;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import { binaryTargetSummary } from "./BinaryTargetSummary.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import type { ProviderOperationHealth } from "../../domain/providerOperationHealth.js";
|
||||
import type {
|
||||
@@ -10,6 +11,7 @@ import type {
|
||||
SessionProviderRoute,
|
||||
SessionProviderRouter,
|
||||
} from "./SessionProviderRouter.js";
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
|
||||
interface BinarySessionStatusInput {
|
||||
readonly target: BinaryTarget | undefined;
|
||||
@@ -38,7 +40,9 @@ export const binarySessionStatus = ({
|
||||
}: BinarySessionStatusInput): JsonValue => {
|
||||
const capabilities = [...route.capabilities.values()]
|
||||
.filter(({ operation }) => operation !== "inventory_artifact")
|
||||
.sort((left, right) => left.operation.localeCompare(right.operation))
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.operation, right.operation),
|
||||
)
|
||||
.map((descriptor) => {
|
||||
const unavailable = runtimeUnavailability.get(descriptor.operation);
|
||||
return unavailable === undefined
|
||||
@@ -68,7 +72,9 @@ export const binarySessionStatus = ({
|
||||
capabilities: candidate.capabilities
|
||||
.slice()
|
||||
.filter(({ operation }) => operation !== "inventory_artifact")
|
||||
.sort((left, right) => left.operation.localeCompare(right.operation))
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.operation, right.operation),
|
||||
)
|
||||
.map(capabilityStatus),
|
||||
}));
|
||||
const common = {
|
||||
@@ -92,11 +98,7 @@ export const binarySessionStatus = ({
|
||||
: {
|
||||
open: true,
|
||||
...common,
|
||||
path: target.path,
|
||||
sha256: target.sha256,
|
||||
format: target.format,
|
||||
kind: target.kind,
|
||||
architecture: target.architecture ?? null,
|
||||
...binaryTargetSummary(target),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -105,7 +107,9 @@ const requestActivityStatus = (
|
||||
) => {
|
||||
const providers = snapshots
|
||||
.slice()
|
||||
.sort((left, right) => left.provider.id.localeCompare(right.provider.id))
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.provider.id, right.provider.id),
|
||||
)
|
||||
.map(({ provider, active, queuedRequests }) => ({
|
||||
provider: providerSummary(provider),
|
||||
active:
|
||||
@@ -153,7 +157,7 @@ const processLineageStatus = (
|
||||
snapshots: snapshots
|
||||
.slice()
|
||||
.sort((left, right) =>
|
||||
left.provider.id.localeCompare(right.provider.id),
|
||||
compareUnicodeCodePoints(left.provider.id, right.provider.id),
|
||||
)
|
||||
.map(({ provider, observation }) => ({
|
||||
provider: providerSummary(provider),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
|
||||
/** Preserve the admitted target interpretation in public lifecycle results. */
|
||||
export const binaryTargetSummary = (target: BinaryTarget) => ({
|
||||
path: target.path,
|
||||
format: target.format,
|
||||
kind: target.kind,
|
||||
sha256: target.sha256,
|
||||
architecture: target.architecture ?? null,
|
||||
...(target.format === "raw-binary" ? { entry_point: target.entryPoint } : {}),
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
ProviderIdentity,
|
||||
} from "../AnalysisProvider.js";
|
||||
import { closeAnalysisClient } from "./AnalysisClientCleanup.js";
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Synthetic identity for a deterministic provider set. */
|
||||
const compositeProviderIdentity = (
|
||||
@@ -53,8 +54,8 @@ export class CompositeProvider implements AnalysisProvider {
|
||||
this.#capabilities = Object.freeze(
|
||||
capabilities.sort(
|
||||
(left, right) =>
|
||||
left.operation.localeCompare(right.operation) ||
|
||||
left.provider.id.localeCompare(right.provider.id),
|
||||
compareUnicodeCodePoints(left.operation, right.operation) ||
|
||||
compareUnicodeCodePoints(left.provider.id, right.provider.id),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -122,13 +123,13 @@ export class CompositeProvider implements AnalysisProvider {
|
||||
[...clients.values()]
|
||||
.flatMap((client) => client.runtimeLineageSnapshots?.() ?? [])
|
||||
.sort((left, right) =>
|
||||
left.provider.id.localeCompare(right.provider.id),
|
||||
compareUnicodeCodePoints(left.provider.id, right.provider.id),
|
||||
),
|
||||
requestActivitySnapshots: () =>
|
||||
[...clients.values()]
|
||||
.flatMap((client) => client.requestActivitySnapshots?.() ?? [])
|
||||
.sort((left, right) =>
|
||||
left.provider.id.localeCompare(right.provider.id),
|
||||
compareUnicodeCodePoints(left.provider.id, right.provider.id),
|
||||
),
|
||||
operationHealthSnapshot: () => {
|
||||
for (const client of clients.values()) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
type UpdateUnknownInput,
|
||||
} from "../../domain/residualUnknown.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
|
||||
type EvidenceLedgerFailure = EvidenceIntegrityError;
|
||||
type RecordResult = Result<"added" | "duplicate", EvidenceLedgerFailure>;
|
||||
@@ -321,7 +322,9 @@ export class EvidenceLedger {
|
||||
unknown.severity === filters.severity) &&
|
||||
(filters.domain === undefined || unknown.domain === filters.domain),
|
||||
)
|
||||
.sort((left, right) => left.unknown_id.localeCompare(right.unknown_id))
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.unknown_id, right.unknown_id),
|
||||
)
|
||||
.map((unknown) => structuredClone(unknown));
|
||||
}
|
||||
|
||||
|
||||
@@ -868,6 +868,365 @@ describe("package exports exact targets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("package import alias resolution", () => {
|
||||
it.each(["import", "require"] as const)(
|
||||
"resolves an exact #%s alias from the enclosing package imports map",
|
||||
(moduleKind) => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./config.cjs" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.cjs": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind,
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "config.cjs",
|
||||
declared_path: "#config",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves an alias from a nested file through the enclosing package root", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./config.cjs" },
|
||||
}),
|
||||
"src/main.js": "",
|
||||
"config.cjs": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "src/main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "config.cjs",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses a nested package imports map rather than the application root", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./root.cjs" },
|
||||
}),
|
||||
"root.cjs": "",
|
||||
"node_modules/fixture/package.json": JSON.stringify({
|
||||
imports: { "#config": "./local.cjs" },
|
||||
}),
|
||||
"node_modules/fixture/index.js": "",
|
||||
"node_modules/fixture/local.cjs": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "node_modules/fixture/index.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "node_modules/fixture/local.cjs",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not inherit an ancestor imports map across a nested package.json", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./root.cjs" },
|
||||
}),
|
||||
"root.cjs": "",
|
||||
"node_modules/fixture/package.json": "{}",
|
||||
"node_modules/fixture/index.js": "",
|
||||
});
|
||||
const outcome = resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "node_modules/fixture/index.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
expect(outcome).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(outcome.limitations.join(" ")).toContain(
|
||||
"node_modules/fixture/package.json",
|
||||
);
|
||||
expect(outcome.limitations.join(" ")).not.toContain("root.cjs");
|
||||
});
|
||||
|
||||
it("does not apply a nested package map to the application root importer", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./root.cjs" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"root.cjs": "",
|
||||
"node_modules/fixture/package.json": JSON.stringify({
|
||||
imports: { "#config": "./local.cjs" },
|
||||
}),
|
||||
"node_modules/fixture/local.cjs": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "root.cjs",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("package import alias target selection", () => {
|
||||
it("selects import and require conditions from an imports target", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: {
|
||||
"#config": {
|
||||
import: "./config.mjs",
|
||||
require: "./config.cjs",
|
||||
default: "./fallback.js",
|
||||
},
|
||||
},
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.mjs": "",
|
||||
"config.cjs": "",
|
||||
"fallback.js": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "import",
|
||||
files,
|
||||
}).resolved_path,
|
||||
).toBe("config.mjs");
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
}).resolved_path,
|
||||
).toBe("config.cjs");
|
||||
});
|
||||
|
||||
it("resolves array import targets at their first string entry", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": [{ import: "./missing.mjs" }, "./config.cjs"] },
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.cjs": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({
|
||||
resolution_status: "resolved",
|
||||
resolved_path: "config.cjs",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not add an extension or index to a selected import target", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./config" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.cjs": "",
|
||||
"config/index.js": "",
|
||||
});
|
||||
const outcome = resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
expect(outcome).toMatchObject({
|
||||
resolution_status: "not-found",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(outcome.limitations.join(" ")).toContain(
|
||||
"import targets are exact files",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("package import alias refusals", () => {
|
||||
it("reports a missing exact alias without looking in another package", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./config.cjs" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.cjs": "",
|
||||
});
|
||||
const outcome = resolve({
|
||||
declaredPath: "#other",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
expect(outcome).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(outcome.limitations.join(" ")).toContain("#other");
|
||||
expect(outcome.limitations.join(" ")).toContain("#config");
|
||||
});
|
||||
|
||||
it("reports an explicit null import target as blocked", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": null },
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.cjs": "",
|
||||
});
|
||||
const outcome = resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
expect(outcome).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(outcome.limitations.join(" ")).toContain("explicit null");
|
||||
});
|
||||
|
||||
it("leaves wildcard import aliases unresolved", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#internal/*": "./src/*.js" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"src/util.js": "",
|
||||
});
|
||||
const outcome = resolve({
|
||||
declaredPath: "#internal/util",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "import",
|
||||
files,
|
||||
});
|
||||
expect(outcome).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(outcome.limitations.join(" ")).toMatch(/wildcard/i);
|
||||
});
|
||||
|
||||
it("leaves recursive and external-package import targets unresolved", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#loop": "#config", "#dep": "fixture" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"node_modules/fixture/index.js": "",
|
||||
});
|
||||
const recursive = resolve({
|
||||
declaredPath: "#loop",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
const external = resolve({
|
||||
declaredPath: "#dep",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
expect(recursive).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(recursive.limitations.join(" ")).toMatch(/recursive/i);
|
||||
expect(external).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(external.limitations.join(" ")).toMatch(/external-package/i);
|
||||
});
|
||||
|
||||
it("rejects reserved hash specifiers", () => {
|
||||
const files = aliasFiles({
|
||||
"package.json": JSON.stringify({
|
||||
imports: { "#config": "./config.cjs" },
|
||||
}),
|
||||
"main.js": "",
|
||||
"config.cjs": "",
|
||||
});
|
||||
expect(
|
||||
resolve({
|
||||
declaredPath: "#",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "import",
|
||||
files,
|
||||
}),
|
||||
).toMatchObject({ resolution_status: "rejected", resolved_path: null });
|
||||
});
|
||||
|
||||
it("does not use a foreign-container enclosing package.json", () => {
|
||||
const files = fileMap([
|
||||
file(
|
||||
"package.json",
|
||||
"other",
|
||||
JSON.stringify({ imports: { "#config": "./config.cjs" } }),
|
||||
),
|
||||
file("main.js", "root"),
|
||||
file("config.cjs", "root"),
|
||||
]);
|
||||
const outcome = resolve({
|
||||
declaredPath: "#config",
|
||||
sourcePath: "main.js",
|
||||
context: "module-specifier",
|
||||
moduleKind: "require",
|
||||
files,
|
||||
});
|
||||
expect(outcome).toMatchObject({
|
||||
resolution_status: "external",
|
||||
resolved_path: null,
|
||||
});
|
||||
expect(outcome.limitations.join(" ")).toContain("package scopes");
|
||||
});
|
||||
});
|
||||
|
||||
describe("directory package entrypoint precedence", () => {
|
||||
it.each([
|
||||
["require", '{"main":"actual.cjs"}', "actual.cjs"],
|
||||
@@ -1211,6 +1570,15 @@ const file = (
|
||||
: { included: true, value: text },
|
||||
});
|
||||
|
||||
const aliasFiles = (
|
||||
entries: Readonly<Record<string, string | null>>,
|
||||
): ReturnType<typeof fileMap> =>
|
||||
fileMap(
|
||||
Object.entries(entries).map(([path, text]) =>
|
||||
file(path, "root", text ?? ""),
|
||||
),
|
||||
);
|
||||
|
||||
describe("exact HTML resource resolution", () => {
|
||||
it.each([
|
||||
["extension", ["app.js"]],
|
||||
|
||||
@@ -14,6 +14,11 @@ import {
|
||||
percentDecodeUrlPath,
|
||||
stripQueryAndFragment,
|
||||
} from "../../domain/artifactPathSyntax.js";
|
||||
import {
|
||||
classifyPackageImportSpecifier,
|
||||
classifyPackageImportTargetString,
|
||||
lookupExactPackageImport,
|
||||
} from "../../domain/javascript/javascriptPackageImportAliases.js";
|
||||
|
||||
type ArtifactPathResolutionContext =
|
||||
| "package-entrypoint"
|
||||
@@ -103,6 +108,13 @@ export const resolveArtifactPathByContext = (
|
||||
};
|
||||
|
||||
const resolvePath = (input: ResolveArtifactPathInput): CandidateResolution => {
|
||||
// Package import keys are literal lookup identities, not artifact paths.
|
||||
// The selected target is admitted separately by resolveExportTarget.
|
||||
if (
|
||||
input.context === "module-specifier" &&
|
||||
input.declaredPath.startsWith("#")
|
||||
)
|
||||
return resolvePackageImportAlias(input, input.declaredPath);
|
||||
const rejected = rejectDeclaration(input.declaredPath);
|
||||
if (rejected !== null) return rejected;
|
||||
const candidate = contextualCandidate(input);
|
||||
@@ -202,9 +214,9 @@ const bareModuleCandidate = (
|
||||
declared: string,
|
||||
): CandidateResolution => {
|
||||
const packageName = barePackageName(declared);
|
||||
if (packageName === null || isBuiltin(declared) || declared.startsWith("#"))
|
||||
if (packageName === null || isBuiltin(declared))
|
||||
return unresolvedCandidate("external", [
|
||||
"The bare specifier is a Node builtin, package import map, or invalid package name.",
|
||||
"The bare specifier is a Node builtin or invalid package name.",
|
||||
]);
|
||||
if (input.moduleKind === "import" && packageName.includes("%"))
|
||||
return unresolvedCandidate("rejected", [
|
||||
@@ -235,6 +247,115 @@ const bareModuleCandidate = (
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Nearest same-container package.json, stopping at a `node_modules` directory
|
||||
* so a nested package cannot inherit an ancestor's map.
|
||||
*/
|
||||
const enclosingPackageMetadata = (
|
||||
input: ResolveArtifactPathInput,
|
||||
):
|
||||
| Extract<PackageMetadata, { readonly kind: "available" | "unavailable" }>
|
||||
| { readonly kind: "none" } => {
|
||||
let directory = posix.dirname(input.sourcePath);
|
||||
while (posix.basename(directory) !== "node_modules") {
|
||||
const metadata = readPackageMetadata(input, directory);
|
||||
if (metadata.kind !== "absent") return metadata;
|
||||
if (directory === "." || directory === "") break;
|
||||
directory = posix.dirname(directory);
|
||||
}
|
||||
return { kind: "none" };
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve an exact `#alias` against the importer's enclosing `imports` map.
|
||||
* Selected relative targets are exact files; patterns, recursive aliases, and
|
||||
* external-package targets stay unresolved without falling through.
|
||||
*/
|
||||
const resolvePackageImportAlias = (
|
||||
input: ResolveArtifactPathInput,
|
||||
specifier: string,
|
||||
): CandidateResolution => {
|
||||
const classified = classifyPackageImportSpecifier(specifier);
|
||||
if (classified.kind === "invalid")
|
||||
return unresolvedCandidate("rejected", [
|
||||
`The package import specifier ${JSON.stringify(specifier)} is invalid; "#" and specifiers that end with "/" are not valid import aliases.`,
|
||||
]);
|
||||
if (classified.kind === "pattern")
|
||||
return unresolvedCandidate("external", [
|
||||
`Wildcard and directory package import aliases remain unresolved; ${JSON.stringify(specifier)} is not an exact imports key.`,
|
||||
]);
|
||||
const metadata = enclosingPackageMetadata(input);
|
||||
if (metadata.kind === "none")
|
||||
return unresolvedCandidate("external", [
|
||||
`No enclosing package.json defines package import alias ${specifier}; package import maps do not cross package scopes.`,
|
||||
]);
|
||||
if (metadata.kind === "unavailable")
|
||||
return unresolvedCandidate("unavailable", [metadata.limitation]);
|
||||
const lookup = lookupExactPackageImport(metadata.imports, specifier);
|
||||
if (lookup.kind === "undefined-map")
|
||||
return unresolvedCandidate("external", [
|
||||
`Package metadata ${metadata.path} does not define package import alias ${specifier}.`,
|
||||
]);
|
||||
if (lookup.kind === "missing-key")
|
||||
return unresolvedCandidate("external", [
|
||||
`Package metadata ${metadata.path} does not define package import alias ${specifier}; it declares ${lookup.declared.join(", ") || "no imports keys"}.`,
|
||||
]);
|
||||
if (lookup.kind === "pattern-unresolved")
|
||||
return unresolvedCandidate("external", [
|
||||
`Wildcard package import aliases remain unresolved; package metadata ${metadata.path} has no exact imports key ${specifier}.`,
|
||||
]);
|
||||
const selected = selectPackageImportTarget(lookup.target, input.moduleKind);
|
||||
if (selected.status === "rejected")
|
||||
return unresolvedCandidate("rejected", [
|
||||
`Package metadata ${metadata.path}: ${selected.limitation}`,
|
||||
]);
|
||||
if (selected.status === "unmatched")
|
||||
return unresolvedCandidate("external", [
|
||||
`Package metadata ${metadata.path} declares no imports target for alias ${specifier} under the active conditions; it declares ${selected.declared.join(", ") || "no conditions"}.`,
|
||||
]);
|
||||
if (selected.status === "blocked")
|
||||
return unresolvedCandidate("external", [
|
||||
`Package metadata ${metadata.path} blocks import alias ${specifier} with ${selected.cause === "null" ? "an explicit null imports target" : "an empty imports target array"}.`,
|
||||
]);
|
||||
if (selected.status === "non-relative") {
|
||||
const target = classifyPackageImportTargetString(selected.value);
|
||||
return unresolvedCandidate("external", [
|
||||
target.kind === "recursive"
|
||||
? `Recursive package import aliases remain unresolved; package metadata ${metadata.path} maps ${specifier} to ${JSON.stringify(target.target)}.`
|
||||
: `External-package import targets remain unresolved; package metadata ${metadata.path} maps ${specifier} to ${JSON.stringify(target.target)}.`,
|
||||
]);
|
||||
}
|
||||
return resolveExportTarget(input, metadata.path, selected.value, "imports");
|
||||
};
|
||||
|
||||
const selectPackageImportTarget = (
|
||||
value: unknown,
|
||||
moduleKind: ResolveArtifactPathInput["moduleKind"],
|
||||
):
|
||||
| { readonly status: "value"; readonly value: string }
|
||||
| { readonly status: "non-relative"; readonly value: string }
|
||||
| { readonly status: "blocked"; readonly cause: PackageTargetBlockCause }
|
||||
| { readonly status: "unmatched"; readonly declared: readonly string[] }
|
||||
| { readonly status: "rejected"; readonly limitation: string } => {
|
||||
const selected = selectExportTarget(
|
||||
value,
|
||||
packageExportConditions(moduleKind),
|
||||
"imports",
|
||||
);
|
||||
if (selected.kind === "invalid" || selected.kind === "invalid-config")
|
||||
return { status: "rejected", limitation: selected.limitation };
|
||||
if (selected.kind === "unmatched")
|
||||
return {
|
||||
status: "unmatched",
|
||||
declared: selected.declared,
|
||||
};
|
||||
if (selected.kind === "blocked")
|
||||
return { status: "blocked", cause: selected.cause };
|
||||
if (selected.kind === "non-relative")
|
||||
return { status: "non-relative", value: selected.value };
|
||||
return { status: "value", value: selected.value };
|
||||
};
|
||||
|
||||
/** Self references use the nearest package scope before dependency lookup. */
|
||||
const commonJsSelfCandidate = (
|
||||
input: ResolveArtifactPathInput,
|
||||
@@ -242,35 +363,22 @@ const commonJsSelfCandidate = (
|
||||
): CandidateResolution | null => {
|
||||
if (input.moduleKind !== "require" || !input.files.has(input.sourcePath))
|
||||
return null;
|
||||
let directory = posix.dirname(input.sourcePath);
|
||||
while (posix.basename(directory) !== "node_modules") {
|
||||
const metadata = readPackageMetadata(input, directory);
|
||||
if (metadata.kind === "unavailable")
|
||||
return unresolvedCandidate("unavailable", [metadata.limitation]);
|
||||
if (metadata.kind === "available") {
|
||||
if (
|
||||
metadata.name === undefined ||
|
||||
metadata.exports === undefined ||
|
||||
(declared !== metadata.name &&
|
||||
!declared.startsWith(`${metadata.name}/`))
|
||||
)
|
||||
return null;
|
||||
const subpath =
|
||||
declared === metadata.name
|
||||
? "."
|
||||
: `.${declared.slice(metadata.name.length)}`;
|
||||
// Self resolution does not apply the CommonJS dependency-name matcher.
|
||||
return resolvePackageExports(
|
||||
input,
|
||||
metadata.path,
|
||||
subpath,
|
||||
metadata.exports,
|
||||
);
|
||||
}
|
||||
if (directory === "." || directory === "") break;
|
||||
directory = posix.dirname(directory);
|
||||
}
|
||||
return null;
|
||||
const metadata = enclosingPackageMetadata(input);
|
||||
if (metadata.kind === "none") return null;
|
||||
if (metadata.kind === "unavailable")
|
||||
return unresolvedCandidate("unavailable", [metadata.limitation]);
|
||||
if (
|
||||
metadata.name === undefined ||
|
||||
metadata.exports === undefined ||
|
||||
(declared !== metadata.name && !declared.startsWith(`${metadata.name}/`))
|
||||
)
|
||||
return null;
|
||||
const subpath =
|
||||
declared === metadata.name
|
||||
? "."
|
||||
: `.${declared.slice(metadata.name.length)}`;
|
||||
// Self resolution does not apply the CommonJS dependency-name matcher.
|
||||
return resolvePackageExports(input, metadata.path, subpath, metadata.exports);
|
||||
};
|
||||
|
||||
/** Package roots and exact subpaths share metadata and exports selection. */
|
||||
@@ -324,16 +432,17 @@ const resolvePackageExports = (
|
||||
]);
|
||||
if (exported.status === "blocked")
|
||||
return unresolvedCandidate("external", [
|
||||
`Directory package metadata ${packagePath} blocks subpath ${subpath} with an explicit null exports target.`,
|
||||
`Directory package metadata ${packagePath} blocks subpath ${subpath} with ${exported.cause === "null" ? "an explicit null exports target" : "an empty exports target array"}.`,
|
||||
]);
|
||||
return resolveExportTarget(input, packagePath, exported.value);
|
||||
};
|
||||
|
||||
/** An exports target is a URL naming one exact file for both Node loaders. */
|
||||
/** An exports or import target is a URL naming one exact file for both Node loaders. */
|
||||
const resolveExportTarget = (
|
||||
input: ResolveArtifactPathInput,
|
||||
packagePath: string,
|
||||
target: string,
|
||||
mapKind: "exports" | "imports" = "exports",
|
||||
): CandidateResolution => {
|
||||
const rejected = rejectDeclaration(target);
|
||||
if (rejected !== null) return rejected;
|
||||
@@ -343,7 +452,7 @@ const resolveExportTarget = (
|
||||
if (typeof candidate !== "string") return candidate;
|
||||
return (
|
||||
resolveFileCandidates(input, [candidate]) ??
|
||||
exactExportsTargetNotFound(candidate)
|
||||
exactPackageTargetNotFound(candidate, mapKind)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -492,6 +601,7 @@ type PackageMetadata =
|
||||
readonly path: string;
|
||||
readonly name: string | undefined;
|
||||
readonly exports: string | object | undefined;
|
||||
readonly imports: object | undefined;
|
||||
readonly main: unknown;
|
||||
readonly module: unknown;
|
||||
}
|
||||
@@ -532,6 +642,7 @@ const readPackageMetadata = (
|
||||
};
|
||||
const name = Reflect.get(value, "name");
|
||||
const exports = Reflect.get(value, "exports");
|
||||
const imports = Reflect.get(value, "imports");
|
||||
return {
|
||||
kind: "available",
|
||||
path,
|
||||
@@ -543,6 +654,11 @@ const readPackageMetadata = (
|
||||
(typeof exports === "object" && exports !== null)
|
||||
? exports
|
||||
: undefined,
|
||||
// Import maps must be non-array objects; other shapes are not a map.
|
||||
imports:
|
||||
typeof imports === "object" && imports !== null && !Array.isArray(imports)
|
||||
? imports
|
||||
: undefined,
|
||||
main: Reflect.get(value, "main"),
|
||||
module: Reflect.get(value, "module"),
|
||||
};
|
||||
@@ -644,10 +760,12 @@ const fileCandidates = (candidate: string): readonly string[] => [
|
||||
const indexCandidates = (candidate: string): readonly string[] =>
|
||||
EXTENSIONS.map((extension) => posix.join(candidate, `index${extension}`));
|
||||
|
||||
type PackageTargetBlockCause = "null" | "empty-array";
|
||||
|
||||
type PackageExportOutcome =
|
||||
| { readonly status: "value"; readonly value: string }
|
||||
| { readonly status: "rejected"; readonly limitation: string }
|
||||
| { readonly status: "blocked" }
|
||||
| { readonly status: "blocked"; readonly cause: PackageTargetBlockCause }
|
||||
| { readonly status: "unmatched"; readonly declared: readonly string[] };
|
||||
|
||||
/** Only exact non-directory keys participate; wildcard expansion is unsupported. */
|
||||
@@ -687,29 +805,33 @@ const selectPackageExport = (
|
||||
if (selected.kind === "unmatched")
|
||||
return {
|
||||
status: "unmatched",
|
||||
declared:
|
||||
typeof target === "object" && target !== null
|
||||
? Object.keys(target)
|
||||
: declared,
|
||||
declared: selected.declared,
|
||||
};
|
||||
return selected.kind === "blocked"
|
||||
? { status: "blocked" }
|
||||
: { status: "value", value: selected.value };
|
||||
if (selected.kind === "blocked")
|
||||
return { status: "blocked", cause: selected.cause };
|
||||
if (selected.kind === "non-relative")
|
||||
return {
|
||||
status: "rejected",
|
||||
limitation: `The package exports target ${JSON.stringify(selected.value)} must start with "./".`,
|
||||
};
|
||||
return { status: "value", value: selected.value };
|
||||
};
|
||||
|
||||
type ExportTargetOutcome =
|
||||
| { readonly kind: "value"; readonly value: string }
|
||||
| { readonly kind: "blocked" }
|
||||
| { readonly kind: "unmatched" }
|
||||
| { readonly kind: "non-relative"; readonly value: string }
|
||||
| { readonly kind: "blocked"; readonly cause: PackageTargetBlockCause }
|
||||
| { readonly kind: "unmatched"; readonly declared: readonly string[] }
|
||||
| { readonly kind: "invalid"; readonly limitation: string }
|
||||
| { readonly kind: "invalid-config"; readonly limitation: string };
|
||||
|
||||
const invalidExportTarget = (
|
||||
value: unknown,
|
||||
reason: string,
|
||||
mapKind: "exports" | "imports" = "exports",
|
||||
): ExportTargetOutcome => ({
|
||||
kind: "invalid",
|
||||
limitation: `The package exports target ${JSON.stringify(value) ?? String(value)} ${reason}.`,
|
||||
limitation: `The package ${mapKind === "imports" ? "import" : "exports"} target ${JSON.stringify(value) ?? String(value)} ${reason}.`,
|
||||
});
|
||||
|
||||
// Node checks raw target segments before URL normalization. Compare encoded
|
||||
@@ -729,50 +851,80 @@ const forbiddenExportSegment = (value: string): string | undefined =>
|
||||
);
|
||||
});
|
||||
|
||||
const selectStringPackageTarget = (
|
||||
value: string,
|
||||
mapKind: "exports" | "imports",
|
||||
): ExportTargetOutcome => {
|
||||
if (mapKind === "imports") {
|
||||
const target = classifyPackageImportTargetString(value);
|
||||
if (target.kind === "invalid")
|
||||
return invalidExportTarget(
|
||||
value,
|
||||
"cannot be parent-relative, absolute, or a URL",
|
||||
mapKind,
|
||||
);
|
||||
if (target.kind !== "relative") return { kind: "non-relative", value };
|
||||
} else if (!value.startsWith("./"))
|
||||
return invalidExportTarget(value, 'must start with "./"', mapKind);
|
||||
const forbidden = forbiddenExportSegment(value);
|
||||
return forbidden === undefined
|
||||
? { kind: "value", value }
|
||||
: invalidExportTarget(
|
||||
value,
|
||||
`contains forbidden path segment ${JSON.stringify(forbidden)} before URL normalization`,
|
||||
mapKind,
|
||||
);
|
||||
};
|
||||
|
||||
const selectArrayPackageTarget = (
|
||||
value: readonly unknown[],
|
||||
conditions: ReadonlySet<string>,
|
||||
mapKind: "exports" | "imports",
|
||||
): ExportTargetOutcome => {
|
||||
if (value.length === 0) return { kind: "blocked", cause: "empty-array" };
|
||||
let lastRefusal:
|
||||
| Extract<ExportTargetOutcome, { readonly kind: "invalid" | "blocked" }>
|
||||
| undefined;
|
||||
const declared = new Set<string>();
|
||||
for (const entry of value) {
|
||||
const nested = selectExportTarget(entry, conditions, mapKind);
|
||||
// Node's array fallback catches invalid targets, not invalid configuration.
|
||||
if (nested.kind === "invalid-config") return nested;
|
||||
if (nested.kind === "unmatched") {
|
||||
for (const condition of nested.declared) declared.add(condition);
|
||||
continue;
|
||||
}
|
||||
if (nested.kind === "invalid" || nested.kind === "blocked") {
|
||||
lastRefusal = nested;
|
||||
continue;
|
||||
}
|
||||
return nested;
|
||||
}
|
||||
return lastRefusal ?? { kind: "unmatched", declared: [...declared] };
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve a target in Node's declared order. Explicit null blocks an active
|
||||
* condition, whereas an unmatched nested object permits the next condition.
|
||||
* An array skips unmatched and invalid entries, stops at its first string, and
|
||||
* preserves the final invalid-versus-null refusal if no string is selected.
|
||||
* preserves the last invalid/null outcome if no string is selected. A nonempty
|
||||
* array of unmatched conditions stays unmatched; an empty array blocks.
|
||||
*/
|
||||
const selectExportTarget = (
|
||||
value: unknown,
|
||||
conditions: ReadonlySet<string>,
|
||||
mapKind: "exports" | "imports" = "exports",
|
||||
): ExportTargetOutcome => {
|
||||
if (typeof value === "string") {
|
||||
if (!value.startsWith("./"))
|
||||
return invalidExportTarget(value, 'must start with "./"');
|
||||
const forbidden = forbiddenExportSegment(value);
|
||||
return forbidden === undefined
|
||||
? { kind: "value", value }
|
||||
: invalidExportTarget(
|
||||
value,
|
||||
`contains forbidden path segment ${JSON.stringify(forbidden)} before URL normalization`,
|
||||
);
|
||||
}
|
||||
if (value === null) return { kind: "blocked" };
|
||||
if (Array.isArray(value)) {
|
||||
let invalid: string | null = null;
|
||||
for (const entry of value) {
|
||||
const nested = selectExportTarget(entry, conditions);
|
||||
// Node's array fallback catches invalid targets, not invalid configuration.
|
||||
if (nested.kind === "invalid-config") return nested;
|
||||
if (nested.kind === "invalid") {
|
||||
invalid = nested.limitation;
|
||||
continue;
|
||||
}
|
||||
if (nested.kind === "unmatched") continue;
|
||||
invalid = null;
|
||||
if (nested.kind === "value") return nested;
|
||||
}
|
||||
return invalid === null
|
||||
? { kind: "blocked" }
|
||||
: { kind: "invalid", limitation: invalid };
|
||||
}
|
||||
if (typeof value === "string")
|
||||
return selectStringPackageTarget(value, mapKind);
|
||||
if (value === null) return { kind: "blocked", cause: "null" };
|
||||
if (Array.isArray(value))
|
||||
return selectArrayPackageTarget(value, conditions, mapKind);
|
||||
if (typeof value !== "object")
|
||||
return invalidExportTarget(
|
||||
value,
|
||||
"must be a relative string, object, array, or null",
|
||||
mapKind,
|
||||
);
|
||||
for (const key of Object.keys(value)) {
|
||||
const numeric = Number(key);
|
||||
@@ -782,12 +934,15 @@ const selectExportTarget = (
|
||||
limitation: `The package exports configuration contains numeric condition key ${JSON.stringify(key)}.`,
|
||||
};
|
||||
}
|
||||
const declared = new Set<string>();
|
||||
for (const [condition, target] of Object.entries(value)) {
|
||||
declared.add(condition);
|
||||
if (!conditions.has(condition)) continue;
|
||||
const nested = selectExportTarget(target, conditions);
|
||||
const nested = selectExportTarget(target, conditions, mapKind);
|
||||
if (nested.kind !== "unmatched") return nested;
|
||||
for (const name of nested.declared) declared.add(name);
|
||||
}
|
||||
return { kind: "unmatched" };
|
||||
return { kind: "unmatched", declared: [...declared] };
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -816,11 +971,14 @@ const notFoundCandidate = (): CandidateResolution => ({
|
||||
],
|
||||
});
|
||||
|
||||
const exactExportsTargetNotFound = (path: string): CandidateResolution => ({
|
||||
const exactPackageTargetNotFound = (
|
||||
path: string,
|
||||
mapKind: "exports" | "imports",
|
||||
): CandidateResolution => ({
|
||||
resolvedPath: null,
|
||||
status: "not-found",
|
||||
limitations: [
|
||||
`The selected package exports target ${path} does not exist in the inventoried artifact container; exports targets are exact files, so no extension or directory index was tried.`,
|
||||
`The selected package ${mapKind === "imports" ? "import" : "exports"} target ${path} does not exist in the inventoried artifact container; ${mapKind === "imports" ? "import" : "exports"} targets are exact files, so no extension or directory index was tried.`,
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { orderAsarListing } from "./AsarArtifactReader.js";
|
||||
|
||||
describe("orderAsarListing", () => {
|
||||
it("orders host-spelled listings by their portable archive path", () => {
|
||||
const posix = orderAsarListing(["/a0", "/a", "/a/b"], "/");
|
||||
const windows = orderAsarListing(["\\a0", "\\a", "\\a\\b"], "\\");
|
||||
|
||||
// "/" (0x2F) precedes "0" (0x30); "\" (0x5C) would follow it.
|
||||
expect(posix.map(({ path }) => path)).toEqual(["a", "a/b", "a0"]);
|
||||
expect(windows.map(({ path }) => path)).toEqual(["a", "a/b", "a0"]);
|
||||
expect(windows.map(({ listed }) => listed)).toEqual([
|
||||
"\\a",
|
||||
"\\a\\b",
|
||||
"\\a0",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps POSIX backslashes as literal filename characters", () => {
|
||||
expect(orderAsarListing(["/a\\b"], "/")).toEqual([
|
||||
{ listed: "/a\\b", path: "a\\b" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -32,6 +32,7 @@ import { closeAsarHandle, readValidatedAsarEntry } from "./AsarEntryStream.js";
|
||||
import { admitAsarHeader } from "./AsarHeader.js";
|
||||
import { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
|
||||
import { readFileHandleChunks } from "../filesystem/readFileHandleChunks.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/**
|
||||
* Official Electron ASAR adapter with range-streamed member reads.
|
||||
@@ -64,7 +65,7 @@ export class AsarArtifactReader implements ArtifactReader {
|
||||
) {}
|
||||
|
||||
async *entries(signal?: AbortSignal): AsyncIterable<ArtifactEntry> {
|
||||
let paths: string[];
|
||||
let paths: readonly AsarListedPath[];
|
||||
try {
|
||||
await this.prepareContainer(undefined, signal);
|
||||
const snapshotPath = this.#snapshotPath();
|
||||
@@ -82,9 +83,7 @@ export class AsarArtifactReader implements ArtifactReader {
|
||||
await headerHandle.close();
|
||||
}
|
||||
abortIfNeeded(signal);
|
||||
paths = listPackage(snapshotPath, { isPack: false }).sort((left, right) =>
|
||||
left.localeCompare(right, "en"),
|
||||
);
|
||||
paths = orderAsarListing(listPackage(snapshotPath, { isPack: false }));
|
||||
const archiveMetadata = await lstat(snapshotPath);
|
||||
if (!archiveMetadata.isFile() || archiveMetadata.isSymbolicLink())
|
||||
throw new ArtifactReaderFailure(
|
||||
@@ -95,13 +94,8 @@ export class AsarArtifactReader implements ArtifactReader {
|
||||
} catch (cause: unknown) {
|
||||
throw asarFailure(this.path, "inventory", cause);
|
||||
}
|
||||
for (const listed of paths) {
|
||||
for (const { listed, path } of paths) {
|
||||
abortIfNeeded(signal);
|
||||
// @electron/asar returns paths assembled with the host path module.
|
||||
// Keep that spelling for its API calls, but expose archive paths with
|
||||
// portable separators. On POSIX, backslashes can be literal filename
|
||||
// characters and must remain untouched.
|
||||
const path = toArtifactPath(listed);
|
||||
if (path.length === 0) continue;
|
||||
const providerPath = listed.startsWith(sep)
|
||||
? listed.slice(sep.length)
|
||||
@@ -577,8 +571,30 @@ const waitForOperation = async (
|
||||
});
|
||||
};
|
||||
|
||||
const toArtifactPath = (listed: string): string => {
|
||||
const portable = sep === "\\" ? listed.replaceAll("\\", "/") : listed;
|
||||
interface AsarListedPath {
|
||||
readonly listed: string;
|
||||
readonly path: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pair each host-spelled listing with its portable archive path, ordered by
|
||||
* the portable path so Windows and POSIX hosts agree.
|
||||
*
|
||||
* @electron/asar returns paths assembled with the host path module. Keep that
|
||||
* spelling for its API calls, but expose archive paths with portable
|
||||
* separators. On POSIX, backslashes can be literal filename characters and
|
||||
* must remain untouched.
|
||||
*/
|
||||
export const orderAsarListing = (
|
||||
listed: readonly string[],
|
||||
separator: string = sep,
|
||||
): AsarListedPath[] =>
|
||||
listed
|
||||
.map((entry) => ({ listed: entry, path: toArtifactPath(entry, separator) }))
|
||||
.sort((left, right) => compareUnicodeCodePoints(left.path, right.path));
|
||||
|
||||
const toArtifactPath = (listed: string, separator: string): string => {
|
||||
const portable = separator === "\\" ? listed.replaceAll("\\", "/") : listed;
|
||||
return portable.replace(/^\/+|\/+$/gu, "");
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,16 @@ describe("hostExecutableMarking", () => {
|
||||
expect(
|
||||
hostExecutableMarking("C:\\scratch\\SETUP.CMD", file(0o444), "win32"),
|
||||
).toBe(true);
|
||||
for (const path of [
|
||||
"tools/SETUP.EXE",
|
||||
"run.Cmd",
|
||||
"build.bat",
|
||||
"legacy.com",
|
||||
])
|
||||
expect(hostExecutableMarking(path, file(0o666), "win32")).toBe(true);
|
||||
expect(hostExecutableMarking("readonly.exe", file(0o444), "win32")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
hostExecutableMarking("C:\\scratch\\library.dll", file(0o666), "win32"),
|
||||
).toBe(false);
|
||||
@@ -25,6 +35,11 @@ describe("hostExecutableMarking", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("does not treat other Windows filenames as executable even with execute bits", () => {
|
||||
for (const path of ["notes.txt", "README", "archive.exe.bak"])
|
||||
expect(hostExecutableMarking(path, file(0o777), "win32")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps POSIX permission bits authoritative regardless of extension", () => {
|
||||
expect(hostExecutableMarking("/scratch/tool", file(0o755), "linux")).toBe(
|
||||
true,
|
||||
|
||||
@@ -68,6 +68,7 @@ import { captureCdpScreenshot } from "./CdpScreenshot.js";
|
||||
import { comparePngScreenshots } from "./PngVisualDiff.js";
|
||||
|
||||
import { CDP_BROWSER_PROVIDER_IDENTITY } from "./providerIdentities.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
const CLEANUP_DOMAINS = ["Network", "Debugger", "Runtime", "Page"] as const;
|
||||
|
||||
/** Passive browser observation through a selected user-owned CDP endpoint. */
|
||||
@@ -408,7 +409,9 @@ const selectTargets = (
|
||||
attached: target.attached,
|
||||
});
|
||||
}
|
||||
allowed.sort((left, right) => left.target_id.localeCompare(right.target_id));
|
||||
allowed.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.target_id, right.target_id),
|
||||
);
|
||||
return {
|
||||
allowed,
|
||||
excluded: {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import { exclusionReasonForUrl } from "./CdpCaptureEventHelpers.js";
|
||||
import type { CdpCaptureCompleteness } from "./CdpCaptureCompleteness.js";
|
||||
import { createDocumentSvgAncestry, domSvgLink } from "./CdpCaptureDomSvg.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
export type CapturedResource = Omit<
|
||||
WebPageInspection["resources"][number],
|
||||
@@ -346,7 +347,7 @@ const accessibilityStates = (
|
||||
if (state !== undefined) states.set(name, state);
|
||||
}
|
||||
return [...states]
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
.sort(([left], [right]) => compareUnicodeCodePoints(left, right))
|
||||
.map(([name, state]) => ({ name, value: state }));
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
import { captureElectronScripts } from "./CdpElectronScripts.js";
|
||||
import { captureElectronWorkers } from "./CdpElectronWorkers.js";
|
||||
import { authorizedElectronFile } from "./ElectronFileScope.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
interface ElectronContext {
|
||||
readonly connection: CdpConnection;
|
||||
@@ -300,7 +301,7 @@ const captureResources = async (
|
||||
pending.push(...recordsValue(tree.childFrames));
|
||||
}
|
||||
return resources.sort((left, right) =>
|
||||
left.resource_key.localeCompare(right.resource_key),
|
||||
compareUnicodeCodePoints(left.resource_key, right.resource_key),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import { inspectCdpElectronPage } from "./CdpElectronInspection.js";
|
||||
import { authorizedElectronFile } from "./ElectronFileScope.js";
|
||||
|
||||
import { CDP_ELECTRON_PROVIDER_IDENTITY } from "./providerIdentities.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
/** Passive Electron provider for local file pages exposed by loopback CDP. */
|
||||
export class CdpElectronProvider implements ElectronObservationPort {
|
||||
identity(): ProviderIdentity {
|
||||
@@ -73,7 +74,7 @@ export class CdpElectronProvider implements ElectronObservationPort {
|
||||
});
|
||||
}
|
||||
allowed.sort((left, right) =>
|
||||
left.target_id.localeCompare(right.target_id),
|
||||
compareUnicodeCodePoints(left.target_id, right.target_id),
|
||||
);
|
||||
return ok(
|
||||
electronTargetListSchema.parse({
|
||||
|
||||
@@ -9,6 +9,7 @@ import { CdpCaptureCompleteness } from "./CdpCaptureCompleteness.js";
|
||||
import { requiredScriptSource } from "./CdpCaptureValues.js";
|
||||
import type { ElectronScriptDraft } from "./CdpElectronScriptEvents.js";
|
||||
import { authorizedElectronFile } from "./ElectronFileScope.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
interface ElectronScriptCaptureInput {
|
||||
readonly connection: CdpConnection;
|
||||
@@ -65,7 +66,7 @@ export const captureElectronScripts = async (
|
||||
return {
|
||||
total,
|
||||
items: items.sort((left, right) =>
|
||||
left.script_key.localeCompare(right.script_key),
|
||||
compareUnicodeCodePoints(left.script_key, right.script_key),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import type { CdpEndpointTarget } from "./CdpEndpoint.js";
|
||||
import { optionalCdpCommand } from "./CdpOptionalCommand.js";
|
||||
import { authorizedElectronFile } from "./ElectronFileScope.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Inventory local worker targets without attaching to them. */
|
||||
export const captureElectronWorkers = async (input: {
|
||||
@@ -70,7 +71,7 @@ export const captureElectronWorkers = async (input: {
|
||||
});
|
||||
}
|
||||
return workers.sort((left, right) =>
|
||||
left.target_id.localeCompare(right.target_id),
|
||||
compareUnicodeCodePoints(left.target_id, right.target_id),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from "./CdpCaptureValues.js";
|
||||
import type { CaptureContext } from "./CdpPageCapture.js";
|
||||
import type { WebSourceMapRequest } from "./WebSourceMapFetcher.js";
|
||||
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
||||
|
||||
export interface CapturedScripts {
|
||||
readonly inventory: WebPageInspection["scripts"];
|
||||
@@ -131,11 +132,15 @@ const keyAndBuildInventory = (
|
||||
}));
|
||||
keyed.sort(
|
||||
(left, right) =>
|
||||
left.base.localeCompare(right.base) ||
|
||||
sourceDigest(left.item.source).localeCompare(
|
||||
compareUnicodeCodePoints(left.base, right.base) ||
|
||||
compareUnicodeCodePoints(
|
||||
sourceDigest(left.item.source),
|
||||
sourceDigest(right.item.source),
|
||||
) ||
|
||||
(left.item.frame_id ?? "").localeCompare(right.item.frame_id ?? ""),
|
||||
compareUnicodeCodePoints(
|
||||
left.item.frame_id ?? "",
|
||||
right.item.frame_id ?? "",
|
||||
),
|
||||
);
|
||||
const totals = new Map<string, number>();
|
||||
for (const { base } of keyed) totals.set(base, (totals.get(base) ?? 0) + 1);
|
||||
|
||||
@@ -7,7 +7,10 @@ import type {
|
||||
} from "../domain/webMcpDiscovery.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { digestCanonicalValue } from "../domain/canonicalDigest.js";
|
||||
import { compositeKey } from "../domain/unicodeCodePointOrder.js";
|
||||
import {
|
||||
compareUnicodeCodePoints,
|
||||
compositeKey,
|
||||
} from "../domain/unicodeCodePointOrder.js";
|
||||
import type { CdpEndpointDiscovery, CdpEndpointTarget } from "./CdpEndpoint.js";
|
||||
import type { CdpConnection, CdpEvent } from "./CdpConnection.js";
|
||||
import { CdpCaptureCompleteness } from "./CdpCaptureCompleteness.js";
|
||||
@@ -521,7 +524,7 @@ const buildWebMcpResult = (options: WebMcpResultOptions): WebMcpDiscovery => {
|
||||
tools: {
|
||||
total: tools.size + completeness.droppedTotal,
|
||||
items: [...tools.values()].sort((left, right) =>
|
||||
left.tool_key.localeCompare(right.tool_key),
|
||||
compareUnicodeCodePoints(left.tool_key, right.tool_key),
|
||||
),
|
||||
},
|
||||
completeness: completeness.snapshot(),
|
||||
|
||||
@@ -6,9 +6,10 @@ import { z } from "zod";
|
||||
import { PROMPT_CONTRACTS } from "./contracts/promptContracts.js";
|
||||
import { TOOL_CONTRACTS } from "./contracts/toolContracts.js";
|
||||
import { CLI_COMMAND_NAMES } from "./cliCommandNames.js";
|
||||
import { compareUnicodeCodePoints } from "./domain/unicodeCodePointOrder.js";
|
||||
|
||||
const sortedToolContracts = [...TOOL_CONTRACTS].sort((left, right) =>
|
||||
left.name.localeCompare(right.name),
|
||||
compareUnicodeCodePoints(left.name, right.name),
|
||||
);
|
||||
|
||||
const createToolCatalog = () =>
|
||||
@@ -39,7 +40,7 @@ const promptCatalog = PROMPT_CONTRACTS.map((contract) => ({
|
||||
description: contract.description,
|
||||
arguments: contract.arguments,
|
||||
steps: contract.steps,
|
||||
})).sort((left, right) => left.name.localeCompare(right.name));
|
||||
})).sort((left, right) => compareUnicodeCodePoints(left.name, right.name));
|
||||
|
||||
const digest = (value: unknown): string => {
|
||||
const encoded = canonicalize(value);
|
||||
|
||||
@@ -8,9 +8,8 @@ import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import type { Logger } from "pino";
|
||||
import {
|
||||
directAnalysisOptions,
|
||||
formatSelectionOption,
|
||||
providerSelectionOption,
|
||||
directAnalysisOptionsFromCli,
|
||||
nativeOpenOptionFields,
|
||||
} from "./options.js";
|
||||
import type { CliInstance } from "./types.js";
|
||||
import { runCliJavaScriptApplicationAnalysis } from "./javascriptApplicationAnalysis.js";
|
||||
@@ -43,8 +42,7 @@ const registerOverviewCommands = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
});
|
||||
cli.command(CLI_COMMANDS.analyze, {
|
||||
description: "Get an overview of an app",
|
||||
@@ -75,12 +73,7 @@ const registerOverviewCommands = (
|
||||
args.path,
|
||||
"binary_overview",
|
||||
{},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -97,12 +90,7 @@ const registerOverviewCommands = (
|
||||
args.path,
|
||||
"binary_overview",
|
||||
{},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -136,8 +124,7 @@ const registerDecompileCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "decompile", () =>
|
||||
@@ -152,12 +139,7 @@ const registerDecompileCommand = (
|
||||
"procedure_pseudo_code",
|
||||
),
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -168,13 +150,17 @@ const routesToJavaScriptAnalysis = async (
|
||||
path: string,
|
||||
options: {
|
||||
readonly snapshot?: string | undefined;
|
||||
readonly "target-format"?: "dos-com" | undefined;
|
||||
readonly "target-format"?: "dos-com" | "raw-binary" | undefined;
|
||||
readonly architecture?: string | undefined;
|
||||
readonly "entry-point"?: string | undefined;
|
||||
readonly provider?: string | undefined;
|
||||
},
|
||||
): Promise<boolean> =>
|
||||
options.provider === undefined &&
|
||||
options.snapshot === undefined &&
|
||||
options["target-format"] === undefined &&
|
||||
options.architecture === undefined &&
|
||||
options["entry-point"] === undefined &&
|
||||
(await isJavaScriptApplicationPath(path));
|
||||
|
||||
const isJavaScriptApplicationPath = async (path: string): Promise<boolean> => {
|
||||
@@ -215,8 +201,7 @@ const registerXrefsCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "xrefs", () =>
|
||||
@@ -231,12 +216,7 @@ const registerXrefsCommand = (
|
||||
"xrefs",
|
||||
),
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -270,8 +250,7 @@ const registerTraceCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "trace", () =>
|
||||
@@ -287,12 +266,7 @@ const registerTraceCommand = (
|
||||
),
|
||||
case_sensitive: options.caseSensitive,
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -326,8 +300,7 @@ const registerFunctionCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "function", () =>
|
||||
@@ -342,12 +315,7 @@ const registerFunctionCommand = (
|
||||
"analyze_function",
|
||||
),
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -381,8 +349,7 @@ const registerInstructionsCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.instructions, () =>
|
||||
@@ -397,12 +364,7 @@ const registerInstructionsCommand = (
|
||||
"read_function_instructions",
|
||||
),
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -448,8 +410,7 @@ const registerSearchCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "search", () =>
|
||||
@@ -468,12 +429,7 @@ const registerSearchCommand = (
|
||||
mode: options.mode,
|
||||
case_sensitive: options.caseSensitive,
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -5,9 +5,8 @@ import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import type { Logger } from "pino";
|
||||
import {
|
||||
directAnalysisOptions,
|
||||
formatSelectionOption,
|
||||
providerSelectionOption,
|
||||
directAnalysisOptionsFromCli,
|
||||
nativeOpenOptionFields,
|
||||
} from "./options.js";
|
||||
import type { CliInstance } from "./types.js";
|
||||
|
||||
@@ -23,8 +22,7 @@ export const registerCoreNativeCommands = (
|
||||
"Verify loaded native bytes, source mappings, relocations and entry",
|
||||
args: z.object({ path: z.string().describe("Local executable path") }),
|
||||
options: z.object({
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectNativeLoadImage, () =>
|
||||
@@ -32,12 +30,7 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
"inspect_native_load_image",
|
||||
{},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -54,8 +47,7 @@ export const registerCoreNativeCommands = (
|
||||
.min(1)
|
||||
.default(256)
|
||||
.describe("Requested byte count"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.readBytes, () =>
|
||||
@@ -63,12 +55,7 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
"read_bytes",
|
||||
{ address: args.address, length: options.length },
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -79,8 +66,7 @@ export const registerCoreNativeCommands = (
|
||||
address: z.string().describe("Exact provider memory address"),
|
||||
}),
|
||||
options: z.object({
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.addressToFileOffset, () =>
|
||||
@@ -88,12 +74,7 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
"address_to_file_offset",
|
||||
{ address: args.address },
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -154,8 +135,7 @@ export const registerCoreNativeCommands = (
|
||||
.max(5000)
|
||||
.default(1000)
|
||||
.describe("Maximum nodes on this page"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.traceNativeValues, () =>
|
||||
@@ -172,12 +152,7 @@ export const registerCoreNativeCommands = (
|
||||
offset: options.offset,
|
||||
limit: options.limit,
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -189,8 +164,7 @@ export const registerCoreNativeCommands = (
|
||||
options: z.object({
|
||||
type: z.string().optional().describe("Exact database type category path"),
|
||||
address: z.string().optional().describe("Exact native address"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectNativeDataType, () =>
|
||||
@@ -203,12 +177,7 @@ export const registerCoreNativeCommands = (
|
||||
? {}
|
||||
: { address: options.address }),
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -226,8 +195,7 @@ export const registerCoreNativeCommands = (
|
||||
address: z.string().describe("Exact native address"),
|
||||
}),
|
||||
options: z.object({
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, command, () =>
|
||||
@@ -235,12 +203,7 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
operation,
|
||||
{ address: args.address },
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -273,8 +236,7 @@ const registerNativeDispatchMetadataCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load or update the local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: async ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-native-dispatch-metadata", () =>
|
||||
@@ -282,12 +244,7 @@ const registerNativeDispatchMetadataCommand = (
|
||||
args.path,
|
||||
"inspect_native_dispatch_metadata",
|
||||
{ max_records: options.maxRecords },
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -332,8 +289,7 @@ const registerNativeUiActionCommand = (
|
||||
.max(5_000)
|
||||
.default(500)
|
||||
.describe("Maximum returned graph edges"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: async ({ args, options }) =>
|
||||
logCliCommand(logger, "trace-native-ui-action", () =>
|
||||
@@ -346,12 +302,7 @@ const registerNativeUiActionCommand = (
|
||||
max_nodes: options.maxNodes,
|
||||
max_edges: options.maxEdges,
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -374,8 +325,7 @@ const registerNativeApiCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-native-api", () =>
|
||||
@@ -383,12 +333,7 @@ const registerNativeApiCommand = (
|
||||
args.path,
|
||||
"inspect_native_api",
|
||||
{ procedure: args.address },
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -417,8 +362,7 @@ const registerAnnotationCommand = (
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Inline entry comment; empty text clears it"),
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
...nativeOpenOptionFields,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.annotateNativeFunction, () =>
|
||||
@@ -435,12 +379,7 @@ const registerAnnotationCommand = (
|
||||
? {}
|
||||
: { inline_comment: options["inline-comment"] }),
|
||||
},
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
+55
-1
@@ -2,6 +2,11 @@ import {
|
||||
executableFormatHintSchema,
|
||||
type ExecutableFormatHint,
|
||||
} from "../domain/dosCom.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
binaryArchitectureSchema,
|
||||
rawBinaryEntryPointSchema,
|
||||
} from "../domain/rawBinary.js";
|
||||
import { analysisProviderSelectorSchema } from "../contracts/providerSelection.js";
|
||||
import type { AnalysisProviderSelector } from "../contracts/providerSelection.js";
|
||||
import type { Logger } from "pino";
|
||||
@@ -15,16 +20,65 @@ export const providerSelectionOption = analysisProviderSelectorSchema
|
||||
/** Explicit interpretation for headerless native executable formats. */
|
||||
export const formatSelectionOption = executableFormatHintSchema
|
||||
.optional()
|
||||
.describe("Explicit headerless DOS COM interpretation");
|
||||
.describe(
|
||||
"Explicit headerless interpretation (dos-com or raw-binary); omission preserves header-based detection",
|
||||
);
|
||||
|
||||
export const architectureSelectionOption = binaryArchitectureSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied CPU family; required with --target-format raw-binary",
|
||||
);
|
||||
|
||||
export const entryPointSelectionOption = rawBinaryEntryPointSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied load and entry address (0xhex); required with --target-format raw-binary",
|
||||
);
|
||||
|
||||
/** Shared CLI flags that bind a native target interpretation. */
|
||||
export const nativeOpenOptionFields = {
|
||||
"target-format": formatSelectionOption,
|
||||
architecture: architectureSelectionOption,
|
||||
"entry-point": entryPointSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
};
|
||||
|
||||
/** Native CLI flags consumed when opening a target for one-shot analysis. */
|
||||
export interface NativeOpenCliFlags {
|
||||
readonly snapshot?: string | undefined;
|
||||
readonly provider?: AnalysisProviderSelector | undefined;
|
||||
readonly "target-format"?: ExecutableFormatHint | undefined;
|
||||
readonly architecture?: BinaryArchitecture | undefined;
|
||||
readonly "entry-point"?: string | undefined;
|
||||
}
|
||||
|
||||
export const directAnalysisOptions = (
|
||||
logger: Logger,
|
||||
snapshotPath: string | undefined,
|
||||
providerId: AnalysisProviderSelector | undefined,
|
||||
formatHint?: ExecutableFormatHint,
|
||||
architecture?: BinaryArchitecture,
|
||||
entryPoint?: string,
|
||||
) => ({
|
||||
logger,
|
||||
snapshotPath,
|
||||
...(formatHint === undefined ? {} : { formatHint }),
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
...(entryPoint === undefined ? {} : { entryPoint }),
|
||||
...(providerId === undefined ? {} : { providerId }),
|
||||
});
|
||||
|
||||
/** Map native CLI flags onto the shared one-shot analysis options. */
|
||||
export const directAnalysisOptionsFromCli = (
|
||||
logger: Logger,
|
||||
options: NativeOpenCliFlags,
|
||||
) =>
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
options.architecture,
|
||||
options["entry-point"],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { openBinaryInputSchema } from "./sessionLifecycleInputs.js";
|
||||
|
||||
describe("open_binary raw-binary input contract", () => {
|
||||
it("accepts header detection without architecture", () => {
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({ path: "/tmp/fixture.bin" }).success,
|
||||
).toBe(true);
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/legacy.com",
|
||||
format: "dos-com",
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
it("accepts raw-binary with architecture and entry", () => {
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entry_point: "0x8000000",
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
it("rejects raw-binary without architecture or entry", () => {
|
||||
const parsed = openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
format: "raw-binary",
|
||||
});
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
it("rejects architecture without format=raw-binary", () => {
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
architecture: "arm",
|
||||
entry_point: "0x8000000",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,11 @@
|
||||
import { isAbsolute } from "node:path";
|
||||
import { executableFormatHintSchema } from "../domain/dosCom.js";
|
||||
import { localPathStringSchema } from "../domain/localPath.js";
|
||||
import {
|
||||
binaryArchitectureSchema,
|
||||
rawBinaryEntryPointSchema,
|
||||
rawBinarySelectionError,
|
||||
} from "../domain/rawBinary.js";
|
||||
import { z } from "zod";
|
||||
import { analysisProviderSelectorSchema } from "./providerSelection.js";
|
||||
|
||||
@@ -25,16 +30,51 @@ const binaryTargetPathSchema = localPathStringSchema
|
||||
);
|
||||
|
||||
/** Input contract for opening a target with an optional staged snapshot. */
|
||||
export const openBinaryInputSchema = z.strictObject({
|
||||
path: binaryTargetPathSchema,
|
||||
format: executableFormatHintSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Explicit headerless DOS COM interpretation; omission preserves header-based detection",
|
||||
),
|
||||
provider_id: analysisProviderSelectorSchema.optional(),
|
||||
snapshot_path: snapshotPathSchema.optional(),
|
||||
});
|
||||
export const openBinaryInputSchema = z
|
||||
.strictObject({
|
||||
path: binaryTargetPathSchema,
|
||||
format: executableFormatHintSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Explicit headerless interpretation: dos-com or raw-binary. Omission preserves header-based detection.",
|
||||
),
|
||||
architecture: binaryArchitectureSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied CPU family. Required with format=raw-binary; rejected otherwise.",
|
||||
),
|
||||
entry_point: rawBinaryEntryPointSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied load and entry address (0xhex). File offset 0 is mapped here. Required with format=raw-binary; rejected otherwise.",
|
||||
),
|
||||
provider_id: analysisProviderSelectorSchema.optional(),
|
||||
snapshot_path: snapshotPathSchema.optional(),
|
||||
})
|
||||
.superRefine((value, context) => {
|
||||
const pairing = rawBinarySelectionError({
|
||||
...(value.format === undefined ? {} : { format: value.format }),
|
||||
...(value.architecture === undefined
|
||||
? {}
|
||||
: { architecture: value.architecture }),
|
||||
...(value.entry_point === undefined
|
||||
? {}
|
||||
: { entryPoint: value.entry_point }),
|
||||
});
|
||||
if (pairing === undefined) return;
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path:
|
||||
value.format === "raw-binary"
|
||||
? value.architecture === undefined
|
||||
? ["architecture"]
|
||||
: ["entry_point"]
|
||||
: value.architecture === undefined
|
||||
? ["entry_point"]
|
||||
: ["architecture"],
|
||||
message: pairing,
|
||||
});
|
||||
});
|
||||
|
||||
/** Input contract for closing a target after an optional atomic snapshot. */
|
||||
export const closeBinaryInputSchema = z.strictObject({
|
||||
|
||||
@@ -69,7 +69,7 @@ export const exportEvidenceBundleInputSchema = z.strictObject({
|
||||
export const SESSION_TOOL_CONTRACTS = [
|
||||
session(
|
||||
"open_binary",
|
||||
"Open a local executable, application bundle, archive, JavaScript, source map, plist, or analysis database after validation. format=dos-com explicitly interprets 1..65280 headerless bytes as a DOS COM analysis image; omission preserves header-based detection. provider_id selects one deep provider or deterministic auto selection; the binding remains stable until close or an explicit switch, with no failure fallback. Reopening the same target and profile retains its active database and metadata edits. An optional analysis snapshot is imported atomically and must match the binary identity, concrete provider, and canonical analysis profile exactly; importing into a session with metadata mutations requires closing and reopening it first.",
|
||||
"Open a local executable, application bundle, archive, JavaScript, source map, plist, or analysis database after validation. format=dos-com explicitly interprets 1..65280 headerless bytes as a DOS COM analysis image. format=raw-binary interprets headerless bytes with a required architecture and entry_point; file offset 0 maps at that address. Omission preserves header-based detection. provider_id selects one deep provider or deterministic auto selection; the binding remains stable until close or an explicit switch, with no failure fallback. Reopening the same target and profile retains its active database and metadata edits. An optional analysis snapshot is imported atomically and must match the binary identity, concrete provider, and canonical analysis profile exactly; importing into a session with metadata mutations requires closing and reopening it first.",
|
||||
openBinaryInputSchema,
|
||||
),
|
||||
session(
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { TOOL_CONTRACTS } from "./toolContracts.js";
|
||||
import { TOOL_EFFECTS, annotationsFromEffects } from "./toolEffects.js";
|
||||
|
||||
/**
|
||||
* Descriptions that name running, launching, executing, starting, installing,
|
||||
* or uninstalling something. A matching tool must declare foreign execution or
|
||||
* device mutation unless it is listed below with the reason the wording does
|
||||
* not describe that effect.
|
||||
*/
|
||||
const EXECUTION_WORDING =
|
||||
/\b(?:run|runs|running|launch|launches|launching|execute|executes|executing|execution|start|starts|install|installs|uninstall|uninstalls)\b/iu;
|
||||
|
||||
const EXECUTION_WORDING_EXCEPTIONS: Readonly<Record<string, string>> = {
|
||||
inspect_native_load_image: "states that it does not execute the target",
|
||||
resolve_native_call_targets: "states that it does not execute code",
|
||||
inspect_pe_resources: "states that it does not execute the image",
|
||||
inspect_binary_layout:
|
||||
"parses the binary offline with operator-configured pwntools",
|
||||
inspect_recorded_crash: "inspects a core file without launching its target",
|
||||
inspect_macho: "runs host Mach-O inspection tools, not the target",
|
||||
inspect_evm_interface:
|
||||
"decodes bytecode in REA's bundled worker without executing it",
|
||||
inspect_managed_artifact: "reads metadata without executing target code",
|
||||
inspect_managed_members: "reads metadata without executing target code",
|
||||
inspect_managed_native_boundaries:
|
||||
"reads metadata without executing target code",
|
||||
verify_managed_native_boundaries: "states it does not execute managed code",
|
||||
project_managed_application_graph: "states it does not execute managed code",
|
||||
inspect_android_package: "states it does not execute the APK",
|
||||
search_android_classes: "states it does not execute the APK",
|
||||
inspect_apktool_client:
|
||||
"inspects the operator-selected apktool launcher; never installs it",
|
||||
inspect_jeb_client: "talks to a caller-started JEB; never launches it",
|
||||
open_jeb_project: "the engine analyzes the file; REA does not execute it",
|
||||
inspect_adb_client:
|
||||
"inspects the operator-selected adb client; never starts its server",
|
||||
list_adb_devices: "may start the local adb server, which REA does not own",
|
||||
inspect_firmware_regions: "states there is no target execution",
|
||||
extract_firmware: "states that extracted code is never executed",
|
||||
analyze_javascript_application: "reconstructs the graph without executing",
|
||||
reconcile_javascript_runtime: "never invents execution claims",
|
||||
observe_javascript_runtime: "never evaluates or resumes the target",
|
||||
trace_application_feature: "never executes the application",
|
||||
trace_javascript_semantics: "static reachability never claims execution",
|
||||
compare_javascript_export_shapes: "states it does not execute JavaScript",
|
||||
project_android_application_graph: "execution-free inventory",
|
||||
project_apple_application_graph: "execution-free inventory",
|
||||
trace_web_source_location: "states there is no application execution",
|
||||
trace_web_module_imports:
|
||||
"runs only REA's resolver stub in operator-configured Chromium",
|
||||
export_web_scripts: "states there is no refetch or execution",
|
||||
observe_web_execution:
|
||||
"instruments an externally driven page; it does not run code itself",
|
||||
recover_javascript_sources: "states there is no application code execution",
|
||||
goto_address: "start names an object boundary, not a launch",
|
||||
prev_address: "start names an object boundary, not a launch",
|
||||
trace_call_path: "start names the traversal origin",
|
||||
observe_native_ui: "observes an already-running app without launching it",
|
||||
inspect_adb_package: "reports install times without changing the device",
|
||||
list_adb_processes: "lists running processes without changing the device",
|
||||
inspect_web_event_listeners: "states it does not evaluate JavaScript",
|
||||
};
|
||||
|
||||
const declaresForeignAuthority = (name: string): boolean => {
|
||||
const effects = TOOL_EFFECTS[name];
|
||||
return (
|
||||
effects !== undefined &&
|
||||
(effects.executesForeignCode || effects.mutatesDevice)
|
||||
);
|
||||
};
|
||||
|
||||
describe("tool effects", () => {
|
||||
it("audits every public tool exactly once", () => {
|
||||
expect(Object.keys(TOOL_EFFECTS).sort()).toEqual(
|
||||
TOOL_CONTRACTS.map(({ name }) => name).sort(),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps execution and device wording aligned with declared effects", () => {
|
||||
const undeclared = TOOL_CONTRACTS.filter(
|
||||
({ name, description }) =>
|
||||
EXECUTION_WORDING.test(description) &&
|
||||
!declaresForeignAuthority(name) &&
|
||||
EXECUTION_WORDING_EXCEPTIONS[name] === undefined,
|
||||
).map(({ name }) => name);
|
||||
expect(undeclared).toEqual([]);
|
||||
const staleExceptions = Object.keys(EXECUTION_WORDING_EXCEPTIONS).filter(
|
||||
(name) => {
|
||||
const contract = TOOL_CONTRACTS.find(
|
||||
(candidate) => candidate.name === name,
|
||||
);
|
||||
return (
|
||||
contract === undefined ||
|
||||
!EXECUTION_WORDING.test(contract.description) ||
|
||||
declaresForeignAuthority(name)
|
||||
);
|
||||
},
|
||||
);
|
||||
expect(staleExceptions).toEqual([]);
|
||||
});
|
||||
|
||||
it("marks foreign execution and device mutation as destructive", () => {
|
||||
const destructive = TOOL_CONTRACTS.filter(
|
||||
({ effects }) => effects.executesForeignCode || effects.mutatesDevice,
|
||||
);
|
||||
expect(destructive.map(({ name }) => name).sort()).toEqual([
|
||||
"capture_browser_scenario",
|
||||
"capture_electron_scenario",
|
||||
"capture_native_ui_scenario",
|
||||
"capture_process_scenario",
|
||||
"install_adb_package",
|
||||
"observe_native_calls",
|
||||
"push_adb_file",
|
||||
"start_adb_activity",
|
||||
"start_adb_app",
|
||||
"stop_adb_app",
|
||||
"uninstall_adb_package",
|
||||
]);
|
||||
for (const contract of destructive)
|
||||
expect(contract.annotations, contract.name).toMatchObject({
|
||||
readOnlyHint: false,
|
||||
destructiveHint: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("derives destructiveHint from each destructive effect alone", () => {
|
||||
const base = TOOL_EFFECTS["binary_session"];
|
||||
if (base === undefined) throw new Error("binary_session is unaudited");
|
||||
expect(annotationsFromEffects(base)).toEqual({
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: false,
|
||||
});
|
||||
for (const flag of [
|
||||
"mayDiscardData",
|
||||
"executesForeignCode",
|
||||
"mutatesDevice",
|
||||
] as const)
|
||||
expect(annotationsFromEffects({ ...base, [flag]: true }), flag).toEqual({
|
||||
readOnlyHint: false,
|
||||
destructiveHint: true,
|
||||
idempotentHint: true,
|
||||
openWorldHint: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("publishes the advertised annotations derived from canonical effects", () => {
|
||||
for (const contract of TOOL_CONTRACTS)
|
||||
expect(contract.annotations, contract.name).toEqual(
|
||||
annotationsFromEffects(contract.effects),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,17 @@ export interface ToolEffects {
|
||||
readonly launchesProcess: boolean;
|
||||
readonly accessesNetwork: boolean;
|
||||
readonly changesUiState: boolean;
|
||||
/** Can overwrite, clear, or drop state that the caller cannot recover from REA. */
|
||||
readonly mayDiscardData: boolean;
|
||||
/**
|
||||
* Runs or drives code REA does not own on the host: the analysis target, a
|
||||
* caller-selected executable, or the application loaded into one. Running
|
||||
* REA's own pinned helpers or operator-configured analysis engines does not
|
||||
* count.
|
||||
*/
|
||||
readonly executesForeignCode: boolean;
|
||||
/** Changes an attached Android device: packages, files, or running apps. */
|
||||
readonly mutatesDevice: boolean;
|
||||
readonly idempotent: boolean;
|
||||
}
|
||||
|
||||
@@ -27,6 +37,8 @@ const effects = (overrides: Partial<ToolEffects> = {}): ToolEffects => ({
|
||||
accessesNetwork: false,
|
||||
changesUiState: false,
|
||||
mayDiscardData: false,
|
||||
executesForeignCode: false,
|
||||
mutatesDevice: false,
|
||||
idempotent: true,
|
||||
...overrides,
|
||||
});
|
||||
@@ -178,6 +190,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
launchesProcess: true,
|
||||
writesFilesystem: true,
|
||||
accessesNetwork: true,
|
||||
mutatesDevice: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
capture_adb_screen: effects({
|
||||
@@ -239,6 +252,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
mutatesSession: true,
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
mutatesDevice: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
uninstall_adb_package: effects({
|
||||
@@ -246,6 +260,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
mutatesSession: true,
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
mutatesDevice: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
start_adb_app: effects({
|
||||
@@ -253,6 +268,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
mutatesSession: true,
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
mutatesDevice: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
start_adb_activity: effects({
|
||||
@@ -260,6 +276,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
mutatesSession: true,
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
mutatesDevice: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
stop_adb_app: effects({
|
||||
@@ -267,6 +284,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
mutatesSession: true,
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
mutatesDevice: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
search_android_classes: effects({
|
||||
@@ -294,6 +312,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
mutatesSession: true,
|
||||
launchesProcess: true,
|
||||
writesFilesystem: true,
|
||||
mayDiscardData: true,
|
||||
}),
|
||||
inspect_native_load_image: evidence,
|
||||
inspect_native_dispatch_metadata: evidence,
|
||||
@@ -330,11 +349,31 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
resolve_containing_procedure: evidence,
|
||||
search_procedures: evidence,
|
||||
search_strings: evidence,
|
||||
set_address_name: effects({ mutatesTarget: true, mutatesSession: true }),
|
||||
set_addresses_names: effects({ mutatesTarget: true, mutatesSession: true }),
|
||||
set_bookmark: effects({ mutatesTarget: true, mutatesSession: true }),
|
||||
set_comment: effects({ mutatesTarget: true, mutatesSession: true }),
|
||||
set_inline_comment: effects({ mutatesTarget: true, mutatesSession: true }),
|
||||
set_address_name: effects({
|
||||
mutatesTarget: true,
|
||||
mutatesSession: true,
|
||||
mayDiscardData: true,
|
||||
}),
|
||||
set_addresses_names: effects({
|
||||
mutatesTarget: true,
|
||||
mutatesSession: true,
|
||||
mayDiscardData: true,
|
||||
}),
|
||||
set_bookmark: effects({
|
||||
mutatesTarget: true,
|
||||
mutatesSession: true,
|
||||
mayDiscardData: true,
|
||||
}),
|
||||
set_comment: effects({
|
||||
mutatesTarget: true,
|
||||
mutatesSession: true,
|
||||
mayDiscardData: true,
|
||||
}),
|
||||
set_inline_comment: effects({
|
||||
mutatesTarget: true,
|
||||
mutatesSession: true,
|
||||
mayDiscardData: true,
|
||||
}),
|
||||
unset_bookmark: effects({
|
||||
mutatesTarget: true,
|
||||
mutatesSession: true,
|
||||
@@ -365,6 +404,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
accessesNetwork: true,
|
||||
changesUiState: true,
|
||||
mayDiscardData: true,
|
||||
executesForeignCode: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
// The owned process can change files, show UI and use the network.
|
||||
@@ -374,6 +414,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
changesUiState: true,
|
||||
executesForeignCode: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
inspect_macho: nativeEvidence,
|
||||
@@ -419,6 +460,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
accessesNetwork: true,
|
||||
changesUiState: true,
|
||||
mayDiscardData: true,
|
||||
executesForeignCode: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
list_electron_targets: browserEvidence,
|
||||
@@ -431,6 +473,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
accessesNetwork: true,
|
||||
changesUiState: true,
|
||||
mayDiscardData: true,
|
||||
executesForeignCode: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
list_javascript_runtime_targets: browserEvidence,
|
||||
@@ -479,6 +522,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
writesFilesystem: true,
|
||||
launchesProcess: true,
|
||||
accessesNetwork: true,
|
||||
executesForeignCode: true,
|
||||
idempotent: false,
|
||||
}),
|
||||
compare_process_captures: sessionEvidence,
|
||||
@@ -506,9 +550,15 @@ export const annotationsFromEffects = (
|
||||
value.launchesProcess ||
|
||||
value.accessesNetwork ||
|
||||
value.changesUiState ||
|
||||
value.mayDiscardData
|
||||
value.mayDiscardData ||
|
||||
value.executesForeignCode ||
|
||||
value.mutatesDevice
|
||||
),
|
||||
destructiveHint: value.mayDiscardData,
|
||||
// MCP defines destructive as possibly non-additive changes to the
|
||||
// environment. Running foreign code or changing a device cannot be bounded
|
||||
// to additive effects, so either one is destructive even without data loss.
|
||||
destructiveHint:
|
||||
value.mayDiscardData || value.executesForeignCode || value.mutatesDevice,
|
||||
idempotentHint: value.idempotent,
|
||||
openWorldHint: value.launchesProcess || value.accessesNetwork,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { z } from "zod";
|
||||
import { evidenceBundleSummarySchema } from "../domain/evidenceRecordSummary.js";
|
||||
import { BINARY_ARCHITECTURES } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
binaryArchitectureSchema,
|
||||
rawBinaryEntryPointSchema,
|
||||
} from "../domain/rawBinary.js";
|
||||
import { nativeFunctionAnnotationsSchema } from "../domain/native/nativeFunctionAnnotations.js";
|
||||
import { nativeLoadImageSchema } from "../domain/native/nativeLoadImage.js";
|
||||
import { nativeUiResultSchema } from "../domain/native/nativeUiObservation.js";
|
||||
@@ -409,16 +413,33 @@ export const managedWorkflowOutputSchemas: Readonly<
|
||||
),
|
||||
};
|
||||
|
||||
const lifecycleTargetFields = {
|
||||
path: z.string(),
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
};
|
||||
const detectedLifecycleTargetSchema = z.object({
|
||||
...lifecycleTargetFields,
|
||||
format: targetFormatSchema.exclude(["raw-binary"]),
|
||||
});
|
||||
const rawLifecycleTargetSchema = z.object({
|
||||
...lifecycleTargetFields,
|
||||
format: z.literal("raw-binary"),
|
||||
kind: z.literal("executable"),
|
||||
architecture: binaryArchitectureSchema,
|
||||
entry_point: rawBinaryEntryPointSchema.describe(
|
||||
"Canonical caller-selected address where raw file offset 0 is mapped and execution is seeded.",
|
||||
),
|
||||
});
|
||||
|
||||
/** Exact structured-content schemas for target lifecycle operations. */
|
||||
export const sessionOutputSchemas = {
|
||||
open_binary: lifecycleResultOf(
|
||||
z.object({
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
}),
|
||||
z.discriminatedUnion("format", [
|
||||
detectedLifecycleTargetSchema,
|
||||
rawLifecycleTargetSchema,
|
||||
]),
|
||||
),
|
||||
close_binary: lifecycleResultOf(
|
||||
z.union([
|
||||
@@ -448,19 +469,15 @@ export const sessionOutputSchemas = {
|
||||
),
|
||||
binary_session: lifecycleResultOf(
|
||||
z.union([
|
||||
z.union([
|
||||
sessionProvider.extend({
|
||||
open: z.literal(false),
|
||||
}),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
}),
|
||||
]),
|
||||
sessionProvider.extend({ open: z.literal(false) }),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
...detectedLifecycleTargetSchema.shape,
|
||||
}),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
...rawLifecycleTargetSchema.shape,
|
||||
}),
|
||||
]),
|
||||
),
|
||||
export_evidence_bundle: lifecycleResultOf(
|
||||
|
||||
@@ -56,6 +56,7 @@ export const targetFormatSchema = z.enum([
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
@@ -292,6 +293,8 @@ const toolAvailabilityFacts = {
|
||||
accessesNetwork: z.boolean(),
|
||||
changesUiState: z.boolean(),
|
||||
mayDiscardData: z.boolean(),
|
||||
executesForeignCode: z.boolean(),
|
||||
mutatesDevice: z.boolean(),
|
||||
idempotent: z.boolean(),
|
||||
}),
|
||||
annotations: z.object({
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
snapshotBinding,
|
||||
snapshotEvidenceForQuery,
|
||||
snapshotTarget,
|
||||
snapshotMatchesTarget,
|
||||
} from "./analysisSnapshot.js";
|
||||
import {
|
||||
ANALYSIS_SNAPSHOT_PROFILE,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
} from "./analysisSnapshot.fixture.js";
|
||||
import { createEvidence } from "./evidence.js";
|
||||
import { createEvidenceBundle } from "./evidenceBundle.js";
|
||||
import type { BinaryTarget } from "./binaryTargetTypes.js";
|
||||
|
||||
const snapshotWithHistoricalEvidence = () => {
|
||||
const target = snapshotTarget(ANALYSIS_SNAPSHOT_TARGET);
|
||||
@@ -68,6 +70,54 @@ const snapshotWithHistoricalEvidence = () => {
|
||||
};
|
||||
|
||||
describe("analysis snapshot contract", () => {
|
||||
it("partitions raw snapshots and query identities by the canonical entry", () => {
|
||||
const target: BinaryTarget = {
|
||||
path: "/fixture/image.bin",
|
||||
sha256: ANALYSIS_SNAPSHOT_TARGET.sha256,
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x08000000",
|
||||
};
|
||||
const snapshot = snapshotTarget(target);
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const changed = {
|
||||
...target,
|
||||
entryPoint: "0x9000000",
|
||||
entryPointSource: "0x09000000",
|
||||
};
|
||||
expect(
|
||||
snapshotMatchesTarget(snapshot, {
|
||||
...target,
|
||||
entryPointSource: "0x8000000",
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(snapshotMatchesTarget(snapshot, changed)).toBe(false);
|
||||
expect(analysisQueryId(snapshot, binding, "list_procedures", {})).not.toBe(
|
||||
analysisQueryId(snapshotTarget(changed), binding, "list_procedures", {}),
|
||||
);
|
||||
const parsed = analysisSnapshotSchema.parse({
|
||||
target: snapshot,
|
||||
binding,
|
||||
entries: [],
|
||||
workflow_entries: [],
|
||||
evidence_bundle: createEvidenceBundle([]),
|
||||
});
|
||||
expect(parsed.target).toHaveProperty("entry_point", target.entryPoint);
|
||||
const { entry_point: _entry, ...legacy } = {
|
||||
...snapshot,
|
||||
entry_point: target.entryPoint,
|
||||
};
|
||||
expect(
|
||||
analysisSnapshotSchema.safeParse({ ...parsed, target: legacy }).success,
|
||||
).toBe(false);
|
||||
expect(snapshotTarget(ANALYSIS_SNAPSHOT_TARGET)).not.toHaveProperty(
|
||||
"entry_point",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves DOS MZ target and subject formats with the x86 family", () => {
|
||||
const target = {
|
||||
path: ANALYSIS_SNAPSHOT_TARGET.path,
|
||||
@@ -113,6 +163,37 @@ describe("analysis snapshot contract", () => {
|
||||
expect(parsed.evidence_bundle.records[0]?.subject?.format).toBe("dos-mz");
|
||||
});
|
||||
|
||||
it("rejects a snapshot subject path containing NUL", () => {
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const entry = {
|
||||
query_id: `query_${"0".repeat(64)}`,
|
||||
operation: "analyze_function",
|
||||
parameters: {},
|
||||
execution: {
|
||||
result: null,
|
||||
raw_result: null,
|
||||
provider: binding.provider,
|
||||
limitations: [],
|
||||
locations: [],
|
||||
subject: {
|
||||
path: "a\u0000b",
|
||||
sha256: "a".repeat(64),
|
||||
format: "elf" as const,
|
||||
architecture: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(
|
||||
analysisSnapshotSchema.safeParse({
|
||||
target: snapshotTarget(ANALYSIS_SNAPSHOT_TARGET),
|
||||
binding,
|
||||
entries: [entry],
|
||||
workflow_entries: [],
|
||||
evidence_bundle: createEvidenceBundle([]),
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts snapshots with more than ten thousand analysis entries", () => {
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const entry = {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
compareUnicodeCodePoints,
|
||||
compositeKey,
|
||||
} from "./unicodeCodePointOrder.js";
|
||||
import { localPathStringSchema } from "./localPath.js";
|
||||
|
||||
import {
|
||||
analysisProfileSchema,
|
||||
@@ -39,6 +40,7 @@ import { digestSchema } from "./../domain/digests.js";
|
||||
import { prefixedDigestSchema } from "./../domain/digests.js";
|
||||
import { canonicalJsonDigestSteps } from "./canonicalJsonDigestSteps.js";
|
||||
import { freezeJsonSnapshot } from "./immutableJson.js";
|
||||
import { rawBinaryEntryPointSchema } from "./rawBinary.js";
|
||||
|
||||
const architectureSchema = z.enum(BINARY_ARCHITECTURES);
|
||||
const formatSchema = z.enum([
|
||||
@@ -48,6 +50,7 @@ const formatSchema = z.enum([
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
@@ -65,7 +68,7 @@ const formatSchema = z.enum([
|
||||
]);
|
||||
const kindSchema = z.enum(["executable", "database", "archive", "artifact"]);
|
||||
const subjectSchema = z.object({
|
||||
path: z.string().min(1),
|
||||
path: localPathStringSchema,
|
||||
sha256: digestSchema,
|
||||
format: z.enum([
|
||||
...formatSchema.options,
|
||||
@@ -79,12 +82,22 @@ const subjectSchema = z.object({
|
||||
]),
|
||||
architecture: architectureSchema.nullable(),
|
||||
});
|
||||
const targetSchema = z.object({
|
||||
const targetIdentitySchema = z.object({
|
||||
sha256: digestSchema,
|
||||
kind: kindSchema,
|
||||
format: formatSchema,
|
||||
architecture: architectureSchema.nullable(),
|
||||
});
|
||||
const targetSchema = z.discriminatedUnion("format", [
|
||||
targetIdentitySchema.extend({
|
||||
format: z.enum(
|
||||
formatSchema.options.filter((format) => format !== "raw-binary"),
|
||||
),
|
||||
}),
|
||||
targetIdentitySchema.extend({
|
||||
format: z.literal("raw-binary"),
|
||||
entry_point: rawBinaryEntryPointSchema,
|
||||
}),
|
||||
]);
|
||||
const bindingSchema = z
|
||||
.object({
|
||||
provider: committedProviderSchema,
|
||||
@@ -310,12 +323,16 @@ const canonicalJson = (value: unknown): string => {
|
||||
/** Project a binary into the path-free identity used for cache invalidation. */
|
||||
export const snapshotTarget = (
|
||||
target: BinaryTarget,
|
||||
): AnalysisSnapshotTarget => ({
|
||||
sha256: target.sha256,
|
||||
kind: target.kind,
|
||||
format: target.format,
|
||||
architecture: target.architecture ?? null,
|
||||
});
|
||||
): AnalysisSnapshotTarget => {
|
||||
const identity = {
|
||||
sha256: target.sha256,
|
||||
kind: target.kind,
|
||||
architecture: target.architecture ?? null,
|
||||
};
|
||||
return target.format === "raw-binary"
|
||||
? { ...identity, format: target.format, entry_point: target.entryPoint }
|
||||
: { ...identity, format: target.format };
|
||||
};
|
||||
|
||||
/** Build the immutable provider/profile binding used by a cached snapshot. */
|
||||
export const snapshotBinding = (
|
||||
@@ -334,7 +351,10 @@ export const snapshotMatchesTarget = (
|
||||
snapshot.sha256 === target.sha256 &&
|
||||
snapshot.kind === target.kind &&
|
||||
snapshot.format === target.format &&
|
||||
snapshot.architecture === (target.architecture ?? null);
|
||||
snapshot.architecture === (target.architecture ?? null) &&
|
||||
(snapshot.format !== "raw-binary" ||
|
||||
(target.format === "raw-binary" &&
|
||||
snapshot.entry_point === target.entryPoint));
|
||||
|
||||
/** Compare a snapshot binding with the selected concrete analysis profile. */
|
||||
export const snapshotMatchesProfile = (
|
||||
|
||||
@@ -50,6 +50,7 @@ const artifactFormatSchema = z.enum([
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"hopper",
|
||||
"analysis-database",
|
||||
"ipa",
|
||||
|
||||
@@ -78,6 +78,13 @@ export type BinaryTarget =
|
||||
readonly executableRole?: never;
|
||||
readonly managed?: never;
|
||||
})
|
||||
| (ExecutableTarget & {
|
||||
readonly format: "raw-binary";
|
||||
readonly entryPoint: string;
|
||||
readonly entryPointSource: string;
|
||||
readonly executableRole?: never;
|
||||
readonly managed?: never;
|
||||
})
|
||||
| (ExecutableTarget & {
|
||||
readonly format: "pe";
|
||||
/** Provider-neutral PE image role observed from COFF characteristics. */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { z } from "zod";
|
||||
import { err, ok, type Result } from "./result.js";
|
||||
|
||||
/** Headerless DOS COM interpretation explicitly selected by the caller. */
|
||||
export const executableFormatHintSchema = z.literal("dos-com");
|
||||
/** Headerless executable interpretation explicitly selected by the caller. */
|
||||
export const executableFormatHintSchema = z.enum(["dos-com", "raw-binary"]);
|
||||
/** Explicit executable interpretation for formats with no identifying header. */
|
||||
export type ExecutableFormatHint = z.infer<typeof executableFormatHintSchema>;
|
||||
|
||||
|
||||
@@ -291,6 +291,22 @@ describe("analysis evidence identity", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a subject local path containing NUL while admitting an empty path", () => {
|
||||
const evidence = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "health",
|
||||
parameters: {},
|
||||
result: true,
|
||||
});
|
||||
expect(evidence.subject).not.toBeNull();
|
||||
const withPath = (path: string) => ({
|
||||
...evidence,
|
||||
subject: { ...evidence.subject, local_path: path },
|
||||
});
|
||||
expect(evidenceSchema.safeParse(withPath("/tmp/fixture")).success).toBe(true);
|
||||
expect(evidenceSchema.safeParse(withPath("")).success).toBe(true);
|
||||
expect(evidenceSchema.safeParse(withPath("a\u0000b")).success).toBe(false);
|
||||
});
|
||||
|
||||
it("binds an explicit unknown-subject reason into the semantic Evidence identity", () => {
|
||||
const reason = "Caller excluded the observed digest.";
|
||||
const observation = { operation: "health", parameters: {}, result: true };
|
||||
|
||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
||||
|
||||
import { digestCanonicalValue } from "./canonicalDigest.js";
|
||||
import { canonicalJsonDigestSteps } from "./canonicalJsonDigestSteps.js";
|
||||
import { nulFreeStringSchema } from "./localPath.js";
|
||||
|
||||
import {
|
||||
analysisProfileSchema,
|
||||
@@ -43,6 +44,7 @@ const subjectSchema = z.object({
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
@@ -65,7 +67,7 @@ const subjectSchema = z.object({
|
||||
"entitlements",
|
||||
]),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
local_path: z.string(),
|
||||
local_path: nulFreeStringSchema,
|
||||
});
|
||||
/** Source location attached to an evidence observation. */
|
||||
/** Source-location schema shared by evidence-bearing persistence formats. */
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ROLLDOWN_MODULE_INTEROP } from "./javascriptModuleInterop.fixture.js";
|
||||
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
|
||||
const CAPTURED_INTEROP = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"__defProp = Object.defineProperty",
|
||||
"__defProp = define",
|
||||
);
|
||||
const WINDOW = `let electron = require("electron");
|
||||
electron = __toESM(electron, 1); new electron.BrowserWindow({});`;
|
||||
|
||||
describe("captured intrinsic invocation reads", () => {
|
||||
it.each([
|
||||
'(0, Object.defineProperty.call)(null,Object,"create",{value:replacement});',
|
||||
'(0, Object.defineProperty.apply)(null,[Object,"create",{value:replacement}]);',
|
||||
])(
|
||||
"does not invent a receiver for a detached invocation member: %s",
|
||||
(invoke) => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
${invoke}
|
||||
${ROLLDOWN_MODULE_INTEROP} ${WINDOW}
|
||||
`);
|
||||
expect(result.electron.browser_windows).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it("retains callee-prefix effects before classifying the invocation", () => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const define = Object.defineProperty;
|
||||
const metadata = {};
|
||||
(Object.defineProperty = replacement, Object.defineProperty)(metadata,"x",{value:1});
|
||||
${CAPTURED_INTEROP} ${WINDOW}
|
||||
`);
|
||||
expect(result.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("retains a callee selected before an argument replaces its global property", () => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const define = Object.defineProperty;
|
||||
const metadata = {};
|
||||
Object.defineProperty(metadata,"x",(Object.defineProperty = replacement,{value:1}));
|
||||
${CAPTURED_INTEROP} ${WINDOW}
|
||||
`);
|
||||
expect(result.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'define.call(null,metadata,"x",{value:1});',
|
||||
'define.apply(null,[metadata,"x",{value:1}]);',
|
||||
'const change = define.bind(null,metadata,"x"); change({value:1});',
|
||||
'const also = define; also.call(null,metadata,"x",{value:1});',
|
||||
])("retains a function captured before global replacement: %s", (invoke) => {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const define = Object.defineProperty;
|
||||
Object.defineProperty = replacement;
|
||||
const metadata = {}; ${invoke}
|
||||
${CAPTURED_INTEROP} ${WINDOW}
|
||||
`);
|
||||
expect(result.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["call", 'define.call(null,metadata,"x",{value:1});'],
|
||||
["apply", 'define.apply(null,[metadata,"x",{value:1}]);'],
|
||||
[
|
||||
"bind",
|
||||
'const change = define.bind(null,metadata,"x"); change({value:1});',
|
||||
],
|
||||
])(
|
||||
"checks the later %s property read on a captured function",
|
||||
(method, invoke) => {
|
||||
for (const owner of ["define", "Function.prototype"]) {
|
||||
const result = analyzeJavaScriptStaticSource(`
|
||||
const define = Object.defineProperty;
|
||||
${owner}.${method} = replacement;
|
||||
const metadata = {}; ${invoke}
|
||||
${CAPTURED_INTEROP} ${WINDOW}
|
||||
`);
|
||||
expect(result.electron.browser_windows, owner).toEqual([]);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,667 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
import { ROLLDOWN_MODULE_INTEROP } from "./javascriptModuleInterop.fixture.js";
|
||||
|
||||
const WINDOW =
|
||||
'new electron.BrowserWindow({webPreferences:{preload:"./preload.js"}});';
|
||||
const IMPORT = 'let electron = require("electron");';
|
||||
const WRAP = "electron = __toESM(electron, 1);";
|
||||
// The upstream runtime uses control-body braces that its bundled printer omits.
|
||||
// https://github.com/rolldown/rolldown/blob/22a0ab13732d81f2559ad2b7064b688699324889/crates/rolldown/src/runtime/runtime-base.js
|
||||
const BLOCK_MODULE_INTEROP = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
'if (from && typeof from === "object" || typeof from === "function") for',
|
||||
'if (from && typeof from === "object" || typeof from === "function") { for',
|
||||
)
|
||||
.replace(
|
||||
"if (!__hasOwnProp.call(to, key) && key !== except) __defProp",
|
||||
"if (!__hasOwnProp.call(to, key) && key !== except) { __defProp",
|
||||
)
|
||||
.replace(" });", " });\n }")
|
||||
.replace(" return to;", " }\n return to;");
|
||||
|
||||
describe("Electron module interop identity", () => {
|
||||
it("preserves named APIs through the released Rolldown namespace conversion", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
new electron.BrowserWindow({webPreferences:{preload:runtimePath}});
|
||||
electron.ipcMain.handle("ping", () => "pong");
|
||||
electron.contextBridge.exposeInMainWorld("api", {ping:true});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toMatchObject([
|
||||
{ preload_path: "./preload.js" },
|
||||
{ preload_path: null },
|
||||
]);
|
||||
expect(analysis.electron.ipc).toMatchObject([
|
||||
{ channel: "ping", side: "main" },
|
||||
]);
|
||||
expect(analysis.electron.context_bridge_apis).toMatchObject([
|
||||
{ api_key: "api" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("follows lexical identities when helper and parameter names change", () => {
|
||||
const source = `${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`
|
||||
.replaceAll("__toESM", "namespaceOf")
|
||||
.replaceAll("__copyProps", "copyNamed")
|
||||
.replaceAll("mod", "inputModule")
|
||||
.replaceAll("isNodeMode", "nodeMode")
|
||||
.replaceAll("target", "namespaceTarget")
|
||||
.replaceAll("from", "sourceObject");
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(source).electron.browser_windows,
|
||||
).toMatchObject([{ preload_path: "./preload.js" }]);
|
||||
});
|
||||
|
||||
it("preserves the same operations through control-body braces", () => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`${BLOCK_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toMatchObject([{ preload_path: "./preload.js" }]);
|
||||
});
|
||||
|
||||
it("keeps additional operations inside a control block unresolved", () => {
|
||||
const altered = BLOCK_MODULE_INTEROP.replace(
|
||||
"{ __defProp",
|
||||
"{ from = unrelated; __defProp",
|
||||
);
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${altered}\n${IMPORT} ${WRAP} ${WINDOW}`)
|
||||
.electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
const BOUND_INTRINSIC_MUTATIONS: [string, string][] = [
|
||||
[
|
||||
"intrinsic changed through aliased prebound arguments",
|
||||
`const objectAlias = Object; const key = "create"; const define = Object.defineProperty; const mutate = define.bind(null, objectAlias, key); mutate({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed through nested prebinding",
|
||||
`const first = Object.defineProperty.bind(null, Object); const second = first.bind(null, "create"); second({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"a replaced bound mutator bind method is unknown",
|
||||
`const first = Object.defineProperty.bind(null, Object); first.bind = customBind; const second = first.bind(null, "create"); second({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed through a computed prebound call",
|
||||
`const mutate = Object.defineProperty.bind(null, Object, "create"); mutate["call"](null, {value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed through a computed prebound apply",
|
||||
`const mutate = Object.defineProperty.bind(null, Object, "create"); mutate["apply"](null, [{value:customCreate}]); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"a replaced bind intrinsic makes a prebound mutator unknown",
|
||||
`Function.prototype.bind = customBind; const mutate = Object.defineProperty.bind(null, Object, "create"); mutate({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
];
|
||||
|
||||
describe("Electron module interop uncertainty", () => {
|
||||
it.each([
|
||||
...BOUND_INTRINSIC_MUTATIONS,
|
||||
[
|
||||
"intrinsic changed through an unresolved mutator target",
|
||||
`Object.defineProperty(getTarget(), "create", {value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via dynamic apply",
|
||||
`const args = [Object, "getOwnPropertyNames", {value:() => []}]; Object.defineProperty.apply(null, args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via spread call",
|
||||
`const args = [Object, "getOwnPropertyNames", {value:() => []}]; Object.defineProperty.call(null, ...args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via Reflect.apply",
|
||||
`const args = [Object, "getOwnPropertyNames", {value:() => []}]; Reflect.apply(Object.defineProperty, null, args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via spread Reflect.apply",
|
||||
`const args = [null, [Object, "create", {value:customCreate}]]; Reflect.apply(Object.defineProperty, ...args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via call",
|
||||
`Object.defineProperty.call(null, Object, "getOwnPropertyNames", {value:() => []}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via apply",
|
||||
`Object.defineProperty.apply(null, [Object, "getOwnPropertyNames", {value:() => []}]); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with defineProperty",
|
||||
`Object.defineProperty(Object, "getOwnPropertyNames", {value:() => []}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with Reflect.set",
|
||||
`Reflect.set(Object, "getOwnPropertyNames", () => []); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with an aliased mutator",
|
||||
`const change = Object.defineProperty; change(Object, "create", {value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with assign",
|
||||
`Object.assign(Object, {getOwnPropertyNames:() => []}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with defineProperties",
|
||||
`Object.defineProperties(Function.prototype, {bind:{value:customBind}}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten Object global",
|
||||
`Object = customObject; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten intrinsic through an alias",
|
||||
`const objectAlias = Object; objectAlias.create = customCreate; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten intrinsic through globalThis",
|
||||
`globalThis.Object.create = customCreate; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"helper called before initialization",
|
||||
`${IMPORT} ${WRAP} ${ROLLDOWN_MODULE_INTEROP}`,
|
||||
],
|
||||
[
|
||||
"fake helper",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__toESM = (mod) => ({BrowserWindow:Fake}); ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"changed getter",
|
||||
`${ROLLDOWN_MODULE_INTEROP.replace("from[k]", "to[k]")}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"replaced copy helper",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__copyProps = () => ({}); ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"replaced intrinsic alias",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__defProp = () => ({}); ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"shadowed Object",
|
||||
`const Object = customObject; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten intrinsic",
|
||||
`Object.create = customCreate; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten alias call",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__hasOwnProp.call = customCall; ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten Function bind",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\nFunction.prototype.bind = customBind; ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"conditional conversion",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} if (flag) { ${WRAP} }`,
|
||||
],
|
||||
[
|
||||
"compound assignment",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} electron ||= __toESM(electron, 1);`,
|
||||
],
|
||||
[
|
||||
"other input",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} electron = __toESM(other, 1);`,
|
||||
],
|
||||
[
|
||||
"later overwrite",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} electron = unrelated;`,
|
||||
],
|
||||
[
|
||||
"overwritten constructor",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} electron.BrowserWindow = Fake;`,
|
||||
],
|
||||
])("does not infer Electron identity after %s", (_name, setup) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${setup}\n${WINDOW}`).electron
|
||||
.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop helper results", () => {
|
||||
it.each([
|
||||
'const {BrowserWindow} = __toESM(require("electron"), 1); new BrowserWindow({});',
|
||||
'const {BrowserWindow: Window} = __toESM(require("electron"), 1); new Window({});',
|
||||
'const {default: {BrowserWindow}} = __toESM(require("electron"), 1); new BrowserWindow({});',
|
||||
'const Window = __toESM(require("electron"), 1).BrowserWindow; new Window({});',
|
||||
])("preserves a proven result projection: %s", (source) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}\n${source}`)
|
||||
.electron.browser_windows,
|
||||
).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const {[key]: Window} = __toESM(require("electron"), 1); new Window({});',
|
||||
'const {...electron} = __toESM(require("electron"), 1); new electron.BrowserWindow({});',
|
||||
'let {BrowserWindow} = __toESM(require("electron"), 1); BrowserWindow = Fake; new BrowserWindow({});',
|
||||
])("keeps an uncertain result projection unresolved: %s", (source) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}\n${source}`)
|
||||
.electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"",
|
||||
", 0",
|
||||
", false",
|
||||
", true",
|
||||
", 1",
|
||||
', "node"',
|
||||
', ""',
|
||||
", null",
|
||||
])("preserves named exports with a literal node mode: %s", (mode) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
const fresh = __toESM(require("electron")${mode});
|
||||
new fresh.BrowserWindow({});
|
||||
const {BrowserWindow} = __toESM(require("electron")${mode});
|
||||
new BrowserWindow({});
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron${mode}); ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(3);
|
||||
});
|
||||
|
||||
it.each(["", ", 0", ", false"])(
|
||||
"does not assume a module-valued default with node mode: %s",
|
||||
(mode) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
const original = require("electron");
|
||||
original.__esModule = true;
|
||||
original.default = {BrowserWindow: Fake};
|
||||
const {default: {BrowserWindow}} = __toESM(require("electron")${mode});
|
||||
new BrowserWindow({});
|
||||
const other = __toESM(require("electron")${mode}).default;
|
||||
new other.BrowserWindow({});
|
||||
new (__toESM(require("electron")${mode}).default.BrowserWindow)({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["__toESM", "identity"])(
|
||||
"rejects side-effecting extra arguments to %s",
|
||||
(helper) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
function identity(mod) { return mod; }
|
||||
const electron = ${helper}(require("electron"), mutate()); ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"const __toESM = () => ({BrowserWindow:FakeWindow});",
|
||||
"const __toESM = async (mod) => mod;",
|
||||
"function* __toESM(mod) { return mod; }",
|
||||
"const __toESM = (this && this.__toESM) || ((mod) => mod);",
|
||||
])("keeps an unproven fresh result unresolved: %s", (helper) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${helper}
|
||||
const electron = __toESM(require("electron"), 1); ${WINDOW}
|
||||
new (__toESM(require("electron"), 1)).BrowserWindow({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves a proven fresh namespace and a pure identity helper", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
const electron = __toESM(require("electron"), 1); ${WINDOW}
|
||||
new (__toESM(require("electron"), 1)).BrowserWindow({});
|
||||
function passthrough(value) {return value;}
|
||||
const plain = passthrough(require("electron"));
|
||||
new plain.BrowserWindow({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop pattern writes", () => {
|
||||
it.each([
|
||||
"({Object} = replacements);",
|
||||
"[Function] = replacements;",
|
||||
"({nested:{Object}} = replacements);",
|
||||
"({replacement:Object = customObject} = replacements);",
|
||||
"({...Object} = replacements);",
|
||||
"[...Function] = replacements;",
|
||||
"for ({Object} of replacements) {}",
|
||||
"for ([Function] in replacements) {}",
|
||||
])("rejects an intrinsic replaced through %s", (write) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${write} ${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.parse_error_count).toBe(0);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"({Object:unrelated} = replacements);",
|
||||
"function decoy(Object) {({Object} = replacements);}",
|
||||
])("preserves intrinsic identity for an unrelated target: %s", (write) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${write} ${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.parse_error_count).toBe(0);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("preserves captured operations after later property destructuring", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${ROLLDOWN_MODULE_INTEROP} ({create:Object.create} = replacements);
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop intrinsic captures", () => {
|
||||
it.each([
|
||||
"var captured = Object.defineProperty;",
|
||||
"const {defineProperty:captured} = Object;",
|
||||
"var first = Object.defineProperty; const captured = first;",
|
||||
])("retains the original function capture through %s", (capture) => {
|
||||
const runtime = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"__defProp = Object.defineProperty",
|
||||
"__defProp = captured",
|
||||
);
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${capture} Object.defineProperty = custom;
|
||||
${runtime} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each(["var", "const"])(
|
||||
"keeps an intrinsic alias read before its %s initializer unresolved",
|
||||
(kind) => {
|
||||
const runtime = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"__defProp = Object.defineProperty",
|
||||
"__defProp = later",
|
||||
);
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${runtime} ${kind} later = Object.defineProperty;
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it("requires the helper's intrinsic binding to initialize before conversion", () => {
|
||||
const runtime = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"var __defProp = Object.defineProperty;",
|
||||
"",
|
||||
);
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var captured = Object.defineProperty;
|
||||
${runtime} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
var __defProp = captured;
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop capture and scope", () => {
|
||||
it.each(["metadata", "alias"])(
|
||||
"recognizes a hoisted function target through %s",
|
||||
(target) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const alias = metadata;
|
||||
Object.defineProperty(${target}, "x", {value:1});
|
||||
function metadata() {}
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"var metadata = function () {};",
|
||||
"const metadata = () => {};",
|
||||
"class metadata {}",
|
||||
])("does not hoist fresh targets from %s", (declaration) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
Object.defineProperty(metadata, "x", {value:1});
|
||||
${declaration}
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const {defineProperty:change} = Object; change(Object,"create",{value:customCreate});',
|
||||
"const objectAlias = Object; const {assign:change} = objectAlias; change(Object,{create:customCreate});",
|
||||
'const {set:change} = Reflect; change(Object,"create",customCreate);',
|
||||
'const {Object:{defineProperty:change}} = globalThis; change(Object,"create",{value:customCreate});',
|
||||
])("rejects a projected intrinsic mutator alias: %s", (write) => {
|
||||
const source = `${write} ${ROLLDOWN_MODULE_INTEROP}
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
`.replaceAll("__toESM", "namespaceOf");
|
||||
const analysis = analyzeJavaScriptStaticSource(source);
|
||||
expect(analysis.parse_error_count).toBe(0);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"const metadata = {};",
|
||||
"const metadata = [];",
|
||||
"const initial = {}; const metadata = initial;",
|
||||
"const metadata = () => {};",
|
||||
"const metadata = function () {};",
|
||||
"const metadata = async () => {};",
|
||||
"const metadata = function* () {};",
|
||||
"const metadata = class {};",
|
||||
"const metadata = /local/;",
|
||||
"function metadata() {}",
|
||||
"class metadata {}",
|
||||
])(
|
||||
"keeps a fresh mutator target separate from intrinsic identity: %s",
|
||||
(setup) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${setup} Object.defineProperty(metadata,"x",{value:1});
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"const metadata = getMetadata();",
|
||||
"let metadata = {}; metadata = Object;",
|
||||
"Object.defineProperty(metadata,'x',{value:1}); const metadata = {};",
|
||||
"const metadata = {intrinsic:Object}; Object.defineProperty(metadata.intrinsic,'create',{value:customCreate});",
|
||||
"const metadata = class {static {Object.create = customCreate;}};",
|
||||
"@(() => Object) class metadata {}",
|
||||
])("keeps an unproven mutator target unresolved: %s", (setup) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${setup} Object.defineProperty(metadata,"x",{value:1});
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not reject unrelated intrinsic property definitions", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
Object.defineProperty(Object, "unrelated", {value:1});
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps opaque targets in a generic helper separate from outer module identity", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
function genericAssign() { Object.assign.apply(null, arguments); }
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("rejects an opaque intrinsic mutation in the namespace's own callable", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
function openWindow(args) {
|
||||
Object.defineProperty.apply(null, args);
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves captured intrinsics across later vendor polyfills and callable writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
Object.create = customCreate;
|
||||
${IMPORT} ${WRAP}
|
||||
function runLoop(key) { globalThis[key] = this; }
|
||||
function polyfill() { Object.create = customCreate; }
|
||||
${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps a shadowed namespace separate from the converted module", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
function decoy(electron) { ${WINDOW} }
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop generic invocations", () => {
|
||||
it.each([
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty); change(null,Object,"create",{value:customCreate});',
|
||||
'const call = Function.prototype.call; const change = call.bind(Object.defineProperty); change(null,Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null,Object,"create"); change({value:customCreate});',
|
||||
'Function.prototype.call.apply(Object.defineProperty,[null,Object,"create",{value:customCreate}]);',
|
||||
'Reflect.apply(Function.prototype.call,Object.defineProperty,[null,Object,"create",{value:customCreate}]);',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty); change(null,[Object,"create",{value:customCreate}]);',
|
||||
'Reflect.apply(Function.prototype.apply,Object.defineProperty,[null,[Object,"create",{value:customCreate}]]);',
|
||||
'const first = Function.prototype.call.bind(Object.defineProperty,null,Object,"create"); const change = first.bind(fake); change({value:customCreate});',
|
||||
"const change = Function.prototype.call.bind(Object.defineProperty); change(null,...args);",
|
||||
"const change = Function.prototype.apply.bind(Object.defineProperty); change(null,args);",
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null,...args); change(metadata,"x",{value:1});',
|
||||
'Function.prototype.call.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Object.defineProperty.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Function.prototype.apply.apply(Object.defineProperty,[null,[Object,"create",{value:customCreate}]]);',
|
||||
'const change = Object.defineProperty.call.bind(Object.defineProperty); change(null,Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.call.call.bind(Object.defineProperty,null,Object,"create"); change({value:customCreate});',
|
||||
])("follows the callable receiver of a generic invocation: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty); change(null,metadata,"x",{value:1});',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null,metadata,"x"); change({value:1});',
|
||||
'Function.prototype.call.call(Object.defineProperty,null,metadata,"x",{value:1});',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty); change(null,[metadata,"x",{value:1}]);',
|
||||
'Reflect.apply(Function.prototype.apply,Object.defineProperty,[null,[metadata,"x",{value:1}]]);',
|
||||
'Function.prototype.call.call.call(Object.defineProperty,null,metadata,"x",{value:1});',
|
||||
'Function.prototype.apply.apply(Object.defineProperty,[null,[metadata,"x",{value:1}]]);',
|
||||
'const change = Object.defineProperty.call.bind(Object.defineProperty); change(null,metadata,"x",{value:1});',
|
||||
])("preserves fresh targets through a generic invocation: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`const metadata = {}; ${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop bound mutators", () => {
|
||||
it.each([
|
||||
'const change = Object.defineProperty.bind(null); change(Object,"create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object,"create"); change({value:customCreate});',
|
||||
'const first = Object.defineProperty.bind(null,Object); const change = first; change("create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object); change.call(null,"create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object); change.apply(null,["create",{value:customCreate}]);',
|
||||
'const change = Object.defineProperty.bind(null,Object); Reflect.apply(change,null,["create",{value:customCreate}]);',
|
||||
'Object.defineProperty.bind(null,Object,"create")({value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,...args); change(Object,"create",{value:customCreate});',
|
||||
'const metadata = {}; Object.defineProperty.call(...args,metadata,"x",{value:1});',
|
||||
'const metadata = {}; Object.defineProperty.apply(...args,[metadata,"x",{value:1}]);',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
'const first = Function.prototype.call.bind(Object.defineProperty,null); const change = first.bind(customReceiver,Object,"create"); change({value:customCreate});',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty,null); change([Object,"create",{value:customCreate}]);',
|
||||
'Function.prototype.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Function.prototype.apply.call(Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'const uncurry = Function.prototype.call.bind(Function.prototype.call); uncurry(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.bind.call(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
'const bind = Function.prototype.call.bind(Function.prototype.bind); const change = bind(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.bind.apply(Object.defineProperty,[null,Object,"create"]); change({value:customCreate});',
|
||||
'const change = Reflect.apply(Function.prototype.bind,Object.defineProperty,[null,Object,"create"]); change({value:customCreate});',
|
||||
'const first = Object.defineProperty.bind(null,Object); const change = Function.prototype.bind.call(first,null,"create"); change({value:customCreate});',
|
||||
'Reflect.apply = Object.defineProperty; Reflect.apply(Object,"create",{value:customCreate});',
|
||||
'const apply = Reflect.apply; Reflect.apply = Object.defineProperty; Reflect.apply(Object,"create",{value:customCreate});',
|
||||
'const change = Reflect.set.bind(null,Object,"create"); change(customCreate);',
|
||||
'const change = Object.defineProperty.call; change.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'const {apply:change} = Object.defineProperty; change.call(Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'const change = Reflect.apply.call; change.call(Reflect.apply,null,Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'Reflect.set({},"create",customCreate,Object);',
|
||||
'const metadata = {}; Reflect.set(metadata,"create",customCreate,Object);',
|
||||
'const change = Reflect.set.bind(null,{},"create",customCreate); change(Object);',
|
||||
'Reflect.apply(Reflect.set,null,[{},"create",customCreate,Object]);',
|
||||
'Reflect.set({},"create",customCreate,...receivers);',
|
||||
'Reflect.set({},"create",...valuesAndReceivers);',
|
||||
"Reflect.set({},...keysValuesAndReceivers);",
|
||||
'Reflect.set({},"create",customCreate,receiver);',
|
||||
'(0, Object.defineProperty)(Object,"create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object,"create"); (0, change)({value:customCreate});',
|
||||
'(0, Reflect.apply)(Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'Reflect.apply((0,Function.prototype.call),Object.defineProperty,[null,Object,"create",{value:customCreate}]);',
|
||||
])("rejects intrinsic writes through a bound mutator: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const change = Object.defineProperty.bind(null); change(metadata,"x",{value:1});',
|
||||
'const change = Object.defineProperty.bind(null,metadata,"x"); change({value:1});',
|
||||
'const first = Object.defineProperty.bind(null,metadata); const change = first.bind(null,"x"); change({value:1});',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null); change(metadata,"x",{value:1});',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty,null); change([metadata,"x",{value:1}]);',
|
||||
'const change = Function.prototype.bind.call(Object.defineProperty,null,metadata,"x"); change({value:1});',
|
||||
'const bind = Function.prototype.call.bind(Function.prototype.bind); const change = bind(Object.defineProperty,null,metadata,"x"); change({value:1});',
|
||||
'const change = Function.prototype.bind.apply(Object.defineProperty,[null,metadata,"x"]); change({value:1});',
|
||||
'const change = Reflect.apply(Function.prototype.bind,Object.defineProperty,[null,metadata,"x"]); change({value:1});',
|
||||
'const apply = Reflect.apply; Reflect.apply = replacement; apply(Object.defineProperty,null,[metadata,"x",{value:1}]);',
|
||||
'const change = Object.defineProperty.bind(null,Object,"create");',
|
||||
'Object.defineProperty.call(null,metadata,"x",{value:1});',
|
||||
'Object.defineProperty.apply(null,[metadata,"x",{value:1}]);',
|
||||
'const change = Object.defineProperty.call; change.call(Object.defineProperty,null,metadata,"x",{value:1});',
|
||||
'const {apply:change} = Object.defineProperty; change.call(Object.defineProperty,null,[metadata,"x",{value:1}]);',
|
||||
'Reflect.set(metadata,"x",1,{});',
|
||||
'const receiver = {}; Reflect.set({},"x",1,receiver);',
|
||||
'(0, Object.defineProperty)(metadata,"x",{value:1});',
|
||||
])("keeps a fresh bound target or unused binding separate: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`const metadata = {}; ${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps unrelated exports after an aliased prebound key write", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const electron = require("electron");
|
||||
const key = "Unrelated";
|
||||
const mutate = Object.defineProperty.bind(null, electron, key);
|
||||
mutate({value: custom});
|
||||
new electron.BrowserWindow({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
@@ -77,7 +77,7 @@ describe("Electron API identity", () => {
|
||||
it("follows bundler namespace interop helpers without accepting other writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var __toESM = (mod) => mod;
|
||||
var __importStar = (this && this.__importStar) || ((mod) => mod);
|
||||
var __importStar = (mod) => mod;
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron);
|
||||
new electron.BrowserWindow({ webPreferences: { preload: "./rolldown.js" } });
|
||||
@@ -120,4 +120,53 @@ describe("Electron API identity", () => {
|
||||
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("follows stable declaration aliases but not an assigned default parameter", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const direct = require("electron");
|
||||
const constAlias = direct;
|
||||
new constAlias.BrowserWindow({webPreferences:{preload:"./const.js"}});
|
||||
|
||||
let letAlias = require("electron");
|
||||
new letAlias.BrowserWindow({webPreferences:{preload:"./let.js"}});
|
||||
|
||||
const { BrowserWindow } = require("electron");
|
||||
new BrowserWindow({webPreferences:{preload:"./destructured.js"}});
|
||||
|
||||
function withDefault(electron = require("./not-electron")) {
|
||||
if (flag) electron = require("electron");
|
||||
new electron.BrowserWindow({webPreferences:{preload:"./default.js"}});
|
||||
}
|
||||
`);
|
||||
|
||||
expect(
|
||||
analysis.electron.browser_windows.map(({ preload_path }) => preload_path),
|
||||
).toEqual(["./const.js", "./let.js", "./destructured.js"]);
|
||||
});
|
||||
|
||||
it("preserves one initializer across variable redeclarations without accepting writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var electron;
|
||||
var electron = require("electron");
|
||||
var electron;
|
||||
new electron.BrowserWindow({webPreferences:{preload:"./redeclared.js"}});
|
||||
|
||||
var replaced;
|
||||
var replaced = require("electron");
|
||||
replaced = fake;
|
||||
new replaced.BrowserWindow({webPreferences:{preload:"./replaced.js"}});
|
||||
|
||||
var initializedTwice = require("electron");
|
||||
var initializedTwice = fake;
|
||||
new initializedTwice.BrowserWindow({});
|
||||
|
||||
var conditional;
|
||||
if (flag) { var conditional = require("electron"); }
|
||||
new conditional.BrowserWindow({});
|
||||
`);
|
||||
|
||||
expect(
|
||||
analysis.electron.browser_windows.map(({ preload_path }) => preload_path),
|
||||
).toEqual(["./redeclared.js"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,16 +86,20 @@ export const semanticObjectPatternKeys = (
|
||||
return key === null ? [] : [key];
|
||||
});
|
||||
|
||||
/** Visit member write targets in direct and destructuring assignment forms. */
|
||||
export function* semanticMemberWriteTargets(
|
||||
/** Visit binding and member leaves in direct and destructuring write targets. */
|
||||
export function* semanticWriteTargets(
|
||||
root: t.Node,
|
||||
): Generator<t.MemberExpression | t.OptionalMemberExpression> {
|
||||
): Generator<t.Identifier | t.MemberExpression | t.OptionalMemberExpression> {
|
||||
const pending = [root];
|
||||
while (pending.length > 0) {
|
||||
const next = pending.pop();
|
||||
if (next === undefined) break;
|
||||
const node = unwrapJavaScriptExpression(next).node;
|
||||
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
|
||||
if (
|
||||
t.isIdentifier(node) ||
|
||||
t.isMemberExpression(node) ||
|
||||
t.isOptionalMemberExpression(node)
|
||||
)
|
||||
yield node;
|
||||
else if (t.isRestElement(node)) pending.push(node.argument);
|
||||
else if (t.isAssignmentPattern(node)) pending.push(node.left);
|
||||
|
||||
@@ -2,10 +2,9 @@ import * as t from "@babel/types";
|
||||
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
semanticMemberWriteTargets,
|
||||
semanticWriteTargets,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
import { SemanticPropertyPathCoverage } from "./javascriptSemanticPropertyPaths.js";
|
||||
import { traverseJavaScriptAstSteps } from "./javascriptSemanticTraversal.js";
|
||||
|
||||
/** Match Electron's supported module entry points. */
|
||||
@@ -24,7 +23,7 @@ export const electronExportPath = (
|
||||
|
||||
/** Static identity recovery cannot establish the absence of Electron usage. */
|
||||
export const ELECTRON_IDENTITY_LIMITATION =
|
||||
"Electron API identity follows proven lexical module aliases, including results of namespace interop helpers (__toESM, __importStar, _interopRequireWildcard) recognized by name and a single program-scope function definition; helper bodies are not evaluated. Other reassigned bindings, dynamic selections, and visibly overwritten namespace members are unresolved; missing findings do not establish absence. Arbitrary call side effects and runtime registration are not evaluated.";
|
||||
"Electron API identity follows proven lexical module aliases and structurally verified module-namespace interop. Other reassignments, dynamic selections, and visibly overwritten namespace members are unresolved; missing findings do not establish absence. Arbitrary call side effects and runtime registration are not evaluated.";
|
||||
|
||||
/** Preserve exact property segments instead of flattening literal dotted keys. */
|
||||
export const electronMemberPath = (
|
||||
@@ -42,12 +41,96 @@ export const electronMemberPath = (
|
||||
return { root, members: members.toReversed() };
|
||||
};
|
||||
|
||||
/** Index visible writes through proven Electron aliases, without executing them. */
|
||||
export function* collectElectronMemberWritesSteps(
|
||||
/** A known intrinsic callable and its examined positional arguments. */
|
||||
export interface JavaScriptIntrinsicInvocation {
|
||||
readonly kind: "known" | "opaque";
|
||||
/** The original bound receiver; rebinding cannot replace it. */
|
||||
readonly receiver?: t.Node;
|
||||
readonly path: readonly string[];
|
||||
readonly arguments:
|
||||
| readonly t.CallExpression["arguments"][number][]
|
||||
| undefined;
|
||||
}
|
||||
|
||||
/** Index member and binding writes through caller-proven lexical identities. */
|
||||
export function* collectJavaScriptIdentityWritesSteps(
|
||||
program: t.Program,
|
||||
origin: (root: t.Node) => readonly string[] | undefined,
|
||||
): Generator<void, SemanticPropertyPathCoverage> {
|
||||
const writes = new SemanticPropertyPathCoverage();
|
||||
origin: (
|
||||
root: t.Node,
|
||||
kind: "binding" | "member" | "opaque-call",
|
||||
) => readonly string[] | undefined,
|
||||
intrinsicInvocation: (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
) => JavaScriptIntrinsicInvocation | undefined,
|
||||
staticString: (node: t.Node | undefined) => string | undefined,
|
||||
freshObject: (node: t.Node) => boolean,
|
||||
retain: (node: t.Node, path: readonly (string | null)[]) => void,
|
||||
): Generator<void> {
|
||||
const objectMutators = new Set([
|
||||
"defineProperty",
|
||||
"defineProperties",
|
||||
"assign",
|
||||
"setPrototypeOf",
|
||||
]);
|
||||
const reflectMutators = new Set([
|
||||
"set",
|
||||
"deleteProperty",
|
||||
"defineProperty",
|
||||
"setPrototypeOf",
|
||||
]);
|
||||
const keyedMutators = new Set(["set", "deleteProperty", "defineProperty"]);
|
||||
const retainCallEffects = (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
): void => {
|
||||
const invocation = intrinsicInvocation(node);
|
||||
if (invocation?.kind === "opaque") {
|
||||
const scope = origin(node, "opaque-call");
|
||||
if (scope !== undefined) retain(node, scope);
|
||||
return;
|
||||
}
|
||||
const callee = invocation?.path;
|
||||
const arguments_ = invocation?.arguments;
|
||||
const method = callee?.at(-1);
|
||||
const owner = callee?.length === 3 ? callee[1] : undefined;
|
||||
if (
|
||||
(owner === "Object" && objectMutators.has(method ?? "")) ||
|
||||
(owner === "Reflect" && reflectMutators.has(method ?? ""))
|
||||
) {
|
||||
// Reflect.set can write through its explicit receiver as well as
|
||||
// dispatching through its target. Both identities need examination.
|
||||
const targets =
|
||||
owner === "Reflect" &&
|
||||
method === "set" &&
|
||||
arguments_ !== undefined &&
|
||||
(arguments_.length >= 4 || arguments_.some(t.isSpreadElement))
|
||||
? [
|
||||
arguments_[0],
|
||||
arguments_.some(t.isSpreadElement) ? undefined : arguments_[3],
|
||||
]
|
||||
: [arguments_?.[0]];
|
||||
for (const target of targets) {
|
||||
// A known mutator with an opaque argument list can overwrite any
|
||||
// captured intrinsic. Do not turn an unexamined target into proof.
|
||||
if (target === undefined || t.isSpreadElement(target)) {
|
||||
const scope = origin(node, "opaque-call");
|
||||
if (scope !== undefined) retain(node, scope);
|
||||
}
|
||||
if (t.isNode(target) && !t.isSpreadElement(target)) {
|
||||
const { root, members } = electronMemberPath(target);
|
||||
const exported = origin(root, "member");
|
||||
if (exported !== undefined) {
|
||||
const key = keyedMutators.has(method ?? "")
|
||||
? [staticString(arguments_?.[1]) ?? null]
|
||||
: [];
|
||||
retain(node, [...exported, ...members, ...key]);
|
||||
} else if (!freshObject(target)) {
|
||||
const scope = origin(node, "opaque-call");
|
||||
if (scope !== undefined) retain(node, scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
yield* traverseJavaScriptAstSteps(program, {
|
||||
enter: (node) => {
|
||||
const target = t.isAssignmentExpression(node)
|
||||
@@ -60,12 +143,20 @@ export function* collectElectronMemberWritesSteps(
|
||||
? node.left
|
||||
: undefined;
|
||||
if (target === undefined) return;
|
||||
for (const member of semanticMemberWriteTargets(target)) {
|
||||
const { root, members } = electronMemberPath(member);
|
||||
const exported = origin(root);
|
||||
if (exported !== undefined) writes.retain([...exported, ...members]);
|
||||
for (const leaf of semanticWriteTargets(target)) {
|
||||
if (t.isIdentifier(leaf)) {
|
||||
const exported = origin(leaf, "binding");
|
||||
if (exported !== undefined) retain(node, exported);
|
||||
continue;
|
||||
}
|
||||
const { root, members } = electronMemberPath(leaf);
|
||||
const exported = origin(root, "member");
|
||||
if (exported !== undefined) retain(node, [...exported, ...members]);
|
||||
}
|
||||
},
|
||||
exit: (node) => {
|
||||
if (t.isCallExpression(node) || t.isOptionalCallExpression(node))
|
||||
retainCallEffects(node);
|
||||
},
|
||||
});
|
||||
return writes;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import type { JavaScriptIntrinsicInvocation } from "./javascriptElectronMemberWrites.js";
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
|
||||
const arrayArguments = (array: t.Node | undefined) =>
|
||||
t.isArrayExpression(array) &&
|
||||
array.elements.every((element) => t.isExpression(element))
|
||||
? array.elements.filter((element): element is t.Expression =>
|
||||
t.isExpression(element),
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const invocationArguments = (
|
||||
method: "call" | "apply",
|
||||
arguments_: JavaScriptIntrinsicInvocation["arguments"],
|
||||
) =>
|
||||
t.isSpreadElement(arguments_?.[0])
|
||||
? undefined
|
||||
: method === "apply"
|
||||
? arrayArguments(arguments_?.[1])
|
||||
: arguments_?.slice(1);
|
||||
|
||||
/**
|
||||
* Normalize known invocation syntax once, retaining bound argument prefixes.
|
||||
* Binding a function alone is not a write; only its eventual call is examined.
|
||||
*/
|
||||
export const resolveJavaScriptIntrinsicInvocation = (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
intrinsicPath: (node: t.Node) => readonly string[] | undefined,
|
||||
boundIntrinsic: (node: t.Node) => JavaScriptIntrinsicInvocation | undefined,
|
||||
intrinsicReadChanged: (node: t.Node, path: readonly string[]) => boolean,
|
||||
): JavaScriptIntrinsicInvocation | undefined => {
|
||||
const visited = new Set<t.Node>();
|
||||
let callee: t.Node = node.callee;
|
||||
let arguments_: JavaScriptIntrinsicInvocation["arguments"] = node.arguments;
|
||||
let receiver: t.Node | undefined;
|
||||
let explicitReceiver = false;
|
||||
for (;;) {
|
||||
callee = unwrapJavaScriptExpression(callee).node;
|
||||
if (t.isSequenceExpression(callee)) {
|
||||
const finalExpression = callee.expressions.at(-1);
|
||||
if (finalExpression === undefined) return undefined;
|
||||
// Comma yields a value, not a member reference. An outer invocation
|
||||
// can still supply an explicit receiver for that value.
|
||||
explicitReceiver = true;
|
||||
callee = finalExpression;
|
||||
continue;
|
||||
}
|
||||
if (visited.has(callee)) return undefined;
|
||||
visited.add(callee);
|
||||
let path = intrinsicPath(callee);
|
||||
if (path !== undefined && intrinsicReadChanged(callee, path))
|
||||
return { kind: "opaque", path, arguments: undefined };
|
||||
if (path === undefined) {
|
||||
if (
|
||||
t.isMemberExpression(callee) ||
|
||||
t.isOptionalMemberExpression(callee)
|
||||
) {
|
||||
const method = semanticStaticPropertyKey(
|
||||
callee.property,
|
||||
callee.computed,
|
||||
);
|
||||
if (method === "call" || method === "apply") {
|
||||
const bound = boundIntrinsic(callee.object);
|
||||
if (
|
||||
bound !== undefined &&
|
||||
intrinsicReadChanged(callee, [...bound.path, method])
|
||||
)
|
||||
return { kind: "opaque", path: bound.path, arguments: undefined };
|
||||
receiver = arguments_?.[0];
|
||||
explicitReceiver = true;
|
||||
callee = callee.object;
|
||||
arguments_ = invocationArguments(method, arguments_);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const bound = boundIntrinsic(callee);
|
||||
if (bound === undefined) return undefined;
|
||||
if (bound.kind === "opaque") return bound;
|
||||
path = bound.path;
|
||||
receiver = bound.receiver;
|
||||
explicitReceiver = true;
|
||||
arguments_ =
|
||||
bound.arguments === undefined
|
||||
? undefined
|
||||
: [...bound.arguments, ...(arguments_ ?? [])];
|
||||
}
|
||||
const method = path.length > 3 ? path.at(-1) : undefined;
|
||||
if (method === "call" || method === "apply") {
|
||||
// These properties hold generic function values. Their receiver selects
|
||||
// the callable; property-chain depth does not consume more arguments.
|
||||
const callable: t.Node | undefined = explicitReceiver
|
||||
? receiver
|
||||
: t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)
|
||||
? callee.object
|
||||
: undefined;
|
||||
if (!t.isExpression(callable)) return undefined;
|
||||
callee = callable;
|
||||
receiver = arguments_?.[0];
|
||||
explicitReceiver = true;
|
||||
arguments_ = invocationArguments(method, arguments_);
|
||||
continue;
|
||||
}
|
||||
if (path.join(".") === "intrinsic.Reflect.apply") {
|
||||
const callable = arguments_?.[0];
|
||||
if (!t.isExpression(callable)) return undefined;
|
||||
callee = callable;
|
||||
receiver = arguments_?.[1];
|
||||
explicitReceiver = true;
|
||||
arguments_ = arrayArguments(arguments_?.[2]);
|
||||
continue;
|
||||
}
|
||||
return {
|
||||
kind: "known",
|
||||
path,
|
||||
arguments: arguments_,
|
||||
...(receiver === undefined ? {} : { receiver }),
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
// Rolldown runtime from the public T3 Code nightly 20261011.2967 main.cjs.
|
||||
// The input is inert source: none of these helpers or Electron APIs is executed.
|
||||
export const ROLLDOWN_MODULE_INTEROP = `
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
`;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user