@applitools/mcp 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/index.js +894 -130
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3228,8 +3228,7 @@ function parseApplitoolsUrl(url) {
|
|
|
3228
3228
|
function parseSessionUrl(url) {
|
|
3229
3229
|
const parsed = parseApplitoolsUrl(url);
|
|
3230
3230
|
if (!parsed.sessionId) {
|
|
3231
|
-
throw new Error('The input URL is a batch URL while a session URL is expected.
|
|
3232
|
-
'Use the eyes_fetch_visual_results MCP tool to obtain URLs of sessions in this batch.');
|
|
3231
|
+
throw new Error('The input URL is a batch URL while a session URL is expected.');
|
|
3233
3232
|
}
|
|
3234
3233
|
return parsed;
|
|
3235
3234
|
}
|
|
@@ -4439,7 +4438,7 @@ function gateRejectionCount() {
|
|
|
4439
4438
|
|
|
4440
4439
|
var name = "@applitools/mcp";
|
|
4441
4440
|
var mcpName = "io.github.applitools/applitools";
|
|
4442
|
-
var version = "0.7.
|
|
4441
|
+
var version = "0.7.2";
|
|
4443
4442
|
var description = "Applitools MCP server for AI coding assistants";
|
|
4444
4443
|
var main = "./dist/index.js";
|
|
4445
4444
|
var bin = "./dist/index.js";
|
|
@@ -4569,6 +4568,21 @@ var packageJson = {
|
|
|
4569
4568
|
lavamoat: lavamoat
|
|
4570
4569
|
};
|
|
4571
4570
|
|
|
4571
|
+
/** Elides every image block's base64 `data` — one evidence call carries megabytes of screenshot, and users attach these logs to support tickets. */
|
|
4572
|
+
function serializeResultForLog(result) {
|
|
4573
|
+
const content = Array.isArray(result.content)
|
|
4574
|
+
? result.content.map(block => {
|
|
4575
|
+
var _a;
|
|
4576
|
+
return block.type === 'image'
|
|
4577
|
+
? {
|
|
4578
|
+
...block,
|
|
4579
|
+
data: `<${String((_a = block.data) !== null && _a !== void 0 ? _a : '').length} base64 chars elided>`,
|
|
4580
|
+
}
|
|
4581
|
+
: block;
|
|
4582
|
+
})
|
|
4583
|
+
: result.content;
|
|
4584
|
+
return JSON.stringify({ ...result, content }, null, 2);
|
|
4585
|
+
}
|
|
4572
4586
|
/** Recursively truncate arrays to `maxItems` before serialisation to avoid megabyte payloads in telemetry. */
|
|
4573
4587
|
function truncateForTelemetry(value, maxItems = 3) {
|
|
4574
4588
|
if (Array.isArray(value)) {
|
|
@@ -4716,7 +4730,7 @@ const createToolHandler = (toolDef, logic) => {
|
|
|
4716
4730
|
const validatedParams = toolDef.input.parse(enrichedParams || {});
|
|
4717
4731
|
const result = await withToolTelemetry(telemetry, () => logic(validatedParams));
|
|
4718
4732
|
if (isVerboseLogging)
|
|
4719
|
-
log$2('info', `[MCP] 📤 Result:`,
|
|
4733
|
+
log$2('info', `[MCP] 📤 Result:`, serializeResultForLog(result));
|
|
4720
4734
|
const structuredContentWithoutMessage = { ...result.structuredContent };
|
|
4721
4735
|
if (structuredContentWithoutMessage && 'message' in structuredContentWithoutMessage) {
|
|
4722
4736
|
delete structuredContentWithoutMessage.message;
|
|
@@ -5582,7 +5596,7 @@ const eyesSetupUfgTool = {
|
|
|
5582
5596
|
};
|
|
5583
5597
|
|
|
5584
5598
|
const TOOL_NAME$3 = TOOL_NAMES.EYES_ADD_CHECKPOINTS;
|
|
5585
|
-
const TOOL_DESCRIPTION$3 = '
|
|
5599
|
+
const TOOL_DESCRIPTION$3 = 'Setup step: add eyes.check() visual checkpoints to an existing Playwright test file. Edits source, not results.';
|
|
5586
5600
|
const PlaywrightJsAddCheckpointsInputSchema = commonInputSchema.extend({
|
|
5587
5601
|
filePath: zod.z
|
|
5588
5602
|
.string()
|
|
@@ -7438,20 +7452,21 @@ const MAX_DELAY_MS = 5000;
|
|
|
7438
7452
|
/** With the backoff curve above this yields probes at 1s, 2.5s, 4.75s, 8.1s, 13.1s, 18.1s —
|
|
7439
7453
|
* six re-checks — before the budget cuts the wait off and the running result goes to the caller. */
|
|
7440
7454
|
const AWAIT_BUDGET_MS = 20000;
|
|
7455
|
+
const COMPOSED_AWAIT_BUDGET_MS = 4000;
|
|
7441
7456
|
const defaultSleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
7442
7457
|
/**
|
|
7443
7458
|
* The MCP side of the api layer's caller-owned re-check cadence: absorb the polling for up to
|
|
7444
|
-
* `
|
|
7459
|
+
* `budgetMs` of planned waits (capped exponential backoff, not a fixed interval — a long
|
|
7445
7460
|
* task shouldn't be hammered every second), then hand the still-`running` result back so the
|
|
7446
7461
|
* tool layer can tell the agent exactly how to resume. The budget counts planned sleeps, not a
|
|
7447
7462
|
* clock — deterministic under test, and in production it keeps the tool call comfortably inside
|
|
7448
7463
|
* common MCP clients' ~60s timeout.
|
|
7449
7464
|
*/
|
|
7450
|
-
async function awaitWithinBudget(first, recheck, sleep, signal) {
|
|
7465
|
+
async function awaitWithinBudget(first, recheck, sleep, budgetMs, signal) {
|
|
7451
7466
|
let result = first;
|
|
7452
7467
|
let delay = INITIAL_DELAY_MS;
|
|
7453
7468
|
let planned = 0;
|
|
7454
|
-
while (result.status === 'running' && planned + delay <=
|
|
7469
|
+
while (result.status === 'running' && planned + delay <= budgetMs) {
|
|
7455
7470
|
// A cancelled request's response is discarded by the MCP layer anyway — stop burning probes
|
|
7456
7471
|
// the moment the client walks away; the server-side task keeps computing into the pair cache.
|
|
7457
7472
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
@@ -7467,18 +7482,18 @@ async function awaitWithinBudget(first, recheck, sleep, signal) {
|
|
|
7467
7482
|
}
|
|
7468
7483
|
/** Submits the domId pair and waits within the budget. A `running` return means the budget ran
|
|
7469
7484
|
* out first — resume with `awaitDomDiffTask` and the returned taskId, never by guessing. */
|
|
7470
|
-
async function awaitDomDiff(baseUrl, baselineDomId, checkpointDomId, keys, signal, deps = defaultAwaitDomDiffDeps) {
|
|
7485
|
+
async function awaitDomDiff(baseUrl, baselineDomId, checkpointDomId, keys, signal, deps = defaultAwaitDomDiffDeps, budgetMs = AWAIT_BUDGET_MS) {
|
|
7471
7486
|
var _a;
|
|
7472
7487
|
const first = await deps.fetchDomDiff(baseUrl, baselineDomId, checkpointDomId, keys);
|
|
7473
|
-
return awaitWithinBudget(first, taskId => deps.checkDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys), (_a = deps.sleep) !== null && _a !== void 0 ? _a : defaultSleep, signal);
|
|
7488
|
+
return awaitWithinBudget(first, taskId => deps.checkDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys), (_a = deps.sleep) !== null && _a !== void 0 ? _a : defaultSleep, budgetMs, signal);
|
|
7474
7489
|
}
|
|
7475
7490
|
/** Resumes waiting on an already-submitted task (a prior call's `running` taskId) — probes the
|
|
7476
7491
|
* task directly instead of resubmitting the pair, with the same budgeted cadence. A ready result
|
|
7477
7492
|
* still lands in the same domId-pair cache, so later calls for the pair are instant. */
|
|
7478
|
-
async function awaitDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys, signal, deps = defaultAwaitDomDiffDeps) {
|
|
7493
|
+
async function awaitDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys, signal, deps = defaultAwaitDomDiffDeps, budgetMs = AWAIT_BUDGET_MS) {
|
|
7479
7494
|
var _a;
|
|
7480
7495
|
const first = await deps.checkDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys);
|
|
7481
|
-
return awaitWithinBudget(first, nextTaskId => deps.checkDomDiffTask(baseUrl, nextTaskId, baselineDomId, checkpointDomId, keys), (_a = deps.sleep) !== null && _a !== void 0 ? _a : defaultSleep, signal);
|
|
7496
|
+
return awaitWithinBudget(first, nextTaskId => deps.checkDomDiffTask(baseUrl, nextTaskId, baselineDomId, checkpointDomId, keys), (_a = deps.sleep) !== null && _a !== void 0 ? _a : defaultSleep, budgetMs, signal);
|
|
7482
7497
|
}
|
|
7483
7498
|
|
|
7484
7499
|
const defaultFetchVisibleDomDiffDeps = {
|
|
@@ -7502,7 +7517,7 @@ function computeVisibleDomDiff(domDiff, area, visualDiffRects) {
|
|
|
7502
7517
|
result = excludeNonVisualNodeDiffs(result, visualDiffRects.baseline, visualDiffRects.checkpoint);
|
|
7503
7518
|
return serializeDiff(result);
|
|
7504
7519
|
}
|
|
7505
|
-
async function fetchVisibleDomDiff(url, stepIndex, keys, area, taskId, signal, deps = defaultFetchVisibleDomDiffDeps) {
|
|
7520
|
+
async function fetchVisibleDomDiff(url, stepIndex, keys, area, taskId, signal, deps = defaultFetchVisibleDomDiffDeps, budgetMs) {
|
|
7506
7521
|
var _a, _b;
|
|
7507
7522
|
const { baseUrl, batchId, sessionId, accountId } = await parseSessionUrlVerified(url, keys);
|
|
7508
7523
|
let rawSession;
|
|
@@ -7516,10 +7531,10 @@ async function fetchVisibleDomDiff(url, stepIndex, keys, area, taskId, signal, d
|
|
|
7516
7531
|
const baselineDomId = (_a = imageForSide(rawSession, stepIndex, 'baseline')) === null || _a === void 0 ? void 0 : _a.domId;
|
|
7517
7532
|
const checkpointDomId = (_b = imageForSide(rawSession, stepIndex, 'checkpoint')) === null || _b === void 0 ? void 0 : _b.domId;
|
|
7518
7533
|
if (!baselineDomId) {
|
|
7519
|
-
|
|
7534
|
+
return { status: 'no-baseline-dom', reason: 'This step has no baseline DOM capture' };
|
|
7520
7535
|
}
|
|
7521
7536
|
if (!checkpointDomId) {
|
|
7522
|
-
|
|
7537
|
+
return { status: 'no-checkpoint-dom', reason: 'This step has no checkpoint DOM capture' };
|
|
7523
7538
|
}
|
|
7524
7539
|
try {
|
|
7525
7540
|
// deps.awaitDomDiff (api, backend-computed) owns its own cache, keyed on the two domIds alone (already
|
|
@@ -7528,8 +7543,8 @@ async function fetchVisibleDomDiff(url, stepIndex, keys, area, taskId, signal, d
|
|
|
7528
7543
|
// requested or how the step's match settings/regions have changed since. A given taskId
|
|
7529
7544
|
// resumes that earlier submission's task directly instead of resubmitting the pair.
|
|
7530
7545
|
const alignment = taskId
|
|
7531
|
-
? await deps.awaitDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys, signal)
|
|
7532
|
-
: await deps.awaitDomDiff(baseUrl, baselineDomId, checkpointDomId, keys, signal);
|
|
7546
|
+
? await deps.awaitDomDiffTask(baseUrl, taskId, baselineDomId, checkpointDomId, keys, signal, undefined, budgetMs)
|
|
7547
|
+
: await deps.awaitDomDiff(baseUrl, baselineDomId, checkpointDomId, keys, signal, undefined, budgetMs);
|
|
7533
7548
|
if (alignment.status === 'running')
|
|
7534
7549
|
return { status: 'computing', taskId: alignment.taskId };
|
|
7535
7550
|
let domDiff = alignment.alignment.diff;
|
|
@@ -7550,10 +7565,165 @@ async function fetchVisibleDomDiff(url, stepIndex, keys, area, taskId, signal, d
|
|
|
7550
7565
|
if (/Unknown or expired task/.test(message)) {
|
|
7551
7566
|
throw new Error('The DOM diff task has expired server-side. Call this tool again with the same sessionUrl/stepIndex but WITHOUT taskId to restart the computation.');
|
|
7552
7567
|
}
|
|
7568
|
+
// Backend-owned and permanent for this step, so it's reported as structural rather than as a transient error.
|
|
7569
|
+
if (/No store found/i.test(message)) {
|
|
7570
|
+
return { status: 'no-dom-data', reason: `The server holds no DOM data for this step: ${message}` };
|
|
7571
|
+
}
|
|
7553
7572
|
throw new Error(`Error computing DOM diff: ${message}`);
|
|
7554
7573
|
}
|
|
7555
7574
|
}
|
|
7556
7575
|
|
|
7576
|
+
const EVIDENCE_PAD = 10;
|
|
7577
|
+
/** Unclamped, an area touching `left: 0` reaches the crop endpoint as `.clip(-10;…)`; a zero width or height means the area falls outside the image entirely. */
|
|
7578
|
+
function padAndClamp(rect, size, pad = EVIDENCE_PAD) {
|
|
7579
|
+
const clamp = (value, max) => Math.max(0, max === undefined ? value : Math.min(value, max));
|
|
7580
|
+
const left = clamp(rect.left - pad, size === null || size === void 0 ? void 0 : size.width);
|
|
7581
|
+
const top = clamp(rect.top - pad, size === null || size === void 0 ? void 0 : size.height);
|
|
7582
|
+
const right = clamp(rect.left + rect.width + pad, size === null || size === void 0 ? void 0 : size.width);
|
|
7583
|
+
const bottom = clamp(rect.top + rect.height + pad, size === null || size === void 0 ? void 0 : size.height);
|
|
7584
|
+
return { left, top, width: Math.max(0, right - left), height: Math.max(0, bottom - top) };
|
|
7585
|
+
}
|
|
7586
|
+
/** Which images this step can produce for this area — the two sides can differ in size, so an area can fall off one of them entirely. */
|
|
7587
|
+
function evidenceCandidates(step, areaRect) {
|
|
7588
|
+
var _a;
|
|
7589
|
+
const sides = [
|
|
7590
|
+
['baseline', step.baseline],
|
|
7591
|
+
['checkpoint', step.checkpoint],
|
|
7592
|
+
];
|
|
7593
|
+
return [
|
|
7594
|
+
// The diff is the checkpoint screenshot with differences highlighted, so it lives in checkpoint space.
|
|
7595
|
+
{ label: 'diff', size: (_a = step.checkpoint.size) !== null && _a !== void 0 ? _a : step.baseline.size, missing: false },
|
|
7596
|
+
...sides.map(([label, info]) => {
|
|
7597
|
+
var _a;
|
|
7598
|
+
return ({
|
|
7599
|
+
label,
|
|
7600
|
+
imageId: (_a = info.id) !== null && _a !== void 0 ? _a : undefined,
|
|
7601
|
+
size: info.size,
|
|
7602
|
+
missing: info.id === null,
|
|
7603
|
+
});
|
|
7604
|
+
}),
|
|
7605
|
+
].map(({ label, size, missing, ...rest }) => {
|
|
7606
|
+
const rect = padAndClamp(areaRect, size);
|
|
7607
|
+
const where = label === 'diff' ? 'the checkpoint image it is drawn on' : `the ${label} image`;
|
|
7608
|
+
return {
|
|
7609
|
+
label,
|
|
7610
|
+
...rest,
|
|
7611
|
+
rect,
|
|
7612
|
+
unavailable: missing
|
|
7613
|
+
? `this step has no ${label} image`
|
|
7614
|
+
: rect.width > 0 && rect.height > 0
|
|
7615
|
+
? undefined
|
|
7616
|
+
: `this area falls outside ${where}`,
|
|
7617
|
+
};
|
|
7618
|
+
});
|
|
7619
|
+
}
|
|
7620
|
+
/** The single source of truth for which images an area can have — `verifyDiffReportHardGate` must only demand evidence this says is obtainable. */
|
|
7621
|
+
function plannedEvidence(step, areaRect) {
|
|
7622
|
+
return evidenceCandidates(step, areaRect).filter(candidate => candidate.unavailable === undefined);
|
|
7623
|
+
}
|
|
7624
|
+
const EVIDENCE_FETCH_CONCURRENCY = 10;
|
|
7625
|
+
async function fetchEvidence(sessionUrl, stepIndex, areaRects, keys) {
|
|
7626
|
+
var _a;
|
|
7627
|
+
const session = await fetchSteps(sessionUrl, keys);
|
|
7628
|
+
const step = (_a = session.steps) === null || _a === void 0 ? void 0 : _a[stepIndex];
|
|
7629
|
+
if (!step)
|
|
7630
|
+
throw new Error(`Step index ${stepIndex} is out of range for this session.`);
|
|
7631
|
+
const { baseUrl } = parseSessionUrl(sessionUrl);
|
|
7632
|
+
const areas = areaRects.map(areaRect => {
|
|
7633
|
+
const candidates = evidenceCandidates(step, areaRect);
|
|
7634
|
+
return {
|
|
7635
|
+
areaRect,
|
|
7636
|
+
planned: candidates.filter(candidate => candidate.unavailable === undefined),
|
|
7637
|
+
unavailable: candidates
|
|
7638
|
+
.filter(candidate => candidate.unavailable !== undefined)
|
|
7639
|
+
.map(({ label, unavailable: reason }) => ({ label, reason: reason })),
|
|
7640
|
+
};
|
|
7641
|
+
});
|
|
7642
|
+
const tasks = areas.flatMap((area, areaIndex) => area.planned.map((request, imageIndex) => ({ areaIndex, imageIndex, request })));
|
|
7643
|
+
const paths = areas.map(area => new Array(area.planned.length));
|
|
7644
|
+
let cursor = 0;
|
|
7645
|
+
async function fetchNext() {
|
|
7646
|
+
while (cursor < tasks.length) {
|
|
7647
|
+
const { areaIndex, imageIndex, request } = tasks[cursor++];
|
|
7648
|
+
paths[areaIndex][imageIndex] =
|
|
7649
|
+
request.imageId === undefined
|
|
7650
|
+
? await fetchImageDiff(sessionUrl, stepIndex, keys, request.rect)
|
|
7651
|
+
: await fetchImage(baseUrl, request.imageId, keys, request.rect);
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
await Promise.all(Array.from({ length: Math.min(EVIDENCE_FETCH_CONCURRENCY, tasks.length) }, fetchNext));
|
|
7655
|
+
return areas.map(({ areaRect, planned, unavailable }, areaIndex) => ({
|
|
7656
|
+
areaRect,
|
|
7657
|
+
images: planned.map((request, imageIndex) => ({ ...request, path: paths[areaIndex][imageIndex], inline: false })),
|
|
7658
|
+
...(unavailable.length > 0 ? { unavailable } : {}),
|
|
7659
|
+
}));
|
|
7660
|
+
}
|
|
7661
|
+
/** Clients known to render an MCP `image` block; anything else gets paths only, since base64-as-text costs ~20k tokens per image and still shows nothing. */
|
|
7662
|
+
const IMAGE_RENDERING_CLIENTS = new Set(['Claude Code']);
|
|
7663
|
+
/** A count, not bytes: Claude Code prices an image block at a flat ~1600 tokens whatever the payload weighed. */
|
|
7664
|
+
const INLINE_IMAGE_BUDGET = 21;
|
|
7665
|
+
/** The most images one area can have (the diff plus both sides), so a batch sized against it inlines whole even in the worst case. */
|
|
7666
|
+
const MAX_IMAGES_PER_AREA = 3;
|
|
7667
|
+
/** The ceiling Claude Code re-encodes every image under, so raw bytes above it buy payload size for zero context. */
|
|
7668
|
+
const MAX_INLINE_IMAGE_BYTES = 512 * 1024;
|
|
7669
|
+
/** Whole areas, in area order: an area's images inline together or not at all, so no area is ever judged from a partial set. */
|
|
7670
|
+
function inlineGroups(evidence) {
|
|
7671
|
+
return evidence.map(area => area.images).filter(group => group.length > 0);
|
|
7672
|
+
}
|
|
7673
|
+
/** The paths are unconditional; the image blocks are the turn saving, and `inlining` reports what the budget actually did. */
|
|
7674
|
+
function buildEvidenceResult(evidence, budget = {}, composed = {}) {
|
|
7675
|
+
var _a, _b;
|
|
7676
|
+
const { images: budgetImages = INLINE_IMAGE_BUDGET, maxImageBytes = MAX_INLINE_IMAGE_BYTES } = budget;
|
|
7677
|
+
const rendersImages = IMAGE_RENDERING_CLIENTS.has((_b = (_a = getClientInfo()) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '');
|
|
7678
|
+
const groups = inlineGroups(evidence);
|
|
7679
|
+
const loaded = new Map();
|
|
7680
|
+
const load = (image) => {
|
|
7681
|
+
if (!rendersImages)
|
|
7682
|
+
return 'client-cannot-render';
|
|
7683
|
+
if (loaded.size >= budgetImages)
|
|
7684
|
+
return 'budget-spent';
|
|
7685
|
+
try {
|
|
7686
|
+
if (fs__namespace.statSync(image.path).size > maxImageBytes)
|
|
7687
|
+
return 'over-per-image-cap';
|
|
7688
|
+
return fs__namespace.readFileSync(image.path);
|
|
7689
|
+
}
|
|
7690
|
+
catch (error) {
|
|
7691
|
+
try {
|
|
7692
|
+
fs__namespace.rmSync(image.path, { force: true });
|
|
7693
|
+
}
|
|
7694
|
+
catch { }
|
|
7695
|
+
const area = evidence.find(entry => entry.images.includes(image));
|
|
7696
|
+
throw new Error(`Error reading the cached ${image.label} image for area ${JSON.stringify(area === null || area === void 0 ? void 0 : area.areaRect)} at ${image.path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
7697
|
+
}
|
|
7698
|
+
};
|
|
7699
|
+
for (const group of groups) {
|
|
7700
|
+
const spent = rendersImages && budgetImages - loaded.size < group.length;
|
|
7701
|
+
for (const image of group) {
|
|
7702
|
+
const outcome = spent ? 'budget-spent' : load(image);
|
|
7703
|
+
if (Buffer.isBuffer(outcome))
|
|
7704
|
+
loaded.set(image, outcome);
|
|
7705
|
+
Object.assign(image, {
|
|
7706
|
+
inline: Buffer.isBuffer(outcome),
|
|
7707
|
+
notInlined: Buffer.isBuffer(outcome) ? undefined : outcome,
|
|
7708
|
+
});
|
|
7709
|
+
}
|
|
7710
|
+
}
|
|
7711
|
+
// Reading order, not selection order: the JSON names inlined images only by their position in the evidence list.
|
|
7712
|
+
const imageBlocks = evidence
|
|
7713
|
+
.flatMap(area => area.images)
|
|
7714
|
+
.filter(image => loaded.has(image))
|
|
7715
|
+
.map(image => ({ type: 'image', data: loaded.get(image).toString('base64'), mimeType: 'image/png' }));
|
|
7716
|
+
const inlining = {
|
|
7717
|
+
inlined: loaded.size,
|
|
7718
|
+
images: groups.reduce((total, group) => total + group.length, 0),
|
|
7719
|
+
budgetImages,
|
|
7720
|
+
maxImageBytes,
|
|
7721
|
+
};
|
|
7722
|
+
return {
|
|
7723
|
+
content: [{ type: 'text', text: JSON.stringify({ evidence, ...composed, inlining }, null, 2) }, ...imageBlocks],
|
|
7724
|
+
};
|
|
7725
|
+
}
|
|
7726
|
+
|
|
7557
7727
|
const SEARCH_MULTIPLIER = 2;
|
|
7558
7728
|
const SEARCH_CAP = 10;
|
|
7559
7729
|
/**
|
|
@@ -7832,14 +8002,17 @@ function logDataToolCall(scopeId, toolName, args, deps) {
|
|
|
7832
8002
|
recordChainSource(scopeId, deps);
|
|
7833
8003
|
logInvocation(scopeId, toolName, args, deps);
|
|
7834
8004
|
}
|
|
7835
|
-
const
|
|
7836
|
-
.object({
|
|
8005
|
+
const RequiredRectShape = zod.z.object({
|
|
7837
8006
|
left: zod.z.number(),
|
|
7838
8007
|
top: zod.z.number(),
|
|
7839
8008
|
width: zod.z.number(),
|
|
7840
8009
|
height: zod.z.number(),
|
|
7841
|
-
})
|
|
7842
|
-
|
|
8010
|
+
});
|
|
8011
|
+
const RectShape = RequiredRectShape.optional();
|
|
8012
|
+
/** Areas, not images. An area inlines whole-or-not, so areas past what the budget holds would come back as paths only — a cost that moves to the client rather than disappearing. */
|
|
8013
|
+
const MAX_EVIDENCE_BATCH = Math.floor(INLINE_IMAGE_BUDGET / MAX_IMAGES_PER_AREA);
|
|
8014
|
+
/** A client only parallelises a batch of tool calls when every one of them declares `readOnlyHint`. */
|
|
8015
|
+
const READ_ONLY = { readOnlyHint: true };
|
|
7843
8016
|
/**
|
|
7844
8017
|
* Every `eyes_inspect_*` tool's own name, in one place — `registerTool`/`logDataToolCall` below
|
|
7845
8018
|
* read from here, and so does `verifyInvocation` in `../eyes-review/tools.ts`'s hard gates, so a
|
|
@@ -7854,9 +8027,56 @@ const EYES_INSPECT_TOOLS = {
|
|
|
7854
8027
|
dom: 'eyes_inspect_dom',
|
|
7855
8028
|
domSearch: 'eyes_inspect_dom_search',
|
|
7856
8029
|
domDiff: 'eyes_inspect_dom_diff',
|
|
8030
|
+
evidence: 'eyes_inspect_evidence',
|
|
7857
8031
|
regions: 'eyes_inspect_regions',
|
|
7858
8032
|
history: 'eyes_inspect_history',
|
|
7859
8033
|
};
|
|
8034
|
+
/** Only `eyes_inspect_dom_diff` resumes the server task, whichever call surfaced the taskId. */
|
|
8035
|
+
function domDiffComputingNext(taskId, resume, budgetMs) {
|
|
8036
|
+
const head = budgetMs < AWAIT_BUDGET_MS
|
|
8037
|
+
? `The DOM diff is still computing server-side. Resume it now — ${resume} plus taskId "${taskId}"; that call waits for the diff, so do not idle first. `
|
|
8038
|
+
: `The DOM diff is still computing server-side. Wait ~10 seconds, then ${resume} plus taskId "${taskId}". `;
|
|
8039
|
+
return (head +
|
|
8040
|
+
'Do NOT guess, summarize, or reconstruct the diff from anything else — it is only available through that call.');
|
|
8041
|
+
}
|
|
8042
|
+
const DOM_DIFF_TERMINAL_NEXT = 'No DOM diff exists for this step and none can be computed — this is terminal, not transient. ' +
|
|
8043
|
+
'Do NOT call eyes_inspect_dom_diff for this step. Review it from the images alone and record that ' +
|
|
8044
|
+
'the structural comparison was not available, rather than that no structural change was found.';
|
|
8045
|
+
/** A composed read must never take the evidence bundle down with it — the images are the call's contract. */
|
|
8046
|
+
function composeFailure(tool) {
|
|
8047
|
+
return (error) => ({
|
|
8048
|
+
status: 'error',
|
|
8049
|
+
error: error instanceof Error ? error.message : String(error),
|
|
8050
|
+
next: `This read failed, so ${tool} still counts as not called for this step — call it directly to retry it. ` +
|
|
8051
|
+
'Everything else in this response is unaffected.',
|
|
8052
|
+
});
|
|
8053
|
+
}
|
|
8054
|
+
function failed(result) {
|
|
8055
|
+
return result.status === 'error';
|
|
8056
|
+
}
|
|
8057
|
+
/** A `null` record keeps the review gates treating the diff as not-yet-fetched until the agent actually receives it. */
|
|
8058
|
+
function composedDomDiff(result) {
|
|
8059
|
+
if (failed(result))
|
|
8060
|
+
return { block: { ...result }, record: null };
|
|
8061
|
+
if (result.status === 'computing') {
|
|
8062
|
+
const resume = `call ${EYES_INSPECT_TOOLS.domDiff} with this step's sessionUrl and stepIndex`;
|
|
8063
|
+
return {
|
|
8064
|
+
block: {
|
|
8065
|
+
status: 'computing',
|
|
8066
|
+
taskId: result.taskId,
|
|
8067
|
+
next: domDiffComputingNext(result.taskId, resume, COMPOSED_AWAIT_BUDGET_MS),
|
|
8068
|
+
},
|
|
8069
|
+
record: null,
|
|
8070
|
+
};
|
|
8071
|
+
}
|
|
8072
|
+
if (result.status !== 'ready') {
|
|
8073
|
+
return {
|
|
8074
|
+
block: { status: result.status, reason: result.reason, next: DOM_DIFF_TERMINAL_NEXT },
|
|
8075
|
+
record: { rect: undefined, status: result.status },
|
|
8076
|
+
};
|
|
8077
|
+
}
|
|
8078
|
+
return { block: { status: 'ready', diff: result.diff }, record: { rect: undefined } };
|
|
8079
|
+
}
|
|
7860
8080
|
const SESSION_URL_DESC = 'Eyes session URL: https://eyes.applitools.com/app/test-results/{batchId}/{sessionId}[/steps/{N}]?accountId=... (the /steps/N suffix is ignored if present)';
|
|
7861
8081
|
const BATCH_URL_DESC = 'Eyes batch URL: https://eyes.applitools.com/app/test-results/{batchId}/?accountId=... (a trailing /{sessionId}[/steps/{N}] is fine too and is ignored — pass a session/step URL here as-is, no need to strip it down)';
|
|
7862
8082
|
const STEP_INDEX_DESC = 'Zero-based index of the step, as returned by eyes_inspect_steps';
|
|
@@ -7884,6 +8104,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7884
8104
|
.describe('Narrow to sessions matching this state — "mismatching" keeps sessions with at least one step that\'s non-matching, missing a checkpoint, or new'),
|
|
7885
8105
|
format: zod.z.enum(['full', 'stats', 'scenarios']).optional().describe('Shape of the response; defaults to "full"'),
|
|
7886
8106
|
},
|
|
8107
|
+
annotations: READ_ONLY,
|
|
7887
8108
|
}, async ({ batchUrl, filter, format }) => {
|
|
7888
8109
|
const keys = readOnlyApiKeyProvider(batchUrl);
|
|
7889
8110
|
const rawArgs = [filter, format].filter((v) => v !== undefined);
|
|
@@ -7896,6 +8117,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7896
8117
|
inputSchema: {
|
|
7897
8118
|
sessionUrl: zod.z.string().describe(SESSION_URL_DESC),
|
|
7898
8119
|
},
|
|
8120
|
+
annotations: READ_ONLY,
|
|
7899
8121
|
}, async ({ sessionUrl }) => {
|
|
7900
8122
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
7901
8123
|
const result = await fetchSteps(sessionUrl, keys);
|
|
@@ -7909,6 +8131,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7909
8131
|
stepIndex: zod.z.number().int().nonnegative().describe(STEP_INDEX_DESC),
|
|
7910
8132
|
rect: RectShape.describe(RECT_DESC),
|
|
7911
8133
|
},
|
|
8134
|
+
annotations: READ_ONLY,
|
|
7912
8135
|
}, async ({ sessionUrl, stepIndex, rect }) => {
|
|
7913
8136
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
7914
8137
|
const result = await fetchChangedAreas(sessionUrl, stepIndex, keys, rect);
|
|
@@ -7922,6 +8145,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7922
8145
|
stepIndex: zod.z.number().int().nonnegative().describe(STEP_INDEX_DESC),
|
|
7923
8146
|
rect: RectShape.describe(RECT_DESC),
|
|
7924
8147
|
},
|
|
8148
|
+
annotations: READ_ONLY,
|
|
7925
8149
|
}, async ({ sessionUrl, stepIndex, rect }) => {
|
|
7926
8150
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
7927
8151
|
const filePath = await fetchImageDiff(sessionUrl, stepIndex, keys, rect);
|
|
@@ -7935,6 +8159,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7935
8159
|
imageId: zod.z.string().describe('Baseline or checkpoint image id from eyes_inspect_steps'),
|
|
7936
8160
|
rect: RectShape.describe(RECT_DESC),
|
|
7937
8161
|
},
|
|
8162
|
+
annotations: READ_ONLY,
|
|
7938
8163
|
}, async ({ sessionUrl, imageId, rect }) => {
|
|
7939
8164
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
7940
8165
|
const { baseUrl } = parseSessionUrl(sessionUrl);
|
|
@@ -7942,6 +8167,41 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7942
8167
|
logDataToolCall(sessionScopeId(sessionUrl), EYES_INSPECT_TOOLS.image, { imageId, rect }, phaseTrackerDeps);
|
|
7943
8168
|
return textResult(filePath);
|
|
7944
8169
|
});
|
|
8170
|
+
server.registerTool(EYES_INSPECT_TOOLS.evidence, {
|
|
8171
|
+
description: 'Everything needed to review a step\'s changed areas, in one call: for each area, the image diff (checkpoint with differences highlighted in pink) plus the baseline and checkpoint screenshots, fetched together. Pass EVERY area you still have to review in a single call\'s `areaRects` — one call per area is exactly what this tool exists to avoid. Pass each rect exactly as eyes_review_progress gave it to you — do NOT pad it, the server pads it and clamps it to each image. Prefer this over calling eyes_inspect_image_diff and eyes_inspect_image separately; it is what eyes_review_diff_report\'s gate checks for. It also returns the whole step\'s structural DOM diff under `domDiff` and the match regions currently in effect under `regions`, so do not call eyes_inspect_dom_diff or eyes_inspect_regions separately for this step — the one exception is a `domDiff` or `regions` reporting `status: "computing"` or `status: "error"` (with the failure\'s own message under `error`), whose own `next` says where to pick it up. The composed `domDiff` waits only briefly, so `status: "computing"` is common and expected here — the images ship without waiting for it; follow its `next` to eyes_inspect_dom_diff, which is where the diff is waited out. Returns `evidence`, one entry per area in the order asked for, each with a labelled file path per image, plus the images themselves for clients that render them — read each `path` only for an image whose `inline` is false, and `notInlined` says why it was not. Inlined images arrive as image blocks in the same order as the `inline: true` entries, reading `evidence` top to bottom; `inlining` reports how much of the budget the response spent. Each image carries the `rect` it was actually cropped at: the two sides of a step can differ in size, so the crops are near-identical but NOT guaranteed equal — compare by content, and check the rects before reading anything into a difference in position or extent. Any image this step cannot produce for an area is listed under that area\'s `unavailable` with the reason, which is a fact about the step, not a failure. Already reflects any match regions added during resolution; resolution can happen between calls, so never reuse an earlier result in this conversation — call it again.',
|
|
8172
|
+
inputSchema: {
|
|
8173
|
+
sessionUrl: zod.z.string().describe(SESSION_URL_DESC),
|
|
8174
|
+
stepIndex: zod.z.number().int().nonnegative().describe(STEP_INDEX_DESC),
|
|
8175
|
+
areaRects: zod.z
|
|
8176
|
+
.array(RequiredRectShape)
|
|
8177
|
+
.min(1)
|
|
8178
|
+
.max(MAX_EVIDENCE_BATCH)
|
|
8179
|
+
.describe(`Every changed area of this step you still need evidence for — from eyes_inspect_changed_areas or eyes_review_progress, verbatim and unpadded. Up to ${MAX_EVIDENCE_BATCH} per call; if a step has more, review these first and call again for the rest.`),
|
|
8180
|
+
},
|
|
8181
|
+
annotations: READ_ONLY,
|
|
8182
|
+
}, async ({ sessionUrl, stepIndex, areaRects }, extra) => {
|
|
8183
|
+
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
8184
|
+
const scopeId = stepScopeId(sessionUrl, stepIndex);
|
|
8185
|
+
// Concurrent, so the merged call costs max(images, regions, domDiff) rather than their sum.
|
|
8186
|
+
const [evidence, regions, domDiff] = await Promise.all([
|
|
8187
|
+
fetchEvidence(sessionUrl, stepIndex, areaRects, keys),
|
|
8188
|
+
fetchRegions(sessionUrl, stepIndex, keys).catch(composeFailure(EYES_INSPECT_TOOLS.regions)),
|
|
8189
|
+
fetchVisibleDomDiff(sessionUrl, stepIndex, keys, undefined, undefined, extra === null || extra === void 0 ? void 0 : extra.signal, undefined, COMPOSED_AWAIT_BUDGET_MS).catch(composeFailure(EYES_INSPECT_TOOLS.domDiff)),
|
|
8190
|
+
]);
|
|
8191
|
+
const { block, record } = composedDomDiff(domDiff);
|
|
8192
|
+
const result = buildEvidenceResult(evidence, {}, { domDiff: block, regions });
|
|
8193
|
+
recordChainSource(scopeId, phaseTrackerDeps);
|
|
8194
|
+
// One record per area, not per call: eyes_review_diff_report's gate reads these area by area.
|
|
8195
|
+
for (const area of evidence) {
|
|
8196
|
+
logInvocation(scopeId, EYES_INSPECT_TOOLS.evidence, { areaRect: area.areaRect, images: area.images.map(image => image.label) }, phaseTrackerDeps);
|
|
8197
|
+
}
|
|
8198
|
+
// The standalone tools' own keys and argument shapes, so the review gates need no change to accept these.
|
|
8199
|
+
if (!failed(regions))
|
|
8200
|
+
logInvocation(scopeId, EYES_INSPECT_TOOLS.regions, { rect: undefined }, phaseTrackerDeps);
|
|
8201
|
+
if (record)
|
|
8202
|
+
logInvocation(scopeId, EYES_INSPECT_TOOLS.domDiff, record, phaseTrackerDeps);
|
|
8203
|
+
return result;
|
|
8204
|
+
});
|
|
7945
8205
|
server.registerTool(EYES_INSPECT_TOOLS.dom, {
|
|
7946
8206
|
description: "Export a DOM capture as JSON, saved to a file. `domId` comes from eyes_inspect_steps (baseline.domId or checkpoint.domId per step). Use to inspect exact computed styles/structure, or to locate an element's rect/id for use elsewhere (e.g. as an eyes_inspect_history nodeId). Returns a file path — pass it directly to the Read tool, or search it with eyes_inspect_dom_search rather than writing an ad-hoc script.",
|
|
7947
8207
|
inputSchema: {
|
|
@@ -7949,6 +8209,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7949
8209
|
domId: zod.z.string().describe('Baseline or checkpoint domId from eyes_inspect_steps'),
|
|
7950
8210
|
rect: RectShape.describe(`${RECT_DESC} Don't pad it.`),
|
|
7951
8211
|
},
|
|
8212
|
+
annotations: READ_ONLY,
|
|
7952
8213
|
}, async ({ sessionUrl, domId, rect }) => {
|
|
7953
8214
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
7954
8215
|
const domIdError = validateDomId(domId);
|
|
@@ -7969,6 +8230,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7969
8230
|
.string()
|
|
7970
8231
|
.describe("Boolean predicate, e.g. \"tagName = 'HEADER'\" or \"child-of (tagName = 'UL') and tagName = 'LI'\""),
|
|
7971
8232
|
},
|
|
8233
|
+
annotations: READ_ONLY,
|
|
7972
8234
|
}, async ({ filePath, predicate }) => {
|
|
7973
8235
|
const result = searchDomFile(filePath, predicate);
|
|
7974
8236
|
return textResult(result);
|
|
@@ -7982,22 +8244,27 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
7982
8244
|
taskId: zod.z
|
|
7983
8245
|
.string()
|
|
7984
8246
|
.optional()
|
|
7985
|
-
.describe('ONLY a taskId from a prior {"status":"computing"} response
|
|
8247
|
+
.describe('ONLY a taskId from a prior {"status":"computing"} response for the same sessionUrl/stepIndex — from this tool or from eyes_inspect_evidence\'s composed `domDiff` — resumes checking that computation instead of resubmitting. Never invent or reuse one across steps.'),
|
|
7986
8248
|
},
|
|
8249
|
+
annotations: READ_ONLY,
|
|
7987
8250
|
}, async ({ sessionUrl, stepIndex, rect, taskId }, extra) => {
|
|
7988
8251
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
7989
8252
|
const result = await fetchVisibleDomDiff(sessionUrl, stepIndex, keys, rect, taskId, extra === null || extra === void 0 ? void 0 : extra.signal);
|
|
7990
8253
|
if (result.status === 'computing') {
|
|
7991
8254
|
// Deliberately NOT logged as an invocation: eyes_review's hard gates must keep treating
|
|
7992
8255
|
// this step's dom diff as not-yet-fetched until the agent actually receives it.
|
|
8256
|
+
const resume = `call ${EYES_INSPECT_TOOLS.domDiff} again with the same sessionUrl/stepIndex/rect`;
|
|
7993
8257
|
return textResult(JSON.stringify({
|
|
7994
8258
|
status: 'computing',
|
|
7995
8259
|
taskId: result.taskId,
|
|
7996
|
-
next:
|
|
7997
|
-
`again with the same sessionUrl/stepIndex/rect plus taskId "${result.taskId}". ` +
|
|
7998
|
-
'Do NOT guess, summarize, or reconstruct the diff from anything else — it is only available through that call.',
|
|
8260
|
+
next: domDiffComputingNext(result.taskId, resume, AWAIT_BUDGET_MS),
|
|
7999
8261
|
}, null, 2));
|
|
8000
8262
|
}
|
|
8263
|
+
if (result.status !== 'ready') {
|
|
8264
|
+
// Logged, unlike `computing`, so eyes_review_end's step-close gate stays satisfiable without a diff.
|
|
8265
|
+
logDataToolCall(stepScopeId(sessionUrl, stepIndex), EYES_INSPECT_TOOLS.domDiff, { rect, status: result.status }, phaseTrackerDeps);
|
|
8266
|
+
return textResult(JSON.stringify({ status: result.status, reason: result.reason, next: DOM_DIFF_TERMINAL_NEXT }, null, 2));
|
|
8267
|
+
}
|
|
8001
8268
|
logDataToolCall(stepScopeId(sessionUrl, stepIndex), EYES_INSPECT_TOOLS.domDiff, { rect }, phaseTrackerDeps);
|
|
8002
8269
|
return textResult(result.diff);
|
|
8003
8270
|
});
|
|
@@ -8008,6 +8275,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
8008
8275
|
stepIndex: zod.z.number().int().nonnegative().describe(STEP_INDEX_DESC),
|
|
8009
8276
|
rect: RectShape.describe(RECT_DESC),
|
|
8010
8277
|
},
|
|
8278
|
+
annotations: READ_ONLY,
|
|
8011
8279
|
}, async ({ sessionUrl, stepIndex, rect }) => {
|
|
8012
8280
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
8013
8281
|
const result = await fetchRegions(sessionUrl, stepIndex, keys, rect);
|
|
@@ -8030,6 +8298,7 @@ function registerEyesInspectDataTools(server, phaseTrackerDeps = defaultPhaseTra
|
|
|
8030
8298
|
.optional()
|
|
8031
8299
|
.describe('Target number of non-empty diffs to collect per node; defaults to 3'),
|
|
8032
8300
|
},
|
|
8301
|
+
annotations: READ_ONLY,
|
|
8033
8302
|
}, async ({ sessionUrl, stepIndex, nodeIds, count }, extra) => {
|
|
8034
8303
|
const keys = readOnlyApiKeyProvider(sessionUrl);
|
|
8035
8304
|
const result = await runHistory(sessionUrl, stepIndex, nodeIds, count !== null && count !== void 0 ? count : 3, keys, undefined, extra === null || extra === void 0 ? void 0 : extra.signal);
|
|
@@ -8952,7 +9221,7 @@ function reviewEndCall(scope, args, rootScope, mode) {
|
|
|
8952
9221
|
* scope id) — otherwise it returns the cached, still-incomplete queue untouched, with no network
|
|
8953
9222
|
* call at all. On a fresh check, only genuinely new keys are appended (`queueChildKeys`'s own
|
|
8954
9223
|
* dedup) — nothing is ever removed. Always returns the full cumulative queue (old + new, completed
|
|
8955
|
-
* or not), so it drops straight into `runProgress`'s `computeCompleted
|
|
9224
|
+
* or not), so it drops straight into `runProgress`'s `computeCompleted`/descent resolution and
|
|
8956
9225
|
* `runEnd`'s `ownChildren`/`getSiblings` exactly like a plain live-fetched list would.
|
|
8957
9226
|
*/
|
|
8958
9227
|
async function resolveScopedChildren(scopeId, fetchLiveChildKeys, descriptorForKey, deps) {
|
|
@@ -8987,20 +9256,20 @@ function computeCompleted(scopeId, liveChildScopeIds, deps) {
|
|
|
8987
9256
|
* by one of them being reviewed/revised afterward), the instruction to call `eyes_review_end` for
|
|
8988
9257
|
* this same level (`scope`); once `completed` holds a fresh timestamp, nothing further — plus,
|
|
8989
9258
|
* only while `level` hasn't already reached `rootScope`, a suggestion to move on to the parent's own
|
|
8990
|
-
* `eyes_review_progress` call. Every incoming call (`
|
|
9259
|
+
* `eyes_review_progress` call. Every incoming call (`descentCall`, `endCall`,
|
|
8991
9260
|
* `parentProgressCall`) is expected to already carry the investigation's `rootScope` — built via
|
|
8992
9261
|
* `nextCall()` at its construction site in `tools.ts` — so this function only ever selects among
|
|
8993
9262
|
* them, never mutates or re-scopes one.
|
|
8994
9263
|
*/
|
|
8995
9264
|
function buildProgressNext(params) {
|
|
8996
|
-
const { level, rootScope, completed,
|
|
9265
|
+
const { level, rootScope, completed, descentCall, endCall, parentProgressCall } = params;
|
|
8997
9266
|
const label = LEVEL_LABELS[level];
|
|
8998
9267
|
const childLabel = LEVEL_LABELS[childLevelOf(level)];
|
|
8999
9268
|
if (completed === null) {
|
|
9000
|
-
if (
|
|
9269
|
+
if (descentCall) {
|
|
9001
9270
|
return {
|
|
9002
9271
|
instruction: `Not every ${childLabel} of this ${label} was reviewed. Call this next, in this order — don't reorder or substitute your own priority:`,
|
|
9003
|
-
calls: [
|
|
9272
|
+
calls: [descentCall],
|
|
9004
9273
|
};
|
|
9005
9274
|
}
|
|
9006
9275
|
return {
|
|
@@ -9026,20 +9295,32 @@ function buildProgressNext(params) {
|
|
|
9026
9295
|
* `parentProgressCall` are expected to already carry `rootScope` from their `nextCall()` call site.
|
|
9027
9296
|
*/
|
|
9028
9297
|
function buildEndNext(params) {
|
|
9029
|
-
const { level, rootScope, siblingCall, parentProgressCall, doneMessage } = params;
|
|
9298
|
+
const { level, rootScope, siblingCall, parentClose, parentProgressCall, doneMessage } = params;
|
|
9030
9299
|
const label = LEVEL_LABELS[level];
|
|
9031
9300
|
if (hasReachedRootScope(level, rootScope)) {
|
|
9032
9301
|
return { instruction: doneMessage };
|
|
9033
9302
|
}
|
|
9034
9303
|
if (siblingCall) {
|
|
9304
|
+
const target = LEVEL_LABELS[siblingCall.level];
|
|
9035
9305
|
return {
|
|
9036
|
-
instruction:
|
|
9037
|
-
|
|
9306
|
+
instruction: siblingCall.level === level
|
|
9307
|
+
? `This ${label} was reviewed. Another ${label} still needs reviewing — call it next.`
|
|
9308
|
+
: `This ${label} was reviewed. Reviewing continues at the next unreviewed ${target} — call it next.`,
|
|
9309
|
+
calls: [siblingCall.call],
|
|
9310
|
+
};
|
|
9311
|
+
}
|
|
9312
|
+
if (parentClose) {
|
|
9313
|
+
const closeLabel = LEVEL_LABELS[parentClose.level];
|
|
9314
|
+
return {
|
|
9315
|
+
instruction: `This ${label} was reviewed, and so was every other ${label}, so the ${closeLabel} is now fully reviewed too. Call ${parentClose.endCall.tool} for the ${closeLabel} next, citing the indexed findings in next.nextLevel as its sources — do not re-check its progress first, this response already is that answer.`,
|
|
9316
|
+
calls: [parentClose.endCall],
|
|
9317
|
+
nextLevel: parentClose.nextLevel,
|
|
9038
9318
|
};
|
|
9039
9319
|
}
|
|
9040
9320
|
if (parentProgressCall) {
|
|
9321
|
+
const parentLabelHere = LEVEL_LABELS[parentLevelOf(level)];
|
|
9041
9322
|
return {
|
|
9042
|
-
instruction: `This ${label} was reviewed, and so was every other ${label}. Move on to ${parentProgressCall.tool} for the ${
|
|
9323
|
+
instruction: `This ${label} was reviewed, and so was every other ${label}. Move on to ${parentProgressCall.tool} for the ${parentLabelHere}.`,
|
|
9043
9324
|
calls: [parentProgressCall],
|
|
9044
9325
|
};
|
|
9045
9326
|
}
|
|
@@ -9180,81 +9461,176 @@ async function walkSubtree(level, ctx, visit, deps) {
|
|
|
9180
9461
|
}
|
|
9181
9462
|
await visit(level, ctx, scopeId);
|
|
9182
9463
|
}
|
|
9464
|
+
/** The one place entry order is decided — validation, display and clustering all derive from it, and a reordering in only one would be silently accepted. */
|
|
9465
|
+
function orderedChildFindingEntries(scopeId, deps) {
|
|
9466
|
+
return Object.entries(getChildFindings(scopeId, deps));
|
|
9467
|
+
}
|
|
9183
9468
|
/**
|
|
9184
|
-
* Every child finding `scopeId`'s children have reported, flattened into one array
|
|
9185
|
-
*
|
|
9186
|
-
*
|
|
9187
|
-
* indexes into, and the same order `attachFindingIndices` numbers for display.
|
|
9469
|
+
* Every child finding `scopeId`'s children have reported, flattened into one array — each child's
|
|
9470
|
+
* own findings sub-array in full before the next child's. This is the exact list a submitted
|
|
9471
|
+
* finding's `sources` indexes into; see `orderedChildFindingEntries` for what fixes the order.
|
|
9188
9472
|
*/
|
|
9189
9473
|
function flattenChildFindings(scopeId, deps) {
|
|
9190
|
-
return
|
|
9474
|
+
return orderedChildFindingEntries(scopeId, deps).flatMap(([, findings]) => findings);
|
|
9191
9475
|
}
|
|
9192
9476
|
/**
|
|
9193
9477
|
* Attaches this same flat, global `index` to every finding across every child-key group, so
|
|
9194
9478
|
* `_progress`'s displayed findings can be cited by a later `_end` call's `sources`. Takes/returns
|
|
9195
|
-
* `
|
|
9196
|
-
*
|
|
9197
|
-
* unchanged.
|
|
9479
|
+
* `orderedChildFindingEntries`' own shape — feed it from there and nothing else, or display and
|
|
9480
|
+
* validation stop agreeing — so each level's `buildFindings` keeps its own per-child key naming
|
|
9481
|
+
* (`scenarioName`, `sessionUrl`, …) unchanged.
|
|
9198
9482
|
*/
|
|
9199
9483
|
function attachFindingIndices(entries) {
|
|
9200
9484
|
let index = 0;
|
|
9201
9485
|
return entries.map(([key, findings]) => [key, findings.map(finding => ({ ...finding, index: index++ }))]);
|
|
9202
9486
|
}
|
|
9487
|
+
const CLUSTER_NOTE = 'These share the listed mechanical key. Whether they share a cause is your call.';
|
|
9488
|
+
/** `undefined` when the value is a DOM node id rather than a rect. */
|
|
9489
|
+
function asRect(value) {
|
|
9490
|
+
const rect = value;
|
|
9491
|
+
return rect && typeof rect === 'object' && typeof rect.left === 'number' && typeof rect.width === 'number'
|
|
9492
|
+
? rect
|
|
9493
|
+
: undefined;
|
|
9494
|
+
}
|
|
9495
|
+
/** Levels disagree on the field name, hence both. */
|
|
9496
|
+
function findingRect(finding) {
|
|
9497
|
+
var _a;
|
|
9498
|
+
const located = finding;
|
|
9499
|
+
return (_a = asRect(located.areaRect)) !== null && _a !== void 0 ? _a : asRect(located.area);
|
|
9500
|
+
}
|
|
9501
|
+
/** Only facts derivable from the finding itself, so the key never depends on traversal order. */
|
|
9502
|
+
function mechanicalKey(childKey, finding) {
|
|
9503
|
+
var _a, _b;
|
|
9504
|
+
const known = finding;
|
|
9505
|
+
const ancestry = Object.entries((_a = known.origin) !== null && _a !== void 0 ? _a : {})
|
|
9506
|
+
.filter(([, value]) => value !== undefined)
|
|
9507
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
9508
|
+
.map(([name, value]) => `${name}:${value}`);
|
|
9509
|
+
return [
|
|
9510
|
+
`at:${childKey}`,
|
|
9511
|
+
...ancestry,
|
|
9512
|
+
`verdict:${known.isBug != null ? 'bug' : '-'}/${known.isExpected != null ? 'expected' : '-'}`,
|
|
9513
|
+
...(((_b = known.dynamic) === null || _b === void 0 ? void 0 : _b.justification) ? [`dynamic:${known.dynamic.justification}`] : []),
|
|
9514
|
+
].join(' · ');
|
|
9515
|
+
}
|
|
9516
|
+
/** Union-find because overlap is not transitive. Membership is stable across runs; ids are not, since they inherit the entry numbering. */
|
|
9517
|
+
function buildSourceClusters(entries) {
|
|
9518
|
+
const flat = entries.flatMap(([childKey, findings]) => findings.map(finding => ({ key: mechanicalKey(childKey, finding), rect: findingRect(finding) })));
|
|
9519
|
+
const parent = flat.map((_, index) => index);
|
|
9520
|
+
const find = (index) => (parent[index] === index ? index : (parent[index] = find(parent[index])));
|
|
9521
|
+
const union = (a, b) => {
|
|
9522
|
+
const [x, y] = [find(a), find(b)];
|
|
9523
|
+
if (x < y)
|
|
9524
|
+
parent[y] = x;
|
|
9525
|
+
else if (y < x)
|
|
9526
|
+
parent[x] = y;
|
|
9527
|
+
};
|
|
9528
|
+
const byKey = new Map();
|
|
9529
|
+
flat.forEach((item, index) => { var _a; return byKey.set(item.key, [...((_a = byKey.get(item.key)) !== null && _a !== void 0 ? _a : []), index]); });
|
|
9530
|
+
for (const members of byKey.values()) {
|
|
9531
|
+
for (let i = 0; i < members.length; i++) {
|
|
9532
|
+
for (let j = i + 1; j < members.length; j++) {
|
|
9533
|
+
const [a, b] = [flat[members[i]], flat[members[j]]];
|
|
9534
|
+
// No rect on either side means no geometry to separate them, so the other keys decide.
|
|
9535
|
+
if (a.rect && b.rect ? rectsIntersect(a.rect, b.rect) : !a.rect && !b.rect)
|
|
9536
|
+
union(members[i], members[j]);
|
|
9537
|
+
}
|
|
9538
|
+
}
|
|
9539
|
+
}
|
|
9540
|
+
const byLabel = new Map();
|
|
9541
|
+
flat.forEach((_, index) => {
|
|
9542
|
+
var _a;
|
|
9543
|
+
const label = find(index);
|
|
9544
|
+
byLabel.set(label, [...((_a = byLabel.get(label)) !== null && _a !== void 0 ? _a : []), index]);
|
|
9545
|
+
});
|
|
9546
|
+
return [...byLabel.entries()]
|
|
9547
|
+
.sort(([a], [b]) => a - b)
|
|
9548
|
+
.map(([label, indices]) => ({ id: `g${label}`, key: flat[label].key, indices, note: CLUSTER_NOTE }));
|
|
9549
|
+
}
|
|
9550
|
+
/** Clusters are disjoint and cover the whole numbering, so expanding them can neither manufacture an overlap nor conceal a gap from `verifySourcedFindings`. */
|
|
9551
|
+
function expandSourceCitations(findings, clusters) {
|
|
9552
|
+
const byId = new Map(clusters.map(cluster => [cluster.id, cluster.indices]));
|
|
9553
|
+
return findings.map((finding, findingIndex) => {
|
|
9554
|
+
var _a;
|
|
9555
|
+
const cited = ((_a = finding.sourceClusters) !== null && _a !== void 0 ? _a : []).flatMap(id => {
|
|
9556
|
+
const indices = byId.get(id);
|
|
9557
|
+
if (!indices) {
|
|
9558
|
+
throw new Error(`Finding ${findingIndex}'s sourceClusters names "${id}", which is not one of the cluster ids this level's own findings were grouped into ` +
|
|
9559
|
+
`(${clusters.map(cluster => cluster.id).join(', ') || 'there are none'}). Call again citing only ids this call was shown, or plain sources indices.`);
|
|
9560
|
+
}
|
|
9561
|
+
return indices;
|
|
9562
|
+
});
|
|
9563
|
+
return { ...finding, sources: [...new Set([...finding.sources, ...cited])].sort((a, b) => a - b) };
|
|
9564
|
+
});
|
|
9565
|
+
}
|
|
9203
9566
|
/**
|
|
9204
9567
|
* Validates a submitted `_end` finding array's `sources` against `childFindings` — the exact flat,
|
|
9205
9568
|
* ordered list `flattenChildFindings` produces for this same scope — then checks each finding's
|
|
9206
9569
|
* own isBug/isExpected for consistency with the isBug/isExpected of just the child findings its
|
|
9207
9570
|
* `sources` names: isBug non-null iff any of them is, isExpected non-null iff every one of them is.
|
|
9208
|
-
*
|
|
9209
|
-
*
|
|
9210
|
-
*
|
|
9211
|
-
*
|
|
9212
|
-
*
|
|
9571
|
+
* The checks run in this order, so the earliest structural problem surfaces before a later,
|
|
9572
|
+
* harder-to-diagnose one: an out-of-range index, then sources claimed by more than one finding,
|
|
9573
|
+
* then a child finding no finding accounts for, and only once `sources` are well-formed, the
|
|
9574
|
+
* isBug/isExpected check. The failing check reports every violation it found, not just the first —
|
|
9575
|
+
* one per rejection would cost a regenerated submission each.
|
|
9213
9576
|
*/
|
|
9214
9577
|
function verifySourcedFindings(findings, childFindings) {
|
|
9215
9578
|
const claimedBy = new Map();
|
|
9579
|
+
const outOfRange = [];
|
|
9580
|
+
const overlapping = [];
|
|
9216
9581
|
findings.forEach((finding, findingIndex) => {
|
|
9217
9582
|
for (const source of finding.sources) {
|
|
9218
9583
|
if (!Number.isInteger(source) || source < 0 || source >= childFindings.length) {
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
`valid indices are ${range}. Call again with sources that only reference indices from the findings this level's own _progress call reported.`);
|
|
9584
|
+
outOfRange.push(`finding ${findingIndex}'s sources names index ${source}`);
|
|
9585
|
+
continue;
|
|
9222
9586
|
}
|
|
9223
9587
|
const claimant = claimedBy.get(source);
|
|
9224
9588
|
if (claimant !== undefined && claimant !== findingIndex) {
|
|
9225
|
-
|
|
9226
|
-
|
|
9589
|
+
overlapping.push(`Child finding ${source} is named in both finding ${claimant}'s and finding ${findingIndex}'s sources`);
|
|
9590
|
+
continue;
|
|
9227
9591
|
}
|
|
9228
9592
|
claimedBy.set(source, findingIndex);
|
|
9229
9593
|
}
|
|
9230
9594
|
});
|
|
9595
|
+
if (outOfRange.length > 0) {
|
|
9596
|
+
const range = childFindings.length > 0 ? `0-${childFindings.length - 1}` : '(there are no child findings to source from)';
|
|
9597
|
+
throw new Error(`Sources name an index that is not a valid child finding index for this call: ${outOfRange.join('; ')}. ` +
|
|
9598
|
+
`Valid indices are ${range}. Call again with sources that only reference indices from the findings this level's own _progress call reported.`);
|
|
9599
|
+
}
|
|
9600
|
+
if (overlapping.length > 0) {
|
|
9601
|
+
throw new Error(`${overlapping.join('; ')} — each child finding must be consolidated into exactly one submitted finding. ` +
|
|
9602
|
+
`Call again with non-overlapping sources.`);
|
|
9603
|
+
}
|
|
9231
9604
|
const missing = childFindings.map((_, i) => i).filter(i => !claimedBy.has(i));
|
|
9232
9605
|
if (missing.length > 0) {
|
|
9233
9606
|
throw new Error(`Child finding${missing.length === 1 ? '' : 's'} ${missing.join(', ')} ${missing.length === 1 ? 'is' : 'are'} not named in ` +
|
|
9234
9607
|
`any submitted finding's sources. Every child finding must be accounted for — call again with a finding (existing or new) whose ` +
|
|
9235
9608
|
`sources include ${missing.length === 1 ? 'it' : 'them'}.`);
|
|
9236
9609
|
}
|
|
9610
|
+
const inconsistent = [];
|
|
9237
9611
|
findings.forEach((finding, findingIndex) => {
|
|
9238
9612
|
const referenced = finding.sources.map(i => childFindings[i]);
|
|
9239
9613
|
const anyIsBug = referenced.some(c => c.isBug !== null);
|
|
9240
9614
|
if (anyIsBug && finding.isBug === null) {
|
|
9241
|
-
|
|
9615
|
+
inconsistent.push(`Finding ${findingIndex} consolidates a child finding with isBug set, so it must have isBug set too — call again with isBug describing the bug.`);
|
|
9242
9616
|
}
|
|
9243
9617
|
if (!anyIsBug && finding.isBug !== null) {
|
|
9244
|
-
|
|
9618
|
+
inconsistent.push(`Finding ${findingIndex} has isBug set, but none of the child findings it consolidates (sources: ${JSON.stringify(finding.sources)}) do — call again with isBug: null, or correct its sources.`);
|
|
9245
9619
|
}
|
|
9246
9620
|
const allIsExpected = referenced.every(c => c.isExpected !== null);
|
|
9247
9621
|
if (allIsExpected && finding.isExpected === null) {
|
|
9248
|
-
|
|
9622
|
+
inconsistent.push(`Finding ${findingIndex} consolidates only child findings with isExpected set, so it must have isExpected set too — call again with isExpected filled in.`);
|
|
9249
9623
|
}
|
|
9250
9624
|
if (!allIsExpected && finding.isExpected !== null) {
|
|
9251
|
-
|
|
9625
|
+
inconsistent.push(`Finding ${findingIndex} has isExpected set, but at least one child finding it consolidates (sources: ${JSON.stringify(finding.sources)}) does not — call again with isExpected: null, or correct its sources.`);
|
|
9252
9626
|
}
|
|
9253
9627
|
});
|
|
9628
|
+
if (inconsistent.length > 0)
|
|
9629
|
+
throw new Error(inconsistent.join(' '));
|
|
9254
9630
|
}
|
|
9255
|
-
/**
|
|
9631
|
+
/** Citations exist only on an `_end` call's input — never in what is persisted or pushed up to a parent. */
|
|
9256
9632
|
function stripSources(findings) {
|
|
9257
|
-
return findings.map(({ sources: _sources, ...rest }) => rest);
|
|
9633
|
+
return findings.map(({ sources: _sources, sourceClusters: _sourceClusters, ...rest }) => rest);
|
|
9258
9634
|
}
|
|
9259
9635
|
|
|
9260
9636
|
// Every Zod shape the review tools share — the `scope` level argument and the entity-id
|
|
@@ -9287,7 +9663,10 @@ const EndScopeShape = zod.z
|
|
|
9287
9663
|
'summary, omit any "(sameAs: ...)" note from the underlying descriptions — describe the change itself, not how it ' +
|
|
9288
9664
|
'was verified. In mode "resolve" this call also decides the step: rejected if any finding is a bug or inconsistent ' +
|
|
9289
9665
|
'with its surroundings, accepted if every finding is justified (expected, or evidenced dynamic content), and ' +
|
|
9290
|
-
'otherwise left unresolved for human review — including whenever a region could not be applied.'
|
|
9666
|
+
'otherwise left unresolved for human review — including whenever a region could not be applied. The block this ' +
|
|
9667
|
+
'call consolidates may hold either already-reduced summaries or raw per-changed-area findings, depending on how ' +
|
|
9668
|
+
'far the walk skipped to reach here — consolidate and cite both the same way, and where a finding carries an ' +
|
|
9669
|
+
'`origin`, keep the session/step it names in the summary you write.');
|
|
9291
9670
|
/**
|
|
9292
9671
|
* The entity-id arguments `eyes_review_progress`/`eyes_review_end` share. All four are optional at
|
|
9293
9672
|
* the schema level and required by `scope` at call time — the MCP tool schema is a flat field
|
|
@@ -9483,10 +9862,30 @@ const IS_EXPECTED_IS_BUG_SHAPE = {
|
|
|
9483
9862
|
};
|
|
9484
9863
|
const SOURCES_DESC = "Indexes into the flat, combined list of every child finding this level's own _progress call reported for this " +
|
|
9485
9864
|
'node — each one numbered there via its own `index` field. Every child finding must be claimed by exactly one ' +
|
|
9486
|
-
|
|
9487
|
-
"entry's isBug/isExpected must then be consistent with the child findings
|
|
9488
|
-
'them has isBug non-null; isExpected non-null iff every one of them has
|
|
9489
|
-
|
|
9865
|
+
'entry (no gaps, no overlap between entries), counting `sourceClusters` too; between the two fields, at least ' +
|
|
9866
|
+
"one citation is required here. This entry's isBug/isExpected must then be consistent with the child findings " +
|
|
9867
|
+
'it names: isBug non-null iff any of them has isBug non-null; isExpected non-null iff every one of them has ' +
|
|
9868
|
+
'isExpected non-null.';
|
|
9869
|
+
const SourcesShape = zod.z.array(zod.z.number().int().nonnegative()).describe(SOURCES_DESC);
|
|
9870
|
+
const SOURCE_CLUSTERS_DESC = 'Ids from the `clusters` block that same _progress call reported — a shorthand for every index the named cluster ' +
|
|
9871
|
+
'holds, so a large list can be claimed without transcribing it. Clusters were grouped by a mechanical key alone ' +
|
|
9872
|
+
'(where a finding came from, its isBug/isExpected pair, how a dynamic claim was justified, overlapping areas); ' +
|
|
9873
|
+
'whether the findings in one share a cause is your judgment, so split a cluster across entries via plain ' +
|
|
9874
|
+
'`sources` whenever they do not. Mixing the two fields on one entry is fine.';
|
|
9875
|
+
const SourceClustersShape = zod.z.array(zod.z.string()).optional().describe(SOURCE_CLUSTERS_DESC);
|
|
9876
|
+
/** Every entry must claim something. Enforced here rather than by a `.min(1)` on `sources`, since either field alone is a complete citation. */
|
|
9877
|
+
function requireCitation(findings, ctx) {
|
|
9878
|
+
findings.forEach((finding, index) => {
|
|
9879
|
+
var _a, _b;
|
|
9880
|
+
if (finding.sources.length + ((_b = (_a = finding.sourceClusters) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0)
|
|
9881
|
+
return;
|
|
9882
|
+
ctx.addIssue({
|
|
9883
|
+
code: 'custom',
|
|
9884
|
+
message: 'each finding must cite at least one child finding, via sources indices or sourceClusters ids',
|
|
9885
|
+
path: [index, 'sources'],
|
|
9886
|
+
});
|
|
9887
|
+
});
|
|
9888
|
+
}
|
|
9490
9889
|
const StepEndDynamicShape = makeDynamicShape("The mask actually applied for this changed area at diff-report time — matching that response's `regions`.");
|
|
9491
9890
|
/**
|
|
9492
9891
|
* One consolidated summary per changed area. Carries the same categorical fields as
|
|
@@ -9494,15 +9893,17 @@ const StepEndDynamicShape = makeDynamicShape("The mask actually applied for this
|
|
|
9494
9893
|
* findings rather than trusting a restatement of it) — the step-level accept/reject decision in
|
|
9495
9894
|
* `eyes_review_end` reads them directly instead of parsing `summary` prose.
|
|
9496
9895
|
*/
|
|
9497
|
-
const
|
|
9896
|
+
const StepEndFindingShape = zod.z.object({
|
|
9498
9897
|
areaRect: AreaRectShape,
|
|
9499
9898
|
summary: zod.z.string(),
|
|
9500
9899
|
consistent: zod.z.boolean().describe('Whether every diff in this changed area is consistent with its surroundings'),
|
|
9501
9900
|
dynamic: StepEndDynamicShape,
|
|
9502
9901
|
...IS_EXPECTED_IS_BUG_SHAPE,
|
|
9503
9902
|
sources: SourcesShape,
|
|
9504
|
-
|
|
9505
|
-
|
|
9903
|
+
sourceClusters: SourceClustersShape,
|
|
9904
|
+
});
|
|
9905
|
+
const StepEndFindingsShape = zod.z.array(StepEndFindingShape).superRefine(requireCitation);
|
|
9906
|
+
const SummaryExampleFindingShape = zod.z.object({
|
|
9506
9907
|
summary: zod.z.string(),
|
|
9507
9908
|
example: zod.z
|
|
9508
9909
|
.string()
|
|
@@ -9511,7 +9912,9 @@ const SummaryExampleShape = zod.z.array(zod.z.object({
|
|
|
9511
9912
|
"(stepIndex + 1) matching the dashboard's own URL convention."),
|
|
9512
9913
|
...IS_EXPECTED_IS_BUG_SHAPE,
|
|
9513
9914
|
sources: SourcesShape,
|
|
9514
|
-
|
|
9915
|
+
sourceClusters: SourceClustersShape,
|
|
9916
|
+
});
|
|
9917
|
+
const SummaryExampleShape = zod.z.array(SummaryExampleFindingShape).superRefine(requireCitation);
|
|
9515
9918
|
/**
|
|
9516
9919
|
* `eyes_review_end`'s `findings`, which takes a different shape per `scope`. The handler
|
|
9517
9920
|
* re-validates against the shape its own `scope` requires and says which one it wanted if they
|
|
@@ -9521,10 +9924,21 @@ const SummaryExampleShape = zod.z.array(zod.z.object({
|
|
|
9521
9924
|
* reaches `commands.ts` is stripped to exactly one shape, as it was when each level had its own tool.
|
|
9522
9925
|
*/
|
|
9523
9926
|
const ReviewEndFindingsShape = zod.z
|
|
9524
|
-
.union([zod.z.array(
|
|
9927
|
+
.union([zod.z.array(StepEndFindingShape.loose()), zod.z.array(SummaryExampleFindingShape.loose())])
|
|
9525
9928
|
.describe('Which shape this takes depends on scope: "step" takes one consolidated summary per changed area (areaRect, ' +
|
|
9526
9929
|
'summary, consistent, dynamic, isExpected/isBug, sources); "batch"/"scenario"/"session" take one summary per ' +
|
|
9527
|
-
"finding with its own example link (summary, example, isExpected/isBug, sources). See each field's own
|
|
9930
|
+
"finding with its own example link (summary, example, isExpected/isBug, sources). See each field's own " +
|
|
9931
|
+
'description. There is no cap on how many entries this array holds, and every entry for this scope must arrive ' +
|
|
9932
|
+
'together in one call. If writing every entry out inline risks the response not finishing before its JSON ' +
|
|
9933
|
+
"closes, use this argument's other accepted form (a file path) instead of the inline array — see JsonFileArgShape's own description.");
|
|
9934
|
+
/** Lets a model-supplied array argument be handed off as a file path instead of inline JSON, for whichever caller finds the array too large to safely generate inline. */
|
|
9935
|
+
const JsonFileArgShape = zod.z
|
|
9936
|
+
.string()
|
|
9937
|
+
.describe('Absolute path to a UTF-8 JSON file whose entire contents are the same array this argument otherwise takes ' +
|
|
9938
|
+
'inline — nothing but the JSON array itself. Use this instead of the inline array only when the array would be ' +
|
|
9939
|
+
'large enough to risk the response not finishing before its JSON closes (e.g. many entries, or many that share ' +
|
|
9940
|
+
'one repetitive cause such as one locale/theme change touching every changed area alike) — writing to a file has ' +
|
|
9941
|
+
'no such limit. The tool reads and validates the file exactly as if its contents had been sent inline.');
|
|
9528
9942
|
|
|
9529
9943
|
/**
|
|
9530
9944
|
* Builds a batch or session URL from parsed components — the inverse of `api`'s
|
|
@@ -10288,7 +10702,6 @@ async function batchChildren(batchUrl, keys, rootScope, mode, deps) {
|
|
|
10288
10702
|
}, scenarioName => ({
|
|
10289
10703
|
key: scenarioChildKey(scenarioName),
|
|
10290
10704
|
scopeId: scenarioScopeId(batchUrl, scenarioName),
|
|
10291
|
-
nextCall: reviewProgressCall('scenario', { batchUrl, scenarioName }, rootScope, mode),
|
|
10292
10705
|
}), deps);
|
|
10293
10706
|
}
|
|
10294
10707
|
/**
|
|
@@ -10326,17 +10739,16 @@ async function scenarioChildren(batchUrl, scenarioName, keys, rootScope, mode, d
|
|
|
10326
10739
|
// sessionStepChildren, which would also try to mutate structural steps (needs write
|
|
10327
10740
|
// access, and doesn't belong in a read-only discovery cascade). That mutation still runs,
|
|
10328
10741
|
// idempotently, whenever this session is genuinely visited with write access.
|
|
10329
|
-
const stepKeys = stepChildDescriptors(s.sessionUrl, session,
|
|
10742
|
+
const stepKeys = stepChildDescriptors(s.sessionUrl, session, structuralExcludedIndices(session, mode)).map(d => d.key);
|
|
10330
10743
|
queueChildKeys(sessionScopeId(s.sessionUrl), stepKeys, deps);
|
|
10331
10744
|
}));
|
|
10332
10745
|
return sessions.map(s => sessionChildKey(s.sessionUrl));
|
|
10333
10746
|
}, sessionUrl => ({
|
|
10334
10747
|
key: sessionChildKey(sessionUrl),
|
|
10335
10748
|
scopeId: sessionScopeId(sessionUrl),
|
|
10336
|
-
nextCall: reviewProgressCall('session', { sessionUrl }, rootScope, mode),
|
|
10337
10749
|
}), deps);
|
|
10338
10750
|
}
|
|
10339
|
-
function stepChildDescriptors(sessionUrl, session,
|
|
10751
|
+
function stepChildDescriptors(sessionUrl, session, excluded) {
|
|
10340
10752
|
var _a;
|
|
10341
10753
|
return ((_a = session.steps) !== null && _a !== void 0 ? _a : [])
|
|
10342
10754
|
.map((step, stepIndex) => ({ step, stepIndex }))
|
|
@@ -10344,7 +10756,6 @@ function stepChildDescriptors(sessionUrl, session, rootScope, mode, excluded) {
|
|
|
10344
10756
|
.map(({ stepIndex }) => ({
|
|
10345
10757
|
key: stepChildKey(stepIndex),
|
|
10346
10758
|
scopeId: stepScopeId(sessionUrl, stepIndex),
|
|
10347
|
-
nextCall: reviewProgressCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
10348
10759
|
}));
|
|
10349
10760
|
}
|
|
10350
10761
|
/**
|
|
@@ -10359,14 +10770,13 @@ function stepChildDescriptors(sessionUrl, session, rootScope, mode, excluded) {
|
|
|
10359
10770
|
* fresh queue" would otherwise skip it entirely whenever the queue arrived pre-populated.
|
|
10360
10771
|
*/
|
|
10361
10772
|
async function sessionStepChildren(params) {
|
|
10362
|
-
const { sessionUrl, session,
|
|
10773
|
+
const { sessionUrl, session, mode, keys, deps } = params;
|
|
10363
10774
|
if (mode === 'resolve') {
|
|
10364
10775
|
await preResolveStructuralSteps({ sessionUrl, session, keys, deps });
|
|
10365
10776
|
}
|
|
10366
|
-
return resolveScopedChildren(sessionScopeId(sessionUrl), async () => stepChildDescriptors(sessionUrl, session,
|
|
10777
|
+
return resolveScopedChildren(sessionScopeId(sessionUrl), async () => stepChildDescriptors(sessionUrl, session, structuralExcludedIndices(session, mode)).map(d => d.key), key => ({
|
|
10367
10778
|
key,
|
|
10368
10779
|
scopeId: stepScopeId(sessionUrl, parseStepChildKey(key)),
|
|
10369
|
-
nextCall: reviewProgressCall('step', { sessionUrl, stepIndex: parseStepChildKey(key) }, rootScope, mode),
|
|
10370
10780
|
}), deps);
|
|
10371
10781
|
}
|
|
10372
10782
|
async function sessionChildren(params) {
|
|
@@ -10376,39 +10786,155 @@ async function sessionChildren(params) {
|
|
|
10376
10786
|
function toRect(area) {
|
|
10377
10787
|
return { left: area.left, top: area.top, width: area.width, height: area.height };
|
|
10378
10788
|
}
|
|
10379
|
-
async function stepChildren(sessionUrl, stepIndex, keys,
|
|
10789
|
+
async function stepChildren(sessionUrl, stepIndex, keys, deps) {
|
|
10380
10790
|
return resolveScopedChildren(stepScopeId(sessionUrl, stepIndex), async () => {
|
|
10381
10791
|
const { areas } = await fetchChangedAreas(sessionUrl, stepIndex, keys);
|
|
10382
10792
|
return areas.map(area => diffChildKey(toRect(area)));
|
|
10383
|
-
}, key => {
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10793
|
+
}, key => ({
|
|
10794
|
+
key,
|
|
10795
|
+
scopeId: diffScopeId(sessionUrl, stepIndex, parseDiffChildKey(key)),
|
|
10796
|
+
}), deps);
|
|
10797
|
+
}
|
|
10798
|
+
// Path compression — see the traversal gotcha in llm-docs/OVERVIEW.md.
|
|
10799
|
+
/** Only these two have no `verifyInvocation` gate and no mutating decision, so skipping one needs no synthetic invocation record. */
|
|
10800
|
+
const COMPRESSIBLE_LEVELS = new Set(['scenario', 'session']);
|
|
10801
|
+
/** Carries the full ancestry down (unlike `review-core`'s `childContextFor`), which the ascent needs to name a parent. */
|
|
10802
|
+
function childWalkNode(level, ctx, childKey, rootScope, mode) {
|
|
10803
|
+
switch (level) {
|
|
10804
|
+
case 'batch':
|
|
10805
|
+
return {
|
|
10806
|
+
level: 'scenario',
|
|
10807
|
+
scopeId: scenarioScopeId(ctx.batchUrl, childKey),
|
|
10808
|
+
ctx: { ...ctx, scenarioName: childKey },
|
|
10809
|
+
key: childKey,
|
|
10810
|
+
call: reviewProgressCall('scenario', { batchUrl: ctx.batchUrl, scenarioName: childKey }, rootScope, mode),
|
|
10811
|
+
};
|
|
10812
|
+
case 'scenario':
|
|
10813
|
+
return {
|
|
10814
|
+
level: 'session',
|
|
10815
|
+
scopeId: sessionScopeId(childKey),
|
|
10816
|
+
ctx: { ...ctx, sessionUrl: childKey },
|
|
10817
|
+
key: childKey,
|
|
10818
|
+
call: reviewProgressCall('session', { sessionUrl: childKey }, rootScope, mode),
|
|
10819
|
+
};
|
|
10820
|
+
case 'session': {
|
|
10821
|
+
const stepIndex = parseStepChildKey(childKey);
|
|
10822
|
+
return {
|
|
10823
|
+
level: 'step',
|
|
10824
|
+
scopeId: stepScopeId(ctx.sessionUrl, stepIndex),
|
|
10825
|
+
ctx: { ...ctx, stepIndex },
|
|
10826
|
+
key: childKey,
|
|
10827
|
+
call: reviewProgressCall('step', { sessionUrl: ctx.sessionUrl, stepIndex }, rootScope, mode),
|
|
10828
|
+
};
|
|
10829
|
+
}
|
|
10830
|
+
case 'step': {
|
|
10831
|
+
const areaRect = parseDiffChildKey(childKey);
|
|
10832
|
+
return {
|
|
10833
|
+
level: 'diff',
|
|
10834
|
+
scopeId: diffScopeId(ctx.sessionUrl, ctx.stepIndex, areaRect),
|
|
10835
|
+
ctx: { ...ctx, areaRect },
|
|
10836
|
+
key: childKey,
|
|
10837
|
+
call: nextCall(EYES_REVIEW_TOOLS.diffReport, { sessionUrl: ctx.sessionUrl, stepIndex: ctx.stepIndex, areaRect }, rootScope, mode),
|
|
10838
|
+
};
|
|
10839
|
+
}
|
|
10840
|
+
case 'diff':
|
|
10841
|
+
throw new Error('diff has no children'); // unreachable — no caller descends past the leaf
|
|
10842
|
+
}
|
|
10843
|
+
}
|
|
10844
|
+
function queuedChildNodes(node, rootScope, mode, deps) {
|
|
10845
|
+
return getQueuedChildKeys(node.scopeId, deps).map(key => childWalkNode(node.level, node.ctx, key, rootScope, mode));
|
|
10846
|
+
}
|
|
10847
|
+
/** The `recordScopeMode` write is load-bearing: `checkModeAgreesWithParent` reads an unrecorded mode as "nothing to disagree with", disarming the gate below. */
|
|
10848
|
+
function chainDown(child, rootScope, mode, deps) {
|
|
10849
|
+
let node = child;
|
|
10850
|
+
for (;;) {
|
|
10851
|
+
if (!COMPRESSIBLE_LEVELS.has(node.level))
|
|
10852
|
+
return node;
|
|
10853
|
+
const incomplete = queuedChildNodes(node, rootScope, mode, deps).filter(c => !isCompleted(c.scopeId, deps));
|
|
10854
|
+
if (incomplete.length !== 1)
|
|
10855
|
+
return node;
|
|
10856
|
+
recordScopeMode(node.scopeId, mode, deps);
|
|
10857
|
+
node = incomplete[0];
|
|
10858
|
+
}
|
|
10859
|
+
}
|
|
10860
|
+
function descentTarget(parentLevel, parentCtx, childKey, rootScope, mode, deps) {
|
|
10861
|
+
return chainDown(childWalkNode(parentLevel, parentCtx, childKey, rootScope, mode), rootScope, mode, deps);
|
|
10862
|
+
}
|
|
10863
|
+
/** Counts entries, not queued children: a step that was never queued still reports one (`preResolveStructuralSteps`), and would be compressed away. */
|
|
10864
|
+
function compressibleOnAscent(level, scopeId, deps) {
|
|
10865
|
+
if (!COMPRESSIBLE_LEVELS.has(level))
|
|
10866
|
+
return false;
|
|
10867
|
+
const entries = orderedChildFindingEntries(scopeId, deps);
|
|
10868
|
+
if (entries.length !== 1)
|
|
10869
|
+
return false;
|
|
10870
|
+
return level === 'scenario' || entries[0][1].length === 1;
|
|
10871
|
+
}
|
|
10872
|
+
/** An identity copy: `origin` accumulates rather than replaces, so a finding carried past both a session and a scenario still names the step it came from. */
|
|
10873
|
+
function forwardFindings(findings, origin) {
|
|
10874
|
+
return findings.map(finding => {
|
|
10875
|
+
const existing = finding.origin;
|
|
10876
|
+
return { ...finding, origin: { ...existing, ...origin } };
|
|
10877
|
+
});
|
|
10878
|
+
}
|
|
10879
|
+
function originContribution(level, childKey) {
|
|
10880
|
+
switch (level.level) {
|
|
10881
|
+
case 'session':
|
|
10882
|
+
return { sessionUrl: level.ctx.sessionUrl, stepIndex: parseStepChildKey(childKey) };
|
|
10883
|
+
case 'scenario':
|
|
10884
|
+
return { scenarioName: level.ctx.scenarioName, sessionUrl: childKey };
|
|
10885
|
+
default:
|
|
10886
|
+
throw new Error(`a ${level.level} is never compressed, so it never forwards findings`);
|
|
10887
|
+
}
|
|
10888
|
+
}
|
|
10889
|
+
/** Every write is keyed by child key and overwriting, so two siblings racing into the same ancestor is safe. */
|
|
10890
|
+
async function deriveClose(level, mode, deps) {
|
|
10891
|
+
const [childKey, childFindings] = orderedChildFindingEntries(level.scopeId, deps)[0];
|
|
10892
|
+
const { findings: forwarded, rollup } = consolidateRollup(level.scopeId, forwardFindings(childFindings, originContribution(level, childKey)), mode, deps);
|
|
10893
|
+
const parent = await level.up.parent();
|
|
10894
|
+
recordCompletion(level.scopeId, forwarded, deps);
|
|
10895
|
+
appendChildFinding(parent.scopeId, level.up.key, forwarded, deps);
|
|
10896
|
+
reportRollup(parent.scopeId, level.up.key, rollup, deps);
|
|
10897
|
+
recordScopeMode(level.scopeId, mode, deps);
|
|
10898
|
+
log(level.scopeId, 'derived-close', { input: { scopeId: level.scopeId } }, deps);
|
|
10899
|
+
return parent;
|
|
10900
|
+
}
|
|
10901
|
+
/** Stops at the first ancestor that consolidates — or sooner, at the first with an unreviewed branch, which it deep-links into rather than re-asking for its progress. */
|
|
10902
|
+
async function chainUp(parent, rootScope, mode, deps) {
|
|
10903
|
+
let level = parent;
|
|
10904
|
+
for (;;) {
|
|
10905
|
+
if (!level.up || !compressibleOnAscent(level.level, level.scopeId, deps))
|
|
10906
|
+
return { kind: 'end', level };
|
|
10907
|
+
const grandParent = await deriveClose(level, mode, deps);
|
|
10908
|
+
const unreviewed = queuedChildNodes(grandParent, rootScope, mode, deps).find(child => child.scopeId !== level.scopeId && !isCompleted(child.scopeId, deps));
|
|
10909
|
+
if (unreviewed) {
|
|
10910
|
+
const target = chainDown(unreviewed, rootScope, mode, deps);
|
|
10911
|
+
return { kind: 'call', call: target.call, level: target.level };
|
|
10912
|
+
}
|
|
10913
|
+
level = grandParent;
|
|
10914
|
+
}
|
|
10391
10915
|
}
|
|
10392
10916
|
async function runProgress(params) {
|
|
10393
|
-
const { level, rootScope, mode, scopeId, children, endCall, parentProgressCall, buildFindings, deps } = params;
|
|
10917
|
+
const { level, rootScope, mode, scopeId, children, descend, endCall, parentProgressCall, buildFindings, deps } = params;
|
|
10394
10918
|
const completed = computeCompleted(scopeId, children.map(c => c.scopeId), deps);
|
|
10395
|
-
const
|
|
10396
|
-
const
|
|
10397
|
-
const
|
|
10919
|
+
const nextChild = completed === null ? children.find(c => !isCompleted(c.scopeId, deps)) : undefined;
|
|
10920
|
+
const descentCall = nextChild && descend(nextChild);
|
|
10921
|
+
const next = buildProgressNext({ level, rootScope, completed, descentCall, endCall, parentProgressCall });
|
|
10922
|
+
const stillInvestigating = completed === null && descentCall !== undefined;
|
|
10398
10923
|
// Each branch below builds its own complete literal, keys already in the order they must
|
|
10399
10924
|
// serialize in — `next` last, however many of findings/resolution/regions precede it — rather
|
|
10400
10925
|
// than mutating one object, so `next`'s position can never drift from a future edit here.
|
|
10401
10926
|
if (stillInvestigating)
|
|
10402
10927
|
return { completed, next };
|
|
10403
10928
|
const findings = buildFindings();
|
|
10929
|
+
const clusters = sourceClustersFor(scopeId, deps);
|
|
10404
10930
|
if (mode !== 'resolve')
|
|
10405
|
-
return { completed, findings, next };
|
|
10931
|
+
return { completed, findings, clusters, next };
|
|
10406
10932
|
const rollup = childRollupTotal(scopeId, deps);
|
|
10407
10933
|
recordToolTelemetry({ resolve_decisions: rollup.resolution });
|
|
10408
|
-
return { completed, findings, resolution: rollup.resolution, regions: rollup.regions, next };
|
|
10934
|
+
return { completed, findings, clusters, resolution: rollup.resolution, regions: rollup.regions, next };
|
|
10409
10935
|
}
|
|
10410
10936
|
async function runEnd(params) {
|
|
10411
|
-
const { level, toolName, rootScope, scopeId, ownChildren, progressCall, pushUpTo, finalize, getSiblings, parentProgressCall, doneMessage, deps, } = params;
|
|
10937
|
+
const { level, toolName, rootScope, scopeId, ownChildren, progressCall, pushUpTo, finalize, getSiblings, descend, parentProgressCall, ascent, mode, doneMessage, deps, } = params;
|
|
10412
10938
|
const stillIncomplete = ownChildren.some(c => !isCompleted(c.scopeId, deps));
|
|
10413
10939
|
if (stillIncomplete) {
|
|
10414
10940
|
const instruction = `Not every ${childLevelLabel(level)} of this ${level} was reviewed yet. This submission was discarded — call ${progressCall.tool} for this ${level} again to see what remains, then call this again once it reports being fully reviewed.`;
|
|
@@ -10429,10 +10955,30 @@ async function runEnd(params) {
|
|
|
10429
10955
|
}
|
|
10430
10956
|
const siblings = await getSiblings();
|
|
10431
10957
|
const incompleteSibling = siblings.find(s => !isCompleted(s.scopeId, deps));
|
|
10958
|
+
// No incomplete sibling means the parent's `_progress` could only answer "call `_end`", which is already known here.
|
|
10959
|
+
let target;
|
|
10960
|
+
if (incompleteSibling) {
|
|
10961
|
+
if (descend)
|
|
10962
|
+
target = { kind: 'call', ...descend(incompleteSibling) };
|
|
10963
|
+
}
|
|
10964
|
+
else if (ascent && !hasReachedRootScope(level, rootScope)) {
|
|
10965
|
+
target = await chainUp(ascent(), rootScope, mode, deps);
|
|
10966
|
+
}
|
|
10432
10967
|
const next = buildEndNext({
|
|
10433
10968
|
level,
|
|
10434
10969
|
rootScope,
|
|
10435
|
-
siblingCall:
|
|
10970
|
+
siblingCall: (target === null || target === void 0 ? void 0 : target.kind) === 'call' ? { call: target.call, level: target.level } : undefined,
|
|
10971
|
+
parentClose: (target === null || target === void 0 ? void 0 : target.kind) === 'end'
|
|
10972
|
+
? {
|
|
10973
|
+
level: target.level.level,
|
|
10974
|
+
endCall: target.level.endCall,
|
|
10975
|
+
nextLevel: {
|
|
10976
|
+
scope: target.level.scope,
|
|
10977
|
+
findings: target.level.findings(),
|
|
10978
|
+
clusters: target.level.clusters(),
|
|
10979
|
+
},
|
|
10980
|
+
}
|
|
10981
|
+
: undefined,
|
|
10436
10982
|
parentProgressCall,
|
|
10437
10983
|
doneMessage,
|
|
10438
10984
|
});
|
|
@@ -10492,7 +11038,7 @@ function endResponse(result, mode, isRootScope) {
|
|
|
10492
11038
|
function verifyAndConsolidate(scopeId, logScopeId, logInput, findings, mode, deps) {
|
|
10493
11039
|
return async () => {
|
|
10494
11040
|
const childFindings = flattenChildFindings(scopeId, deps);
|
|
10495
|
-
await withGateLog(EYES_REVIEW_TOOLS.end, logScopeId, logInput, deps, () => verifySourcedFindings(findings, childFindings));
|
|
11041
|
+
await withGateLog(EYES_REVIEW_TOOLS.end, logScopeId, logInput, deps, () => verifySourcedFindings(expandSourceCitations(findings, sourceClustersFor(scopeId, deps)), childFindings));
|
|
10496
11042
|
return consolidateRollup(scopeId, stripSources(findings), mode, deps);
|
|
10497
11043
|
};
|
|
10498
11044
|
}
|
|
@@ -10614,39 +11160,53 @@ async function verifySameAsEligibility(sessionUrl, stepIndex, areaRect, sameAs,
|
|
|
10614
11160
|
`— only occurrences within the same scenario can be fast-tracked against each other.`);
|
|
10615
11161
|
}
|
|
10616
11162
|
}
|
|
11163
|
+
/** Whether the record is a diff the agent examined rather than a placeholder for a step that has none — tagged `unobtainable` by `stepProgress`, `status` by the tool handler. */
|
|
11164
|
+
function isExaminedDomDiff(args) {
|
|
11165
|
+
const record = args;
|
|
11166
|
+
return record.status === undefined && record.unobtainable === undefined;
|
|
11167
|
+
}
|
|
10617
11168
|
async function verifyDiffReportHardGate(sessionUrl, stepIndex, areaRect, findings, sameAs, keys, deps) {
|
|
10618
11169
|
var _a, _b;
|
|
10619
11170
|
const stepScope = stepScopeId(sessionUrl, stepIndex);
|
|
10620
11171
|
const rectMatches = (loggedRect) => loggedRect === undefined || rectsIntersect(loggedRect, areaRect);
|
|
11172
|
+
// Both the bundled call and the raw per-image calls are agent-initiated, so either satisfies the gate.
|
|
11173
|
+
const evidenceCovers = (label) => verifyInvocation(stepScope, EYES_INSPECT_TOOLS.evidence, args => { var _a; return rectMatches(args.areaRect) && ((_a = args.images) === null || _a === void 0 ? void 0 : _a.includes(label)) === true; }, deps);
|
|
10621
11174
|
const session = await fetchSteps(sessionUrl, keys);
|
|
10622
11175
|
const step = (_a = session.steps) === null || _a === void 0 ? void 0 : _a[stepIndex];
|
|
10623
11176
|
if (!step)
|
|
10624
11177
|
throw new Error(`Step index ${stepIndex} is out of range for this session.`);
|
|
10625
11178
|
if (sameAs) {
|
|
10626
|
-
if (!verifyInvocation(stepScope, EYES_INSPECT_TOOLS.domDiff,
|
|
10627
|
-
throw new Error('
|
|
11179
|
+
if (!verifyInvocation(stepScope, EYES_INSPECT_TOOLS.domDiff, isExaminedDomDiff, deps)) {
|
|
11180
|
+
throw new Error('No examined dom diff is on record for this step. A sameAs shortcut is only valid once ' +
|
|
10628
11181
|
"you've actually examined this step's own dom diff and confirmed it shows the same structural " +
|
|
10629
|
-
'change — call eyes_inspect_dom_diff first.'
|
|
11182
|
+
'change — call eyes_inspect_dom_diff first. A step that structurally has no dom diff cannot ' +
|
|
11183
|
+
'use this shortcut at all: report it the full way, with its own image diff and both images.');
|
|
10630
11184
|
}
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
11185
|
+
const checkpoint = plannedEvidence(step, areaRect).find(request => request.label === 'checkpoint');
|
|
11186
|
+
if (checkpoint &&
|
|
11187
|
+
!evidenceCovers('checkpoint') &&
|
|
11188
|
+
!verifyInvocation(sessionScopeId(sessionUrl), EYES_INSPECT_TOOLS.image, args => args.imageId === checkpoint.imageId && rectMatches(args.rect), deps)) {
|
|
11189
|
+
throw new Error(`This step's checkpoint image has not been fetched for this areaRect yet. Even with sameAs, you must ` +
|
|
11190
|
+
`fetch and review it before calling eyes_review_diff_report — call eyes_inspect_evidence with this areaRect in its areaRects.`);
|
|
10635
11191
|
}
|
|
10636
11192
|
await verifySameAsEligibility(sessionUrl, stepIndex, areaRect, sameAs, session.sessionName, keys, deps);
|
|
10637
11193
|
return; // the per-finding gates below are not re-checked on this branch — see the reasoning above.
|
|
10638
11194
|
}
|
|
10639
|
-
|
|
10640
|
-
|
|
11195
|
+
// Exactly what `eyes_inspect_evidence` would gather and no more: demanding a side the bundle refuses to fetch would leave the step unclosable.
|
|
11196
|
+
const planned = plannedEvidence(step, areaRect);
|
|
11197
|
+
if (planned.length === 0) {
|
|
11198
|
+
// Otherwise the loop below would demand nothing and pass vacuously on an invented rect.
|
|
11199
|
+
throw new Error(`areaRect ${JSON.stringify(areaRect)} lies outside every image of this step, so there is no evidence to review it by. Report a changed area that eyes_inspect_changed_areas or eyes_review_progress actually named.`);
|
|
10641
11200
|
}
|
|
10642
|
-
for (const
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
if (!
|
|
10649
|
-
|
|
11201
|
+
for (const request of planned) {
|
|
11202
|
+
if (evidenceCovers(request.label))
|
|
11203
|
+
continue;
|
|
11204
|
+
const fetchedRaw = request.label === 'diff'
|
|
11205
|
+
? verifyInvocation(stepScope, EYES_INSPECT_TOOLS.imageDiff, args => rectMatches(args.rect), deps)
|
|
11206
|
+
: verifyInvocation(sessionScopeId(sessionUrl), EYES_INSPECT_TOOLS.image, args => args.imageId === request.imageId && rectMatches(args.rect), deps);
|
|
11207
|
+
if (!fetchedRaw) {
|
|
11208
|
+
const what = request.label === 'diff' ? 'The image diff' : `This step's ${request.label} image`;
|
|
11209
|
+
throw new Error(`${what} has not been fetched for this areaRect yet. Call eyes_inspect_evidence with this areaRect in its areaRects — batch every other unreviewed area of this step into the same call — before calling eyes_review_diff_report.`);
|
|
10650
11210
|
}
|
|
10651
11211
|
}
|
|
10652
11212
|
for (const finding of findings) {
|
|
@@ -10725,6 +11285,82 @@ function finalDoneMessage(params) {
|
|
|
10725
11285
|
// and calls exactly one of these per handler, after resolving `rootScope`/`mode`/`keys`, and
|
|
10726
11286
|
// JSON-serializes whatever it returns.
|
|
10727
11287
|
// ---------------------------------------------------------------------------
|
|
11288
|
+
/** Each level's indexed child findings — the block its `_end` validates `sources` against, read by its own `_progress` and by its last child's `_end`. */
|
|
11289
|
+
const findingsBlock = {
|
|
11290
|
+
batch: (scopeId, deps) => attachFindingIndices(orderedChildFindingEntries(scopeId, deps)).map(([scenarioName, findings]) => ({ scenarioName, findings })),
|
|
11291
|
+
scenario: (scopeId, deps) => attachFindingIndices(orderedChildFindingEntries(scopeId, deps)).map(([sessionUrl, findings]) => ({ sessionUrl, findings })),
|
|
11292
|
+
session: (scopeId, deps) => attachFindingIndices(orderedChildFindingEntries(scopeId, deps)).map(([stepKey, findings]) => ({
|
|
11293
|
+
stepIndex: parseStepChildKey(stepKey),
|
|
11294
|
+
findings,
|
|
11295
|
+
})),
|
|
11296
|
+
step: (scopeId, deps) => attachFindingIndices(orderedChildFindingEntries(scopeId, deps)).map(([rectKey, findings]) => ({
|
|
11297
|
+
areaRect: parseDiffChildKey(rectKey),
|
|
11298
|
+
findings,
|
|
11299
|
+
})),
|
|
11300
|
+
};
|
|
11301
|
+
/** Parent links are thunks so a walk that compresses nothing resolves nothing — at the step edge, naming the parent costs a fetch. */
|
|
11302
|
+
function batchAscent(batchUrl, rootScope, mode, deps) {
|
|
11303
|
+
const scopeId = batchScopeId(batchUrl);
|
|
11304
|
+
return {
|
|
11305
|
+
level: 'batch',
|
|
11306
|
+
scope: 'batch',
|
|
11307
|
+
scopeId,
|
|
11308
|
+
ctx: { batchUrl },
|
|
11309
|
+
endCall: reviewEndCall('batch', { batchUrl }, rootScope, mode),
|
|
11310
|
+
findings: () => findingsBlock.batch(scopeId, deps),
|
|
11311
|
+
clusters: () => sourceClustersFor(scopeId, deps),
|
|
11312
|
+
};
|
|
11313
|
+
}
|
|
11314
|
+
function scenarioAscent(batchUrl, scenarioName, rootScope, mode, deps) {
|
|
11315
|
+
const scopeId = scenarioScopeId(batchUrl, scenarioName);
|
|
11316
|
+
return {
|
|
11317
|
+
level: 'scenario',
|
|
11318
|
+
scope: 'scenario',
|
|
11319
|
+
scopeId,
|
|
11320
|
+
ctx: { batchUrl, scenarioName },
|
|
11321
|
+
endCall: reviewEndCall('scenario', { batchUrl, scenarioName }, rootScope, mode),
|
|
11322
|
+
findings: () => findingsBlock.scenario(scopeId, deps),
|
|
11323
|
+
clusters: () => sourceClustersFor(scopeId, deps),
|
|
11324
|
+
...(hasReachedRootScope('scenario', rootScope)
|
|
11325
|
+
? {}
|
|
11326
|
+
: {
|
|
11327
|
+
up: {
|
|
11328
|
+
key: scenarioChildKey(scenarioName),
|
|
11329
|
+
parent: async () => batchAscent(batchUrl, rootScope, mode, deps),
|
|
11330
|
+
},
|
|
11331
|
+
}),
|
|
11332
|
+
};
|
|
11333
|
+
}
|
|
11334
|
+
function sessionAscent(params) {
|
|
11335
|
+
const { sessionUrl, scenario, rootScope, mode, deps } = params;
|
|
11336
|
+
const scopeId = sessionScopeId(sessionUrl);
|
|
11337
|
+
return {
|
|
11338
|
+
level: 'session',
|
|
11339
|
+
scope: 'session',
|
|
11340
|
+
scopeId,
|
|
11341
|
+
ctx: { sessionUrl },
|
|
11342
|
+
endCall: reviewEndCall('session', { sessionUrl }, rootScope, mode),
|
|
11343
|
+
findings: () => findingsBlock.session(scopeId, deps),
|
|
11344
|
+
clusters: () => sourceClustersFor(scopeId, deps),
|
|
11345
|
+
...(hasReachedRootScope('session', rootScope) ? {} : { up: { key: sessionChildKey(sessionUrl), parent: scenario } }),
|
|
11346
|
+
};
|
|
11347
|
+
}
|
|
11348
|
+
/** No `up` link on purpose: a step is never compressed, so the ascent stops here. */
|
|
11349
|
+
function stepAscent(sessionUrl, stepIndex, rootScope, mode, deps) {
|
|
11350
|
+
const scopeId = stepScopeId(sessionUrl, stepIndex);
|
|
11351
|
+
return {
|
|
11352
|
+
level: 'step',
|
|
11353
|
+
scope: 'step',
|
|
11354
|
+
scopeId,
|
|
11355
|
+
ctx: { sessionUrl, stepIndex },
|
|
11356
|
+
endCall: reviewEndCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
11357
|
+
findings: () => findingsBlock.step(scopeId, deps),
|
|
11358
|
+
clusters: () => sourceClustersFor(scopeId, deps),
|
|
11359
|
+
};
|
|
11360
|
+
}
|
|
11361
|
+
function sourceClustersFor(scopeId, deps) {
|
|
11362
|
+
return buildSourceClusters(orderedChildFindingEntries(scopeId, deps));
|
|
11363
|
+
}
|
|
10728
11364
|
async function batchProgress(params) {
|
|
10729
11365
|
const { batchUrl, keys, rootScope, mode, restart, deps } = params;
|
|
10730
11366
|
const scopeId = batchScopeId(batchUrl);
|
|
@@ -10737,8 +11373,9 @@ async function batchProgress(params) {
|
|
|
10737
11373
|
rootScope,
|
|
10738
11374
|
mode,
|
|
10739
11375
|
children,
|
|
11376
|
+
descend: child => descentTarget('batch', { batchUrl }, child.key, rootScope, mode, deps).call,
|
|
10740
11377
|
endCall: reviewEndCall('batch', { batchUrl }, rootScope, mode),
|
|
10741
|
-
buildFindings: () =>
|
|
11378
|
+
buildFindings: () => findingsBlock.batch(scopeId, deps),
|
|
10742
11379
|
deps,
|
|
10743
11380
|
});
|
|
10744
11381
|
}
|
|
@@ -10765,6 +11402,7 @@ async function batchEnd(params) {
|
|
|
10765
11402
|
finalize: verifyAndConsolidate(scopeId, batchScopeId(batchUrl), { batchUrl, findings }, findings, mode, deps),
|
|
10766
11403
|
progressCall: reviewProgressCall('batch', { batchUrl }, rootScope, mode),
|
|
10767
11404
|
getSiblings: async () => [],
|
|
11405
|
+
mode,
|
|
10768
11406
|
doneMessage,
|
|
10769
11407
|
deps,
|
|
10770
11408
|
});
|
|
@@ -10794,8 +11432,9 @@ async function scenarioProgress(params) {
|
|
|
10794
11432
|
rootScope,
|
|
10795
11433
|
mode,
|
|
10796
11434
|
children,
|
|
11435
|
+
descend: child => descentTarget('scenario', { batchUrl, scenarioName }, child.key, rootScope, mode, deps).call,
|
|
10797
11436
|
endCall: reviewEndCall('scenario', { batchUrl, scenarioName }, rootScope, mode),
|
|
10798
|
-
buildFindings: () =>
|
|
11437
|
+
buildFindings: () => findingsBlock.scenario(scopeId, deps),
|
|
10799
11438
|
deps,
|
|
10800
11439
|
});
|
|
10801
11440
|
}
|
|
@@ -10837,7 +11476,10 @@ async function scenarioEnd(params) {
|
|
|
10837
11476
|
? undefined
|
|
10838
11477
|
: { parentScopeId: batchScopeId(batchUrl), childKey: scenarioChildKey(scenarioName) },
|
|
10839
11478
|
getSiblings: async () => (await batchChildren(batchUrl, keys, rootScope, mode, deps)).filter(s => s.scopeId !== scopeId),
|
|
11479
|
+
descend: sibling => descentTarget('batch', { batchUrl }, sibling.key, rootScope, mode, deps),
|
|
10840
11480
|
parentProgressCall: reviewProgressCall('batch', { batchUrl }, rootScope, mode),
|
|
11481
|
+
ascent: () => batchAscent(batchUrl, rootScope, mode, deps),
|
|
11482
|
+
mode,
|
|
10841
11483
|
doneMessage,
|
|
10842
11484
|
deps,
|
|
10843
11485
|
});
|
|
@@ -10895,15 +11537,16 @@ async function sessionProgress(params) {
|
|
|
10895
11537
|
if (mismatch)
|
|
10896
11538
|
return { completed: null, next: mismatch };
|
|
10897
11539
|
await promoteAndRecordMode({ level: 'session', scopeId, ctx: { sessionUrl }, rootScope, mode, restart, keys, deps });
|
|
10898
|
-
const children = await sessionStepChildren({ sessionUrl, session,
|
|
11540
|
+
const children = await sessionStepChildren({ sessionUrl, session, mode, keys, deps });
|
|
10899
11541
|
return runProgress({
|
|
10900
11542
|
level: 'session',
|
|
10901
11543
|
scopeId,
|
|
10902
11544
|
rootScope,
|
|
10903
11545
|
mode,
|
|
10904
11546
|
children,
|
|
11547
|
+
descend: child => descentTarget('session', { sessionUrl }, child.key, rootScope, mode, deps).call,
|
|
10905
11548
|
endCall: reviewEndCall('session', { sessionUrl }, rootScope, mode),
|
|
10906
|
-
buildFindings: () =>
|
|
11549
|
+
buildFindings: () => findingsBlock.session(scopeId, deps),
|
|
10907
11550
|
deps,
|
|
10908
11551
|
});
|
|
10909
11552
|
}
|
|
@@ -10933,7 +11576,7 @@ async function sessionEnd(params) {
|
|
|
10933
11576
|
if (mismatch)
|
|
10934
11577
|
return { next: mismatch };
|
|
10935
11578
|
await promoteAndRecordMode({ level: 'session', scopeId, ctx: { sessionUrl }, rootScope, mode, restart, keys, deps });
|
|
10936
|
-
const children = await sessionStepChildren({ sessionUrl, session,
|
|
11579
|
+
const children = await sessionStepChildren({ sessionUrl, session, mode, keys, deps });
|
|
10937
11580
|
const doneMessage = finalDoneMessage({
|
|
10938
11581
|
level: 'This session',
|
|
10939
11582
|
findingsCount: findings.length,
|
|
@@ -10956,12 +11599,26 @@ async function sessionEnd(params) {
|
|
|
10956
11599
|
childKey: sessionChildKey(sessionUrl),
|
|
10957
11600
|
},
|
|
10958
11601
|
getSiblings: async () => (await scenarioChildren(batchUrl, session.sessionName, keys, rootScope, mode, deps)).filter(s => s.scopeId !== scopeId),
|
|
11602
|
+
descend: sibling => descentTarget('scenario', { batchUrl, scenarioName: session.sessionName }, sibling.key, rootScope, mode, deps),
|
|
10959
11603
|
parentProgressCall: reviewProgressCall('scenario', { batchUrl, scenarioName: session.sessionName }, rootScope, mode),
|
|
11604
|
+
ascent: () => scenarioAscent(batchUrl, session.sessionName, rootScope, mode, deps),
|
|
11605
|
+
mode,
|
|
10960
11606
|
doneMessage,
|
|
10961
11607
|
deps,
|
|
10962
11608
|
});
|
|
10963
11609
|
return endResponse(result, mode, result.next.instruction === doneMessage);
|
|
10964
11610
|
}
|
|
11611
|
+
const DOM_DIFF_OBTAINABLE_RECORD = 'stepProgress:domDiffObtainable';
|
|
11612
|
+
/** Why this step can never yield a DOM diff, decided from session data ahead of any call; `fetchVisibleDomDiff`'s third case, `no-dom-data`, is only knowable from the server. */
|
|
11613
|
+
function domDiffUnobtainableReason(step) {
|
|
11614
|
+
if (!step)
|
|
11615
|
+
return null;
|
|
11616
|
+
if (!step.baseline.domId)
|
|
11617
|
+
return 'it has no baseline DOM capture';
|
|
11618
|
+
if (!step.checkpoint.domId)
|
|
11619
|
+
return 'it has no checkpoint DOM capture';
|
|
11620
|
+
return null;
|
|
11621
|
+
}
|
|
10965
11622
|
async function stepProgress(params) {
|
|
10966
11623
|
var _a, _b;
|
|
10967
11624
|
const { sessionUrl, stepIndex, keys, rootScope, mode, restart, deps } = params;
|
|
@@ -10980,27 +11637,94 @@ async function stepProgress(params) {
|
|
|
10980
11637
|
keys,
|
|
10981
11638
|
deps,
|
|
10982
11639
|
});
|
|
10983
|
-
const children = await stepChildren(sessionUrl, stepIndex, keys,
|
|
11640
|
+
const children = await stepChildren(sessionUrl, stepIndex, keys, deps);
|
|
10984
11641
|
const result = await runProgress({
|
|
10985
11642
|
level: 'step',
|
|
10986
11643
|
scopeId,
|
|
10987
11644
|
rootScope,
|
|
10988
11645
|
mode,
|
|
10989
11646
|
children,
|
|
11647
|
+
descend: child => descentTarget('step', { sessionUrl, stepIndex }, child.key, rootScope, mode, deps).call,
|
|
10990
11648
|
endCall: reviewEndCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
10991
|
-
buildFindings: () =>
|
|
11649
|
+
buildFindings: () => findingsBlock.step(scopeId, deps),
|
|
10992
11650
|
deps,
|
|
10993
11651
|
});
|
|
10994
11652
|
if (result.completed === null) {
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
11653
|
+
let unobtainable = null;
|
|
11654
|
+
if (!verifyInvocation(scopeId, EYES_INSPECT_TOOLS.domDiff, isExaminedDomDiff, deps)) {
|
|
11655
|
+
const alreadyLogged = verifyInvocation(scopeId, EYES_INSPECT_TOOLS.domDiff, args => {
|
|
11656
|
+
const reason = args.unobtainable;
|
|
11657
|
+
if (typeof reason !== 'string')
|
|
11658
|
+
return false;
|
|
11659
|
+
unobtainable = reason;
|
|
11660
|
+
return true;
|
|
11661
|
+
}, deps);
|
|
11662
|
+
if (!alreadyLogged && !verifyInvocation(scopeId, DOM_DIFF_OBTAINABLE_RECORD, () => true, deps)) {
|
|
11663
|
+
unobtainable = domDiffUnobtainableReason((_a = (await fetchSteps(sessionUrl, keys)).steps) === null || _a === void 0 ? void 0 : _a[stepIndex]);
|
|
11664
|
+
if (unobtainable)
|
|
11665
|
+
logInvocation(scopeId, EYES_INSPECT_TOOLS.domDiff, { unobtainable }, deps);
|
|
11666
|
+
else
|
|
11667
|
+
logInvocation(scopeId, DOM_DIFF_OBTAINABLE_RECORD, {}, deps);
|
|
11668
|
+
}
|
|
11669
|
+
}
|
|
11670
|
+
if (unobtainable) {
|
|
11671
|
+
result.next.instruction += ` Do NOT call eyes_inspect_dom_diff for this step — ${unobtainable}, so no structural comparison is available. Review from the images alone, and record that the structural comparison was unavailable rather than that no structural change was found.`;
|
|
11672
|
+
}
|
|
11673
|
+
const calls = result.next.calls;
|
|
11674
|
+
if (((_b = calls === null || calls === void 0 ? void 0 : calls[0]) === null || _b === void 0 ? void 0 : _b.tool) === EYES_REVIEW_TOOLS.diffReport) {
|
|
11675
|
+
// Not a review tool, so it carries no rootScope/mode and is not built through `nextCall`.
|
|
11676
|
+
const unreviewed = incompleteAreaRects(children, deps);
|
|
11677
|
+
const evidence = evidenceRoundCall(sessionUrl, stepIndex, unreviewed);
|
|
11678
|
+
const batched = evidence.args.areaRects;
|
|
11679
|
+
calls.unshift(evidence);
|
|
11680
|
+
result.next.instruction += ` Call ${EYES_INSPECT_TOOLS.evidence} ONCE, with the ${batched.length} areaRects the first call in next.calls already carries — not once per area, and do NOT pad them yourself; it returns the image diff and both baseline/checkpoint images for every area together, already padded and cropped.`;
|
|
11681
|
+
if (!unobtainable) {
|
|
11682
|
+
result.next.instruction += ` That same response carries this step's structural DOM diff and the match regions currently in effect, so ${EYES_INSPECT_TOOLS.domDiff} and ${EYES_INSPECT_TOOLS.regions} need no calls of their own here. Read the DOM diff regardless of how small or scattered the changed areas look — a visual crop comparison can miss small displacement it catches directly — and if its \`domDiff\` field reports anything other than a diff, follow that field's own \`next\` before reporting.`;
|
|
11683
|
+
}
|
|
11684
|
+
if (unreviewed.length > batched.length) {
|
|
11685
|
+
result.next.instruction += ` This step has ${unreviewed.length} unreviewed areas, more than one call can carry: review these ${batched.length} first, then call ${EYES_INSPECT_TOOLS.evidence} again for the rest.`;
|
|
11686
|
+
}
|
|
10998
11687
|
result.next.instruction +=
|
|
10999
|
-
"
|
|
11688
|
+
" Then take the areas one at a time: count the pink regions in that area's image diff. If more than one, report each individually via eyes_review_diff_report with its own smaller rect, then always finish with one eyes_review_diff_report call on the changed area's own full areaRect — that's what marks it reviewed.";
|
|
11689
|
+
// sameAs buys its way past the image gates with an examined dom diff, so a step with none can't use it.
|
|
11690
|
+
if (!unobtainable) {
|
|
11691
|
+
result.next.instruction +=
|
|
11692
|
+
" Shortcut: if that response's DOM diff shows this exact structural change was recorded earlier in this scenario (another step of this session, or a sibling session in another browser/environment/viewport), call eyes_review_diff_report with sameAs: {sessionUrl, stepIndex, areaRect} pointing at that prior call and report from this step's own evidence without re-analysing the whole change.";
|
|
11693
|
+
}
|
|
11694
|
+
}
|
|
11695
|
+
else if (!unobtainable) {
|
|
11696
|
+
result.next.instruction += ` Call ${EYES_INSPECT_TOOLS.domDiff} for this step before ${EYES_REVIEW_TOOLS.end} — every area here is already reviewed, so no ${EYES_INSPECT_TOOLS.evidence} call is left to carry this step's structural DOM diff, and the step does not close until that diff is on record. Read it regardless of how small or scattered the changed areas look — a visual crop comparison can miss small displacement it catches directly.`;
|
|
11000
11697
|
}
|
|
11001
11698
|
}
|
|
11002
11699
|
return result;
|
|
11003
11700
|
}
|
|
11701
|
+
/** The changed areas of a step still unreviewed. */
|
|
11702
|
+
function incompleteAreaRects(children, deps) {
|
|
11703
|
+
return children.filter(child => !isCompleted(child.scopeId, deps)).map(child => parseDiffChildKey(child.key));
|
|
11704
|
+
}
|
|
11705
|
+
/** One evidence round: as many unreviewed areas as a single call can inline. A step with more is reviewed a round at a time, so no area is ever judged from paths alone. */
|
|
11706
|
+
function evidenceRoundCall(sessionUrl, stepIndex, unreviewed) {
|
|
11707
|
+
return {
|
|
11708
|
+
tool: EYES_INSPECT_TOOLS.evidence,
|
|
11709
|
+
args: { sessionUrl, stepIndex, areaRects: unreviewed.slice(0, MAX_EVIDENCE_BATCH) },
|
|
11710
|
+
};
|
|
11711
|
+
}
|
|
11712
|
+
function hasEvidence(sessionUrl, stepIndex, areaRect, deps) {
|
|
11713
|
+
return verifyInvocation(stepScopeId(sessionUrl, stepIndex), EYES_INSPECT_TOOLS.evidence, args => rectsIntersect(args.areaRect, areaRect), deps);
|
|
11714
|
+
}
|
|
11715
|
+
/** Opens the next round when the walk reaches an area the last round did not cover — without it the area's gate would reject and the step would stall. */
|
|
11716
|
+
async function prependEvidenceRound(next, params) {
|
|
11717
|
+
var _a;
|
|
11718
|
+
const { sessionUrl, stepIndex, keys, deps } = params;
|
|
11719
|
+
const target = (_a = next.calls) === null || _a === void 0 ? void 0 : _a[0];
|
|
11720
|
+
if ((target === null || target === void 0 ? void 0 : target.tool) !== EYES_REVIEW_TOOLS.diffReport)
|
|
11721
|
+
return;
|
|
11722
|
+
if (hasEvidence(sessionUrl, stepIndex, target.args.areaRect, deps))
|
|
11723
|
+
return;
|
|
11724
|
+
const unreviewed = incompleteAreaRects(await stepChildren(sessionUrl, stepIndex, keys, deps), deps);
|
|
11725
|
+
next.calls.unshift(evidenceRoundCall(sessionUrl, stepIndex, unreviewed));
|
|
11726
|
+
next.instruction += ` The areas left need their own evidence: call ${EYES_INSPECT_TOOLS.evidence} ONCE with the areaRects the first call in next.calls already carries.`;
|
|
11727
|
+
}
|
|
11004
11728
|
async function stepEnd(params) {
|
|
11005
11729
|
const { sessionUrl, stepIndex, findings, keys, rootScope, mode, restart, deps } = params;
|
|
11006
11730
|
const scopeId = stepScopeId(sessionUrl, stepIndex);
|
|
@@ -11023,7 +11747,7 @@ async function stepEnd(params) {
|
|
|
11023
11747
|
throw new Error('eyes_inspect_dom_diff has not been called for this session+step yet. Call it before eyes_review_end for this step — it may reveal the diff is caused by element displacement rather than independent content changes.');
|
|
11024
11748
|
}
|
|
11025
11749
|
});
|
|
11026
|
-
const children = await stepChildren(sessionUrl, stepIndex, keys,
|
|
11750
|
+
const children = await stepChildren(sessionUrl, stepIndex, keys, deps);
|
|
11027
11751
|
// Whatever this call decides is captured here so the response can state the outcome plainly
|
|
11028
11752
|
// — `finalize` only runs when the call genuinely persists, so on the discarded path these
|
|
11029
11753
|
// stay untouched and nothing is resolved.
|
|
@@ -11044,7 +11768,7 @@ async function stepEnd(params) {
|
|
|
11044
11768
|
ownChildren: children,
|
|
11045
11769
|
finalize: async () => {
|
|
11046
11770
|
const childFindings = flattenChildFindings(scopeId, deps);
|
|
11047
|
-
await withGateLog(EYES_REVIEW_TOOLS.end, sessionScopeId(sessionUrl), { sessionUrl, stepIndex, findings, rootScope, mode }, deps, () => verifySourcedFindings(findings, childFindings));
|
|
11771
|
+
await withGateLog(EYES_REVIEW_TOOLS.end, sessionScopeId(sessionUrl), { sessionUrl, stepIndex, findings, rootScope, mode }, deps, () => verifySourcedFindings(expandSourceCitations(findings, sourceClustersFor(scopeId, deps)), childFindings));
|
|
11048
11772
|
const cleanFindings = stripSources(findings);
|
|
11049
11773
|
// Computed here rather than asked of the model (unlike the session/scenario/batch
|
|
11050
11774
|
// levels' model-supplied `example`): sessionUrl/stepIndex are this call's own args and
|
|
@@ -11081,8 +11805,21 @@ async function stepEnd(params) {
|
|
|
11081
11805
|
pushUpTo: hasReachedRootScope('step', rootScope)
|
|
11082
11806
|
? undefined
|
|
11083
11807
|
: { parentScopeId: sessionScopeId(sessionUrl), childKey: stepChildKey(stepIndex) },
|
|
11084
|
-
getSiblings: async () => (await sessionChildren({ sessionUrl, keys,
|
|
11808
|
+
getSiblings: async () => (await sessionChildren({ sessionUrl, keys, mode, deps })).filter(s => s.scopeId !== scopeId),
|
|
11809
|
+
descend: sibling => descentTarget('session', { sessionUrl }, sibling.key, rootScope, mode, deps),
|
|
11085
11810
|
parentProgressCall: reviewProgressCall('session', { sessionUrl }, rootScope, mode),
|
|
11811
|
+
ascent: () => sessionAscent({
|
|
11812
|
+
sessionUrl,
|
|
11813
|
+
rootScope,
|
|
11814
|
+
mode,
|
|
11815
|
+
deps,
|
|
11816
|
+
scenario: async () => {
|
|
11817
|
+
const { sessionName } = await fetchSteps(sessionUrl, keys);
|
|
11818
|
+
const { baseUrl, batchId, accountId } = await parseSessionUrlVerified(sessionUrl, keys);
|
|
11819
|
+
return scenarioAscent(buildBatchUrl({ baseUrl, batchId, accountId }), sessionName, rootScope, mode, deps);
|
|
11820
|
+
},
|
|
11821
|
+
}),
|
|
11822
|
+
mode,
|
|
11086
11823
|
doneMessage,
|
|
11087
11824
|
deps,
|
|
11088
11825
|
});
|
|
@@ -11151,11 +11888,15 @@ async function diffReport(params) {
|
|
|
11151
11888
|
pushUpTo: hasReachedRootScope('diff', rootScope)
|
|
11152
11889
|
? undefined
|
|
11153
11890
|
: { parentScopeId: stepScopeId(sessionUrl, stepIndex), childKey: diffChildKey(areaRect) },
|
|
11154
|
-
getSiblings: async () => (await stepChildren(sessionUrl, stepIndex, keys,
|
|
11891
|
+
getSiblings: async () => (await stepChildren(sessionUrl, stepIndex, keys, deps)).filter(s => s.scopeId !== scopeId),
|
|
11892
|
+
descend: sibling => descentTarget('step', { sessionUrl, stepIndex }, sibling.key, rootScope, mode, deps),
|
|
11155
11893
|
parentProgressCall: reviewProgressCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
11894
|
+
ascent: () => stepAscent(sessionUrl, stepIndex, rootScope, mode, deps),
|
|
11895
|
+
mode,
|
|
11156
11896
|
doneMessage: 'This changed area is recorded.',
|
|
11157
11897
|
deps,
|
|
11158
11898
|
});
|
|
11899
|
+
await prependEvidenceRound(result.next, { sessionUrl, stepIndex, keys, deps });
|
|
11159
11900
|
return { findings: result.findings, next: result.next };
|
|
11160
11901
|
}
|
|
11161
11902
|
|
|
@@ -11227,6 +11968,24 @@ function findingsFor(shape, findings, scope) {
|
|
|
11227
11968
|
}
|
|
11228
11969
|
return parsed.data;
|
|
11229
11970
|
}
|
|
11971
|
+
/** Resolves a JsonFileArgShape-eligible argument: reads and parses it if the model sent a file path instead of the array inline. */
|
|
11972
|
+
async function resolveJsonArg(raw, argName) {
|
|
11973
|
+
if (typeof raw !== 'string')
|
|
11974
|
+
return raw;
|
|
11975
|
+
let contents;
|
|
11976
|
+
try {
|
|
11977
|
+
contents = await promises.readFile(raw, 'utf-8');
|
|
11978
|
+
}
|
|
11979
|
+
catch (err) {
|
|
11980
|
+
throw new Error(`${argName} named a file path ("${raw}") that could not be read: ${err.message}`);
|
|
11981
|
+
}
|
|
11982
|
+
try {
|
|
11983
|
+
return JSON.parse(contents);
|
|
11984
|
+
}
|
|
11985
|
+
catch (err) {
|
|
11986
|
+
throw new Error(`${argName}'s file ("${raw}") is not valid JSON: ${err.message}`);
|
|
11987
|
+
}
|
|
11988
|
+
}
|
|
11230
11989
|
function recordReviewCall(scopeType, mode) {
|
|
11231
11990
|
recordToolTelemetry({ chain_source: 'review', scope_type: scopeType, mode });
|
|
11232
11991
|
}
|
|
@@ -11285,15 +12044,16 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
11285
12044
|
inputSchema: {
|
|
11286
12045
|
scope: EndScopeShape,
|
|
11287
12046
|
...REVIEW_SCOPE_ID_SHAPES,
|
|
11288
|
-
findings: ReviewEndFindingsShape,
|
|
12047
|
+
findings: zod.z.union([ReviewEndFindingsShape, JsonFileArgShape]),
|
|
11289
12048
|
rootScope: RootScopeShape,
|
|
11290
12049
|
mode: ModeShape,
|
|
11291
12050
|
restart: RestartShape,
|
|
11292
12051
|
},
|
|
11293
|
-
}, async ({ scope, batchUrl, scenarioName, sessionUrl, stepIndex, findings:
|
|
12052
|
+
}, async ({ scope, batchUrl, scenarioName, sessionUrl, stepIndex, findings: rawFindingsArg, rootScope: rawRootScope, mode: rawMode, restart, }) => {
|
|
11294
12053
|
const rootScope = resolveRootScope(scope, rawRootScope);
|
|
11295
12054
|
const mode = resolveMode(rawMode);
|
|
11296
12055
|
recordReviewCall(scope, mode);
|
|
12056
|
+
const rawFindings = await resolveJsonArg(rawFindingsArg, 'findings');
|
|
11297
12057
|
const summaryFindings = () => findingsFor(SummaryExampleShape, rawFindings, scope);
|
|
11298
12058
|
const result = await (async () => {
|
|
11299
12059
|
switch (scope) {
|
|
@@ -11380,7 +12140,11 @@ const EXPERIMENTAL_TOOL_SWAP = {
|
|
|
11380
12140
|
// Hidden IN experimental mode: the legacy results tools the families replace. Runtime-hidden
|
|
11381
12141
|
// rather than deleted (see `.team-lead/plan-remove-legacy-results-tools.md` for the eventual
|
|
11382
12142
|
// removal) so the default server keeps its published tool set untouched.
|
|
11383
|
-
replacedByExperimental: [
|
|
12143
|
+
replacedByExperimental: [
|
|
12144
|
+
TOOL_NAMES.EYES_GET_BATCH_URL,
|
|
12145
|
+
TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS,
|
|
12146
|
+
TOOL_NAMES.EYES_ANALYZE_BATCH,
|
|
12147
|
+
],
|
|
11384
12148
|
};
|
|
11385
12149
|
function skippedToolNames(experimental) {
|
|
11386
12150
|
return new Set(experimental ? EXPERIMENTAL_TOOL_SWAP.replacedByExperimental : EXPERIMENTAL_TOOL_SWAP.experimentalOnly);
|