quad/.claude/audit/handtrace-round7-reference-impl/spikes/t9_gate_chain.luau
qwreey 6f939a8d2d
audit: 7라운드 4·5·6차 패스의 참조 구현·스파이크를 저장소로 (재현 가능하게)
지금까지 세션 스크래치패드에만 있던 것을
.claude/audit/handtrace-round7-reference-impl/로 옮긴다. 다음 세션이
발견 52건을 판정하려면 이게 있어야 한다.

구성:
- spikes/core.luau      — 반응형 코어(state-epoch §2~§5, 전파 모델,
                          gate 4·8번, Blocker, H-23 스냅샷)
- spikes/dispatch.luau  — Length/Offset 부기(getOffsetAt 접두합 캐시,
                          recompute, setLength/setOffsetSource, 배치 게이팅)
- spikes/chain.luau     — Dispatch 체인(하강 diff, retractFrom)
- spikes/*.luau         — 시나리오 29개(런타임 18 + 타입 11)
- RUN-runtime.txt / RUN-typecheck.txt — 2026-08-25 실행 결과 스냅샷
- README.md             — 원문 대조표 + 스파이크→발견 대조표

⚠️ README가 가장 중요하다: 이 참조 구현은 base/의 확정 의사코드를 손으로
옮긴 **전사물**이라 그 자체가 틀렸을 수 있다. 그래서 "재실행은 검증이
아니다"를 못박고, (a) 어느 파일이 어느 절을 옮긴 것인지 대조표와
(b) 문서와 **의도적으로** 다른 곳 3개(H-72 때문에 임시로 둔 PeekDiffers,
H-102의 A/B 대조를 위한 위치 박스, 생명주기 게이팅 부재=H-97)를 같이
싣는다. 그 셋 외의 모든 차이는 전사 오류 후보다.

부수로 round7 문서 머리에 이 폴더 포인터와 같은 경고를 달았고,
.claude/README.md의 audit/ 행에도 등재했다.

Co-authored-by: qwreey <me@qwreey.moe>
2026-08-25 12:00:08 +09:00

27 lines
1.5 KiB
Text

--!nocheck
local q = require("./core")
-- gate-plan.md 4번: "하류가 또 다른 게이트면 받은 집합을 풀어 자기 withheld에 합친다.
-- 게이트가 몇 겹으로 겹쳐도 각 층이 자기 집합을 들고 있으므로 어느 층이 먼저 풀리든
-- 정보가 안 샌다"
local function run(order)
local A, B = q.Source(1), q.Source(1)
local w = q.State(function(self, prev, a, b) return a:Get() + b:Get() end, {A, B}, "w")
local b1, b2 = q.Blocker(), q.Blocker()
local g1 = q.Gate(w, function(emit) return b1:Policy(emit) end, "g1")
local g2 = q.Gate(g1, function(emit) return b2:Policy(emit) end, "g2")
local hits = {}
local o = q.Observer(g2, function(self, from)
local n = 0; for _ in from do n += 1 end
table.insert(hits, ("v=%d, batch=%d"):format(g2:Get(), n))
end, "o")
b1:On(); b2:On()
A:Set(2); B:Set(3)
local function w1() return next(g1.withheld) ~= nil end
local function w2() return next(g2.withheld) ~= nil end
print(("[%s] 유보 중 g1=%s g2=%s | 발화 %d"):format(order, tostring(w1()), tostring(w2()), o.fires))
if order == "상류 먼저" then b1:Off(); print(" b1:Off 후 g1=" .. tostring(w1()) .. " g2=" .. tostring(w2()) .. " 발화=" .. o.fires); b2:Off()
else b2:Off(); print(" b2:Off 후 g1=" .. tostring(w1()) .. " g2=" .. tostring(w2()) .. " 발화=" .. o.fires); b1:Off() end
print((" 최종 발화 %d | %s"):format(o.fires, table.concat(hits, " ; ")))
end
run("상류 먼저")
run("하류 먼저")