mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
* fix(views): size evidence-json pages to the effective agent result budget An over-budget delivery names inspect_analysis_view evidence-json at offset 0 as its next call. With limit omitted, a page held at most 24,576 bytes of escaped text, sized for the 32 KiB default budget with a fixed 8 KiB allowance for its view Evidence. Below about 32 KiB (the minimum is 4,096), following next returned another answer over the budget. The view service now pages an omitted limit as the largest page whose view Evidence, measured as delivered, fits the effective budget (the runtime override, then REA_AGENT_RESULT_BUDGET_BYTES, then the default). A page over the budget shrinks by its measured excess and is projected again. The MCP binding, application-execution views and the CLI pass the launch seed they captured. A default page also never spans more code units than the largest explicit limit, so large budgets keep fitting the stdio frame. The fixed envelope constant and default page size are gone. * perf(views): reuse the last window while shrinking an uncached evidence-json page
159 lines
6.6 KiB
TypeScript
159 lines
6.6 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { ArtifactResourceScope } from "../resources/index.js";
|
|
import { ANALYSIS_VIEW_PROVIDER } from "../domain/investigationProviders.js";
|
|
import { inspectEvidenceBundleCommand } from "../application/EvidenceBundleCommands.js";
|
|
import { ANALYSIS_VIEW_TOOL_CONTRACTS } from "../contracts/analysisViewToolContracts.js";
|
|
import {
|
|
getEvidenceBundleInputSchema,
|
|
importEvidenceBundleInputSchema,
|
|
} from "../contracts/sessionToolSchemas.js";
|
|
import { CLI_COMMANDS } from "../contracts/cliCommandNames.js";
|
|
import { parseCliJsonInput } from "./cliJsonInput.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
|
import type { Logger } from "pino";
|
|
import { registerCliCommand } from "./commandRegistry.js";
|
|
import type { CliInstance } from "./types.js";
|
|
import { localPathStringSchema } from "../domain/localPath.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
import { cliPublicationInvocation } from "./cliEvidencePublication.js";
|
|
import { renewRetainedEvidence } from "./cliEvidenceRetention.js";
|
|
|
|
/** The Evidence files a successful view read: its file source and bundle. */
|
|
const renewReadRetainedEvidence = async (
|
|
document: unknown,
|
|
bundlePath: string | undefined,
|
|
): Promise<void> => {
|
|
const { retention } = cliPublicationInvocation();
|
|
const source =
|
|
typeof document === "object" && document !== null
|
|
? (document as { readonly source?: unknown }).source
|
|
: undefined;
|
|
const sourcePath =
|
|
typeof source === "object" &&
|
|
source !== null &&
|
|
(source as { readonly kind?: unknown }).kind === "evidence-file"
|
|
? (source as { readonly path?: unknown }).path
|
|
: undefined;
|
|
for (const path of [sourcePath, bundlePath])
|
|
if (typeof path === "string") await renewRetainedEvidence(path, retention);
|
|
};
|
|
import { contractNamed } from "./contractCliDescription.js";
|
|
import { registerContractDocumentCommand } from "./contractDocumentCommand.js";
|
|
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
import { jsonInputArgument } from "./jsonInputArgument.js";
|
|
|
|
const inspectEvidenceBundleCliInputSchema =
|
|
getEvidenceBundleInputSchema.safeExtend({
|
|
path: importEvidenceBundleInputSchema.shape.path,
|
|
});
|
|
|
|
/** Project selected views of completed analysis Evidence through the CLI. */
|
|
export const registerAnalysisViewCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
): void => {
|
|
registerCliCommand(cli, CLI_COMMANDS.inspectEvidenceBundle, {
|
|
description:
|
|
"Inspect a local Evidence bundle completely, as optionally paged discovery metadata, as a page of selected complete records, or as direct-link and retained-closure membership and direct referrers.",
|
|
args: z.object({
|
|
inputJson: jsonInputArgument(
|
|
"JSON or JSON file with absolute path, detail, optional source-record filters, summary/records/links offset/limit, and links traversal/linked_evidence_id/link_status (default all with a linked ID, otherwise missing)",
|
|
inspectEvidenceBundleCliInputSchema,
|
|
),
|
|
}),
|
|
run: ({ args }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectEvidenceBundle, async () => {
|
|
const input = await parseCliJsonInput(
|
|
args.inputJson,
|
|
CLI_COMMANDS.inspectEvidenceBundle,
|
|
signal,
|
|
);
|
|
if (!input.ok) return input.error;
|
|
const parsed = inspectEvidenceBundleCliInputSchema.safeParse(
|
|
input.value,
|
|
);
|
|
if (!parsed.success)
|
|
return {
|
|
error: "Evidence bundle inspection failed",
|
|
...projectAnalysisError(
|
|
analysisInputErrorFromIssues(
|
|
CLI_COMMANDS.inspectEvidenceBundle,
|
|
parsed.error.issues,
|
|
input.value,
|
|
),
|
|
),
|
|
};
|
|
const result = await inspectEvidenceBundleCommand(
|
|
parsed.data,
|
|
signal,
|
|
);
|
|
return result.ok
|
|
? result.value
|
|
: {
|
|
error: "Evidence bundle inspection failed",
|
|
...projectAnalysisError(result.error),
|
|
};
|
|
}),
|
|
),
|
|
});
|
|
registerContractDocumentCommand(
|
|
cli,
|
|
logger,
|
|
contractNamed(ANALYSIS_VIEW_TOOL_CONTRACTS, "inspect_analysis_view"),
|
|
{
|
|
description:
|
|
"Project a selected view of completed Evidence JSON for a supported analysis operation. For inventory rows, use --format csv or --format tsv with --filter-output normalized_result.items and --columns logical_path,artifact_id (if those fields are included in the view).",
|
|
document: "Inline workflow JSON or JSON file path",
|
|
// An evidence-file path is resolved against the operator's working directory.
|
|
// `view.artifact_path` exists only on format_record_headers pages, so
|
|
// no other view's semantic `path` selector is resolved as a file.
|
|
callerPaths: [
|
|
["source", "path"],
|
|
["view", "artifact_path"],
|
|
],
|
|
cliOptions: {
|
|
evidenceBundle: localPathStringSchema
|
|
.optional()
|
|
.describe(
|
|
"Read the exact retained-evidence source ID from this local Evidence bundle without reopening the target; omit for inline Evidence",
|
|
),
|
|
},
|
|
},
|
|
async (document, { signal, operation, cliOptions }) => {
|
|
const resources = new ArtifactResourceScope();
|
|
const bundlePath = cliOptions.evidenceBundle;
|
|
const result = await finishAnalysisCommand(
|
|
async () => {
|
|
const { inspectAnalysisView } =
|
|
await import("../application/analysisView/AnalysisViewService.js");
|
|
return inspectAnalysisView(document, undefined, {
|
|
signal,
|
|
resources,
|
|
agentBudgetSeed: cliPublicationInvocation().agentBudgetSeed,
|
|
...(bundlePath === undefined
|
|
? {}
|
|
: { evidenceBundlePath: bundlePath }),
|
|
});
|
|
},
|
|
resources,
|
|
ANALYSIS_VIEW_PROVIDER.id,
|
|
operation,
|
|
signal,
|
|
);
|
|
// Reading a retained record renews its age in the private cache.
|
|
if (result.ok) await renewReadRetainedEvidence(document, bundlePath);
|
|
// Preserve the inline command's existing error label without copying
|
|
// the authenticated completed Evidence or its partial observation.
|
|
return result.ok
|
|
? result.value
|
|
: bundlePath === undefined
|
|
? { error: "Application workflow failed", ...result.error }
|
|
: result.error;
|
|
},
|
|
);
|
|
};
|