Repository navigation
Description
The problem
A few source and test files are too big for a coding agent to read whole. Agents read them in many small sed -n ranges, each after a grep -n to find the spot. That costs tokens and turns, and an agent that sees one range at a time misses what sits next to it. In the last 10 agent sessions the worst file, src/drivers/android/index.ts, was read in 198 separate ranges.
Cut-off: 1,400 lines for code and 2,500 for tests (measured with git ls-files src ui e2e scripts .agents/scripts | xargs wc -l, no vendor, generated files or fixtures). Both sit at a gap in the spread: code drops from 1,431 to 1,336, tests from 2,835 to 2,485. Nothing in ui/, e2e/, scripts/ or .agents/scripts/ is above either cut-off.
| File | Lines | Range reads (last 10 sessions) |
|---|---|---|
src/drivers/android/index.ts |
3,073 | 198 |
src/drivers/ios/index.ts |
2,228 | 78 |
src/daemon/main.ts |
1,885 | 37 |
src/daemon/server.ts |
1,782 | |
src/gateway/fleet-coordinator.ts |
1,623 | 48 |
src/leasing/lease-acquisition-coordinator.ts |
1,537 | 50 |
src/contract/schemas.ts |
1,431 | 55 |
src/cli/index.test.ts |
11,107 | 44 |
src/drivers/android/index.test.ts |
8,327 | 129 |
src/gateway/fleet-coordinator.test.ts |
5,283 | |
src/leasing/create-leasing.test.ts |
5,208 | |
src/daemon/main.test.ts |
5,158 | |
src/drivers/ios/index.test.ts |
4,935 | 53 |
src/daemon/dispatcher.test.ts |
4,929 | 89 |
src/agent-device/edge.test.ts |
4,516 | |
src/daemon/server.test.ts |
4,355 | |
src/leasing/lease-acquisition-coordinator.test.ts |
3,640 | |
src/core/doctor.test.ts |
3,409 | |
src/http/app.test.ts |
3,396 | |
src/core/warm-pool/converger.test.ts |
2,905 | |
src/core/registry.test.ts |
2,835 |
Who runs into this
Every coding agent that builds, reviews or fixes a change in these modules: the implementer, the reviewers and bug triage. Most features touch at least one of these files.
What you would like to happen
Split each file along the seams below, so no listed file stays above its cut-off. Behaviour does not change.
Rules for every split:
- A move only. The module's surface stays its
index.tswith the same exports; nothing outside the directory imports a new file (architecture rule 14). - Tests keep going through
index.ts(testing rule 6). Helpers a split test file shares move once into onetest-<name>.tsbeside it, never copied (Fallow's duplication check). A helper nothing uses after the move is deleted (Fallow's dead-code check). - Moved lines count as added for
comment-lintandtest-lint. A moved comment that is not awhy:is deleted (architecture rule 17), and a moved test the lint rejects is fixed. - The module's
AGENTS.mdfiles table names the new files.
src/drivers/android/index.ts
AndroidDriver keeps the Driver verbs and create, and calls into:
passthrough-rules.ts:ANDROID_PASSTHROUGH_TOOLS,REFUSED_ADB_VERB,REFUSED_ADB_SEQUENCES,walkGlobals,actsOnNoDevice,namesOwnSerial,fillAdbDevice,containsSequence,refusedSequenceMessage,isBareShell, the body of#assertProxyable. All pure.console-ports.ts:PortAllocator,portAllocatorFor,consolePortsInUse,portsFromAdbDevices,serialFor.system-images.ts: the component verbs' bodies,#installedImages,#matchingImage,#requireImage,#taggedApiLevel,#installSystemImageOrThrow,#acceptLicenses,#sdkmanager,AndroidLicenseNotAcceptedError,AndroidImageTagMissingErrorand the image helpers (systemImagePackage,packageRevision,readSourceProperties,systemImageTags,compareCatalogImages,hasUnacceptedLicense).avd-config.ts:#applyLibraryProfile,#applyHardwareProperties,#mergeConfigIniLines,#configHash,#currentConfigHash,#avdConfig,iniValues,isSeedHardwareLine,stableHash,defaultDeviceProfileSources.emulator-boot.ts:#startEmulator,#waitForReadiness,#bootSettled,#waitForExit,#emulatorLogTail,emulatorLaunchFlags,prepareLaunchArgs, and the clean baseline (#baselineVerdict,#reconcileBaseline,#captureBaseline,#loadCleanBaseline,#baselineHash,baselineLaunchInputs).ownership.ts: the marks (#writeMark,#writeDurableMark,#writeErasableMark,#readDurableMark,parseErasableMark,buildObservedMark) and the ownership probe (#deviceIsOwn,#serialIsOwn,#confirmAvdAnswers,#readAvdPath,#isOwnAvdPath,answeredAvdPath).
Stays together: the ownership probe is the one check before every emu kill, snapshot load and destroy (safety rule 1, architecture rule 10), so every caller goes through ownership.ts. makeReady's per-device lock stays in the driver. Provision and baseline share one config-hash function.
src/drivers/ios/index.ts
IosSimctlDriver keeps the Driver verbs, and calls into:
runtime-components.ts: the component verbs' bodies,#deleteRuntimeImage,#waitWhileDeleting,#downloadResidue,#assetsSize,#listedImages,#xcodebuildOrThrow,parseRuntimeImages,runtimeReceipt,leftoverDownloadsSentence.catalog.ts:parseCatalog,parseDeviceType,parseRuntime, the version helpers (versionTriple,compareVersions,isVersionInRange,formatVersionRange), the pairing lookups (findDeviceType,findPairedRuntime,pairedVersions), and theIos*Errorclasses.#resolveExactRuntimeand#resolveDefaultRuntimebecome functions over the catalog here.slim-boot.ts, besideslim-labels.tsandslim-overrides.ts:#canSlim,#writeOverrides,#readOverrides,#readBack,#skipApply,#removeOverrides,planSlimBoot,supportsPersistentSlim,#slimAdvisories.passthrough-rules.ts:REFUSED_SIMCTL_VERBS,CALLER_SUPPLIED_SCOPE_FLAGS,#assertProxyable,#subcommand,#refuse,#devicectlPassthrough.simctl.ts:#simctl,#legacySimctl,#invokeSimctl,#invokeXcrun,#scopedSimctlArgv,#checked,#assertSuccessful.
Stays together: the mark write and read with #ownedUdids (only owned devices are destroyed), and resolveSpec's cache with #resolvedSpec.
src/daemon/main.ts
The process entry block stays here (the CLI and MCP spawn this file, and it is a Fallow entry). startGatewayDaemon stays here too, because only main.ts may import the gateway (only-main-knows-gateway).
driver-discovery.ts:discoverDrivers,discoverIosDriver,discoverAndroidDriver,loadDriversModule,adbServerRejection,rootRejection,productionDeviceDataTables,resolveDeviceDataTables,platformPrerequisiteChecks,logAndroidDiagnostic.entry-support.ts:parseDaemonArgv,createFatalLogger,logAlreadyRunning,logFatalStart,serviceCheckFor,productionServiceCheck,currentServiceCheckHost.composeDaemonsplits in two: the part both roles share (ports, config, logger, bus, history,state.db, auth, version check) andcomposeWorker, which can move toworker-composition.tswithdeviceModeWiring,modelPreferenceWiring,emitSlimDiagnostic,processRunnerFor,deviceRoots.
Stays together: the HTTP frontend start handshake (gatewayStarted, stopHttpGateway, socketClaimed, lockClaim) and convergeStartup stay inside composeWorker, in today's order (the startup flow, ADR 0019).
src/daemon/server.ts
server-pushes.ts:#pushOutput,#pushStarted,#pushProgress,#pushComponentProgress,#pushEvent, the lease-lost and device health pairs (#notify*,#push*),#manageEventSubscription,writeFrame.server-hello.ts:#handleHello,ProtocolError,parseInput.
Stays in DaemonServer: start, stop and disposal (the stop order shuts the HTTP frontend before lease teardown), #dispatchLine and its gates (daemon.stop is caught before the protocol and stopping gates), and the #handleRequest switch.
src/gateway/fleet-coordinator.ts
fleet-refusals.ts:#reasonsFor,#reasonFor,#cannotServeReason,#refusedReason,#rememberCannotServe,#rememberRefusal,#refused,refusedCapacityReason,passedOver,Refusal.fleet-forwarding.ts: the forwarded calls after a grant (renew,release,releaseAll,exec,rotatebodies),#forwardToWorker,#withExecTimeout,#withLeaseRequestTimeout,#raceTimeout,#namedForCaller,#classifyRelayedError,replaceWholeId.
Stays together: #admit, #dispatch, #dispatchPass, #walkWaiter, #attempt, #settleGrant and the #reject* methods. This is the one dispatch path that architecture rule 10's worked example is about.
src/leasing/lease-acquisition-coordinator.ts
target-resolution.ts:resolve,#resolveSpec,#exactTarget,#resolveClass,#resolveRanged,#rangedTarget,#resolveOrInstall,checkedSpec,refusalOf,matchingRuntimes,newestRuntime,requiredOs,requestedRange, the downloading-progress helpers.lease-timing.ts:estimatedTiming,estimatedBootTiming,grantReadyTiming,releaseReclaimEstimateMs.- The update and maintenance hold (
beginMaintenance,holdForUpdate,releaseUpdateHold,endMaintenance,#refuseUnderHold,#refuseForUpdate) can follow if the file is still too big.
Stays together: request, the requester-limit and lease-id refusals, and the plan-then-perform loop (#drive, #perform, #decide, #nextPlan, #grant, the evictions, #bootShutdown, #defer, #enqueue, #reject, #wakeQueue).
src/contract/schemas.ts
Split it into one file per group, and index.ts re-exports each one:
device-schemas.ts: platform, class, state,deviceRecordSchema,statusDeviceSchema,grantedDeviceSchema,imageTagSchema, the quarantine message helpers.lease-schemas.ts:requesterIdSchema,leaseRecordSchema,leaseGrantSchema,leaseRequestRecordSchema,capacityReasonSchema,waitingRequestSchema,leaseProgressSchema,passthroughCommandSchema.status-schemas.ts: capacity, warm pool, health, update, host facts and load, platform catalog and thefit*bounders, installs, capabilities,workerViewSchema,statusLeaseSchema.config-schemas.ts:configSchema, token and daemon-mode schemas.report-schemas.ts: doctor, nuke, history, event envelope, inbox and usage schemas.
The type imports that name contract/schemas by path (ui/src/model/*, src/simlock-client/types.ts, src/core/warm-pool/config.ts) point at the new files. protocol-bump-check counts the move as a shape change, so the commit carries Protocol-bump: none (move only).
Test files
Each split follows the top-level describe blocks, and the shared harness moves to a test-<name>.ts beside the tests.
src/cli/index.test.ts:daemon-commands.test.ts(auto-launch blocks, daemon status, logs, install, start through a service),status.test.ts(fleet status, warm pool block, Load lines, history lines, update and status),lease-commands.test.ts(exit codes and remote passthrough, lease, holder renew and release, lease pushes,list --requests, rotate),config-and-tokens.test.ts(config set blocks, admin credential, tokens,--yes,--json),fleet-commands.test.ts(worker, component, catalog, device add and remove, alerts, warm forget, stats, events, mcp). Harness:runCliwiring,outputCapture,fakeClient,startInMemoryDaemon,startTestDaemon,testConfig.src/drivers/android/index.test.ts:driver-boot.test.ts(boot, readiness, baseline, reclaim and mark tests, launch options, console ports, registration, ownership),driver-profiles.test.ts(avdmanager reads, profile sources and advisories, library profiles, custom profile fit, library catalog, default models),driver-images.test.ts(image fit, image tag, licenses, component install, list and remove). Harness:createDriver,provisionedHarness,fitHarness,libraryHarness,EmulatorHost,PortTakingMachine, the scripted runners and expectations.src/drivers/ios/index.test.ts:driver-slim.test.ts(slim mode),driver-components.test.ts(empty runtime catalog, component install,listComponents(),removeComponent()),driver-catalog.test.ts(model classes, model and runtime pairing, default models).src/daemon/main.test.ts:driver-discovery.test.ts(thediscoverDriversblocks and the wiring helpers, following the code split),main-stop.test.ts(every stop and HTTP start race block),main-agent-device.test.ts(the agent-device edge block and itsdoctor.run).src/daemon/dispatcher.test.ts:dispatcher-leases.test.ts(ownership, release-all, requires, noWait refusal, startup parking, device mode),dispatcher-status.test.ts(everystatus.getblock,list.get),dispatcher-components.test.ts(component install, list, remove, image tags, download policy),dispatcher-exec.test.ts(device.exec, device add and remove). The rest stays.src/daemon/server.test.ts:server-update.test.ts(daemon.update),server-roles.test.ts(roles and ownership,daemon.stopauthorization). Shares a harness with the dispatcher tests where they overlap.src/gateway/fleet-coordinator.test.ts:fleet-routing.test.ts(catalog, busy or unable, cannot-serve retry, class and range, requires, starting worker, physical routing, no worker can serve),fleet-requests.test.ts(lease.rejected, recorded outcomes, caller-chosen ids, per-requester limit, why each worker cannot take a request).src/leasing/create-leasing.test.ts:create-leasing-warm.test.ts(warm pool, warm targets, warm pool port),create-leasing-requests.test.ts(lease.rejected, queue timeout, stored request recovery, class requests, chosen lease ids, per-requester limit, probes, waiting reasons, quarantine retry).src/leasing/lease-acquisition-coordinator.test.ts:lease-acquisition-class.test.ts(class requests),lease-acquisition-resolution.test.ts(missing runtimes, download progress, image tags, resolve, levels a model no longer pairs with), following the code split.src/agent-device/edge.test.ts:edge-request-rules.test.ts(the front's request rules),edge-lease-end.test.ts(ending a lease ends the session, capabilities). The large preamble of fakes moves totest-edge.ts.src/core/doctor.test.ts:doctor-stalled.test.ts(stalled transitions, startup read),doctor-advisories.test.ts(driver advisories, prerequisites, optional module findings).src/http/app.test.ts:app-leases.test.ts(lease-request routes, lease routes and exec),app-proxy-auth.test.ts(the sign-in proxy block with its stream and change blocks).src/core/warm-pool/converger.test.ts:converger-targets.test.ts(warm pool targets),converger-learned.test.ts(learned kinds).src/core/registry.test.ts:registry-physical.test.ts(physical, absent and enrollment blocks),registry-state-db.test.ts(state.db rows).
Anything else
- Wait for the baselines stack (Named baselines: a lease starts from a device the operator prepared #327: PRs feat(ios): every simulator is a copy of a seed, and every virtual device serves one lease #1210, feat(android): every emulator is a copy of a seed, booted from its boot snapshot #1222, feat(baselines): save, list and remove baselines from held leases #1235, feat(leasing): a lease names a baseline and gets a copy of it #1236, feat(gateway): route baseline lease requests to a worker that holds the baseline #1241, feat(ios): lease --label names the leased simulator #1243, feat(ui): a Baselines page and a device's baseline #1245) to merge first. It changes most of these files. Measure the line counts again then.
- This needs several tasks: one per file in the table (21). Two tasks on the same module run one after the other. Each one is a move-only PR that should merge fast, so it does not go stale against other work.
Written by an agent.
Activity
chore(agents): manuals reach agents, retired words, fresh checkouts, …
V3RON commentedon Nov 4, 2026
Being specified in #1259. This issue stays open until that feature ships.
Written by an agent.
github-actions commentedon Nov 4, 2026
Shipped as #1259.
github-actions commentedon Nov 4, 2026
Shipped as #1259.
refactor(agent-device): split edge.test.ts into parts (ADR 0063) (#1339)
refactor(daemon): split server.ts into parts (ADR 0063) (#1341)
refactor(core): split doctor.test.ts and registry.test.ts into parts …
refactor(gateway): split fleet-coordinator.ts into parts (ADR 0063) (#…
fix(test-lint): a contract schema counts as moved only when its whole…
refactor(contract): callers past the index import the schemas barrel …
docs(contract): restore the reasons the split dropped from schema doc…
refactor(leasing): split lease-acquisition-coordinator.test.ts into p…
refactor(http): split app.test.ts into parts (ADR 0063) (#1343)
refactor(contract): split schemas.ts into parts (ADR 0063) (#1345)
refactor(daemon): split main.ts into parts (ADR 0063) (#1347)