// Boundary rules for crate dependencies and lightweight profiles.

const agentRuntimeIpcForbiddenDeps = [
  'bitfun-acp',
  'bitfun-agent-runtime',
  'bitfun-agent-stream',
  'bitfun-agent-tools',
  'bitfun-ai-adapters',
  'bitfun-claude-code-adapter',
  'bitfun-codex-adapter',
  'bitfun-core',
  'bitfun-core-types',
  'bitfun-dsh-adapter',
  'bitfun-external-sources',
  'bitfun-harness',
  'bitfun-opencode-adapter',
  'bitfun-page-function-runtime',
  'bitfun-plugin-runtime-client',
  'bitfun-product-capabilities',
  'bitfun-relay-service',
  'bitfun-runtime-services',
  'bitfun-sdk-host',
  'bitfun-services-core',
  'bitfun-services-integrations',
  'bitfun-static-hook-support',
  'bitfun-tool-call-jsonrepair',
  'bitfun-tool-packs',
  'bitfun-webdriver',
  'terminal-core',
  'tool-runtime',
  'tauri',
  'reqwest',
  'tokio-tungstenite',
  'bitfun-cli',
  'ratatui',
  'crossterm',
  'arboard',
  'syntect-tui',
];

export const noCoreDependencyCrates = [
  'agent-content',
  'core-types',
  'events',
  'ai-adapters',
  'agent-stream',
  'tool-call-jsonrepair',
  'agent-runtime',
  'agent-runtime-ipc',
  'app-server-client',
  'app-server-protocol',
  'harness',
  'plugin-runtime-client',
  'product-capabilities',
  'runtime-ports',
  'runtime-services',
  'sdk-host',
  'services-core',
  'services-integrations',
  'agent-tools',
  'tool-packs',
  'product-domains',
  'claude-code-adapter',
  'codex-adapter',
  'dsh-adapter',
  'opencode-adapter',
  'opencode-plugin-host',
  'static-hook-support',
  'external-sources',
  'terminal',
  'tool-runtime',
  'transport',
  'webdriver',
];

