feat(mcp): add opt-in paging for retained unknown heads
Keep complete default delivery and exact filters. Select stable ID pages at the ledger owner before cloning, return filtered totals and continuation offsets, and preserve detached records through the shared session port. Validate public MCP paging, safe-integer edges, snapshot replay and converted JSON Schemas. Document the bounded Flameox workflow comparison and its token/CPU/latency measurement limits; no real model performance claim.
This commit is contained in:
@@ -19,6 +19,10 @@ import type {
|
||||
UnknownStatus,
|
||||
UpdateUnknownInput,
|
||||
} from "../../domain/residualUnknown.js";
|
||||
import type {
|
||||
UnknownPage,
|
||||
UnknownQuery,
|
||||
} from "../investigation/InvestigationRecordPort.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import type {
|
||||
AnalysisExecution,
|
||||
@@ -350,6 +354,10 @@ export abstract class BinarySessionRecords {
|
||||
return this.#records.listUnknowns(filters);
|
||||
}
|
||||
|
||||
listUnknownsPage(query: UnknownQuery = {}): UnknownPage {
|
||||
return this.#records.listUnknownsPage(query);
|
||||
}
|
||||
|
||||
verifyUnknownResolution(unknownId: string): Result<
|
||||
{
|
||||
readonly valid: boolean;
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
} from "../../domain/residualUnknown.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
||||
import type { UnknownPage, UnknownQuery } from "./InvestigationRecordPort.js";
|
||||
|
||||
type EvidenceLedgerFailure = EvidenceIntegrityError;
|
||||
type RecordResult = Result<"added" | "duplicate", EvidenceLedgerFailure>;
|
||||
@@ -326,18 +327,39 @@ export class EvidenceLedger {
|
||||
readonly domain?: string;
|
||||
} = {},
|
||||
): ResidualUnknown[] {
|
||||
return [...this.#unknownHeads.values()]
|
||||
return this.listUnknownsPage(filters).items;
|
||||
}
|
||||
|
||||
/** Select a stable page of current heads before detaching record payloads. */
|
||||
listUnknownsPage(query: UnknownQuery = {}): UnknownPage {
|
||||
const offset = query.offset ?? 0;
|
||||
const matching = [...this.#unknownHeads.values()]
|
||||
.filter(
|
||||
(unknown) =>
|
||||
(filters.status === undefined || unknown.status === filters.status) &&
|
||||
(filters.severity === undefined ||
|
||||
unknown.severity === filters.severity) &&
|
||||
(filters.domain === undefined || unknown.domain === filters.domain),
|
||||
(query.status === undefined || unknown.status === query.status) &&
|
||||
(query.severity === undefined ||
|
||||
unknown.severity === query.severity) &&
|
||||
(query.domain === undefined || unknown.domain === query.domain),
|
||||
)
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.unknown_id, right.unknown_id),
|
||||
)
|
||||
.map((unknown) => structuredClone(unknown));
|
||||
);
|
||||
const start = Math.min(offset, matching.length);
|
||||
const end =
|
||||
query.limit === undefined
|
||||
? undefined
|
||||
: start + Math.min(query.limit, matching.length - start);
|
||||
const page = matching.slice(start, end);
|
||||
const nextOffset =
|
||||
offset <= matching.length && start + page.length < matching.length
|
||||
? start + page.length
|
||||
: null;
|
||||
return {
|
||||
items: page.map((unknown) => structuredClone(unknown)),
|
||||
total: matching.length,
|
||||
offset,
|
||||
next_offset: nextOffset,
|
||||
};
|
||||
}
|
||||
|
||||
/** Return current resolution validity; imported invalid states are rejected. */
|
||||
|
||||
@@ -38,6 +38,21 @@ export interface EvidenceUnknownWriter {
|
||||
): Result<ResidualUnknown | null, AnalysisError>;
|
||||
}
|
||||
|
||||
export type UnknownPage = {
|
||||
readonly items: ResidualUnknown[];
|
||||
readonly total: number;
|
||||
readonly offset: number;
|
||||
readonly next_offset: number | null;
|
||||
};
|
||||
|
||||
export interface UnknownQuery {
|
||||
readonly status?: UnknownStatus;
|
||||
readonly severity?: ResidualUnknown["severity"];
|
||||
readonly domain?: string;
|
||||
readonly offset?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
|
||||
/** Optimistic Unknown revisions and consistency verification. */
|
||||
export interface UnknownRegistryPort {
|
||||
recordUnknown(
|
||||
@@ -51,6 +66,7 @@ export interface UnknownRegistryPort {
|
||||
readonly severity?: ResidualUnknown["severity"];
|
||||
readonly domain?: string;
|
||||
}): ResidualUnknown[];
|
||||
listUnknownsPage(query?: UnknownQuery): UnknownPage;
|
||||
verifyUnknownResolution(unknownId: string): Result<
|
||||
{
|
||||
readonly valid: boolean;
|
||||
|
||||
@@ -19,6 +19,8 @@ import type {
|
||||
EvidenceWriter,
|
||||
EvidenceUnknownWriter,
|
||||
UnknownRegistryPort,
|
||||
UnknownPage,
|
||||
UnknownQuery,
|
||||
} from "./InvestigationRecordPort.js";
|
||||
|
||||
/** One investigation's validated record owner, independent of binary execution. */
|
||||
@@ -124,6 +126,10 @@ export class InvestigationRecords
|
||||
return this.#evidence.listUnknowns(filters);
|
||||
}
|
||||
|
||||
listUnknownsPage(query: UnknownQuery = {}): UnknownPage {
|
||||
return this.#evidence.listUnknownsPage(query);
|
||||
}
|
||||
|
||||
/** Verify registry consistency without asserting the answer is true. */
|
||||
verifyUnknownResolution(unknownId: string): Result<
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user