"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createManifestUpdateCommand = createManifestUpdateCommand;
const runtime_contract_1 = require("../../../lib/runtime/runtime-contract");
const metadata_update_operation_1 = require("../metadata-update-operation");
async function createManifestUpdateCommand() {
    const { Command } = await import("commander");
    const command = new Command("update");
    command
        .description("Apply helper-backed metadata field updates to an existing prompt/template manifest.")
        .requiredOption("--manifest <path>", "Repository-relative manifest path to update.")
        .option("--field <key=value>", "Direct intended metadata update. Repeat for multiple fields. Use replace:<path>=<json-object> for guarded entry replacement.", collectFieldAssignment, [])
        .action((_, commandInstance) => {
        const repositoryContext = (0, runtime_contract_1.createRepositoryContext)((0, runtime_contract_1.detectRepositoryRoot)(), false);
        (0, metadata_update_operation_1.executeMetadataUpdateOperation)({
            commandName: "manifest update",
            write: true,
            commandInstance,
            repositoryRoot: repositoryContext.root,
            detectionSource: repositoryContext.detectionSource,
            artifactPathOption: "manifest",
            expectedFamilies: ["prompt-manifest", "template-manifest"]
        });
    });
    return command;
}
function collectFieldAssignment(value, previous) {
    previous.push(value);
    return previous;
}
