Skip to content

Commit 2303128

Browse files
refactor(mcp): align ref-pin result handling with #1343 typed result projection
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent fd06d2b commit 2303128

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/mcp/tool-ref-pins.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ function mergeIssuedRefPins(
133133
return;
134134
}
135135
if (!REF_ISSUING_TOOLS.has(name)) return;
136-
const record = asOptionalRecord(result);
137-
const refsGeneration = record?.refsGeneration;
138-
if (record === undefined || typeof refsGeneration !== 'number') {
136+
const record = result as CommandExecutionResult<'snapshot' | 'find'>;
137+
const refsGeneration = record.refsGeneration;
138+
if (typeof refsGeneration !== 'number') {
139139
// ADR 0014: a MUTATING find returns its acted ref as diagnostic pre-action
140140
// identity WITHOUT `refsGeneration` — it is explicitly non-issuing and must
141141
// leave remembered pins untouched (forwarding the old pin on a later ref is
@@ -161,11 +161,14 @@ function mergeSettleIssuedRefPins(
161161
scopeKey: string,
162162
result: CommandExecutionResult,
163163
): void {
164-
const settle = asOptionalRecord(asOptionalRecord(result)?.settle);
164+
const interactionResult = result as CommandExecutionResult<
165+
'press' | 'click' | 'fill' | 'longpress'
166+
>;
167+
const settle = asOptionalRecord(interactionResult.settle);
165168
if (!settle) return;
166-
const refsGeneration = settle?.refsGeneration;
169+
const refsGeneration = settle.refsGeneration;
167170
if (typeof refsGeneration !== 'number') return;
168-
const lines = asOptionalRecord(settle?.diff)?.lines;
171+
const lines = asOptionalRecord(settle.diff)?.lines;
169172
const issuedRefs: string[] = [];
170173
collectRefBodies(lines, issuedRefs);
171174
collectRefBodies(settle.refs, issuedRefs);
@@ -197,9 +200,7 @@ function recordIssuedPins(
197200
pins.set(ref, refsGeneration);
198201
}
199202
while (pins.size > MAX_REF_PINS_PER_SCOPE) {
200-
const oldest = pins.keys().next().value;
201-
if (oldest === undefined) break;
202-
pins.delete(oldest);
203+
pins.delete(pins.keys().next().value!);
203204
}
204205
}
205206

0 commit comments

Comments
 (0)