|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +WORKSPACE="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" |
| 5 | +COUNCIL_DIR="$WORKSPACE/memory/council-lite" |
| 6 | +INDEX_PATH="$COUNCIL_DIR/index.json" |
| 7 | + |
| 8 | +usage() { |
| 9 | + cat <<'EOF' |
| 10 | +Usage: validate-council-lite.sh [--latest | <session-id> | <session-path>] |
| 11 | +
|
| 12 | +Examples: |
| 13 | + ./scripts/validate-council-lite.sh --latest |
| 14 | + ./scripts/validate-council-lite.sh 20260211-150000-design-safe-billing-webhooks |
| 15 | + ./scripts/validate-council-lite.sh memory/council-lite/20260211-150000-design-safe-billing-webhooks |
| 16 | +EOF |
| 17 | +} |
| 18 | + |
| 19 | +resolve_session_path() { |
| 20 | + local input="${1:-}" |
| 21 | + python3 - "$INDEX_PATH" "$COUNCIL_DIR" "$input" <<'PY' |
| 22 | +import json |
| 23 | +import os |
| 24 | +import sys |
| 25 | +from pathlib import Path |
| 26 | +
|
| 27 | +index_path = Path(sys.argv[1]) |
| 28 | +council_dir = Path(sys.argv[2]) |
| 29 | +input_value = sys.argv[3].strip() |
| 30 | +
|
| 31 | +if not index_path.exists(): |
| 32 | + raise SystemExit("No council-lite index found. Run council-lite first.") |
| 33 | +
|
| 34 | +data = json.loads(index_path.read_text(encoding="utf-8")) |
| 35 | +sessions = data.get("sessions", []) |
| 36 | +if not sessions: |
| 37 | + raise SystemExit("No council-lite sessions found in index.") |
| 38 | +
|
| 39 | +if input_value in ("", "--latest"): |
| 40 | + print(sessions[-1]["path"]) |
| 41 | + raise SystemExit(0) |
| 42 | +
|
| 43 | +input_path = Path(input_value) |
| 44 | +if input_path.exists() and input_path.is_dir(): |
| 45 | + print(str(input_path.resolve())) |
| 46 | + raise SystemExit(0) |
| 47 | +
|
| 48 | +for session in sessions: |
| 49 | + if session.get("id") == input_value: |
| 50 | + print(session.get("path", "")) |
| 51 | + raise SystemExit(0) |
| 52 | +
|
| 53 | +candidate = council_dir / input_value |
| 54 | +if candidate.exists() and candidate.is_dir(): |
| 55 | + print(str(candidate.resolve())) |
| 56 | + raise SystemExit(0) |
| 57 | +
|
| 58 | +raise SystemExit(f"Session not found: {input_value}") |
| 59 | +PY |
| 60 | +} |
| 61 | + |
| 62 | +main() { |
| 63 | + case "${1:-}" in |
| 64 | + -h | --help) |
| 65 | + usage |
| 66 | + exit 0 |
| 67 | + ;; |
| 68 | + esac |
| 69 | + |
| 70 | + local selector="${1:---latest}" |
| 71 | + local session_path |
| 72 | + session_path="$(resolve_session_path "$selector")" |
| 73 | + |
| 74 | + python3 - "$session_path" <<'PY' |
| 75 | +import sys |
| 76 | +from pathlib import Path |
| 77 | +
|
| 78 | +session_path = Path(sys.argv[1]) |
| 79 | +required_files = [ |
| 80 | + "session.md", |
| 81 | + "intake.md", |
| 82 | + "assembly.md", |
| 83 | + "deliberation/round1-position.md", |
| 84 | + "deliberation/round2-challenge.md", |
| 85 | + "deliberation/round3-converge.md", |
| 86 | + "plan.md", |
| 87 | +] |
| 88 | +
|
| 89 | +missing = [f for f in required_files if not (session_path / f).is_file()] |
| 90 | +if missing: |
| 91 | + print("Validation failed: missing required files") |
| 92 | + for item in missing: |
| 93 | + print(f"- {item}") |
| 94 | + raise SystemExit(1) |
| 95 | +
|
| 96 | +checks = { |
| 97 | + "session.md": ["# Council Lite Session", "Session ID:", "Goal:"], |
| 98 | + "intake.md": ["# Intake", "## Goal", "## Success Criteria"], |
| 99 | + "assembly.md": ["# Assembly", "## Recommended Agents", "## Selection Rationale"], |
| 100 | + "deliberation/round1-position.md": ["# Round 1 - Position"], |
| 101 | + "deliberation/round2-challenge.md": ["# Round 2 - Challenge"], |
| 102 | + "deliberation/round3-converge.md": ["# Round 3 - Converge"], |
| 103 | + "plan.md": ["# Execution Plan", "## Ordered Steps", "## Verification"], |
| 104 | +} |
| 105 | +
|
| 106 | +errors = [] |
| 107 | +for rel_path, required_tokens in checks.items(): |
| 108 | + text = (session_path / rel_path).read_text(encoding="utf-8") |
| 109 | + for token in required_tokens: |
| 110 | + if token not in text: |
| 111 | + errors.append(f"{rel_path}: missing token '{token}'") |
| 112 | +
|
| 113 | +if errors: |
| 114 | + print("Validation failed: content checks did not pass") |
| 115 | + for err in errors: |
| 116 | + print(f"- {err}") |
| 117 | + raise SystemExit(1) |
| 118 | +
|
| 119 | +print(f"Council-lite artifact validation passed: {session_path}") |
| 120 | +PY |
| 121 | +} |
| 122 | + |
| 123 | +main "$@" |
0 commit comments