Repository navigation
bridge: split bridge.tsx by concern — state, stream, requests, rows (Arkho #77, 7.157.3) - #200
Merged
Merged
Conversation
bridge.tsx had grown to 2,036 lines carrying five concerns. It now keeps the hooks and every function that takes `$` (the session start, the child and the session it serves, control, the wait for a decision), and the rest moves beside it into modules that take no `$`: - bridge-state.tsx: the one state object, its types, resetBridge, and the shared helpers; - bridge-stream.tsx: the mod's copy of the live state, the poster, the child's stop, and a step end held for its rows; - bridge-requests.tsx: requests from outside and their settlement; - bridge-rows.tsx: each kept row's notice, and the export to the host. Each module imports only the ones listed before it, so there is no import cycle. That is why the held step end (endStep, releaseStepEnd) sits with the stream that track() releases it from, and stopChild sits with the poster's retire. The split only moves code: every function body and constant is unchanged, with `export` added where another module imports it. bridge.tsx re-exports what it exported before, so register.tsx and the tests import the same names. For a bridge-only module, the validator reports the same `$` calls, with the same call paths, as before. Arkho board #77.
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Arkho board ticket #77: split
hooks/mods/bridge.tsxby concern. The behavior is unchanged. Version 7.157.3, over main's 7.157.2 (main merged atb2a59fa0).Problem
bridge.tsxwas 2,036 lines and carried five concerns, each with its own state and its own asynchronous boundaries: the stream, control, requests and settlement, row order and export, and the child and the session. A change to one concern meant reading the whole file. DC2 (PR #195) left the split as residue, and #78 (plugin-own notices) is blocked on it.The layout
bridge.tsx(988 lines) keeps the hooks,registerBridge,bridgeStart, and every function that takes$: control (steer,interrupt,chooseModel,compact/runCompaction,deliver,mainTurnEnded, and the unknown-turn guard), the child and the session (onLine,startChild,switchSession,awaitNextSession,beat), andawaitDecision. The rest now sits beside it in modules that take no$. Each module imports only the ones listed before it, so there is no import cycle:bridge-state.tsxBridgeStateobject (export let state), its types,fresh/resetBridge, and the shared helpers (message,isRecord,parsed,capped,loopKey,isEffort)bridge-stream.tsxtrack,trackChunk,resyncEvent,forgetLive,adoptSeed,adoptKept), the poster (emit,pump,poster,lose,retire,stopChild), and a held step end (endStep,releaseStepEnd)bridge-requests.tsxraise,settle,claimCheck,decisionRecorded,settleDecided,callEnded,settleFromTranscript,answeredThrough,onAskNote,answerFromOutside,withdrawAll,firstQuestion,askCallForbridge-rows.tsxnoticeRow,announceRow,nameBlock,observeRow,exportRow,keepAskTwo placements differ from the ticket's grouping. Both keep the import graph acyclic:
endStepandreleaseStepEndlive in the stream module, not with the rows.track()releases a held end when a subagent stops, andemit→track→releaseStepEnd→emitis one recursion through the poster's entry point. With these two in the stream module, the rows module calls into the stream and the stream never calls back.stopChildlives besideretire, which the poster calls. If it stayed inbridge.tsx, the stream module would have to import the file that imports it.A pure move
Every function body and constant moved verbatim. The only code edits are
exporton declarations that another module now imports, and the import lines. The section comment// Requests from outside the terminal.was dropped; the requests module's header replaces it. The module-header paragraphs moved to the modules they describe.bridge.tsxre-exports everything it exported before (TEXT_CAP,capped,resetBridge,STEP_END_WAIT_MS,RECORD_WAIT_MS,TRANSCRIPT_RETRY_MS,onAskNote), soregister.tsxandtests/mods/bridge.test.tskeep their imports unchanged.The files were generated by a script that slices main's
bridge.tsxby line range and asserts that every non-blank body line lands in exactly one module. A separate check compares the multiset of lines before and after, withexportstripped on both sides: the one line lost is that section comment, and every line added is a header, an import, or a re-export.Validation Evidence
tests/mods/run-mods-tests.sh, gated on 1-minute load < 60, insidewith-slot.sh298 pass, 0 fail(start load 58.28); the split:298 pass, 0 fail(start load 56.56); ask search: all checks passedtests/sminos/test-bridge{,-control,-requests,-export,-order}.sh, one at a time, gatedtest-bridge-order.shrunsbridge_order.py. After merging main (#199 changed the control suite),test-bridge-control.shagain: 80 assertions passed (start load 57.07)tests/mods/live-walk-check.py(merged tree, claude 2.1.301; it spends model calls)passed: 45 of 45 checks passed(start load 56.93), including a module reload mid-response, steer, interrupt, decide, answer, compact, model, the[ answer ]press, and the row-notice audit$callsclaude plugin validate --json .before and afterregistercalls onlyregisterBridge). Its fullcalls:line is identical before and after, down to everyviapath:$.clock.after (via bridgeStart, interrupt, startChild), … $.turn.abort (via interrupt), $.ui.logtscoverhooks/modsandtests/modsagainst the 2.1.301 engine typesask.tsx(L1454, L1496; there-entrycomparison); none in any bridge filedoperpowers:reviewer-high, lens: hook registration order,$scoping, shared stateResidue
$across an import (a probe withlogIt($)imported from a sibling file reported$.fs.read (via logIt)and no refusal). That contradicts the "$may only be passed to functions in the same file" rule quoted in CLAUDE.md and in the ask-async design, which cite an earlier build's refusal. The runtime loader was not tested with$crossing a file, so the split keeps to the rule. Whether the rule still binds is open.system/compact_boundary, the summaryuserrow,agent_listing_delta,mcp_instructions_delta,environment,model, all within 2 ms).runCompactionstays inbridge.tsxbecause it takes$;noticeRowand the cut are inbridge-rows.tsx.