All files / agent/src/recipes builtinRecipes.ts

100% Statements 707/707
100% Branches 0/0
100% Functions 0/0
100% Lines 707/707

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 7081x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Built-in Recipe Definitions
 *
 * 15 production-ready recipes covering the most common CI ecosystems.
 * Each recipe provides sensible defaults for detection, execution,
 * caching, artifacts, and lifecycle hooks.
 */
 
import { Recipe } from './types.js';
 
// ---------------------------------------------------------------------------
// 1. Android (Gradle)
// ---------------------------------------------------------------------------
const androidGradle: Recipe = {
  name: 'android-gradle',
  description: 'Android project built with Gradle (APK / AAB)',
  version: '1.0.0',
  detection: {
    files: ['build.gradle', 'build.gradle.kts', 'settings.gradle', 'settings.gradle.kts'],
    contentPatterns: [
      { file: 'build.gradle', pattern: 'com.android.application' },
      { file: 'build.gradle.kts', pattern: 'com.android.application' },
      { file: 'settings.gradle', pattern: 'android' },
      { file: 'settings.gradle.kts', pattern: 'android' },
    ],
    priority: 50,
  },
  executionMode: 'docker',
  dockerImage: 'cimg/android:2024.04.1',
  requiredMemoryGB: 8,
  timeoutMinutes: 30,
  defaultBuildCommand: './gradlew assembleRelease --no-daemon --stacktrace',
  setup: [
    { name: 'Accept SDK licenses', command: 'yes | sdkmanager --licenses || true', timeout: 60, continueOnError: true },
    { name: 'Download dependencies', command: './gradlew dependencies --no-daemon', timeout: 300 },
  ],
  teardown: [
    { name: 'Cleanup Gradle daemons', command: './gradlew --stop || true', continueOnError: true },
  ],
  cache: {
    key: "gradle-${hashFiles('**/*.gradle*', '**/gradle-wrapper.properties')}",
    paths: [
      '~/.gradle/caches',
      '~/.gradle/wrapper',
      '~/.android/build-cache',
    ],
    restoreKeys: ['gradle-'],
    maxSizeMB: 2048,
  },
  artifacts: {
    paths: [
      '**/build/outputs/apk/**/*.apk',
      '**/build/outputs/bundle/**/*.aab',
      '**/build/reports/**',
    ],
    expireAfterDays: 14,
  },
  environment: {
    GRADLE_OPTS: '-Dorg.gradle.daemon=false -Xmx4g -XX:+HeapDumpOnOutOfMemoryError',
    ANDROID_HOME: '/opt/android/sdk',
  },
  variables: {
    buildVariant: { default: 'Release', description: 'Android build variant (Debug, Release, etc.)' },
    gradleTask: { default: 'assembleRelease', description: 'Gradle task to execute' },
  },
};
 
// ---------------------------------------------------------------------------
// 2. iOS (Xcode)
// ---------------------------------------------------------------------------
const iosXcode: Recipe = {
  name: 'ios-xcode',
  description: 'iOS / macOS project built with Xcode (IPA / app bundle)',
  version: '1.0.0',
  detection: {
    files: ['*.xcodeproj', '*.xcworkspace', 'Podfile', 'Package.swift'],
    contentPatterns: [],
    priority: 60,
  },
  executionMode: 'native',
  requiredOS: 'darwin',
  requiredMemoryGB: 8,
  timeoutMinutes: 45,
  defaultBuildCommand:
    'xcodebuild -workspace *.xcworkspace -scheme ${SCHEME:-App} -configuration Release -archivePath build/App.xcarchive archive CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO',
  setup: [
    { name: 'Install CocoaPods', command: 'bundle install && bundle exec pod install || pod install', timeout: 300, continueOnError: true },
    { name: 'Select Xcode version', command: 'sudo xcode-select -s /Applications/Xcode.app/Contents/Developer || true', timeout: 30, continueOnError: true },
  ],
  teardown: [
    { name: 'Cleanup DerivedData', command: 'rm -rf ~/Library/Developer/Xcode/DerivedData || true', continueOnError: true },
  ],
  cache: {
    key: "pods-${hashFiles('**/Podfile.lock')}",
    paths: [
      'Pods',
      '~/.cocoapods',
      '~/Library/Developer/Xcode/DerivedData',
    ],
    restoreKeys: ['pods-'],
    maxSizeMB: 4096,
  },
  artifacts: {
    paths: [
      'build/**/*.xcarchive',
      'build/**/*.ipa',
      'build/**/*.app',
    ],
    expireAfterDays: 14,
  },
  environment: {
    DEVELOPER_DIR: '/Applications/Xcode.app/Contents/Developer',
  },
  variables: {
    scheme: { default: 'App', description: 'Xcode scheme name' },
    configuration: { default: 'Release', description: 'Build configuration (Debug / Release)' },
  },
};
 
