Skip to content

Commit ad5edc7

Browse files
committed
refactor: update preflight handling and enhance low-confidence search quality guidance
- Modified preflight output structure to support both full preflight cards and flattened responses based on context. - Updated the logic in `buildEvidenceLock` to ensure low-confidence search quality status provides clear guidance for editing restrictions. - Added tests to validate behavior when search quality is low, ensuring readiness checks and next action messages are accurate.
1 parent 0cff063 commit ad5edc7

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,17 +1190,20 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
11901190
}
11911191
}
11921192

1193-
// Build lean preflight: flatten to { ready, reason } for agent consumption
1194-
let preflightOutput: { ready: boolean; reason?: string } | undefined;
1193+
// For edit/refactor/migrate: return full preflight card (risk, patterns, impact, etc.).
1194+
// For explore or lite-only: return flattened { ready, reason }.
1195+
let preflightPayload: { ready: boolean; reason?: string } | Record<string, unknown> | undefined;
11951196
if (preflight) {
11961197
const el = preflight.evidenceLock;
1197-
preflightOutput = {
1198+
// Full card per tool schema; add top-level ready/reason for backward compatibility
1199+
preflightPayload = {
1200+
...preflight,
11981201
ready: el?.readyToEdit ?? false,
11991202
...(el && !el.readyToEdit && el.nextAction && { reason: el.nextAction })
12001203
};
12011204
} else if (editPreflight) {
12021205
const el = editPreflight.evidenceLock;
1203-
preflightOutput = {
1206+
preflightPayload = {
12041207
ready: el?.readyToEdit ?? false,
12051208
...(el && !el.readyToEdit && el.nextAction && { reason: el.nextAction })
12061209
};
@@ -1221,7 +1224,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
12211224
hint: searchQuality.nextSteps[0]
12221225
})
12231226
},
1224-
...(preflightOutput && { preflight: preflightOutput }),
1227+
...(preflightPayload && { preflight: preflightPayload }),
12251228
results: results.map((r) => {
12261229
const relationships = enrichResult(r);
12271230
// Condensed relationships: importedBy count + hasTests flag

src/preflight/evidence-lock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ export function buildEvidenceLock(input: BuildEvidenceLockInput): EvidenceLock {
181181

182182
// Hard gate: low search quality overrides everything.
183183
// If retrieval is bad, we CANNOT claim readiness regardless of evidence counts.
184+
// Surface low-confidence guidance so callers see the actual reason edits are blocked.
184185
if (input.searchQualityStatus === 'low_confidence') {
185186
if (status === 'pass') status = 'warn';
186-
nextAction =
187-
nextAction || 'Search quality is low. Refine query or add concrete symbols before editing.';
187+
nextAction = 'Search quality is low. Refine query or add concrete symbols before editing.';
188188
if (!gaps.includes('Search quality is low')) {
189189
gaps.push('Search quality is low — evidence may be unreliable');
190190
}

tests/evidence-lock.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,39 @@ describe('Epistemic stress detection', () => {
198198
expect(lock.readyToEdit).toBe(true);
199199
});
200200
});
201+
202+
describe('Low-confidence search quality gate', () => {
203+
const lowConfidenceMessage =
204+
'Search quality is low. Refine query or add concrete symbols before editing.';
205+
206+
it('forces readyToEdit false when searchQualityStatus is low_confidence', () => {
207+
const lock = buildEvidenceLock({
208+
results: [makeResult('src/a.ts'), makeResult('src/b.ts'), makeResult('src/c.ts')],
209+
preferredPatterns: [
210+
{ pattern: 'inject()' },
211+
{ pattern: 'signals' }
212+
],
213+
relatedMemories: [makeMemory('1'), makeMemory('2')],
214+
failureWarnings: [],
215+
searchQualityStatus: 'low_confidence'
216+
});
217+
218+
expect(lock.readyToEdit).toBe(false);
219+
expect(lock.nextAction).toBe(lowConfidenceMessage);
220+
});
221+
222+
it('overrides prior warn nextAction with low-confidence guidance', () => {
223+
// Evidence that yields status 'warn' and "Proceed cautiously..." before low_confidence gate
224+
const lock = buildEvidenceLock({
225+
results: [makeResult('src/a.ts')],
226+
preferredPatterns: [{ pattern: 'Use service wrapper' }],
227+
relatedMemories: [makeMemory('1', { stale: true })],
228+
failureWarnings: [],
229+
searchQualityStatus: 'low_confidence'
230+
});
231+
232+
expect(lock.readyToEdit).toBe(false);
233+
expect(lock.nextAction).toBe(lowConfidenceMessage);
234+
expect(lock.nextAction).not.toContain('Proceed cautiously');
235+
});
236+
});

0 commit comments

Comments
 (0)