58fb372071
Add opt-in retained inventory and WASM Evidence views with exact nested output contracts and a small static WASM descriptor. Preserve old complete CLI/MCP workflows, producer choices, original authenticated Evidence and cleanup ownership. Validated with real public applications, genuine old Evidence migration, 123 focused assertions, 11 synchronized description checks and 42 installed-package WABT cases. Detailed generated experiment JSON stays outside the final tree; concise findings and reproduction inputs remain. Main-existing completion/package CI failures are separately attributed and left unchanged. Refs #2016 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import type { AnalysisError } from "../analysisErrorBase.js";
|
|
import { err, ok, type Result } from "../result.js";
|
|
import {
|
|
analysisViewInputError,
|
|
type AnalysisViewCoverage,
|
|
} from "./analysisView.js";
|
|
import { pageViewCoverage } from "./analysisViewCoverage.js";
|
|
|
|
const viewError = (message: string): AnalysisError =>
|
|
analysisViewInputError([
|
|
{ path: ["view"], reason: "invalid_value", message },
|
|
]);
|
|
|
|
/** Slice text by UTF-16 code units without losing a partial Unicode character. */
|
|
export const analysisTextPage = (
|
|
body: string,
|
|
offset: number,
|
|
limit: number,
|
|
label = "Pseudocode",
|
|
): Result<
|
|
{
|
|
readonly item: { readonly text: string; readonly unit: "utf16-code-units" };
|
|
readonly coverage: AnalysisViewCoverage;
|
|
},
|
|
AnalysisError
|
|
> => {
|
|
const start = Math.min(offset, body.length);
|
|
const high = (n: number) => n >= 0xd800 && n <= 0xdbff;
|
|
const low = (n: number) => n >= 0xdc00 && n <= 0xdfff;
|
|
if (
|
|
start > 0 &&
|
|
start < body.length &&
|
|
high(body.charCodeAt(start - 1)) &&
|
|
low(body.charCodeAt(start))
|
|
)
|
|
return err(viewError(`${label} offset splits a UTF-16 surrogate pair.`));
|
|
let end = Math.min(start + limit, body.length);
|
|
if (
|
|
end > start &&
|
|
end < body.length &&
|
|
high(body.charCodeAt(end - 1)) &&
|
|
low(body.charCodeAt(end))
|
|
)
|
|
end--;
|
|
if (end === start && start < body.length)
|
|
return err(
|
|
viewError(
|
|
`Increase ${label.toLowerCase()} limit to include the next complete Unicode character.`,
|
|
),
|
|
);
|
|
return ok({
|
|
item: { text: body.slice(start, end), unit: "utf16-code-units" },
|
|
coverage: pageViewCoverage(start, end - start, body.length),
|
|
});
|
|
};
|