Shemot 28:2 — V'asita vigdei kodesh l'Aharon achicha, l'khavod ul'tifaret. The builder makes the garments. The kohen wears them. Four access tiers (Operations spec §1.1): - Pe'ah (GET/POST /peah/ask) — public, no auth, no tracking. The stranger is safe to approach. - Courtyard (POST /courtyard/offering) — Bearer token auth, offering types: shelamim, olah, chatat, minchah - Chatzer (POST /chatzer/sanhedrin) — Sanhedrin deliberation, returns majority/minority with preserved dissent - Kodesh (GET /kodesh/health, /kodesh/status) — operator interface, health checks for K8s liveness/readiness probes Error format follows chatat protocol (Operations spec §1.2): KIYOR_* (422), SHABBAT (503), MANNA_DEPLETED (503), CLOUD_MOVING (503), HALT_* (503), UNAUTHORIZED (401) Implementation: - Plug.Router with Bandit HTTP server - Added to supervision tree via maybe_add_http_server - Checks system availability (Shabbat, halt) before processing - Health check reads L1 integrity, cloud, manna, halt monitor - Status shows all component states, signal count, refuge list - 16 API tests covering all four tiers + error format All 235 Elixir + 19 L3 + 195 Prolog + 33 Haskell = 463+ tests, 0 failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
95 lines
3.1 KiB
Elixir
95 lines
3.1 KiB
Elixir
defmodule VavPipeline.Application do
|
|
@moduledoc """
|
|
OTP Application for the Vav Pipeline.
|
|
|
|
Starts the supervision tree with:
|
|
- Repo (L3 PostgreSQL — oral tradition persistence)
|
|
- Chatzotzrot (silver trumpets — signal system)
|
|
- AreiMiklat (cities of refuge — protection protocol)
|
|
- EglahArufah (accountability for unknown harm)
|
|
- Bikurim (first fruits — release protocol)
|
|
- MannaLedger (consumption tracking and anti-hoarding enforcement)
|
|
- HaltMonitor (esh tamid — cardinal sin detection)
|
|
- ShabbatTimer (mandatory cessation monitor)
|
|
- Bandit HTTP server (bigdei kodesh — the garments)
|
|
- ShoreshEnginePort (Erlang Port to Haskell engine, if binary found)
|
|
- TalmudicEngineSocket (Unix socket to Prolog engine)
|
|
|
|
Step 14 (Architecture §4): Component connections supervised.
|
|
The port and socket are optional — the pipeline degrades gracefully
|
|
if external engines are not available (clients fall back to stubs).
|
|
"""
|
|
|
|
use Application
|
|
|
|
require Logger
|
|
|
|
@impl true
|
|
def start(_type, _args) do
|
|
shoresh_binary = Application.get_env(:vav_pipeline, :shoresh_engine_binary, "shoresh-engine")
|
|
shoresh_cwd = Application.get_env(:vav_pipeline, :shoresh_engine_cwd, nil)
|
|
talmudic_socket = Application.get_env(:vav_pipeline, :talmudic_socket_path, "/tmp/shorashim/talmudic.sock")
|
|
|
|
children =
|
|
[
|
|
{VavPipeline.Chatzotzrot, []},
|
|
{VavPipeline.AreiMiklat, []},
|
|
{VavPipeline.EglahArufah, []},
|
|
{VavPipeline.Bikurim, []},
|
|
{VavPipeline.MannaLedger, []},
|
|
{VavPipeline.HaltMonitor, []},
|
|
{VavPipeline.ShabbatTimer, []}
|
|
]
|
|
|> maybe_add_http_server()
|
|
|> maybe_add_repo()
|
|
|> maybe_add_shoresh_port(shoresh_binary, shoresh_cwd)
|
|
|> maybe_add_talmudic_socket(talmudic_socket)
|
|
|
|
opts = [strategy: :one_for_one, name: VavPipeline.Supervisor]
|
|
Supervisor.start_link(children, opts)
|
|
end
|
|
|
|
defp maybe_add_http_server(children) do
|
|
port = Application.get_env(:vav_pipeline, :http_port, 4000)
|
|
|
|
if port do
|
|
children ++ [{Bandit, plug: VavPipeline.BigdeiKodesh.Router, port: port}]
|
|
else
|
|
children
|
|
end
|
|
end
|
|
|
|
defp maybe_add_repo(children) do
|
|
repo_config = Application.get_env(:vav_pipeline, VavPipeline.Repo)
|
|
|
|
cond do
|
|
is_nil(repo_config) ->
|
|
Logger.warning("VavPipeline.Repo: no config found — running without L3 persistence")
|
|
children
|
|
|
|
repo_config[:start] == false ->
|
|
Logger.info("VavPipeline.Repo: start disabled — running without L3 persistence")
|
|
children
|
|
|
|
true ->
|
|
[VavPipeline.Repo | children]
|
|
end
|
|
end
|
|
|
|
defp maybe_add_shoresh_port(children, binary, cwd) do
|
|
case System.find_executable(binary) do
|
|
nil ->
|
|
Logger.warning("ShoreshEnginePort: binary '#{binary}' not in PATH — running without Haskell engine")
|
|
children
|
|
|
|
path ->
|
|
children ++ [{VavPipeline.ShoreshEnginePort, [binary: path, cwd: cwd]}]
|
|
end
|
|
end
|
|
|
|
defp maybe_add_talmudic_socket(children, socket_path) do
|
|
# Always add the socket client — it connects lazily on first request
|
|
children ++ [{VavPipeline.TalmudicEngineSocket, [socket_path: socket_path]}]
|
|
end
|
|
end
|