// ---------------------------------------------------------------------------
// 3. Node.js (npm)
// ---------------------------------------------------------------------------
const nodejsNpm: Recipe = {
  name: 'nodejs-npm',
  description: 'Node.js project using npm',
  version: '1.0.0',
  detection: {
    files: ['package-lock.json'],
    priority: 40,
  },
  executionMode: 'docker',
  dockerImage: 'node:20-alpine',
  requiredMemoryGB: 4,
  timeoutMinutes: 15,
  defaultBuildCommand: 'npm ci && npm run build',
  setup: [
    { name: 'Verify Node version', command: 'node --version && npm --version', timeout: 10 },
  ],
  cache: {
    key: "npm-${hashFiles('**/package-lock.json')}",
    paths: ['~/.npm', 'node_modules'],
    restoreKeys: ['npm-'],
    maxSizeMB: 1024,
  },
  artifacts: {
    paths: ['dist/**', 'build/**'],
    expireAfterDays: 7,
  },
  environment: {
    NODE_ENV: 'production',
    CI: 'true',
  },
  variables: {
    nodeVersion: { default: '20', description: 'Node.js major version' },
    buildScript: { default: 'build', description: 'npm script name to run' },
  },
};
 
// ---------------------------------------------------------------------------
// 4. Node.js (Yarn)
// ---------------------------------------------------------------------------
const nodejsYarn: Recipe = {
  name: 'nodejs-yarn',
  description: 'Node.js project using Yarn',
  version: '1.0.0',
  detection: {
    files: ['yarn.lock'],
    priority: 45,
  },
  executionMode: 'docker',
  dockerImage: 'node:20-alpine',
  requiredMemoryGB: 4,
  timeoutMinutes: 15,
  defaultBuildCommand: 'yarn install --frozen-lockfile && yarn build',
  setup: [
    { name: 'Verify Yarn version', command: 'node --version && yarn --version', timeout: 10 },
  ],
  cache: {
    key: "yarn-${hashFiles('**/yarn.lock')}",
    paths: ['~/.yarn/cache', '.yarn/cache', 'node_modules'],
    restoreKeys: ['yarn-'],
    maxSizeMB: 1024,
  },
  artifacts: {
    paths: ['dist/**', 'build/**'],
    expireAfterDays: 7,
  },
  environment: {
    NODE_ENV: 'production',
    CI: 'true',
  },
  variables: {
    nodeVersion: { default: '20', description: 'Node.js major version' },
    buildScript: { default: 'build', description: 'Yarn script name to run' },
  },
};
 
// ---------------------------------------------------------------------------
// 5. Python (pip)
// ---------------------------------------------------------------------------
const pythonPip: Recipe = {
  name: 'python-pip',
  description: 'Python project using pip / setuptools',
  version: '1.0.0',
  detection: {
    files: ['requirements.txt', 'setup.py', 'setup.cfg'],
    priority: 30,
  },
  executionMode: 'docker',
  dockerImage: 'python:3.12-slim',
  requiredMemoryGB: 2,
  timeoutMinutes: 15,
  defaultBuildCommand: 'pip install -r requirements.txt && python -m pytest',
  setup: [
    { name: 'Upgrade pip', command: 'pip install --upgrade pip setuptools wheel', timeout: 60 },
  ],
  cache: {
    key: "pip-${hashFiles('**/requirements*.txt')}",
    paths: ['~/.cache/pip'],
    restoreKeys: ['pip-'],
    maxSizeMB: 512,
  },
  artifacts: {
    paths: ['dist/**', '*.whl', '*.tar.gz'],
    expireAfterDays: 7,
  },
  environment: {
    PYTHONDONTWRITEBYTECODE: '1',
    PIP_NO_CACHE_DIR: '0',
  },
  variables: {
    pythonVersion: { default: '3.12', description: 'Python version' },
  },
};
 
