refactor: return complete tool results inline

This commit is contained in:
morluto
2026-09-29 07:08:46 +08:00
parent 2160d4fae5
commit 0d96275b68
535 changed files with 4084 additions and 13537 deletions
+1 -3
View File
@@ -69,7 +69,7 @@ export const createCacheProvider = (
resolveAnalysisProfile: () =>
Promise.resolve(
resultOk({
profile: createAnalysisProfile(identity, 1, { fixture: true }),
profile: createAnalysisProfile(identity, { fixture: true }),
compatibility: {},
}),
),
@@ -136,8 +136,6 @@ const cacheCapability = (
): CapabilityDescriptor => ({
provider,
operation,
inputContractVersion: 1,
outputContractVersion: 1,
available: true,
reason: null,
pagination: "none",
@@ -16,20 +16,16 @@ def _probe(namespace, payload):
action = payload["action"]
try:
if action == "match":
parsed = namespace["sre_parse"].parse(payload["pattern"])
paths, steps = namespace["_validate_regex_node"](parsed)
flags = (
0
if payload.get("case_sensitive", False)
else namespace["re"].IGNORECASE
)
expression = namespace["re"].compile(payload["pattern"], flags)
matcher = namespace["_bounded_regex_matcher"](expression, paths, steps)
matched = matcher(payload["value"])
matched = expression.search(payload["value"]) is not None
return {
"action": action,
"ok": True,
"backtracking_paths": paths,
"matched": matched,
}
if action == "search":
@@ -38,7 +34,7 @@ def _probe(namespace, payload):
return {
"action": action,
"ok": True,
"result": namespace["_search_page"](
"result": namespace["_search_results"](
object(), "string", payload["params"]
),
}
+19
View File
@@ -46,6 +46,14 @@ export const targets = (
},
]
: []),
...Array.from({ length: options.additionalPageCount ?? 0 }, (_, index) => ({
id: `allowed-page-${String(index).padStart(4, "0")}`,
type: "page",
title: `Additional application page ${String(index)}`,
url: `http://127.0.0.1:${String(port)}/additional-${String(index)}`,
attached: false,
webSocketDebuggerUrl: `ws://localhost:${String(port)}/devtools/page/allowed-page`,
})),
{
id: "unsupported-page",
type: "page",
@@ -100,6 +108,17 @@ export const targets = (
webSocketDebuggerUrl: `ws://localhost:${String(port)}/devtools/page/electron-page`,
}),
},
...Array.from(
{ length: options.additionalElectronPageCount ?? 0 },
(_, index) => ({
id: `electron-page-${String(index).padStart(4, "0")}`,
type: "page",
title: `Additional Electron page ${String(index)}`,
url: options.electronFileUrl,
attached: false,
webSocketDebuggerUrl: `ws://localhost:${String(port)}/devtools/page/electron-page`,
}),
),
{
id: "electron-worker",
type: "worker",
+2
View File
@@ -27,6 +27,8 @@ export interface FakeOptions {
readonly omitTargetWebSocket?: boolean;
readonly additionalPageWithWebSocket?: boolean;
readonly additionalPageWithoutWebSocket?: boolean;
readonly additionalPageCount?: number;
readonly additionalElectronPageCount?: number;
readonly invalidAttachedSession?: boolean;
readonly malformedMessageOnMethod?: string;
readonly malformedEventOnMethod?: string;
+5 -19
View File
@@ -226,39 +226,29 @@ const inventoryResultFor = (method) => {
case "list_documents":
return ["fixture"];
case "list_names":
return page(method, [nameItem()]);
return [nameItem()];
case "list_procedures":
return page(method, [procedureItem()]);
return [procedureItem()];
case "list_segments":
return [segmentItem()];
case "list_strings":
return page(method, [stringItem("0x2000", "fixture value")]);
return [stringItem("0x2000", "fixture value")];
case "procedure_address":
return "0x1000";
case "resolve_containing_procedure":
return containingProcedureResult();
case "search_procedures":
return page(method, [procedureSearchItem()]);
return [procedureSearchItem()];
case "search_strings":
return page(method, [stringSearchItem()]);
return [stringSearchItem()];
default:
return undefined;
}
};
const page = (method, items) => ({
items,
offset: 0,
limit: method.startsWith("search_") ? 100 : 500,
total: items.length,
next_offset: null,
has_more: false,
});
const nameItem = () => ({
address: "0x1000",
value: "fixture_main",
value_truncated: false,
symbol: {
primary: true,
dynamic: false,
@@ -271,7 +261,6 @@ const nameItem = () => ({
const procedureItem = () => ({
address: "0x1000",
value: "fixture_main",
value_truncated: false,
procedure: { external: false, thunk: false, thunk_target: null },
});
@@ -294,7 +283,6 @@ const segmentItem = () => ({
const stringItem = (address, value) => ({
address,
value,
value_truncated: false,
string: {
encoding: "UTF-8",
termination: "present_or_not_required",
@@ -320,11 +308,9 @@ const containingProcedureResult = () => ({
const procedureSearchItem = () => ({
address: "0x1000",
value: "fixture_main",
value_truncated: false,
});
const stringSearchItem = () => ({
address: "0x2000",
value: "fixture value",
value_truncated: false,
});
+14 -64
View File
@@ -69,33 +69,12 @@ const enhancedFixtureResult = (method) => {
case "list_documents":
return ["fixture"];
case "list_procedures":
return {
items: [{ address: "0x1000", value: "fixture" }],
offset: 0,
limit: 500,
total: 1,
next_offset: null,
has_more: false,
};
return [{ address: "0x1000", value: "fixture" }];
case "list_strings":
return {
items: [{ address: "0x1000", value: "fixture" }],
offset: 0,
limit: 500,
total: 1,
next_offset: null,
has_more: false,
};
return [{ address: "0x1000", value: "fixture" }];
case "procedure_pseudo_code":
return "return 0;";
case "analyze_function": {
const empty = () => ({
items: [],
total: 0,
returned: 0,
truncated: false,
next_offset: null,
});
return {
procedure: {
address: "0x1000",
@@ -103,42 +82,21 @@ const enhancedFixtureResult = (method) => {
signature: null,
locals: [],
},
pseudocode: {
text: "return 0;",
total_chars: 9,
returned_chars: 9,
truncated: false,
next_offset: null,
},
assembly: { ...empty(), items: ["ret"], total: 1, returned: 1 },
comments: empty(),
callers: empty(),
callees: empty(),
incoming_references: empty(),
outgoing_references: empty(),
referenced_strings: empty(),
referenced_names: empty(),
basic_blocks: {
...empty(),
items: [{ start: "0x1000", end: "0x1001", successors: [] }],
total: 1,
returned: 1,
},
instruction_scan: { scanned: 1, truncated: false },
pseudocode: "return 0;",
assembly: ["ret"],
comments: [],
callers: [],
callees: [],
incoming_references: [],
outgoing_references: [],
referenced_strings: [],
referenced_names: [],
basic_blocks: [{ start: "0x1000", end: "0x1001", successors: [] }],
};
}
case "search_strings":
case "search_procedures":
return {
items: [
{ address: "0x1000", value: "fixture", value_truncated: false },
],
offset: 0,
limit: 100,
total: 1,
next_offset: null,
has_more: false,
};
return [];
case "xrefs":
return ["0x1000"];
default:
@@ -240,15 +198,7 @@ const server = createServer((socket) => {
result: {
procedure: { address: "0x1000", name: "fixture" },
direction: request.params.direction ?? "outgoing",
references: {
items: [],
total: 0,
returned: 0,
truncated: false,
next_offset: null,
},
instructions_scanned: 1,
instruction_scan_truncated: false,
references: [],
},
});
} else {
+5 -1
View File
@@ -2,7 +2,11 @@ import { spawn } from "node:child_process";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const bootstrapIndex = process.argv.indexOf("--python") + 1;
const bootstrapFlag = ["-Y", "--python"].find((flag) =>
process.argv.includes(flag),
);
const bootstrapIndex =
bootstrapFlag === undefined ? 0 : process.argv.indexOf(bootstrapFlag) + 1;
const actionIndex = Math.max(
process.argv.indexOf("--executable"),
process.argv.indexOf("--database"),
+11
View File
@@ -13,6 +13,7 @@ interface FakeV8InspectorOptions {
readonly targetType?: "node" | "page";
readonly scriptUrls?: readonly string[];
readonly additionalTargetUrl?: string;
readonly additionalTargetCount?: number;
readonly closeOnMethod?: string;
}
@@ -63,6 +64,16 @@ export const startFakeV8Inspector = async (
port,
),
]),
...Array.from(
{ length: options.additionalTargetCount ?? 0 },
(_, index) =>
target(
`00000000-0000-4000-8000-${String(index + 3).padStart(12, "0")}`,
options.targetUrl,
options.targetType ?? "node",
port,
),
),
]),
);
return;
+11 -5
View File
@@ -29,14 +29,16 @@ class FakeDocument:
class FakeDocumentProvider:
document = FakeDocument()
current = FakeDocument()
documents = [document, current]
@classmethod
def getAllDocuments(cls):
return [cls.document]
return cls.documents
@classmethod
def getCurrentDocument(cls):
return cls.document
return cls.current
def load_bridge(path):
@@ -61,14 +63,17 @@ def main():
}
bridge["REA_TARGET_PATH"] = "/tmp/rea-hopper-facade-fixture"
bridge["REA_OWNS_PROCESS_LIFETIME"] = False
bridge["_configure_hopper_api"](FakeDocumentProvider)
bridge["_bind_session_document"]()
current = bridge["_dispatch"]("current_document", {})
current_address = bridge["_dispatch"]("current_address", {})
selected = bridge["_session_document"]().getDocumentName()
selected = bridge["_session_document"]() is FakeDocumentProvider.current
retained = bridge["_dispatch"]("shutdown", {})
analysis_guard = None
try:
bridge["_dispatch"]("list_procedures", {"offset": 0, "limit": 1})
bridge["_dispatch"]("list_procedures", {})
except Exception as error:
analysis_guard = {
"type": type(error).__name__,
@@ -110,7 +115,8 @@ def main():
"imported_without_hopper": unavailable,
"current_document": current,
"current_address": current_address,
"session_document": selected,
"session_document_reused": selected,
"shared_document_shutdown": retained,
"analysis_guard": analysis_guard,
"bridge_messages": bridge_messages,
"invalid_id_response": invalid_id_response,