feat(sqlite): inspect offline snapshots with selective evidence (#2271)
Add offline SQLite database/WAL inspection through the shared CLI/MCP. Use compact inventory, selected-table schema, exact ordered columns and bounded row samples while preserving source identity and lossless values. Retain completed Evidence through late cancellation and private-root cleanup failures, bound concurrent inspections, and recheck journal validity after acquisition. Reuse prepared CI runtime artifacts across supported Node lines. Co-authored-by: Y0UW1SH <29498139+Y0UW1SH@users.noreply.github.com> Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -61,8 +61,19 @@ export const createEvidenceToolHandler =
|
||||
const result = await logToolExecution(logger, name, () =>
|
||||
operation(input, { signal: context.mcpReq.signal }),
|
||||
);
|
||||
if (!result.ok)
|
||||
if (!result.ok) {
|
||||
const partial = result.error.partialObservation;
|
||||
if (partial !== undefined && "evidence_id" in partial) {
|
||||
const recorded = recordEvidence?.(partial);
|
||||
if (recorded !== undefined)
|
||||
return server.delivery.toRecordedPartialErrorToolResult(
|
||||
result.error,
|
||||
partial.evidence_id,
|
||||
recorded,
|
||||
);
|
||||
}
|
||||
return server.delivery.toCallToolResult(result, contract);
|
||||
}
|
||||
const recorded = recordEvidence?.(result.value);
|
||||
return server.delivery.toEvidenceToolResult(
|
||||
result.value,
|
||||
|
||||
@@ -7,6 +7,9 @@ import { registerPeResourcesTool } from "./registerPeResourcesTool.js";
|
||||
import type { EvmInterfaceService } from "../application/evm/EvmInterfaceService.js";
|
||||
import { evmInterfaceModule } from "../composition/evm.js";
|
||||
import { registerEvmTools } from "./registerEvmTools.js";
|
||||
import type { SqliteDatabaseService } from "../application/sqlite/SqliteDatabaseService.js";
|
||||
import { createSqliteDatabaseService } from "../composition/sqlite.js";
|
||||
import { registerSqliteTools } from "./registerSqliteTools.js";
|
||||
import { registerRecordedCrashTools } from "./registerRecordedCrashTools.js";
|
||||
import { createRecordedCrashService } from "../composition/binaryDiagnostics.js";
|
||||
import { createGoBinaryService } from "../composition/go.js";
|
||||
@@ -118,6 +121,7 @@ export interface CreateServerOptions {
|
||||
readonly delivery?: ToolResultDelivery;
|
||||
readonly wasmArtifact?: WasmArtifactService;
|
||||
readonly evmInterface?: EvmInterfaceService;
|
||||
readonly sqliteDatabase?: SqliteDatabaseService;
|
||||
readonly logger?: Logger;
|
||||
readonly binaryLayout?: BinaryLayoutService;
|
||||
readonly goBinary?: GoBinaryService;
|
||||
@@ -243,6 +247,8 @@ export const createServer = (
|
||||
const delivery = selectToolResultDelivery(environment, options.delivery);
|
||||
const evmInterface =
|
||||
options.evmInterface ?? evmInterfaceModule.create(environment);
|
||||
const sqliteDatabase =
|
||||
options.sqliteDatabase ?? createSqliteDatabaseService(environment);
|
||||
const binaryLayout =
|
||||
options.binaryLayout ?? createBinaryLayoutService(environment);
|
||||
const recordedCrash =
|
||||
@@ -262,6 +268,7 @@ export const createServer = (
|
||||
environment,
|
||||
delivery,
|
||||
evmInterface,
|
||||
sqliteDatabase,
|
||||
binaryLayout,
|
||||
recordedCrash,
|
||||
webSourceLocation,
|
||||
@@ -302,6 +309,7 @@ export const createServer = (
|
||||
adbDevice.close(),
|
||||
flutter.close(),
|
||||
evmInterface.close(),
|
||||
sqliteDatabase.close(),
|
||||
binaryLayout.close(),
|
||||
recordedCrash.close(),
|
||||
webSourceLocation.close(),
|
||||
@@ -520,6 +528,13 @@ const registerConfiguredAnalysisTools = (
|
||||
recordEvidence,
|
||||
withAdmittedAnalysis,
|
||||
);
|
||||
registerSqliteTools(
|
||||
server,
|
||||
options.sqliteDatabase ?? createSqliteDatabaseService(environment),
|
||||
toolLogger,
|
||||
recordEvidence,
|
||||
withAdmittedAnalysis,
|
||||
);
|
||||
registerRecordedCrashTools(
|
||||
server,
|
||||
options.recordedCrash ?? createRecordedCrashService(environment),
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
|
||||
import type { SqliteDatabaseService } from "../application/sqlite/SqliteDatabaseService.js";
|
||||
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "pino";
|
||||
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
import { createEvidenceToolHandler } from "./contractToolHandler.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
|
||||
/** Bind snapshot inspection to its named contract and additive session Evidence. */
|
||||
export const registerSqliteTools = (
|
||||
server: EvidenceMcpServer,
|
||||
service: SqliteDatabaseService,
|
||||
logger: Logger,
|
||||
recordEvidence?: EvidenceWriter["recordEvidence"],
|
||||
withAdmittedAnalysis?: WithAdmittedAnalysis,
|
||||
): void => {
|
||||
const contract = toolContract("inspect_sqlite_database");
|
||||
const handler = createEvidenceToolHandler(
|
||||
server,
|
||||
(input, options) => service.inspect(input, options),
|
||||
logger,
|
||||
recordEvidence,
|
||||
withAdmittedAnalysis,
|
||||
);
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
handler(contract),
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user