refactor(structure): promote app to repo root + remove redundant workspace cruft

Standard production layout: the OKR app (was nested under AINative_OKR_CASAN5/) is now
the repository root. No more wrapper directory.

- Promote AINative_OKR_CASAN5/* -> repo root (backend/ frontend/ packages/ apps/
  .specify/ docs/ infra/ nginx/ scripts/ + configs). Merge tool dirs: .gitea (kept the
  active deploy ci.yml, added harness-ci.yml + runbooks), .claude (agents/commands +
  launch.json), .github moved up.
- Remove redundant: 00_SUBMISSION_PACKAGE, scattered root notes (FPT_CASAN_Full.md,
  tu-tuong-casan.md, casan-tu-sinh..., casan_harness_assessment.md, source-review...,
  README_CASAN5_REFINED.md), casan-next-plans/ and optimize-docs/ (competition/planning
  artifacts — roadmap + design history preserved in git log / commit messages).
- Update all references to the old layout:
  - .gitea/workflows/{ci,harness-ci}.yml, .github/workflows/{ci,deploy}.yml:
    working-directory .; drop AINative_OKR_CASAN5/ prefix; .specify/{tests,scripts}
    -> packages/casan-harness/... (.specify/logs state kept)
  - .claude/launch.json, .gitea/*-runbook.md: path prefixes
  - CLAUDE.md, README.md: docs/input -> apps/okr/domain/input
  - policy-bundle.yaml: 8 policy paths -> packages/casan-harness/...; manifest re-signed
- secrets-scan.sh: fixture excludes -> new package/domain paths.

Full gate from the new root: PASS=64 FAIL=0 SKIP=3.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
thanhnv
2026-07-08 13:26:36 +09:00
co-authored by Claude Opus 4.8
parent 7101af9fd4
commit 36a4812ef3
925 changed files with 410 additions and 18001 deletions
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
set -uo pipefail
# CASAN Plan-17 Track 2 — No-progress / Oscillation Detector.
#
# Proves:
# * a strictly improving progress series -> CONVERGING (exit 0),
# * N identical consecutive actions -> OSCILLATING (repeat),
# * A,B,A,B... alternation -> OSCILLATING (thrash),
# * flat progress over the window -> STALLED,
# * on_stall=escalate -> ESCALATE (exit 4); on_stall=halt -> HALT (exit 3),
# * a corrupt observation stream fails closed (HALT, not silent CONVERGING),
# * verdicts write a hash-linked audit record,
# * state is redirected -> repo .specify/state stays clean.
#
# Deterministic; hermetic; no model / network / docker.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../scripts/bash/casan-paths.sh"
PROJECT_ROOT="$CASAN_APP_ROOT"
CONV="$CASAN_HARNESS_ROOT/scripts/bash/loop-convergence.py"
POLICY="$CASAN_HARNESS_ROOT/config/loop-policy.yaml"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
export CASAN_LOOP_STATE_ROOT="$WORK/state"
export CASAN_LOOP_POLICY_FILE="$POLICY"
PASS=0; FAIL=0
pass() { echo "PASS: $1"; PASS=$((PASS + 1)); }
fail() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); }
obs() { python3 "$CONV" observe --run-id "$1" --step "$2" --action-hash "$3" --progress "$4" >/dev/null; }
verdict() {
# verdict <expect_rc> <desc> <run-id> [profile]
local expect="$1" desc="$2" run="$3" prof="${4:-prod}"
set +e
OUT="$(python3 "$CONV" verdict --run-id "$run" --profile "$prof" 2>/dev/null)"
local rc=$?
set -e 2>/dev/null || true
if [[ "$rc" -eq "$expect" ]]; then pass "$desc (rc=$rc)"; else fail "$desc (rc=$rc, want $expect)"; fi
}
echo "===== Plan-17 T2: Convergence Detector ====="
# 1) improving progress -> CONVERGING
obs conv-ok 1 aaa 0.1; obs conv-ok 2 bbb 0.4; obs conv-ok 3 ccc 0.7; obs conv-ok 4 ddd 0.95
verdict 0 "improving progress -> CONVERGING" conv-ok
grep -q '"verdict": "CONVERGING"' <<<"$OUT" && pass "CONVERGING in envelope" || fail "missing CONVERGING"
# 2) N identical consecutive actions -> OSCILLATING (repeat). prod N=3.
obs osc-rep 1 same 0.2; obs osc-rep 2 same 0.3; obs osc-rep 3 same 0.4
verdict 4 "repeat action -> OSCILLATING (escalate)" osc-rep
grep -q '"verdict": "OSCILLATING"' <<<"$OUT" && pass "OSCILLATING (repeat) in envelope" || fail "missing OSCILLATING repeat"
# 3) A,B,A,B thrash over window (prod thrash_window=4) -> OSCILLATING
obs osc-thr 1 A 0.1; obs osc-thr 2 B 0.2; obs osc-thr 3 A 0.3; obs osc-thr 4 B 0.4
verdict 4 "thrash A,B,A,B -> OSCILLATING" osc-thr
grep -q '"pattern": "thrash"' <<<"$OUT" && pass "thrash pattern detected" || fail "thrash not detected"
# 4) flat progress over window (prod no_progress_window=3) -> STALLED
obs stall 1 a 0.5; obs stall 2 b 0.5; obs stall 3 c 0.5; obs stall 4 d 0.5
verdict 4 "flat progress -> STALLED (escalate)" stall
grep -q '"verdict": "STALLED"' <<<"$OUT" && pass "STALLED in envelope" || fail "missing STALLED"
# 5) on_stall=halt -> HALT (exit 3)
cat > "$WORK/halt-stall.yaml" <<'YAML'
version: 1
profiles:
prod:
convergence:
oscillation_repeat: 3
no_progress_window: 3
on_stall: halt
YAML
obs halt-run 1 x 0.5; obs halt-run 2 x 0.5; obs halt-run 3 x 0.5
CASAN_LOOP_POLICY_FILE="$WORK/halt-stall.yaml" verdict 3 "on_stall=halt -> HALT" halt-run
# 6) corrupt observation stream -> fail-closed HALT
mkdir -p "$CASAN_LOOP_STATE_ROOT/runs/broken"
printf 'not-json{{{\n' > "$CASAN_LOOP_STATE_ROOT/runs/broken/convergence.jsonl"
verdict 3 "corrupt observation stream -> fail-closed HALT" broken
grep -q '"reason": "fail_closed"' <<<"$OUT" && pass "corrupt stream fails closed" || fail "corrupt stream not fail-closed"
# 7) insufficient data -> CONVERGING (governor is the hard stop)
obs few 1 a 0.1
verdict 0 "insufficient data -> CONVERGING" few
# 8) verdict wrote a hash-linked audit record chaining to genesis
AUDIT="$CASAN_LOOP_STATE_ROOT/audit/loop-audit.jsonl"
if [[ -s "$AUDIT" ]]; then
pass "audit log written on verdict"
python3 - "$AUDIT" <<'PY' && pass "audit chain links to genesis" || fail "audit chain broken"
import json, sys
lines=[l for l in open(sys.argv[1]) if l.strip()]
prev="0"*64
for l in lines:
e=json.loads(l)
if e.get("prev_hash")!=prev: raise SystemExit(1)
prev=e.get("hash")
raise SystemExit(0 if lines else 1)
PY
else
fail "audit log not written"
fi
# 9) no repo pollution
if [[ -d "$CASAN_STATE_ROOT/state" ]] && [[ -n "$(ls -A "$CASAN_STATE_ROOT/state" 2>/dev/null)" ]]; then
fail "repo .specify/state was polluted"
else
pass "repo .specify/state stays clean"
fi
echo ""
echo "===== T2 SUMMARY: PASS=$PASS FAIL=$FAIL ====="
[[ "$FAIL" -eq 0 ]] || exit 1