"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneCommandDescriptor = cloneCommandDescriptor;
exports.projectCommandDescriptorSearchMatch = projectCommandDescriptorSearchMatch;
exports.projectCommandDescriptorInspection = projectCommandDescriptorInspection;
exports.projectCommandDescriptorInventoryFields = projectCommandDescriptorInventoryFields;
function cloneCommandDescriptor(descriptor) {
    return { ...descriptor };
}
function projectCommandDescriptorSearchMatch(descriptor, score) {
    const callable = descriptor.availability === "callable";
    return Object.freeze({
        command: descriptor.command,
        summary: descriptor.summary,
        score,
        availability: descriptor.availability,
        callable,
        capability: descriptor.capability,
        artifactFamily: descriptor.artifactFamily,
        authorization: descriptor.authorization,
        writeCapable: callable ? descriptor.writeCapable : false,
        mutationPosture: callable ? descriptor.mutationPosture : "non-writing",
        exampleArgv: callable ? descriptor.examples[0]?.argv ?? [] : []
    });
}
function projectCommandDescriptorInspection(descriptor, options = {}) {
    if (descriptor.availability === "callable" && options.forceNonCallable !== true) {
        return cloneCommandDescriptor(descriptor);
    }
    return Object.freeze({
        ...descriptor,
        writeCapable: false,
        mutationPosture: "non-writing",
        effects: Object.freeze({
            filesystem: "none",
            scope: "inspection-only command metadata",
            network: "none",
            hostState: "none",
            destructive: false,
            interactive: false
        }),
        authorization: "read",
        confirmation: "none",
        selectionRequired: false,
        examples: Object.freeze([]),
        transition: Object.freeze({
            id: `${descriptor.command.replace(/\s+/gu, ".")}:noncallable-inspection`,
            kind: "state-observed",
            expected: "Command availability is observed without execution.",
            expectedPostconditions: Object.freeze([{
                    id: "availability-inspected",
                    description: "The command availability is inspected without claiming execution or mutation."
                }])
        })
    });
}
function projectCommandDescriptorInventoryFields(descriptor) {
    return {
        availability: descriptor?.availability ?? null,
        writeCapable: descriptor?.writeCapable ?? null,
        capability: descriptor?.capability ?? null,
        artifactFamily: descriptor?.artifactFamily ?? null,
        mutationPosture: descriptor?.mutationPosture ?? null,
        coordinationScope: descriptor?.coordinationScope ?? null,
        targetPathPosture: descriptor?.targetPathPosture ?? null,
        destinationPosture: descriptor?.destinationPosture ?? null,
        summary: descriptor?.summary ?? null,
        noWriteBoundary: descriptor?.noWriteBoundary ?? null,
        descriptorSource: descriptor === null ? null : "command-descriptor-registry",
        descriptorAliases: descriptor?.aliases ?? [],
        descriptorInputs: descriptor?.inputs ?? [],
        validationNotes: descriptor?.validationNotes ?? [],
        examples: descriptor?.examples ?? [],
        effects: descriptor?.effects ?? null,
        authorization: descriptor?.authorization ?? null,
        confirmation: descriptor?.confirmation ?? null,
        idempotency: descriptor?.idempotency ?? null,
        transition: descriptor?.transition ?? null
    };
}