// ---------------------------------------------------------------------------
// 6. Python (Poetry)
// ---------------------------------------------------------------------------
const pythonPoetry: Recipe = {
  name: 'python-poetry',
  description: 'Python project using Poetry',
  version: '1.0.0',
  detection: {
    files: ['poetry.lock'],
    contentPatterns: [
      { file: 'pyproject.toml', pattern: 'tool.poetry' },
    ],
    priority: 35,
  },
  executionMode: 'docker',
  dockerImage: 'python:3.12-slim',
  requiredMemoryGB: 2,
  timeoutMinutes: 15,
  defaultBuildCommand: 'poetry install --no-interaction && poetry run pytest',
  setup: [
    { name: 'Install Poetry', command: 'pip install poetry', timeout: 60 },
    { name: 'Configure Poetry', command: 'poetry config virtualenvs.in-project true', timeout: 10 },
  ],
  cache: {
    key: "poetry-${hashFiles('**/poetry.lock')}",
    paths: ['~/.cache/pypoetry', '.venv'],
    restoreKeys: ['poetry-'],
    maxSizeMB: 512,
  },
  artifacts: {
    paths: ['dist/**'],
    expireAfterDays: 7,
  },
  environment: {
    PYTHONDONTWRITEBYTECODE: '1',
    POETRY_VIRTUALENVS_IN_PROJECT: 'true',
  },
  variables: {
    pythonVersion: { default: '3.12', description: 'Python version' },
  },
};
 
// ---------------------------------------------------------------------------
// 7. Go (Module)
// ---------------------------------------------------------------------------
const goModule: Recipe = {
  name: 'go-module',
  description: 'Go project using Go Modules',
  version: '1.0.0',
  detection: {
    files: ['go.mod'],
    priority: 40,
  },
  executionMode: 'docker',
  dockerImage: 'golang:1.22-alpine',
  requiredMemoryGB: 4,
  timeoutMinutes: 15,
  defaultBuildCommand: 'go build -v ./...',
  setup: [
    { name: 'Download dependencies', command: 'go mod download', timeout: 120 },
  ],
  cache: {
    key: "go-${hashFiles('**/go.sum')}",
    paths: ['~/go/pkg/mod', '~/.cache/go-build'],
    restoreKeys: ['go-'],
    maxSizeMB: 1024,
  },
  artifacts: {
    paths: ['bin/**', 'dist/**'],
    expireAfterDays: 7,
  },
  environment: {
    CGO_ENABLED: '0',
    GOPROXY: 'https://proxy.golang.org,direct',
  },
  variables: {
    goVersion: { default: '1.22', description: 'Go version' },
    buildTarget: { default: './...', description: 'Go build target(s)' },
  },
};
 
// ---------------------------------------------------------------------------
// 8. Rust (Cargo)
// ---------------------------------------------------------------------------
const rustCargo: Recipe = {
  name: 'rust-cargo',
  description: 'Rust project built with Cargo',
  version: '1.0.0',
  detection: {
    files: ['Cargo.toml'],
    priority: 40,
  },
  executionMode: 'docker',
  dockerImage: 'rust:1.75-slim',
  requiredMemoryGB: 4,
  timeoutMinutes: 30,
  defaultBuildCommand: 'cargo build --release',
  setup: [
    { name: 'Fetch dependencies', command: 'cargo fetch', timeout: 120 },
  ],
  teardown: [
    { name: 'Cleanup target', command: 'cargo clean -p $(cargo metadata --no-deps --format-version 1 | grep -o \'"name":"[^"]*"\' | head -1 | cut -d\\" -f4) || true', continueOnError: true },
  ],
  cache: {
    key: "cargo-${hashFiles('**/Cargo.lock')}",
    paths: ['~/.cargo/registry', '~/.cargo/git', 'target'],
    restoreKeys: ['cargo-'],
    maxSizeMB: 2048,
  },
  artifacts: {
    paths: ['target/release/*'],
    expireAfterDays: 7,
  },
  environment: {
    CARGO_INCREMENTAL: '0',
    RUSTFLAGS: '-D warnings',
  },
  variables: {
    toolchain: { default: 'stable', description: 'Rust toolchain (stable, nightly, etc.)' },
    profile: { default: 'release', description: 'Cargo build profile' },
  },
};
 
