# Step 6: Create Task Runner (justfile/Makefile)

<purpose>
Create a justfile or Makefile in the orchestrator that proxies commands to subrepos, providing a single entry point for common operations.
</purpose>

<instructions>
1. Detect existing task runners (justfile, Makefile, package.json scripts)
2. Generate task runner with recipes for all subrepos
3. Include common orchestrator patterns (test all, build all, dev)
4. Allow user to customize recipes
5. Write to project root
</instructions>

<output>
- justfile or Makefile created/updated
- Recipes for each subrepo
- Common orchestrator commands (test-all, build-all, dev)
- User has approved the configuration
</output>

## TASK RUNNER DETECTION

Check for existing task runners:

```bash
ls -la justfile Justfile Makefile makefile package.json 2>/dev/null
```

### Prefer justfile over Makefile

**Why justfile:**
- Modern syntax, easier to read
- Better error messages
- Cross-platform (Windows support)
- Native variables and interpolation
- Recipes are isolated by default

## JUSTFILE STRUCTURE FOR ORCHESTRATORS

```just
# justfile for {project_name}
# Generated by Pennyfarthing project-setup workflow

# Default recipe - show help
default:
    @just --list

# ============================================
# ALL REPOS
# ============================================

# Run tests in all repos
test-all:
    @echo "Testing all repos..."
    just test-api
    just test-ui

# Build all repos
build-all:
    @echo "Building all repos..."
    just build-api
    just build-ui

# Install dependencies in all repos
install-all:
    @echo "Installing dependencies..."
    cd {api_path} && npm install
    cd {ui_path} && npm install

# ============================================
# API ({api_path})
# ============================================

# Run API tests
test-api:
    cd {api_path} && {api_test_command}

# Build API
build-api:
    cd {api_path} && {api_build_command}

# Start API development server
dev-api:
    cd {api_path} && {api_dev_command}

# Lint API
lint-api:
    cd {api_path} && {api_lint_command}

# ============================================
# UI ({ui_path})
# ============================================

# Run UI tests
test-ui:
    cd {ui_path} && {ui_test_command}

# Build UI
build-ui:
    cd {ui_path} && {ui_build_command}

# Start UI development server
dev-ui:
    cd {ui_path} && {ui_dev_command}

# Lint UI
lint-ui:
    cd {ui_path} && {ui_lint_command}

# ============================================
# ORCHESTRATOR
# ============================================

# Start both API and UI (background API, foreground UI)
dev:
    just dev-api &
    just dev-ui

# Run linting in all repos
lint-all:
    just lint-api
    just lint-ui

# Clone missing subrepos
clone-repos:
    @echo "Cloning subrepos..."
    test -d {api_path} || git clone {api_git_url} {api_path}
    test -d {ui_path} || git clone {ui_git_url} {ui_path}

# Check repo status across all repos
status:
    @echo "=== Orchestrator ===" && git status --short
    @echo "=== API ===" && cd {api_path} && git status --short
    @echo "=== UI ===" && cd {ui_path} && git status --short
```

## GENERATION FROM REPOS.YAML

For each repo in repos.yaml, generate recipes:

```yaml
# repos.yaml input:
repos:
  api:
    path: conductor-api
    test_command: npm test
    build_command: npm run build
    dev_command: npm run dev
    lint_command: npm run lint
```

Generates:
```just
test-api:
    cd conductor-api && npm test

build-api:
    cd conductor-api && npm run build
```

## COMMON ORCHESTRATOR RECIPES

### Sprint Management Integration

```just
# ============================================
# PENNYFARTHING / SPRINT
# ============================================

# Show current sprint status
sprint:
    @.pennyfarthing/scripts/sprint/sprint-cli.sh status

# List available stories
backlog:
    @.pennyfarthing/scripts/sprint/sprint-cli.sh backlog

# Start Cyclist visual terminal
cyclist:
    cd {cyclist_path} && npm run dev:once
```

### CI/CD Recipes

```just
# ============================================
# CI/CD
# ============================================

# Run full CI check
ci: lint-all test-all build-all
    @echo "CI passed!"

# Create release
release version:
    @echo "Creating release {{version}}..."
    # Add release logic here
```

## INTERACTIVE CUSTOMIZATION

```
📋 Task Runner Configuration
═════════════════════════════

Detected: {existing_runner or "none"}
Recommended: justfile

Generated recipes:
  ✓ test-all, build-all, install-all
  ✓ Per-repo: test-{repo}, build-{repo}, dev-{repo}
  ✓ Orchestrator: dev, status, clone-repos
  ✓ Sprint: sprint, backlog, cyclist

Options:
[A] Accept and write justfile
[E] Edit recipes
[M] Generate Makefile instead
[P] Preview full file
[S] Skip - I'll create my own
```

### Edit Flow

```
Which recipe to edit?

[1] test-all
[2] build-all
[3] test-api
[4] Add new recipe
[5] Remove a recipe

> 4

Recipe name: deploy-staging
Recipe commands:
> cd api && npm run deploy:staging
> cd ui && npm run deploy:staging

Added recipe 'deploy-staging'
```

## MAKEFILE ALTERNATIVE

If user prefers Makefile:

```makefile
# Makefile for {project_name}
# Generated by Pennyfarthing project-setup workflow

.PHONY: test-all build-all install-all test-api build-api dev-api

# Default target
help:
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  %-20s %s\n", $$1, $$2}'

test-all: test-api test-ui ## Run tests in all repos

test-api: ## Run API tests
	cd {api_path} && {api_test_command}

test-ui: ## Run UI tests
	cd {ui_path} && {ui_test_command}
```

## SUCCESS CRITERIA

✅ Task runner created (justfile preferred)
✅ All repos have standard recipes (test, build, dev, lint)
✅ Aggregated commands work (test-all, build-all)
✅ Orchestrator commands included
✅ User has reviewed and approved

## NEXT STEP

After task runner is created, proceed to `step-07-theme.md` to configure the persona theme.
