feat(cli): summarize managed members with durable Evidence paging (#5167)

Fixes #5148.

Add opt-in durable managed member summaries and authenticated paging while preserving complete default output, original Evidence, cleanup ownership and queued cancellation.

Verified with bounded real Newtonsoft/Redux/Rust tasks, independent oracles, 556 focused tests and the expanded domain gate; paired token estimates and latency tradeoffs are recorded in experiments/analysis-efficiency/managed-cli.md.
This commit is contained in:
Jay-Alexander Elliot authored and GitHub committed 2026-10-22 00:43:30 +00:00
1 parent d8948efb81
commit 57fd3ea5d8
48 files changed
+4671 -196

No files matched your search

+68 -29
View File
@@ -1,6 +1,9 @@
import { z } from "incur";
import { inspectAnalysisViewValidatedWithFiles } from "../application/analysisView/AnalysisViewService.js";
import { inspectAnalysisViewFromBundle } from "../application/EvidenceBundleCommands.js";
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
import { ANALYSIS_VIEW_PROVIDER } from "../application/InvestigationProviders.js";
import { readEvidenceBundle } from "../application/EvidenceBundleFiles.js";
import { inspectEvidenceBundle } from "../application/investigation/InspectEvidenceBundle.js";
import {
@@ -12,9 +15,11 @@ import { parseCliJsonInput, resolveCliJsonPaths } from "../cliJsonInput.js";
import { logCliCommand } from "../cliLogging.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
import { localPathStringSchema } from "../domain/localPath.js";
import { withCommandCancellation } from "./commandCancellation.js";
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
import { inspectAnalysisViewInputSchema } from "../domain/analysisView/analysisView.js";
/** Project selected views of completed analysis Evidence through the CLI. */
@@ -54,7 +59,12 @@ export const registerAnalysisViewCommands = (
),
),
};
const loaded = await readEvidenceBundle(parsed.data.path);
const loaded = await readEvidenceBundle(
parsed.data.path,
undefined,
undefined,
"get_evidence_bundle",
);
if (!loaded.ok)
return {
error: "Evidence bundle inspection failed",
@@ -75,34 +85,63 @@ export const registerAnalysisViewCommands = (
args: z.object({
inputJson: z.string().describe("Inline workflow JSON or JSON file path"),
}),
run: ({ args }) =>
logCliCommand(logger, CLI_COMMANDS.inspectAnalysisView, async () => {
const input = await parseCliJsonInput(
args.inputJson,
CLI_COMMANDS.inspectAnalysisView,
);
if (!input.ok) return input.error;
// An evidence-file path is resolved against the operator's working directory.
const value = resolveCliJsonPaths(input.value, [["source", "path"]]);
const parsed = inspectAnalysisViewInputSchema.safeParse(value);
if (!parsed.success)
return {
error: "Application workflow failed",
...projectAnalysisError(
analysisInputErrorFromIssues(
CLI_COMMANDS.inspectAnalysisView,
parsed.error.issues,
value,
),
),
};
const result = await inspectAnalysisViewValidatedWithFiles(parsed.data);
return result.ok
? jsonValueSchema.parse(result.value)
: {
options: z.object({
evidenceBundle: localPathStringSchema
.optional()
.describe(
"Read the exact retained-evidence source ID from this local Evidence bundle without reopening the target; omit for inline Evidence",
),
}),
run: ({ args, options }) =>
withCommandCancellation((signal) =>
logCliCommand(logger, CLI_COMMANDS.inspectAnalysisView, async () => {
const input = await parseCliJsonInput(
args.inputJson,
CLI_COMMANDS.inspectAnalysisView,
signal,
);
if (!input.ok) return input.error;
// An evidence-file path is resolved against the operator's working directory.
const value = resolveCliJsonPaths(input.value, [["source", "path"]]);
const parsed = inspectAnalysisViewInputSchema.safeParse(value);
if (!parsed.success)
return {
error: "Application workflow failed",
...projectAnalysisError(result.error),
...projectAnalysisError(
analysisInputErrorFromIssues(
CLI_COMMANDS.inspectAnalysisView,
parsed.error.issues,
value,
),
),
};
}),
const resources = new ArtifactResourceScope();
const bundlePath = options.evidenceBundle;
const result = await finishAnalysisCommand(
() =>
bundlePath === undefined
? inspectAnalysisViewValidatedWithFiles(
parsed.data,
undefined,
{ signal, resources },
)
: inspectAnalysisViewFromBundle(
parsed.data,
bundlePath,
resources,
signal,
),
resources,
ANALYSIS_VIEW_PROVIDER.id,
"inspect_analysis_view",
signal,
);
// Preserve the inline command's existing error label without copying
// the authenticated completed Evidence or its partial observation.
return bundlePath === undefined && "code" in result
? { error: "Application workflow failed", ...result }
: result;
}),
),
});
};
+6 -3
View File
@@ -9,6 +9,7 @@ import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import type { Result } from "../domain/result.js";
import { dispatchQueuedInterrupts } from "../process/queuedInterrupts.js";
/** Finish a one-shot CLI operation while retaining primary results through close. */
export const finishAnalysisCommand = async <
@@ -59,16 +60,18 @@ export const finishAnalysisCommand = async <
);
}
if (result.ok) cleanup.retainPartialObservation(result.value);
return projectAnalysisError(
result.ok
result = {
ok: false,
error: result.ok
? cleanup
: analysisErrorWithCleanupFailure(
result.error,
cleanup,
canonicalOperation,
),
);
};
}
await dispatchQueuedInterrupts();
if (result.ok && signal.aborted)
return projectAnalysisError(
new AnalysisCancelledError(canonicalOperation, {
+27 -6
View File
@@ -17,6 +17,8 @@ import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
import { registerProjectManagedApplicationGraph } from "./managedProjectGraphCommand.js";
import { managedMembersInputSchema } from "../contracts/managed/managedToolContracts.js";
import { localPathStringSchema } from "../domain/localPath.js";
import { withCommandCancellation } from "./commandCancellation.js";
export const registerManagedCommands = (
cli: CliInstance,
@@ -64,14 +66,33 @@ const registerInspectManagedMembers = (
type: managedMembersInputSchema.shape.type_names.describe(
"Inspect only members declared by this exact type full name, and the string literals they load, such as System.Threading.Monitor; a nested type is named by its bare name, which selects every nested type of that name (repeatable)",
),
detail: managedMembersInputSchema.shape.detail.describe(
"complete returns full Evidence (default); summary returns identity, selection, coverage, limitations and collection counts and requires --evidence-bundle",
),
evidenceBundle: localPathStringSchema
.optional()
.describe(
"Write complete parent Evidence to a new local bundle for later inspect-analysis-view calls; never replaces an existing path",
),
}),
run: ({ args, options }) =>
logCliCommand(logger, "inspect-managed-members", () =>
runProviderAnalysis(
args.path,
"inspect_managed_members",
options.type === undefined ? {} : { type_names: options.type },
logger,
withCommandCancellation((signal) =>
logCliCommand(logger, "inspect-managed-members", () =>
runProviderAnalysis(
args.path,
"inspect_managed_members",
options.type === undefined ? {} : { type_names: options.type },
logger,
signal,
{
...(options.detail === undefined
? {}
: { detail: options.detail }),
...(options.evidenceBundle === undefined
? {}
: { evidenceBundlePath: options.evidenceBundle }),
},
),
),
),
});