// ---------------------------------------------------------------------------
// 9. .NET
// ---------------------------------------------------------------------------
const dotnet: Recipe = {
  name: 'dotnet',
  description: '.NET project built with dotnet SDK',
  version: '1.0.0',
  detection: {
    files: ['*.csproj', '*.sln', '*.fsproj'],
    priority: 40,
  },
  executionMode: 'docker',
  dockerImage: 'mcr.microsoft.com/dotnet/sdk:8.0',
  requiredMemoryGB: 4,
  timeoutMinutes: 20,
  defaultBuildCommand: 'dotnet build --configuration Release --no-restore && dotnet test --no-build --configuration Release',
  setup: [
    { name: 'Restore NuGet packages', command: 'dotnet restore', timeout: 120 },
  ],
  cache: {
    key: "nuget-${hashFiles('**/*.csproj', '**/packages.lock.json')}",
    paths: ['~/.nuget/packages'],
    restoreKeys: ['nuget-'],
    maxSizeMB: 1024,
  },
  artifacts: {
    paths: ['**/bin/Release/**', '**/publish/**'],
    expireAfterDays: 7,
  },
  environment: {
    DOTNET_CLI_TELEMETRY_OPTOUT: '1',
    DOTNET_NOLOGO: '1',
  },
  variables: {
    configuration: { default: 'Release', description: 'Build configuration (Debug / Release)' },
    framework: { default: 'net8.0', description: 'Target framework moniker' },
  },
};
 
// ---------------------------------------------------------------------------
// 10. Flutter
// ---------------------------------------------------------------------------
const flutter: Recipe = {
  name: 'flutter',
  description: 'Flutter project (mobile, web, desktop)',
  version: '1.0.0',
  detection: {
    files: ['pubspec.yaml'],
    contentPatterns: [
      { file: 'pubspec.yaml', pattern: 'flutter' },
    ],
    priority: 55,
  },
  executionMode: 'auto',
  dockerImage: 'ghcr.io/cirruslabs/flutter:stable',
  requiredOS: 'darwin',
  requiredMemoryGB: 8,
  timeoutMinutes: 30,
  defaultBuildCommand: 'flutter build apk --release',
  setup: [
    { name: 'Flutter doctor', command: 'flutter doctor -v', timeout: 60, continueOnError: true },
    { name: 'Get dependencies', command: 'flutter pub get', timeout: 120 },
  ],
  teardown: [
    { name: 'Clean Flutter build', command: 'flutter clean || true', continueOnError: true },
  ],
  cache: {
    key: "flutter-${hashFiles('**/pubspec.lock')}",
    paths: ['~/.pub-cache', '.dart_tool'],
    restoreKeys: ['flutter-'],
    maxSizeMB: 2048,
  },
  artifacts: {
    paths: [
      'build/app/outputs/**/*.apk',
      'build/app/outputs/**/*.aab',
      'build/ios/**/*.ipa',
      'build/web/**',
    ],
    expireAfterDays: 14,
  },
  environment: {
    PUB_CACHE: '~/.pub-cache',
    CI: 'true',
  },
  variables: {
    platform: { default: 'apk', description: 'Build target: apk, ios, web, linux, macos, windows' },
    buildMode: { default: 'release', description: 'Build mode: debug, profile, release' },
  },
};
 
// ---------------------------------------------------------------------------
// 11. React Native
// ---------------------------------------------------------------------------
const reactNative: Recipe = {
  name: 'react-native',
  description: 'React Native project (Android & iOS)',
  version: '1.0.0',
  detection: {
    files: ['package.json', 'metro.config.js', 'metro.config.ts', 'app.json'],
    contentPatterns: [
      { file: 'package.json', pattern: 'react-native' },
    ],
    priority: 55,
  },
  executionMode: 'auto',
  dockerImage: 'cimg/android:2024.04.1-node',
  requiredMemoryGB: 8,
  timeoutMinutes: 30,
  defaultBuildCommand: 'npx react-native build-android --mode=release',
  setup: [
    { name: 'Install JS dependencies', command: 'yarn install --frozen-lockfile || npm ci', timeout: 120 },
    { name: 'Accept Android SDK licenses', command: 'yes | sdkmanager --licenses || true', timeout: 60, continueOnError: true },
  ],
  teardown: [
    { name: 'Kill Metro bundler', command: 'pkill -f "react-native.*start" || true', continueOnError: true },
  ],
  cache: {
    key: "rn-${hashFiles('**/yarn.lock', '**/package-lock.json')}",
    paths: ['node_modules', '~/.gradle/caches', '~/.gradle/wrapper', 'Pods'],
    restoreKeys: ['rn-'],
    maxSizeMB: 3072,
  },
  artifacts: {
    paths: [
      'android/app/build/outputs/**/*.apk',
      'android/app/build/outputs/**/*.aab',
      'ios/build/**/*.ipa',
    ],
    expireAfterDays: 14,
  },
  environment: {
    NODE_ENV: 'production',
    CI: 'true',
    ANDROID_HOME: '/opt/android/sdk',
  },
  variables: {
    platform: { default: 'android', description: 'Target platform: android, ios, both' },
    buildMode: { default: 'release', description: 'Build mode: debug, release' },
  },
};
 
