# koru.yaml — project pipeline (schema 1.0)
# Created by `koru --init` when this file was missing. Edit freely and commit.
#
# Paths use `--project .` — run these from the repository root (same on Linux, macOS, CI).
# `koru --init --agent-lane auto` picks a lane from the first present marker, in order:
#   .cursor → .windsurf → .vscode → .idea → .zed → else `local`.
# When CI=true or GITHUB_ACTIONS=true, auto lane is always `local` (no IDE socket from markers).

schema: "1.0"
project: local
description: >
  When to run koru, planfile, and local quality commands. Koru reads this file
  for briefs/doctor; it does not auto-run shell steps.

extends_profile: null
# Optional shared snippets for `koru --context` (see docs / large-repo examples):
# extends_profile: .koru/profiles/default.yaml

# Optional markdown ↔ sprint sync (uncomment and tune `.planfile/config.yaml` keys first):
# planfile_markdown_todo:
#   config_path: .planfile/config.yaml
#   config_key: koru.markdown_todo
#   active_profile: default
#   alternate_profiles: []

environment:
  # Fold semcod exports into `koru scan` / `koru scan --apply` (off unless set):
  # KORU_SCAN_SEMCOD_ARTIFACTS: "1"
  #
  # Autopilot + queue lane (after init, prefer: `source .planfile/.koru/shell-env.sh`):
  # KORU_AUTOPILOT_INSTANCE: "main"       # unique per IDE window; default from init lane
  # KORU_AUTOPILOT_SOCKET: ""            # absolute Unix socket path (overrides instance path)
  # KORU_AUTOPILOT_IDE: "auto"           # auto | cursor | windsurf | vscode | jetbrains | zed
  # KORU_SUGGESTED_QUEUE_ACTOR: ""       # planfile queue actor hint (koru-<lane> from init)

when:
  bootstrap:
    description: First-time planfile + koru runtime wiring.
    commands:
      - koru --init --project .
      - koru --doctor --project .

  ticket_iteration:
    description: >
      Each coding iteration — prefer the development queue (structural defects
      from Subactor on_fail:ticket / subactor-improvement), then default work.
      Koru patches code only; never DNS/Plesk/secrets/prod grant bypass.
    commands:
      - planfile ticket next --queue development
      - task tickets:next
      - koru --project .
      - task quality:regix:local

  backlog_hygiene:
    description: Turn repo signals into planfile tickets (dry-run first).
    commands:
      - koru scan --project .
      - koru scan --apply --project .
      - koru scan --apply --semcod-artifacts --project .

  autonomous_outer_loop:
    description: >
      Unattended cycle (scan → queue → optional autopilot). Development defects
      from Subactor land on queue `development` (see architecture note
      subactor-koru-development-bridge.md). Resume of ops tickets still requires
      Subactor preflight/AQL/dry-run/grant/Y/n — Koru must not auto-apply.
    commands:
      - koru autonomous up --project . --max-cycles 1 --agent-lane auto --queue-name development

  before_complete_ticket:
    description: Right before `planfile ticket done` / policy CI hook.
    commands:
      - task quality:regix:local

  after_development_defect_closed:
    description: >
      Optional resume hook after a development_defect ticket is done. Does not
      bypass grants — dry-run first, then human Y/n / --execute.
    commands:
      - echo "Resume source ticket with: subactor-run --ticket <SOURCE_ID>"
      - echo "Execute only after dry-run + apply grant + Y/n"
autonomy:
  strategy:
    schema: '1.0'
    id: accordion_detail_to_general
    description: 'Default autonomy rhythm: execute concrete planfile tickets first;
      when the queue is empty, broaden to whole-project discovery and turn findings
      back into focused planfile tickets.'
    source_of_truth: planfile
    default_pipeline:
      order:
      - planfile_queue
      - idle_scan
      - whole_project_discovery
      - ticket_generation
      - queue_execution
      proposal_policy: explain_before_mutating
    idle_discovery:
      enabled: true
      min_interval_seconds: 60
      duplicate_cooldown_behavior: continue_to_general_discovery
      ide_follow_up:
        enabled: true
        workflow: standardized_project_discovery_ticket
        trigger: no_tickets_after_scan_and_code2llm
        prompt: Co jeszcze zostalo do wykonania? zrob z tego nastepne tickety do planfile.
        expected_output: new_planfile_tickets_only
      tools:
        automated:
        - koru_scan
        - code2llm
        artifact_sources:
        - jscpd
        - redup
        - testql
        - vallm
        - pyqual
        - prefact
        - regix
        - redsl
        - metrun
        - pfix
        advisory:
        - goal
        - costs
    planning_assistant:
      enabled: true
      provider_order:
      - openrouter
      - ide_llm
      openrouter:
        model: openrouter/qwen/qwen3-coder-next
        api_key_env: OPENROUTER_API_KEY
        mode: prompt_or_explicit_call
      ide_llm:
        mode: prepared_prompt
        target: active_autopilot_lane
      editable_sections:
      - autonomy.strategy
      - when
      - environment
      update_policy: propose_yaml_patch
    heuristics:
      signals:
      - open_planfile_tickets
      - idle_streak
      - scan_duplicate_cooldown
      - code2llm_artifact_age
      - semcod_tool_availability
      - test_health
      prefer_specific_work_until_queue_empty: true
      prefer_general_discovery_when_idle: true
