name: brain-l1-watcher (weekly)

on:
  schedule:
    - cron: '0 6 * * 1'
  workflow_dispatch:

jobs:
  drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
      - name: run l1-watcher
        id: l1
        run: node tools/l1-watcher.mjs
        continue-on-error: true
      - name: open issue on drift
        if: steps.l1.outcome == 'failure'
        uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.create({
              owner: context.repo.owner,
              repo: context.repo.repo,
              title: `[l1-watcher] drift detected (weekly cron ${new Date().toISOString().slice(0,10)})`,
              body: `Run failed. Check workflow logs and run /claude-md-management:claude-md-improver.`,
              labels: ['brain', 'drift']
            });