// ---------------------------------------------------------------------------
// 12. Docker Build
// ---------------------------------------------------------------------------
const dockerBuild: Recipe = {
  name: 'docker-build',
  description: 'Build and optionally push a Docker image',
  version: '1.0.0',
  detection: {
    files: ['Dockerfile', 'Containerfile', 'docker-compose.yml', 'docker-compose.yaml'],
    priority: 20,
  },
  executionMode: 'docker',
  dockerImage: 'docker:27-dind',
  requiredMemoryGB: 4,
  requiredTags: ['docker'],
  timeoutMinutes: 30,
  defaultBuildCommand: 'docker build -t ${IMAGE_NAME:-app}:${IMAGE_TAG:-latest} .',
  setup: [
    { name: 'Wait for Docker daemon', command: 'until docker info >/dev/null 2>&1; do sleep 1; done', timeout: 30 },
    { name: 'Login to registry', command: 'echo "${REGISTRY_PASSWORD}" | docker login ${REGISTRY:-docker.io} -u "${REGISTRY_USER}" --password-stdin || true', timeout: 15, continueOnError: true },
  ],
  cache: {
    key: "docker-${hashFiles('Dockerfile', '.dockerignore')}",
    paths: ['/var/lib/docker'],
    restoreKeys: ['docker-'],
    maxSizeMB: 4096,
  },
  artifacts: {
    paths: ['*.tar', 'docker-image-*.tar'],
    expireAfterDays: 7,
  },
  environment: {
    DOCKER_BUILDKIT: '1',
  },
  variables: {
    imageName: { default: 'app', description: 'Docker image name' },
    imageTag: { default: 'latest', description: 'Docker image tag' },
    registry: { default: 'docker.io', description: 'Container registry URL' },
  },
};
 
// ---------------------------------------------------------------------------
// 13. Terraform
// ---------------------------------------------------------------------------
const terraform: Recipe = {
  name: 'terraform',
  description: 'Terraform infrastructure plan & apply',
  version: '1.0.0',
  detection: {
    files: ['main.tf', '*.tf', 'terraform.tfvars'],
    priority: 35,
  },
  executionMode: 'docker',
  dockerImage: 'hashicorp/terraform:1.7',
  requiredMemoryGB: 2,
  timeoutMinutes: 20,
  defaultBuildCommand: 'terraform init && terraform plan -out=tfplan',
  setup: [
    { name: 'Validate configuration', command: 'terraform validate', timeout: 30 },
    { name: 'Format check', command: 'terraform fmt -check -recursive', timeout: 30, continueOnError: true },
  ],
  cache: {
    key: "terraform-${hashFiles('**/.terraform.lock.hcl')}",
    paths: ['.terraform/providers'],
    restoreKeys: ['terraform-'],
    maxSizeMB: 512,
  },
  artifacts: {
    paths: ['tfplan', '*.tfstate', 'terraform-plan-*.txt'],
    expireAfterDays: 30,
  },
  environment: {
    TF_IN_AUTOMATION: 'true',
    TF_INPUT: 'false',
  },
  variables: {
    workspace: { default: 'default', description: 'Terraform workspace' },
    backendConfig: { default: '', description: 'Extra backend config flags' },
  },
};
 
