min_version = "2026.2.4"

[env]
GOAMD64 = "v3"

[vars]
binary = "cooked-mcp"
main = "./cmd/cooked-mcp"
static_tags = "netgo,osusergo,static_build"
static_ldflags = "-d -s -w -buildid= -extldflags=-static"
test_args = "-v -race -count=5 -p=3 -timeout=5m ./..."

[tools]
"aqua:google/yamlfmt" = "latest"
go = "latest"
"go:golang.org/x/vuln/cmd/govulncheck" = "latest"
golangci-lint = "latest"

[tasks.fmt]
description = "Format Go code"
run = "golangci-lint fmt"

[tasks.tidy]
description = "Tidy go.mod and go.sum"
run = "go mod tidy"

[tasks.modernize]
description = "Apply Go modernization fixes"
run = "golangci-lint run --enable-only modernize --fix ./..."

[tasks.lint]
description = "Lint Go code and apply safe fixes"
run = "golangci-lint run --fix"

[tasks.fix]
description = "Format, modernize, and apply lint fixes"
run = [
  "mise run fmt",
  "mise run modernize",
  "mise run lint",
]

[tasks.vet]
description = "Run go vet"
run = "go vet ./..."

[tasks."yaml:fmt"]
description = "Format YAML files"
run = "yamlfmt ."

[tasks."yaml:lint"]
description = "Check YAML formatting"
run = "yamlfmt -lint ."

[tasks.vuln]
description = "Run govulncheck"
run = "govulncheck ./..."

[tasks.build]
description = "Build a static pure-Go cooked-mcp binary"
env = { CGO_ENABLED = "0" }
run = '''
go build \
  -trimpath \
  -tags '{{vars.static_tags}}' \
  -ldflags '{{vars.static_ldflags}}' \
  -o {{vars.binary}} \
  {{vars.main}}
'''

[tasks.install]
description = "Install a static pure-Go cooked-mcp binary"
env = { CGO_ENABLED = "0" }
run = '''
go install \
  -trimpath \
  -tags '{{vars.static_tags}}' \
  -ldflags '{{vars.static_ldflags}}' \
  {{vars.main}}
'''

[tasks.test]
description = "Run Go tests repeatedly with the race detector"
env = { CGO_ENABLED = "1" }
run = "go test {{vars.test_args}}"

[tasks."test:quiet"]
description = "Run Go tests with quiet success output"
env = { CGO_ENABLED = "1" }
run = '''
if output=$(go test {{vars.test_args}} 2>&1); then
  echo "✓"
else
  echo "$output"
  exit 1
fi
'''

[tasks.check]
description = "Format, tidy, lint, scan, build, and test"
run = [
  "mise run fix",
  "mise run yaml:fmt",
  "mise run tidy",
  "mise run yaml:lint",
  "mise run vet",
  "mise run vuln",
  "mise run build",
  "mise run test:quiet",
]
