Repository navigation
refactor(server): extract protocol preparation + tool-injection zone into src/server/{prepare-*,inject} modules - #2368
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2553-pr.2368.c93ed52This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2368.tgz
npm install -g packageInstall instructions are refreshed on each push. |
6961308 to
f379e29
Compare
…into src/server/{prepare-*,inject} modules (#1440 P2 cut 2)
f379e29 to
a233b6e
Compare
[bot] 🏷 上游冲突已解决,分支已 rebase 到最新 master 并 force-push,PR #2368 现读
补充:master 本会话期间连续前进三次( |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.132-master.1716212 # this exact build
npm install -g billion-context@master # always the newest merged build
|
#1440 P2 cut 2: extract the protocol-preparation + tool-injection zone out of
src/server.tsinto five new modules. Pure move — zero renames, zero signature changes, zero logic edits.What moves where
src/server/prepare-anthropic.tsprepareAnthropic+ auto-mode classifier pair (AUTO_MODE_CLASSIFIER_STOPS/isAutoModeClassifier, stay non-exported — sole caller was in-zone)src/server/prepare-openai.tsprepareOpenaisrc/server/prepare-google.tsappendGoogleNudge(internal),prepareGoogle,prepareGoogleCountTokenssrc/server/prepare-responses.tsprepareResponses,prepareResponsesCompact, codex-upstream/lite/prompt-cache-key helpers,effectiveAbsorbBlock(now exported; caller at former line 7259 imports it back)src/server/inject.tsinjectSystem, private generic coremergeOwnedTools+ the four flat wrappers,FORCE_TEXT_PROTOCOLStays in
src/server.ts:isCountTokensRequest+ theprepareCountTokensdispatcher (it calls the prepares → imports the new modules, no cycle), bothscrub*helpers, and everything else. Net: monolith-1458 lines(7707 → 6249 @ current master); 8 kept-helper defs gainexport; 3 now-dead import specifiers pruned fromacp-kernel/compress-settings/config.Cycle handling
New modules take type-only imports from
../server.ts(Prepared) and runtime values only from kernel/knobs/sibling modules… except the 8 helpers that were monolith-internal and are now cross-module: they became exportedfunctiondeclarations (ESM-hoisted ⇒ the module cycle cannot touch an uninitialized binding during circular init). Precedent:src/server/admin.tsfrom cut 1 already does this. No top-level const in any new module initializes from a../server.jsbinding.Proof it is a pure move
server.tsequals the verbatim moved zones (+ documentedexportprefixes at exactly 13 def sites); independently re-verified against the rebased base with a whole-tree multiset comparison — zero residual delta modulo blanks/import bookkeeping/export prefixes.X as knobXaliases.Rebase note
Built against
55af975e, rebased onto current master2495ad25: upstream #2332/#2302 (one-call payload) had amended exactly the four nudge-injection sites inside the moved zones. Their two-line change (const renderedWithPayload = rendered.text;) is ported byte-for-byte into the four new modules — no behavior delta versus master, just relocated together with their functions.Verification (all local, post-rebuild of kernel for the rebase)
npm run check:unused-exportsclean ·tsc --noEmit(incl. tests/) clean · full build (kernel + tsup + annotations) OKserver.jsre-export that keeps its brace-import intact), count-tokens, responses-websocket (38), preflight-compress-responses, preflight-responses-reasoning-extract, fix-920-bypass-drop, prompt-pack-tool-prompts, e2e-responses-offhead-system, e2e-image-billing (5/5), e2e-codex-fake (env-gated skip, unchanged) — all passreference/architecture.mdgains one line per new module (docs-sync gate)No behavior change intended; any golden/wire delta would have shown in the suites above.
Why this PR also touches
tests/side-lane-invariants.test.ts(lane-guard)The pure move carries three comment lines containing the phrase "side request" out of
src/server.ts; the lane guard's keyword scan over that file's diff fires on those deletions, and the guard has no exemption for comment relocation. Rather than rewording the comments to dodge the keyword or loosening the guard, I pinned a real invariant the guard exists to protect: test (F) asserts the five extracted modules never couple into the #388 side-lane engine (no import ofside-request.js, no gate symbols) — locking the module boundary this refactor creates. All four side-lane suites pass unchanged.