feat(artifacts): inspect and extract Godot PCK with retained facts (#3634)

* feat(artifacts): read Godot PCK packs

Add a Godot Engine PCK artifact reader for standalone packs and packs
embedded behind an executable trailer (formats 2 and 3). Members are
uncompressed byte ranges verified against their declared MD5 on read.

Encrypted directories, sparse bundles, patch removal entries, unknown
flags and format 1 fail closed as unavailable; encrypted members are
reported without being read. inspect-artifact and extract-artifact
recognize standalone packs by their GDPC magic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(artifacts): bound Godot PCK metadata and own member streams

Cap member paths at 4096 bytes and the retained directory at 64 MiB
before allocation. Read members with positional chunk reads through
pipeline so cancellation is typed, abandoned consumers release their
source, and the shared descriptor stays reader-owned. Retain the root
descriptor for godot-pck inventory, as for ZIP and universal Mach-O.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(artifacts): complete Godot PCK facts, integrity and selected views

* fix(artifacts): preserve atomic-root inventory Evidence

* fix(artifacts): bound aggregate PCK member expansion

---------

Co-authored-by: Samucahub <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: gensokyo-dev <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-20 09:53:53 +08:00
1 parent 833136507d
commit 5fa4defcbc
58 files changed
+3298 -361

No files matched your search

+59 -23
View File
@@ -1,7 +1,8 @@
import { z } from "incur";
import type { Evidence } from "../domain/evidence.js";
import { parseEvidence, type Evidence } from "../domain/evidence.js";
import type { JsonValue } from "../domain/jsonValue.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import type { AnalysisError } from "../domain/analysisErrorBase.js";
import type { AnalysisErrorProjection } from "../domain/analysisErrorProjection.js";
import type { Result } from "../domain/result.js";
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
import { createEvidenceBundle } from "../domain/evidenceBundle.js";
@@ -25,20 +26,42 @@ export const analysisEvidenceDeliveryOptions = {
),
};
const isEvidence = (
value: Evidence | AnalysisErrorProjection,
): value is Evidence => "evidence_id" in value && "normalized_result" in value;
const isEvidence = (value: JsonValue): value is Evidence =>
typeof value === "object" &&
value !== null &&
!Array.isArray(value) &&
"evidence_id" in value &&
"normalized_result" in value;
/** One-shot delivery owns report publication; analysis keeps its own cleanup owner. */
export const deliverCliAnalysisEvidence = async (input: {
readonly run: () => Promise<Result<Evidence, AnalysisError>>;
readonly service: { close(): Promise<void> };
interface CliEvidenceDelivery {
readonly providerId: string;
readonly operation: string;
readonly signal: AbortSignal;
readonly detail: "complete" | "summary";
readonly evidenceOutput: string | undefined;
}) => {
}
export const cliEvidenceDeliveryInputError = (
input: Pick<CliEvidenceDelivery, "detail" | "evidenceOutput" | "operation">,
): AnalysisInputError | undefined =>
input.detail === "summary" && input.evidenceOutput === undefined
? new AnalysisInputError(input.operation, undefined, [
{
path: ["evidence_output"],
reason: "invalid_value",
message:
"Summary delivery requires --evidence_output so complete source Evidence remains available.",
},
])
: undefined;
/** One-shot delivery owns report publication; analysis keeps its own cleanup owner. */
export const deliverCliAnalysisEvidence = async (
input: CliEvidenceDelivery & {
readonly run: () => Promise<Result<Evidence, AnalysisError>>;
readonly service: { close(): Promise<void> };
},
) => {
const {
run,
service,
@@ -48,19 +71,10 @@ export const deliverCliAnalysisEvidence = async (input: {
detail,
evidenceOutput,
} = input;
if (detail === "summary" && evidenceOutput === undefined)
const inputError = cliEvidenceDeliveryInputError(input);
if (inputError !== undefined)
return finishAnalysisCommand(
async () => ({
ok: false,
error: new AnalysisInputError(operation, undefined, [
{
path: ["evidence_output"],
reason: "invalid_value",
message:
"Summary delivery requires --evidence_output so complete source Evidence remains available.",
},
]),
}),
async () => ({ ok: false, error: inputError }),
service,
providerId,
operation,
@@ -73,7 +87,29 @@ export const deliverCliAnalysisEvidence = async (input: {
operation,
signal,
);
if (!isEvidence(complete) || evidenceOutput === undefined) return complete;
return publishCliAnalysisEvidence(complete, {
providerId,
operation,
signal,
detail,
evidenceOutput,
});
};
/** Publish already finalized CLI analysis without opening a second provider/session. */
export const publishCliAnalysisEvidence = async (
value: JsonValue,
input: CliEvidenceDelivery,
) => {
const { providerId, operation, signal, detail, evidenceOutput } = input;
if (!isEvidence(value)) return value;
const complete = parseEvidence(value);
const inputError = cliEvidenceDeliveryInputError(input);
if (inputError !== undefined) {
inputError.retainPartialObservation(complete);
return projectAnalysisError(inputError);
}
if (evidenceOutput === undefined) return complete;
const resources = new ArtifactResourceScope();
let receipt: { readonly path: string; readonly bytes: number } | undefined;
const delivered = await finishAnalysisCommand(
+28 -8
View File
@@ -1,3 +1,11 @@
import {
analysisEvidenceDeliveryOptions,
cliEvidenceDeliveryInputError,
publishCliAnalysisEvidence,
} from "./analysisEvidenceDelivery.js";
import { withCommandCancellation } from "./commandCancellation.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { ARTIFACT_GRAPH_PROVIDER } from "../application/InvestigationProviders.js";
import { z } from "incur";
import type { DirectAnalysis } from "../composition/directAnalysis.js";
@@ -228,6 +236,7 @@ const registerInspectionCommand = (
path: z.string().min(1).describe("Application or package path"),
}),
options: z.object({
...analysisEvidenceDeliveryOptions,
integrityPolicy: z
.enum(["fail", "record-and-continue"])
.default("fail")
@@ -235,14 +244,25 @@ const registerInspectionCommand = (
}),
run: ({ args, options }) =>
logCliCommand(logger, "inspect-artifact", () =>
runProviderAnalysis(
args.path,
"inspect_artifact",
{
integrity_policy: options.integrityPolicy,
},
logger,
),
withCommandCancellation(async (signal) => {
const delivery = {
providerId: ARTIFACT_GRAPH_PROVIDER.id,
operation: "inspect_artifact",
signal,
detail: options.detail,
evidenceOutput: options.evidence_output,
};
const inputError = cliEvidenceDeliveryInputError(delivery);
if (inputError !== undefined) return projectAnalysisError(inputError);
const complete = await runProviderAnalysis(
args.path,
"inspect_artifact",
{ integrity_policy: options.integrityPolicy },
logger,
signal,
);
return publishCliAnalysisEvidence(complete, delivery);
}),
),
});
};