Files
bikoret/shoresh-engine/src/Shoresh/KiTov.hs
T
Scott KarpandClaude Sonnet 4.6 c039fa61e0 Phase 1-2 build: Steps 5-6, 8-13
Shoresh Engine (Haskell, Step 5)
- 12 modules: Types, Lexicon, Binyanim, Teamim, Gematria, Graph,
  KetivQere, Smikhut, Havdalah, Kriah, KiTov, Firmware
- 33 EUnit tests, 0 failures
- Firmware module verifies L1 SHA-256 hash at startup

Talmudic Engine (SWI-Prolog, Step 6)
- 15 modules: halt, reasoning, specification, interface
- 57 PlUnit tests, 0 failures
- Three cardinal halt conditions: avodah_zarah, shfichut_damim, gilui_arayot

Vav Pipeline (Elixir, Steps 8-11)
- 14 modules: BereishitCycle, Shema, Cloud, Manna, L1Reader,
  Specification, HaltConditions, ShabbatTimer, CycleLog, Chatzotzrot,
  ShoreshEngineClient, TalmudicEngineClient, Application
- 46 ExUnit tests, 0 failures
- Nishma-first architecture: hears before it speaks

Sanhedrin Framework (Erlang/OTP, Step 12)
- 8 modules: sanhedrin_app, sanhedrin_sup, escalation, panel_sup,
  panel, judge, clerk, halt_monitor
- 46 EUnit tests, 0 failures (includes fix: rejected outcome now reachable)
- Panel sizes: 1/3/23/71 — unanimous capital guilty → acquit (Sanhedrin 17a)
- Minority opinions append-only, never deleted

Korban Processor (Python, Step 13)
- 6 modules: korban, shechitah, semichah, zerikah, haktarah, router

Builder tooling: AGENTS.md, opencode.json, memory/, src/tools/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 14:02:34 -05:00

65 lines
2.4 KiB
Haskell

{-# LANGUAGE OverloadedStrings #-}
-- | KiTov — fitness evaluation.
--
-- Architecture §3.1:
-- kiTov :: ProcessedResult -> Specification -> Evaluation
-- data Evaluation = Tov | LoTov Text | Teiku
--
-- Evaluates whether processed output fits the specification.
-- "And God saw that it was good" — the evaluation against the source.
--
-- Ki tov is not approval. It is verification against specification.
-- The specification is Torah (L1). The evaluation checks:
-- 1. Are the roots real? (found in L1)
-- 2. Are the references valid? (point to existing verses)
-- 3. Are dual readings preserved? (ketiv/qere not collapsed)
module Shoresh.KiTov
( kiTov
, verifyRootsExist
, verifyReferences
) where
import Shoresh.Types
import Shoresh.Lexicon (ShoreshLexicon, lookupRoot)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Maybe (isNothing)
-- | Evaluate a processed result against the specification (lexicon).
kiTov :: ProcessedResult -> ShoreshLexicon -> Evaluation
kiTov result lexicon =
let rootCheck = verifyRootsExist (prRoots result) lexicon
refCheck = verifyReferences (prRoots result)
in case (rootCheck, refCheck) of
(Tov, Tov) -> Tov
(LoTov r, _) -> LoTov r
(_, LoTov r) -> LoTov r
(Teiku, _) -> Teiku
(_, Teiku) -> Teiku
-- | Verify that all roots in the result exist in the lexicon.
verifyRootsExist :: [ShoreshEntry] -> ShoreshLexicon -> Evaluation
verifyRootsExist entries lexicon =
let missing = [ seShoresh e | e <- entries
, isNothing (lookupRoot (seShoresh e) lexicon) ]
in case missing of
[] -> Tov
ms -> LoTov $ "Roots not found in lexicon: "
<> T.intercalate ", " (map shoreshToText ms)
-- | Verify that Torah references in the entries are structurally valid.
-- (Range checks — the full check against L1 files happens at the pipeline level.)
verifyReferences :: [ShoreshEntry] -> Evaluation
verifyReferences entries =
let invalid = concatMap checkEntry entries
in case invalid of
[] -> Tov
msgs -> LoTov $ T.intercalate "; " msgs
where
checkEntry entry = concatMap checkRef (seTorahOccurrences entry)
checkRef ref
| refChapter ref < 1 = ["Invalid chapter: " <> T.pack (show (refChapter ref))]
| refVerse ref < 1 = ["Invalid verse: " <> T.pack (show (refVerse ref))]
| otherwise = []