// ---------------------------------------------------------------------------
// 14. Kotlin Multiplatform (KMP)
// ---------------------------------------------------------------------------
const kmp: Recipe = {
  name: 'kmp',
  description: 'Kotlin Multiplatform project (JVM, JS, Native, Android, iOS)',
  version: '1.0.0',
  detection: {
    files: ['build.gradle.kts', 'build.gradle', 'settings.gradle.kts', 'settings.gradle'],
    contentPatterns: [
      { file: 'build.gradle.kts', pattern: 'multiplatform' },
      { file: 'build.gradle', pattern: 'multiplatform' },
      { file: 'settings.gradle.kts', pattern: 'multiplatform' },
    ],
    priority: 60,
  },
  executionMode: 'docker',
  dockerImage: 'cimg/android:2024.04.1',
  requiredMemoryGB: 8,
  timeoutMinutes: 40,
  defaultBuildCommand: './gradlew build --no-daemon --stacktrace',
  setup: [
    { name: 'Accept SDK licenses', command: 'yes | sdkmanager --licenses || true', timeout: 60, continueOnError: true },
    { name: 'Download dependencies', command: './gradlew dependencies --no-daemon', timeout: 300 },
  ],
  teardown: [
    { name: 'Stop Gradle daemons', command: './gradlew --stop || true', continueOnError: true },
  ],
  cache: {
    key: "kmp-${hashFiles('**/*.gradle*', '**/gradle-wrapper.properties')}",
    paths: [
      '~/.gradle/caches',
      '~/.gradle/wrapper',
      '~/.konan',
      '~/.android/build-cache',
    ],
    restoreKeys: ['kmp-'],
    maxSizeMB: 3072,
  },
  artifacts: {
    paths: [
      '**/build/outputs/apk/**/*.apk',
      '**/build/libs/*.jar',
      '**/build/distributions/**',
      '**/build/reports/**',
    ],
    expireAfterDays: 14,
  },
  environment: {
    GRADLE_OPTS: '-Dorg.gradle.daemon=false -Xmx6g -XX:+HeapDumpOnOutOfMemoryError',
    ANDROID_HOME: '/opt/android/sdk',
  },
  variables: {
    gradleTask: { default: 'build', description: 'Gradle task to execute' },
  },
};
 
// ---------------------------------------------------------------------------
// 15. Ruby on Rails
// ---------------------------------------------------------------------------
const rubyRails: Recipe = {
  name: 'ruby-rails',
  description: 'Ruby on Rails application',
  version: '1.0.0',
  detection: {
    files: ['Gemfile'],
    contentPatterns: [
      { file: 'Gemfile', pattern: 'rails' },
      { file: 'config/routes.rb', pattern: '' },
    ],
    priority: 40,
  },
  executionMode: 'docker',
  dockerImage: 'ruby:3.3-slim',
  requiredMemoryGB: 4,
  timeoutMinutes: 20,
  defaultBuildCommand: 'bundle exec rails test',
  setup: [
    { name: 'Install dependencies', command: 'bundle install --jobs 4 --retry 3', timeout: 180 },
    { name: 'Setup database', command: 'bundle exec rails db:prepare || true', timeout: 60, continueOnError: true },
    { name: 'Precompile assets', command: 'bundle exec rails assets:precompile || true', timeout: 120, continueOnError: true },
  ],
  cache: {
    key: "bundle-${hashFiles('**/Gemfile.lock')}",
    paths: ['vendor/bundle', '~/.bundle/cache'],
    restoreKeys: ['bundle-'],
    maxSizeMB: 1024,
  },
  artifacts: {
    paths: ['log/**', 'tmp/screenshots/**', 'coverage/**'],
    expireAfterDays: 7,
  },
  environment: {
    RAILS_ENV: 'test',
    BUNDLE_PATH: 'vendor/bundle',
    BUNDLE_JOBS: '4',
    BUNDLE_RETRY: '3',
  },
  variables: {
    rubyVersion: { default: '3.3', description: 'Ruby version' },
    railsEnv: { default: 'test', description: 'RAILS_ENV value' },
  },
};
 
// ---------------------------------------------------------------------------
// Export
// ---------------------------------------------------------------------------
 
/** All built-in recipes, keyed by name. */
export const BUILTIN_RECIPES: Recipe[] = [
  androidGradle,
  iosXcode,
  nodejsNpm,
  nodejsYarn,
  pythonPip,
  pythonPoetry,
  goModule,
  rustCargo,
  dotnet,
  flutter,
  reactNative,
  dockerBuild,
  terraform,
  kmp,
  rubyRails,
];