"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.COMMAND_CAPABILITY_REGISTRY = exports.COMMAND_DESCRIPTOR_REGISTRY = exports.PLANNING_ADVANCEMENT_INTENT_PHRASES = exports.SOURCE_SPEC_REVIEW_REFINEMENT_INTENT_PHRASES = exports.SOURCE_SPEC_ONLY_INTENT_PHRASES = exports.NO_WRITE_EVIDENCE_SEVERITIES = exports.COMMAND_CAPABILITY_TOKENS = void 0;
exports.normalizeCommandCapability = normalizeCommandCapability;
exports.normalizeCommandCapabilityRegistry = normalizeCommandCapabilityRegistry;
exports.findCommandCapability = findCommandCapability;
exports.getCommandDescriptorRegistry = getCommandDescriptorRegistry;
exports.getRegisteredCommandDescriptor = getRegisteredCommandDescriptor;
exports.getCommandCapabilityRegistry = getCommandCapabilityRegistry;
exports.getRegisteredCommandCapability = getRegisteredCommandCapability;
exports.createNoWriteBoundaryEvidence = createNoWriteBoundaryEvidence;
exports.createNoWriteRecommendation = createNoWriteRecommendation;
exports.createNoWriteFindingEvidenceDetails = createNoWriteFindingEvidenceDetails;
exports.classifySourceSpecLifecycleIntent = classifySourceSpecLifecycleIntent;
exports.createSourceSpecLifecycleGateEvidenceDetails = createSourceSpecLifecycleGateEvidenceDetails;
const command_descriptors_1 = require("./command-descriptors");
const command_descriptor_projections_1 = require("./command-descriptor-projections");
const command_availability_1 = require("./command-availability");
exports.COMMAND_CAPABILITY_TOKENS = [
    "read",
    "validation",
    "review",
    "navigation",
    "list",
    "inspection",
    "scaffold",
    "update",
    "build",
    "sync",
    "migration",
    "install",
    "materialize",
    "release",
    "cleanup"
];
exports.NO_WRITE_EVIDENCE_SEVERITIES = ["blocker", "warning", "informational"];
exports.SOURCE_SPEC_ONLY_INTENT_PHRASES = [
    "create spec",
    "capture spec",
    "draft spec",
    "revise spec",
    "update spec"
];
exports.SOURCE_SPEC_REVIEW_REFINEMENT_INTENT_PHRASES = [
    "review",
    "navigation",
    "second pass",
    "harden",
    "hardening",
    "improve",
    "improvement",
    "completeness"
];
exports.PLANNING_ADVANCEMENT_INTENT_PHRASES = [
    "plan from spec",
    "create slice",
    "start planning",
    "create next planning layer",
    "scaffold slice"
];
const READ_ONLY_BOUNDARY = "Reports local command evidence only and writes no files.";
const DEFAULT_SOURCE_SPEC_SURFACE = "selected source spec and spec registry entry";
const SOURCE_SPEC_PLANNING_RECOVERY_COMMAND = "day-shift slice new --spec-id <id>";
const SOURCE_SPEC_PLANNING_RECOVERY_WORKFLOW = ".day-shift/workflows/02-plan-from-spec.md";
function readCommand(command, capability, artifactFamily, summary, noWriteBoundary = READ_ONLY_BOUNDARY) {
    return (0, command_descriptors_1.defineCommandDescriptor)({
        command,
        capability,
        summary,
        writeCapable: false,
        artifactFamily,
        noWriteBoundary
    });
}
function writeCommand(command, capability, artifactFamily, destinationPosture, targetPathPosture, coordinationScope, mutationPosture, summary) {
    return (0, command_descriptors_1.defineCommandDescriptor)({
        command,
        capability,
        summary,
        writeCapable: true,
        artifactFamily,
        destinationPosture,
        targetPathPosture,
        coordinationScope,
        mutationPosture
    });
}
function withInvocation(descriptor, inputs, argv) {
    return {
        ...descriptor,
        inputs,
        examples: [{ description: descriptor.summary, argv }]
    };
}
const BASE_COMMAND_DESCRIPTOR_REGISTRATIONS = [
    readCommand("agent", "read", "agent-orientation", "Reports automation-agent orientation, command boundaries, and lifecycle guidance."),
    readCommand("agent orient", "read", "agent-orientation", "Runs the full agent orientation alias."),
    readCommand("agent remind", "read", "agent-orientation", "Runs the correction-focused agent reminder alias."),
    withInvocation({
        ...readCommand("agent context", "navigation", "agent-orientation", "Returns bounded context for one explicit or stored planning-artifact selection."),
        coordinationScope: "selected-artifact",
        selectionRequired: true
    }, [
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional existing repository-relative planning artifact." },
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local selection session name." },
        { kind: "option", name: "intent", required: false, variadic: false, defaultValue: null, validation: "Optional printable intent up to 256 characters." },
        { kind: "option", name: "includeContextPack", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Boolean flag enabling the default-capped relevance-ranked context pack." },
        { kind: "option", name: "contextPackBudget", valueType: "integer", required: false, variadic: false, defaultValue: null, validation: "Integer from 1024 to 65536; requires includeContextPack." }
    ], ["day-shift", "agent", "context", "--artifact", ".day-shift/planning/example/task-definition.md", "--format", "json", "--detail", "compact"]),
    readCommand("about", "inspection", "configuration", "Reports runtime and package context."),
    readCommand("completion", "inspection", "completion", "Prints shell completion setup guidance."),
    readCommand("completion complete", "inspection", "completion", "Resolves shell completion candidates without executing target commands."),
    writeCommand("completion install", "install", "completion", "local-install-target", "shell completion integration file", "local-installation", "installs-local-files", "Installs Day Shift-managed shell completion integration."),
    readCommand("completion script", "inspection", "completion", "Prints a sourceable shell completion script."),
    writeCommand("completion uninstall", "cleanup", "completion", "local-install-target", "shell completion integration file", "local-installation", "prunes-generated-output", "Removes Day Shift-managed shell completion integration."),
    readCommand("commands", "inspection", "configuration", "Groups command inventory and command-surface metadata reports."),
    readCommand("commands inventory", "inspection", "configuration", "Reports callable command inventory merged with command capability metadata."),
    {
        ...readCommand("commands search", "navigation", "configuration", "Searches authoritative command descriptors with bounded deterministic results."),
        inputs: [
            { kind: "argument", name: "query", required: false, variadic: false, defaultValue: null, validation: "Shell query is optional at parse time; shell or structured input must supply a non-empty query." },
            { kind: "option", name: "maxResults", required: false, variadic: false, defaultValue: 10, validation: "Integer from 1 to 50." },
            { kind: "option", name: "includeNoncallable", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Boolean inspection flag for descriptors outside the executable intersection." }
        ],
        examples: [{ description: "Search command descriptors by intent or posture.", argv: ["day-shift", "commands", "search", "planning", "--format", "json"] }]
    },
    {
        ...readCommand("commands describe", "inspection", "configuration", "Describes one exact authoritative command descriptor."),
        inputs: [{ kind: "argument", name: "command", required: false, variadic: true, defaultValue: null, validation: "Shell command path is optional at parse time; shell or structured input must supply an exact registered command." }],
        examples: [{ description: "Describe one command descriptor.", argv: ["day-shift", "commands", "describe", "task", "update", "--format", "json"] }]
    },
    {
        ...readCommand("commands manifest", "inspection", "configuration", "Generates native tool descriptors from the authoritative command registry."),
        inputs: [
            { kind: "argument", name: "command", required: false, variadic: true, defaultValue: null, validation: "Optional exact registered command path." },
            { kind: "option", name: "includeNoncallable", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Boolean inspection flag for descriptors outside the executable intersection." }
        ],
        examples: [{ description: "Generate one native tool descriptor.", argv: ["day-shift", "commands", "manifest", "task", "update", "--format", "json"] }]
    },
    readCommand("commands validate", "validation", "configuration", "Validates authoritative descriptors against the live command tree and generated tool manifest."),
    readCommand("config", "inspection", "configuration", "Reports resolved Day Shift configuration."),
    readCommand("config get", "inspection", "configuration", "Shows resolved configuration values."),
    readCommand("config inventory", "inspection", "configuration", "Reports catalog-backed configuration inventory without writing files."),
    writeCommand("config set", "update", "configuration", "workspace-metadata", ".day-shift local configuration", "workspace", "updates-selected-artifact", "Sets writable configuration values."),
    withInvocation(readCommand("doctor", "inspection", "doctor", "Reports repository-wide or explicitly scoped read-only workspace health findings."), [
        { kind: "option", name: "runtimeOnly", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Mutually exclusive runtime/setup-only scope selector." },
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Mutually exclusive existing repository-relative planning Markdown artifact." },
        { kind: "option", name: "planningDirectory", required: false, variadic: false, defaultValue: null, validation: "Mutually exclusive existing repository-relative directory inside the configured planning root." },
        { kind: "option", name: "scanSurface", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Mutually exclusive bounded read-only workspace scan-surface selector." },
        { kind: "option", name: "scanPath", required: false, variadic: false, defaultValue: null, validation: "Existing repository-relative directory; requires scanSurface." },
        { kind: "option", name: "repositoryAudit", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Explicit repository-wide audit selector; also the default when no selector is supplied, or a deeper budget modifier for --scan-surface." },
        { kind: "option", name: "action", required: false, variadic: false, defaultValue: null, validation: "Optional exact authoritative command descriptor identity used to classify current-action blockers." }
    ], ["day-shift", "doctor", "--runtime-only", "--format", "json"]),
    writeCommand("ignore", "install", "ignore", "local-install-target", ".gitignore or local ignore destination", "local-installation", "installs-local-files", "Installs Day Shift ignore rules."),
    writeCommand("ignore install", "install", "ignore", "local-install-target", ".gitignore or local ignore destination", "local-installation", "installs-local-files", "Installs canonical Day Shift local-only ignore entries."),
    withInvocation(readCommand("ignore explain", "inspection", "ignore", "Explains the canonical ignore-policy decision and winning evidence for one workspace-relative path."), [
        { kind: "argument", name: "path", required: true, variadic: false, defaultValue: null, validation: "Workspace-relative path that must remain inside the effective workspace." },
        { kind: "option", name: "include", required: false, variadic: true, defaultValue: [], validation: "Repeatable highest-precedence inclusion override pattern." },
        { kind: "option", name: "exclude", required: false, variadic: true, defaultValue: [], validation: "Repeatable highest-precedence exclusion override pattern." },
        { kind: "option", name: "ignoreFile", required: false, variadic: false, defaultValue: null, validation: "Optional workspace-relative ignore-file evidence path." }
    ], ["day-shift", "ignore", "explain", "src/index.ts", "--format", "json"]),
    readCommand("ignore integration", "inspection", "ignore", "Groups target-specific ignore integration preview and explicit apply actions."),
    withInvocation(readCommand("ignore integration preview", "inspection", "ignore", "Previews exact target-specific ignore mutations without writing editor settings or Day Shift state."), [
        { kind: "option", name: "target", required: true, variadic: false, defaultValue: null, validation: "Supported target token: vscode." }
    ], ["day-shift", "ignore", "integration", "preview", "--target", "vscode", "--format", "json"]),
    withInvocation(writeCommand("ignore integration apply", "update", "ignore", "selected-existing-artifact", ".vscode/settings.json", "selected-artifact", "updates-selected-artifact", "Applies previewed target-specific ignore mutations with explicit preconditions and recovery evidence."), [
        { kind: "option", name: "target", required: true, variadic: false, defaultValue: null, validation: "Supported target token: vscode." },
        { kind: "option", name: "policyId", required: true, variadic: false, defaultValue: null, validation: "Exact policy identity from preview." },
        { kind: "option", name: "preconditionSha256", required: true, variadic: false, defaultValue: null, validation: "Exact lowercase SHA-256 from preview." },
        { kind: "option", name: "preconditionBytes", required: true, variadic: false, defaultValue: null, validation: "Exact target byte length from preview." },
        { kind: "option", name: "preconditionExists", required: true, variadic: false, defaultValue: null, validation: "Exact target existence boolean from preview." }
    ], ["day-shift", "ignore", "integration", "apply", "--target", "vscode", "--policy-id", "ignore-policy-v1", "--precondition-sha256", "<sha256>", "--precondition-bytes", "<bytes>", "--precondition-exists", "<boolean>", "--format", "json"]),
    writeCommand("init", "scaffold", "configuration", "canonical-artifact", ".day-shift/ workspace scaffold", "workspace", "creates-artifacts", "Initializes a Day Shift workspace."),
    readCommand("license", "inspection", "license", "Groups license install, status, and reminder cleanup surfaces."),
    writeCommand("license cleanup-reminders", "cleanup", "license", "derived-state", "license reminder state", "workspace", "prunes-generated-output", "Cleans obsolete license reminder state."),
    writeCommand("license install", "install", "license", "local-install-target", "local license file", "local-installation", "installs-local-files", "Installs a Day Shift license locally."),
    readCommand("license status", "inspection", "license", "Inspects local license status and guidance."),
    readCommand("link", "inspection", "validation", "Groups trace-link lifecycle disposition management surfaces."),
    readCommand("link disposition", "inspection", "validation", "Groups trace-link disposition read and write surfaces."),
    writeCommand("link disposition add", "update", "validation", "derived-state", ".day-shift/state/trace-link-dispositions.json", "workspace", "updates-derived-state", "Creates trace-link lifecycle disposition records."),
    writeCommand("link disposition apply", "migration", "validation", "workspace-metadata", "planning trace fields and disposition storage", "workspace", "applies-migration", "Applies migrated trace-link disposition updates."),
    writeCommand("link disposition delete", "update", "validation", "derived-state", ".day-shift/state/trace-link-dispositions.json", "workspace", "updates-derived-state", "Deletes trace-link lifecycle disposition records."),
    readCommand("link disposition list", "inspection", "validation", "Lists trace-link disposition records without writing files."),
    readCommand("link disposition preview", "validation", "validation", "Previews affected planning trace links for recorded dispositions without writing files."),
    readCommand("link disposition show", "inspection", "validation", "Shows one trace-link disposition record without writing files."),
    writeCommand("link disposition update", "update", "validation", "derived-state", ".day-shift/state/trace-link-dispositions.json", "workspace", "updates-derived-state", "Updates trace-link lifecycle disposition records."),
    withInvocation(writeCommand("link materialize", "materialize", "planning", "selected-existing-artifact", "selected slice, phase, milestone, task, summary, reconciliation, or planning directory Markdown body references", "selected-artifact", "updates-selected-artifact", "Materializes validated local Markdown body references as clickable navigation links."), [
        { kind: "option", name: "scope", required: false, variadic: false, defaultValue: "planning", validation: "Currently planning." },
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional repository-relative selected Markdown artifact or directory; required for write execution." },
        { kind: "option", name: "dryRun", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Preview candidates without writing." },
        { kind: "option", name: "write", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Apply safe selected-artifact materialization." },
        { kind: "option", name: "format", required: false, variadic: false, defaultValue: "text", validation: "text or json." }
    ], ["day-shift", "link", "materialize", "--dry-run", "--artifact", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    readCommand("spec", "inspection", "spec-registry", "Groups spec registry read and write surfaces."),
    readCommand("spec source", "inspection", "spec-registry", "Groups append-only spec source transition surfaces."),
    withInvocation({
        ...writeCommand("spec source add", "update", "spec-registry", "selected-existing-artifact", ".day-shift/specs/index.json", "selected-family", "updates-selected-artifact", "Appends the current source to history and atomically installs a new source reference."),
        semantics: {
            conditionalInputs: [],
            dependentInputs: [],
            conflictingInputs: [],
            mutableFields: ["source.ref", "source_history", "updated_at"],
            genericGuards: [{
                    id: "append-only-source-reference",
                    description: "The previous source is appended to chronological history before the current ref changes."
                }],
            failureTaxonomy: {
                missingRequiredInput: "invalid-input",
                invalidField: "invalid-input",
                invalidRepositoryState: "invalid-config"
            },
            recoveries: [],
            exactExamples: [[
                    "day-shift", "spec", "source", "add", "--id", "spec-registry-commands",
                    "--ref", "revised-spec.md", "--reason", "Replace superseded source reference"
                ]]
        }
    }, [
        { kind: "option", name: "id", required: true, variadic: false, defaultValue: null, validation: "Existing spec registry entry id." },
        { kind: "option", name: "ref", required: true, variadic: false, defaultValue: null, validation: "New non-empty source reference." },
        { kind: "option", name: "reason", required: true, variadic: false, defaultValue: null, validation: "Reviewable non-empty transition reason." }
    ], [
        "day-shift", "spec", "source", "add", "--id", "spec-registry-commands",
        "--ref", "revised-spec.md", "--reason", "Replace superseded source reference"
    ]),
    writeCommand("spec add", "update", "spec-registry", "selected-existing-artifact", ".day-shift/specs/index.json", "selected-family", "updates-selected-artifact", "Adds a spec registry entry."),
    writeCommand("spec archive", "update", "spec-registry", "selected-existing-artifact", ".day-shift/specs/index.json", "selected-family", "updates-selected-artifact", "Archives a spec registry entry."),
    withInvocation(readCommand("spec list", "list", "spec-registry", "Lists registered specs with lifecycle-transparent filtering."), [
        { kind: "option", name: "status", required: false, variadic: true, defaultValue: [], validation: "Optional repeatable lifecycle status; values are trimmed, lowercased, and deduplicated." },
        { kind: "option", name: "includeArchived", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Adds archived entries to default or explicitly requested statuses." }
    ], ["day-shift", "spec", "list", "--status", "draft", "--status", "active", "--include-archived", "--format", "json"]),
    withInvocation(readCommand("spec search", "navigation", "spec-registry", "Searches registered specs with lifecycle-transparent filtering and omission evidence."), [
        { kind: "argument", name: "query", required: false, variadic: false, defaultValue: null, validation: "Optional case-insensitive substring query across canonical searchable fields." },
        { kind: "option", name: "status", required: false, variadic: true, defaultValue: [], validation: "Optional repeatable lifecycle status; values are trimmed, lowercased, and deduplicated." },
        { kind: "option", name: "includeArchived", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Adds archived entries to default or explicitly requested statuses." }
    ], ["day-shift", "spec", "search", "emergent-agent-inference-burn-and-workflow-reliability", "--status", "draft", "--format", "json"]),
    withInvocation({
        ...writeCommand("spec update", "update", "spec-registry", "selected-existing-artifact", ".day-shift/specs/index.json", "selected-family", "updates-selected-artifact", "Updates mutable spec registry fields."),
        semantics: {
            conditionalInputs: [],
            dependentInputs: [],
            conflictingInputs: [],
            mutableFields: [
                "title", "depth", "status", "implementation_order", "registered_at", "updated_at",
                "archived_at", "linked_slice.slice", "linked_slice.path"
            ],
            genericGuards: [{
                    id: "append-only-source-reference",
                    description: "source.ref is append-only and may be changed only through spec source add."
                }],
            failureTaxonomy: {
                missingRequiredInput: "invalid-input",
                invalidField: "invalid-input",
                invalidRepositoryState: "invalid-config"
            },
            recoveries: [{
                    command: "spec source add",
                    requiredInputs: ["id", "ref", "reason"],
                    callableWhen: "all-required-inputs-present",
                    availability: "callable"
                }],
            exactExamples: [[
                    "day-shift", "spec", "update", "--spec-id", "spec-registry-commands",
                    "--field", "title=Updated spec title"
                ]]
        }
    }, [
        { kind: "option", name: "specId", required: true, variadic: false, defaultValue: null, validation: "Existing spec registry entry id." },
        { kind: "option", name: "field", required: true, variadic: true, defaultValue: null, validation: "One or more supported mutable <key=value> assignments; source.ref is excluded." }
    ], [
        "day-shift", "spec", "update", "--spec-id", "spec-registry-commands",
        "--field", "title=Updated spec title"
    ]),
    readCommand("slice", "inspection", "planning", "Groups slice scaffold, update, and review surfaces."),
    writeCommand("slice new", "scaffold", "planning", "canonical-artifact", "slice overview and companion directories", "planning-layer", "creates-artifacts", "Creates a slice overview scaffold."),
    writeCommand("slice update", "update", "planning", "selected-existing-artifact", "selected slice overview", "selected-artifact", "updates-selected-artifact", "Updates slice overview metadata."),
    readCommand("slice review", "review", "planning", "Reviews slice planning evidence."),
    readCommand("phase", "inspection", "planning", "Groups phase scaffold, update, and review surfaces."),
    writeCommand("phase new", "scaffold", "planning", "canonical-artifact", "phase overview", "planning-layer", "creates-artifacts", "Creates phase overview scaffolds."),
    withInvocation(writeCommand("phase update", "update", "planning", "selected-existing-artifact", "selected phase overview", "selected-artifact", "updates-selected-artifact", "Updates phase overview metadata."), [
        { kind: "option", name: "phaseOverview", required: true, variadic: false, defaultValue: null, validation: "Repository-relative phase-overview.md path." },
        { kind: "option", name: "activeArtifact", required: false, variadic: false, defaultValue: null, validation: "Optional matching active-artifact guard." },
        { kind: "option", name: "field", required: false, variadic: true, defaultValue: null, validation: "Adapter requires one or more direct key=value metadata updates before execution." }
    ], ["day-shift", "phase", "update", "--phase-overview", ".day-shift/planning/example/phase-overview.md", "--field", "status=completed"]),
    withInvocation(readCommand("phase review", "review", "planning", "Reviews phase planning evidence."), [
        { kind: "option", name: "phaseOverview", required: true, variadic: false, defaultValue: null, validation: "Repository-relative phase-overview.md path." }
    ], ["day-shift", "phase", "review", "--phase-overview", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    readCommand("milestone", "inspection", "planning", "Groups milestone scaffold, update, and review surfaces."),
    withInvocation(writeCommand("milestone new", "scaffold", "planning", "canonical-artifact", "milestone overview and reconciliation placeholder", "planning-layer", "creates-artifacts", "Creates milestone overview scaffolds."), [
        { kind: "option", name: "phaseOverview", required: true, variadic: false, defaultValue: null, validation: "Repository-relative parent phase overview." },
        { kind: "option", name: "milestoneSlug", required: false, variadic: false, defaultValue: null, validation: "Declared ordered milestone slug unless fullSet is true." },
        { kind: "option", name: "fullSet", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Create every declared milestone." },
        { kind: "option", name: "milestoneTitle", required: false, variadic: false, defaultValue: null, validation: "Optional explicit H1 title." }
    ], ["day-shift", "milestone", "new", "--phase-overview", ".day-shift/planning/example/phase-overview.md", "--full-set"]),
    withInvocation(writeCommand("milestone update", "update", "planning", "selected-existing-artifact", "selected milestone overview", "selected-artifact", "updates-selected-artifact", "Updates milestone overview metadata."), [
        { kind: "option", name: "milestoneOverview", required: true, variadic: false, defaultValue: null, validation: "Repository-relative milestone-overview.md path." },
        { kind: "option", name: "activeArtifact", required: false, variadic: false, defaultValue: null, validation: "Optional matching active-artifact guard." },
        { kind: "option", name: "field", required: false, variadic: true, defaultValue: null, validation: "Adapter requires one or more direct key=value metadata updates before execution." }
    ], ["day-shift", "milestone", "update", "--milestone-overview", ".day-shift/planning/example/milestone-overview.md", "--field", "status=completed"]),
    readCommand("milestone review", "review", "planning", "Reviews milestone planning and reconciliation evidence."),
    readCommand("task", "inspection", "planning", "Groups task scaffold, promote, update, readiness, and review surfaces."),
    withInvocation(writeCommand("task baseline", "update", "planning", "selected-existing-artifact", "selected task definition", "selected-artifact", "updates-selected-artifact", "Captures one post-readiness, pre-write runtime-attribution baseline."), [
        { kind: "option", name: "taskDefinition", required: true, variadic: false, defaultValue: null, validation: "Repository-relative task-definition.md path for a ready runtime or hybrid task." },
        { kind: "option", name: "taskCycleId", required: true, variadic: false, defaultValue: null, validation: "Stable task-cycle identity using 3-128 allowed identity characters." },
        { kind: "option", name: "checkpointId", required: true, variadic: false, defaultValue: null, validation: "Stable successful-readiness checkpoint identity using 3-128 allowed identity characters." },
        { kind: "option", name: "resume", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Reuses only an existing baseline whose task-cycle and checkpoint identities exactly match." },
        { kind: "option", name: "adopt", required: false, variadic: true, defaultValue: null, validation: "Repeatable declared-path::concrete-rationale adoption evidence for dirty pre-staged targets." }
    ], ["day-shift", "task", "baseline", "--task-definition", ".day-shift/planning/example/task-definition.md", "--task-cycle-id", "task01-cycle01", "--checkpoint-id", "readiness-approved-v1"]),
    withInvocation(writeCommand("task new", "scaffold", "planning", "canonical-artifact", "task directory with task definition and implementation summary", "planning-layer", "creates-artifacts", "Creates task artifacts."), [
        { kind: "option", name: "milestoneOverview", required: false, variadic: false, defaultValue: null, validation: "Repository-relative parent milestone overview." },
        { kind: "option", name: "sliceOverview", required: false, variadic: false, defaultValue: null, validation: "Repository-relative lightweight parent slice overview." },
        { kind: "option", name: "lightweight", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Create a lightweight direct task." },
        { kind: "option", name: "taskSlug", required: false, variadic: false, defaultValue: null, validation: "Declared ordered task slug unless fullSet is true." },
        { kind: "option", name: "fullSet", valueType: "boolean", required: false, variadic: false, defaultValue: false, validation: "Create every declared task." },
        { kind: "option", name: "taskTitle", required: false, variadic: false, defaultValue: null, validation: "Optional explicit H1 title." }
    ], ["day-shift", "task", "new", "--milestone-overview", ".day-shift/planning/example/milestone-overview.md", "--full-set"]),
    writeCommand("task promote", "scaffold", "planning", "canonical-artifact", "promoted task planning artifacts", "planning-layer", "creates-artifacts", "Promotes planning work into task artifacts."),
    readCommand("task readiness-review", "review", "planning", "Reviews task readiness without writing."),
    readCommand("task review", "review", "planning", "Reviews task closeout evidence without writing."),
    withInvocation(writeCommand("task update", "update", "planning", "selected-existing-artifact", "selected task definition", "selected-artifact", "updates-selected-artifact", "Updates task definition metadata."), [
        { kind: "option", name: "taskDefinition", required: true, variadic: false, defaultValue: null, validation: "Repository-relative task-definition.md path." },
        { kind: "option", name: "activeArtifact", required: false, variadic: false, defaultValue: null, validation: "Optional matching active-artifact guard." },
        { kind: "option", name: "field", required: false, variadic: true, defaultValue: null, validation: "Adapter requires one or more direct key=value metadata updates before execution." }
    ], ["day-shift", "task", "update", "--task-definition", ".day-shift/planning/example/task-definition.md", "--field", "readiness=completed", "--field", "status=completed"]),
    readCommand("implementation-summary", "inspection", "planning", "Groups implementation summary build, review, and update surfaces."),
    withInvocation(writeCommand("implementation-summary build", "build", "planning", "canonical-artifact", "paired implementation-summary.md", "selected-artifact", "updates-selected-artifact", "Builds or refreshes paired implementation summary artifacts."), [
        { kind: "option", name: "taskDefinition", required: true, variadic: false, defaultValue: null, validation: "Repository-relative owning task-definition.md path." }
    ], ["day-shift", "implementation-summary", "build", "--task-definition", ".day-shift/planning/example/task-definition.md"]),
    withInvocation(readCommand("implementation-summary review", "review", "planning", "Reviews implementation summary closeout evidence."), [
        { kind: "option", name: "taskDefinition", required: true, variadic: false, defaultValue: null, validation: "Repository-relative owning task-definition.md path." }
    ], ["day-shift", "implementation-summary", "review", "--task-definition", ".day-shift/planning/example/task-definition.md", "--format", "json"]),
    writeCommand("implementation-summary update", "update", "planning", "selected-existing-artifact", "selected implementation summary", "selected-artifact", "updates-selected-artifact", "Updates implementation summary metadata."),
    readCommand("reconciliation", "inspection", "planning", "Groups reconciliation build, review, and update surfaces."),
    withInvocation(writeCommand("reconciliation build", "build", "planning", "canonical-artifact", "milestone reconciliation.md", "planning-layer", "updates-selected-artifact", "Builds or refreshes milestone reconciliation artifacts."), [
        { kind: "option", name: "milestoneOverview", required: false, variadic: false, defaultValue: null, validation: "Repository-relative owning milestone overview." },
        { kind: "option", name: "taskDefinition", required: false, variadic: false, defaultValue: null, validation: "Explicit task-level exception owner." },
        { kind: "option", name: "rationale", required: false, variadic: false, defaultValue: null, validation: "Required for task-level reconciliation." }
    ], ["day-shift", "reconciliation", "build", "--milestone-overview", ".day-shift/planning/example/milestone-overview.md"]),
    withInvocation(readCommand("reconciliation review", "review", "planning", "Reviews milestone reconciliation evidence."), [
        { kind: "option", name: "milestoneOverview", required: false, variadic: false, defaultValue: null, validation: "Repository-relative owning milestone overview." },
        { kind: "option", name: "taskDefinition", required: false, variadic: false, defaultValue: null, validation: "Explicit task-level exception owner." },
        { kind: "option", name: "rationale", required: false, variadic: false, defaultValue: null, validation: "Required for task-level reconciliation." }
    ], ["day-shift", "reconciliation", "review", "--milestone-overview", ".day-shift/planning/example/milestone-overview.md", "--format", "json"]),
    writeCommand("reconciliation update", "update", "planning", "selected-existing-artifact", "selected reconciliation artifact", "selected-artifact", "updates-selected-artifact", "Updates reconciliation metadata."),
    readCommand("planning", "navigation", "planning", "Groups planning navigation surfaces."),
    withInvocation(readCommand("planning inventory", "navigation", "planning", "Reports planning hierarchy inventory."), [{ kind: "option", name: "root", required: false, variadic: false, defaultValue: ".day-shift/planning", validation: "Repository-relative planning root or subdirectory." }], ["day-shift", "planning", "inventory", "--root", ".day-shift/planning", "--format", "json"]),
    withInvocation(readCommand("planning gap-report", "navigation", "planning", "Reports missing or incomplete planning artifacts."), [
        { kind: "option", name: "scope", required: false, variadic: false, defaultValue: ".day-shift/planning", validation: "Repository-relative planning artifact or directory." },
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Alias for scope." }
    ], ["day-shift", "planning", "gap-report", "--scope", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    withInvocation(readCommand("planning next-action", "navigation", "planning", "Reports the next likely planning action."), [{ kind: "option", name: "artifact", required: true, variadic: false, defaultValue: null, validation: "Repository-relative selected planning artifact." }], ["day-shift", "planning", "next-action", "--artifact", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    readCommand("work", "navigation", "planning", "Groups explicit planning-work candidate and selection surfaces."),
    withInvocation(readCommand("work candidates", "navigation", "planning", "Reports bounded advisory planning-work candidates without writing selection state."), [
        { kind: "option", name: "root", required: false, variadic: false, defaultValue: ".day-shift/planning", validation: "Repository-relative planning root or subdirectory." },
        { kind: "option", name: "maxResults", required: false, variadic: false, defaultValue: 10, validation: "Integer from 1 to 50." }
    ], ["day-shift", "work", "candidates", "--root", ".day-shift/planning", "--max-results", "10", "--format", "json"]),
    withInvocation({ ...writeCommand("work select", "update", "planning", "derived-state", "user-local work selection state", "workspace", "updates-derived-state", "Selects one planning artifact in a named user-local session."), authorization: "host-write" }, [
        { kind: "option", name: "artifact", required: true, variadic: false, defaultValue: null, validation: "Existing repository-relative planning artifact." },
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." },
        { kind: "option", name: "intent", required: false, variadic: false, defaultValue: null, validation: "Optional printable provenance up to 256 characters." },
        { kind: "option", name: "ifMatch", required: false, variadic: false, defaultValue: null, validation: "Opaque token from work current; required to replace existing session state." }
    ], ["day-shift", "work", "select", "--artifact", ".day-shift/planning/example/task-definition.md"]),
    withInvocation(readCommand("work current", "inspection", "planning", "Inspects one named user-local work selection and freshness."), [
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." }
    ], ["day-shift", "work", "current", "--session", "default", "--format", "json"]),
    withInvocation(readCommand("work next", "navigation", "planning", "Resolves explicit or stored selection and reports its next action."), [
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional existing repository-relative planning artifact." },
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." }
    ], ["day-shift", "work", "next", "--artifact", ".day-shift/planning/example/task-definition.md", "--format", "json"]),
    withInvocation({ ...writeCommand("work clear", "cleanup", "planning", "derived-state", "user-local work selection state", "workspace", "updates-derived-state", "Clears one named user-local work selection session."), authorization: "host-write" }, [
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." },
        { kind: "option", name: "ifMatch", required: false, variadic: false, defaultValue: null, validation: "Opaque token from work current; required when session state exists." }
    ], ["day-shift", "work", "clear", "--session", "default"]),
    withInvocation({ ...writeCommand("work cleanup", "cleanup", "planning", "derived-state", "user-local work selection state", "workspace", "updates-derived-state", "Clears stale named selection state while preserving fresh or absent state."), authorization: "host-write" }, [
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." },
        { kind: "option", name: "ifMatch", required: false, variadic: false, defaultValue: null, validation: "Opaque token from work current; required to clear stale state." }
    ], ["day-shift", "work", "cleanup", "--session", "default", "--if-match", "<token>"]),
    readCommand("resume", "inspection", "planning", "Groups evidence-backed local resume capsule lifecycle surfaces."),
    withInvocation({ ...writeCommand("resume create", "update", "planning", "derived-state", "user-local resume capsule state", "workspace", "updates-derived-state", "Creates or replaces one evidence-backed resume capsule."), authorization: "host-write" }, [
        { kind: "option", name: "artifact", required: true, variadic: false, defaultValue: null, validation: "Existing repository-relative planning artifact." },
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." },
        { kind: "option", name: "ifMatch", required: false, variadic: false, defaultValue: null, validation: "Opaque token from resume inspect; required to replace existing state." },
        { kind: "option", name: "completedAction", required: false, variadic: true, defaultValue: [], validation: "Historical completed action identifiers." },
        { kind: "option", name: "evidence", required: false, variadic: true, defaultValue: [], validation: "Repository-relative evidence paths to hash." },
        { kind: "option", name: "postcondition", required: false, variadic: true, defaultValue: [], validation: "Repository-relative postcondition evidence paths to hash." },
        { kind: "option", name: "blocker", required: false, variadic: true, defaultValue: [], validation: "Unresolved blocker evidence to preserve." },
        { kind: "option", name: "expiresInHours", required: false, variadic: false, defaultValue: 24, validation: "Positive expiry duration in hours." }
    ], ["day-shift", "resume", "create", "--artifact", ".day-shift/planning/example/task-definition.md"]),
    withInvocation(readCommand("resume inspect", "inspection", "planning", "Inspects capsule freshness and conflicts without writing state."), [
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional explicit artifact identity." },
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." }
    ], ["day-shift", "resume", "inspect", "--session", "default", "--format", "json"]),
    withInvocation(readCommand("resume resume", "navigation", "planning", "Revalidates a fresh capsule and reports current action legality without writes."), [
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional explicit artifact identity; conflicts fail closed." },
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." }
    ], ["day-shift", "resume", "resume", "--session", "default", "--format", "json"]),
    withInvocation({ ...writeCommand("resume clear", "cleanup", "planning", "derived-state", "user-local resume capsule state", "workspace", "updates-derived-state", "Clears one named resume capsule."), authorization: "host-write" }, [
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." },
        { kind: "option", name: "ifMatch", required: false, variadic: false, defaultValue: null, validation: "Opaque token from resume inspect; required when state exists." }
    ], ["day-shift", "resume", "clear", "--session", "default", "--if-match", "<token>"]),
    withInvocation({ ...writeCommand("resume cleanup", "cleanup", "planning", "derived-state", "user-local resume capsule state", "workspace", "updates-derived-state", "Clears stale or expired capsule state while preserving fresh or absent state."), authorization: "host-write" }, [
        { kind: "option", name: "session", required: false, variadic: false, defaultValue: "default", validation: "Validated local session name." },
        { kind: "option", name: "ifMatch", required: false, variadic: false, defaultValue: null, validation: "Opaque token from resume inspect; required to clear stale state." }
    ], ["day-shift", "resume", "cleanup", "--session", "default", "--if-match", "<token>"]),
    readCommand("workflow", "navigation", "planning", "Groups workflow explanation surfaces."),
    withInvocation(readCommand("workflow explain", "navigation", "planning", "Explains the workflow and prompt for a selected artifact."), [{ kind: "option", name: "artifact", required: true, variadic: false, defaultValue: null, validation: "Repository-relative selected planning artifact." }], ["day-shift", "workflow", "explain", "--artifact", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    readCommand("validation", "validation", "validation", "Groups validation report and checkpoint surfaces."),
    withInvocation(readCommand("validation smoke", "validation", "validation", "Reports planning validation smoke findings."), [
        { kind: "option", name: "scope", required: false, variadic: false, defaultValue: "planning", validation: "Currently planning." },
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional repository-relative selected planning artifact." },
        { kind: "option", name: "action", required: false, variadic: false, defaultValue: null, validation: "Exact authoritative command descriptor id; requires artifact." }
    ], ["day-shift", "validation", "smoke", "--scope", "planning", "--artifact", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    writeCommand("validation checkpoint", "sync", "validation", "derived-state", ".day-shift/state validation baseline", "workspace", "updates-derived-state", "Writes a forward-only validation baseline."),
    readCommand("validation rollup", "validation", "validation", "Reports validation rollup evidence."),
    withInvocation(readCommand("validation links-check", "validation", "validation", "Reports local trace-link evidence."), [
        { kind: "option", name: "scope", required: false, variadic: false, defaultValue: "planning", validation: "Currently planning." },
        { kind: "option", name: "format", required: false, variadic: false, defaultValue: "text", validation: "text or json." },
        { kind: "option", name: "artifact", required: false, variadic: false, defaultValue: null, validation: "Optional repository-relative planning artifact or directory." }
    ], ["day-shift", "validation", "links-check", "--scope", "planning", "--artifact", ".day-shift/planning/example/phase-overview.md", "--format", "json"]),
    readCommand("validation scope-guard", "validation", "validation", "Reserved scope-guard validation report surface."),
    readCommand("validation diff-check", "validation", "validation", "Reserved diff-check validation report surface."),
    readCommand("validation impact-analysis", "validation", "validation", "Reserved impact-analysis validation report surface."),
    readCommand("metadata", "inspection", "metadata", "Groups metadata inventory, validation, update, and sync surfaces."),
    readCommand("metadata inventory", "inspection", "metadata", "Reports metadata-bearing artifact inventory."),
    writeCommand("metadata update", "update", "metadata", "selected-existing-artifact", "selected metadata-bearing artifact", "selected-artifact", "updates-selected-artifact", "Updates metadata fields through shared helpers."),
    readCommand("metadata validate-update", "validation", "metadata", "Validates metadata update requests without writing."),
    writeCommand("metadata sync-status-from-review", "sync", "metadata", "selected-existing-artifact", "selected planning artifact", "selected-artifact", "updates-selected-artifact", "Synchronizes lifecycle status from completed review evidence."),
    readCommand("manifest", "inspection", "manifest", "Groups manifest update surfaces."),
    writeCommand("manifest update", "update", "manifest", "selected-existing-artifact", "selected prompt or template manifest", "selected-artifact", "updates-selected-artifact", "Updates prompt or template manifest metadata."),
    readCommand("prompt", "inspection", "prompt", "Groups prompt init, edit, update, and reconciliation surfaces."),
    readCommand("prompt show", "inspection", "prompt", "Reserved prompt rendering contract that has no runtime action yet."),
    writeCommand("prompt init", "scaffold", "prompt", "canonical-artifact", ".day-shift/prompts/ assets", "selected-family", "creates-artifacts", "Initializes prompt assets."),
    writeCommand("prompt edit", "update", "prompt", "selected-existing-artifact", "selected prompt markdown", "selected-artifact", "updates-selected-artifact", "Edits prompt markdown."),
    writeCommand("prompt update", "update", "prompt", "selected-existing-artifact", "selected prompt front matter", "selected-artifact", "updates-selected-artifact", "Updates prompt metadata."),
    readCommand("prompt reconcile", "inspection", "prompt", "Groups prompt reconciliation preview and apply surfaces."),
    withInvocation(readCommand("prompt reconcile preview", "inspection", "prompt", "Previews three-way prompt drift without writing."), [
        { kind: "option", name: "prompt", required: true, variadic: false, defaultValue: null, validation: "Repository-relative prompt path." }
    ], ["day-shift", "prompt", "reconcile", "preview", "--prompt", ".day-shift/prompts/user/task.next.md", "--format", "json"]),
    withInvocation(writeCommand("prompt reconcile apply", "update", "prompt", "selected-existing-artifact", "selected user-layer prompt and prompt materialization state", "selected-artifact", "updates-selected-artifact", "Applies an explicit preview-bound prompt reconciliation decision."), [
        { kind: "option", name: "prompt", required: true, variadic: false, defaultValue: null, validation: "Repository-relative prompt path." },
        { kind: "option", name: "decision", required: true, variadic: false, defaultValue: null, validation: "preserve or replace." },
        { kind: "option", name: "previewHash", required: true, variadic: false, defaultValue: null, validation: "Exact hash returned by prompt reconcile preview." }
    ], ["day-shift", "prompt", "reconcile", "apply", "--prompt", ".day-shift/prompts/user/task.next.md", "--decision", "preserve", "--preview-hash", "<sha256>", "--format", "json"]),
    readCommand("template", "inspection", "template", "Groups template materialization and update surfaces."),
    writeCommand("template materialize", "materialize", "template", "canonical-artifact", "template destination path", "selected-artifact", "materializes-assets", "Materializes a template to its destination."),
    writeCommand("template update", "update", "template", "selected-existing-artifact", "selected template front matter", "selected-artifact", "updates-selected-artifact", "Updates template metadata."),
    readCommand("templates", "list", "template", "Lists available templates."),
    readCommand("templates list", "list", "template", "Lists available template inventory."),
    readCommand("structural-pressure", "inspection", "structural-pressure", "Groups structural-pressure report and sync surfaces."),
    readCommand("structural-pressure report", "review", "structural-pressure", "Reports structural pressure evidence."),
    writeCommand("structural-pressure sync", "sync", "structural-pressure", "derived-state", ".day-shift/state/structural-pressure.json", "workspace", "updates-derived-state", "Synchronizes structural-pressure derived state."),
    readCommand("workspace", "inspection", "workspace", "Groups workspace inspection, migration, and content-upgrade surfaces."),
    writeCommand("workspace migrate", "migration", "workspace", "workspace-metadata", ".day-shift workspace metadata", "workspace", "applies-migration", "Plans or applies explicit workspace metadata migrations."),
    readCommand("workspace upgrade", "inspection", "workspace", "Groups workspace content-upgrade preview and apply surfaces."),
    withInvocation(readCommand("workspace upgrade preview", "inspection", "workspace", "Previews latest-layer prompt delivery without writing."), [
        { kind: "option", name: "latestMode", required: false, variadic: false, defaultValue: "materialize", validation: "materialize, disabled, or legacy-not-materialized." }
    ], ["day-shift", "workspace", "upgrade", "preview", "--latest-mode", "materialize", "--format", "json"]),
    withInvocation(writeCommand("workspace upgrade apply", "migration", "workspace", "workspace-metadata", ".day-shift/prompts/latest and prompt materialization state", "workspace", "applies-migration", "Applies a preview-bound latest-layer prompt upgrade without writing user prompts."), [
        { kind: "option", name: "latestMode", required: false, variadic: false, defaultValue: "materialize", validation: "materialize, disabled, or legacy-not-materialized." },
        { kind: "option", name: "previewHash", required: true, variadic: false, defaultValue: null, validation: "Exact hash returned by workspace upgrade preview." },
        { kind: "option", name: "confirm", required: true, variadic: false, defaultValue: null, validation: "apply-workspace-upgrade." }
    ], ["day-shift", "workspace", "upgrade", "apply", "--latest-mode", "materialize", "--preview-hash", "<sha256>", "--confirm", "apply-workspace-upgrade", "--format", "json"]),
    readCommand("version", "inspection", "release", "Groups installed Day Shift version manager surfaces."),
    writeCommand("version alias", "update", "release", "derived-state", "version-manager alias metadata", "local-installation", "updates-derived-state", "Groups version-manager alias update surfaces."),
    readCommand("version alias list", "list", "release", "Lists version-manager aliases."),
    writeCommand("version alias set", "update", "release", "derived-state", "version-manager alias metadata", "local-installation", "updates-derived-state", "Sets a version-manager alias."),
    readCommand("version check", "validation", "release", "Checks version availability without installing."),
    readCommand("version current", "inspection", "release", "Reports the currently selected managed version."),
    readCommand("version doctor", "inspection", "release", "Reports version-manager diagnostics."),
    writeCommand("version install", "install", "release", "local-install-target", "version-manager package state", "local-installation", "installs-local-files", "Installs a local Day Shift package source into version-manager state."),
    readCommand("version list", "list", "release", "Lists installed managed versions."),
    writeCommand("version pin", "update", "release", "derived-state", "version-manager selection metadata", "local-installation", "updates-derived-state", "Pins managed version selection."),
    writeCommand("version uninstall", "cleanup", "release", "local-install-target", "version-manager package state", "local-installation", "prunes-generated-output", "Uninstalls managed versions from local state."),
    writeCommand("version use", "update", "release", "derived-state", "version-manager selection metadata", "local-installation", "updates-derived-state", "Selects a managed version for current use."),
    readCommand("release", "inspection", "release", "Groups release validation and generated-output surfaces."),
    writeCommand("release build", "release", "release", "generated-output", "release/<version>/", "release-output", "materializes-assets", "Builds local release output."),
    readCommand("release check", "validation", "release", "Checks local release inputs and staged outputs."),
    writeCommand("release manifest", "release", "release", "generated-output", "release manifest", "release-output", "materializes-assets", "Generates release manifest output."),
    writeCommand("release archive", "release", "release", "generated-output", "release archives", "release-output", "materializes-assets", "Generates release archives."),
    writeCommand("release checksum", "release", "release", "generated-output", "release checksums", "release-output", "materializes-assets", "Generates release checksums."),
    writeCommand("release installer", "release", "release", "generated-output", "release installer assets", "release-output", "materializes-assets", "Generates release installer assets."),
    writeCommand("release notes", "release", "release", "generated-output", "release notes draft", "release-output", "materializes-assets", "Generates release notes draft output."),
    writeCommand("release retention", "cleanup", "release", "generated-output", "release output retention targets", "release-output", "prunes-generated-output", "Prunes old release output according to retention policy."),
    writeCommand("release cleanup", "cleanup", "release", "generated-output", "release output directory", "release-output", "prunes-generated-output", "Cleans generated release output.")
];
// Legacy adapters remain authoritative for command-specific and cross-field
// validation. This catalog makes their invocation surface available to native
// tool consumers while those adapters converge on shared structured parsing.
const LEGACY_COMMAND_INPUTS = Object.freeze({
    "agent": ["b:verbose"], "agent orient": ["b:verbose"],
    "completion complete": ["!o:shell", "!o:line", "!o:cursor"], "completion install": ["!o:shell", "b:dryRun", "b:force"],
    "completion script": ["!o:shell"], "completion uninstall": ["!o:shell", "b:dryRun"],
    "config get": ["a:selector"], "config inventory": ["o:licenseFile"], "config set": ["!a:key", "!a:value"],
    "ignore install": ["b:yes"], "implementation-summary update": ["!o:summary", "o:activeArtifact", "o:field"],
    "init": ["b:noAgent", "b:withoutTemplates", "b:dryRun", "b:force", "o:directory", "o:sandboxRunId"],
    "license cleanup-reminders": ["o:licenseFile", "b:dryRun"], "license install": ["!a:license-file"], "license status": ["o:licenseFile"],
    "link disposition add": ["!o:status", "!o:target", "o:replacementTarget", "o:sourceArtifact", "o:traceField", "o:scope", "o:reason", "o:format"],
    "link disposition apply": ["o:id", "o:target", "o:artifact", "b:dryRun", "o:format"],
    "link disposition delete": ["o:id", "o:target", "o:format"], "link disposition list": ["o:status", "o:format"],
    "link disposition preview": ["o:id", "o:target", "o:artifact", "o:format"], "link disposition show": ["o:id", "o:target", "o:format"],
    "link disposition update": ["o:id", "o:target", "o:status", "o:replacementTarget", "b:clearReplacementTarget", "o:sourceArtifact", "o:traceField", "o:scope", "o:reason", "b:clearReason", "o:format"],
    "manifest update": ["!o:manifest", "o:field"], "metadata inventory": ["o:root"],
    "metadata sync-status-from-review": ["o:taskDefinition", "o:milestoneOverview", "o:phaseOverview", "o:activeArtifact"],
    "metadata update": ["!o:artifact", "o:activeArtifact", "o:field"], "metadata validate-update": ["!o:artifact", "o:activeArtifact", "o:field"],
    "milestone review": ["!o:milestoneOverview"], "phase new": ["!o:sliceOverview", "o:phaseSlug", "b:fullSet", "o:phaseTitle"],
    "prompt edit": ["!o:prompt"], "prompt init": ["!o:prompt", "b:force"], "prompt update": ["!o:prompt", "o:field"],
    "prompt reconcile preview": ["!o:prompt"], "prompt reconcile apply": ["!o:prompt", "!o:decision", "!o:previewHash"],
    "reconciliation update": ["!o:reconciliation", "o:activeArtifact", "o:field"],
    "release archive": ["o:releaseVersion", "o:outputDir", "b:dryRun"],
    "release build": ["o:releaseVersion", "o:commandName", "o:outputDir", "b:dryRun", "b:dirty"],
    "release check": ["o:releaseVersion", "o:commandName", "o:outputDir"], "release checksum": ["o:releaseVersion", "o:outputDir", "b:dryRun"],
    "release cleanup": ["o:outputDir", "b:confirm", "b:dryRun"], "release installer": ["o:releaseVersion", "o:commandName", "o:outputDir", "b:dryRun"],
    "release manifest": ["o:releaseVersion", "o:commandName", "o:outputDir", "b:dryRun"], "release notes": ["o:releaseVersion", "o:commandName", "o:outputDir", "b:dryRun"],
    "release retention": ["o:releaseVersion", "o:outputDir", "o:keep", "b:dryRun"],
    "slice new": ["o:specId", "o:sliceId"], "slice update": ["!o:sliceOverview", "o:activeArtifact", "o:field"],
    "spec add": ["o:entryJson", "o:entryFile"], "spec archive": ["!a:id"],
    "structural-pressure report": ["o:path"], "structural-pressure sync": ["!o:milestoneReconciliation"],
    "task promote": ["!o:taskDefinition", "b:dryRun"], "task readiness-review": ["!o:taskDefinition"], "task review": ["!o:taskDefinition"],
    "template materialize": ["!o:template", "!o:mode", "o:destination", "b:manifestDestination", "o:placeholder", "b:dryRun", "b:force"],
    "template update": ["!o:template", "o:field"], "validation checkpoint": ["o:scope"], "validation rollup": ["o:scope", "o:format", "o:artifact"],
    "version alias set": ["!a:name", "!a:version"], "version check": ["a:version", "b:network"],
    "version install": ["o:from", "o:assertVersion"], "version pin": ["!a:version"],
    "version uninstall": ["a:version", "o:replaceWith", "b:confirmSelectedRemoval"], "version use": ["!a:version"],
    "workspace migrate": ["!o:targetSchemaVersion", "b:dryRun", "o:confirm", "o:family", "o:field"],
    "workspace upgrade preview": ["o:latestMode"], "workspace upgrade apply": ["o:latestMode", "!o:previewHash", "!o:confirm"]
});
const VARIADIC_LEGACY_INPUTS = new Set(["field", "placeholder"]);
function addLegacyInvocationInputs(descriptor) {
    if (descriptor.inputs.length > 0)
        return descriptor;
    const tokens = LEGACY_COMMAND_INPUTS[descriptor.command];
    if (tokens === undefined)
        return descriptor;
    return {
        ...descriptor,
        inputs: tokens.map((token) => {
            const separator = token.indexOf(":");
            const prefix = token.slice(0, separator);
            const name = token.slice(separator + 1);
            return {
                kind: prefix.endsWith("a") ? "argument" : "option",
                name,
                valueType: prefix === "b" ? "boolean" : "string",
                required: prefix.startsWith("!"),
                variadic: VARIADIC_LEGACY_INPUTS.has(name) && descriptor.command !== "workspace migrate",
                defaultValue: prefix === "b" ? false : null,
                validation: "Validated by the command adapter; descriptor/runtime input-name drift is enforced globally."
            };
        })
    };
}
const RESERVED_COMMAND_FAMILY_CONTAINERS = new Set([
    "completion",
    "commands",
    "config",
    "ignore",
    "ignore integration",
    "implementation-summary",
    "license",
    "link",
    "link disposition",
    "metadata",
    "manifest",
    "milestone",
    "phase",
    "planning",
    "prompt",
    "prompt reconcile",
    "release",
    "resume",
    "reconciliation",
    "slice",
    "spec",
    "spec source",
    "structural-pressure",
    "task",
    "template",
    "templates",
    "validation",
    "version",
    "workflow",
    "work",
    "workspace",
    "workspace upgrade"
]);
const PLANNED_COMMAND_DESCRIPTORS = new Set([
    "prompt show",
    "slice review",
    "validation scope-guard",
    "validation diff-check",
    "validation impact-analysis"
]);
const COMMAND_DESCRIPTOR_REGISTRATIONS = BASE_COMMAND_DESCRIPTOR_REGISTRATIONS
    .map(applyAuthoredCommandAvailability)
    .map(addLegacyInvocationInputs);
function applyAuthoredCommandAvailability(registration) {
    const availability = PLANNED_COMMAND_DESCRIPTORS.has(registration.command)
        ? "planned"
        : RESERVED_COMMAND_FAMILY_CONTAINERS.has(registration.command)
            ? "reserved"
            : "callable";
    if (availability === "callable") {
        return { ...registration, availability };
    }
    return {
        ...registration,
        availability,
        examples: []
    };
}
const NON_WRITING_CAPABILITIES = new Set([
    "read",
    "validation",
    "review",
    "navigation",
    "list",
    "inspection"
]);
const WRITE_CAPABLE_CAPABILITIES = new Set([
    "scaffold",
    "update",
    "build",
    "sync",
    "migration",
    "install",
    "materialize",
    "release",
    "cleanup"
]);
function normalizeCommandCapability(registration) {
    const command = normalizeRequiredText(registration.command, "command");
    const summary = normalizeRequiredText(registration.summary, `${command} summary`);
    const availability = registration.availability ?? "callable";
    if (!command_availability_1.COMMAND_AVAILABILITY_TOKENS.includes(availability)) {
        throw new Error(`Command '${command}' uses unsupported availability '${availability}'.`);
    }
    if (!exports.COMMAND_CAPABILITY_TOKENS.includes(registration.capability)) {
        throw new Error(`Command '${command}' uses unsupported capability '${registration.capability}'.`);
    }
    if (NON_WRITING_CAPABILITIES.has(registration.capability)) {
        if (registration.writeCapable) {
            throw new Error(`Command '${command}' uses non-writing capability '${registration.capability}' but is marked writeCapable.`);
        }
        return Object.freeze({
            command,
            availability,
            capability: registration.capability,
            primaryCapability: registration.capability,
            summary,
            writeCapable: false,
            artifactFamily: registration.artifactFamily ?? "planning",
            destinationPosture: registration.destinationPosture ?? "none",
            targetPathPosture: registration.targetPathPosture ?? "none",
            coordinationScope: registration.coordinationScope ?? "none",
            mutationPosture: "non-writing",
            noWriteBoundary: normalizeRequiredText(registration.noWriteBoundary, `${command} no-write boundary`)
        });
    }
    if (!WRITE_CAPABLE_CAPABILITIES.has(registration.capability)) {
        throw new Error(`Command '${command}' uses unclassified capability '${registration.capability}'.`);
    }
    if (!registration.writeCapable) {
        throw new Error(`Command '${command}' uses write-capable capability '${registration.capability}' but writeCapable is false.`);
    }
    return Object.freeze({
        command,
        availability,
        capability: registration.capability,
        primaryCapability: registration.capability,
        summary,
        writeCapable: true,
        artifactFamily: requireField(registration.artifactFamily, command, "artifactFamily"),
        destinationPosture: requireField(registration.destinationPosture, command, "destinationPosture"),
        targetPathPosture: normalizeRequiredText(registration.targetPathPosture, `${command} targetPathPosture`),
        coordinationScope: requireField(registration.coordinationScope, command, "coordinationScope"),
        mutationPosture: requireField(registration.mutationPosture, command, "mutationPosture"),
        noWriteBoundary: registration.noWriteBoundary ?? "Write-capable command; mutation is limited to the declared artifact family, destination posture, target-path posture, and coordination scope."
    });
}
function normalizeCommandCapabilityRegistry(registrations) {
    const seen = new Set();
    return Object.freeze(registrations.map((registration) => {
        const normalized = normalizeCommandCapability(registration);
        if (seen.has(normalized.command)) {
            throw new Error(`Duplicate command capability registration for '${normalized.command}'.`);
        }
        seen.add(normalized.command);
        return normalized;
    }));
}
function findCommandCapability(registry, command) {
    return registry.find((entry) => entry.command === command) ?? null;
}
exports.COMMAND_DESCRIPTOR_REGISTRY = (0, command_descriptors_1.normalizeCommandDescriptorRegistry)(COMMAND_DESCRIPTOR_REGISTRATIONS, normalizeCommandCapability);
exports.COMMAND_CAPABILITY_REGISTRY = exports.COMMAND_DESCRIPTOR_REGISTRY;
function getCommandDescriptorRegistry() {
    return exports.COMMAND_DESCRIPTOR_REGISTRY.map(command_descriptor_projections_1.cloneCommandDescriptor);
}
function getRegisteredCommandDescriptor(command) {
    return (0, command_descriptors_1.findCommandDescriptor)(exports.COMMAND_DESCRIPTOR_REGISTRY, command);
}
function getCommandCapabilityRegistry() {
    return exports.COMMAND_CAPABILITY_REGISTRY.map((entry) => ({ ...entry }));
}
function getRegisteredCommandCapability(command) {
    return findCommandCapability(exports.COMMAND_CAPABILITY_REGISTRY, command);
}
function createNoWriteBoundaryEvidence(commandOrCapability, options = {}) {
    const capability = typeof commandOrCapability === "string"
        ? findCommandCapability(options.registry ?? exports.COMMAND_CAPABILITY_REGISTRY, commandOrCapability)
        : commandOrCapability;
    if (capability === null) {
        throw new Error(`No command capability registration exists for '${commandOrCapability}'.`);
    }
    if (capability.writeCapable) {
        throw new Error(`Command '${capability.command}' is write-capable and cannot be represented as read-only no-write evidence.`);
    }
    const severity = options.severity ?? "informational";
    if (!exports.NO_WRITE_EVIDENCE_SEVERITIES.includes(severity)) {
        throw new Error(`Unsupported no-write evidence severity '${severity}'.`);
    }
    return Object.freeze({
        command: capability.command,
        capability: capability.capability,
        primaryCapability: capability.primaryCapability,
        writeCapable: false,
        artifactFamily: capability.artifactFamily,
        coordinationScope: "none",
        mutationPosture: "non-writing",
        noWriteBoundary: capability.noWriteBoundary,
        noWriteReason: options.noWriteReason ?? "The command is a read-only evidence surface.",
        evidenceOnly: true,
        severity,
        ...(options.recommendedCommand === undefined
            ? {}
            : {
                recommendation: createNoWriteRecommendation(options.recommendedCommand, {
                    recommendationLabel: options.recommendationLabel,
                    recommendationBoundary: options.recommendationBoundary,
                    registry: options.registry
                })
            })
    });
}
function createNoWriteRecommendation(command, options = {}) {
    const normalizedCommand = normalizeRequiredText(command, "recommended follow-up command");
    const recommendedCapability = findCommandCapability(options.registry ?? exports.COMMAND_CAPABILITY_REGISTRY, normalizedCommand);
    return Object.freeze({
        command: normalizedCommand,
        label: options.recommendationLabel ?? "Separate follow-up command",
        writeCapable: recommendedCapability?.writeCapable ?? true,
        ...(recommendedCapability === null
            ? {}
            : {
                capability: recommendedCapability.capability,
                artifactFamily: recommendedCapability.artifactFamily,
                mutationPosture: recommendedCapability.mutationPosture,
                coordinationScope: recommendedCapability.coordinationScope
            }),
        followUpOnly: true,
        boundary: options.recommendationBoundary
            ?? "Recommended command is a separate follow-up action; the current read-only command did not run it."
    });
}
function createNoWriteFindingEvidenceDetails(commandOrCapability, options = {}) {
    const evidence = createNoWriteBoundaryEvidence(commandOrCapability, options);
    return Object.freeze({
        command: evidence.command,
        ruleFamily: "command-capability",
        evidenceSource: "command-capability-registry",
        capability: evidence.capability,
        primaryCapability: evidence.primaryCapability,
        writeCapable: evidence.writeCapable,
        artifactFamily: evidence.artifactFamily,
        coordinationScope: evidence.coordinationScope,
        mutationPosture: evidence.mutationPosture,
        noWriteBoundary: evidence.noWriteBoundary,
        noWriteReason: evidence.noWriteReason,
        reason: evidence.noWriteReason,
        evidenceOnly: evidence.evidenceOnly,
        noWriteSeverity: evidence.severity,
        ...(evidence.recommendation === undefined
            ? {}
            : {
                nextAction: evidence.recommendation.command,
                recommendedCommand: evidence.recommendation.command,
                recommendationLabel: evidence.recommendation.label,
                recommendationWriteCapable: evidence.recommendation.writeCapable,
                recommendationCapability: evidence.recommendation.capability,
                recommendationArtifactFamily: evidence.recommendation.artifactFamily,
                recommendationMutationPosture: evidence.recommendation.mutationPosture,
                recommendationCoordinationScope: evidence.recommendation.coordinationScope,
                recommendationFollowUpOnly: evidence.recommendation.followUpOnly,
                recommendationBoundary: evidence.recommendation.boundary
            })
    });
}
function classifySourceSpecLifecycleIntent(input, selectedSourceSpecSurface = DEFAULT_SOURCE_SPEC_SURFACE) {
    const normalizedInput = normalizeIntentInput(input);
    const planningAdvancementPhrase = findExplicitIntentPhrase(normalizedInput, exports.PLANNING_ADVANCEMENT_INTENT_PHRASES);
    if (planningAdvancementPhrase !== null) {
        return createSourceSpecIntentClassification({
            intent: "planning-advancement",
            matchedPhrase: planningAdvancementPhrase,
            selectedSourceSpecSurface,
            noDownstreamPlanningWrite: false,
            planningRecoveryCommand: SOURCE_SPEC_PLANNING_RECOVERY_COMMAND,
            planningRecoveryWorkflow: SOURCE_SPEC_PLANNING_RECOVERY_WORKFLOW,
            reason: "The request explicitly selects a planning-advancement lifecycle action."
        });
    }
    const sourceSpecOnlyPhrase = findExplicitIntentPhrase(normalizedInput, exports.SOURCE_SPEC_ONLY_INTENT_PHRASES);
    if (sourceSpecOnlyPhrase !== null) {
        return createSourceSpecIntentClassification({
            intent: "source-spec-only",
            matchedPhrase: sourceSpecOnlyPhrase,
            selectedSourceSpecSurface,
            noDownstreamPlanningWrite: true,
            planningRecoveryCommand: SOURCE_SPEC_PLANNING_RECOVERY_COMMAND,
            planningRecoveryWorkflow: SOURCE_SPEC_PLANNING_RECOVERY_WORKFLOW,
            reason: "Source-spec authoring and revision stop at the selected source-spec surface unless planning advancement is explicit."
        });
    }
    const reviewPhrase = findExplicitIntentPhrase(normalizedInput, exports.SOURCE_SPEC_REVIEW_REFINEMENT_INTENT_PHRASES);
    if (reviewPhrase !== null) {
        return createSourceSpecIntentClassification({
            intent: "review-or-refinement",
            matchedPhrase: reviewPhrase,
            selectedSourceSpecSurface,
            noDownstreamPlanningWrite: true,
            planningRecoveryCommand: SOURCE_SPEC_PLANNING_RECOVERY_COMMAND,
            planningRecoveryWorkflow: SOURCE_SPEC_PLANNING_RECOVERY_WORKFLOW,
            reason: "Source-spec review, hardening, second-pass, improvement, navigation, and completeness discussions are evidence-only or selected-spec-only by default."
        });
    }
    return createSourceSpecIntentClassification({
        intent: "unclassified",
        matchedPhrase: null,
        selectedSourceSpecSurface,
        noDownstreamPlanningWrite: true,
        planningRecoveryCommand: SOURCE_SPEC_PLANNING_RECOVERY_COMMAND,
        planningRecoveryWorkflow: SOURCE_SPEC_PLANNING_RECOVERY_WORKFLOW,
        reason: "No explicit planning-advancement lifecycle phrase was detected."
    });
}
function createSourceSpecLifecycleGateEvidenceDetails(input, options = {}) {
    const classification = classifySourceSpecLifecycleIntent(input, options.selectedSourceSpecSurface);
    const command = options.command ?? "spec";
    const noWriteEvidence = createNoWriteFindingEvidenceDetails(command, {
        severity: options.severity ?? "informational",
        noWriteReason: classification.reason,
        recommendedCommand: classification.planningRecoveryCommand ?? undefined,
        recommendationLabel: "Advance into planning explicitly",
        recommendationBoundary: "Planning advancement is a separate lifecycle action; the current source-spec flow did not create downstream planning artifacts."
    });
    return Object.freeze({
        ...noWriteEvidence,
        sourceSpecIntent: classification.intent,
        matchedSourceSpecPhrase: classification.matchedPhrase,
        selectedSourceSpecSurface: classification.selectedSourceSpecSurface,
        noDownstreamPlanningWrite: classification.noDownstreamPlanningWrite,
        planningRecoveryCommand: classification.planningRecoveryCommand,
        planningRecoveryWorkflow: classification.planningRecoveryWorkflow,
        sourceSpecLifecycleReason: classification.reason
    });
}
function normalizeRequiredText(value, field) {
    const normalized = value?.trim();
    if (normalized === undefined || normalized.length === 0) {
        throw new Error(`Missing command capability ${field}.`);
    }
    return normalized;
}
function normalizeIntentInput(input) {
    return input.toLowerCase().replace(/[-_]+/g, " ").replace(/\s+/g, " ").trim();
}
function findExplicitIntentPhrase(input, phrases) {
    for (const phrase of phrases) {
        const normalizedPhrase = normalizeIntentInput(phrase);
        const phrasePattern = new RegExp(`(^| )${escapeRegExp(normalizedPhrase)}($| )`);
        if (phrasePattern.test(input)) {
            return phrase;
        }
    }
    return null;
}
function escapeRegExp(value) {
    return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function createSourceSpecIntentClassification(classification) {
    return Object.freeze({
        ...classification,
        selectedSourceSpecSurface: normalizeOptionalIntentSurface(classification.selectedSourceSpecSurface)
    });
}
function normalizeOptionalIntentSurface(value) {
    const normalized = value?.trim();
    return normalized === undefined || normalized.length === 0
        ? DEFAULT_SOURCE_SPEC_SURFACE
        : normalized;
}
function requireField(value, command, field) {
    if (value === undefined || value.trim().length === 0) {
        throw new Error(`Command '${command}' is missing required write-capable posture field '${field}'.`);
    }
    return value;
}
