gate: Shorashim between a caller and a model, with the fringe and rebuke once (bishe'arecha step 4)

Devarim 6:9 / 11:20 — on your gates. POST /gate/anthropic/v1/messages and
POST /gate/openai/v1/chat/completions take the model's own request shape
under the caller's own upstream key (x-api-key, or Authorization with the
courtyard key in X-Shorashim-Key), forward it unchanged (OTP inets/ssl,
verify_peer; the Korban socket is serial, so the upstream call is made
in the Vav Pipeline and the reply enters as korban like every bedikah),
examine the reply with the request in hand — sources = the system prompt
and the user turns, query = the last user turn; the model's prior turns
are not sources — and deliver it with its fringe (Bamidbar 15:39): a
trailer on the last text block naming ref, verdict, the rules with their
verses and sentences; X-Shorashim-Bedikah / X-Shorashim-Verdict; a
`shorashim` object. A non-200 passes through as it came; a reply with
no text is not delivered; stream is refused.

Rebuke once (Vayikra 19:17; X-Shorashim-Rebuke: once): a lo_tov reply is
answered once more with the finding; the second reply is examined like
the first, its record carries rebukes: <first ref> (migration
20261007000002), and it is delivered marked with both. Never a third.

Manna: one api_calls_external per upstream call, gathered before any
call. Stateless: no conversation, no key kept; the log is the path class.
Gate.bearer accepts X-Shorashim-Key. Construction §3.10, Tamid §1.1,
KOHEN "Standing at the gate", bishearecha §I/§III/§VII marked built.
Elixir 592/0 (+14 gate tests incl. a real httpc round trip to a local
model double), L3 9/0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Scott KarpandClaude Fable 5.1 committed 2026-10-07 11:38:32 +00:00
1 parent 47025fbfeb
commit 5c63273dba
16 files changed
+1082 -15

No files matched your search

+50 -1
View File
@@ -293,7 +293,8 @@ Recorded in L3 (`bedikot`, append-only): provenance, query, the output's
SHA-256 and length — never the output itself — the sources by id,
SHA-256 and length — never their text — vital content, propositions,
references, claims with their anchors, authority claims, actions, the
sentences read for checks 4–6, the forms found for check 7, trace, violations, verdict.
sentences read for checks 4–6, the forms found for check 7, trace, violations, verdict,
and at the gate `rebukes` — the ref of the examination this one answers.
```
**Every rule cites its verse** (`bishearecha.md` §X; Devarim 4:2).
@@ -362,6 +363,54 @@ Errors: as /courtyard/bedikah, with "side 'a': …" / "side 'b': …" in the
message; a missing side is 422.
```
**The gate — between a caller and a model** (`bishearecha.md` §I, §III,
§VII; Construction §3.10; `VavPipeline.Gate`). The caller sends the
model's own request, in the model's own API shape, under the caller's
own upstream key; Shorashim forwards it unchanged, reads the reply as
korban with the request in hand — sources = the system prompt and the
user turns, query = the last user turn; the model's prior turns are not
sources — and delivers the reply with its fringe. Shorashim holds no
model key and keeps no conversation.
```
POST /gate/anthropic/v1/messages body: the Anthropic Messages request, unchanged
POST /gate/openai/v1/chat/completions body: the OpenAI Chat Completions request, unchanged
Headers:
Authorization: Bearer <courtyard key> (or X-Shorashim-Key: <courtyard key>)
x-api-key: <your Anthropic key> forwarded; never stored, never logged
Authorization: Bearer <your OpenAI key> with the courtyard key in X-Shorashim-Key
anthropic-version: 2023-06-01 forwarded (default when absent)
X-Shorashim-Rebuke: once optional — hocheach tochiach
Response (200): the upstream's reply, with
- the fringe appended to its last text block:
"\n\n— shorashim bedikah-<ref>: tov"
"\n\n— shorashim bedikah-<ref>: lo_tov — <rule> (<verse>): \"<sentence…>\"; …"
"… (after rebuke of bedikah-<first>: lo_tov)" when rebuked
- headers X-Shorashim-Bedikah, X-Shorashim-Verdict
- "shorashim": { bedikah_ref, verdict, violations, anchors, fired: ["<rule> (<verse>): …"],
checks, sources: [{id, sha256, length}], model,
rebuked?: {first_bedikah_ref, first_verdict}, disclosure }
Any non-200 from the upstream is returned as it came (X-Shorashim-Verdict: none).
A stream request is refused (422): a fringe needs the whole garment.
Rebuke once: when X-Shorashim-Rebuke is "once" and the first reply is
lo_tov, one second request = the first + the first reply as an
assistant turn + one user turn naming the rules that fired, their verses
and the sentences, asking for the answer again without them. The second
reply is examined like the first (its record carries rebukes: <first
ref>) and is the one delivered, marked with both. Never a third.
Manna: one api_calls_external per upstream call, one compute unit per
examination; spent → 503 MANNA_DEPLETED before any call. Errors: 401/403
(courtyard key), 422 (no upstream key, no messages, stream), 502
UPSTREAM_UNAVAILABLE (the gate made no verdict and delivered nothing),
503 KORBAN/TALMUDIC_UNAVAILABLE (a 200 from the model is never delivered
unexamined).
```
**Anchoring is deterministic and lexical** (`korban_processor/bedikah.py`):
a claim is anchored in a source when six consecutive words of it occur
there (`quote`), or when at least 60 % of its content words — and at