set shell := ["bash", "-c"]

# List available tasks
default:
    @just --list

# Install workspace dependencies
install:
    npm install

# Full build (core + web)
build:
    npm run build

# Build core runtime only (faster)
build-core:
    npm run build:core

# Build native Rust addon (release)
build-native:
    npm run build:native-pkg

# Run all tests
test:
    npm test

# Run unit tests only
test-unit:
    npm run test:unit

# Run smoke tests
test-smoke:
    npm run test:smoke

# Run TypeScript type checking
typecheck:
    npm run typecheck:extensions

# Lint
lint:
    npm run lint

# Lint and auto-fix
lint-fix:
    npm run lint:fix

# Remove build outputs
clean:
    rm -rf dist dist-test

# Run SF CLI from source (usage: just sf <args>)
sf *args:
    ./bin/sf-from-source {{args}}

# Create a new ADR from the template (usage: just adr "My Decision Title")
adr title:
    #!/usr/bin/env bash
    set -euo pipefail
    next=$(ls docs/dev/ADR-*.md 2>/dev/null | sed 's/.*ADR-\([0-9]*\).*/\1/' | sort -n | tail -1)
    num=$(printf "%03d" $(( ${next:-0} + 1 )))
    slug=$(echo "{{title}}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd 'a-z0-9-')
    dest="docs/dev/ADR-${num}-${slug}.md"
    sed "s/ADR-NNN/ADR-${num}/; s/Title/{{title}}/" docs/design-docs/ADR-TEMPLATE.md > "${dest}"
    echo "Created: ${dest}"

# Create a new product spec (usage: just spec "my-feature-name")
spec name:
    #!/usr/bin/env bash
    set -euo pipefail
    dest="docs/product-specs/{{name}}.md"
    if [ -f "${dest}" ]; then echo "Already exists: ${dest}"; exit 1; fi
    printf "# {{name}}\n\n## Job to be done\n\n## Workflow\n\n## Edge cases\n\n## Non-goals\n\n## Verification\n\n\`\`\`bash\n# command that proves this spec passes\n\`\`\`\n" > "${dest}"
    echo "Created: ${dest}"

# Create a new harness spec (usage: just harness-spec "behavior-name")
harness-spec name:
    #!/usr/bin/env bash
    set -euo pipefail
    dest="harness/specs/{{name}}.md"
    if [ -f "${dest}" ]; then echo "Already exists: ${dest}"; exit 1; fi
    printf "# Harness Spec: {{name}}\n\n## Behavior\n\n## Verification command\n\n\`\`\`bash\n\n\`\`\`\n\n## Pass criteria\n\n" > "${dest}"
    echo "Created: ${dest}"
