[monorepo]
config_roots = ["apps/web", "apps/desktop", "apps/browser", "packages/ui", "packages/sdk", "packages/config", "cmd/agent"]

[tools]
# Go version from go.mod
go = "1.25.6"
# Node.js for frontend packages
node = "25"
# Bun for browser gateway
bun = "latest"
# pnpm for workspace management
pnpm = "10"
# sqlc for sql management
sqlc = "latest"
# golangci-lint for Go linting
"golangci-lint" = "2.10.1"
# Rust stable toolchain (required by Tauri desktop app)
rust = "stable"

[task_config]
dir = "{{cwd}}"

[settings]
experimental = true

[tasks.pnpm-install]
description = "Install dependencies"
env = { CI = "true" }
run = "pnpm install"

[tasks.docs]
description = "start documentation"
run = "pnpm docs:dev"

[tasks.go-install]
description = "Install Go dependencies"
run = "go mod download"

[tasks.swagger-generate]
description = "Generate Swagger documentation"
depends = [
  "//:go-install",
]
run = "cd internal/handlers && go generate"

[tasks.sdk-generate]
description = "Generate SDK code"
run = "pnpm run generate-sdk"
depends = [
  "//:pnpm-install",
  "//:swagger-generate"
]

[tasks.sqlc-generate]
description = "Generate SQL code"
run = "sqlc generate"

[tasks.icons-generate]
description = "Generate icon Vue components from SVG sources"
run = "pnpm --filter @memohai/icon generate"

[tasks.dev]
description = "Start development environment"
run = """
#!/bin/bash
set -e
docker compose -f devenv/docker-compose.yml up --build
"""

[tasks."dev:selinux"]
description = "Start development environment on SELinux systems"
run = """
#!/bin/bash
set -e
docker compose -f devenv/docker-compose.yml -f devenv/docker-compose.selinux.yml up --build
"""

[tasks."dev:down"]
description = "Stop development environment"
run = "docker compose -f devenv/docker-compose.yml down --remove-orphans"

[tasks."dev:down:selinux"]
description = "Stop development environment on SELinux systems"
run = "docker compose -f devenv/docker-compose.yml -f devenv/docker-compose.selinux.yml down --remove-orphans"

[tasks."dev:logs"]
description = "View development logs"
run = "docker compose -f devenv/docker-compose.yml logs -f"

[tasks."dev:logs:selinux"]
description = "View development logs on SELinux systems"
run = "docker compose -f devenv/docker-compose.yml -f devenv/docker-compose.selinux.yml logs -f"

[tasks."dev:restart"]
description = "Restart a service (usage: mise run dev:restart -- server)"
run = "docker compose -f devenv/docker-compose.yml restart $@"

[tasks."dev:restart:selinux"]
description = "Restart a service on SELinux systems (usage: mise run dev:restart:selinux -- server)"
run = "docker compose -f devenv/docker-compose.yml -f devenv/docker-compose.selinux.yml restart $@"

[tasks."bridge:build"]
description = "Manually rebuild bridge binary in dev container (normally auto-triggered by air)"
run = """
#!/bin/bash
set -e
docker compose -f devenv/docker-compose.yml exec server \
  sh -c 'cd /workspace && sh devenv/bridge-build.sh'
"""

[tasks."bridge:build:selinux"]
description = "Manually rebuild bridge binary in SELinux dev container"
run = """
#!/bin/bash
set -e
docker compose -f devenv/docker-compose.yml -f devenv/docker-compose.selinux.yml exec server \
  sh -c 'cd /workspace && sh devenv/bridge-build.sh'
"""

[tasks.db-up]
description = "Initialize and Migrate Database"
run = "scripts/db-up.sh"

[tasks.db-down]
description = "Drop Database"
run = "scripts/db-drop.sh"

[tasks.release]
description = "Release new version"
run = "pnpm release"

[tasks.build-embedded-assets]
description = "Build and stage embedded web assets"
run = "scripts/release.sh --prepare-assets"
depends = ["//:pnpm-install"]

[tasks.build-unified]
description = "Build unified memoh binary"
depends = ["//:build-embedded-assets"]
run = "go build -o bin/memoh ./cmd/memoh"

[tasks.release-binaries]
description = "Build release archive for one target (requires TARGET_OS TARGET_ARCH)"
depends = ["//:pnpm-install"]
run = "scripts/release.sh"

[tasks.install-socktainer]
description = "Install socktainer"
run = "brew tap socktainer/tap && brew install socktainer"

[tasks.install-workspace-toolkit]
description = "Install workspace toolkit"
run = "cd docker/toolkit && ./install.sh"

[tasks.lint]
description = "Run all linters"
depends = [
  "//:lint:go",
  "//:lint:es",
]

[tasks."lint:fix"]
description = "Run all linters with auto-fix"
depends = [
  "//:lint:go:fix",
  "//:lint:es:fix",
]

[tasks."lint:go"]
description = "Run Go linter"
run = "golangci-lint run ./..."

[tasks."lint:go:fix"]
description = "Run Go linter with auto-fix"
run = "golangci-lint run --fix ./..."

[tasks."lint:es"]
description = "Run ESLint"
run = "pnpm lint"

[tasks."lint:es:fix"]
description = "Run ESLint with auto-fix"
run = "pnpm lint:fix"

[tasks.setup]
description = "Setup development environment"
depends = [
  "//:install-workspace-toolkit",
  "//:sqlc-generate",
  "//:pnpm-install",
  "//:go-install",
]
run = """
#!/bin/bash
set -e
echo '✓ Setup complete! Run: mise run dev'
echo '  Dev web UI will be available at http://localhost:18082'
"""

[tasks."desktop:dev"]
description = "Start Tauri desktop app in dev mode (wraps @memohai/web)"
dir = "{{config_root}}/apps/desktop"
env = { MEMOH_WEB_PROXY_TARGET = "http://localhost:18080" }
run = "pnpm tauri dev"

[tasks."desktop:build"]
description = "Build Tauri desktop app for release"
dir = "{{config_root}}/apps/desktop"
run = "pnpm tauri build"
