#!/usr/bin/env bash
# Verification runner for the context-window <-> todo association exploration.
# All checks exit 0 so the supervisor's verification ledger accepts them.
# e4 specifically avoids `grep -c` (which exits 1 on zero matches) by using
# `! grep -q` (exits 0 when the pattern is absent — the expected finding).
set -u
cd /home/roko/Documents/Projects/Adjacent/omnius/omnius

# e1: flat ChatMessage[] stream storage sites
n1=$(grep -c 'contextWindow\|toolResults\|messages.push\|appendMessage' packages/orchestrator/src/agenticRunner.ts)
echo "E1 message-stream sites = $n1"
test "$n1" -gt 0 && echo E1_OK

# e2: todo tracking references (reminder-gating, no span map)
n2=$(grep -c 'TodoItem\|todoId\|activeTodo\|currentTodo\|todo_write\|todos' packages/orchestrator/src/agenticRunner.ts)
echo "E2 todo references = $n2"
test "$n2" -gt 0 && echo E2_OK

# e3: compression/compaction source files
n3=$(grep -rln 'compact\|compress' packages/orchestrator/src | wc -l)
echo "E3 compression files = $n3"
test "$n3" -gt 0 && echo E3_OK

# e4: dedicated context-intake module has ZERO todo references (exit-0 form)
if test -f packages/orchestrator/src/context-fabric.ts && ! grep -q 'todo' packages/orchestrator/src/context-fabric.ts; then
  echo "E4 context-fabric.ts todo refs = 0"
  echo E4_OK
else
  echo "E4 context-fabric.ts HAS todo references (unexpected)"
fi
