perf(android): filter class pages before bridge serialization (#4791)

Filter class names at the native owner before serialization, and resume matching pages through contiguous inventory positions without a second index or query-result cache. Preserve selected source Evidence, query identity, complete top-level coverage and shared CLI/MCP behavior.

Fixes #4776.

Co-authored-by: gensokyo-dev <[email protected]>
Co-authored-by: Kaoru0822 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-17 13:21:37 +00:00
1 parent 060eb43b54
commit 2d84c800bc
16 files changed
+361 -73

No files matched your search

+22 -23
View File
@@ -136,56 +136,55 @@ const searchClasses = async (
loaded: z.infer<typeof jadxLoadSchema>,
engine: Engine,
): Promise<JsonValue> => {
const classes: string[] = [];
const matches: string[] = [];
const pageSize = 4096;
let total: number | undefined;
let offset = 0;
do {
const page = jadxClassPageSchema.parse(
await tools.json("list_classes", {
offset: classes.length,
query: request.input.query,
offset,
limit: pageSize,
}),
);
if (
(total !== undefined && total !== page.total) ||
page.offset !== classes.length ||
page.total_classes !== loaded.class_count ||
page.offset !== offset ||
page.limit !== pageSize ||
page.items.length > pageSize
page.next_offset < offset ||
page.next_offset > loaded.class_count ||
page.items.length > pageSize ||
page.items.length > page.next_offset - offset ||
(request.input.query === "" &&
page.items.length !== page.next_offset - offset) ||
page.items.some((name) => !name.includes(request.input.query))
)
throw new AnalysisOutputError(
request.operation,
"JADX class pagination changed identity or counts",
);
total = page.total;
classes.push(...page.items);
if (
classes.length > total ||
(page.items.length === 0 && classes.length < total)
(offset < loaded.class_count && page.next_offset === offset) ||
(page.next_offset < loaded.class_count && page.items.length !== pageSize)
)
throw new AnalysisOutputError(
request.operation,
"JADX class pagination is incomplete",
);
} while (classes.length < total);
if (total !== loaded.class_count)
throw new AnalysisOutputError(
request.operation,
"JADX class inventory count differs from the loaded class count",
);
matches.push(...page.items);
offset = page.next_offset;
} while (offset < loaded.class_count);
const occurrences = new Map<string, number>();
for (const name of classes)
for (const name of matches)
occurrences.set(name, (occurrences.get(name) ?? 0) + 1);
const matchingNames = classes.filter((name) =>
name.includes(request.input.query),
);
const duplicateNames = [...occurrences]
.filter(([name, count]) => count > 1 && name.includes(request.input.query))
.filter(([, count]) => count > 1)
.map(([name, count]) => ({ name, occurrences: count }));
return androidResultSchemas.search_android_classes.parse({
engine,
query: request.input.query,
total_classes: total,
matches: matchingNames,
total_classes: loaded.class_count,
matches,
duplicate_names: duplicateNames,
coverage: "complete",
});
+3 -1
View File
@@ -36,7 +36,9 @@ export const jadxAppSchema = z.object({
permissions: z.array(z.string()),
});
export const jadxClassPageSchema = z.object({
total: count,
scope: z.literal("top_level"),
total_classes: count,
next_offset: count,
offset: count,
limit: count,
items: z.array(z.string()),
+1 -1
View File
@@ -9,7 +9,7 @@ export const JADX_RELEASE = Object.freeze({
/** Identity of REA's metadata bridge, distinct from the producing engine. */
export const JADX_BRIDGE_IDENTITY = Object.freeze({
name: "rea-jadx-bridge",
version: "1",
version: "2",
});
/** Remediation when `REA_JADX_MCP_JAR` is missing or not an absolute path. */
@@ -5,11 +5,10 @@ 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.
* Class-search pages duplicate matching names already present in normalized
* results; an empty query also returns the complete top-level inventory.
* Keep the selection and pagination audit inline and link the retained
* record carrying every complete producer reply.
*/
const elideInventoryText = (text: string): string | undefined => {
let page: JsonValue;
@@ -68,9 +67,8 @@ const summarizeInventoryCall = (call: JsonValue): JsonValue => {
/**
* 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.
* Callers without a retaining session receive complete source Evidence inline.
* Both copies preserve examined inventory ranges separately from matching rows.
*/
export const summarizeRetainedAndroidSearch = (
evidence: Evidence,
@@ -36,7 +36,7 @@ export const ANDROID_TOOL_CONTRACTS = [
name: "search_android_classes",
...toolContractMetadata("search_android_classes"),
description:
"Search complete decompiler class-name rows in an explicit local APK by case-sensitive substring. Empty query inventories all rows. Repeated names remain repeated and appear in duplicate_names; the provider accepts only class names for lookup, so these rows do not identify which same-name class node a later lookup selects. Retains artifact and engine identity; no APK execution.",
"Search complete top-level decompiler class-name rows in an explicit local APK by case-sensitive substring. Empty query inventories all rows. Repeated names remain repeated and appear in duplicate_names; the provider accepts only class names for lookup, so these rows do not identify which same-name class node a later lookup selects. Retains artifact and engine identity; no APK execution.",
kind: "android-provider",
inputSchema: androidInputSchemas.search_android_classes,
outputSchema: evidenceResultOf(androidResultSchemas.search_android_classes),