@applitools/mcp 0.8.5 → 0.8.6
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 +39 -0
- package/dist/index.js +408 -1483
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -50,10 +50,9 @@ const TOOL_NAMES = {
|
|
|
50
50
|
EYES_SETUP_PROJECT: 'eyes_setup_project',
|
|
51
51
|
EYES_SETUP_UFG: 'eyes_setup_ufg',
|
|
52
52
|
EYES_ADD_CHECKPOINTS: 'eyes_add_checkpoints_to_test',
|
|
53
|
-
EYES_GET_BATCH_URL: 'eyes_get_batch_url',
|
|
54
|
-
EYES_FETCH_VISUAL_RESULTS: 'eyes_fetch_visual_results',
|
|
55
|
-
EYES_ANALYZE_BATCH: 'eyes_analyze_batch',
|
|
56
53
|
};
|
|
54
|
+
/** Opt-in for the experimental tool set (`1`/`true`). Off by default; see `EXPERIMENTAL_TOOLS`. */
|
|
55
|
+
const EXPERIMENTAL_ENV = 'APPLITOOLS_MCP_EXPERIMENTAL';
|
|
57
56
|
const DEFAULT_SERVER_URL = 'https://eyes.applitools.com';
|
|
58
57
|
const TRANSPORT_MODE = 'stdio';
|
|
59
58
|
const RESOURCE_URIS = {
|
|
@@ -216,7 +215,6 @@ function findApiKey(workingDirectory = process.cwd()) {
|
|
|
216
215
|
let currentClientInfo = undefined;
|
|
217
216
|
let currentCredentials = undefined;
|
|
218
217
|
let ide = undefined;
|
|
219
|
-
let experimental = false;
|
|
220
218
|
function setClientInfo(clientInfo) {
|
|
221
219
|
currentClientInfo = clientInfo;
|
|
222
220
|
}
|
|
@@ -239,20 +237,10 @@ function parseIDE(env, argv) {
|
|
|
239
237
|
var _a;
|
|
240
238
|
return env['ide'] || ((_a = argv.find(arg => arg.startsWith('--ide='))) === null || _a === void 0 ? void 0 : _a.split('=')[1]) || 'unknown';
|
|
241
239
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return experimental;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* The swap is unconditional: the server always registers the eyes-inspect/eyes-resolve/eyes-review
|
|
250
|
-
* families in place of the legacy results tools — see `registerAllTools`. No env, argv or config
|
|
251
|
-
* turns it off; the retired `--experimental` argv and `APPLITOOLS_MCP_EXPERIMENTAL` stay ignored.
|
|
252
|
-
* Kept as a seam so the mode plumbing can be unwound in one pass rather than threaded through here.
|
|
253
|
-
*/
|
|
254
|
-
function parseExperimental() {
|
|
255
|
-
return true;
|
|
240
|
+
/** Evaluated once at process start; off unless `EXPERIMENTAL_ENV` is `1`/`true` (any case). */
|
|
241
|
+
function parseExperimental(env) {
|
|
242
|
+
var _a;
|
|
243
|
+
return ['1', 'true'].includes(((_a = env[EXPERIMENTAL_ENV]) !== null && _a !== void 0 ? _a : '').toLowerCase());
|
|
256
244
|
}
|
|
257
245
|
|
|
258
246
|
/** Load credentials from server context, config files, or environment variables */
|
|
@@ -552,6 +540,17 @@ function recordScopeMode(scopeId, mode, deps = defaultPhaseTrackerDeps) {
|
|
|
552
540
|
function getScopeMode(scopeId, deps = defaultPhaseTrackerDeps) {
|
|
553
541
|
return readJson(deps, recordPath(deps, 'modes', scopeId));
|
|
554
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Persists `rootScope` as the root of the review that last touched `scopeId`, overwriting any earlier one.
|
|
545
|
+
* A hint for the caller's guidance only: concurrent reviews of one scope overwrite each other.
|
|
546
|
+
*/
|
|
547
|
+
function recordScopeRoot(scopeId, rootScope, deps = defaultPhaseTrackerDeps) {
|
|
548
|
+
writeJson(deps, recordPath(deps, 'roots', scopeId), rootScope);
|
|
549
|
+
}
|
|
550
|
+
/** The root last recorded for `scopeId` via `recordScopeRoot`, or `undefined` if never recorded. */
|
|
551
|
+
function getScopeRoot(scopeId, deps = defaultPhaseTrackerDeps) {
|
|
552
|
+
return readJson(deps, recordPath(deps, 'roots', scopeId));
|
|
553
|
+
}
|
|
555
554
|
/** Discards `id`'s completion, as if `recordCompletion` had never been called for it. */
|
|
556
555
|
function clearCompletion(id, deps = defaultPhaseTrackerDeps) {
|
|
557
556
|
withRetry(() => deps.deleteFile(recordPath(deps, 'completions', id)), deps);
|
|
@@ -564,6 +563,10 @@ function clearChildFindings(parentId, deps = defaultPhaseTrackerDeps) {
|
|
|
564
563
|
function clearScopeMode(scopeId, deps = defaultPhaseTrackerDeps) {
|
|
565
564
|
withRetry(() => deps.deleteFile(recordPath(deps, 'modes', scopeId)), deps);
|
|
566
565
|
}
|
|
566
|
+
/** Discards `scopeId`'s recorded root, as if `recordScopeRoot` had never been called for it. */
|
|
567
|
+
function clearScopeRoot(scopeId, deps = defaultPhaseTrackerDeps) {
|
|
568
|
+
withRetry(() => deps.deleteFile(recordPath(deps, 'roots', scopeId)), deps);
|
|
569
|
+
}
|
|
567
570
|
/** Persists the keys of `scopeId`'s children still unready to be finalized, as of its own latest live check — overwriting whatever was recorded before, so a child that has since become ready (or a newly-discovered unready one) is reflected exactly, never accumulated across checks. */
|
|
568
571
|
function recordUnreadyChildren(scopeId, childKeys, deps = defaultPhaseTrackerDeps) {
|
|
569
572
|
writeJson(deps, recordPath(deps, 'unready-children', scopeId), childKeys);
|
|
@@ -3827,7 +3830,7 @@ async function getCompatibleSelectors(options, image1, image2, selectors, fetchI
|
|
|
3827
3830
|
* differs from what the test actually ran with (see `eyes-inspect`'s `fetchDiffRects`, this
|
|
3828
3831
|
* function's only caller, for when the more expensive `compareStep` path is needed instead).
|
|
3829
3832
|
*/
|
|
3830
|
-
async function fetchStepDiff
|
|
3833
|
+
async function fetchStepDiff(options, fetchImpl = reqTransport) {
|
|
3831
3834
|
const { baseUrl, batchId, sessionId, stepIndex, accountId, keys } = options;
|
|
3832
3835
|
const url = `${baseUrl}/api/sessions/batches/${batchId}/${sessionId}/${stepIndex}/diff?accountId=${accountId}&apiKey=${encodeURIComponent(keys.getReadKey())}`;
|
|
3833
3836
|
const data = await getJson(url, fetchImpl);
|
|
@@ -4060,7 +4063,7 @@ async function mapAnchoredRegionsBySelector(rawSession, stepIndex, anchored, dep
|
|
|
4060
4063
|
}
|
|
4061
4064
|
|
|
4062
4065
|
const defaultFetchRawDiffsDeps = {
|
|
4063
|
-
fetchStepDiff
|
|
4066
|
+
fetchStepDiff,
|
|
4064
4067
|
compareStep,
|
|
4065
4068
|
readFile: defaultFsCacheDeps.readFile,
|
|
4066
4069
|
writeFile: defaultFsCacheDeps.writeFile,
|
|
@@ -4496,7 +4499,7 @@ function gateRejectionCount() {
|
|
|
4496
4499
|
|
|
4497
4500
|
var name = "@applitools/mcp";
|
|
4498
4501
|
var mcpName = "io.github.applitools/applitools";
|
|
4499
|
-
var version = "0.8.
|
|
4502
|
+
var version = "0.8.6";
|
|
4500
4503
|
var description = "Applitools MCP server for AI coding assistants";
|
|
4501
4504
|
var main = "./dist/index.js";
|
|
4502
4505
|
var bin = "./dist/index.js";
|
|
@@ -4755,7 +4758,7 @@ const createToolHandler = (toolDef, logic) => {
|
|
|
4755
4758
|
const { batchId, sessionId } = extractScopeIds(safeParams);
|
|
4756
4759
|
const telemetry = {};
|
|
4757
4760
|
const callInputs = reportedInputs(safeParams);
|
|
4758
|
-
const outcomeJsonParams = () => jsonParams({
|
|
4761
|
+
const outcomeJsonParams = () => jsonParams({ ...telemetry, gate_rejections: gateRejectionCount() }, callInputs);
|
|
4759
4762
|
externalLog('mcp_tool_invoked', {
|
|
4760
4763
|
ide: getIDE() || 'unknown',
|
|
4761
4764
|
mcp_version: packageJson.version,
|
|
@@ -4766,7 +4769,7 @@ const createToolHandler = (toolDef, logic) => {
|
|
|
4766
4769
|
batch_id: batchId,
|
|
4767
4770
|
session_id: sessionId,
|
|
4768
4771
|
params: JSON.stringify(params, null, 2).slice(0, 1024),
|
|
4769
|
-
json_params: jsonParams({
|
|
4772
|
+
json_params: jsonParams({}, callInputs),
|
|
4770
4773
|
automation_framework: automationFramework,
|
|
4771
4774
|
automation_framework_version: automationFrameworkVersion,
|
|
4772
4775
|
sdk_language: sdkLanguage,
|
|
@@ -4791,7 +4794,10 @@ const createToolHandler = (toolDef, logic) => {
|
|
|
4791
4794
|
transport_mode: TRANSPORT_MODE,
|
|
4792
4795
|
batch_id: batchId,
|
|
4793
4796
|
session_id: sessionId,
|
|
4794
|
-
|
|
4797
|
+
// Only tools with structured output report it; an empty `{}` carries nothing worth a field.
|
|
4798
|
+
...(Object.keys(structuredContentWithoutMessage).length
|
|
4799
|
+
? { params: JSON.stringify(truncateForTelemetry(structuredContentWithoutMessage), null, 2).slice(0, 1024) }
|
|
4800
|
+
: {}),
|
|
4795
4801
|
json_params: outcomeJsonParams(),
|
|
4796
4802
|
}).catch(() => { });
|
|
4797
4803
|
const handlerResult = result;
|
|
@@ -5057,8 +5063,8 @@ async function verifyApiKeyWithServer(params) {
|
|
|
5057
5063
|
}
|
|
5058
5064
|
|
|
5059
5065
|
/** Authentication Tools - Verify API Key */
|
|
5060
|
-
const TOOL_NAME$
|
|
5061
|
-
const TOOL_DESCRIPTION$
|
|
5066
|
+
const TOOL_NAME$3 = TOOL_NAMES.EYES_VERIFY_API_KEY;
|
|
5067
|
+
const TOOL_DESCRIPTION$3 = 'Validate your Applitools API key and optional server URL. Searches for API key in .env, applitools.config.js/ts/cjs/mjs, and playwright.config.js/ts/cjs/mjs files.';
|
|
5062
5068
|
const VerifyApiKeyInputSchema = zod.z.object({
|
|
5063
5069
|
apiKey: zod.z.string().optional().describe('Optional API key to validate (will search config files if not provided)'),
|
|
5064
5070
|
serverUrl: zod.z.string().optional().describe('Optional Applitools server URL (defaults to https://eyes.applitools.com)'),
|
|
@@ -5134,11 +5140,11 @@ async function verifyApiKey(input = {}) {
|
|
|
5134
5140
|
/** Verify API Key Tool - MCP Tool Object Export */
|
|
5135
5141
|
/** MCP Tool Object for verify_api_key */
|
|
5136
5142
|
const verifyApiKeyTool = {
|
|
5137
|
-
name: TOOL_NAME$
|
|
5138
|
-
description: TOOL_DESCRIPTION$
|
|
5143
|
+
name: TOOL_NAME$3,
|
|
5144
|
+
description: TOOL_DESCRIPTION$3,
|
|
5139
5145
|
inputSchema: VerifyApiKeyInputSchema,
|
|
5140
5146
|
handler: createToolHandler({
|
|
5141
|
-
name: TOOL_NAME$
|
|
5147
|
+
name: TOOL_NAME$3,
|
|
5142
5148
|
input: VerifyApiKeyInputSchema,
|
|
5143
5149
|
}, async (params) => {
|
|
5144
5150
|
const result = await verifyApiKey(params);
|
|
@@ -5234,61 +5240,28 @@ function validateCommonInput(input) {
|
|
|
5234
5240
|
};
|
|
5235
5241
|
}
|
|
5236
5242
|
|
|
5237
|
-
//
|
|
5238
|
-
//
|
|
5239
|
-
|
|
5240
|
-
// The new-family tool names are spelled literally, matching how the family descriptions
|
|
5241
|
-
// reference each other, to keep this module free of the families' import graph.
|
|
5242
|
-
/** Why `--reporter` overrides are forbidden — the justification names whichever results surface the mode has. */
|
|
5243
|
+
// Tool names are spelled literally, matching how the family descriptions reference each other,
|
|
5244
|
+
// to keep this module free of the families' import graph.
|
|
5245
|
+
/** Why `--reporter` overrides are forbidden — the justification names what the run loses. */
|
|
5243
5246
|
function reporterOverrideWarning() {
|
|
5244
|
-
|
|
5245
|
-
? 'which means the HTML report will not contain Eyes results and the batch URL printed at the end of the run is lost.'
|
|
5246
|
-
: `which means the HTML report will not contain Eyes results. The "${TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS}" tool will then read a stale report from a previous run and return outdated results.`;
|
|
5247
|
-
return `**IMPORTANT: When running Playwright tests (including this example), NEVER add \`--reporter=list\`, \`--reporter=dot\`, \`--reporter=line\`, or any other \`--reporter\` flag. Doing so overrides the configured reporters and suppresses the Eyes reporter, ${consequence}**`;
|
|
5247
|
+
return '**IMPORTANT: When running Playwright tests (including this example), NEVER add `--reporter=list`, `--reporter=dot`, `--reporter=line`, or any other `--reporter` flag. Doing so overrides the configured reporters and suppresses the Eyes reporter, which means the HTML report will not contain Eyes results and the batch URL printed at the end of the run is lost.**';
|
|
5248
5248
|
}
|
|
5249
5249
|
const REVIEW_FLOW = `After the run, take the Eyes batch URL printed at the end of the test output and call the MCP tool "eyes_review_progress" with scope "batch" to review the results — it drives the whole investigation and tells you exactly what to inspect next; use mode "resolve" to also accept/reject checkpoints. For raw data instead of a driven review, "eyes_inspect_sessions" lists the batch's sessions and "eyes_inspect_steps" their steps.`;
|
|
5250
5250
|
function viewingResultsSection(flavor) {
|
|
5251
|
-
if (isExperimental()) {
|
|
5252
|
-
return flavor === 'project'
|
|
5253
|
-
? `**Viewing Test Results:**
|
|
5254
|
-
|
|
5255
|
-
${REVIEW_FLOW}`
|
|
5256
|
-
: `**Viewing UFG Test Results:**
|
|
5257
|
-
|
|
5258
|
-
${REVIEW_FLOW} Every browser/device configured in "browsersInfo" appears as its own session in the batch.`;
|
|
5259
|
-
}
|
|
5260
5251
|
return flavor === 'project'
|
|
5261
5252
|
? `**Viewing Test Results:**
|
|
5262
5253
|
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
1. **Get structured test status data** (RECOMMENDED):
|
|
5266
|
-
Use the MCP tool "${TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS}" to fetch complete test results including:
|
|
5267
|
-
- Batch name and URL
|
|
5268
|
-
- Test name and status (passed/failed/unresolved/new/aborted)
|
|
5269
|
-
- Retry attempt number
|
|
5270
|
-
- Individual session details
|
|
5271
|
-
This tool requires the playwright-report/index.html file to be generated.
|
|
5272
|
-
|
|
5273
|
-
2. **Extract URLs from console output**:
|
|
5274
|
-
If the playwright-report/index.html file is not available, Use the MCP tool "${TOOL_NAMES.EYES_GET_BATCH_URL}" to extract batch and session URLs from the Playwright test output.`
|
|
5254
|
+
${REVIEW_FLOW}`
|
|
5275
5255
|
: `**Viewing UFG Test Results:**
|
|
5276
5256
|
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
1. **Get structured test status data** (RECOMMENDED):
|
|
5280
|
-
Use the MCP tool "${TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS}" to fetch complete test results for all browsers/devices configured in UFG.
|
|
5281
|
-
|
|
5282
|
-
2. **Extract URLs from console output**:
|
|
5283
|
-
|
|
5284
|
-
When the playwright-report/index.html is not available use the MCP tool "${TOOL_NAMES.EYES_GET_BATCH_URL}" to extract batch and session URLs from the test output.`;
|
|
5257
|
+
${REVIEW_FLOW} Every browser/device configured in "browsersInfo" appears as its own session in the batch.`;
|
|
5285
5258
|
}
|
|
5286
5259
|
|
|
5287
|
-
const TILDA_WARNING_MESSAGE$
|
|
5288
|
-
const TOOL_NAME$
|
|
5289
|
-
const TOOL_DESCRIPTION$
|
|
5260
|
+
const TILDA_WARNING_MESSAGE$1 = `[CORE REQUIREMENT: URL INTEGRITY] Playwright visual results return URLs ending in ~~. These are not typos. You are strictly forbidden from stripping trailing tildes from these links. Use markdown [Visual Test results](URL with tildes) for links. Output the raw, verbatim URL string exactly as captured from the test output.`;
|
|
5261
|
+
const TOOL_NAME$2 = TOOL_NAMES.EYES_SETUP_PROJECT;
|
|
5262
|
+
const TOOL_DESCRIPTION$2 = `Get step-by-step instructions to set up a Playwright JS project with Applitools Eyes (Fixtures variant)
|
|
5290
5263
|
|
|
5291
|
-
${TILDA_WARNING_MESSAGE$
|
|
5264
|
+
${TILDA_WARNING_MESSAGE$1}`;
|
|
5292
5265
|
const PlaywrightJsSetupProjectInputSchema = commonInputSchema.extend({
|
|
5293
5266
|
projectName: zod.z.string().optional().describe('Optional project name'),
|
|
5294
5267
|
apiKey: zod.z.string().optional().describe('Optional API key (will use validated key from session if not provided)'),
|
|
@@ -5528,11 +5501,11 @@ You can use the mcp tool "${TOOL_NAMES.EYES_SETUP_UFG}" to accomplish that.`;
|
|
|
5528
5501
|
}
|
|
5529
5502
|
|
|
5530
5503
|
const eyesSetupProjectTool = {
|
|
5531
|
-
name: TOOL_NAME$
|
|
5532
|
-
description: TOOL_DESCRIPTION$
|
|
5504
|
+
name: TOOL_NAME$2,
|
|
5505
|
+
description: TOOL_DESCRIPTION$2,
|
|
5533
5506
|
inputSchema: PlaywrightJsSetupProjectClientInputSchema,
|
|
5534
5507
|
handler: createToolHandler({
|
|
5535
|
-
name: TOOL_NAME$
|
|
5508
|
+
name: TOOL_NAME$2,
|
|
5536
5509
|
input: PlaywrightJsSetupProjectInputSchema,
|
|
5537
5510
|
}, async (params) => {
|
|
5538
5511
|
const result = await eyesSetupProject(params);
|
|
@@ -5547,11 +5520,11 @@ const eyesSetupProjectTool = {
|
|
|
5547
5520
|
}),
|
|
5548
5521
|
};
|
|
5549
5522
|
|
|
5550
|
-
const TILDA_WARNING_MESSAGE
|
|
5551
|
-
const TOOL_NAME$
|
|
5552
|
-
const TOOL_DESCRIPTION$
|
|
5523
|
+
const TILDA_WARNING_MESSAGE = `[CORE REQUIREMENT: URL INTEGRITY] Playwright visual results return URLs ending in ~~. These are not typos. You are strictly forbidden from stripping trailing tildes from these links. Use markdown [Visual Test results](URL with tildes) for links. Output the raw, verbatim URL string exactly as captured from the test output.`;
|
|
5524
|
+
const TOOL_NAME$1 = TOOL_NAMES.EYES_SETUP_UFG;
|
|
5525
|
+
const TOOL_DESCRIPTION$1 = `Configure Ultrafast Grid (UFG) for cross-browser and cross-device testing
|
|
5553
5526
|
|
|
5554
|
-
${TILDA_WARNING_MESSAGE
|
|
5527
|
+
${TILDA_WARNING_MESSAGE}`;
|
|
5555
5528
|
const PlaywrightJsSetupUfgInputSchema = commonInputSchema.extend({
|
|
5556
5529
|
playwrightConfigPath: zod.z
|
|
5557
5530
|
.string()
|
|
@@ -5623,11 +5596,11 @@ ${viewingResultsSection('ufg')}`;
|
|
|
5623
5596
|
}
|
|
5624
5597
|
|
|
5625
5598
|
const eyesSetupUfgTool = {
|
|
5626
|
-
name: TOOL_NAME$
|
|
5627
|
-
description: TOOL_DESCRIPTION$
|
|
5599
|
+
name: TOOL_NAME$1,
|
|
5600
|
+
description: TOOL_DESCRIPTION$1,
|
|
5628
5601
|
inputSchema: PlaywrightJsSetupUfgClientInputSchema,
|
|
5629
5602
|
handler: createToolHandler({
|
|
5630
|
-
name: TOOL_NAME$
|
|
5603
|
+
name: TOOL_NAME$1,
|
|
5631
5604
|
input: PlaywrightJsSetupUfgInputSchema,
|
|
5632
5605
|
}, async (params) => {
|
|
5633
5606
|
const result = await eyesSetupUfg(params);
|
|
@@ -5642,8 +5615,8 @@ const eyesSetupUfgTool = {
|
|
|
5642
5615
|
}),
|
|
5643
5616
|
};
|
|
5644
5617
|
|
|
5645
|
-
const TOOL_NAME
|
|
5646
|
-
const TOOL_DESCRIPTION
|
|
5618
|
+
const TOOL_NAME = TOOL_NAMES.EYES_ADD_CHECKPOINTS;
|
|
5619
|
+
const TOOL_DESCRIPTION = 'Setup step: add eyes.check() visual checkpoints to an existing Playwright test file. Edits source, not results.';
|
|
5647
5620
|
const PlaywrightJsAddCheckpointsInputSchema = commonInputSchema.extend({
|
|
5648
5621
|
filePath: zod.z
|
|
5649
5622
|
.string()
|
|
@@ -5841,11 +5814,11 @@ You can use the MCP tool "${TOOL_NAMES.EYES_SETUP_UFG}" to setup the UFG for the
|
|
|
5841
5814
|
}
|
|
5842
5815
|
|
|
5843
5816
|
const eyesAddCheckpointsToTestTool = {
|
|
5844
|
-
name: TOOL_NAME
|
|
5845
|
-
description: TOOL_DESCRIPTION
|
|
5817
|
+
name: TOOL_NAME,
|
|
5818
|
+
description: TOOL_DESCRIPTION,
|
|
5846
5819
|
inputSchema: PlaywrightJsAddCheckpointsClientInputSchema,
|
|
5847
5820
|
handler: createToolHandler({
|
|
5848
|
-
name: TOOL_NAME
|
|
5821
|
+
name: TOOL_NAME,
|
|
5849
5822
|
input: PlaywrightJsAddCheckpointsInputSchema,
|
|
5850
5823
|
}, async (params) => {
|
|
5851
5824
|
const result = await eyesAddCheckpointsToTest(params);
|
|
@@ -5860,1019 +5833,24 @@ const eyesAddCheckpointsToTestTool = {
|
|
|
5860
5833
|
}),
|
|
5861
5834
|
};
|
|
5862
5835
|
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
Extract and convert Eyes test result URLs from console output. Parses the test execution output to find session URLs and converts them to batch URLs for viewing all test results together in the Eyes dashboard. This tool extracts URLs only - use ${TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS} to get detailed test status and results data.`;
|
|
5870
|
-
const GetBatchUrlFromOutputInputSchema = zod.z.object({
|
|
5871
|
-
testOutput: zod.z.string().describe('The console output from running the Playwright test'),
|
|
5872
|
-
workspaceRoot: zod.z.string().optional().describe('Workspace root directory (optional, defaults to current directory)'),
|
|
5873
|
-
});
|
|
5874
|
-
const BatchUrlToolResultSchema = zod.z.object({
|
|
5875
|
-
message: zod.z.string().describe('Human-readable summary of URL extraction results'),
|
|
5876
|
-
batchUrls: zod.z
|
|
5877
|
-
.array(zod.z.url())
|
|
5878
|
-
.nullable()
|
|
5879
|
-
.optional()
|
|
5880
|
-
.describe('Array of batch URLs for viewing all test results together in the Eyes dashboard. Null if no URLs found.'),
|
|
5881
|
-
sessionUrls: zod.z
|
|
5882
|
-
.array(zod.z.string({ message: 'CRITICAL: The Session URL with contains ~~ in the end that must be kept in the output' }))
|
|
5883
|
-
.nullable()
|
|
5884
|
-
.optional()
|
|
5885
|
-
.describe('Array of individual session URLs from test output (may end with ~~). Null if no URLs found.'),
|
|
5886
|
-
testResults: zod.z.any().optional().describe('Additional test result metadata if available'),
|
|
5887
|
-
});
|
|
5888
|
-
/**
|
|
5889
|
-
* Helper function to get batch URL for a given session
|
|
5890
|
-
* This would ideally use the Eyes API, but for now we provide a fallback
|
|
5891
|
-
*/
|
|
5892
|
-
async function getBatchUrlForSession(_sessionId, _accountId) {
|
|
5893
|
-
// For now, we'll construct a likely batch URL based on the session URL pattern
|
|
5894
|
-
// In a full implementation, you would query the Eyes API to get the actual batch ID
|
|
5895
|
-
// The batch URL typically follows this pattern:
|
|
5896
|
-
// https://eyes.applitools.com/app/batches/{batchId}?accountId={accountId}~~
|
|
5897
|
-
// However, we need the actual batch ID which requires an API call
|
|
5898
|
-
throw new Error('Batch URL extraction requires API access. Please use the Playwright HTML report or click the session URL and find the batch link in the dashboard.');
|
|
5899
|
-
}
|
|
5900
|
-
/**
|
|
5901
|
-
* Get batch URL from test console output
|
|
5902
|
-
* Extracts Eyes result URLs from test output and converts them to batch URLs
|
|
5903
|
-
*/
|
|
5904
|
-
async function getBatchUrlFromOutput(input) {
|
|
5905
|
-
const { testOutput } = input;
|
|
5906
|
-
// Extract all Eyes result URLs from the output
|
|
5907
|
-
// Pattern: https://eyes.applitools.com/app/test-results/{sessionId}?accountId={accountId}~~
|
|
5908
|
-
const urlPattern = /https:\/\/eyes\.applitools\.com\/app\/test-results\/(\d+)\?accountId=([^~\s]+)(~~)?/g;
|
|
5909
|
-
const matches = [...testOutput.matchAll(urlPattern)];
|
|
5910
|
-
if (matches.length === 0) {
|
|
5911
|
-
const result = {
|
|
5912
|
-
message: wrapText('No Eyes test result URLs found in the output. Make sure the test has completed and the Eyes reporter is configured correctly.', 'prefix'),
|
|
5913
|
-
batchUrls: null,
|
|
5914
|
-
sessionUrls: null,
|
|
5915
|
-
};
|
|
5916
|
-
return BatchUrlToolResultSchema.parse(result);
|
|
5917
|
-
}
|
|
5918
|
-
const sessionUrls = [];
|
|
5919
|
-
const sessionIds = [];
|
|
5920
|
-
const accountIds = [];
|
|
5921
|
-
matches.forEach(match => {
|
|
5922
|
-
const fullUrl = match[0];
|
|
5923
|
-
const sessionId = match[1];
|
|
5924
|
-
const accountId = match[2];
|
|
5925
|
-
sessionUrls.push(fullUrl);
|
|
5926
|
-
sessionIds.push(sessionId);
|
|
5927
|
-
accountIds.push(accountId);
|
|
5928
|
-
});
|
|
5929
|
-
// Get batch information from the first session
|
|
5930
|
-
// All sessions from the same test run should be in the same batch
|
|
5931
|
-
const firstSessionId = sessionIds[0];
|
|
5932
|
-
const firstAccountId = accountIds[0];
|
|
5933
|
-
try {
|
|
5934
|
-
// Try to get batch information from the Eyes API
|
|
5935
|
-
// This is a simplified approach - in production, you'd want to use the actual Eyes API
|
|
5936
|
-
const batchUrl = await getBatchUrlForSession(firstSessionId, firstAccountId);
|
|
5937
|
-
const message = wrapText(`Found ${sessionUrls.length} Eyes test result(s).\n\n` +
|
|
5938
|
-
`**Batch URL** (view all results together):\n[View Batch Results](${batchUrl})\n\n` +
|
|
5939
|
-
`**Individual Session URLs**:\n${sessionUrls
|
|
5940
|
-
.map((url, i) => `${i + 1}. [Session ${i + 1}](${url})`)
|
|
5941
|
-
.join('\n')}\n\n` +
|
|
5942
|
-
`🚨 **IMPORTANT**: Always use the Batch URL to view all test results together. ` +
|
|
5943
|
-
`The batch URL shows all visual checkpoints and tests in a single dashboard view.`, 'prefix');
|
|
5944
|
-
const result = {
|
|
5945
|
-
message,
|
|
5946
|
-
batchUrls: [batchUrl],
|
|
5947
|
-
sessionUrls,
|
|
5948
|
-
};
|
|
5949
|
-
return BatchUrlToolResultSchema.parse(result);
|
|
5950
|
-
}
|
|
5951
|
-
catch (error) {
|
|
5952
|
-
// If we can't get batch info, provide instructions on how to find it
|
|
5953
|
-
const message = wrapText(`Found ${sessionUrls.length} Eyes test result(s):\n\n` +
|
|
5954
|
-
`${sessionUrls.map((url, i) => `${i + 1}. [Session ${i + 1}](${url})`).join('\n')}\n\n` +
|
|
5955
|
-
`**Note**: These are individual session URLs. To view all results together:\n` +
|
|
5956
|
-
`1. Click any of the URLs above\n` +
|
|
5957
|
-
`2. Look for the "View Batch" or "Batch Results" link in the dashboard\n` +
|
|
5958
|
-
`3. Or use the Playwright HTML report by running: \`npx playwright show-report\`\n\n` +
|
|
5959
|
-
`Error getting batch URL: ${error instanceof Error ? error.message : String(error)}`, 'prefix');
|
|
5960
|
-
const result = {
|
|
5961
|
-
message,
|
|
5962
|
-
batchUrls: null,
|
|
5963
|
-
sessionUrls,
|
|
5964
|
-
};
|
|
5965
|
-
return BatchUrlToolResultSchema.parse(result);
|
|
5966
|
-
}
|
|
5967
|
-
}
|
|
5968
|
-
|
|
5969
|
-
/** Get Batch URL from Output Tool - MCP Tool Object Export */
|
|
5970
|
-
/** MCP Tool Object for get_batch_url */
|
|
5971
|
-
const getBatchUrlFromOutputTool = {
|
|
5972
|
-
name: TOOL_NAME$2,
|
|
5973
|
-
description: TOOL_DESCRIPTION$2,
|
|
5974
|
-
inputSchema: GetBatchUrlFromOutputInputSchema,
|
|
5975
|
-
outputSchema: BatchUrlToolResultSchema,
|
|
5976
|
-
handler: createToolHandler({
|
|
5977
|
-
name: TOOL_NAME$2,
|
|
5978
|
-
input: GetBatchUrlFromOutputInputSchema,
|
|
5979
|
-
output: BatchUrlToolResultSchema,
|
|
5980
|
-
}, async (params) => {
|
|
5981
|
-
const result = await getBatchUrlFromOutput(params);
|
|
5982
|
-
return {
|
|
5983
|
-
content: [
|
|
5984
|
-
{
|
|
5985
|
-
type: 'text',
|
|
5986
|
-
text: result.message,
|
|
5987
|
-
},
|
|
5988
|
-
],
|
|
5989
|
-
structuredContent: result,
|
|
5990
|
-
};
|
|
5991
|
-
}),
|
|
5836
|
+
const ALL_TOOLS = {
|
|
5837
|
+
verifyApiKey: verifyApiKeyTool,
|
|
5838
|
+
eyesSetupProject: eyesSetupProjectTool,
|
|
5839
|
+
eyesSetupUfg: eyesSetupUfgTool,
|
|
5840
|
+
eyesAddCheckpointsToTest: eyesAddCheckpointsToTestTool,
|
|
5992
5841
|
};
|
|
5993
5842
|
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
// correctly skipping braces that appear inside JSON string values.
|
|
6004
|
-
// Note: do NOT bound by </script> — that tag can appear verbatim inside a
|
|
6005
|
-
// JSON string value (e.g. a test named "close</script>tag"), which would
|
|
6006
|
-
// truncate the slice mid-JSON and cause a spurious parse error.
|
|
6007
|
-
// The brace walker terminates as soon as depth returns to 0.
|
|
6008
|
-
const bounded = reportHtml.slice(startIndex);
|
|
6009
|
-
let depth = 0;
|
|
6010
|
-
let inStr = false;
|
|
6011
|
-
let esc = false;
|
|
6012
|
-
let endIdx = -1;
|
|
6013
|
-
for (let i = 0; i < bounded.length; i++) {
|
|
6014
|
-
const c = bounded[i];
|
|
6015
|
-
if (esc) {
|
|
6016
|
-
esc = false;
|
|
6017
|
-
continue;
|
|
6018
|
-
}
|
|
6019
|
-
if (c === '\\' && inStr) {
|
|
6020
|
-
esc = true;
|
|
6021
|
-
continue;
|
|
6022
|
-
}
|
|
6023
|
-
if (c === '"') {
|
|
6024
|
-
inStr = !inStr;
|
|
6025
|
-
continue;
|
|
6026
|
-
}
|
|
6027
|
-
if (!inStr) {
|
|
6028
|
-
if (c === '{')
|
|
6029
|
-
depth++;
|
|
6030
|
-
else if (c === '}' && --depth === 0) {
|
|
6031
|
-
endIdx = i;
|
|
6032
|
-
break;
|
|
6033
|
-
}
|
|
6034
|
-
}
|
|
6035
|
-
}
|
|
6036
|
-
if (endIdx === -1) {
|
|
6037
|
-
throw new Error('Malformed JSON: unmatched braces');
|
|
6038
|
-
}
|
|
6039
|
-
try {
|
|
6040
|
-
return JSON.parse(bounded.slice(0, endIdx + 1));
|
|
6041
|
-
}
|
|
6042
|
-
catch {
|
|
6043
|
-
throw new Error('Malformed JSON: invalid structure in test results map');
|
|
6044
|
-
}
|
|
6045
|
-
}
|
|
6046
|
-
|
|
6047
|
-
function fixEyesUrl(url) {
|
|
6048
|
-
return url.replace(/eyesapi\./gi, 'eyes.');
|
|
6049
|
-
}
|
|
6050
|
-
function ensureTrailingSlash(url) {
|
|
6051
|
-
return url.endsWith('/') ? url : `${url}/`;
|
|
6052
|
-
}
|
|
6053
|
-
/**
|
|
6054
|
-
* The reusable tool-description fragment that warns the LLM not to strip the
|
|
6055
|
-
* trailing `~~` from server-emitted session/batch URLs. The tildes are base64
|
|
6056
|
-
* padding inside the accountId value itself (`=` encoded as `~`), so stripping
|
|
6057
|
-
* them corrupts the account ID and the server rejects the request.
|
|
6058
|
-
*/
|
|
6059
|
-
const TILDA_URL_WARNING = '[CORE REQUIREMENT: URL INTEGRITY] Visual-results URLs returned by Eyes end with `~~`. ' +
|
|
6060
|
-
'These tildes are part of the account ID token, not typos. You are strictly forbidden from stripping ' +
|
|
6061
|
-
'trailing tildes from these links. Render them with markdown ' +
|
|
6062
|
-
'`[Visual Test results](URL with tildes)` and output the raw, verbatim URL.';
|
|
6063
|
-
/**
|
|
6064
|
-
* Build the canonical Eyes dashboard URL for a single test session.
|
|
6065
|
-
*
|
|
6066
|
-
* Output shape: `{serverUrl}/app/test-results/{batchId}/{sessionId}[?accountId={accountId}]`
|
|
6067
|
-
*
|
|
6068
|
-
* Nothing is appended after the accountId: any `~~` in the final URL is base64
|
|
6069
|
-
* padding inside the accountId value, which arrives complete from the server.
|
|
6070
|
-
*
|
|
6071
|
-
* `accountId` is optional because not every caller has one to hand (the
|
|
6072
|
-
* batch-results-API flow authenticates by API key alone); pass it whenever
|
|
6073
|
-
* the URL was itself derived from a parsed accountId, so review round-trips
|
|
6074
|
-
* stay tied to the account they came from.
|
|
6075
|
-
*/
|
|
6076
|
-
function buildSessionUrl$1(serverUrl, batchId, sessionId, accountId) {
|
|
6077
|
-
const accountIdQuery = accountId ? `?accountId=${accountId}` : '';
|
|
6078
|
-
return `${serverUrl}/app/test-results/${batchId}/${sessionId}${accountIdQuery}`;
|
|
6079
|
-
}
|
|
6080
|
-
/**
|
|
6081
|
-
* Build the canonical Eyes dashboard URL for a whole batch.
|
|
6082
|
-
*
|
|
6083
|
-
* Output shape: `{serverUrl}/app/test-results/{batchId}[/?accountId={accountId}]`
|
|
6084
|
-
*/
|
|
6085
|
-
function buildBatchUrl$1(serverUrl, batchId, accountId) {
|
|
6086
|
-
return accountId
|
|
6087
|
-
? `${serverUrl}/app/test-results/${batchId}/?accountId=${accountId}`
|
|
6088
|
-
: `${serverUrl}/app/test-results/${batchId}`;
|
|
6089
|
-
}
|
|
6090
|
-
|
|
6091
|
-
/**
|
|
6092
|
-
* Canonical visual-test status set, shared by every part of the MCP package
|
|
6093
|
-
* that produces or consumes a per-test status string.
|
|
6094
|
-
*
|
|
6095
|
-
* Single source of truth for:
|
|
6096
|
-
* - the Zod enum on `VisualTestResultSchema.status`
|
|
6097
|
-
* ([[../dtos/visual-results-result.ts]])
|
|
6098
|
-
* - the runtime `normalizeStatus()` helper used by `eyes_analyze_batch`
|
|
6099
|
-
* ([[../tools/eyes-analyze-batch/tool.ts]]) to coerce arbitrary BE
|
|
6100
|
-
* strings into the canonical set
|
|
6101
|
-
* - the `STATUS_PRIORITY` ordering used by `eyes_fetch_visual_results`
|
|
6102
|
-
* ([[../tools/eyes-fetch-visual-results/batch-processor.ts]]) when it
|
|
6103
|
-
* reconciles per-step results into a single test status
|
|
6104
|
-
* - the per-status counters in `buildVisualResultsResult`
|
|
6105
|
-
* ([[../utils/build-visual-results-result.ts]])
|
|
6106
|
-
*
|
|
6107
|
-
* Adding a new status: append it to {@link CANONICAL_STATUSES} and the rest
|
|
6108
|
-
* of the package picks it up automatically.
|
|
6109
|
-
*/
|
|
6110
|
-
/**
|
|
6111
|
-
* Tuple of every status the MCP tools may return on a per-test basis. Keep
|
|
6112
|
-
* this as a `readonly` tuple (not a plain array) so we can derive both the
|
|
6113
|
-
* Zod enum and the TypeScript union without re-declaring the values.
|
|
6114
|
-
*/
|
|
6115
|
-
const CANONICAL_STATUSES = ['passed', 'failed', 'unresolved', 'new', 'aborted', 'running', 'empty'];
|
|
6116
|
-
/** Set form of {@link CANONICAL_STATUSES} for O(1) membership checks. */
|
|
6117
|
-
const CANONICAL_STATUS_SET = new Set(CANONICAL_STATUSES);
|
|
6118
|
-
/**
|
|
6119
|
-
* Reconciliation order for `determineStatus()` in
|
|
6120
|
-
* [[../tools/eyes-fetch-visual-results/batch-processor.ts]] — the lowest
|
|
6121
|
-
* index wins when multiple statuses are observed for the same test across
|
|
6122
|
-
* retries / chunks.
|
|
6123
|
-
*
|
|
6124
|
-
* Aborted / empty / new are decided by boolean flags before this list is
|
|
6125
|
-
* consulted, so they don't appear here.
|
|
6126
|
-
*/
|
|
6127
|
-
const STATUS_PRIORITY = [
|
|
6128
|
-
'running',
|
|
6129
|
-
'passed',
|
|
6130
|
-
'failed',
|
|
6131
|
-
'unresolved',
|
|
6132
|
-
];
|
|
6133
|
-
/** Default fallback when an unrecognised status string arrives from the BE. */
|
|
6134
|
-
const DEFAULT_UNKNOWN_STATUS = 'unresolved';
|
|
6135
|
-
/**
|
|
6136
|
-
* Coerce an arbitrary status string from the Eyes BE into the canonical set
|
|
6137
|
-
* the MCP tools expose on the wire. Case-insensitive; unknown values fall
|
|
6138
|
-
* back to {@link DEFAULT_UNKNOWN_STATUS} so the schema parse never throws on
|
|
6139
|
-
* unexpected BE input (forward-compatible with new server-side states).
|
|
6140
|
-
*/
|
|
6141
|
-
function normalizeStatus(status) {
|
|
6142
|
-
const lower = status.toLowerCase();
|
|
6143
|
-
return CANONICAL_STATUS_SET.has(lower) ? lower : DEFAULT_UNKNOWN_STATUS;
|
|
6144
|
-
}
|
|
6145
|
-
|
|
6146
|
-
function filterToLastRetry(eyesResults) {
|
|
6147
|
-
if (eyesResults.length === 0) {
|
|
6148
|
-
return [];
|
|
6149
|
-
}
|
|
6150
|
-
const maxRetry = Math.max(...eyesResults.map(r => { var _a; return (_a = r.playwrightRetry) !== null && _a !== void 0 ? _a : 0; }));
|
|
6151
|
-
return eyesResults.filter(r => { var _a; return ((_a = r.playwrightRetry) !== null && _a !== void 0 ? _a : 0) === maxRetry; });
|
|
6152
|
-
}
|
|
6153
|
-
function determineStatus(result) {
|
|
6154
|
-
if (result.isAborted)
|
|
6155
|
-
return 'aborted';
|
|
6156
|
-
if (result.steps === 0)
|
|
6157
|
-
return 'empty';
|
|
6158
|
-
const status = result.status.toLowerCase();
|
|
6159
|
-
if (result.isNew && status !== 'running')
|
|
6160
|
-
return 'new';
|
|
6161
|
-
if (STATUS_PRIORITY.includes(status))
|
|
6162
|
-
return status;
|
|
6163
|
-
return 'unresolved';
|
|
6164
|
-
}
|
|
6165
|
-
async function fetchBatchStatus(batchId, batchData) {
|
|
6166
|
-
const chunkSize = 300;
|
|
6167
|
-
const chunks = [];
|
|
6168
|
-
for (let i = 0; i < batchData.sessions.length; i += chunkSize) {
|
|
6169
|
-
chunks.push(batchData.sessions.slice(i, i + chunkSize));
|
|
6170
|
-
}
|
|
6171
|
-
const baseUrl = ensureTrailingSlash(fixEyesUrl(batchData.eyesServerUrl));
|
|
6172
|
-
const apiClient = new ApiClient({
|
|
6173
|
-
baseUrl: baseUrl.replace(/\/$/, ''),
|
|
6174
|
-
apiKey: batchData.apiKey,
|
|
6175
|
-
timeout: 30000,
|
|
6176
|
-
});
|
|
6177
|
-
try {
|
|
6178
|
-
const results = await Promise.all(chunks.map(async (chunk) => {
|
|
6179
|
-
try {
|
|
6180
|
-
const response = await apiClient.post(`api/sessions/batches/${batchId}/sessions/sdkquery`, { sessions: chunk });
|
|
6181
|
-
return response;
|
|
6182
|
-
}
|
|
6183
|
-
catch {
|
|
6184
|
-
return { sessions: [], errors: [] };
|
|
6185
|
-
}
|
|
6186
|
-
}));
|
|
6187
|
-
return {
|
|
6188
|
-
sessions: results.map(result => result.sessions).flat(),
|
|
6189
|
-
errors: results.map(result => result.errors).flat(),
|
|
6190
|
-
};
|
|
6191
|
-
}
|
|
6192
|
-
catch {
|
|
6193
|
-
return { sessions: [], errors: [] };
|
|
6194
|
-
}
|
|
6195
|
-
}
|
|
6196
|
-
async function processBatches(testResultsData, fallbackApiKey) {
|
|
6197
|
-
const sessionsByBatchId = new Map();
|
|
6198
|
-
const eyesResultsByBatch = new Map();
|
|
6199
|
-
Object.values(testResultsData).forEach(results => {
|
|
6200
|
-
if (Array.isArray(results)) {
|
|
6201
|
-
const lastRetryResults = filterToLastRetry(results);
|
|
6202
|
-
lastRetryResults.forEach(result => {
|
|
6203
|
-
const batchId = result.batchId;
|
|
6204
|
-
if (!eyesResultsByBatch.has(batchId)) {
|
|
6205
|
-
eyesResultsByBatch.set(batchId, []);
|
|
6206
|
-
}
|
|
6207
|
-
eyesResultsByBatch.get(batchId).push(result);
|
|
6208
|
-
if (!sessionsByBatchId.has(batchId)) {
|
|
6209
|
-
sessionsByBatchId.set(batchId, {
|
|
6210
|
-
batchName: result.batchName,
|
|
6211
|
-
batchUrl: result.appUrls.batch,
|
|
6212
|
-
sessions: [],
|
|
6213
|
-
apiKey: result.eyesServer.apiKey,
|
|
6214
|
-
eyesServerUrl: result.eyesServer.eyesServerUrl,
|
|
6215
|
-
});
|
|
6216
|
-
}
|
|
6217
|
-
const batchData = sessionsByBatchId.get(batchId);
|
|
6218
|
-
batchData.sessions.push({
|
|
6219
|
-
id: result.id,
|
|
6220
|
-
accessToken: result.secretToken,
|
|
6221
|
-
});
|
|
6222
|
-
});
|
|
6223
|
-
}
|
|
6224
|
-
});
|
|
6225
|
-
if (sessionsByBatchId.size === 0) {
|
|
6226
|
-
return [];
|
|
6227
|
-
}
|
|
6228
|
-
const batchStatusPromises = Array.from(sessionsByBatchId.entries()).map(async ([batchId, batchData]) => {
|
|
6229
|
-
const effectiveApiKey = batchData.apiKey || fallbackApiKey;
|
|
6230
|
-
const effectiveBatchData = effectiveApiKey ? { ...batchData, apiKey: effectiveApiKey } : batchData;
|
|
6231
|
-
const serverResponse = await fetchBatchStatus(batchId, effectiveBatchData);
|
|
6232
|
-
return { batchId, serverResponse };
|
|
6233
|
-
});
|
|
6234
|
-
const batchStatuses = await Promise.all(batchStatusPromises);
|
|
6235
|
-
const statusBySessionId = new Map();
|
|
6236
|
-
batchStatuses.forEach(({ serverResponse }) => {
|
|
6237
|
-
serverResponse.sessions.forEach(session => {
|
|
6238
|
-
statusBySessionId.set(session.id, session);
|
|
6239
|
-
});
|
|
6240
|
-
});
|
|
6241
|
-
const processedBatches = [];
|
|
6242
|
-
eyesResultsByBatch.forEach((eyesResults, batchId) => {
|
|
6243
|
-
const batchData = sessionsByBatchId.get(batchId);
|
|
6244
|
-
const tests = [];
|
|
6245
|
-
eyesResults.forEach(result => {
|
|
6246
|
-
var _a;
|
|
6247
|
-
const serverStatus = statusBySessionId.get(result.id);
|
|
6248
|
-
if (serverStatus) {
|
|
6249
|
-
result.status = serverStatus.status;
|
|
6250
|
-
result.isDifferent = serverStatus.isDifferent;
|
|
6251
|
-
result.isNew = serverStatus.isNew;
|
|
6252
|
-
result.isAborted = serverStatus.isAborted;
|
|
6253
|
-
}
|
|
6254
|
-
const finalStatus = determineStatus(result);
|
|
6255
|
-
// Extract diff descriptions from actualAppOutput
|
|
6256
|
-
const stepDiffs = [];
|
|
6257
|
-
if (serverStatus === null || serverStatus === void 0 ? void 0 : serverStatus.actualAppOutput) {
|
|
6258
|
-
serverStatus.actualAppOutput.forEach((output, index) => {
|
|
6259
|
-
if (output.diffDescriptions && output.diffDescriptions.length > 0) {
|
|
6260
|
-
stepDiffs.push({
|
|
6261
|
-
stepIndex: index,
|
|
6262
|
-
stepName: output.tag || `Step ${index + 1}`,
|
|
6263
|
-
diffDescriptions: output.diffDescriptions,
|
|
6264
|
-
});
|
|
6265
|
-
}
|
|
6266
|
-
});
|
|
6267
|
-
}
|
|
6268
|
-
tests.push({
|
|
6269
|
-
testName: result.name,
|
|
6270
|
-
batchName: result.batchName,
|
|
6271
|
-
status: finalStatus,
|
|
6272
|
-
sessionUrl: result.appUrls.session,
|
|
6273
|
-
steps: result.steps,
|
|
6274
|
-
retryAttempt: (_a = result.playwrightRetry) !== null && _a !== void 0 ? _a : 0,
|
|
6275
|
-
browser: result.hostApp,
|
|
6276
|
-
...(stepDiffs.length > 0 ? { stepDiffs } : {}),
|
|
6277
|
-
});
|
|
6278
|
-
});
|
|
6279
|
-
processedBatches.push({
|
|
6280
|
-
batchId,
|
|
6281
|
-
batchName: batchData.batchName,
|
|
6282
|
-
batchUrl: batchData.batchUrl,
|
|
6283
|
-
tests,
|
|
6284
|
-
});
|
|
6285
|
-
});
|
|
6286
|
-
return processedBatches;
|
|
6287
|
-
}
|
|
6288
|
-
|
|
6289
|
-
/**
|
|
6290
|
-
* Tool-agnostic builder that turns an array of `ProcessedBatch` into the
|
|
6291
|
-
* `VisualResultsToolResult` shape (message + structured results + summary).
|
|
6292
|
-
*
|
|
6293
|
-
* Used by both `eyes_fetch_visual_results` and `eyes_analyze_batch` so they
|
|
6294
|
-
* produce identical output structures from different upstream sources.
|
|
6295
|
-
*/
|
|
6296
|
-
function calculateSummary(batches) {
|
|
6297
|
-
let totalTests = 0;
|
|
6298
|
-
let passed = 0;
|
|
6299
|
-
let failed = 0;
|
|
6300
|
-
let unresolved = 0;
|
|
6301
|
-
let newTests = 0;
|
|
6302
|
-
let aborted = 0;
|
|
6303
|
-
batches.forEach(batch => {
|
|
6304
|
-
batch.tests.forEach(test => {
|
|
6305
|
-
totalTests++;
|
|
6306
|
-
if (test.status === 'passed')
|
|
6307
|
-
passed++;
|
|
6308
|
-
else if (test.status === 'failed')
|
|
6309
|
-
failed++;
|
|
6310
|
-
else if (test.status === 'unresolved')
|
|
6311
|
-
unresolved++;
|
|
6312
|
-
else if (test.status === 'new')
|
|
6313
|
-
newTests++;
|
|
6314
|
-
else if (test.status === 'aborted')
|
|
6315
|
-
aborted++;
|
|
6316
|
-
});
|
|
6317
|
-
});
|
|
6318
|
-
return {
|
|
6319
|
-
totalBatches: batches.length,
|
|
6320
|
-
totalTests,
|
|
6321
|
-
passed,
|
|
6322
|
-
failed,
|
|
6323
|
-
unresolved,
|
|
6324
|
-
new: newTests,
|
|
6325
|
-
aborted,
|
|
6326
|
-
};
|
|
6327
|
-
}
|
|
6328
|
-
// Textual diff descriptions are temporarily disabled because they interfere
|
|
6329
|
-
// with the eyes-inspect skill. Re-enable by restoring the original body of
|
|
6330
|
-
// this function and the stepDiffs propagation in buildVisualResultsResult.
|
|
6331
|
-
function formatDiffDescriptions(_test) {
|
|
6332
|
-
return '';
|
|
6333
|
-
}
|
|
6334
|
-
function formatMessage(batches, summary) {
|
|
6335
|
-
return wrapText(`✅ Fetched visual test results from ${batches.length} batch(es):\n\n` +
|
|
6336
|
-
`**Summary:**\n` +
|
|
6337
|
-
`- Total Tests: ${summary.totalTests}\n` +
|
|
6338
|
-
`- Passed: ${summary.passed}\n` +
|
|
6339
|
-
`- Failed: ${summary.failed}\n` +
|
|
6340
|
-
`- Unresolved: ${summary.unresolved}\n` +
|
|
6341
|
-
`- New: ${summary.new}\n` +
|
|
6342
|
-
`- Aborted: ${summary.aborted}\n\n` +
|
|
6343
|
-
batches
|
|
6344
|
-
.map((batch, i) => {
|
|
6345
|
-
const testsWithDiffs = batch.tests.filter(t => t.stepDiffs && t.stepDiffs.length > 0);
|
|
6346
|
-
const testLines = testsWithDiffs
|
|
6347
|
-
.map(t => ` - **${t.testName}** (${t.browser}) — ${t.status}${formatDiffDescriptions()}`)
|
|
6348
|
-
.join('\n');
|
|
6349
|
-
return (`**Batch ${i + 1}: ${batch.batchName}**\n` +
|
|
6350
|
-
`- [View Batch](${batch.batchUrl})\n` +
|
|
6351
|
-
`- Tests: ${batch.tests.length}\n` +
|
|
6352
|
-
(testLines ? `- Tests with visual differences:\n${testLines}\n` : ''));
|
|
6353
|
-
})
|
|
6354
|
-
.join('\n'), 'prefix');
|
|
6355
|
-
}
|
|
6356
|
-
function buildVisualResultsResult(batches) {
|
|
6357
|
-
const summary = calculateSummary(batches);
|
|
6358
|
-
const results = batches.map(batch => ({
|
|
6359
|
-
batchId: batch.batchId,
|
|
6360
|
-
batchName: batch.batchName,
|
|
6361
|
-
batchUrl: batch.batchUrl,
|
|
6362
|
-
tests: batch.tests.map(test => ({
|
|
6363
|
-
testName: test.testName,
|
|
6364
|
-
batchName: test.batchName,
|
|
6365
|
-
status: test.status,
|
|
6366
|
-
sessionUrl: test.sessionUrl,
|
|
6367
|
-
steps: test.steps,
|
|
6368
|
-
retryAttempt: test.retryAttempt,
|
|
6369
|
-
browser: test.browser,
|
|
6370
|
-
// stepDiffs intentionally omitted while textual diff descriptions are disabled
|
|
6371
|
-
})),
|
|
6372
|
-
}));
|
|
6373
|
-
const message = formatMessage(results, summary);
|
|
6374
|
-
return {
|
|
6375
|
-
message,
|
|
6376
|
-
results,
|
|
6377
|
-
summary: {
|
|
6378
|
-
totalBatches: summary.totalBatches,
|
|
6379
|
-
totalTests: summary.totalTests,
|
|
6380
|
-
passed: summary.passed,
|
|
6381
|
-
failed: summary.failed,
|
|
6382
|
-
unresolved: summary.unresolved,
|
|
6383
|
-
new: summary.new,
|
|
6384
|
-
aborted: summary.aborted,
|
|
6385
|
-
},
|
|
5843
|
+
const workspaceRootSchema = zod.z
|
|
5844
|
+
.string()
|
|
5845
|
+
.optional()
|
|
5846
|
+
.describe("Root directory of the caller's project (optional; used to locate its .env credentials)");
|
|
5847
|
+
function instrumentedRegistrar(server) {
|
|
5848
|
+
const registerTool = (name, config, handler) => {
|
|
5849
|
+
const inputSchema = { workspaceRoot: workspaceRootSchema, ...config.inputSchema };
|
|
5850
|
+
const wrapped = createToolHandler({ name, input: zod.z.object(inputSchema) }, async (params) => handler(params).then(result => result));
|
|
5851
|
+
return server.registerTool(name, { ...config, inputSchema }, wrapped);
|
|
6386
5852
|
};
|
|
6387
|
-
}
|
|
6388
|
-
|
|
6389
|
-
/**
|
|
6390
|
-
* Shared Zod schemas describing the "visual results" tool output shape.
|
|
6391
|
-
*
|
|
6392
|
-
* Both `eyes_fetch_visual_results` (Playwright report flow) and
|
|
6393
|
-
* `eyes_analyze_batch` (paste-batch-URL flow) return data in this shape, so
|
|
6394
|
-
* the schemas live here rather than inside either tool. Each tool re-exports
|
|
6395
|
-
* them under tool-specific aliases for stable public names.
|
|
6396
|
-
*/
|
|
6397
|
-
const DiffDescriptionSchema = zod.z.object({
|
|
6398
|
-
baselineValue: zod.z.string().describe('Original value from the baseline snapshot'),
|
|
6399
|
-
checkpointValue: zod.z.string().describe('New value from the checkpoint snapshot'),
|
|
6400
|
-
category: zod.z
|
|
6401
|
-
.string()
|
|
6402
|
-
.describe('Diff category code emitted by the Eyes BE. Canonical set: ' +
|
|
6403
|
-
'"ContentTextShort" (text changed ≤10 words), ' +
|
|
6404
|
-
'"ContentTextLong" (text changed >10 words), ' +
|
|
6405
|
-
'"FontColor" (font foreground color), ' +
|
|
6406
|
-
'"FontSize" (font size), ' +
|
|
6407
|
-
'"FontFamily" (font family), ' +
|
|
6408
|
-
'"FontStyle" (bold / italic / underline), ' +
|
|
6409
|
-
'"BackgroundColor" (element background color), ' +
|
|
6410
|
-
'"BorderStyle" (border style / color / width), ' +
|
|
6411
|
-
'"GraphicChanged" (image / icon / SVG content). ' +
|
|
6412
|
-
'New BE-side categories are passed through verbatim.'),
|
|
6413
|
-
});
|
|
6414
|
-
const StepDiffSchema = zod.z.object({
|
|
6415
|
-
stepIndex: zod.z.number().describe('Zero-based index of the step within the test'),
|
|
6416
|
-
stepName: zod.z.string().describe('Name/label of the visual checkpoint'),
|
|
6417
|
-
diffDescriptions: zod.z
|
|
6418
|
-
.array(DiffDescriptionSchema)
|
|
6419
|
-
.describe('List of textual descriptions of visual differences detected in this step'),
|
|
6420
|
-
});
|
|
6421
|
-
const VisualTestResultSchema = zod.z.object({
|
|
6422
|
-
testName: zod.z.string().describe('Name of the visual test'),
|
|
6423
|
-
batchName: zod.z.string().describe('Name of the batch this test belongs to'),
|
|
6424
|
-
status: zod.z
|
|
6425
|
-
.enum(CANONICAL_STATUSES)
|
|
6426
|
-
.describe('Visual test status: "passed" - all checkpoints match baseline, ' +
|
|
6427
|
-
'"failed" - visual differences detected, ' +
|
|
6428
|
-
'"unresolved" - differences need review, ' +
|
|
6429
|
-
'"new" - first-time checkpoint with no baseline, ' +
|
|
6430
|
-
'"aborted" - test terminated prematurely, ' +
|
|
6431
|
-
'"running" - test still executing, ' +
|
|
6432
|
-
'"empty" - test completed with zero checkpoints.'),
|
|
6433
|
-
sessionUrl: zod.z
|
|
6434
|
-
.string()
|
|
6435
|
-
.describe('URL to the visual test results in the Eyes dashboard. Any trailing `~~` is base64 ' +
|
|
6436
|
-
'padding inside the accountId value — part of the account ID token, not typos. ' +
|
|
6437
|
-
'Do not strip it.'),
|
|
6438
|
-
steps: zod.z.number().describe('Number of visual checkpoints in this test'),
|
|
6439
|
-
retryAttempt: zod.z.number().describe('Retry attempt number (0 for first attempt)'),
|
|
6440
|
-
browser: zod.z.string().describe('Browser/device configuration this test ran on'),
|
|
6441
|
-
stepDiffs: zod.z
|
|
6442
|
-
.array(StepDiffSchema)
|
|
6443
|
-
.optional()
|
|
6444
|
-
.describe('Textual descriptions of visual differences for steps with diffs. Only present for tests where DOM-based diff analysis detected categorized differences.'),
|
|
6445
|
-
});
|
|
6446
|
-
const BatchResultSchema = zod.z.object({
|
|
6447
|
-
// batchId/batchUrl are intentionally part of the public response shape:
|
|
6448
|
-
// - `batchId` is the stable identifier the LLM/agent uses to correlate
|
|
6449
|
-
// this result with prior tool calls (e.g. the stale-report check in
|
|
6450
|
-
// `eyes_fetch_visual_results` reads `batchId` to verify expected vs
|
|
6451
|
-
// observed batches) and to disambiguate multiple batches in one run.
|
|
6452
|
-
// - `batchUrl` is rendered as a `[View Batch]` link in the human message
|
|
6453
|
-
// and is what the user clicks to open the dashboard.
|
|
6454
|
-
// Removing either would force every consumer to reconstruct the URL from
|
|
6455
|
-
// the server URL + ID, so they stay.
|
|
6456
|
-
batchId: zod.z
|
|
6457
|
-
.string()
|
|
6458
|
-
.describe('Stable batch identifier; used by clients to correlate, deduplicate, and detect stale reports.'),
|
|
6459
|
-
batchName: zod.z.string().describe('Human-readable batch label as shown in the Eyes dashboard.'),
|
|
6460
|
-
batchUrl: zod.z.string().describe('Full Eyes dashboard URL for this batch; rendered as a `[View Batch]` link.'),
|
|
6461
|
-
tests: zod.z.array(VisualTestResultSchema).describe('All visual tests within this batch'),
|
|
6462
|
-
});
|
|
6463
|
-
const VisualResultsToolResultSchema = zod.z.object({
|
|
6464
|
-
message: zod.z.string().describe('Human-readable summary of the visual test results'),
|
|
6465
|
-
results: zod.z.array(BatchResultSchema).optional().describe('Detailed results grouped by batch'),
|
|
6466
|
-
summary: zod.z
|
|
6467
|
-
.object({
|
|
6468
|
-
totalBatches: zod.z.number().describe('Total number of batches'),
|
|
6469
|
-
totalTests: zod.z.number().describe('Total number of visual tests across all batches'),
|
|
6470
|
-
passed: zod.z
|
|
6471
|
-
.number()
|
|
6472
|
-
.describe('Number of tests where all visual checkpoints matched the baseline (no differences detected)'),
|
|
6473
|
-
failed: zod.z.number().describe('Number of tests with visual differences that were marked as failures after review'),
|
|
6474
|
-
unresolved: zod.z
|
|
6475
|
-
.number()
|
|
6476
|
-
.describe('Number of tests with visual differences that require human review and acceptance/rejection'),
|
|
6477
|
-
new: zod.z
|
|
6478
|
-
.number()
|
|
6479
|
-
.describe('Number of tests running for the first time with no existing baseline to compare against'),
|
|
6480
|
-
aborted: zod.z.number().describe('Number of tests that were terminated prematurely before completion'),
|
|
6481
|
-
})
|
|
6482
|
-
.optional()
|
|
6483
|
-
.describe('Aggregated statistics summarizing test results across all batches. Counts tests by their visual comparison status.'),
|
|
6484
|
-
});
|
|
6485
|
-
|
|
6486
|
-
// Shared with `eyes_analyze_batch` so the wording (and the underlying URL
|
|
6487
|
-
// convention) stays in lock-step. See TILDA_URL_WARNING in url-utils.
|
|
6488
|
-
const TILDA_WARNING_MESSAGE = TILDA_URL_WARNING;
|
|
6489
|
-
const TOOL_NAME$1 = TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS;
|
|
6490
|
-
const TOOL_DESCRIPTION$1 = `Fetch current up-to-date visual test results from the Playwright HTML report and the Eyes server.
|
|
6491
|
-
|
|
6492
|
-
IMPORTANT:
|
|
6493
|
-
- This tool reads the Playwright HTML report directly from disk.
|
|
6494
|
-
- **Do NOT copy or move the report file.** Instead, always point this tool to the actual report location using the \`reportPath\` argument when it's not in the default location.
|
|
6495
|
-
- For standard Playwright runs, the default report is at \`playwright-report/index.html\` in the workspace root.
|
|
6496
|
-
- For the Eyes example (\`npx eyes-setup run-example\`), the report is generated at:
|
|
6497
|
-
\`<workspaceRoot>/eyes-examples/eyes-playwright-report/index.html\`
|
|
6498
|
-
In that case, call the tool with:
|
|
6499
|
-
- \`reportPath: "<workspaceRoot>/eyes-examples/eyes-playwright-report/index.html"\`
|
|
6500
|
-
- \`workspaceRoot: "<workspaceRoot>"\`
|
|
6501
|
-
|
|
6502
|
-
**CRITICAL: Do NOT run Playwright with \`--reporter=list\`, \`--reporter=dot\`, \`--reporter=line\`, or any other \`--reporter\` flag that overrides the configured reporters. Doing so suppresses the Eyes reporter, preventing it from writing results to the HTML report. This tool will then read a stale report from a previous run and return outdated results.**
|
|
6503
|
-
|
|
6504
|
-
Always run Playwright without reporter overrides, for example:
|
|
6505
|
-
- ✅ CORRECT: \`npx playwright test\`
|
|
6506
|
-
- ❌ INCORRECT: \`npx playwright test --reporter=list\`
|
|
6507
|
-
|
|
6508
|
-
**Stale report detection (optional):** If you know the batch IDs from the current Playwright run output, pass them via the \`expectedBatchIds\` parameter. This tool will warn you if those batch IDs are not found in the report, indicating the report may be from a previous run.
|
|
6509
|
-
|
|
6510
|
-
The tool returns structured test results that can be displayed in a table, including:
|
|
6511
|
-
- Test name
|
|
6512
|
-
- Visual test status (passed/failed/unresolved/new/aborted)
|
|
6513
|
-
- Retry attempt number
|
|
6514
|
-
- Browser/device configuration
|
|
6515
|
-
|
|
6516
|
-
${TILDA_WARNING_MESSAGE}`;
|
|
6517
|
-
const PlaywrightFetchVisualResultsInputSchema = commonInputSchema.extend({
|
|
6518
|
-
reportPath: zod.z
|
|
6519
|
-
.string()
|
|
6520
|
-
.optional()
|
|
6521
|
-
.describe('Path to the Playwright HTML report (optional, defaults to playwright-report/index.html)'),
|
|
6522
|
-
serverUrl: zod.z.string().optional().describe('Optional Applitools server URL (defaults to https://eyes.applitools.com)'),
|
|
6523
|
-
expectedBatchIds: zod.z
|
|
6524
|
-
.array(zod.z.string())
|
|
6525
|
-
.optional()
|
|
6526
|
-
.describe('Optional list of batch IDs extracted from the Playwright run output. When provided, the tool verifies these IDs appear in the report to confirm it is current and not stale from a previous run.'),
|
|
6527
|
-
});
|
|
6528
|
-
const PlaywrightFetchVisualResultsClientInputSchema = createClientInputSchema(PlaywrightFetchVisualResultsInputSchema);
|
|
6529
|
-
function buildStaleReportWarning(expectedBatchIds, processedBatches) {
|
|
6530
|
-
const reportBatchIds = new Set(processedBatches.map(b => b.batchId));
|
|
6531
|
-
const missingBatchIds = expectedBatchIds.filter(id => !reportBatchIds.has(id));
|
|
6532
|
-
if (missingBatchIds.length === 0)
|
|
6533
|
-
return '';
|
|
6534
|
-
return (`⚠️ STALE REPORT WARNING: The following batch IDs from the Playwright run were NOT found in the report: [${missingBatchIds.join(', ')}]. ` +
|
|
6535
|
-
`The report likely reflects a previous run, not the current one.\n` +
|
|
6536
|
-
`To fix this: re-run Playwright WITHOUT any --reporter flag overrides (e.g. npx playwright test), then call this tool again.\n\n`);
|
|
6537
|
-
}
|
|
6538
|
-
/**
|
|
6539
|
-
* Main tool function to fetch visual test results
|
|
6540
|
-
*/
|
|
6541
|
-
async function playwrightFetchVisualResults(input) {
|
|
6542
|
-
const { workspaceRoot, warning } = validateCommonInput(input);
|
|
6543
|
-
const reportPath = input.reportPath || path.join(workspaceRoot, 'playwright-report', 'index.html');
|
|
6544
|
-
try {
|
|
6545
|
-
// Step 1: Parse report file to extract test results
|
|
6546
|
-
let testResultsData;
|
|
6547
|
-
try {
|
|
6548
|
-
testResultsData = await parseReportFile(reportPath);
|
|
6549
|
-
}
|
|
6550
|
-
catch (parseError) {
|
|
6551
|
-
if (parseError instanceof Error && parseError.message.includes('No Eyes test results found')) {
|
|
6552
|
-
const result = {
|
|
6553
|
-
message: wrapText(`${warning}No Eyes test results found in the Playwright report.\n\n` +
|
|
6554
|
-
`Make sure:\n` +
|
|
6555
|
-
`1. The Eyes Playwright reporter is configured: ['@applitools/eyes-playwright/reporter']\n` +
|
|
6556
|
-
`2. Tests are using the Eyes fixture: import { test } from '@applitools/eyes-playwright/fixture'\n` +
|
|
6557
|
-
`3. Visual checkpoints are added: await eyes.check('label')`, 'prefix'),
|
|
6558
|
-
};
|
|
6559
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
6560
|
-
}
|
|
6561
|
-
throw parseError;
|
|
6562
|
-
}
|
|
6563
|
-
// Step 2: Get API key from session or config
|
|
6564
|
-
const apiKey = getLastValidatedApiKey() || loadCredentials(workspaceRoot).apiKey;
|
|
6565
|
-
// Step 3: Process batches (filter, group, fetch status, resolve)
|
|
6566
|
-
const processedBatches = await processBatches(testResultsData, apiKey);
|
|
6567
|
-
// Check if we have any results to process
|
|
6568
|
-
if (processedBatches.length === 0) {
|
|
6569
|
-
const result = {
|
|
6570
|
-
message: wrapText(`${warning}Found Eyes test results but no sessions to query.\n\n` +
|
|
6571
|
-
`This can happen if tests haven't completed yet.`, 'prefix'),
|
|
6572
|
-
};
|
|
6573
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
6574
|
-
}
|
|
6575
|
-
// Step 4: Build final response
|
|
6576
|
-
const result = buildVisualResultsResult(processedBatches);
|
|
6577
|
-
if (warning)
|
|
6578
|
-
result.message = warning + result.message;
|
|
6579
|
-
// Step 5: Optionally verify expected batch IDs to detect stale reports
|
|
6580
|
-
if (input.expectedBatchIds && input.expectedBatchIds.length > 0) {
|
|
6581
|
-
const staleWarning = buildStaleReportWarning(input.expectedBatchIds, processedBatches);
|
|
6582
|
-
if (staleWarning)
|
|
6583
|
-
result.message = staleWarning + result.message;
|
|
6584
|
-
}
|
|
6585
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
6586
|
-
}
|
|
6587
|
-
catch (error) {
|
|
6588
|
-
// Handle file read errors
|
|
6589
|
-
if (error instanceof Error && error.message.includes('ENOENT')) {
|
|
6590
|
-
const result = {
|
|
6591
|
-
message: wrapText(`${warning}Error reading Playwright report: ${error.message}\n\n` +
|
|
6592
|
-
`Make sure the report exists at: ${reportPath}`, 'prefix'),
|
|
6593
|
-
};
|
|
6594
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
6595
|
-
}
|
|
6596
|
-
// Handle parsing errors
|
|
6597
|
-
if (error instanceof Error && error.message.includes('Malformed JSON')) {
|
|
6598
|
-
const result = {
|
|
6599
|
-
message: wrapText(`${warning}Error parsing Eyes test results from report: ${error.message}`, 'prefix'),
|
|
6600
|
-
};
|
|
6601
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
6602
|
-
}
|
|
6603
|
-
// Generic error handling
|
|
6604
|
-
const result = {
|
|
6605
|
-
message: wrapText(`${warning}Error processing visual test results: ${error instanceof Error ? error.message : String(error)}`, 'prefix'),
|
|
6606
|
-
};
|
|
6607
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
6608
|
-
}
|
|
6609
|
-
}
|
|
6610
|
-
|
|
6611
|
-
const playwrightFetchVisualResultsTool = {
|
|
6612
|
-
name: TOOL_NAME$1,
|
|
6613
|
-
description: TOOL_DESCRIPTION$1,
|
|
6614
|
-
inputSchema: PlaywrightFetchVisualResultsClientInputSchema,
|
|
6615
|
-
outputSchema: VisualResultsToolResultSchema,
|
|
6616
|
-
handler: createToolHandler({
|
|
6617
|
-
name: TOOL_NAME$1,
|
|
6618
|
-
input: PlaywrightFetchVisualResultsInputSchema,
|
|
6619
|
-
output: VisualResultsToolResultSchema,
|
|
6620
|
-
}, async (params) => {
|
|
6621
|
-
const result = await playwrightFetchVisualResults(params);
|
|
6622
|
-
return {
|
|
6623
|
-
content: [
|
|
6624
|
-
{
|
|
6625
|
-
type: 'text',
|
|
6626
|
-
text: result.message,
|
|
6627
|
-
},
|
|
6628
|
-
],
|
|
6629
|
-
structuredContent: result,
|
|
6630
|
-
};
|
|
6631
|
-
}),
|
|
6632
|
-
};
|
|
6633
|
-
|
|
6634
|
-
/**
|
|
6635
|
-
* API client for the "Paste Batch URL" flow (AD-13206 Part 2).
|
|
6636
|
-
*
|
|
6637
|
-
* Uses two public v1 API endpoints:
|
|
6638
|
-
* 1. GET /api/v1/batches/{batchId}?steps=true — batch results with step-level diffs count
|
|
6639
|
-
* 2. GET /api/v1/batches/{batchId}/{sessionId}/{stepIndex}/diff — per-step diff descriptions
|
|
6640
|
-
*
|
|
6641
|
-
* Both authenticate with `X-Eyes-Api-Key` header only (no session tokens required).
|
|
6642
|
-
* Delegates HTTP concerns (retry, auth headers, timeouts) to the shared `ApiClient`.
|
|
6643
|
-
*
|
|
6644
|
-
* ## Concurrency cap (vs. pagination / throttling)
|
|
6645
|
-
*
|
|
6646
|
-
* The fan-out helper {@link fetchStepDiffsWithCap} caps the number of
|
|
6647
|
-
* **simultaneous in-flight** per-step `/diff` requests at
|
|
6648
|
-
* {@link DEFAULT_STEP_DIFF_CONCURRENCY} (10 by default). It is **not**:
|
|
6649
|
-
*
|
|
6650
|
-
* - **Pagination.** The Eyes BE returns the full diff for one
|
|
6651
|
-
* `(batchId, sessionId, stepIndex)` in one response — there is no page
|
|
6652
|
-
* cursor, no `nextPage`, no partial result; `stepIndex` is an identity
|
|
6653
|
-
* coordinate, not an offset. We always issue exactly one request per
|
|
6654
|
-
* step that has diffs and the BE never asks us to ask again.
|
|
6655
|
-
* - **Server-side throttling.** The Eyes BE does not advertise a per-key
|
|
6656
|
-
* concurrency budget for these endpoints; the cap is purely client-side
|
|
6657
|
-
* courtesy so that batches with hundreds of failing steps don't open
|
|
6658
|
-
* hundreds of sockets at once. Real throttling (HTTP 429) is handled
|
|
6659
|
-
* transparently by the shared `ApiClient` retry policy.
|
|
6660
|
-
*
|
|
6661
|
-
* In other words: we always request "all the data in one go", but we drip
|
|
6662
|
-
* the requests through a fixed-size worker pool.
|
|
6663
|
-
*/
|
|
6664
|
-
// ─── URL helpers ─────────────────────────────────────────────────────────────
|
|
6665
|
-
// Unlike eyes-results' own BATCH_PATH: single capture, and `\s` excluded so the id can be
|
|
6666
|
-
// plucked out of surrounding console text, not only out of a well-formed URL.
|
|
6667
|
-
const BATCH_ID_PATTERN = new RegExp(`${BATCH_ROUTE_PREFIX_SOURCE}([^/?#\\s]+)`);
|
|
6668
|
-
/**
|
|
6669
|
-
* Extract a batch ID from a full Applitools dashboard URL or return the value
|
|
6670
|
-
* as-is if it already looks like a plain batch ID.
|
|
6671
|
-
*
|
|
6672
|
-
* The regex anchors on either dashboard path prefix — `/app/test-results/` and the
|
|
6673
|
-
* `/app/batches/` form the Eyes server returns as a run's own session URL — and captures
|
|
6674
|
-
* everything up to the next `/`, `?`, `#`, or whitespace, so deep links into a specific
|
|
6675
|
-
* session/step inside the batch resolve to the **batch ID** — not the
|
|
6676
|
-
* session ID — which is what every downstream API call expects.
|
|
6677
|
-
*
|
|
6678
|
-
* Examples:
|
|
6679
|
-
* https://eyes.applitools.com/app/test-results/00000251626130890241 → 00000251626130890241
|
|
6680
|
-
* https://eyes.applitools.com/app/test-results/00000251626130890241?some=param → 00000251626130890241
|
|
6681
|
-
* https://eyes.applitools.com/app/test-results/00000251626130890241#anchor → 00000251626130890241
|
|
6682
|
-
* https://eyes.applitools.com/app/test-results/00000251626130890241/00000251626130890242 → 00000251626130890241
|
|
6683
|
-
* https://eyes.applitools.com/app/test-results/00000251626130890241/00000251626130890242/other → 00000251626130890241
|
|
6684
|
-
* https://eyes.applitools.com/app/batches/00000251626130890241/00000251626130890242 → 00000251626130890241
|
|
6685
|
-
* 00000251626130890241 → 00000251626130890241 (passthrough)
|
|
6686
|
-
*/
|
|
6687
|
-
function extractBatchId(urlOrId) {
|
|
6688
|
-
const match = urlOrId.match(BATCH_ID_PATTERN);
|
|
6689
|
-
if (match)
|
|
6690
|
-
return match[1];
|
|
6691
|
-
return urlOrId.trim();
|
|
6692
|
-
}
|
|
6693
|
-
/**
|
|
6694
|
-
* Extract the Eyes server base URL from an Applitools batch URL.
|
|
6695
|
-
* Falls back to the defaultUrl if the input is not a valid URL.
|
|
6696
|
-
*
|
|
6697
|
-
* Example: https://eyes.applitools.com/app/test-results/... → https://eyes.applitools.com
|
|
6698
|
-
*/
|
|
6699
|
-
function extractServerUrl(urlOrId, defaultUrl = 'https://eyes.applitools.com') {
|
|
6700
|
-
try {
|
|
6701
|
-
const parsed = new URL(urlOrId);
|
|
6702
|
-
return `${parsed.protocol}//${parsed.host}`;
|
|
6703
|
-
}
|
|
6704
|
-
catch {
|
|
6705
|
-
return defaultUrl;
|
|
6706
|
-
}
|
|
6707
|
-
}
|
|
6708
|
-
// ─── Batch Results API ────────────────────────────────────────────────────────
|
|
6709
|
-
/** Sentinel for a 404 from the Batch Results API — the batch ID does not exist. */
|
|
6710
|
-
class BatchNotFoundError extends Error {
|
|
6711
|
-
constructor(batchId) {
|
|
6712
|
-
super(`Batch not found: ${batchId}`);
|
|
6713
|
-
this.batchId = batchId;
|
|
6714
|
-
this.name = 'BatchNotFoundError';
|
|
6715
|
-
}
|
|
6716
|
-
}
|
|
6717
|
-
/**
|
|
6718
|
-
* Fetch batch results from the public Batch Results API.
|
|
6719
|
-
*
|
|
6720
|
-
* Returns step-level data including `diffDescriptionsCount` per step. Throws
|
|
6721
|
-
* `InvalidApiKeyError` on 401 (via the shared client) and `BatchNotFoundError`
|
|
6722
|
-
* on 404 so the calling tool can render actionable messages.
|
|
6723
|
-
*/
|
|
6724
|
-
async function fetchBatchResults(batchId, apiKey, serverUrl) {
|
|
6725
|
-
const client = new ApiClient({ baseUrl: serverUrl, apiKey });
|
|
6726
|
-
const res = await client.getRaw(`api/v1/batches/${batchId}?steps=true`);
|
|
6727
|
-
if (res.status === 404)
|
|
6728
|
-
throw new BatchNotFoundError(batchId);
|
|
6729
|
-
if (!res.ok)
|
|
6730
|
-
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
6731
|
-
return (await res.json());
|
|
6732
|
-
}
|
|
6733
|
-
// ─── Per-step diff API ────────────────────────────────────────────────────────
|
|
6734
|
-
/**
|
|
6735
|
-
* Fetch and deduplicate diff descriptions for a single step.
|
|
6736
|
-
*
|
|
6737
|
-
* Returns an empty array when:
|
|
6738
|
-
* - The step has no diffs (204 No Content)
|
|
6739
|
-
* - The request fails for any reason (graceful degradation)
|
|
6740
|
-
*
|
|
6741
|
-
* Deduplicates diff descriptions across pixel regions, since the same logical
|
|
6742
|
-
* difference can appear in multiple diff regions in the response.
|
|
6743
|
-
*/
|
|
6744
|
-
async function fetchStepDiff(client, batchId,
|
|
6745
|
-
/** In the Eyes API, testId and sessionId refer to the same entity. The Batch Results API calls it testId; this endpoint calls it sessionId. */
|
|
6746
|
-
sessionId, stepIndex) {
|
|
6747
|
-
var _a;
|
|
6748
|
-
try {
|
|
6749
|
-
const res = await client.getRaw(`api/v1/batches/${batchId}/${sessionId}/${stepIndex}/diff`);
|
|
6750
|
-
// 204 = matching step (no diffs)
|
|
6751
|
-
if (res.status === 204)
|
|
6752
|
-
return [];
|
|
6753
|
-
if (!res.ok)
|
|
6754
|
-
return [];
|
|
6755
|
-
const data = (await res.json());
|
|
6756
|
-
return deduplicateDiffDescriptions((_a = data.image1) !== null && _a !== void 0 ? _a : []);
|
|
6757
|
-
}
|
|
6758
|
-
catch (err) {
|
|
6759
|
-
// Surface auth errors loudly so the user sees "invalid API key" instead of
|
|
6760
|
-
// an empty diff list for every step. Everything else degrades gracefully
|
|
6761
|
-
// — one flaky per-step request must not fail the whole tool.
|
|
6762
|
-
if (err instanceof InvalidApiKeyError || err instanceof MissingApiKeyError) {
|
|
6763
|
-
throw err;
|
|
6764
|
-
}
|
|
6765
|
-
return [];
|
|
6766
|
-
}
|
|
6767
|
-
}
|
|
6768
|
-
/**
|
|
6769
|
-
* Default ceiling on concurrent in-flight `/diff` requests. See the
|
|
6770
|
-
* "Concurrency cap" section at the top of the file for the rationale and
|
|
6771
|
-
* for why this is a client-side fan-out limit, not server pagination.
|
|
6772
|
-
*/
|
|
6773
|
-
const DEFAULT_STEP_DIFF_CONCURRENCY = 10;
|
|
6774
|
-
/**
|
|
6775
|
-
* Fetch per-step diffs for every step in `tasks`, in one go, but with a
|
|
6776
|
-
* client-side concurrency cap so we don't open one socket per step on big
|
|
6777
|
-
* failing batches. Results are returned in the same order as `tasks`.
|
|
6778
|
-
*
|
|
6779
|
-
* Important non-features (so reviewers don't have to ask):
|
|
6780
|
-
* - `stepIndex` is an **identity** coordinate, not a pagination cursor;
|
|
6781
|
-
* each `(batchId, sessionId, stepIndex)` returns a complete diff in
|
|
6782
|
-
* one shot.
|
|
6783
|
-
* - The cap is purely client-side. Real throttling (HTTP 429) is handled
|
|
6784
|
-
* by `ApiClient`'s retry policy; this function only limits how many
|
|
6785
|
-
* requests are awaited concurrently.
|
|
6786
|
-
* - A single `ApiClient` is shared across all fan-out calls so retry
|
|
6787
|
-
* config, auth headers, and connection state are reused.
|
|
6788
|
-
*/
|
|
6789
|
-
async function fetchStepDiffsWithCap(tasks, apiKey, serverUrl, concurrencyLimit = DEFAULT_STEP_DIFF_CONCURRENCY) {
|
|
6790
|
-
const client = new ApiClient({ baseUrl: serverUrl, apiKey });
|
|
6791
|
-
const results = new Array(tasks.length);
|
|
6792
|
-
let cursor = 0;
|
|
6793
|
-
async function processNext() {
|
|
6794
|
-
while (cursor < tasks.length) {
|
|
6795
|
-
const index = cursor++;
|
|
6796
|
-
const t = tasks[index];
|
|
6797
|
-
results[index] = await fetchStepDiff(client, t.batchId, t.sessionId, t.stepIndex);
|
|
6798
|
-
}
|
|
6799
|
-
}
|
|
6800
|
-
const workers = Array.from({ length: Math.min(concurrencyLimit, tasks.length) }, processNext);
|
|
6801
|
-
await Promise.all(workers);
|
|
6802
|
-
return results;
|
|
6803
|
-
}
|
|
6804
|
-
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
6805
|
-
/**
|
|
6806
|
-
* Deduplicate diff descriptions across pixel diff regions.
|
|
6807
|
-
*
|
|
6808
|
-
* The per-step diff API can return the same logical difference (e.g. "text
|
|
6809
|
-
* changed") in multiple pixel regions of the image. This function collapses
|
|
6810
|
-
* them to unique `(baselineValue, checkpointValue, category)` tuples.
|
|
6811
|
-
*/
|
|
6812
|
-
function deduplicateDiffDescriptions(regions) {
|
|
6813
|
-
var _a;
|
|
6814
|
-
const seen = new Set();
|
|
6815
|
-
const result = [];
|
|
6816
|
-
for (const region of regions) {
|
|
6817
|
-
for (const desc of (_a = region.diffDescriptions) !== null && _a !== void 0 ? _a : []) {
|
|
6818
|
-
const key = `${desc.baselineValue}|||${desc.checkpointValue}|||${desc.category}`;
|
|
6819
|
-
if (!seen.has(key)) {
|
|
6820
|
-
seen.add(key);
|
|
6821
|
-
result.push({
|
|
6822
|
-
baselineValue: desc.baselineValue,
|
|
6823
|
-
checkpointValue: desc.checkpointValue,
|
|
6824
|
-
category: desc.category,
|
|
6825
|
-
});
|
|
6826
|
-
}
|
|
6827
|
-
}
|
|
6828
|
-
}
|
|
6829
|
-
return result;
|
|
6830
|
-
}
|
|
6831
|
-
|
|
6832
|
-
/**
|
|
6833
|
-
* Translate auth/transport errors thrown by `ApiClient` into actionable,
|
|
6834
|
-
* user-facing wording shared between every MCP tool that talks to the Eyes
|
|
6835
|
-
* server.
|
|
6836
|
-
*
|
|
6837
|
-
* Keeping this in one place means a wording change (or a new error class
|
|
6838
|
-
* like {@link InvalidApiKeyError}) is reflected everywhere automatically;
|
|
6839
|
-
* tools only have to add their own specialised cases (e.g. `BatchNotFoundError`
|
|
6840
|
-
* in `eyes_analyze_batch`) before falling through to {@link formatApiFetchError}.
|
|
6841
|
-
*/
|
|
6842
|
-
/**
|
|
6843
|
-
* Default, generic prefix used when the error has no recognised type. Tools
|
|
6844
|
-
* may override it via the `genericPrefix` option to add tool-specific
|
|
6845
|
-
* context (e.g. "Failed to fetch batch results: ...").
|
|
6846
|
-
*/
|
|
6847
|
-
const DEFAULT_GENERIC_PREFIX = 'Eyes server request failed: ';
|
|
6848
|
-
/**
|
|
6849
|
-
* Map an unknown error thrown by an `ApiClient` call to a single-string
|
|
6850
|
-
* message suitable for `wrapText()`-rendered tool output.
|
|
6851
|
-
*
|
|
6852
|
-
* Recognised cases:
|
|
6853
|
-
* - {@link InvalidApiKeyError}: tells the user to call the `eyes_verify_api_key`
|
|
6854
|
-
* MCP tool again, or set `APPLITOOLS_API_KEY`.
|
|
6855
|
-
* - {@link MissingApiKeyError}: same remediation, different opening.
|
|
6856
|
-
* - Anything else: prefix + `err.message` (or `String(err)` if not an Error).
|
|
6857
|
-
*
|
|
6858
|
-
* Tools with extra error classes should special-case those FIRST and only
|
|
6859
|
-
* fall through to this helper for the shared cases.
|
|
6860
|
-
*/
|
|
6861
|
-
function formatApiFetchError(err, options = {}) {
|
|
6862
|
-
var _a;
|
|
6863
|
-
if (err instanceof InvalidApiKeyError) {
|
|
6864
|
-
return (`Authentication failed: invalid API key. ` +
|
|
6865
|
-
`Please call the \`${TOOL_NAMES.EYES_VERIFY_API_KEY}\` MCP tool to refresh your credentials, ` +
|
|
6866
|
-
`or set a valid APPLITOOLS_API_KEY environment variable.`);
|
|
6867
|
-
}
|
|
6868
|
-
if (err instanceof MissingApiKeyError) {
|
|
6869
|
-
return (`No Applitools API key found. ` +
|
|
6870
|
-
`Please call the \`${TOOL_NAMES.EYES_VERIFY_API_KEY}\` MCP tool first, ` +
|
|
6871
|
-
`or set the APPLITOOLS_API_KEY environment variable.`);
|
|
6872
|
-
}
|
|
6873
|
-
const prefix = (_a = options.genericPrefix) !== null && _a !== void 0 ? _a : DEFAULT_GENERIC_PREFIX;
|
|
6874
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
6875
|
-
return `${prefix}${msg}`;
|
|
5853
|
+
return { registerTool };
|
|
6876
5854
|
}
|
|
6877
5855
|
|
|
6878
5856
|
const defaultResolverDeps = {
|
|
@@ -6917,236 +5895,6 @@ async function getFullAccountId(accountId, apiKey, serverUrl = DEFAULT_SERVER_UR
|
|
|
6917
5895
|
}
|
|
6918
5896
|
}
|
|
6919
5897
|
|
|
6920
|
-
/**
|
|
6921
|
-
* eyes_analyze_batch MCP tool — "Paste Batch URL" flow (AD-13206 Part 2).
|
|
6922
|
-
*
|
|
6923
|
-
* Accepts an Applitools batch URL or bare batch ID and returns visual test
|
|
6924
|
-
* results with textual diff descriptions. Unlike `eyes_fetch_visual_results`,
|
|
6925
|
-
* this tool does NOT require a Playwright HTML report on disk — it queries
|
|
6926
|
-
* the public Batch Results API directly.
|
|
6927
|
-
*
|
|
6928
|
-
* Data flow:
|
|
6929
|
-
* 1. Extract batch ID + server URL from the input URL
|
|
6930
|
-
* 2. Load API key (session cache → config files → env vars)
|
|
6931
|
-
* 3. GET /api/v1/batches/{batchId}?steps=true (via shared ApiClient)
|
|
6932
|
-
* 4. For every step with diffDescriptionsCount > 0:
|
|
6933
|
-
* GET /api/v1/batches/{batchId}/{sessionId}/{stepIndex}/diff
|
|
6934
|
-
* (≤10 concurrent; deduplicate across pixel regions)
|
|
6935
|
-
* 5. Build structured response in the same shape as eyes_fetch_visual_results
|
|
6936
|
-
*/
|
|
6937
|
-
// ─── Tool metadata ────────────────────────────────────────────────────────────
|
|
6938
|
-
const TOOL_NAME = TOOL_NAMES.EYES_ANALYZE_BATCH;
|
|
6939
|
-
const TOOL_DESCRIPTION = `Fetch visual test results and textual diff descriptions from an Applitools Eyes batch URL.
|
|
6940
|
-
|
|
6941
|
-
Use this tool when the user provides a batch URL from the Applitools dashboard (e.g. https://eyes.applitools.com/app/test-results/{batchId}) or a bare batch ID, and you need to analyze its visual test results without a Playwright HTML report on disk.
|
|
6942
|
-
|
|
6943
|
-
This is the counterpart to \`eyes_fetch_visual_results\` for cases where:
|
|
6944
|
-
- The user is looking at results from a CI run or a previous run
|
|
6945
|
-
- There is no Playwright report available locally
|
|
6946
|
-
- The user pastes a batch URL from the Eyes dashboard
|
|
6947
|
-
|
|
6948
|
-
The tool returns the same structured output as \`eyes_fetch_visual_results\`, including:
|
|
6949
|
-
- Per-test status (passed / failed / unresolved / new / aborted)
|
|
6950
|
-
- Textual diff descriptions for steps with visual differences
|
|
6951
|
-
- Aggregate summary statistics
|
|
6952
|
-
|
|
6953
|
-
Note: Textual diff descriptions require DOM-based diff analysis on the server side. Steps without DOM capture (e.g. Figma, mobile native) may not have diff descriptions even when diffs are present.`;
|
|
6954
|
-
// ─── Input / output schemas ───────────────────────────────────────────────────
|
|
6955
|
-
const AnalyzeBatchInputSchema = commonInputSchema.extend({
|
|
6956
|
-
batchUrl: zod.z
|
|
6957
|
-
.string()
|
|
6958
|
-
.describe('The Applitools Eyes batch URL (e.g. https://eyes.applitools.com/app/test-results/{batchId}) or a bare batch ID.'),
|
|
6959
|
-
serverUrl: zod.z
|
|
6960
|
-
.string()
|
|
6961
|
-
.optional()
|
|
6962
|
-
.describe('Eyes server base URL (optional, auto-detected from batchUrl or defaults to https://eyes.applitools.com). Set this for on-premises Eyes deployments.'),
|
|
6963
|
-
});
|
|
6964
|
-
const AnalyzeBatchClientInputSchema = createClientInputSchema(AnalyzeBatchInputSchema);
|
|
6965
|
-
// ─── Tool implementation ──────────────────────────────────────────────────────
|
|
6966
|
-
async function analyzeEyesBatch(input) {
|
|
6967
|
-
var _a, _b;
|
|
6968
|
-
const { workspaceRoot } = validateCommonInput(input);
|
|
6969
|
-
// Step 1 — Extract batch ID and server URL
|
|
6970
|
-
const batchId = extractBatchId(input.batchUrl);
|
|
6971
|
-
if (!batchId) {
|
|
6972
|
-
return VisualResultsToolResultSchema.parse({
|
|
6973
|
-
message: wrapText(`Could not extract a batch ID from: ${input.batchUrl}\n\n` +
|
|
6974
|
-
`Please provide a full Eyes batch URL (e.g. https://eyes.applitools.com/app/test-results/{batchId}) ` +
|
|
6975
|
-
`or a bare batch ID.`, 'prefix'),
|
|
6976
|
-
});
|
|
6977
|
-
}
|
|
6978
|
-
const serverUrl = (_a = input.serverUrl) !== null && _a !== void 0 ? _a : extractServerUrl(input.batchUrl, DEFAULT_SERVER_URL);
|
|
6979
|
-
// Step 2 — Load API key. Defer wording to the shared `formatApiFetchError`
|
|
6980
|
-
// helper so that any future copy change in one place propagates here too.
|
|
6981
|
-
const apiKey = getLastValidatedApiKey() || loadCredentials(workspaceRoot).apiKey;
|
|
6982
|
-
if (!apiKey) {
|
|
6983
|
-
return VisualResultsToolResultSchema.parse({
|
|
6984
|
-
message: wrapText(formatApiFetchError(new MissingApiKeyError()), 'prefix'),
|
|
6985
|
-
});
|
|
6986
|
-
}
|
|
6987
|
-
// Resolve the key's true accountId so emitted dashboard URLs carry it; on
|
|
6988
|
-
// verification failure the URLs simply omit the accountId query param.
|
|
6989
|
-
const accountId = await getFullAccountId(undefined, apiKey, serverUrl);
|
|
6990
|
-
// Step 3 — Fetch batch results
|
|
6991
|
-
let batchData;
|
|
6992
|
-
try {
|
|
6993
|
-
batchData = await fetchBatchResults(batchId, apiKey, serverUrl);
|
|
6994
|
-
}
|
|
6995
|
-
catch (err) {
|
|
6996
|
-
return VisualResultsToolResultSchema.parse({
|
|
6997
|
-
message: wrapText(formatFetchError(err, batchId), 'prefix'),
|
|
6998
|
-
});
|
|
6999
|
-
}
|
|
7000
|
-
if (!batchData.tests || batchData.tests.length === 0) {
|
|
7001
|
-
return VisualResultsToolResultSchema.parse({
|
|
7002
|
-
message: wrapText(`Batch ${batchId} contains no tests.`, 'prefix'),
|
|
7003
|
-
});
|
|
7004
|
-
}
|
|
7005
|
-
// Step 4 — Fetch per-step diff descriptions for steps that have diffs
|
|
7006
|
-
const stepDiffsByTest = new Map();
|
|
7007
|
-
const diffTasks = buildDiffTasks(batchData.tests);
|
|
7008
|
-
if (diffTasks.length > 0) {
|
|
7009
|
-
// Fetch all step diffs with concurrency cap. Auth errors propagate; other
|
|
7010
|
-
// per-step failures are absorbed inside fetchStepDiff and surface as [].
|
|
7011
|
-
let diffResults;
|
|
7012
|
-
try {
|
|
7013
|
-
diffResults = await fetchStepDiffsWithCap(diffTasks.map(t => ({ batchId, sessionId: t.testId, stepIndex: t.stepIndex })), apiKey, serverUrl);
|
|
7014
|
-
}
|
|
7015
|
-
catch (err) {
|
|
7016
|
-
return VisualResultsToolResultSchema.parse({
|
|
7017
|
-
message: wrapText(formatFetchError(err, batchId), 'prefix'),
|
|
7018
|
-
});
|
|
7019
|
-
}
|
|
7020
|
-
// Group results by testId
|
|
7021
|
-
for (let i = 0; i < diffTasks.length; i++) {
|
|
7022
|
-
const task = diffTasks[i];
|
|
7023
|
-
const descriptions = diffResults[i];
|
|
7024
|
-
if (descriptions.length > 0) {
|
|
7025
|
-
if (!stepDiffsByTest.has(task.testId)) {
|
|
7026
|
-
stepDiffsByTest.set(task.testId, []);
|
|
7027
|
-
}
|
|
7028
|
-
stepDiffsByTest.get(task.testId).push({
|
|
7029
|
-
stepIndex: task.stepIndex,
|
|
7030
|
-
stepName: task.stepName,
|
|
7031
|
-
diffDescriptions: descriptions,
|
|
7032
|
-
});
|
|
7033
|
-
}
|
|
7034
|
-
}
|
|
7035
|
-
}
|
|
7036
|
-
// Step 5 — Build ProcessedBatch compatible with the shared response builder
|
|
7037
|
-
//
|
|
7038
|
-
// Any `~~` in these URLs is base64 padding inside the accountId value itself
|
|
7039
|
-
// (`=` encoded as `~`), never a separate suffix. Both visual-results tools
|
|
7040
|
-
// build URLs through the shared helpers in utils/url-utils.ts.
|
|
7041
|
-
const batchUrl = buildBatchUrl$1(serverUrl, batchId, accountId);
|
|
7042
|
-
const batchName = ((_b = batchData.statistics) === null || _b === void 0 ? void 0 : _b.name) || batchId;
|
|
7043
|
-
const processedTests = batchData.tests.map(test => {
|
|
7044
|
-
var _a, _b, _c;
|
|
7045
|
-
const stepDiffs = (_a = stepDiffsByTest.get(test.testId)) !== null && _a !== void 0 ? _a : [];
|
|
7046
|
-
const browser = ((_b = test.env) === null || _b === void 0 ? void 0 : _b.app) || ((_c = test.env) === null || _c === void 0 ? void 0 : _c.device) || 'Unknown';
|
|
7047
|
-
return {
|
|
7048
|
-
testName: test.testName,
|
|
7049
|
-
batchName,
|
|
7050
|
-
status: normalizeStatus(test.status),
|
|
7051
|
-
sessionUrl: buildSessionUrl$1(serverUrl, batchId, test.testId, accountId),
|
|
7052
|
-
steps: test.steps.length,
|
|
7053
|
-
retryAttempt: 0,
|
|
7054
|
-
browser,
|
|
7055
|
-
...(stepDiffs.length > 0 ? { stepDiffs } : {}),
|
|
7056
|
-
};
|
|
7057
|
-
});
|
|
7058
|
-
const processedBatches = [
|
|
7059
|
-
{
|
|
7060
|
-
batchId,
|
|
7061
|
-
batchName,
|
|
7062
|
-
batchUrl,
|
|
7063
|
-
tests: processedTests,
|
|
7064
|
-
},
|
|
7065
|
-
];
|
|
7066
|
-
// Reuse the shared response builder for consistent output formatting
|
|
7067
|
-
const result = buildVisualResultsResult(processedBatches);
|
|
7068
|
-
return VisualResultsToolResultSchema.parse(result);
|
|
7069
|
-
}
|
|
7070
|
-
// Fall back to `Step N` for unnamed steps: the API omits `name`, and the
|
|
7071
|
-
// downstream StepDiffSchema requires a string `stepName`.
|
|
7072
|
-
function buildDiffTasks(tests) {
|
|
7073
|
-
const diffTasks = [];
|
|
7074
|
-
for (const test of tests) {
|
|
7075
|
-
for (let i = 0; i < test.steps.length; i++) {
|
|
7076
|
-
const step = test.steps[i];
|
|
7077
|
-
if (step.diffDescriptionsCount > 0) {
|
|
7078
|
-
diffTasks.push({
|
|
7079
|
-
testId: test.testId,
|
|
7080
|
-
stepIndex: i,
|
|
7081
|
-
stepName: step.name || `Step ${i + 1}`,
|
|
7082
|
-
});
|
|
7083
|
-
}
|
|
7084
|
-
}
|
|
7085
|
-
}
|
|
7086
|
-
return diffTasks;
|
|
7087
|
-
}
|
|
7088
|
-
/**
|
|
7089
|
-
* Translate a fetch error into actionable, user-facing wording.
|
|
7090
|
-
*
|
|
7091
|
-
* Specialises for {@link BatchNotFoundError} (this tool's own 404 sentinel),
|
|
7092
|
-
* then defers to the shared {@link formatApiFetchError} util so that
|
|
7093
|
-
* `InvalidApiKeyError` / `MissingApiKeyError` wording stays consistent with
|
|
7094
|
-
* `eyes_fetch_visual_results` (and any future MCP tool that talks to the
|
|
7095
|
-
* Eyes server).
|
|
7096
|
-
*/
|
|
7097
|
-
function formatFetchError(err, batchId) {
|
|
7098
|
-
if (err instanceof BatchNotFoundError) {
|
|
7099
|
-
return `Batch not found: ${batchId}. Verify the URL/batch ID and that the key has access to this batch.`;
|
|
7100
|
-
}
|
|
7101
|
-
return formatApiFetchError(err, { genericPrefix: 'Failed to fetch batch results: ' });
|
|
7102
|
-
}
|
|
7103
|
-
|
|
7104
|
-
const analyzeEyesBatchTool = {
|
|
7105
|
-
name: TOOL_NAME,
|
|
7106
|
-
description: TOOL_DESCRIPTION,
|
|
7107
|
-
inputSchema: AnalyzeBatchClientInputSchema,
|
|
7108
|
-
outputSchema: VisualResultsToolResultSchema,
|
|
7109
|
-
handler: createToolHandler({
|
|
7110
|
-
name: TOOL_NAME,
|
|
7111
|
-
input: AnalyzeBatchInputSchema,
|
|
7112
|
-
output: VisualResultsToolResultSchema,
|
|
7113
|
-
}, async (params) => {
|
|
7114
|
-
const result = await analyzeEyesBatch(params);
|
|
7115
|
-
return {
|
|
7116
|
-
content: [
|
|
7117
|
-
{
|
|
7118
|
-
type: 'text',
|
|
7119
|
-
text: result.message,
|
|
7120
|
-
},
|
|
7121
|
-
],
|
|
7122
|
-
structuredContent: result,
|
|
7123
|
-
};
|
|
7124
|
-
}),
|
|
7125
|
-
};
|
|
7126
|
-
|
|
7127
|
-
const ALL_TOOLS = {
|
|
7128
|
-
verifyApiKey: verifyApiKeyTool,
|
|
7129
|
-
eyesSetupProject: eyesSetupProjectTool,
|
|
7130
|
-
eyesSetupUfg: eyesSetupUfgTool,
|
|
7131
|
-
eyesAddCheckpointsToTest: eyesAddCheckpointsToTestTool,
|
|
7132
|
-
getBatchUrlFromOutput: getBatchUrlFromOutputTool,
|
|
7133
|
-
playwrightFetchVisualResults: playwrightFetchVisualResultsTool,
|
|
7134
|
-
analyzeEyesBatch: analyzeEyesBatchTool,
|
|
7135
|
-
};
|
|
7136
|
-
|
|
7137
|
-
const workspaceRootSchema = zod.z
|
|
7138
|
-
.string()
|
|
7139
|
-
.optional()
|
|
7140
|
-
.describe("Root directory of the caller's project (optional; used to locate its .env credentials)");
|
|
7141
|
-
function instrumentedRegistrar(server) {
|
|
7142
|
-
const registerTool = (name, config, handler) => {
|
|
7143
|
-
const inputSchema = { workspaceRoot: workspaceRootSchema, ...config.inputSchema };
|
|
7144
|
-
const wrapped = createToolHandler({ name, input: zod.z.object(inputSchema) }, async (params) => handler(params).then(result => result));
|
|
7145
|
-
return server.registerTool(name, { ...config, inputSchema }, wrapped);
|
|
7146
|
-
};
|
|
7147
|
-
return { registerTool };
|
|
7148
|
-
}
|
|
7149
|
-
|
|
7150
5898
|
const defaultDeps = { getFullAccountId };
|
|
7151
5899
|
// One resolution per parse: everything downstream — API-call fetchers and URL
|
|
7152
5900
|
// builders alike — receives the healed accountId. The raw eyes-results parse
|
|
@@ -7213,7 +5961,7 @@ const defaultCommandsDeps$1 = {
|
|
|
7213
5961
|
fetchRawSession,
|
|
7214
5962
|
fetchPrunedDom,
|
|
7215
5963
|
getCompatibleSelectors,
|
|
7216
|
-
fetchStepDiff
|
|
5964
|
+
fetchStepDiff,
|
|
7217
5965
|
fetchCheckpointImage,
|
|
7218
5966
|
fetchImageById,
|
|
7219
5967
|
compareStep,
|
|
@@ -7547,7 +6295,7 @@ const defaultFetchVisibleDomDiffDeps = {
|
|
|
7547
6295
|
fetchRawSession,
|
|
7548
6296
|
awaitDomDiff,
|
|
7549
6297
|
awaitDomDiffTask,
|
|
7550
|
-
fetchStepDiff
|
|
6298
|
+
fetchStepDiff,
|
|
7551
6299
|
compareStep,
|
|
7552
6300
|
readFile: defaultFsCacheDeps.readFile,
|
|
7553
6301
|
writeFile: defaultFsCacheDeps.writeFile,
|
|
@@ -9223,9 +7971,19 @@ function parentLevelOf(level) {
|
|
|
9223
7971
|
function childLevelLabel(level) {
|
|
9224
7972
|
return LEVEL_LABELS[childLevelOf(level)];
|
|
9225
7973
|
}
|
|
9226
|
-
/**
|
|
7974
|
+
/**
|
|
7975
|
+
* `rootScope`, defaulted to `level` itself when the caller omits it — except a diff, which always
|
|
7976
|
+
* belongs to at least a step review, so a diff-rooted `next` would strand the model after the last area.
|
|
7977
|
+
*/
|
|
9227
7978
|
function resolveRootScope(level, rootScope) {
|
|
9228
|
-
return rootScope !== null && rootScope !== void 0 ? rootScope : level;
|
|
7979
|
+
return rootScope !== null && rootScope !== void 0 ? rootScope : (level === 'diff' ? 'step' : level);
|
|
7980
|
+
}
|
|
7981
|
+
function isScopeType(value) {
|
|
7982
|
+
return SCOPE_TYPES.includes(value);
|
|
7983
|
+
}
|
|
7984
|
+
/** Whether `outer` is `inner` itself or one of its ancestors. */
|
|
7985
|
+
function isAtOrAbove(outer, inner) {
|
|
7986
|
+
return levelDepth(outer) <= levelDepth(inner);
|
|
9229
7987
|
}
|
|
9230
7988
|
/** Whether escalating beyond `level` (to a sibling, or to the parent) would go past the entity the investigation was scoped to. */
|
|
9231
7989
|
function hasReachedRootScope(level, rootScope) {
|
|
@@ -9311,7 +8069,10 @@ function computeCompleted(scopeId, liveChildScopeIds, deps) {
|
|
|
9311
8069
|
* them, never mutates or re-scopes one.
|
|
9312
8070
|
*/
|
|
9313
8071
|
function buildProgressNext(params) {
|
|
9314
|
-
|
|
8072
|
+
return withRootReminder(progressNext(params), params.rootScope);
|
|
8073
|
+
}
|
|
8074
|
+
function progressNext(params) {
|
|
8075
|
+
const { level, rootScope, completed, descentCall, endCall, hasChildFindings, parentProgressCall } = params;
|
|
9315
8076
|
const label = LEVEL_LABELS[level];
|
|
9316
8077
|
const childLabel = LEVEL_LABELS[childLevelOf(level)];
|
|
9317
8078
|
if (completed === null) {
|
|
@@ -9321,6 +8082,12 @@ function buildProgressNext(params) {
|
|
|
9321
8082
|
calls: [descentCall],
|
|
9322
8083
|
};
|
|
9323
8084
|
}
|
|
8085
|
+
if (!hasChildFindings) {
|
|
8086
|
+
return {
|
|
8087
|
+
instruction: emptyCloseInstruction(`Every ${childLabel} of this ${label} was reviewed and none of them recorded a finding`, endCall.tool, level),
|
|
8088
|
+
calls: [withEmptyFindings(endCall)],
|
|
8089
|
+
};
|
|
8090
|
+
}
|
|
9324
8091
|
return {
|
|
9325
8092
|
instruction: `Every ${childLabel} of this ${label} was reviewed. Call ${endCall.tool} with scope "${level}" and a summary built from findings.`,
|
|
9326
8093
|
calls: [endCall],
|
|
@@ -9335,6 +8102,20 @@ function buildProgressNext(params) {
|
|
|
9335
8102
|
calls: [parentProgressCall],
|
|
9336
8103
|
};
|
|
9337
8104
|
}
|
|
8105
|
+
/** Clients that rebuild arguments instead of copying `next.calls` drop `rootScope`; restating it in prose keeps it in view. */
|
|
8106
|
+
function rootReminder(rootScope) {
|
|
8107
|
+
return `This review is rooted at scope "${rootScope}" — pass rootScope: "${rootScope}" on every eyes_review_* call until it reports complete.`;
|
|
8108
|
+
}
|
|
8109
|
+
/** Root responses carry no calls and keep their done message verbatim. */
|
|
8110
|
+
function withRootReminder(next, rootScope) {
|
|
8111
|
+
return next.calls ? { ...next, instruction: `${next.instruction} ${rootReminder(rootScope)}` } : next;
|
|
8112
|
+
}
|
|
8113
|
+
function emptyCloseInstruction(reviewedNothingFound, endTool, scope) {
|
|
8114
|
+
return `${reviewedNothingFound}, so there is nothing to summarize — call ${endTool} with scope "${scope}" and \`findings: []\` (an empty list is the only valid submission here).`;
|
|
8115
|
+
}
|
|
8116
|
+
function withEmptyFindings(call) {
|
|
8117
|
+
return { ...call, args: { ...call.args, findings: [] } };
|
|
8118
|
+
}
|
|
9338
8119
|
/**
|
|
9339
8120
|
* `eyes_review_end`'s `next` for one level, once its checks have passed (soft-incomplete redirects
|
|
9340
8121
|
* are built by the caller directly — see `tools.ts`): while `level` hasn't reached `rootScope`, a call
|
|
@@ -9344,6 +8125,9 @@ function buildProgressNext(params) {
|
|
|
9344
8125
|
* `parentProgressCall` are expected to already carry `rootScope` from their `nextCall()` call site.
|
|
9345
8126
|
*/
|
|
9346
8127
|
function buildEndNext(params) {
|
|
8128
|
+
return withRootReminder(endNext(params), params.rootScope);
|
|
8129
|
+
}
|
|
8130
|
+
function endNext(params) {
|
|
9347
8131
|
const { level, rootScope, siblingCall, parentClose, parentProgressCall, doneMessage } = params;
|
|
9348
8132
|
const label = LEVEL_LABELS[level];
|
|
9349
8133
|
if (hasReachedRootScope(level, rootScope)) {
|
|
@@ -9360,6 +8144,13 @@ function buildEndNext(params) {
|
|
|
9360
8144
|
}
|
|
9361
8145
|
if (parentClose) {
|
|
9362
8146
|
const closeLabel = LEVEL_LABELS[parentClose.level];
|
|
8147
|
+
if (!parentClose.hasChildFindings) {
|
|
8148
|
+
return {
|
|
8149
|
+
instruction: emptyCloseInstruction(`This ${label} was reviewed, and so was every other ${label}, so the ${closeLabel} is now fully reviewed too — and none of its ${childLevelLabel(parentClose.level)}s recorded a finding`, parentClose.endCall.tool, parentClose.level),
|
|
8150
|
+
calls: [withEmptyFindings(parentClose.endCall)],
|
|
8151
|
+
nextLevel: parentClose.nextLevel,
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
9363
8154
|
return {
|
|
9364
8155
|
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.`,
|
|
9365
8156
|
calls: [parentClose.endCall],
|
|
@@ -9641,10 +8432,12 @@ function verifySourcedFindings(findings, childFindings) {
|
|
|
9641
8432
|
claimedBy.set(source, findingIndex);
|
|
9642
8433
|
}
|
|
9643
8434
|
});
|
|
8435
|
+
if (outOfRange.length > 0 && childFindings.length === 0) {
|
|
8436
|
+
throw new Error("This level has no child findings to cite, so `sources` cannot name anything. Call again with `findings: []` — the only valid submission when the list this level's own _progress call reported is empty.");
|
|
8437
|
+
}
|
|
9644
8438
|
if (outOfRange.length > 0) {
|
|
9645
|
-
const range = childFindings.length > 0 ? `0-${childFindings.length - 1}` : '(there are no child findings to source from)';
|
|
9646
8439
|
throw new Error(`Sources name an index that is not a valid child finding index for this call: ${outOfRange.join('; ')}. ` +
|
|
9647
|
-
`Valid indices are
|
|
8440
|
+
`Valid indices are 0-${childFindings.length - 1}. Call again with sources that only reference indices from the findings this level's own _progress call reported.`);
|
|
9648
8441
|
}
|
|
9649
8442
|
if (overlapping.length > 0) {
|
|
9650
8443
|
throw new Error(`${overlapping.join('; ')} — each child finding must be consolidated into exactly one submitted finding. ` +
|
|
@@ -9743,9 +8536,9 @@ const REVIEW_SCOPE_ID_SHAPES = {
|
|
|
9743
8536
|
.describe(`${STEP_INDEX_DESC}. Required for scope "step"; omit it otherwise.`),
|
|
9744
8537
|
};
|
|
9745
8538
|
const RootScopeShape = zod.z
|
|
9746
|
-
.enum(
|
|
8539
|
+
.enum(SCOPE_TYPES)
|
|
9747
8540
|
.optional()
|
|
9748
|
-
.describe("
|
|
8541
|
+
.describe("The scope this review was started at; bounds how far `next` escalates. Omit it only on a review's first call — it then defaults to that call's own scope (for eyes_review_diff_report, to its step). On every later call pass through the value the previous call's `next` gave, unchanged: a call that omits it while a wider review is still in progress is sent back unexecuted with the call to repeat (findings always roll up to the parent level regardless).");
|
|
9749
8542
|
const ModeShape = zod.z
|
|
9750
8543
|
.enum(MODES)
|
|
9751
8544
|
.optional()
|
|
@@ -9951,7 +8744,7 @@ const SOURCES_DESC = "Indexes into the flat, combined list of every child findin
|
|
|
9951
8744
|
'entry (no gaps, no overlap between entries), counting `sourceClusters` too; between the two fields, at least ' +
|
|
9952
8745
|
"one citation is required here. This entry's isBug/isExpected must then be consistent with the child findings " +
|
|
9953
8746
|
'it names: isBug non-null iff any of them has isBug non-null; isExpected non-null iff every one of them has ' +
|
|
9954
|
-
'isExpected non-null.';
|
|
8747
|
+
'isExpected non-null. When _progress reported no child findings, submit `findings: []`.';
|
|
9955
8748
|
const SourcesShape = zod.z.array(zod.z.number().int().nonnegative()).describe(SOURCES_DESC);
|
|
9956
8749
|
const SOURCE_CLUSTERS_DESC = 'Ids from the `clusters` block that same _progress call reported — a shorthand for every index the named cluster ' +
|
|
9957
8750
|
'holds, so a large list can be claimed without transcribing it. Clusters were grouped by a mechanical key alone ' +
|
|
@@ -10026,6 +8819,34 @@ const JsonFileArgShape = zod.z
|
|
|
10026
8819
|
'one repetitive cause such as one locale/theme change touching every changed area alike) — writing to a file has ' +
|
|
10027
8820
|
'no such limit. The tool reads and validates the file exactly as if its contents had been sent inline.');
|
|
10028
8821
|
|
|
8822
|
+
/**
|
|
8823
|
+
* Build the canonical Eyes dashboard URL for a single test session.
|
|
8824
|
+
*
|
|
8825
|
+
* Output shape: `{serverUrl}/app/test-results/{batchId}/{sessionId}[?accountId={accountId}]`
|
|
8826
|
+
*
|
|
8827
|
+
* Nothing is appended after the accountId: any `~~` in the final URL is base64
|
|
8828
|
+
* padding inside the accountId value, which arrives complete from the server.
|
|
8829
|
+
*
|
|
8830
|
+
* `accountId` is optional because not every caller has one to hand (the
|
|
8831
|
+
* batch-results-API flow authenticates by API key alone); pass it whenever
|
|
8832
|
+
* the URL was itself derived from a parsed accountId, so review round-trips
|
|
8833
|
+
* stay tied to the account they came from.
|
|
8834
|
+
*/
|
|
8835
|
+
function buildSessionUrl$1(serverUrl, batchId, sessionId, accountId) {
|
|
8836
|
+
const accountIdQuery = accountId ? `?accountId=${accountId}` : '';
|
|
8837
|
+
return `${serverUrl}/app/test-results/${batchId}/${sessionId}${accountIdQuery}`;
|
|
8838
|
+
}
|
|
8839
|
+
/**
|
|
8840
|
+
* Build the canonical Eyes dashboard URL for a whole batch.
|
|
8841
|
+
*
|
|
8842
|
+
* Output shape: `{serverUrl}/app/test-results/{batchId}[/?accountId={accountId}]`
|
|
8843
|
+
*/
|
|
8844
|
+
function buildBatchUrl$1(serverUrl, batchId, accountId) {
|
|
8845
|
+
return accountId
|
|
8846
|
+
? `${serverUrl}/app/test-results/${batchId}/?accountId=${accountId}`
|
|
8847
|
+
: `${serverUrl}/app/test-results/${batchId}`;
|
|
8848
|
+
}
|
|
8849
|
+
|
|
10029
8850
|
/**
|
|
10030
8851
|
* Builds a batch or session URL from parsed components — the inverse of `api`'s
|
|
10031
8852
|
* `parseBatchUrl`/`parseSessionUrl`. The review tools need these to construct ready-made
|
|
@@ -10737,16 +9558,13 @@ async function decideOrCreditStepAction(params) {
|
|
|
10737
9558
|
* model-authored summary prose from whenever `_end` first recorded them, never regenerated —
|
|
10738
9559
|
* this only re-consolidates its rollup now that its children are promoted.
|
|
10739
9560
|
*
|
|
10740
|
-
*
|
|
10741
|
-
* `
|
|
10742
|
-
* every node below the root always pushes up to its immediate in-subtree parent, since that's how
|
|
10743
|
-
* the root's own consolidation gets the data to consolidate from.
|
|
9561
|
+
* Every node, the walk's root included, pushes up to its parent exactly as the live `_end` calls
|
|
9562
|
+
* do — `rootScope` bounds `next`, never where findings are recorded.
|
|
10744
9563
|
*/
|
|
10745
|
-
function promoteSubtreeToResolve(rootLevel,
|
|
9564
|
+
function promoteSubtreeToResolve(rootLevel, ctx, keys, deps) {
|
|
10746
9565
|
return walkSubtree(rootLevel, ctx, async (level, nodeCtx, scopeId) => {
|
|
10747
9566
|
if (getScopeMode(scopeId, deps) !== 'inspect')
|
|
10748
9567
|
return;
|
|
10749
|
-
const pushesUp = level !== rootLevel || !hasReachedRootScope(level, rootScope);
|
|
10750
9568
|
if (level === 'diff') {
|
|
10751
9569
|
const findings = getCompletion(scopeId, deps).payload;
|
|
10752
9570
|
const promoted = await applyRegionMasking({
|
|
@@ -10757,11 +9575,9 @@ function promoteSubtreeToResolve(rootLevel, rootScope, ctx, keys, deps) {
|
|
|
10757
9575
|
deps,
|
|
10758
9576
|
});
|
|
10759
9577
|
recordCompletion(scopeId, promoted, deps);
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
reportRollup(parentScopeId, diffChildKey(nodeCtx.areaRect), { resolution: { accepted: 0, rejected: 0, unresolved: 0 }, regions: mergeFindingRegions(promoted) }, deps);
|
|
10764
|
-
}
|
|
9578
|
+
const parentScopeId = stepScopeId(nodeCtx.sessionUrl, nodeCtx.stepIndex);
|
|
9579
|
+
appendChildFinding(parentScopeId, diffChildKey(nodeCtx.areaRect), promoted, deps);
|
|
9580
|
+
reportRollup(parentScopeId, diffChildKey(nodeCtx.areaRect), { resolution: { accepted: 0, rejected: 0, unresolved: 0 }, regions: mergeFindingRegions(promoted) }, deps);
|
|
10765
9581
|
}
|
|
10766
9582
|
else if (level === 'step') {
|
|
10767
9583
|
const session = await fetchSteps(nodeCtx.sessionUrl, keys);
|
|
@@ -10777,21 +9593,19 @@ function promoteSubtreeToResolve(rootLevel, rootScope, ctx, keys, deps) {
|
|
|
10777
9593
|
deps,
|
|
10778
9594
|
});
|
|
10779
9595
|
recordCompletion(scopeId, findings, deps);
|
|
10780
|
-
|
|
10781
|
-
|
|
10782
|
-
|
|
10783
|
-
reportRollup(parentScopeId, stepChildKey(nodeCtx.stepIndex), { resolution, regions: rollup.regions }, deps);
|
|
10784
|
-
}
|
|
9596
|
+
const parentScopeId = sessionScopeId(nodeCtx.sessionUrl);
|
|
9597
|
+
appendChildFinding(parentScopeId, stepChildKey(nodeCtx.stepIndex), findings, deps);
|
|
9598
|
+
reportRollup(parentScopeId, stepChildKey(nodeCtx.stepIndex), { resolution, regions: rollup.regions }, deps);
|
|
10785
9599
|
}
|
|
10786
9600
|
else {
|
|
10787
9601
|
const findings = getCompletion(scopeId, deps).payload;
|
|
10788
9602
|
const { rollup } = consolidateRollup(scopeId, findings, 'resolve', deps);
|
|
10789
9603
|
recordCompletion(scopeId, findings, deps);
|
|
10790
|
-
if (
|
|
9604
|
+
if (level === 'scenario') {
|
|
10791
9605
|
appendChildFinding(batchScopeId(nodeCtx.batchUrl), scenarioChildKey(nodeCtx.scenarioName), findings, deps);
|
|
10792
9606
|
reportRollup(batchScopeId(nodeCtx.batchUrl), scenarioChildKey(nodeCtx.scenarioName), rollup, deps);
|
|
10793
9607
|
}
|
|
10794
|
-
else if (
|
|
9608
|
+
else if (level === 'session') {
|
|
10795
9609
|
const session = await fetchSteps(nodeCtx.sessionUrl, keys);
|
|
10796
9610
|
const parentScopeId = scenarioScopeIdForSession(nodeCtx.sessionUrl, session.sessionName);
|
|
10797
9611
|
appendChildFinding(parentScopeId, sessionChildKey(nodeCtx.sessionUrl), findings, deps);
|
|
@@ -11057,6 +9871,7 @@ function chainDown(child, rootScope, mode, deps) {
|
|
|
11057
9871
|
if (incomplete.length !== 1)
|
|
11058
9872
|
return node;
|
|
11059
9873
|
recordScopeMode(node.scopeId, mode, deps);
|
|
9874
|
+
recordScopeRoot(node.scopeId, rootScope, deps);
|
|
11060
9875
|
node = incomplete[0];
|
|
11061
9876
|
}
|
|
11062
9877
|
}
|
|
@@ -11090,7 +9905,7 @@ function originContribution(level, childKey) {
|
|
|
11090
9905
|
}
|
|
11091
9906
|
}
|
|
11092
9907
|
/** Every write is keyed by child key and overwriting, so two siblings racing into the same ancestor is safe. */
|
|
11093
|
-
async function deriveClose(level, mode, deps) {
|
|
9908
|
+
async function deriveClose(level, rootScope, mode, deps) {
|
|
11094
9909
|
const [childKey, childFindings] = orderedChildFindingEntries(level.scopeId, deps)[0];
|
|
11095
9910
|
const { findings: forwarded, rollup } = consolidateRollup(level.scopeId, forwardFindings(childFindings, originContribution(level, childKey)), mode, deps);
|
|
11096
9911
|
const parent = await level.up.parent();
|
|
@@ -11098,6 +9913,7 @@ async function deriveClose(level, mode, deps) {
|
|
|
11098
9913
|
appendChildFinding(parent.scopeId, level.up.key, forwarded, deps);
|
|
11099
9914
|
reportRollup(parent.scopeId, level.up.key, rollup, deps);
|
|
11100
9915
|
recordScopeMode(level.scopeId, mode, deps);
|
|
9916
|
+
recordScopeRoot(level.scopeId, rootScope, deps);
|
|
11101
9917
|
log(level.scopeId, 'derived-close', { input: { scopeId: level.scopeId } }, deps);
|
|
11102
9918
|
return parent;
|
|
11103
9919
|
}
|
|
@@ -11107,7 +9923,7 @@ async function chainUp(parent, rootScope, mode, deps) {
|
|
|
11107
9923
|
for (;;) {
|
|
11108
9924
|
if (!level.up || !compressibleOnAscent(level.level, level.scopeId, deps))
|
|
11109
9925
|
return { kind: 'end', level };
|
|
11110
|
-
const grandParent = await deriveClose(level, mode, deps);
|
|
9926
|
+
const grandParent = await deriveClose(level, rootScope, mode, deps);
|
|
11111
9927
|
const unreviewed = queuedChildNodes(grandParent, rootScope, mode, deps).find(child => child.scopeId !== level.scopeId && !isCompleted(child.scopeId, deps));
|
|
11112
9928
|
if (unreviewed) {
|
|
11113
9929
|
const target = chainDown(unreviewed, rootScope, mode, deps);
|
|
@@ -11121,7 +9937,16 @@ async function runProgress(params) {
|
|
|
11121
9937
|
const completed = computeCompleted(scopeId, children.map(c => c.scopeId), deps);
|
|
11122
9938
|
const nextChild = completed === null ? children.find(c => !isCompleted(c.scopeId, deps)) : undefined;
|
|
11123
9939
|
const descentCall = nextChild && descend(nextChild);
|
|
11124
|
-
const
|
|
9940
|
+
const hasChildFindings = completed === null && !descentCall && flattenChildFindings(scopeId, deps).length > 0;
|
|
9941
|
+
const next = buildProgressNext({
|
|
9942
|
+
level,
|
|
9943
|
+
rootScope,
|
|
9944
|
+
completed,
|
|
9945
|
+
descentCall,
|
|
9946
|
+
endCall,
|
|
9947
|
+
hasChildFindings,
|
|
9948
|
+
parentProgressCall,
|
|
9949
|
+
});
|
|
11125
9950
|
const stillInvestigating = completed === null && descentCall !== undefined;
|
|
11126
9951
|
// Each branch below builds its own complete literal, keys already in the order they must
|
|
11127
9952
|
// serialize in — `next` last, however many of findings/resolution/regions precede it — rather
|
|
@@ -11136,14 +9961,38 @@ async function runProgress(params) {
|
|
|
11136
9961
|
recordToolTelemetry({ resolve_decisions: rollup.resolution });
|
|
11137
9962
|
return { completed, findings, clusters, resolution: rollup.resolution, regions: rollup.regions, next };
|
|
11138
9963
|
}
|
|
9964
|
+
/** Below batch only; `undefined` when nothing recorded on the parent suggests an enclosing walk. */
|
|
9965
|
+
function inferEnclosingReview(parent, parentScopeId, deps) {
|
|
9966
|
+
// A stored root narrower than the parent, or not a scope at all, would make `widen` a call
|
|
9967
|
+
// the schema or the walk rejects.
|
|
9968
|
+
const stored = getScopeRoot(parentScopeId, deps);
|
|
9969
|
+
const root = isScopeType(stored) && isAtOrAbove(stored, parent) ? stored : undefined;
|
|
9970
|
+
if (!root && !getScopeMode(parentScopeId, deps))
|
|
9971
|
+
return undefined;
|
|
9972
|
+
return {
|
|
9973
|
+
scope: parent,
|
|
9974
|
+
rootScope: root !== null && root !== void 0 ? root : parent,
|
|
9975
|
+
state: getCompletion(parentScopeId, deps) ? 'closed-earlier' : 'in-progress',
|
|
9976
|
+
};
|
|
9977
|
+
}
|
|
9978
|
+
function enclosingWarning(level, enclosing) {
|
|
9979
|
+
return enclosing.state === 'in-progress'
|
|
9980
|
+
? `This call omitted rootScope, so the review closed here at scope "${level}" — but the enclosing ${enclosing.scope} is mid-review, rooted at "${enclosing.rootScope}". If you are continuing that review, call the tool named in review.widen.tool with review.widen.args unchanged; this ${level}'s findings are already recorded for it.`
|
|
9981
|
+
: `The enclosing ${enclosing.scope}'s summary predates this ${level}'s new findings; to refresh it, call the tool named in review.widen.tool with review.widen.args unchanged.`;
|
|
9982
|
+
}
|
|
11139
9983
|
async function runEnd(params) {
|
|
11140
|
-
|
|
9984
|
+
var _a;
|
|
9985
|
+
const { level, toolName, rootScope, rootScopeOmitted, scopeId, ownChildren, progressCall, pushUpTo, finalize, getSiblings, descend, parentProgressCall, ascent, mode, doneMessage, deps, } = params;
|
|
11141
9986
|
const stillIncomplete = ownChildren.some(c => !isCompleted(c.scopeId, deps));
|
|
11142
9987
|
if (stillIncomplete) {
|
|
11143
9988
|
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.`;
|
|
11144
9989
|
countGateRejection();
|
|
11145
9990
|
log(scopeId, toolName, { input: { scopeId }, error: instruction }, deps);
|
|
11146
|
-
return {
|
|
9991
|
+
return {
|
|
9992
|
+
persisted: false,
|
|
9993
|
+
next: { instruction: `${instruction} ${rootReminder(rootScope)}`, calls: [progressCall] },
|
|
9994
|
+
reachedRoot: false,
|
|
9995
|
+
};
|
|
11147
9996
|
}
|
|
11148
9997
|
const { findings, rollup } = await finalize();
|
|
11149
9998
|
const count = Array.isArray(findings) ? findings.length : undefined;
|
|
@@ -11156,6 +10005,7 @@ async function runEnd(params) {
|
|
|
11156
10005
|
appendChildFinding(pushUpTo.parentScopeId, pushUpTo.childKey, findings, deps);
|
|
11157
10006
|
reportRollup(pushUpTo.parentScopeId, pushUpTo.childKey, rollup, deps);
|
|
11158
10007
|
}
|
|
10008
|
+
const reachedRoot = hasReachedRootScope(level, rootScope);
|
|
11159
10009
|
const siblings = await getSiblings();
|
|
11160
10010
|
const incompleteSibling = siblings.find(s => !isCompleted(s.scopeId, deps));
|
|
11161
10011
|
// No incomplete sibling means the parent's `_progress` could only answer "call `_end`", which is already known here.
|
|
@@ -11164,7 +10014,7 @@ async function runEnd(params) {
|
|
|
11164
10014
|
if (descend)
|
|
11165
10015
|
target = { kind: 'call', ...descend(incompleteSibling) };
|
|
11166
10016
|
}
|
|
11167
|
-
else if (ascent && !
|
|
10017
|
+
else if (ascent && !reachedRoot) {
|
|
11168
10018
|
target = await chainUp(ascent(), rootScope, mode, deps);
|
|
11169
10019
|
}
|
|
11170
10020
|
const next = buildEndNext({
|
|
@@ -11180,26 +10030,23 @@ async function runEnd(params) {
|
|
|
11180
10030
|
findings: target.level.findings(),
|
|
11181
10031
|
clusters: target.level.clusters(),
|
|
11182
10032
|
},
|
|
10033
|
+
hasChildFindings: flattenChildFindings(target.level.scopeId, deps).length > 0,
|
|
11183
10034
|
}
|
|
11184
10035
|
: undefined,
|
|
11185
10036
|
parentProgressCall,
|
|
11186
10037
|
doneMessage,
|
|
11187
10038
|
});
|
|
11188
|
-
|
|
10039
|
+
if (!reachedRoot || !parentProgressCall || !pushUpTo)
|
|
10040
|
+
return { persisted: true, next, findings, rollup, reachedRoot };
|
|
10041
|
+
const parent = parentProgressCall.args.scope;
|
|
10042
|
+
const enclosing = rootScopeOmitted ? inferEnclosingReview(parent, pushUpTo.parentScopeId, deps) : undefined;
|
|
10043
|
+
const widen = { ...parentProgressCall, args: { ...parentProgressCall.args, rootScope: (_a = enclosing === null || enclosing === void 0 ? void 0 : enclosing.rootScope) !== null && _a !== void 0 ? _a : parent } };
|
|
10044
|
+
const instruction = enclosing ? `${next.instruction} ${enclosingWarning(level, enclosing)}` : next.instruction;
|
|
10045
|
+
return { persisted: true, next: { ...next, instruction }, findings, rollup, reachedRoot, widen, enclosing };
|
|
11189
10046
|
}
|
|
11190
10047
|
/**
|
|
11191
|
-
*
|
|
11192
|
-
*
|
|
11193
|
-
* parent call — folds each finding's `example` link into its `summary` text as a markdown link
|
|
11194
|
-
* and drops the standalone `example` key. This is what makes the link survive into the report
|
|
11195
|
-
* structurally: past this point the model is only ever copying/paraphrasing `summary` prose, so a
|
|
11196
|
-
* link embedded in that same string travels with it, instead of sitting in a separate field a
|
|
11197
|
-
* "compose a readable report" pass can quietly leave behind.
|
|
11198
|
-
*
|
|
11199
|
-
* Below the root, both fields are left separate and untouched — the next level up still needs its
|
|
11200
|
-
* own `example` input when consolidating (see `SummaryExampleShape`), and folding early would
|
|
11201
|
-
* bake this level's link into a `summary` that gets restated, not carried forward verbatim, at
|
|
11202
|
-
* the next hop.
|
|
10048
|
+
* At `reachedRoot` the model only paraphrases `summary` into the user's report, so the link must live inside it;
|
|
10049
|
+
* below the root the next level still consolidates from a separate `example`.
|
|
11203
10050
|
*/
|
|
11204
10051
|
function foldExampleIntoSummary(findings) {
|
|
11205
10052
|
if (!Array.isArray(findings))
|
|
@@ -11211,20 +10058,20 @@ function foldExampleIntoSummary(findings) {
|
|
|
11211
10058
|
return { ...rest, summary: `${summary} ([view](${example}))` };
|
|
11212
10059
|
});
|
|
11213
10060
|
}
|
|
11214
|
-
/**
|
|
11215
|
-
|
|
11216
|
-
* tallies beside it — the same merged totals `runEnd`'s own `rollup` carries. `regions` is also
|
|
11217
|
-
* attached to each finding individually (see `consolidateRollup`), where the change it describes
|
|
11218
|
-
* actually happened; the top-level copy here is just that same total, for a reader who only wants
|
|
11219
|
-
* the global count without walking every finding. `isRootScope` gates `foldExampleIntoSummary` —
|
|
11220
|
-
* see its own doc comment for why the fold only happens there.
|
|
11221
|
-
*/
|
|
11222
|
-
function endResponse(result, mode, isRootScope) {
|
|
10061
|
+
/** `review` is internal: it carries the root-only data to `tools.ts`, whose `withReviewField` merges it into the leading `review` field. */
|
|
10062
|
+
function endResponse(result, mode) {
|
|
11223
10063
|
// `next` is assigned last so it always serializes as this response's final key, however many
|
|
11224
10064
|
// of findings/resolution/regions precede it.
|
|
11225
10065
|
const response = {};
|
|
10066
|
+
if (result.reachedRoot) {
|
|
10067
|
+
response.review = {
|
|
10068
|
+
reachedRoot: true,
|
|
10069
|
+
...(result.widen && { widen: result.widen }),
|
|
10070
|
+
...(result.enclosing && { enclosing: result.enclosing }),
|
|
10071
|
+
};
|
|
10072
|
+
}
|
|
11226
10073
|
if (result.persisted)
|
|
11227
|
-
response.findings =
|
|
10074
|
+
response.findings = result.reachedRoot ? foldExampleIntoSummary(result.findings) : result.findings;
|
|
11228
10075
|
if (result.persisted && mode === 'resolve' && result.rollup) {
|
|
11229
10076
|
response.resolution = result.rollup.resolution;
|
|
11230
10077
|
response.regions = result.rollup.regions;
|
|
@@ -11271,7 +10118,8 @@ function checkModeAgreesWithParent(params) {
|
|
|
11271
10118
|
if (!parentMode || parentMode === mode)
|
|
11272
10119
|
return null;
|
|
11273
10120
|
const instruction = `This call passed mode "${mode}", but its parent scope is already being reviewed in mode "${parentMode}". ` +
|
|
11274
|
-
`Call ${retryCall.tool} again with mode: "${parentMode}" — every level of one investigation must share the same mode
|
|
10121
|
+
`Call ${retryCall.tool} again with mode: "${parentMode}" — every level of one investigation must share the same mode. ` +
|
|
10122
|
+
rootReminder(retryCall.args.rootScope);
|
|
11275
10123
|
countGateRejection();
|
|
11276
10124
|
log(parentScopeId, retryCall.tool, { input: { parentScopeId, mode }, error: instruction }, deps);
|
|
11277
10125
|
return { instruction, calls: [{ ...retryCall, args: { ...retryCall.args, mode: parentMode } }] };
|
|
@@ -11286,6 +10134,39 @@ function checkParentModeMismatch(level, rootScope, parentScopeId, mode, retryCal
|
|
|
11286
10134
|
? null
|
|
11287
10135
|
: checkModeAgreesWithParent({ parentScopeId, mode, retryCall, deps });
|
|
11288
10136
|
}
|
|
10137
|
+
/** Nearest first: the call's own scope, its session (step level only), its batch. */
|
|
10138
|
+
function midWalkCandidates(own, scopeId, sessionUrl) {
|
|
10139
|
+
const session = own === 'step' ? [{ scope: 'session', scopeId: sessionScopeId(sessionUrl) }] : [];
|
|
10140
|
+
return [{ scope: own, scopeId }, ...session, { scope: 'batch', scopeId: rootScopeId(scopeId) }];
|
|
10141
|
+
}
|
|
10142
|
+
/** Reads `roots` only; a mid-walk rootless call is redirected before anything is discarded or written. */
|
|
10143
|
+
function checkRootlessMidWalk(params) {
|
|
10144
|
+
const { level, scopeId, sessionUrl, rootScopeOmitted, retryCall, restart, deps } = params;
|
|
10145
|
+
if (!rootScopeOmitted)
|
|
10146
|
+
return null;
|
|
10147
|
+
const own = resolveRootScope(level, undefined);
|
|
10148
|
+
const root = midWalkCandidates(own, scopeId, sessionUrl)
|
|
10149
|
+
.map(candidate => {
|
|
10150
|
+
const stored = getScopeRoot(candidate.scopeId, deps);
|
|
10151
|
+
const open = isScopeType(stored) &&
|
|
10152
|
+
isAtOrAbove(stored, candidate.scope) &&
|
|
10153
|
+
!isAtOrAbove(own, stored) &&
|
|
10154
|
+
getCompletion(candidate.scopeId, deps) === undefined;
|
|
10155
|
+
return open ? stored : undefined;
|
|
10156
|
+
})
|
|
10157
|
+
.find(stored => stored !== undefined);
|
|
10158
|
+
if (!root)
|
|
10159
|
+
return null;
|
|
10160
|
+
const instruction = `This call omitted rootScope, but this ${own} belongs to a review that is still in progress and rooted at "${root}"; without rootScope it would be narrowed to this ${own} alone. Nothing was recorded. ` +
|
|
10161
|
+
`Call ${retryCall.tool} again with rootScope: "${root}" and every other argument unchanged — next.calls holds exactly that call. ` +
|
|
10162
|
+
`To review this ${own} on its own instead, pass rootScope: "${own}" explicitly. ${rootReminder(root)}`;
|
|
10163
|
+
countGateRejection();
|
|
10164
|
+
log(scopeId, retryCall.tool, { input: { scopeId, rootScopeOmitted: true }, error: instruction }, deps);
|
|
10165
|
+
return {
|
|
10166
|
+
instruction,
|
|
10167
|
+
calls: [{ ...retryCall, args: { ...retryCall.args, rootScope: root, ...(restart ? { restart: true } : {}) } }],
|
|
10168
|
+
};
|
|
10169
|
+
}
|
|
11289
10170
|
// ---------------------------------------------------------------------------
|
|
11290
10171
|
// `restart` — discards every cached record for a scope and everything beneath it, so a caller
|
|
11291
10172
|
// that wants to independently re-review something already reviewed (by this investigation or a
|
|
@@ -11299,6 +10180,7 @@ function discardSubtree(level, ctx, deps) {
|
|
|
11299
10180
|
clearChildFindings(scopeId, deps);
|
|
11300
10181
|
clearChildFindings(rollupScopeId(scopeId), deps);
|
|
11301
10182
|
clearScopeMode(scopeId, deps);
|
|
10183
|
+
clearScopeRoot(scopeId, deps);
|
|
11302
10184
|
clearQueuedChildKeys(scopeId, deps);
|
|
11303
10185
|
clearUnreadyChildren(scopeId, deps);
|
|
11304
10186
|
clearDiscoveredChildren(scopeId, deps);
|
|
@@ -11317,15 +10199,16 @@ async function maybeDiscard(restart, level, ctx, deps) {
|
|
|
11317
10199
|
// to promote.
|
|
11318
10200
|
// ---------------------------------------------------------------------------
|
|
11319
10201
|
async function promoteIfNeeded(params) {
|
|
11320
|
-
const { level, scopeId, ctx,
|
|
10202
|
+
const { level, scopeId, ctx, mode, restart, keys, deps } = params;
|
|
11321
10203
|
if (restart || mode !== 'resolve' || !isCompleted(scopeId, deps) || getScopeMode(scopeId, deps) !== 'inspect')
|
|
11322
10204
|
return;
|
|
11323
|
-
await promoteSubtreeToResolve(level,
|
|
10205
|
+
await promoteSubtreeToResolve(level, ctx, keys, deps);
|
|
11324
10206
|
}
|
|
11325
|
-
/** `promoteIfNeeded` followed by `recordScopeMode` — every level's own
|
|
10207
|
+
/** `promoteIfNeeded` followed by `recordScopeMode`/`recordScopeRoot` — every level's own sequence, in this same order. */
|
|
11326
10208
|
async function promoteAndRecordMode(params) {
|
|
11327
10209
|
await promoteIfNeeded(params);
|
|
11328
10210
|
recordScopeMode(params.scopeId, params.mode, params.deps);
|
|
10211
|
+
recordScopeRoot(params.scopeId, params.rootScope, params.deps);
|
|
11329
10212
|
}
|
|
11330
10213
|
// ---------------------------------------------------------------------------
|
|
11331
10214
|
// diff_report's hard gates — verifies eyes_inspect_image_diff and both baseline/checkpoint
|
|
@@ -11464,14 +10347,19 @@ async function withGateLog(toolName, scopeId, input, deps, fn) {
|
|
|
11464
10347
|
// ---------------------------------------------------------------------------
|
|
11465
10348
|
const ASK_TO_RESOLVE = ' Unless you are already resolving this investigation, ask the user whether to proceed to resolve the differences found.';
|
|
11466
10349
|
function finalDoneMessage(params) {
|
|
11467
|
-
const {
|
|
10350
|
+
const { rootScope, where, findingsCount, hasExampleLink, mentionEnvironment, runningSessionCount = 0, debugLogPath, } = params;
|
|
10351
|
+
const opener = `The review the user started at scope "${rootScope}" (${where}) is complete`;
|
|
10352
|
+
const parent = parentLevelOf(rootScope);
|
|
10353
|
+
const widenClause = parent
|
|
10354
|
+
? ` Nothing further is needed unless the user wants a wider review; to widen it, call the tool named in review.widen.tool with review.widen.args unchanged (${EYES_REVIEW_TOOLS.progress} at scope "${parent}").`
|
|
10355
|
+
: ' This is the widest scope; nothing further is needed.';
|
|
11468
10356
|
const runningClause = runningSessionCount > 0
|
|
11469
10357
|
? ` ${runningSessionCount} session(s) are still running and could not be reviewed. Mention this to the user and suggest re-running this review once those sessions complete, or are aborted manually, to review them too.`
|
|
11470
10358
|
: '';
|
|
11471
10359
|
const debugLogClause = ` This investigation's debug log is at ${debugLogPath}, for troubleshooting only — never mention it in ` +
|
|
11472
10360
|
`the report above; reveal it only if the user explicitly asks where the log is.`;
|
|
11473
10361
|
if (findingsCount === 0) {
|
|
11474
|
-
return `${
|
|
10362
|
+
return `${opener} — no differences were found. Report this to the user.${widenClause}${runningClause}${debugLogClause}`;
|
|
11475
10363
|
}
|
|
11476
10364
|
const exampleClause = hasExampleLink
|
|
11477
10365
|
? ', each with its example link already folded into the summary text — reproduce it exactly, never strip it out,'
|
|
@@ -11479,9 +10367,9 @@ function finalDoneMessage(params) {
|
|
|
11479
10367
|
const environmentClause = mentionEnvironment
|
|
11480
10368
|
? ' Call out any finding that occurs in one environment (browser/OS/viewport) but not others.'
|
|
11481
10369
|
: '';
|
|
11482
|
-
return (`${
|
|
10370
|
+
return (`${opener}: ${findingsCount} finding${findingsCount === 1 ? '' : 's'}. Produce a report for the user, ordered: known bugs first (most severe first), then unexpected changes, then ` +
|
|
11483
10371
|
`expected changes last — a finding that's both a known bug and an expected change is still a bug, so order it with the bugs. One entry per ` +
|
|
11484
|
-
`distinct diff (skip duplicates)${exampleClause} noting whether it's expected or a bug.${environmentClause}${ASK_TO_RESOLVE}${runningClause}${debugLogClause}`);
|
|
10372
|
+
`distinct diff (skip duplicates)${exampleClause} noting whether it's expected or a bug.${environmentClause}${ASK_TO_RESOLVE}${widenClause}${runningClause}${debugLogClause}`);
|
|
11485
10373
|
}
|
|
11486
10374
|
// ---------------------------------------------------------------------------
|
|
11487
10375
|
// One exported command function per (tool, scope) pair — `tools.ts` dispatches on `scope`
|
|
@@ -11583,13 +10471,14 @@ async function batchProgress(params) {
|
|
|
11583
10471
|
});
|
|
11584
10472
|
}
|
|
11585
10473
|
async function batchEnd(params) {
|
|
11586
|
-
const { batchUrl, findings, keys, rootScope, mode, restart, deps } = params;
|
|
10474
|
+
const { batchUrl, findings, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11587
10475
|
const scopeId = batchScopeId(batchUrl);
|
|
11588
10476
|
await maybeDiscard(restart, 'batch', { batchUrl }, deps);
|
|
11589
10477
|
await promoteAndRecordMode({ level: 'batch', scopeId, ctx: { batchUrl }, rootScope, mode, restart, keys, deps });
|
|
11590
10478
|
const children = await batchChildren(batchUrl, keys, rootScope, mode, deps);
|
|
11591
10479
|
const doneMessage = finalDoneMessage({
|
|
11592
|
-
|
|
10480
|
+
rootScope: 'batch',
|
|
10481
|
+
where: `batch ${batchUrl}`,
|
|
11593
10482
|
findingsCount: findings.length,
|
|
11594
10483
|
hasExampleLink: true,
|
|
11595
10484
|
mentionEnvironment: true,
|
|
@@ -11601,6 +10490,7 @@ async function batchEnd(params) {
|
|
|
11601
10490
|
toolName: EYES_REVIEW_TOOLS.end,
|
|
11602
10491
|
scopeId,
|
|
11603
10492
|
rootScope,
|
|
10493
|
+
rootScopeOmitted,
|
|
11604
10494
|
ownChildren: children,
|
|
11605
10495
|
finalize: verifyAndConsolidate(scopeId, batchScopeId(batchUrl), { batchUrl, findings }, findings, mode, deps),
|
|
11606
10496
|
progressCall: reviewProgressCall('batch', { batchUrl }, rootScope, mode),
|
|
@@ -11609,13 +10499,17 @@ async function batchEnd(params) {
|
|
|
11609
10499
|
doneMessage,
|
|
11610
10500
|
deps,
|
|
11611
10501
|
});
|
|
11612
|
-
return endResponse(result, mode
|
|
10502
|
+
return endResponse(result, mode);
|
|
11613
10503
|
}
|
|
11614
10504
|
async function scenarioProgress(params) {
|
|
11615
|
-
const { batchUrl, scenarioName, keys, rootScope, mode, restart, deps } = params;
|
|
10505
|
+
const { batchUrl, scenarioName, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11616
10506
|
const scopeId = scenarioScopeId(batchUrl, scenarioName);
|
|
10507
|
+
const retryCall = reviewProgressCall('scenario', { batchUrl, scenarioName }, rootScope, mode);
|
|
10508
|
+
const midWalk = checkRootlessMidWalk({ level: 'scenario', scopeId, rootScopeOmitted, retryCall, restart, deps });
|
|
10509
|
+
if (midWalk)
|
|
10510
|
+
return { completed: null, next: midWalk };
|
|
11617
10511
|
await maybeDiscard(restart, 'scenario', { batchUrl, scenarioName }, deps);
|
|
11618
|
-
const mismatch = checkParentModeMismatch('scenario', rootScope, batchScopeId(batchUrl), mode,
|
|
10512
|
+
const mismatch = checkParentModeMismatch('scenario', rootScope, batchScopeId(batchUrl), mode, retryCall, deps);
|
|
11619
10513
|
if (mismatch)
|
|
11620
10514
|
return { completed: null, next: mismatch };
|
|
11621
10515
|
await promoteAndRecordMode({
|
|
@@ -11642,10 +10536,14 @@ async function scenarioProgress(params) {
|
|
|
11642
10536
|
});
|
|
11643
10537
|
}
|
|
11644
10538
|
async function scenarioEnd(params) {
|
|
11645
|
-
const { batchUrl, scenarioName, findings, keys, rootScope, mode, restart, deps } = params;
|
|
10539
|
+
const { batchUrl, scenarioName, findings, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11646
10540
|
const scopeId = scenarioScopeId(batchUrl, scenarioName);
|
|
10541
|
+
const retryCall = reviewEndCall('scenario', { batchUrl, scenarioName, findings }, rootScope, mode);
|
|
10542
|
+
const midWalk = checkRootlessMidWalk({ level: 'scenario', scopeId, rootScopeOmitted, retryCall, restart, deps });
|
|
10543
|
+
if (midWalk)
|
|
10544
|
+
return { next: midWalk };
|
|
11647
10545
|
await maybeDiscard(restart, 'scenario', { batchUrl, scenarioName }, deps);
|
|
11648
|
-
const mismatch = checkParentModeMismatch('scenario', rootScope, batchScopeId(batchUrl), mode,
|
|
10546
|
+
const mismatch = checkParentModeMismatch('scenario', rootScope, batchScopeId(batchUrl), mode, retryCall, deps);
|
|
11649
10547
|
if (mismatch)
|
|
11650
10548
|
return { next: mismatch };
|
|
11651
10549
|
await promoteAndRecordMode({
|
|
@@ -11660,7 +10558,8 @@ async function scenarioEnd(params) {
|
|
|
11660
10558
|
});
|
|
11661
10559
|
const children = await scenarioChildren(batchUrl, scenarioName, keys, rootScope, mode, deps);
|
|
11662
10560
|
const doneMessage = finalDoneMessage({
|
|
11663
|
-
|
|
10561
|
+
rootScope: 'scenario',
|
|
10562
|
+
where: `scenario "${scenarioName}"`,
|
|
11664
10563
|
findingsCount: findings.length,
|
|
11665
10564
|
hasExampleLink: true,
|
|
11666
10565
|
mentionEnvironment: true,
|
|
@@ -11672,12 +10571,11 @@ async function scenarioEnd(params) {
|
|
|
11672
10571
|
toolName: EYES_REVIEW_TOOLS.end,
|
|
11673
10572
|
scopeId,
|
|
11674
10573
|
rootScope,
|
|
10574
|
+
rootScopeOmitted,
|
|
11675
10575
|
ownChildren: children,
|
|
11676
10576
|
finalize: verifyAndConsolidate(scopeId, batchScopeId(batchUrl), { batchUrl, scenarioName, findings }, findings, mode, deps),
|
|
11677
10577
|
progressCall: reviewProgressCall('scenario', { batchUrl, scenarioName }, rootScope, mode),
|
|
11678
|
-
pushUpTo:
|
|
11679
|
-
? undefined
|
|
11680
|
-
: { parentScopeId: batchScopeId(batchUrl), childKey: scenarioChildKey(scenarioName) },
|
|
10578
|
+
pushUpTo: { parentScopeId: batchScopeId(batchUrl), childKey: scenarioChildKey(scenarioName) },
|
|
11681
10579
|
getSiblings: async () => (await batchChildren(batchUrl, keys, rootScope, mode, deps)).filter(s => s.scopeId !== scopeId),
|
|
11682
10580
|
descend: sibling => descentTarget('batch', { batchUrl }, sibling.key, rootScope, mode, deps),
|
|
11683
10581
|
parentProgressCall: reviewProgressCall('batch', { batchUrl }, rootScope, mode),
|
|
@@ -11686,7 +10584,7 @@ async function scenarioEnd(params) {
|
|
|
11686
10584
|
doneMessage,
|
|
11687
10585
|
deps,
|
|
11688
10586
|
});
|
|
11689
|
-
return endResponse(result, mode
|
|
10587
|
+
return endResponse(result, mode);
|
|
11690
10588
|
}
|
|
11691
10589
|
// ---------------------------------------------------------------------------
|
|
11692
10590
|
// A queued session whose entity has genuinely stopped existing (deleted, merged, otherwise
|
|
@@ -11713,8 +10611,12 @@ function missingSessionFinding(sessionUrl) {
|
|
|
11713
10611
|
};
|
|
11714
10612
|
}
|
|
11715
10613
|
async function sessionProgress(params) {
|
|
11716
|
-
const { sessionUrl, keys, rootScope, mode, restart, deps } = params;
|
|
10614
|
+
const { sessionUrl, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11717
10615
|
const scopeId = sessionScopeId(sessionUrl);
|
|
10616
|
+
const retryCall = reviewProgressCall('session', { sessionUrl }, rootScope, mode);
|
|
10617
|
+
const midWalk = checkRootlessMidWalk({ level: 'session', scopeId, rootScopeOmitted, retryCall, restart, deps });
|
|
10618
|
+
if (midWalk)
|
|
10619
|
+
return { completed: null, next: midWalk };
|
|
11718
10620
|
await maybeDiscard(restart, 'session', { sessionUrl }, deps);
|
|
11719
10621
|
// Fetched before computing children (rather than going through the sessionChildren wrapper,
|
|
11720
10622
|
// which would fetch it again) so the mode gate below can run — and, on a mismatch, exit —
|
|
@@ -11736,7 +10638,7 @@ async function sessionProgress(params) {
|
|
|
11736
10638
|
},
|
|
11737
10639
|
};
|
|
11738
10640
|
}
|
|
11739
|
-
const mismatch = checkParentModeMismatch('session', rootScope, scenarioScopeIdForSession(sessionUrl, session.sessionName), mode,
|
|
10641
|
+
const mismatch = checkParentModeMismatch('session', rootScope, scenarioScopeIdForSession(sessionUrl, session.sessionName), mode, retryCall, deps);
|
|
11740
10642
|
if (mismatch)
|
|
11741
10643
|
return { completed: null, next: mismatch };
|
|
11742
10644
|
await promoteAndRecordMode({ level: 'session', scopeId, ctx: { sessionUrl }, rootScope, mode, restart, keys, deps });
|
|
@@ -11754,8 +10656,12 @@ async function sessionProgress(params) {
|
|
|
11754
10656
|
});
|
|
11755
10657
|
}
|
|
11756
10658
|
async function sessionEnd(params) {
|
|
11757
|
-
const { sessionUrl, findings, keys, rootScope, mode, restart, deps } = params;
|
|
10659
|
+
const { sessionUrl, findings, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11758
10660
|
const scopeId = sessionScopeId(sessionUrl);
|
|
10661
|
+
const retryCall = reviewEndCall('session', { sessionUrl, findings }, rootScope, mode);
|
|
10662
|
+
const midWalk = checkRootlessMidWalk({ level: 'session', scopeId, rootScopeOmitted, retryCall, restart, deps });
|
|
10663
|
+
if (midWalk)
|
|
10664
|
+
return { next: midWalk };
|
|
11759
10665
|
await maybeDiscard(restart, 'session', { sessionUrl }, deps);
|
|
11760
10666
|
let session;
|
|
11761
10667
|
try {
|
|
@@ -11775,13 +10681,14 @@ async function sessionEnd(params) {
|
|
|
11775
10681
|
}
|
|
11776
10682
|
const { baseUrl, batchId, accountId } = await parseSessionUrlVerified(sessionUrl, keys);
|
|
11777
10683
|
const batchUrl = buildBatchUrl({ baseUrl, batchId, accountId });
|
|
11778
|
-
const mismatch = checkParentModeMismatch('session', rootScope, scenarioScopeIdForSession(sessionUrl, session.sessionName), mode,
|
|
10684
|
+
const mismatch = checkParentModeMismatch('session', rootScope, scenarioScopeIdForSession(sessionUrl, session.sessionName), mode, retryCall, deps);
|
|
11779
10685
|
if (mismatch)
|
|
11780
10686
|
return { next: mismatch };
|
|
11781
10687
|
await promoteAndRecordMode({ level: 'session', scopeId, ctx: { sessionUrl }, rootScope, mode, restart, keys, deps });
|
|
11782
10688
|
const children = await sessionStepChildren({ sessionUrl, session, mode, keys, deps });
|
|
11783
10689
|
const doneMessage = finalDoneMessage({
|
|
11784
|
-
|
|
10690
|
+
rootScope: 'session',
|
|
10691
|
+
where: `session ${sessionUrl}`,
|
|
11785
10692
|
findingsCount: findings.length,
|
|
11786
10693
|
hasExampleLink: true,
|
|
11787
10694
|
mentionEnvironment: false,
|
|
@@ -11792,15 +10699,14 @@ async function sessionEnd(params) {
|
|
|
11792
10699
|
toolName: EYES_REVIEW_TOOLS.end,
|
|
11793
10700
|
scopeId,
|
|
11794
10701
|
rootScope,
|
|
10702
|
+
rootScopeOmitted,
|
|
11795
10703
|
ownChildren: children,
|
|
11796
10704
|
finalize: verifyAndConsolidate(scopeId, sessionScopeId(sessionUrl), { sessionUrl, findings }, findings, mode, deps),
|
|
11797
10705
|
progressCall: reviewProgressCall('session', { sessionUrl }, rootScope, mode),
|
|
11798
|
-
pushUpTo:
|
|
11799
|
-
|
|
11800
|
-
:
|
|
11801
|
-
|
|
11802
|
-
childKey: sessionChildKey(sessionUrl),
|
|
11803
|
-
},
|
|
10706
|
+
pushUpTo: {
|
|
10707
|
+
parentScopeId: scenarioScopeIdForSession(sessionUrl, session.sessionName),
|
|
10708
|
+
childKey: sessionChildKey(sessionUrl),
|
|
10709
|
+
},
|
|
11804
10710
|
getSiblings: async () => (await scenarioChildren(batchUrl, session.sessionName, keys, rootScope, mode, deps)).filter(s => s.scopeId !== scopeId),
|
|
11805
10711
|
descend: sibling => descentTarget('scenario', { batchUrl, scenarioName: session.sessionName }, sibling.key, rootScope, mode, deps),
|
|
11806
10712
|
parentProgressCall: reviewProgressCall('scenario', { batchUrl, scenarioName: session.sessionName }, rootScope, mode),
|
|
@@ -11809,7 +10715,7 @@ async function sessionEnd(params) {
|
|
|
11809
10715
|
doneMessage,
|
|
11810
10716
|
deps,
|
|
11811
10717
|
});
|
|
11812
|
-
return endResponse(result, mode
|
|
10718
|
+
return endResponse(result, mode);
|
|
11813
10719
|
}
|
|
11814
10720
|
const DOM_DIFF_OBTAINABLE_RECORD = 'stepProgress:domDiffObtainable';
|
|
11815
10721
|
/** 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. */
|
|
@@ -11824,10 +10730,14 @@ function domDiffUnobtainableReason(step) {
|
|
|
11824
10730
|
}
|
|
11825
10731
|
async function stepProgress(params) {
|
|
11826
10732
|
var _a, _b;
|
|
11827
|
-
const { sessionUrl, stepIndex, keys, rootScope, mode, restart, deps } = params;
|
|
10733
|
+
const { sessionUrl, stepIndex, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11828
10734
|
const scopeId = stepScopeId(sessionUrl, stepIndex);
|
|
10735
|
+
const retryCall = reviewProgressCall('step', { sessionUrl, stepIndex }, rootScope, mode);
|
|
10736
|
+
const midWalk = checkRootlessMidWalk({ level: 'step', scopeId, sessionUrl, rootScopeOmitted, retryCall, restart, deps });
|
|
10737
|
+
if (midWalk)
|
|
10738
|
+
return { completed: null, next: midWalk };
|
|
11829
10739
|
await maybeDiscard(restart, 'step', { sessionUrl, stepIndex }, deps);
|
|
11830
|
-
const mismatch = checkParentModeMismatch('step', rootScope, sessionScopeId(sessionUrl), mode,
|
|
10740
|
+
const mismatch = checkParentModeMismatch('step', rootScope, sessionScopeId(sessionUrl), mode, retryCall, deps);
|
|
11831
10741
|
if (mismatch)
|
|
11832
10742
|
return { completed: null, next: mismatch };
|
|
11833
10743
|
await promoteAndRecordMode({
|
|
@@ -11924,10 +10834,14 @@ function prependEvidenceRound(next, params) {
|
|
|
11924
10834
|
next.instruction += ` ${unseen.length} of the ${remaining.length} areas left have no evidence yet: call ${EYES_INSPECT_TOOLS.evidence} ONCE with exactly the areaRects the first call in next.calls already carries — the other areas left already have theirs on record — then report all ${remaining.length} in the one ${EYES_REVIEW_TOOLS.diffReport} call.`;
|
|
11925
10835
|
}
|
|
11926
10836
|
async function stepEnd(params) {
|
|
11927
|
-
const { sessionUrl, stepIndex, findings, keys, rootScope, mode, restart, deps } = params;
|
|
10837
|
+
const { sessionUrl, stepIndex, findings, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11928
10838
|
const scopeId = stepScopeId(sessionUrl, stepIndex);
|
|
10839
|
+
const retryCall = reviewEndCall('step', { sessionUrl, stepIndex, findings }, rootScope, mode);
|
|
10840
|
+
const midWalk = checkRootlessMidWalk({ level: 'step', scopeId, sessionUrl, rootScopeOmitted, retryCall, restart, deps });
|
|
10841
|
+
if (midWalk)
|
|
10842
|
+
return { next: midWalk };
|
|
11929
10843
|
await maybeDiscard(restart, 'step', { sessionUrl, stepIndex }, deps);
|
|
11930
|
-
const mismatch = checkParentModeMismatch('step', rootScope, sessionScopeId(sessionUrl), mode,
|
|
10844
|
+
const mismatch = checkParentModeMismatch('step', rootScope, sessionScopeId(sessionUrl), mode, retryCall, deps);
|
|
11931
10845
|
if (mismatch)
|
|
11932
10846
|
return { next: mismatch };
|
|
11933
10847
|
await promoteAndRecordMode({
|
|
@@ -11952,7 +10866,8 @@ async function stepEnd(params) {
|
|
|
11952
10866
|
let action = null;
|
|
11953
10867
|
let resolution = emptyRollup().resolution;
|
|
11954
10868
|
const doneMessage = finalDoneMessage({
|
|
11955
|
-
|
|
10869
|
+
rootScope: 'step',
|
|
10870
|
+
where: `stepIndex ${stepIndex} of session ${sessionUrl}`,
|
|
11956
10871
|
findingsCount: findings.length,
|
|
11957
10872
|
hasExampleLink: true,
|
|
11958
10873
|
mentionEnvironment: false,
|
|
@@ -11963,6 +10878,7 @@ async function stepEnd(params) {
|
|
|
11963
10878
|
toolName: EYES_REVIEW_TOOLS.end,
|
|
11964
10879
|
scopeId,
|
|
11965
10880
|
rootScope,
|
|
10881
|
+
rootScopeOmitted,
|
|
11966
10882
|
ownChildren: children,
|
|
11967
10883
|
finalize: async () => {
|
|
11968
10884
|
const childFindings = flattenChildFindings(scopeId, deps);
|
|
@@ -12000,9 +10916,7 @@ async function stepEnd(params) {
|
|
|
12000
10916
|
return { findings: findingsWithExamples, rollup: { resolution, regions: rollup.regions } };
|
|
12001
10917
|
},
|
|
12002
10918
|
progressCall: reviewProgressCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
12003
|
-
pushUpTo:
|
|
12004
|
-
? undefined
|
|
12005
|
-
: { parentScopeId: sessionScopeId(sessionUrl), childKey: stepChildKey(stepIndex) },
|
|
10919
|
+
pushUpTo: { parentScopeId: sessionScopeId(sessionUrl), childKey: stepChildKey(stepIndex) },
|
|
12006
10920
|
getSiblings: async () => (await sessionChildren({ sessionUrl, keys, mode, deps })).filter(s => s.scopeId !== scopeId),
|
|
12007
10921
|
descend: sibling => descentTarget('session', { sessionUrl }, sibling.key, rootScope, mode, deps),
|
|
12008
10922
|
parentProgressCall: reviewProgressCall('session', { sessionUrl }, rootScope, mode),
|
|
@@ -12021,13 +10935,10 @@ async function stepEnd(params) {
|
|
|
12021
10935
|
doneMessage,
|
|
12022
10936
|
deps,
|
|
12023
10937
|
});
|
|
12024
|
-
// Captured before describeStepOutcome appends its own sentence below — otherwise the
|
|
12025
|
-
// instruction would no longer match `doneMessage` verbatim even at the true rootScope.
|
|
12026
|
-
const isRootScope = result.next.instruction === doneMessage;
|
|
12027
10938
|
if (result.persisted && mode === 'resolve') {
|
|
12028
10939
|
result.next.instruction += ` ${describeStepOutcome(action, resolution)}`;
|
|
12029
10940
|
}
|
|
12030
|
-
return endResponse(result, mode
|
|
10941
|
+
return endResponse(result, mode);
|
|
12031
10942
|
}
|
|
12032
10943
|
async function diffReport(params) {
|
|
12033
10944
|
const { sessionUrl, stepIndex, areaRect, findings, sameAs, keys, rootScope, mode, restart, groupIndex, deps } = params;
|
|
@@ -12040,7 +10951,6 @@ async function diffReport(params) {
|
|
|
12040
10951
|
level: 'diff',
|
|
12041
10952
|
scopeId,
|
|
12042
10953
|
ctx: { sessionUrl, stepIndex, areaRect },
|
|
12043
|
-
rootScope,
|
|
12044
10954
|
mode,
|
|
12045
10955
|
restart,
|
|
12046
10956
|
keys,
|
|
@@ -12083,9 +10993,7 @@ async function diffReport(params) {
|
|
|
12083
10993
|
};
|
|
12084
10994
|
},
|
|
12085
10995
|
progressCall: reviewProgressCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
12086
|
-
pushUpTo:
|
|
12087
|
-
? undefined
|
|
12088
|
-
: { parentScopeId: stepScopeId(sessionUrl, stepIndex), childKey: diffChildKey(areaRect) },
|
|
10996
|
+
pushUpTo: { parentScopeId: stepScopeId(sessionUrl, stepIndex), childKey: diffChildKey(areaRect) },
|
|
12089
10997
|
getSiblings: async () => (await stepChildren(sessionUrl, stepIndex, keys, deps)).filter(s => s.scopeId !== scopeId),
|
|
12090
10998
|
descend: sibling => descentTarget('step', { sessionUrl, stepIndex }, sibling.key, rootScope, mode, deps),
|
|
12091
10999
|
parentProgressCall: reviewProgressCall('step', { sessionUrl, stepIndex }, rootScope, mode),
|
|
@@ -12099,7 +11007,19 @@ async function diffReport(params) {
|
|
|
12099
11007
|
// Sequential, not verify-all-then-apply-all: an entry may `sameAs` an area an earlier entry of this same call recorded, and in resolve mode its mask gate re-reads the regions earlier entries applied.
|
|
12100
11008
|
async function diffReportBatch(params) {
|
|
12101
11009
|
var _a, _b;
|
|
12102
|
-
const { sessionUrl, stepIndex, reports, keys, rootScope, mode, restart, deps } = params;
|
|
11010
|
+
const { sessionUrl, stepIndex, reports, keys, rootScope, rootScopeOmitted, mode, restart, deps } = params;
|
|
11011
|
+
const scopeId = stepScopeId(sessionUrl, stepIndex);
|
|
11012
|
+
const midWalk = checkRootlessMidWalk({
|
|
11013
|
+
level: 'diff',
|
|
11014
|
+
scopeId,
|
|
11015
|
+
sessionUrl,
|
|
11016
|
+
rootScopeOmitted,
|
|
11017
|
+
retryCall: nextCall(EYES_REVIEW_TOOLS.diffReport, { sessionUrl, stepIndex, reports }, rootScope, mode),
|
|
11018
|
+
restart,
|
|
11019
|
+
deps,
|
|
11020
|
+
});
|
|
11021
|
+
if (midWalk)
|
|
11022
|
+
return { groups: [], next: midWalk };
|
|
12103
11023
|
const groups = [];
|
|
12104
11024
|
let last;
|
|
12105
11025
|
for (const [groupIndex, report] of reports.entries()) {
|
|
@@ -12184,8 +11104,8 @@ async function batchStopMessage(params) {
|
|
|
12184
11104
|
// completeness live on every call; `eyes_review_end` persists findings once complete, pushing them
|
|
12185
11105
|
// up into its parent's own accumulated record so they survive a child later dropping out of its
|
|
12186
11106
|
// parent's live-children set; `rootScope` bounds how far `next` ever escalates, so a request scoped to
|
|
12187
|
-
// one entity never
|
|
12188
|
-
// resolves what it reports.
|
|
11107
|
+
// one entity never leads the model into its siblings or ancestors — it never decides whether findings
|
|
11108
|
+
// are pushed up; `mode` decides whether the traversal also resolves what it reports.
|
|
12189
11109
|
//
|
|
12190
11110
|
// This is a thin registration layer over `commands.ts`, in the same shape as
|
|
12191
11111
|
// `eyes-inspect/tools.ts`/`eyes-resolve/tools.ts`: Zod schemas, descriptions, and handlers that
|
|
@@ -12278,9 +11198,15 @@ async function resolveJsonArg(raw, argName) {
|
|
|
12278
11198
|
function recordReviewCall(scopeType, mode) {
|
|
12279
11199
|
recordToolTelemetry({ chain_source: 'review', scope_type: scopeType, mode });
|
|
12280
11200
|
}
|
|
12281
|
-
/** The
|
|
12282
|
-
function commonArgs(url, rootScope, mode, restart, deps) {
|
|
12283
|
-
return { keys: reviewApiKeyProvider(url, mode), rootScope, mode, restart, deps };
|
|
11201
|
+
/** The args every scope's own arm passes identically, once its own id(s) are resolved. */
|
|
11202
|
+
function commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps) {
|
|
11203
|
+
return { keys: reviewApiKeyProvider(url, mode), rootScope, rootScopeOmitted, mode, restart, deps };
|
|
11204
|
+
}
|
|
11205
|
+
/** `review` leads every review-family response so `next` stays the last key; an `_end` at its root supplies `reachedRoot`/`widen`/`enclosing`. */
|
|
11206
|
+
function withReviewField(result, scope, rootScope, mode) {
|
|
11207
|
+
const { review: atRoot, ...rest } = result;
|
|
11208
|
+
const review = { rootScope, mode, scope, reachedRoot: false, ...atRoot };
|
|
11209
|
+
return { review, ...rest };
|
|
12284
11210
|
}
|
|
12285
11211
|
function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
12286
11212
|
server.registerTool(EYES_REVIEW_TOOLS.progress, {
|
|
@@ -12294,13 +11220,14 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12294
11220
|
},
|
|
12295
11221
|
}, async ({ scope, batchUrl, scenarioName, sessionUrl, stepIndex, rootScope: rawRootScope, mode: rawMode, restart }) => {
|
|
12296
11222
|
const rootScope = resolveRootScope(scope, rawRootScope);
|
|
11223
|
+
const rootScopeOmitted = rawRootScope === undefined;
|
|
12297
11224
|
const mode = resolveMode(rawMode);
|
|
12298
11225
|
recordReviewCall(scope, mode);
|
|
12299
11226
|
const result = await (async () => {
|
|
12300
11227
|
switch (scope) {
|
|
12301
11228
|
case 'batch': {
|
|
12302
11229
|
const url = requireId(batchUrl, 'batchUrl', scope);
|
|
12303
|
-
return batchProgress({ batchUrl: url, ...commonArgs(url, rootScope, mode, restart, deps) });
|
|
11230
|
+
return batchProgress({ batchUrl: url, ...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps) });
|
|
12304
11231
|
}
|
|
12305
11232
|
case 'scenario': {
|
|
12306
11233
|
const url = requireId(batchUrl, 'batchUrl', scope);
|
|
@@ -12308,12 +11235,15 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12308
11235
|
return scenarioProgress({
|
|
12309
11236
|
batchUrl: url,
|
|
12310
11237
|
scenarioName: name,
|
|
12311
|
-
...commonArgs(url, rootScope, mode, restart, deps),
|
|
11238
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
12312
11239
|
});
|
|
12313
11240
|
}
|
|
12314
11241
|
case 'session': {
|
|
12315
11242
|
const url = requireId(sessionUrl, 'sessionUrl', scope);
|
|
12316
|
-
return sessionProgress({
|
|
11243
|
+
return sessionProgress({
|
|
11244
|
+
sessionUrl: url,
|
|
11245
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
11246
|
+
});
|
|
12317
11247
|
}
|
|
12318
11248
|
case 'step': {
|
|
12319
11249
|
const url = requireId(sessionUrl, 'sessionUrl', scope);
|
|
@@ -12321,12 +11251,12 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12321
11251
|
return stepProgress({
|
|
12322
11252
|
sessionUrl: url,
|
|
12323
11253
|
stepIndex: index,
|
|
12324
|
-
...commonArgs(url, rootScope, mode, restart, deps),
|
|
11254
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
12325
11255
|
});
|
|
12326
11256
|
}
|
|
12327
11257
|
}
|
|
12328
11258
|
})();
|
|
12329
|
-
return textResult(JSON.stringify(result, null, 2));
|
|
11259
|
+
return textResult(JSON.stringify(withReviewField(result, scope, rootScope, mode), null, 2));
|
|
12330
11260
|
});
|
|
12331
11261
|
server.registerTool(EYES_REVIEW_TOOLS.end, {
|
|
12332
11262
|
description: END_DESC,
|
|
@@ -12340,6 +11270,7 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12340
11270
|
},
|
|
12341
11271
|
}, async ({ scope, batchUrl, scenarioName, sessionUrl, stepIndex, findings: rawFindingsArg, rootScope: rawRootScope, mode: rawMode, restart, }) => {
|
|
12342
11272
|
const rootScope = resolveRootScope(scope, rawRootScope);
|
|
11273
|
+
const rootScopeOmitted = rawRootScope === undefined;
|
|
12343
11274
|
const mode = resolveMode(rawMode);
|
|
12344
11275
|
recordReviewCall(scope, mode);
|
|
12345
11276
|
const rawFindings = await resolveJsonArg(rawFindingsArg, 'findings');
|
|
@@ -12351,7 +11282,7 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12351
11282
|
return batchEnd({
|
|
12352
11283
|
batchUrl: url,
|
|
12353
11284
|
findings: summaryFindings(),
|
|
12354
|
-
...commonArgs(url, rootScope, mode, restart, deps),
|
|
11285
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
12355
11286
|
});
|
|
12356
11287
|
}
|
|
12357
11288
|
case 'scenario': {
|
|
@@ -12361,7 +11292,7 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12361
11292
|
batchUrl: url,
|
|
12362
11293
|
scenarioName: name,
|
|
12363
11294
|
findings: summaryFindings(),
|
|
12364
|
-
...commonArgs(url, rootScope, mode, restart, deps),
|
|
11295
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
12365
11296
|
});
|
|
12366
11297
|
}
|
|
12367
11298
|
case 'session': {
|
|
@@ -12369,7 +11300,7 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12369
11300
|
return sessionEnd({
|
|
12370
11301
|
sessionUrl: url,
|
|
12371
11302
|
findings: summaryFindings(),
|
|
12372
|
-
...commonArgs(url, rootScope, mode, restart, deps),
|
|
11303
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
12373
11304
|
});
|
|
12374
11305
|
}
|
|
12375
11306
|
case 'step': {
|
|
@@ -12380,12 +11311,12 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12380
11311
|
sessionUrl: url,
|
|
12381
11312
|
stepIndex: index,
|
|
12382
11313
|
findings: stepFindings,
|
|
12383
|
-
...commonArgs(url, rootScope, mode, restart, deps),
|
|
11314
|
+
...commonArgs(url, rootScope, rootScopeOmitted, mode, restart, deps),
|
|
12384
11315
|
});
|
|
12385
11316
|
}
|
|
12386
11317
|
}
|
|
12387
11318
|
})();
|
|
12388
|
-
return textResult(JSON.stringify(result, null, 2));
|
|
11319
|
+
return textResult(JSON.stringify(withReviewField(result, scope, rootScope, mode), null, 2));
|
|
12389
11320
|
});
|
|
12390
11321
|
// --- Diff (leaf) -------------------------------------------------------------
|
|
12391
11322
|
server.registerTool(EYES_REVIEW_TOOLS.diffReport, {
|
|
@@ -12400,32 +11331,33 @@ function registerReviewTools(server, deps = defaultPhaseTrackerDeps) {
|
|
|
12400
11331
|
},
|
|
12401
11332
|
}, async ({ sessionUrl, stepIndex, reports: rawReportsArg, rootScope: rawRootScope, mode: rawMode, restart }) => {
|
|
12402
11333
|
const rootScope = resolveRootScope('diff', rawRootScope);
|
|
11334
|
+
const rootScopeOmitted = rawRootScope === undefined;
|
|
12403
11335
|
const mode = resolveMode(rawMode);
|
|
12404
11336
|
recordReviewCall('diff', mode);
|
|
12405
11337
|
const keys = reviewApiKeyProvider(sessionUrl, mode);
|
|
12406
11338
|
const rawReports = await resolveJsonArg(rawReportsArg, 'reports');
|
|
12407
11339
|
const reports = parseResolvedArg(DiffReportsShape, rawReports, 'reports');
|
|
12408
|
-
const result = await diffReportBatch({
|
|
12409
|
-
|
|
11340
|
+
const result = await diffReportBatch({
|
|
11341
|
+
sessionUrl,
|
|
11342
|
+
stepIndex,
|
|
11343
|
+
reports,
|
|
11344
|
+
keys,
|
|
11345
|
+
rootScope,
|
|
11346
|
+
rootScopeOmitted,
|
|
11347
|
+
mode,
|
|
11348
|
+
restart,
|
|
11349
|
+
deps,
|
|
11350
|
+
});
|
|
11351
|
+
return textResult(JSON.stringify(withReviewField(result, 'diff', rootScope, mode), null, 2));
|
|
12410
11352
|
});
|
|
12411
11353
|
}
|
|
12412
11354
|
|
|
12413
|
-
/**
|
|
12414
|
-
const
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
experimentalOnly: [EYES_INSPECT_TOOLS, EYES_RESOLVE_TOOLS, EYES_REVIEW_TOOLS].flatMap(family => Object.values(family)),
|
|
12418
|
-
// Hidden IN experimental mode: the legacy results tools the families replace. Runtime-hidden
|
|
12419
|
-
// rather than deleted (see `.team-lead/plan-remove-legacy-results-tools.md` for the eventual
|
|
12420
|
-
// removal) so the default server keeps its published tool set untouched.
|
|
12421
|
-
replacedByExperimental: [
|
|
12422
|
-
TOOL_NAMES.EYES_GET_BATCH_URL,
|
|
12423
|
-
TOOL_NAMES.EYES_FETCH_VISUAL_RESULTS,
|
|
12424
|
-
TOOL_NAMES.EYES_ANALYZE_BATCH,
|
|
12425
|
-
],
|
|
12426
|
-
};
|
|
11355
|
+
/** Derived from the family name maps — not hand-copied — so a newly added family tool can't be missed. */
|
|
11356
|
+
const FAMILY_TOOL_NAMES = [EYES_INSPECT_TOOLS, EYES_RESOLVE_TOOLS, EYES_REVIEW_TOOLS].flatMap(family => Object.values(family));
|
|
11357
|
+
/** Tools registered only in experimental mode (`EXPERIMENTAL_ENV`). Add a name here to ship a tool behind the flag. */
|
|
11358
|
+
const EXPERIMENTAL_TOOLS = [];
|
|
12427
11359
|
function skippedToolNames(experimental) {
|
|
12428
|
-
return new Set(
|
|
11360
|
+
return new Set(experimental ? [] : EXPERIMENTAL_TOOLS);
|
|
12429
11361
|
}
|
|
12430
11362
|
function filteredRegistrar(inner, skipped) {
|
|
12431
11363
|
const registerTool = (name, config, handler) => {
|
|
@@ -12436,20 +11368,15 @@ function filteredRegistrar(inner, skipped) {
|
|
|
12436
11368
|
return { registerTool };
|
|
12437
11369
|
}
|
|
12438
11370
|
/**
|
|
12439
|
-
* Registers the server's tool set for the mode chosen at process start
|
|
12440
|
-
*
|
|
12441
|
-
* place that decides which tools each mode exposes.
|
|
11371
|
+
* Registers the server's tool set for the mode chosen at process start: the native tools plus the
|
|
11372
|
+
* three tool families, minus whatever `skippedToolNames` hides in this mode.
|
|
12442
11373
|
*/
|
|
12443
11374
|
function registerAllTools(server, experimental) {
|
|
12444
|
-
const skipped = skippedToolNames();
|
|
11375
|
+
const skipped = skippedToolNames(experimental);
|
|
12445
11376
|
Object.values(ALL_TOOLS).forEach(tool => {
|
|
12446
11377
|
if (skipped.has(tool.name))
|
|
12447
11378
|
return;
|
|
12448
|
-
server.registerTool(tool.name, {
|
|
12449
|
-
description: tool.description,
|
|
12450
|
-
inputSchema: tool.inputSchema,
|
|
12451
|
-
...('outputSchema' in tool && tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
|
|
12452
|
-
}, tool.handler);
|
|
11379
|
+
server.registerTool(tool.name, { description: tool.description, inputSchema: tool.inputSchema }, tool.handler);
|
|
12453
11380
|
});
|
|
12454
11381
|
// The families register themselves; the instrumented registrar gives their handlers the same
|
|
12455
11382
|
// createToolHandler wrapping as the tools above, and the filter drops the skipped names.
|
|
@@ -12457,19 +11384,17 @@ function registerAllTools(server, experimental) {
|
|
|
12457
11384
|
registerEyesInspectDataTools(registrar);
|
|
12458
11385
|
registerEyesResolveTools(registrar);
|
|
12459
11386
|
registerReviewTools(registrar);
|
|
12460
|
-
// A resource, not a tool — outside the name-based swap, so it stays gated by the mode directly.
|
|
12461
11387
|
registerEyesInspectResources(server);
|
|
12462
11388
|
}
|
|
12463
|
-
/** Derived from the same
|
|
11389
|
+
/** Derived from the same name sources as registration, so the startup log can't drift. */
|
|
12464
11390
|
function registeredToolNames(experimental) {
|
|
12465
|
-
const skipped = skippedToolNames();
|
|
12466
|
-
return [...Object.values(TOOL_NAMES), ...
|
|
11391
|
+
const skipped = skippedToolNames(experimental);
|
|
11392
|
+
return [...Object.values(TOOL_NAMES), ...FAMILY_TOOL_NAMES].filter(name => !skipped.has(name));
|
|
12467
11393
|
}
|
|
12468
11394
|
|
|
12469
11395
|
async function startServer() {
|
|
12470
11396
|
loadEnvOnce(process.cwd(), 'server startup');
|
|
12471
|
-
const experimental = parseExperimental();
|
|
12472
|
-
setExperimental(experimental);
|
|
11397
|
+
const experimental = parseExperimental(process.env);
|
|
12473
11398
|
const server = new mcp_js.McpServer({
|
|
12474
11399
|
name: 'applitools-mcp',
|
|
12475
11400
|
version: packageJson.version,
|
|
@@ -12531,7 +11456,7 @@ async function startServer() {
|
|
|
12531
11456
|
.catch(error => log$2('debug', '[MCP Server] roots/list failed:', error));
|
|
12532
11457
|
}
|
|
12533
11458
|
};
|
|
12534
|
-
registerAllTools(server);
|
|
11459
|
+
registerAllTools(server, experimental);
|
|
12535
11460
|
server.registerResource('documentation', RESOURCE_URIS.DOCUMENTATION_README, {
|
|
12536
11461
|
title: RESOURCE_METADATA.DOCUMENTATION_README.title,
|
|
12537
11462
|
description: RESOURCE_METADATA.DOCUMENTATION_README.description,
|
|
@@ -12554,8 +11479,8 @@ async function startServer() {
|
|
|
12554
11479
|
const transport = new stdio_js.StdioServerTransport();
|
|
12555
11480
|
await server.connect(transport);
|
|
12556
11481
|
log$2('info', '[MCP Server] Applitools MCP Server started successfully (Stdio Mode)');
|
|
12557
|
-
log$2('info', `[MCP Server] Experimental tools ${'enabled' }`);
|
|
12558
|
-
log$2('info', `[MCP Server] Available tools: ${registeredToolNames().join(', ')}`);
|
|
11482
|
+
log$2('info', `[MCP Server] Experimental tools ${experimental ? 'enabled' : 'disabled'}`);
|
|
11483
|
+
log$2('info', `[MCP Server] Available tools: ${registeredToolNames(experimental).join(', ')}`);
|
|
12559
11484
|
log$2('info', `[MCP Server] Available resources: documentation (${RESOURCE_URIS.DOCUMENTATION_README})`);
|
|
12560
11485
|
}
|
|
12561
11486
|
process.on('SIGINT', () => {
|