2026-10-07 12:46:13 +08:00
import { z } from "zod" ;
2026-10-07 17:16:58 +08:00
import { digestSchema } from "../digests.js" ;
2026-10-07 12:46:13 +08:00
import { analyzeJavaScriptApplicationInputSchema } from "./javascriptApplicationAnalysis.js" ;
2026-10-09 06:47:48 +08:00
import { localPathStringSchema } from "../localPath.js" ;
2026-10-07 12:46:13 +08:00
2026-10-11 18:39:49 +08:00
/** Recover derived readable modules from explicitly selected local scripts. */
2026-10-07 12:46:13 +08:00
export const javascriptRecoveryInputSchema = z . strictObject ({
2026-10-09 06:47:48 +08:00
path : localPathStringSchema.describe (
"Absolute path to a UTF-8 JavaScript file; never executed" ,
),
2026-10-11 18:39:49 +08:00
additional_paths : z
. array ( localPathStringSchema )
. max ( 16 )
. optional ()
. describe (
"Additional absolute UTF-8 JavaScript files recovered together with path; each is snapshotted separately so imports can resolve across related chunks. All inputs share a 64 MiB total budget" ,
),
2026-10-09 06:47:48 +08:00
output_directory : localPathStringSchema.describe (
"Absolute absent output directory; parent must exist" ,
),
2026-10-07 12:46:13 +08:00
extraction_mode : z
. enum ([ "structural" , "heuristic" , "inspection" ])
. default ( "structural" )
. describe (
"Structural module boundaries, heuristic fallback, or finer inspection-only regions" ,
),
rewrite_level : z
. enum ([ "minimal" , "standard" , "aggressive" ])
. default ( "standard" )
. describe (
"Upstream syntax recovery level; runtime equivalence remains unverified" ,
),
});
const fileSchema = z . strictObject ({
path : z.string (). min ( 1 ),
sha256 : digestSchema ,
bytes : z.number (). int (). nonnegative (),
});
const rangeSchema = z . strictObject ({
start : z.number (). int (). nonnegative (),
end : z.number (). int (). nonnegative (),
});
2026-10-11 18:39:49 +08:00
const sourceSchema = fileSchema . extend ({
snapshot_path : z.string (). min ( 1 ),
published_copy : fileSchema ,
});
2026-10-07 12:46:13 +08:00
/** Complete published artifacts and exact producer provenance for source recovery. */
export const javascriptRecoveryResultSchema = z . strictObject ({
2026-10-11 18:39:49 +08:00
source : sourceSchema ,
additional_sources : z.array ( sourceSchema ). optional (),
2026-10-07 12:46:13 +08:00
engine : z.strictObject ({
id : z.string (). min ( 1 ),
version : z.string (). min ( 1 ),
executable : fileSchema ,
audited_source_revision : z.string (). min ( 1 ),
executed_source_revision : z.string (). nullable (),
}),
options : z.strictObject ({
extraction_mode :
javascriptRecoveryInputSchema.shape.extraction_mode.removeDefault (),
rewrite_level :
javascriptRecoveryInputSchema.shape.rewrite_level.removeDefault (),
}),
status : z.enum ([ "complete" , "partial" ]),
detected_formats : z.array ( z . string ()),
reported_safety : z.string (),
reported_strategy : z.string (),
reported_format : z.string (),
total : z.number (). int (). nonnegative (),
failed : z.number (). int (). nonnegative (),
modules : z.array (
z . strictObject ({
reported_filename : z.string (). min ( 1 ),
reported_status : z.string (). min ( 1 ),
artifact : fileSchema ,
source_map : fileSchema.nullable (),
provenance : z.strictObject ({
reported_input : z.string (),
original_path : z.string (),
original_sha256 : digestSchema ,
extraction : z.string (),
byte_ranges : z.array ( rangeSchema ),
context_byte_ranges : z.array ( rangeSchema ),
range_semantics : z.literal ( "half-open-utf8-bytes" ),
}),
}),
),
warnings : z.array (
z . strictObject ({
filename : z.string (),
kind : z.string (),
is_error : z.boolean (),
message : z.string (),
}),
),
report : fileSchema ,
provenance : fileSchema ,
manifest : fileSchema ,
analysis_input : z
. strictObject ({
input_path : analyzeJavaScriptApplicationInputSchema.shape.input_path ,
format : z.literal ( "directory" ),
})
. nullable (),
runtime_equivalence : z.literal ( "unknown" ),
limitations : z.array ( z . string ()),
});
export type JavaScriptRecoveryInput = z . output <
typeof javascriptRecoveryInputSchema
> ;
export type JavaScriptRecoveryResult = z . output <
typeof javascriptRecoveryResultSchema
> ;
2026-10-11 05:16:30 +08:00
/** Completed publication retained when cleanup fails after durable commit. */
export interface JavaScriptRecoveryPartialObservation {
readonly kind : "javascript-recovery" ;
readonly result : JavaScriptRecoveryResult ;
}