version: '3'

vars:
  DEFT_ROOT: '{{joinPath .TASKFILE_DIR ".."}}'

# spec tasks -- consumer-safe CWD + script resolution (#539, #540, #566).
# Scripts are dispatched via {{.DEFT_ROOT}} (defined locally in this file's
# `vars:` block via ``{{joinPath .TASKFILE_DIR ".."}}`` -- see
# ../Taskfile.yml for why root-level definition is avoided) to keep the
# path traversal-free and avoid the {{.TASKFILE_DIR}}/.. form that breaks
# on Windows under `uv --project "{{.DEFT_ROOT}}" run python` (#566).

tasks:

  validate:
    desc: Validate that the specification artifact exists and is well-formed JSON
    dir: '{{.USER_WORKING_DIR}}'
    deps:
      - task: :engine:_ts-build
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'spec-validate --project-root "{{.USER_WORKING_DIR}}"'

  render:
    desc: >-
      Render the specification artifact to a compact SPECIFICATION.md by default
      (#1566: no completed lifecycle dump, no LegacyArtifacts). Nested plan.items
      render on by default to depth 3 (#4511). Opt in via
      --include-scopes=current|all, --include-legacy-artifacts=on, and
      --item-depth=N after --.
    dir: '{{.USER_WORKING_DIR}}'
    deps:
      - task: :engine:_ts-build
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'spec-render --project-root "{{.USER_WORKING_DIR}}" {{.CLI_ARGS}}'

  reconstruct:
    desc: >-
      Draft-only brownfield spec reconstruction (#1589). Emits a candidate under
      xbrief/.audit/spec-reconstruct-draft.json; never auto-promotes to
      specification.xbrief.json. Consumes #1595 codebase MAP as code oracle.
      Consumer alias: task deft:spec:reconstruct.
    dir: '{{.USER_WORKING_DIR}}'
    deps:
      - task: :engine:_ts-build
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'spec-reconstruct --project-root "{{.USER_WORKING_DIR}}" {{.CLI_ARGS}}'

  pipeline:
    desc: Run full spec pipeline (validate then render)
    cmds:
      - task: validate
      - task: render
