version: '3'

# tasks/triage-bulk.yml -- Story 4 of #845 + #915 cache-walk re-enable.
#
# Wired into the parent ../Taskfile.yml `includes:` block under namespace
# key `triage-bulk` (#845 Story 6). The user-facing `task triage:bulk-accept`
# / `triage:bulk-reject` / `triage:bulk-defer` / `triage:bulk-needs-ac` /
# `triage:refresh-active` surface lives as root-level alias tasks in
# Taskfile.yml that delegate here (#913); inner tasks below are
# `internal: true` so the fragment-namespace forms (`triage-bulk:bulk-*`)
# are hidden from `task -l`.
#
# The disable-gate `cmds:` blocks introduced by PR #916 (#915 hot-fix) were
# reversed once bulk ops walked the local cache instead of live `gh issue
# list`. As of #883 Story 3 the cache walk consumes the unified `cache:get`
# surface (`.deft-cache/github-issue/<owner>/<repo>/<N>/`); the four
# `bulk-*` targets invoke packages/cli/src/triage-bulk.ts via engine:invoke.
# The cache-empty hard-fail (exit 2) and Tier-2 audit-log short-circuit are
# enforced inside that handler (#915 fix).
#
# Per `conventions/task-caching.md` (#574): every target here accepts user
# flags via `{{.CLI_ARGS}}` (--label, --author, --age-days, --cluster,
# --reason, --repo, --re-action) so MUST NOT declare `sources:` /
# `generates:` -- the cached cmds: skip would silently swallow the
# recovery flag.
#
# Path resolution mirrors the convention from tasks/issue.yml + tasks/policy.yml:
# `DEFT_ROOT` is defined locally via `joinPath .TASKFILE_DIR ".."` so
# `node .../bin.js` resolves cleanly on Windows under go-task's mvdan/sh
# interpreter (#566).

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

tasks:
  bulk-accept:
    desc: "Bulk accept candidates (#845 Story 4) -- task triage:bulk-accept -- --repo OWNER/NAME [--label L] [--author A] [--age-days N] [--cluster C] [--re-action]"
    internal: true
    deps: [":engine:_ts-build"]
    dir: '{{.USER_WORKING_DIR}}'
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'triage-bulk accept {{.CLI_ARGS}}'

  bulk-reject:
    desc: "Bulk reject candidates (#845 Story 4) -- task triage:bulk-reject -- --repo OWNER/NAME --reason 'why' [--label L] [--author A] [--age-days N] [--cluster C] [--re-action]"
    internal: true
    deps: [":engine:_ts-build"]
    dir: '{{.USER_WORKING_DIR}}'
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'triage-bulk reject {{.CLI_ARGS}}'

  bulk-defer:
    desc: "Bulk defer candidates (#845 Story 4) -- task triage:bulk-defer -- --repo OWNER/NAME [--label L] [--author A] [--age-days N] [--cluster C] [--re-action]"
    internal: true
    deps: [":engine:_ts-build"]
    dir: '{{.USER_WORKING_DIR}}'
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'triage-bulk defer {{.CLI_ARGS}}'

  bulk-needs-ac:
    desc: "Bulk needs-ac candidates (#845 Story 4) -- task triage:bulk-needs-ac -- --repo OWNER/NAME [--label L] [--author A] [--age-days N] [--cluster C] [--re-action]"
    internal: true
    deps: [":engine:_ts-build"]
    dir: '{{.USER_WORKING_DIR}}'
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'triage-bulk needs-ac {{.CLI_ARGS}}'

  refresh-active:
    desc: "Pre-swarm freshness gate (#845 Story 4) -- detects drift between cached and live `gh issue view` for every issue referenced in vbrief/active/*.vbrief.json"
    internal: true
    deps: [":engine:_ts-build"]
    dir: '{{.USER_WORKING_DIR}}'
    cmds:
      - task: :engine:invoke
        vars:
          ENGINE_CMD: 'triage-refresh --project-root "{{.USER_WORKING_DIR}}" {{.CLI_ARGS}}'