export const forbiddenManifestDependencyRules = [
  {
    dependencyNames: ['rmcp'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    forbidWorkspaceAliases: false,
    allowManifestPaths: [
      'src/crates/services/services-integrations/Cargo.toml',
    ],
    reason: 'the RMCP SDK is a concrete MCP integration service dependency',
    message: 'rmcp must stay in services-integrations and be consumed through its MCP owner facade',
  },
  {
    dependencyNames: ['bitfun-agent-runtime-ipc'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    allowManifestPaths: ['src/apps/cli/Cargo.toml'],
    reason: 'the private local IPC protocol has one reviewed first-party Shared TUI consumer',
    message:
      'agent-runtime-ipc may only be consumed by the CLI Shared TUI adapter; SDK Host, GUI, remote, and other products require separate review',
  },
  {
    dependencyNames: ['sherpa-onnx'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    forbidWorkspaceAliases: false,
    allowManifestPaths: [
      'src/crates/services/services-integrations/Cargo.toml',
    ],
    reason:
      'speech recognition engines are concrete integration service dependencies',
    message:
      'sherpa-onnx must stay in services-integrations and be injected by a product composition root',
  },
  {
    dependencyNames: ['bitfun-opencode-adapter'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    allowManifestPaths: [
      'src/crates/adapters/opencode-adapter/Cargo.toml',
      'src/crates/assembly/core/Cargo.toml',
    ],
    reason:
      'OpenCode adapter production dependencies are limited to the reviewed product composition root',
    message:
      'only bitfun-core product-full assembly may register bitfun-opencode-adapter through reviewed capability composition roots',
  },
  {
    dependencyNames: ['bitfun-dsh-adapter'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    allowManifestPaths: [
      'src/crates/adapters/dsh-adapter/Cargo.toml',
      'src/crates/assembly/core/Cargo.toml',
    ],
    reason:
      'DeepSeek Harness adapter production dependencies are limited to the reviewed product composition root',
    message:
      'only bitfun-core product-full assembly may register bitfun-dsh-adapter through reviewed capability composition roots',
  },
  {
    dependencyNames: ['bitfun-opencode-plugin-host'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    allowManifestPaths: [
      'src/crates/adapters/opencode-plugin-host/Cargo.toml',
      'src/crates/assembly/core/Cargo.toml',
    ],
    reason:
      'OpenCode plugin host process dependencies are limited to the reviewed product composition root',
    message:
      'only bitfun-core product-full assembly may register bitfun-opencode-plugin-host',
  },
  ...[
    ['bitfun-claude-code-adapter', 'claude-code-adapter'],
    ['bitfun-codex-adapter', 'codex-adapter'],
  ].map(([dependencyName, crateName]) => ({
    dependencyNames: [dependencyName],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    allowManifestPaths: [
      `src/crates/adapters/${crateName}/Cargo.toml`,
      'src/crates/assembly/core/Cargo.toml',
    ],
    reason: `${crateName} production dependencies are limited to the reviewed product composition root`,
    message: `only bitfun-core product-full assembly may register ${dependencyName} through the static Hook provider boundary`,
  })),
  {
    dependencyNames: ['bitfun-static-hook-support'],
    scanRoots: ['src/apps', 'src/crates', 'BitFun-Installer/src-tauri'],
    workspaceManifestPath: 'Cargo.toml',
    allowManifestPaths: [
      'src/crates/adapters/static-hook-support/Cargo.toml',
      'src/crates/adapters/opencode-adapter/Cargo.toml',
      'src/crates/adapters/claude-code-adapter/Cargo.toml',
      'src/crates/adapters/codex-adapter/Cargo.toml',
    ],
    reason: 'static Hook parsing support is private to ecosystem source adapters',
    message: 'static Hook support may only be consumed by reviewed ecosystem Hook adapters',
  },
];

export const lightweightBoundaryRules = [
  {
    crateName: 'app-server-protocol',
    reason:
      'App Server wire contracts must stay behavior-light and independent of Runtime, Core, services, product assembly, and UI implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-agent-runtime',
      'bitfun-agent-runtime-ipc',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-runtime-services',
      'bitfun-product-capabilities',
      'bitfun-external-sources',
      'bitfun-app-server',
      'bitfun-app-server-client',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
    ],
  },
  {
    crateName: 'app-server-client',
    reason:
      'App Server Rich Client support may depend on wire contracts and transport scaffolding but not backend or UI implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-agent-runtime',
      'bitfun-agent-runtime-ipc',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-runtime-services',
      'bitfun-product-capabilities',
      'bitfun-external-sources',
      'bitfun-app-server',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
    ],
  },
  {
    crateName: 'agent-runtime-ipc',
    reason:
      'agent-runtime-ipc is the non-published local protocol for the reviewed Shared TUI adapter, not a Runtime, SDK Host, service, or remote product surface',
    forbiddenDeps: agentRuntimeIpcForbiddenDeps,
  },
  {
    crateName: 'core-types',
    reason: 'core-types must stay low-level DTO-only',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-events',
      'bitfun-ai-adapters',
      'bitfun-agent-stream',
      'bitfun-runtime-ports',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'runtime-ports',
    reason: 'runtime-ports must stay DTO/trait-only',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-agent-stream',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'runtime-services',
    reason: 'runtime-services must stay a typed service assembly contract without concrete runtime implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-agent-stream',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'agent-runtime',
    reason: 'agent-runtime must own portable runtime decisions without concrete service or product implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-tool-packs',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'sdk-host',
    reason:
      'SDK Host protocol must stay a portable Runtime adapter without concrete product, terminal, service, or CLI implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-sdk-host-app',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'harness',
    reason:
      'harness must own workflow contracts without concrete service, product, or platform implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-tool-packs',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'plugin-runtime-client',
    reason:
      'plugin-runtime-client must implement the portable PluginRuntimeClient boundary without concrete ecosystem, product, or platform implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-opencode-adapter',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'product-capabilities',
    reason:
      'product-capabilities must own product capability assembly facts without concrete runtime implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-agent-tools',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'agent-tools',
    reason: 'agent-tools must not depend on concrete service or product runtime implementations',
    forbiddenDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-tool-packs',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
];

export const dependencyProfileRules = [
  {
    crateName: 'agent-runtime-ipc',
    profileName: 'private Shared TUI local IPC profile',
    reason:
      'agent-runtime-ipc may share stable DTO contracts and protocol-neutral bitfun-transport mechanics but must not acquire Runtime owners, SDK Host, services, remote transports, or product implementations',
    forbiddenNonOptionalDeps: agentRuntimeIpcForbiddenDeps,
  },
  {
    crateName: 'core',
    profileName: 'no-default runtime-surface-light profile',
    reason:
      'bitfun-core no-default profile must not force product/runtime integration dependencies',
    forbiddenNonOptionalDeps: [
      'aes',
      'aes-gcm',
      'bitfun-services-integrations',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-agent-tools',
      'bitfun-relay-service',
      'bitfun-tool-packs',
      'chrono-tz',
      'cron',
      'dashmap',
      'eventsource-stream',
      'filetime',
      'flate2',
      'fluent-bundle',
      'fs2',
      'git2',
      'glob',
      'globset',
      'hostname',
      'htmd',
      'image',
      'include_dir',
      'indexmap',
      'legible',
      'local-ip-address',
      'mac_address',
      'md5',
      'notify',
      'qrcode',
      'rand',
      'readability-js',
      'rmcp',
      'rusqlite',
      'russh',
      'rustls',
      'rustls-native-certs',
      'schannel',
      'sse-stream',
      'similar',
      'serde_yaml',
      'terminal-core',
      'tool-runtime',
      'tokio-tungstenite',
      'bitfun-transport',
      'unic-langid',
      'win32job',
      'x25519-dalek',
    ],
  },
  {
    crateName: 'services-core',
    profileName: 'default reusable service profile',
    reason:
      'services-core default profile must not compile capability-specific native or runtime implementations',
    forbiddenNonOptionalDeps: [
      'anyhow',
      'async-trait',
      'base64',
      'bitfun-core-types',
      'bitfun-events',
      'bitfun-runtime-ports',
      'chrono',
      'dunce',
      'fs2',
      'git2',
      'globset',
      'ignore',
      'libc',
      'notify',
      'regex',
      'rusqlite',
      'serde_yaml',
      'sha2',
      'similar',
      'which',
      'win32job',
      'windows',
      'zip',
    ],
  },
  {
    crateName: 'core-types',
    profileName: 'default DTO profile',
    reason: 'core-types default profile must stay DTO-only',
    forbiddenNonOptionalDeps: [
      'bitfun-core',
      'bitfun-events',
      'bitfun-ai-adapters',
      'bitfun-agent-stream',
      'bitfun-runtime-ports',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'runtime-ports',
    profileName: 'default ports profile',
    reason: 'runtime-ports default profile must stay trait/DTO-only',
    forbiddenNonOptionalDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-agent-stream',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'runtime-services',
    profileName: 'default runtime service assembly profile',
    reason: 'runtime-services default profile must not compile concrete service or product runtime implementations',
    forbiddenNonOptionalDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-agent-stream',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'agent-runtime',
    profileName: 'default agent runtime decision profile',
    reason: 'agent-runtime default profile must not compile concrete services or product surfaces',
    forbiddenNonOptionalDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-tool-packs',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'plugin-runtime-client',
    profileName: 'default plugin runtime client boundary profile',
    reason:
      'plugin-runtime-client default profile must not compile concrete plugin execution or product-surface implementations',
    forbiddenNonOptionalDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-opencode-adapter',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-agent-tools',
      'bitfun-tool-packs',
      'bitfun-product-capabilities',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'agent-tools',
    profileName: 'tool contract-only profile',
    reason: 'agent-tools must stay a lightweight tool contract crate',
    forbiddenNonOptionalDeps: [
      'bitfun-ai-adapters',
      'bitfun-product-capabilities',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'tauri',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'product-capabilities',
    profileName: 'default product capability profile',
    reason: 'product-capabilities default profile must stay assembly-fact only',
    forbiddenNonOptionalDeps: [
      'bitfun-core',
      'bitfun-ai-adapters',
      'bitfun-agent-tools',
      'bitfun-services-core',
      'bitfun-services-integrations',
      'bitfun-product-domains',
      'bitfun-transport',
      'terminal-core',
      'tool-runtime',
      'tauri',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'product-domains',
    profileName: 'default product domain profile',
    reason: 'product-domains default profile must not compile runtime/platform helpers',
    forbiddenNonOptionalDeps: [
      'dirs',
      'log',
      'sha2',
      'which',
      'reqwest',
      'git2',
      'rmcp',
      'image',
      'tokio-tungstenite',
      'tauri',
      'bitfun-cli',
      'ratatui',
      'crossterm',
      'arboard',
      'syntect-tui',
    ],
  },
  {
    crateName: 'services-integrations',
    profileName: 'default integrations profile',
    reason: 'services-integrations default profile must not compile feature-gated integrations',
    forbiddenNonOptionalDeps: [
      'aes',
      'aes-gcm',
      'anyhow',
      'async-trait',
      'base64',
      'bitfun-product-domains',
      'bitfun-runtime-ports',
      'bitfun-services-core',
      'chrono',
      'dunce',
      'futures',
      'git2',
      'hex',
      'local-ip-address',
      'md5',
      'notify',
      'rand',
      'reqwest',
      'rmcp',
      'sha2',
      'sse-stream',
      'thiserror',
      'tokio-util',
      'tokio-tungstenite',
      'uuid',
      'which',
    ],
  },
];