/**
 * FeatureDefinitions — Static definitions for all opt-in features in instar.
 *
 * Each feature registers itself with the FeatureRegistry at startup.
 * Definitions are immutable at runtime — only FeatureState changes.
 *
 * To add a new opt-in feature:
 * 1. Add a FeatureDefinition to this file
 * 2. Export it from BUILTIN_FEATURES
 * 3. Ensure configPath maps to the correct InstarConfig field
 */
export const BUILTIN_FEATURES = [
    // ── Communication ────────────────────────────────────────────────
    {
        id: 'threadline-relay',
        name: 'Agent Network (Threadline)',
        category: 'communication',
        featureVersion: '1.0.0',
        configPath: 'threadline',
        enableAction: { method: 'PATCH', path: '/config', body: { threadline: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { threadline: { enabled: false } } },
        oneLiner: 'Connect to other agents for cross-machine collaboration and messaging.',
        fullDescription: 'The Threadline relay enables agent-to-agent communication over a secure cloud relay. Agents can discover each other, exchange messages, and collaborate on tasks across machines. Messages are end-to-end authenticated with trust levels you control.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'agent identity and public key', destination: 'custom', retention: 'while connected', description: 'Your agent name and public key are shared with the relay server for discovery.' },
            { dataType: 'inter-agent messages', destination: 'custom', retention: 'ephemeral (relay only)', description: 'Messages pass through the relay server but are not stored long-term.' },
        ],
        reversibilityNote: 'Disable anytime by setting threadline.enabled to false in config. Your agent will disconnect from the relay immediately.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User mentions coordinating with another agent or machine',
                surfaceAs: 'suggestion',
                messageTemplate: "I notice you're working across machines. There's an opt-in feature called Agent Network that lets agents discover and message each other securely. Happy to explain more if you're curious.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'publishing-telegraph',
        name: 'Public Publishing (Telegraph)',
        category: 'communication',
        featureVersion: '1.0.0',
        configPath: 'publishing',
        enableAction: { method: 'PATCH', path: '/config', body: { publishing: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { publishing: { enabled: false } } },
        oneLiner: 'Share content as public web pages via Telegraph.',
        fullDescription: 'Publish markdown content as publicly accessible web pages using Telegraph. Useful for sharing reports, documentation, or any content that should be viewable by anyone with the link. Pages are public — anyone with the URL can view them.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'published content', destination: 'custom', retention: 'indefinite (Telegraph servers)', description: 'Content is published to Telegraph and is publicly accessible. Cannot be fully deleted once cached.' },
        ],
        reversibilityNote: 'Disable publishing in config. Existing pages remain on Telegraph but no new pages can be created.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User wants to share content publicly or create a public link',
                surfaceAs: 'suggestion',
                messageTemplate: "I can publish content as public web pages via Telegraph. It's opt-in — the content becomes publicly accessible to anyone with the link.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    // ── Infrastructure ───────────────────────────────────────────────
    {
        id: 'cloudflare-tunnel',
        name: 'Cloudflare Tunnel',
        category: 'infrastructure',
        featureVersion: '1.0.0',
        configPath: 'tunnel',
        enableAction: { method: 'PATCH', path: '/config', body: { tunnel: { enabled: true, type: 'quick' } } },
        disableAction: { method: 'PATCH', path: '/config', body: { tunnel: { enabled: false } } },
        oneLiner: 'Expose your agent server to the internet for remote access.',
        fullDescription: 'Creates a Cloudflare tunnel that makes your local agent server accessible from anywhere. Enables remote access to the dashboard, private views, and API from your phone or other devices. Quick tunnels require no account; named tunnels give you a persistent custom domain.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'HTTP traffic', destination: 'cloudflare', retention: 'transient (tunnel proxy)', description: 'All requests to your agent pass through Cloudflare infrastructure.' },
        ],
        reversibilityNote: 'Disable the tunnel in config or stop the server. Quick tunnels disappear immediately. Named tunnels can be deleted from the Cloudflare dashboard.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User wants to access agent remotely or from mobile',
                surfaceAs: 'suggestion',
                messageTemplate: "There's an opt-in Cloudflare Tunnel feature that would let you access your agent from anywhere — phone, other machines, etc. No account needed for quick tunnels.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'git-backup',
        name: 'Git Backup & Sync',
        category: 'infrastructure',
        featureVersion: '1.0.0',
        configPath: 'gitBackup',
        enableAction: { method: 'PATCH', path: '/config', body: { gitBackup: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { gitBackup: { enabled: false } } },
        oneLiner: 'Automatically version-control and sync agent state via git.',
        fullDescription: 'Enables automatic git commits and pushes of your agent state. Your identity files, memory, config, and job definitions are version-controlled and synced to a remote repository. Supports multi-machine coordination — changes from one machine are pulled and merged on others.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'agent state files', destination: 'custom', retention: 'git history (indefinite)', description: 'Agent state is committed to git and pushed to your configured remote. Includes memory, config, and identity files.' },
        ],
        reversibilityNote: 'Disable in config. Existing git history remains. No new commits or pushes will be made.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User mentions backup, sync, or multi-machine setup',
                surfaceAs: 'suggestion',
                messageTemplate: "I have an opt-in git backup feature that automatically versions and syncs agent state. Useful for backup and multi-machine coordination.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'dashboard-file-viewer',
        name: 'Dashboard File Viewer',
        category: 'infrastructure',
        featureVersion: '1.0.0',
        configPath: 'dashboard.fileViewer',
        enableAction: { method: 'PATCH', path: '/api/files/config', body: { enabled: true } },
        disableAction: { method: 'PATCH', path: '/api/files/config', body: { enabled: false } },
        oneLiner: 'Browse and edit project files from the web dashboard.',
        fullDescription: 'The Files tab in the dashboard lets you browse configured directories with syntax highlighting and rendered markdown. Optionally enable editing for specific paths to make changes from your phone or any browser.',
        consentTier: 'informational',
        dataImplications: [
            { dataType: 'file contents', destination: 'local', description: 'Files are served to your browser over the local server (or tunnel if enabled). No data leaves your machine unless a tunnel is active.' },
        ],
        reversibilityNote: 'Disable the file viewer in dashboard config. Files are only served, never modified unless editing is explicitly enabled for specific paths.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User wants to view or edit files from mobile or browser',
                surfaceAs: 'awareness',
                messageTemplate: 'By the way — the dashboard has a Files tab for browsing and editing project files from any device. No action needed, just letting you know it exists.',
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 3,
            },
        ],
    },
    // ── Intelligence ─────────────────────────────────────────────────
    {
        id: 'evolution-system',
        name: 'Evolution System',
        category: 'intelligence',
        featureVersion: '1.0.0',
        configPath: 'evolution',
        enableAction: { method: 'PATCH', path: '/config', body: { evolution: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { evolution: { enabled: false } } },
        oneLiner: 'Staged self-improvement through proposals, learnings, and gap analysis.',
        fullDescription: 'The evolution system enables structured self-improvement. The agent can submit proposals for behavioral changes, track learnings from interactions, identify capability gaps, and take actions to address them. All changes go through a staged review process.',
        consentTier: 'local',
        dataImplications: [
            { dataType: 'proposals, learnings, and gap analysis', destination: 'local', retention: 'indefinite (on disk)', description: 'Evolution data is stored locally in .instar/evolution/. No data leaves your machine.' },
        ],
        reversibilityNote: 'Disable in config. Evolution data remains on disk but no new proposals, learnings, or actions will be generated.',
        discoveryTriggers: [
            {
                type: 'usage-pattern',
                condition: 'Agent has been running for several sessions and user is engaged with customization',
                surfaceAs: 'awareness',
                messageTemplate: "FYI — there's an opt-in Evolution system that lets me track learnings and propose behavioral improvements over time. Everything stays local on your machine.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'autonomous-evolution',
        name: 'Autonomous Evolution',
        category: 'intelligence',
        featureVersion: '1.0.0',
        configPath: 'evolution.autoImplement',
        prerequisiteFeatures: ['evolution-system'],
        enableAction: { method: 'PATCH', path: '/config', body: { evolution: { autoImplement: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { evolution: { autoImplement: false } } },
        oneLiner: 'Allow the agent to implement approved evolution proposals without asking.',
        fullDescription: 'When enabled, the agent can automatically implement evolution proposals that have been approved. Without this, proposals require explicit user approval before the agent acts on them. This is the highest level of agent autonomy.',
        consentTier: 'self-governing',
        dataImplications: [
            { dataType: 'agent behavior modifications', destination: 'local', description: 'The agent modifies its own configuration and behavioral files based on approved proposals.' },
        ],
        reversibilityNote: 'Disable autoImplement in evolution config. All changes made by the agent are tracked in evolution history and can be reverted.',
        discoveryTriggers: [
            {
                type: 'usage-pattern',
                condition: 'User has been using evolution system actively and has approved multiple proposals manually',
                surfaceAs: 'awareness',
                messageTemplate: "Since you've been actively reviewing evolution proposals, there's an opt-in mode where I can implement approved proposals automatically. You can turn it off anytime.",
                cooldownAfterSurfaceMs: 604800000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 1,
            },
        ],
    },
    // ── Safety ───────────────────────────────────────────────────────
    {
        id: 'external-operation-gate',
        name: 'External Operation Safety',
        category: 'safety',
        featureVersion: '1.0.0',
        configPath: 'externalOperations',
        enableAction: { method: 'PATCH', path: '/config', body: { externalOperations: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { externalOperations: { enabled: false } } },
        oneLiner: 'Classify and gate external operations (email, Slack, GitHub) by risk level.',
        fullDescription: 'The external operation gate intercepts MCP tool calls that interact with external services. It classifies each operation by mutability and reversibility, then decides whether to proceed, block, or require user approval. Includes adaptive trust that elevates permissions as operations succeed.',
        consentTier: 'local',
        dataImplications: [
            { dataType: 'operation classification logs', destination: 'local', retention: '30 days', description: 'Logs of classified operations are stored locally for audit.' },
        ],
        reversibilityNote: 'Disable in config. The gate stops intercepting operations immediately.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User is setting up MCP tools for external services',
                surfaceAs: 'suggestion',
                messageTemplate: "Since you're connecting external services, there's an opt-in safety gate that classifies and controls what the agent can do with them. It prevents accidental destructive actions.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'response-review',
        name: 'Response Review Pipeline',
        category: 'safety',
        featureVersion: '1.0.0',
        configPath: 'responseReview',
        enableAction: { method: 'PATCH', path: '/config', body: { responseReview: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { responseReview: { enabled: false } } },
        oneLiner: 'Review agent responses before delivery for coherence and safety.',
        fullDescription: 'The response review pipeline evaluates agent messages before they reach users. It checks for coherence with the current topic, safety issues, and behavioral alignment. Responses that fail review are flagged or held for manual approval.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'agent responses (for review)', destination: 'anthropic-cli', retention: 'transient (subscription-path call only)', description: 'Responses are sent to Anthropic via the Claude CLI subscription path for evaluation by a reviewer model.' },
        ],
        reversibilityNote: 'Disable in config. Responses will be delivered directly without review.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User concerned about agent response quality or safety',
                surfaceAs: 'suggestion',
                messageTemplate: "There's an opt-in response review system that evaluates my messages before delivery — checking for coherence, safety, and alignment. Uses an LLM reviewer so it does consume API tokens.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'input-guard',
        name: 'Input Guard',
        category: 'safety',
        featureVersion: '1.0.0',
        configPath: 'inputGuard',
        enableAction: { method: 'PATCH', path: '/config', body: { inputGuard: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { inputGuard: { enabled: false } } },
        oneLiner: 'Defend against cross-topic prompt injection in incoming messages.',
        fullDescription: 'The input guard analyzes incoming messages for potential prompt injection attempts — messages that try to manipulate the agent into acting outside its current topic scope. Uses lightweight LLM classification to detect and block suspicious inputs.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'incoming message classifications', destination: 'anthropic-cli', retention: 'transient (subscription-path call only)', description: 'Messages are sent to Anthropic via the Claude CLI subscription path for injection classification.' },
        ],
        reversibilityNote: 'Disable in config. Messages will be delivered without injection analysis.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'Agent is exposed to untrusted input sources or multi-user environments',
                surfaceAs: 'suggestion',
                messageTemplate: "Since your agent handles messages from multiple sources, there's an opt-in input guard that defends against prompt injection. It classifies incoming messages for manipulation attempts.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'feedback-system',
        name: 'Feedback System',
        category: 'communication',
        featureVersion: '1.0.0',
        configPath: 'feedback',
        enableAction: { method: 'PATCH', path: '/config', body: { feedback: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { feedback: { enabled: false } } },
        oneLiner: 'Report bugs and request features to the instar maintainer.',
        fullDescription: 'The feedback system lets the agent submit bug reports, feature requests, and observations to the instar maintainer via a structured API. Feedback is delivered through the configured channel (typically Telegram).',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'bug reports and feature requests', destination: 'custom', retention: 'indefinite (delivered to maintainer)', description: 'Feedback messages are sent to the instar maintainer. They contain descriptions of issues or suggestions, not user data.' },
        ],
        reversibilityNote: 'Disable in config. No new feedback will be sent. Previously sent feedback remains with the maintainer.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'Agent encounters a bug or limitation in instar',
                surfaceAs: 'awareness',
                messageTemplate: 'By the way — I have a feedback system for reporting bugs and requesting features to the instar maintainer. No action needed on your part.',
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'baseline-telemetry',
        name: 'Baseline Telemetry',
        category: 'infrastructure',
        featureVersion: '1.0.0',
        configPath: 'monitoring.telemetry',
        enableAction: { method: 'POST', path: '/telemetry/enable', body: {} },
        disableAction: { method: 'POST', path: '/telemetry/disable', body: {} },
        oneLiner: 'See how your agent compares to the population — anonymously.',
        fullDescription: 'Baseline collects anonymous, structural metrics about job behavior (skip rates, durations, model usage, schedule adherence) and submits them every 6 hours to a central aggregation service. No content, names, paths, or prompts are ever collected. Your agent gets a random UUID identity that cannot be traced back to you. Every submission is logged locally for your review. You can disable at any time and request remote data deletion.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'job skip rates with reasons', destination: 'custom', retention: '30 days (remote and local)', description: 'How often each job is skipped and why (quota, priority, disabled, etc.).' },
            { dataType: 'job durations and results', destination: 'custom', retention: '30 days', description: 'How long jobs run and whether they succeed, fail, or timeout.' },
            { dataType: 'model usage per job', destination: 'custom', retention: '30 days', description: 'Which model tier each job uses.' },
            { dataType: 'agent version and feature flags', destination: 'custom', retention: '30 days', description: 'Instar version, OS, and which opt-in features are enabled (curated whitelist, never security flags).' },
        ],
        reversibilityNote: 'Disable with `instar telemetry disable`. Your local identity is deleted immediately and remote data deletion is requested. Re-enabling creates a new identity — prior history is not recoverable.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'User or agent investigating job performance, skip rates, or wanting to know if behavior is normal',
                surfaceAs: 'suggestion',
                messageTemplate: "I'm seeing patterns in job behavior but I don't know if they're normal across other agents. There's an opt-in Baseline feature that anonymously compares your agent's metrics to the population. No content is ever collected — just structural data like skip rates and durations.",
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
    {
        id: 'dispatches',
        name: 'Dispatch System',
        category: 'intelligence',
        featureVersion: '1.0.0',
        configPath: 'dispatches',
        enableAction: { method: 'PATCH', path: '/config', body: { dispatches: { enabled: true } } },
        disableAction: { method: 'PATCH', path: '/config', body: { dispatches: { enabled: false } } },
        oneLiner: 'Receive behavioral instructions and updates from the instar maintainer.',
        fullDescription: 'The dispatch system allows the agent to receive behavioral instructions, configuration updates, and guidance from the instar maintainer. Dispatches are pulled from a central API and applied automatically or after review, depending on your autonomy profile.',
        consentTier: 'network',
        dataImplications: [
            { dataType: 'dispatch instructions', destination: 'custom', retention: 'stored locally after receipt', description: 'Instructions are fetched from the dispatch API. Your agent identity is sent to authenticate the request.' },
        ],
        reversibilityNote: 'Disable in config. No new dispatches will be fetched. Previously applied dispatches remain in effect until manually reverted.',
        discoveryTriggers: [
            {
                type: 'problem-match',
                condition: 'Agent is newly set up and needs configuration guidance',
                surfaceAs: 'awareness',
                messageTemplate: 'FYI — there\'s a dispatch system that lets the instar maintainer send behavioral guidance and updates to agents. It\'s how agents stay in sync with platform improvements.',
                cooldownAfterSurfaceMs: 86400000,
                cooldownAfterDeclineMs: 2592000000,
                maxSurfacesBeforeQuiet: 2,
            },
        ],
    },
];
//# sourceMappingURL=FeatureDefinitions.js.map