"use strict";
/**
 * agent-manifest — Machine-readable description of the CLI surface.
 *
 * Exposed via `amplitude-wizard help --json` so AI coding agents can
 * introspect the available commands, flags, env vars, and exit codes
 * without parsing human help text.
 *
 * Kept hand-maintained (rather than auto-generated from yargs internals)
 * so it stays a stable contract that changes only intentionally.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAgentManifest = getAgentManifest;
function getAgentManifest() {
    return {
        schemaVersion: 1,
        bin: 'amplitude-wizard',
        package: '@amplitude/wizard',
        invocations: [
            {
                argv: ['npx', '@amplitude/wizard'],
                describe: 'Works without installation (recommended for agents)',
                requiresGlobalInstall: false,
            },
            {
                argv: ['amplitude-wizard'],
                describe: 'Direct bin — requires `npm install -g @amplitude/wizard`',
                requiresGlobalInstall: true,
            },
        ],
        description: 'Interactive CLI that instruments apps with Amplitude analytics.',
        concepts: {
            hierarchy: ['org', 'project', 'app', 'environment'],
            glossary: [
                {
                    term: 'org',
                    describe: 'An Amplitude organization (account-level). Identified by a UUID. Canonical backend term: `org_id` (Python) / `orgId` (TS). Auto-derived from --app-id — agents should not pass --org directly.',
                },
                {
                    term: 'project',
                    describe: 'A tracking-plan container inside an org (holds branches, tickets, and observed schema). Identified by a UUID. Auto-derived from --app-id — agents should not pass --project-id directly. Note: the backend still refers to this as a "workspace" internally.',
                },
                {
                    term: 'app',
                    describe: 'An Amplitude app — the ingestion surface that owns an API key and receives events. Identified by a numeric ID (e.g. 769610). Canonical across amplitude/amplitude (`app_id`, `orgs` table has `supports_cross_app`) and amplitude/javascript (`export type App`, `appId`). Amplitude\'s UI labels the same numeric ID "Project ID". Pass --app-id <id> — this is the only scope flag agents need.',
                },
                {
                    term: 'environment',
                    describe: 'A named runtime mode of an app (e.g. "Production", "Development", "Staging"). Not a POSIX environment variable. Each env has its own app.id and API key, so --app-id already identifies one env. Auto-selected from --app-id.',
                },
                {
                    term: 'API key',
                    describe: 'An app-level ingestion key embedded into client code (amplitude.init("<key>")). Fetched automatically after `amplitude-wizard login`; agents should not pass one directly.',
                },
                {
                    term: 'access token',
                    describe: 'An OAuth access token minted by `amplitude-wizard login`. Used for server-side API calls, never embedded in client code. Passed with AMPLITUDE_TOKEN.',
                },
            ],
        },
        globalFlags: [
            {
                name: '--agent',
                describe: 'NDJSON output, auto-approve prompts (best for AI coding agents)',
                type: 'boolean',
                default: false,
            },
            {
                name: '--json',
                describe: 'Emit machine-readable JSON output (implied when piped). Unlike --agent, does not auto-approve prompts.',
                type: 'boolean',
                default: false,
            },
            {
                name: '--human',
                describe: 'Force human-readable output (overrides --json auto-detect)',
                type: 'boolean',
                default: false,
            },
            {
                name: '--ci',
                describe: 'Run non-interactively (no prompts, no colors)',
                type: 'boolean',
                default: false,
            },
            {
                name: '--yes',
                describe: 'Skip all prompts and grant the inner agent write capability. Required for the `apply` subcommand. Distinct from --auto-approve, which only picks defaults on `needs_input`.',
                type: 'boolean',
                default: false,
            },
            {
                name: '--auto-approve',
                describe: 'Silently pick the recommended choice on `needs_input` prompts. Does NOT grant write capability — pair with --yes to allow file writes.',
                type: 'boolean',
                default: false,
            },
            {
                name: '--force',
                describe: 'Allow destructive writes (overwrite/delete existing files). Implies --yes.',
                type: 'boolean',
                default: false,
            },
            {
                name: '--install-dir',
                describe: 'Project directory to inspect or instrument',
                type: 'string',
            },
            {
                name: '--app-id',
                describe: 'Amplitude app ID (numeric, e.g. 769610). The only scope flag agents need — org, project, and environment are derived automatically. See concepts.glossary.',
                type: 'string',
            },
            {
                name: '--app-name',
                describe: 'Name for a new Amplitude app (creates one when no apps exist, or with --ci/--agent).',
                type: 'string',
            },
            {
                name: '--debug',
                describe: 'Enable debug logging',
                type: 'boolean',
                default: false,
            },
        ],
        env: [
            {
                name: 'AMPLITUDE_TOKEN',
                describe: 'OAuth access-token override (requires prior `amplitude-wizard login`)',
            },
            {
                name: 'AMPLITUDE_WIZARD_TOKEN',
                describe: 'Alias for AMPLITUDE_TOKEN',
            },
            {
                name: 'AMPLITUDE_WIZARD_AGENT',
                describe: 'Set to 1 to force agent mode (NDJSON output, auto-approve)',
            },
            {
                name: 'AMPLITUDE_WIZARD_DEBUG',
                describe: 'Set to 1 to enable debug logging',
            },
            {
                name: 'AMPLITUDE_WIZARD_LOG',
                describe: 'Path to write logs to',
            },
            {
                name: 'AMPLITUDE_WIZARD_ALLOW_NESTED',
                describe: 'Set to 1 to skip the nested-invocation diagnostic. The wizard sanitizes inherited outer-agent env vars either way, so nesting works by default.',
            },
            {
                name: 'AMPLITUDE_WIZARD_MAX_TURNS',
                describe: "Override the inner agent's per-run turn cap (default 200, sanity-bounded at 10000). Useful for unusually long-running setups.",
            },
        ],
        exitCodes: [
            { code: 0, name: 'SUCCESS', describe: 'Completed successfully' },
            { code: 1, name: 'GENERAL_ERROR', describe: 'Unclassified error' },
            { code: 2, name: 'INVALID_ARGS', describe: 'Invalid flags or arguments' },
            {
                code: 3,
                name: 'AUTH_REQUIRED',
                describe: 'Not logged in; run `amplitude-wizard login` first',
            },
            {
                code: 4,
                name: 'NETWORK_ERROR',
                describe: 'Could not reach Amplitude or a required service',
            },
            {
                code: 10,
                name: 'AGENT_FAILED',
                describe: 'The AI-powered setup agent failed mid-run',
            },
            {
                code: 130,
                name: 'USER_CANCELLED',
                describe: 'User cancelled (Ctrl-C or prompt rejection)',
            },
        ],
        commands: [
            {
                command: '(default)',
                describe: 'Run the full interactive setup wizard',
                outputs: 'human',
            },
            {
                command: 'detect',
                describe: 'Detect the framework used in the current project',
                outputs: 'both',
                flags: [
                    {
                        name: '--install-dir',
                        describe: 'Project directory to inspect',
                        type: 'string',
                    },
                ],
            },
            {
                command: 'status',
                describe: 'Report project setup state: framework, SDK installed, API key, auth',
                outputs: 'both',
                flags: [
                    {
                        name: '--install-dir',
                        describe: 'Project directory to inspect',
                        type: 'string',
                    },
                ],
            },
            {
                command: 'plan',
                describe: 'Plan an Amplitude setup without making any changes (emits a structured WizardPlan + planId; planId is valid for 24h, pass it to `apply` to execute)',
                outputs: 'both',
                flags: [
                    {
                        name: '--install-dir',
                        describe: 'Project directory to plan against',
                        type: 'string',
                    },
                ],
            },
            {
                command: 'apply',
                describe: 'Execute a previously generated plan. Requires --plan-id and --yes; pair with --force for destructive overwrites.',
                outputs: 'both',
                flags: [
                    {
                        name: '--plan-id',
                        describe: 'plan ID returned by `amplitude-wizard plan`',
                        type: 'string',
                    },
                    {
                        name: '--install-dir',
                        describe: 'Project directory the plan was generated against',
                        type: 'string',
                    },
                ],
            },
            {
                command: 'verify',
                describe: 'Verify a project setup without running the agent (no-network check that SDK + API key + framework are all in place). Exits non-zero on failure.',
                outputs: 'both',
                flags: [
                    {
                        name: '--install-dir',
                        describe: 'Project directory to verify',
                        type: 'string',
                    },
                ],
            },
            {
                command: 'auth status',
                describe: 'Show current login state',
                outputs: 'both',
            },
            {
                command: 'auth token',
                describe: 'Print the stored OAuth access token to stdout (for scripts)',
                outputs: 'both',
            },
            {
                command: 'login',
                describe: 'Authenticate with Amplitude via browser OAuth',
                outputs: 'human',
            },
            {
                command: 'logout',
                describe: 'Clear stored credentials',
                outputs: 'human',
            },
            {
                command: 'whoami',
                describe: 'Show logged-in user (legacy; prefer `auth status --json`)',
                outputs: 'human',
            },
            {
                command: 'mcp add',
                describe: 'Install the Amplitude MCP server into your editor',
                outputs: 'human',
            },
            {
                command: 'mcp remove',
                describe: 'Remove the Amplitude MCP server from your editor',
                outputs: 'human',
            },
            {
                command: 'mcp serve',
                describe: 'Run the Amplitude wizard MCP server on stdio (for AI coding agents)',
                outputs: 'json',
            },
            {
                command: 'manifest',
                describe: 'Print this machine-readable CLI manifest',
                outputs: 'json',
            },
        ],
        ndjsonSchemaVersion: 1,
    };
}
