mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
2538214e2c
Add opt-in summaries and stable selected-field pages for native inventories through the shared CLI/MCP Evidence layer. Preserve complete source access, row identity, provenance, string qualifications and unknown discovery coverage. Record real true/jq workflows and portable old-Evidence checks, including tokenizer proxy reductions, additional call/schema costs and observed latency/memory regressions. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { addressedValueSchema } from "../domain/native/nativeInventory.js";
|
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import {
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisInputError,
|
|
AnalysisOutputError,
|
|
} from "../domain/analysisErrorCore.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
import type { AnalysisOperationPort } from "./AnalysisProvider.js";
|
|
import { resolveProcedureAddress } from "./ProcedureAddressResolution.js";
|
|
|
|
/** Resolve a CLI symbol selector without changing existing address spellings. */
|
|
export const resolveXrefsAddress = async (
|
|
analysis: AnalysisOperationPort,
|
|
selector: string,
|
|
signal: AbortSignal,
|
|
): Promise<Result<string, AnalysisError>> => {
|
|
if (
|
|
selector.length === 0 ||
|
|
/^[0-9a-f]+$/iu.test(selector) ||
|
|
/^0x/iu.test(selector) ||
|
|
/:0x/iu.test(selector)
|
|
)
|
|
return ok(selector);
|
|
|
|
const inventory = await analysis.execute("list_names", {}, { signal });
|
|
if (!inventory.ok) {
|
|
if (
|
|
inventory.error instanceof AnalysisCapabilityUnavailableError &&
|
|
inventory.error.operation === "list_names" &&
|
|
!inventory.error.cleanupIncomplete
|
|
)
|
|
return resolveProcedureAddress(
|
|
async (operation, parameters, signal) => {
|
|
const result = await analysis.execute(
|
|
operation,
|
|
parameters,
|
|
signal === undefined ? {} : { signal },
|
|
);
|
|
return result.ok ? ok(result.value.result) : result;
|
|
},
|
|
selector,
|
|
signal,
|
|
);
|
|
return inventory;
|
|
}
|
|
if (!Array.isArray(inventory.value.result))
|
|
return err(
|
|
new AnalysisOutputError(
|
|
"list_names",
|
|
"Expected a symbol inventory array",
|
|
),
|
|
);
|
|
|
|
const addresses = new Set<string>();
|
|
for (const [index, item] of inventory.value.result.entries()) {
|
|
const parsed = addressedValueSchema.safeParse(item);
|
|
if (!parsed.success || parsed.data.address.length === 0)
|
|
return err(
|
|
new AnalysisOutputError(
|
|
"list_names",
|
|
`Invalid symbol inventory entry at index ${index}`,
|
|
),
|
|
);
|
|
if (parsed.data.value === selector) addresses.add(parsed.data.address);
|
|
}
|
|
const [address] = addresses;
|
|
if (addresses.size === 1 && address !== undefined) return ok(address);
|
|
return err(
|
|
new AnalysisInputError("xrefs", undefined, [
|
|
{
|
|
path: ["address"],
|
|
reason: "invalid_value",
|
|
message:
|
|
addresses.size === 0
|
|
? `Unknown analyzed symbol name ${JSON.stringify(selector)}. Use an exact analyzed name or a hexadecimal address.`
|
|
: `Analyzed symbol name ${JSON.stringify(selector)} is ambiguous at ${[...addresses].join(", ")}. Select an exact address.`,
|
|
},
|
|
]),
|
|
);
|
|
};
|