You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Phase 87 — post-refactor hardening (after Phase 86b's cdp-client extraction):
- Extract cdp/recovery.ts (probeFreshness, recoverFromStaleTarget) from utils.ts.
Replaces error-string matching for stale detection with the __RN_AGENT.__v
version probe as the primary signal. utils.ts shrinks; recovery is testable
in isolation.
- Extract cdp/connect.ts (autoConnect, discoverAndConnect, connectToTarget,
connectWs) via a ConnectContext. Shrinks CDPClient facade to a thin shell
over the cdp/* modules.
- Extract cdp/helper-expr.ts — helperExpr + bridgeWithFallback now pure
functions testable without a CDPClient.
- cdp/state.ts now exposes a setter-based ResettableState interface, replacing
the `as unknown as CDPResettableState` cast. Rename a private field and the
type system actually catches it.
- D631 (S1): cache the freshness probe for 2s per (client, connectionGeneration)
via a WeakMap. Eliminates the 30-150ms extra round-trip on back-to-back
tool calls.
- D632 (S2): RingBuffer gains an optional indexKey option building a parallel
Map<key, entry>. Network event handlers + tools/network-body.ts swap
findLast (O(n)) for getByKey (O(1)).
- D634: optional `code` field on ResultEnvelope — ToolErrorCode union of
STALE_TARGET / HELPERS_STALE / RECONNECT_TIMEOUT / NOT_CONNECTED /
HELPERS_NOT_INJECTED. Agents can branch on code instead of regex on
error text.
- B110/D630: MCP server version now comes from package.json at module load
(readFileSync of ../package.json). Replaces the hardcoded '0.10.1' literal
in index.ts that had drifted 7 minor versions from the real version.
sync-versions.sh gets a regex guard that fails CI if any future
`version: '...'` literal appears in src/.
Phase 88 — benchmark-surfaced plugin fixes:
- B111/D635: cdp_connect now accepts targetId + bundleId filters threaded
through autoConnect -> discoverAndConnect -> selectTarget. Fixes silent
attachment to zombie Expo Go host.exp.Exponent pages when the real
com.<app> target is also present. selectTarget also supports a soft
preferredBundleId for auto-selection. Back-compat preserved — legacy
string signature still works.
- B113/D636: device_screenshot dropped the unconditional `--format` flag
(agent-device >= 0.8.0 rejects it with Unknown flag: --format). Now uses
--out <path> explicitly. The handler was split into a pure
buildScreenshotArgs() + thin delegate so tests have no runAgentDevice
coupling.
Tests: +45 across the session (158 -> 203).
- cdp-state.test.js: 7 tests for resetState setter interface + sleep
- cdp-discovery.test.js: 9 tests for filterValidTargets + selectTarget,
plus 7 for the B111 filter matrix (targetId, bundleId, preferredBundleId,
precedence, legacy signature)
- cdp-transport.test.js: 11 tests for sendWithTimeout, rejectAllPending,
handleMessage, including malformed-message tolerance
- device-screenshot.test.js: 5 tests guarding against --format regression
- ring-buffer.test.js: 7 new tests for the indexKey feature (eviction,
key-reuse, clear semantics)
All 203 tests pass; TypeScript clean; dist/ rebuilt.
console.error(`CDP: target ${candidate.id} (${candidate.title}) has __DEV__=${devCheck.value}, skipping`);
133
-
if(sorted.indexOf(candidate)<sorted.length-1){
134
-
if(this.ws){
135
-
this.ws.removeAllListeners();
136
-
if(this.ws.readyState===WebSocket.OPEN)
137
-
this.ws.close();
138
-
this.ws=null;
139
-
}
140
-
this._state='disconnected';
141
-
this._helpersInjected=false;
142
-
this._connectedTarget=null;
143
-
continue;
144
-
}
145
-
console.error('CDP: no target with __DEV__=true found, using last available target');
146
-
connectedTarget=candidate;
147
-
}
148
-
catch(err){
149
-
if(sorted.indexOf(candidate)<sorted.length-1)
150
-
continue;
151
-
throwerr;
152
-
}
153
-
}
154
-
this._connectionGeneration++;
155
-
logger.info('CDP',`Connected to target ${connectedTarget.id} (${connectedTarget.title}) on port ${metroPort}, generation=${this._connectionGeneration}`);
156
-
constmsg=`Connected to ${connectedTarget.title} on port ${metroPort}`;
0 commit comments