@mcpjam/cli 3.23.0 → 3.24.0
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/dist/index.js +1047 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
|
|
4
4
|
import { pathToFileURL } from 'url';
|
|
5
|
-
import { probeMcpServer, redactForTelemetry, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, classifyMcpHeader, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, SubscriptionCoordinator, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, scoreFromAppsResult, MCPAppsConformanceSuite, MCPTasksConformanceTest, scoreFromTasksResult, runOAuthLogin, OAuthConformanceTest, scoreFromOAuthResult, OAuthConformanceSuite, runXaaFlow, MCPConformanceTest, scoreFromProtocolResult, MCPConformanceSuite, openUrlInBrowser, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, DEFAULT_SUBSCRIPTION_RECONNECT_POLICY, isKnownProtocolVersion, describeConformanceScore, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeXaaClientAuth, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, getLocalConfidentialCimdProvider, MCP_PROTOCOL_VERSIONS, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, MCPClientManager, decodeMcpHeaderValue, canDeclareTasksExtension, createStrictElicitationContentValidator, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, MCP_TASKS_CHECK_CATEGORIES, MCP_TASKS_CHECK_IDS, OAuthProxyError, isLoopbackHost, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS, TaskLifecycleEngine, driveTaskToTerminal, extensionTaskToObservation, legacyTaskToObservation, isUnknownTaskError, isMCPTasksWireError, LEGACY_TASK_STATUSES } from '@mcpjam/sdk';
|
|
6
|
-
import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
|
|
5
|
+
import { probeMcpServer, redactForTelemetry, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, classifyMcpHeader, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, SubscriptionCoordinator, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, scoreFromAppsResult, MCPAppsConformanceSuite, MCPTasksConformanceTest, scoreFromTasksResult, runOAuthLogin, OAuthConformanceTest, scoreFromOAuthResult, OAuthConformanceSuite, runXaaFlow, MCPConformanceTest, scoreFromProtocolResult, MCPConformanceSuite, openUrlInBrowser, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, DEFAULT_SUBSCRIPTION_RECONNECT_POLICY, isKnownProtocolVersion, describeConformanceScore, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeXaaClientAuth, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, getLocalConfidentialCimdProvider, MCP_PROTOCOL_VERSIONS, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, formatGateReport, detectFlakyCases, evaluateCompareGates, buildRunCompareReport, buildCorpus, HostedOnlyCaseError, verifyCorpusLock, MCPClientManager, decodeMcpHeaderValue, canDeclareTasksExtension, createStrictElicitationContentValidator, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, MCP_TASKS_CHECK_CATEGORIES, MCP_TASKS_CHECK_IDS, OAuthProxyError, isLoopbackHost, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS, evaluateGates, gateInputFromPlatformRun, calculateLatencyStats, CORPUS_LOCK_VERSION, TaskLifecycleEngine, driveTaskToTerminal, extensionTaskToObservation, legacyTaskToObservation, passRateFractionFromPercent, isUnknownTaskError, isMCPTasksWireError, LEGACY_TASK_STATUSES } from '@mcpjam/sdk';
|
|
6
|
+
import { mkdir, writeFile, readFile, chmod, rename, rm, open, unlink } from 'fs/promises';
|
|
7
7
|
import path2, { dirname, join, basename } from 'path';
|
|
8
|
-
import { randomUUID } from 'crypto';
|
|
8
|
+
import { randomUUID, randomBytes } from 'crypto';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
10
|
import { createRequire } from 'module';
|
|
11
11
|
import os, { homedir } from 'os';
|
|
12
|
-
import { createProjectOperation, updateProjectOperation, deleteProjectOperation, connectProjectServerOperation, getProjectServerConnectionStatusOperation, listEvalSuiteRunsOperation, cancelEvalRunOperation, listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalRunStepsOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, setEvalSuiteEnvironmentsOperation, listEvalCasesOperation, getEvalCaseOperation, runEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation,
|
|
12
|
+
import { createProjectOperation, updateProjectOperation, deleteProjectOperation, connectProjectServerOperation, getProjectServerConnectionStatusOperation, listEvalSuiteRunsOperation, cancelEvalRunOperation, listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalRunStepsOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, setEvalSuiteEnvironmentsOperation, listEvalCasesOperation, getEvalCaseOperation, runEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, listChatSessionsOperation, createHostOperation, updateHostOperation, setHostServersOperation, duplicateHostOperation, createEnvironmentOperation, updateEnvironmentOperation, createImageOperation, validateImageBlueprintOperation, updateImageOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listOrganizationsOperation, listProjectsOperation, listProjectServersOperation, createProjectServerOperation, getProjectServerOperation, updateProjectServerOperation, deleteProjectServerOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation, resolveProject, listHostsOperation, getHostOperation, deleteHostOperation, listEnvironmentsOperation, getEnvironmentOperation, resolveEnvironmentOperation, getEnvironmentCapabilitiesOperation, archiveEnvironmentOperation, restoreEnvironmentOperation, listJourneysOperation, listJourneyRunsOperation, getJourneyRunOperation, launchJourneyRunOperation, cancelJourneyRunOperation, listJourneyRunSessionsOperation, listScenariosOperation, getScenarioOperation, publishScenarioOperation, unpublishScenarioOperation, listImagesOperation, getImageOperation, buildImageOperation, listImageBuildsOperation, useImageOperation, resetComputerOperation, promoteImageOperation, deleteImageOperation, getCapabilitiesOperation, listPersonasOperation, getPersonaOperation, createPersonaOperation, updatePersonaOperation, deletePersonaOperation, generatePersonasOperation, getJourneyOperation, createJourneyOperation, updateJourneyOperation, archiveJourneyOperation, generateJourneysOperation, getSwarmOverviewOperation, getJourneyRunScorecardOperation, listSwarmFindingsOperation, dismissSwarmFindingOperation, undismissSwarmFindingOperation, getWaveInsightsOperation, requestWaveInsightsOperation, cancelWaveInsightsOperation, listSwarmsOperation, getSwarmOperation, createSwarmOperation, updateSwarmOperation, archiveSwarmOperation, getUserTestingScenarioOperation, listUserTestingSessionsOperation, getUserTestingSessionOperation, getUserTestingMetricsOperation, getUserTestingUsageOperation, listUserTestingFindingsOperation, getUserTestingSignalsOperation, getUserTestingInsightsOperation, requestUserTestingInsightsOperation, cancelUserTestingInsightsOperation, dismissUserTestingFindingOperation, undismissUserTestingFindingOperation, updateUserTestingScenarioOperation, setUserTestingGuestExecutionOperation, rotateUserTestingLinkOperation, upsertUserTestingMemberOperation, removeUserTestingMemberOperation, rebindUserTestingScenarioOperation, searchSessionsOperation } from '@mcpjam/sdk/platform';
|
|
13
13
|
import { buildHostProfilesFromCatalog, buildMarketHostProfiles, scanWidgetUsage, evaluateMarketHosts, fetchHostCompatCatalog } from '@mcpjam/sdk/host-compat';
|
|
14
14
|
import { HOST_TEMPLATES as HOST_TEMPLATES$1, HOST_TEMPLATE_IDS, seedHostTemplate } from '@mcpjam/sdk/host-config/templates';
|
|
15
15
|
import { applyVisibilityPolicyAndCountSignals, isAppOnlyTool, extractHostExecutionPolicy, hostConnectionProfile } from '@mcpjam/sdk/host-config/internal';
|
|
@@ -25,7 +25,7 @@ import { WebSocket } from 'ws';
|
|
|
25
25
|
|
|
26
26
|
// package.json
|
|
27
27
|
var package_default = {
|
|
28
|
-
version: "3.
|
|
28
|
+
version: "3.24.0"};
|
|
29
29
|
function conformanceExitCode(result) {
|
|
30
30
|
if (result.outcome === "incomplete") return 3;
|
|
31
31
|
if (result.outcome === "failed") return 1;
|
|
@@ -453,6 +453,8 @@ function renderConformanceReporterResult(result, reporter) {
|
|
|
453
453
|
function renderConformanceForCli(result, reporter, format) {
|
|
454
454
|
return reporter ? renderConformanceReporterResult(result, reporter) : renderConformanceResult(result, format);
|
|
455
455
|
}
|
|
456
|
+
|
|
457
|
+
// src/lib/reporting.ts
|
|
456
458
|
function parseReporterFormat(value) {
|
|
457
459
|
if (value === void 0) {
|
|
458
460
|
return void 0;
|
|
@@ -477,7 +479,7 @@ async function writeJsonArtifact(outputPath, payload) {
|
|
|
477
479
|
await mkdir(path2.dirname(resolvedPath), { recursive: true });
|
|
478
480
|
await writeFile(
|
|
479
481
|
resolvedPath,
|
|
480
|
-
`${JSON.stringify(payload, null, 2)}
|
|
482
|
+
`${JSON.stringify(redactForTelemetry(payload), null, 2)}
|
|
481
483
|
`,
|
|
482
484
|
"utf8"
|
|
483
485
|
);
|
|
@@ -760,7 +762,7 @@ function isAccessTokenUsable(contents, now) {
|
|
|
760
762
|
}
|
|
761
763
|
return Date.parse(contents.expiresAt) - now.getTime() > ACCESS_TOKEN_EXPIRY_SKEW_MS;
|
|
762
764
|
}
|
|
763
|
-
var readTextFile = (
|
|
765
|
+
var readTextFile = (path7, encoding) => readFileSync(path7, encoding);
|
|
764
766
|
var JsonInputContext = class {
|
|
765
767
|
constructor(readFile2 = readTextFile) {
|
|
766
768
|
this.readFile = readFile2;
|
|
@@ -1578,7 +1580,7 @@ var InspectorApiClient = class {
|
|
|
1578
1580
|
}
|
|
1579
1581
|
throw operationalError("Inspector command response was invalid.", payload);
|
|
1580
1582
|
}
|
|
1581
|
-
async request(
|
|
1583
|
+
async request(path7, init = {}) {
|
|
1582
1584
|
const fetchRequest = async () => {
|
|
1583
1585
|
const token = await fetchInspectorSessionToken(this.baseUrl);
|
|
1584
1586
|
const { body: initBody, timeoutMs, ...fetchInit } = init;
|
|
@@ -1589,7 +1591,7 @@ var InspectorApiClient = class {
|
|
|
1589
1591
|
headers.set("Content-Type", "application/json");
|
|
1590
1592
|
body = JSON.stringify(initBody);
|
|
1591
1593
|
}
|
|
1592
|
-
return await fetch(`${this.baseUrl}${
|
|
1594
|
+
return await fetch(`${this.baseUrl}${path7}`, {
|
|
1593
1595
|
...fetchInit,
|
|
1594
1596
|
signal: fetchInit.signal ?? AbortSignal.timeout(timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS),
|
|
1595
1597
|
headers,
|
|
@@ -1612,7 +1614,7 @@ var InspectorApiClient = class {
|
|
|
1612
1614
|
const payload = await readResponsePayload(response);
|
|
1613
1615
|
if (!response.ok) {
|
|
1614
1616
|
throw operationalError(
|
|
1615
|
-
getErrorMessage(payload) ?? `Inspector request ${
|
|
1617
|
+
getErrorMessage(payload) ?? `Inspector request ${path7} failed with ${response.status}.`,
|
|
1616
1618
|
payload
|
|
1617
1619
|
);
|
|
1618
1620
|
}
|
|
@@ -4553,34 +4555,6 @@ async function executeOp(op, input, options, command) {
|
|
|
4553
4555
|
writeResult(result, globalOptions.format);
|
|
4554
4556
|
}
|
|
4555
4557
|
function registerChatCommands(program) {
|
|
4556
|
-
const chatboxes = program.command("chatboxes").description("Inspect the chatboxes published from a hosted project");
|
|
4557
|
-
addPlatformOptions2(
|
|
4558
|
-
chatboxes.command("list").description("List the chatboxes published from a project").option(
|
|
4559
|
-
"--project <id-or-name>",
|
|
4560
|
-
"Project name or ID (defaults to the most recently updated project)"
|
|
4561
|
-
)
|
|
4562
|
-
).action(async (options, command) => {
|
|
4563
|
-
const input = validateOpInput(listChatboxesOperation, {
|
|
4564
|
-
...options.project === void 0 ? {} : { project: options.project }
|
|
4565
|
-
});
|
|
4566
|
-
await executeOp(listChatboxesOperation, input, options, command);
|
|
4567
|
-
});
|
|
4568
|
-
addPlatformOptions2(
|
|
4569
|
-
chatboxes.command("get").description(
|
|
4570
|
-
"Show one chatbox: access mode, attached servers, share link"
|
|
4571
|
-
).requiredOption("--chatbox <id-or-name>", "Chatbox name or ID").option(
|
|
4572
|
-
"--project <id-or-name>",
|
|
4573
|
-
"Project name or ID (defaults to the most recently updated project)"
|
|
4574
|
-
)
|
|
4575
|
-
).action(
|
|
4576
|
-
async (options, command) => {
|
|
4577
|
-
const input = validateOpInput(getChatboxOperation, {
|
|
4578
|
-
chatbox: options.chatbox,
|
|
4579
|
-
...options.project === void 0 ? {} : { project: options.project }
|
|
4580
|
-
});
|
|
4581
|
-
await executeOp(getChatboxOperation, input, options, command);
|
|
4582
|
-
}
|
|
4583
|
-
);
|
|
4584
4558
|
const sessions = program.command("chat-sessions").description("Inspect saved chat sessions");
|
|
4585
4559
|
addPlatformOptions2(
|
|
4586
4560
|
sessions.command("list").description(
|
|
@@ -5148,6 +5122,49 @@ function registerScenariosCommands(program) {
|
|
|
5148
5122
|
"invited_only",
|
|
5149
5123
|
"anyone_with_link"
|
|
5150
5124
|
];
|
|
5125
|
+
addPlatformOptions5(
|
|
5126
|
+
scenarios.command("list").description("List the scenarios published from a project").option(
|
|
5127
|
+
"--project <id-or-name>",
|
|
5128
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
5129
|
+
)
|
|
5130
|
+
).action(async (options, command) => {
|
|
5131
|
+
const globalOptions = getGlobalOptions(command);
|
|
5132
|
+
const result = await runPlatformCommand5(
|
|
5133
|
+
options,
|
|
5134
|
+
globalOptions.timeout,
|
|
5135
|
+
({ client, signal }) => listScenariosOperation.execute(
|
|
5136
|
+
{
|
|
5137
|
+
...options.project === void 0 ? {} : { project: options.project }
|
|
5138
|
+
},
|
|
5139
|
+
{ client, signal }
|
|
5140
|
+
)
|
|
5141
|
+
);
|
|
5142
|
+
writeResult(result, globalOptions.format);
|
|
5143
|
+
});
|
|
5144
|
+
addPlatformOptions5(
|
|
5145
|
+
scenarios.command("get").description(
|
|
5146
|
+
"Show one scenario: access mode, attached servers, share link"
|
|
5147
|
+
).requiredOption("--scenario <id-or-name>", "Scenario name or ID").option(
|
|
5148
|
+
"--project <id-or-name>",
|
|
5149
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
5150
|
+
)
|
|
5151
|
+
).action(
|
|
5152
|
+
async (options, command) => {
|
|
5153
|
+
const globalOptions = getGlobalOptions(command);
|
|
5154
|
+
const result = await runPlatformCommand5(
|
|
5155
|
+
options,
|
|
5156
|
+
globalOptions.timeout,
|
|
5157
|
+
({ client, signal }) => getScenarioOperation.execute(
|
|
5158
|
+
{
|
|
5159
|
+
scenario: options.scenario,
|
|
5160
|
+
...options.project === void 0 ? {} : { project: options.project }
|
|
5161
|
+
},
|
|
5162
|
+
{ client, signal }
|
|
5163
|
+
)
|
|
5164
|
+
);
|
|
5165
|
+
writeResult(result, globalOptions.format);
|
|
5166
|
+
}
|
|
5167
|
+
);
|
|
5151
5168
|
addPlatformOptions5(
|
|
5152
5169
|
scenarios.command("publish").description(
|
|
5153
5170
|
"Publish an environment as a scenario and print its share link. Idempotent \u2014 re-publishing returns the existing scenario, with created: false. --name, --description and --mode apply at CREATE TIME, in the same call; on a re-publish they are ignored and the result says overridesIgnored: true (use `mcpjam user-testing update` to change an existing scenario)."
|
|
@@ -6137,6 +6154,434 @@ function screenshotFilename(shot, index) {
|
|
|
6137
6154
|
const suffix = shot.toolCallId ? shot.toolCallId.replace(/[^a-zA-Z0-9_-]+/g, "-") : String(index + 1);
|
|
6138
6155
|
return `${tool}-${suffix}.png`;
|
|
6139
6156
|
}
|
|
6157
|
+
var DEFAULT_CORPUS_LOCK_PATH = "mcpjam-evals.lock.json";
|
|
6158
|
+
var CORPUS_DRIFT_EXIT_CODE = 1;
|
|
6159
|
+
var CORPUS_INCOMPLETE_EXIT_CODE = 3;
|
|
6160
|
+
var CORPUS_USAGE_EXIT_CODE = 2;
|
|
6161
|
+
function incomplete(code, message, details) {
|
|
6162
|
+
return cliError(code, message, CORPUS_INCOMPLETE_EXIT_CODE, details);
|
|
6163
|
+
}
|
|
6164
|
+
function corpusFetchFailure(error) {
|
|
6165
|
+
const normalized = error instanceof CliError ? error : normalizeCliError(error);
|
|
6166
|
+
if (normalized.exitCode === CORPUS_USAGE_EXIT_CODE) {
|
|
6167
|
+
return normalized;
|
|
6168
|
+
}
|
|
6169
|
+
return cliError(
|
|
6170
|
+
normalized.code,
|
|
6171
|
+
normalized.message,
|
|
6172
|
+
CORPUS_INCOMPLETE_EXIT_CODE,
|
|
6173
|
+
normalized.details
|
|
6174
|
+
);
|
|
6175
|
+
}
|
|
6176
|
+
function resolveCorpusLockPath(value) {
|
|
6177
|
+
return path2.resolve(process.cwd(), value ?? DEFAULT_CORPUS_LOCK_PATH);
|
|
6178
|
+
}
|
|
6179
|
+
function isMissingFileError(error) {
|
|
6180
|
+
return typeof error === "object" && error !== null && error.code === "ENOENT";
|
|
6181
|
+
}
|
|
6182
|
+
function isRecord3(value) {
|
|
6183
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6184
|
+
}
|
|
6185
|
+
function describeLockDefect(lock) {
|
|
6186
|
+
if (!isRecord3(lock.suite) || typeof lock.suite.id !== "string") {
|
|
6187
|
+
return `"suite.id" is missing or not a string`;
|
|
6188
|
+
}
|
|
6189
|
+
if (typeof lock.evaluationConfigHash !== "string") {
|
|
6190
|
+
return `"evaluationConfigHash" is missing or not a string`;
|
|
6191
|
+
}
|
|
6192
|
+
if (typeof lock.fetchedAt !== "string") {
|
|
6193
|
+
return `"fetchedAt" is missing or not a string`;
|
|
6194
|
+
}
|
|
6195
|
+
const REQUIRED_STRINGS = [
|
|
6196
|
+
"scenarioKey",
|
|
6197
|
+
"caseId",
|
|
6198
|
+
"title",
|
|
6199
|
+
"scenarioContentHash",
|
|
6200
|
+
"evaluationConfigHash"
|
|
6201
|
+
];
|
|
6202
|
+
for (const [index, row] of lock.cases.entries()) {
|
|
6203
|
+
if (!isRecord3(row)) {
|
|
6204
|
+
return `case ${index} is not an object`;
|
|
6205
|
+
}
|
|
6206
|
+
for (const field of REQUIRED_STRINGS) {
|
|
6207
|
+
if (typeof row[field] !== "string") {
|
|
6208
|
+
return `case ${index} is missing "${field}"`;
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
if (row.scenarioKey !== `external:${row.caseId}`) {
|
|
6212
|
+
return `case ${index} ("${String(row.scenarioKey)}") has a scenarioKey that does not match its caseId`;
|
|
6213
|
+
}
|
|
6214
|
+
if (!Number.isInteger(row.iterations) || row.iterations < 1) {
|
|
6215
|
+
return `case ${index} ("${String(row.scenarioKey)}") has an invalid "iterations" (${String(row.iterations)})`;
|
|
6216
|
+
}
|
|
6217
|
+
if (!isRecord3(row.normalizedContent)) {
|
|
6218
|
+
return `case ${index} ("${String(
|
|
6219
|
+
row.scenarioKey
|
|
6220
|
+
)}") is missing "normalizedContent"`;
|
|
6221
|
+
}
|
|
6222
|
+
}
|
|
6223
|
+
const keys = /* @__PURE__ */ new Set();
|
|
6224
|
+
for (const row of lock.cases) {
|
|
6225
|
+
const key = row.scenarioKey;
|
|
6226
|
+
if (keys.has(key)) {
|
|
6227
|
+
return `"${key}" appears twice`;
|
|
6228
|
+
}
|
|
6229
|
+
keys.add(key);
|
|
6230
|
+
}
|
|
6231
|
+
return void 0;
|
|
6232
|
+
}
|
|
6233
|
+
async function readCorpusLock(lockPath) {
|
|
6234
|
+
let raw;
|
|
6235
|
+
try {
|
|
6236
|
+
const handle = await open(lockPath, "r");
|
|
6237
|
+
try {
|
|
6238
|
+
raw = await handle.readFile("utf8");
|
|
6239
|
+
} finally {
|
|
6240
|
+
await handle.close();
|
|
6241
|
+
}
|
|
6242
|
+
} catch (error) {
|
|
6243
|
+
if (isMissingFileError(error)) {
|
|
6244
|
+
throw incomplete(
|
|
6245
|
+
"CORPUS_LOCK_MISSING",
|
|
6246
|
+
`No corpus lock at "${lockPath}". Run \`mcpjam eval pull\` to create one before checking it with --frozen.`
|
|
6247
|
+
);
|
|
6248
|
+
}
|
|
6249
|
+
throw incomplete(
|
|
6250
|
+
"CORPUS_LOCK_UNREADABLE",
|
|
6251
|
+
`Could not read the corpus lock at "${lockPath}".`,
|
|
6252
|
+
{ source: error instanceof Error ? error.message : String(error) }
|
|
6253
|
+
);
|
|
6254
|
+
}
|
|
6255
|
+
let parsed;
|
|
6256
|
+
try {
|
|
6257
|
+
parsed = JSON.parse(raw);
|
|
6258
|
+
} catch (error) {
|
|
6259
|
+
throw incomplete(
|
|
6260
|
+
"CORPUS_LOCK_MALFORMED",
|
|
6261
|
+
`The corpus lock at "${lockPath}" is not valid JSON. Re-create it with \`mcpjam eval pull\`.`,
|
|
6262
|
+
{ source: error instanceof Error ? error.message : String(error) }
|
|
6263
|
+
);
|
|
6264
|
+
}
|
|
6265
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
6266
|
+
throw incomplete(
|
|
6267
|
+
"CORPUS_LOCK_MALFORMED",
|
|
6268
|
+
`The corpus lock at "${lockPath}" is not a lock object.`
|
|
6269
|
+
);
|
|
6270
|
+
}
|
|
6271
|
+
const lock = parsed;
|
|
6272
|
+
if (typeof lock.lockVersion !== "number" || !Array.isArray(lock.cases)) {
|
|
6273
|
+
throw incomplete(
|
|
6274
|
+
"CORPUS_LOCK_MALFORMED",
|
|
6275
|
+
`The corpus lock at "${lockPath}" is missing "lockVersion" or "cases". Re-create it with \`mcpjam eval pull\`.`
|
|
6276
|
+
);
|
|
6277
|
+
}
|
|
6278
|
+
const structural = describeLockDefect(lock);
|
|
6279
|
+
if (structural) {
|
|
6280
|
+
throw incomplete(
|
|
6281
|
+
"CORPUS_LOCK_MALFORMED",
|
|
6282
|
+
`The corpus lock at "${lockPath}" is malformed: ${structural}. Re-create it with \`mcpjam eval pull\`.`
|
|
6283
|
+
);
|
|
6284
|
+
}
|
|
6285
|
+
if (lock.lockVersion !== CORPUS_LOCK_VERSION) {
|
|
6286
|
+
throw incomplete(
|
|
6287
|
+
"CORPUS_LOCK_VERSION_MISMATCH",
|
|
6288
|
+
`The corpus lock at "${lockPath}" is version ${lock.lockVersion}, but this CLI writes version ${CORPUS_LOCK_VERSION}. Hashes are not comparable across lock versions. Re-create it with \`mcpjam eval pull\`.`
|
|
6289
|
+
);
|
|
6290
|
+
}
|
|
6291
|
+
return lock;
|
|
6292
|
+
}
|
|
6293
|
+
async function writeCorpusLockAtomic(lockPath, lock) {
|
|
6294
|
+
const resolved = path2.resolve(process.cwd(), lockPath);
|
|
6295
|
+
const temporary = `${resolved}.${process.pid}-${randomBytes(6).toString(
|
|
6296
|
+
"hex"
|
|
6297
|
+
)}.tmp`;
|
|
6298
|
+
try {
|
|
6299
|
+
const body = `${JSON.stringify(lock, null, 2)}
|
|
6300
|
+
`;
|
|
6301
|
+
await writeFile(temporary, body, { encoding: "utf8", mode: 420 });
|
|
6302
|
+
const handle = await open(temporary, "r+");
|
|
6303
|
+
try {
|
|
6304
|
+
await handle.sync();
|
|
6305
|
+
} finally {
|
|
6306
|
+
await handle.close();
|
|
6307
|
+
}
|
|
6308
|
+
await rename(temporary, resolved);
|
|
6309
|
+
} catch (error) {
|
|
6310
|
+
await unlink(temporary).catch(() => {
|
|
6311
|
+
});
|
|
6312
|
+
throw incomplete(
|
|
6313
|
+
"CORPUS_LOCK_WRITE_FAILED",
|
|
6314
|
+
`Failed to write the corpus lock to "${resolved}". The previous lock, if any, is unchanged.`,
|
|
6315
|
+
{ source: error instanceof Error ? error.message : String(error) }
|
|
6316
|
+
);
|
|
6317
|
+
}
|
|
6318
|
+
return resolved;
|
|
6319
|
+
}
|
|
6320
|
+
var DRIFT_LABELS = {
|
|
6321
|
+
caseAdded: "added ",
|
|
6322
|
+
caseRemoved: "removed ",
|
|
6323
|
+
contentChanged: "content ",
|
|
6324
|
+
evaluationConfigChanged: "grading "
|
|
6325
|
+
};
|
|
6326
|
+
var DRIFT_MARKS = {
|
|
6327
|
+
caseAdded: "+",
|
|
6328
|
+
caseRemoved: "-",
|
|
6329
|
+
contentChanged: "~",
|
|
6330
|
+
evaluationConfigChanged: "~"
|
|
6331
|
+
};
|
|
6332
|
+
function renderCorpusDrift(drift) {
|
|
6333
|
+
if (drift.length === 0) {
|
|
6334
|
+
return "Corpus matches the lock.";
|
|
6335
|
+
}
|
|
6336
|
+
const lines = drift.map(
|
|
6337
|
+
(entry) => ` ${DRIFT_MARKS[entry.kind]} ${DRIFT_LABELS[entry.kind]} ${entry.scenarioKey} ${JSON.stringify(entry.title)}`
|
|
6338
|
+
);
|
|
6339
|
+
return [
|
|
6340
|
+
`Corpus drifted from the lock (${drift.length} ${drift.length === 1 ? "change" : "changes"}):`,
|
|
6341
|
+
...lines,
|
|
6342
|
+
"",
|
|
6343
|
+
"Run `mcpjam eval pull` to accept these changes, or restore the cases in the dashboard."
|
|
6344
|
+
].join("\n");
|
|
6345
|
+
}
|
|
6346
|
+
|
|
6347
|
+
// src/lib/eval-gate-exit-code.ts
|
|
6348
|
+
function evalGateExitCode(report) {
|
|
6349
|
+
switch (report.outcome) {
|
|
6350
|
+
case "passed":
|
|
6351
|
+
return 0;
|
|
6352
|
+
case "failed":
|
|
6353
|
+
return 1;
|
|
6354
|
+
case "usage_error":
|
|
6355
|
+
return 2;
|
|
6356
|
+
case "incomplete":
|
|
6357
|
+
return 3;
|
|
6358
|
+
default:
|
|
6359
|
+
return 3;
|
|
6360
|
+
}
|
|
6361
|
+
}
|
|
6362
|
+
var TERMINAL_RUN_STATUSES = /* @__PURE__ */ new Set([
|
|
6363
|
+
"completed",
|
|
6364
|
+
"failed",
|
|
6365
|
+
"cancelled",
|
|
6366
|
+
"timed_out"
|
|
6367
|
+
]);
|
|
6368
|
+
var NON_VERDICT_STATUSES = /* @__PURE__ */ new Set(["cancelled", "timed_out", "failed"]);
|
|
6369
|
+
function isNonVerdictRunStatus(status) {
|
|
6370
|
+
return status !== void 0 && NON_VERDICT_STATUSES.has(status);
|
|
6371
|
+
}
|
|
6372
|
+
var EVAL_GATE_INCOMPLETE_EXIT_CODE = 3;
|
|
6373
|
+
var EVAL_GATE_USAGE_EXIT_CODE = 2;
|
|
6374
|
+
function parsePercent(raw, flag) {
|
|
6375
|
+
const value = raw.trim() === "" ? NaN : Number(raw);
|
|
6376
|
+
if (!Number.isFinite(value) || value < 0 || value > 100) {
|
|
6377
|
+
throw usageError(`${flag} must be a number between 0 and 100, got "${raw}".`);
|
|
6378
|
+
}
|
|
6379
|
+
return passRateFractionFromPercent(value);
|
|
6380
|
+
}
|
|
6381
|
+
function parseScorerMap(entries, flag, parseValue) {
|
|
6382
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
6383
|
+
for (const entry of entries) {
|
|
6384
|
+
const index = entry.indexOf("=");
|
|
6385
|
+
if (index <= 0) {
|
|
6386
|
+
throw usageError(`${flag} must be <scorerId>=<value>, got "${entry}".`);
|
|
6387
|
+
}
|
|
6388
|
+
const scorerId = entry.slice(0, index).trim();
|
|
6389
|
+
if (!scorerId) {
|
|
6390
|
+
throw usageError(`${flag} is missing a scorer id in "${entry}".`);
|
|
6391
|
+
}
|
|
6392
|
+
if (Object.prototype.hasOwnProperty.call(out, scorerId)) {
|
|
6393
|
+
throw usageError(
|
|
6394
|
+
`${flag} names "${scorerId}" more than once; pass one threshold per scorer.`
|
|
6395
|
+
);
|
|
6396
|
+
}
|
|
6397
|
+
out[scorerId] = parseValue(entry.slice(index + 1).trim(), flag);
|
|
6398
|
+
}
|
|
6399
|
+
return out;
|
|
6400
|
+
}
|
|
6401
|
+
function parseUnit(raw, flag) {
|
|
6402
|
+
const value = raw.trim() === "" ? NaN : Number(raw);
|
|
6403
|
+
if (!Number.isFinite(value) || value < 0 || value > 1) {
|
|
6404
|
+
throw usageError(`${flag} must be a number between 0 and 1, got "${raw}".`);
|
|
6405
|
+
}
|
|
6406
|
+
return value;
|
|
6407
|
+
}
|
|
6408
|
+
function policyFromOptions(options) {
|
|
6409
|
+
const policy = {};
|
|
6410
|
+
if (options.minPassRatePercent !== void 0) {
|
|
6411
|
+
policy.minimumPassRate = parsePercent(
|
|
6412
|
+
options.minPassRatePercent,
|
|
6413
|
+
"--min-pass-rate-percent"
|
|
6414
|
+
);
|
|
6415
|
+
}
|
|
6416
|
+
if (options.noGatingScoreErrors) policy.noGatingScoreErrors = true;
|
|
6417
|
+
if (options.minScorerPassRate?.length) {
|
|
6418
|
+
policy.minimumScorerPassRate = parseScorerMap(
|
|
6419
|
+
options.minScorerPassRate,
|
|
6420
|
+
"--min-scorer-pass-rate",
|
|
6421
|
+
parsePercent
|
|
6422
|
+
);
|
|
6423
|
+
}
|
|
6424
|
+
if (options.minMeanScore?.length) {
|
|
6425
|
+
policy.minimumMeanScore = parseScorerMap(
|
|
6426
|
+
options.minMeanScore,
|
|
6427
|
+
"--min-mean-score",
|
|
6428
|
+
parseUnit
|
|
6429
|
+
);
|
|
6430
|
+
}
|
|
6431
|
+
return policy;
|
|
6432
|
+
}
|
|
6433
|
+
function policyNeedsIterations(policy) {
|
|
6434
|
+
return Boolean(
|
|
6435
|
+
policy.noGatingScoreErrors || policy.minimumScorerPassRate || policy.minimumMeanScore || policy.maximumTotalTokens !== void 0 || // p95 comes from iteration durations, exactly like tokens come from
|
|
6436
|
+
// iteration counts. Omitting it here would leave the latency gate
|
|
6437
|
+
// permanently non-gateable — the fetch that could decide it never runs.
|
|
6438
|
+
policy.maximumP95LatencyMs !== void 0
|
|
6439
|
+
);
|
|
6440
|
+
}
|
|
6441
|
+
function reportForRun(run, iterations, policy) {
|
|
6442
|
+
return evaluateGates(gateInputFromPlatformRun(run, iterations), policy);
|
|
6443
|
+
}
|
|
6444
|
+
|
|
6445
|
+
// src/lib/eval-iterations.ts
|
|
6446
|
+
async function fetchAllIterations(client, signal, projectId, runId) {
|
|
6447
|
+
const items = [];
|
|
6448
|
+
let cursor;
|
|
6449
|
+
for (let page = 0; page < 100; page += 1) {
|
|
6450
|
+
const result = await client.listEvalRunIterations(
|
|
6451
|
+
{ projectId, runId, ...cursor ? { cursor } : {}, limit: 200 },
|
|
6452
|
+
{ signal }
|
|
6453
|
+
);
|
|
6454
|
+
items.push(...result.items);
|
|
6455
|
+
if (!result.nextCursor) return { items, complete: true };
|
|
6456
|
+
cursor = result.nextCursor;
|
|
6457
|
+
}
|
|
6458
|
+
return { items, complete: false };
|
|
6459
|
+
}
|
|
6460
|
+
|
|
6461
|
+
// src/lib/eval-compare.ts
|
|
6462
|
+
function parseNonNegativeInteger2(raw, flag) {
|
|
6463
|
+
const value = raw.trim() === "" ? NaN : Number(raw);
|
|
6464
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
6465
|
+
throw usageError(
|
|
6466
|
+
`${flag} must be a non-negative integer, got "${raw}".`
|
|
6467
|
+
);
|
|
6468
|
+
}
|
|
6469
|
+
return value;
|
|
6470
|
+
}
|
|
6471
|
+
function parsePercentAsFraction(raw, flag) {
|
|
6472
|
+
const value = raw.trim() === "" ? NaN : Number(raw);
|
|
6473
|
+
if (!Number.isFinite(value) || value < 0 || value > 100) {
|
|
6474
|
+
throw usageError(
|
|
6475
|
+
`${flag} must be a number between 0 and 100, got "${raw}".`
|
|
6476
|
+
);
|
|
6477
|
+
}
|
|
6478
|
+
return value / 100;
|
|
6479
|
+
}
|
|
6480
|
+
function comparePolicyFromOptions(options) {
|
|
6481
|
+
const policy = {};
|
|
6482
|
+
const tuning = {};
|
|
6483
|
+
if (options.minSampleSize !== void 0) {
|
|
6484
|
+
tuning.minSampleSize = parseNonNegativeInteger2(
|
|
6485
|
+
options.minSampleSize,
|
|
6486
|
+
"--min-sample-size"
|
|
6487
|
+
);
|
|
6488
|
+
}
|
|
6489
|
+
if (options.minEffectSizePercent !== void 0) {
|
|
6490
|
+
tuning.minEffectSize = parsePercentAsFraction(
|
|
6491
|
+
options.minEffectSizePercent,
|
|
6492
|
+
"--min-effect-size-percent"
|
|
6493
|
+
);
|
|
6494
|
+
}
|
|
6495
|
+
if (Object.keys(tuning).length > 0 && !options.gateRegressions) {
|
|
6496
|
+
throw usageError(
|
|
6497
|
+
"--min-sample-size and --min-effect-size-percent tune the pass-rate regression gate; pass --gate-regressions to enable it."
|
|
6498
|
+
);
|
|
6499
|
+
}
|
|
6500
|
+
if (options.gateRegressions) policy.passRateRegression = tuning;
|
|
6501
|
+
if (options.gateDeterministicRegressions) {
|
|
6502
|
+
policy.noDeterministicRegressions = true;
|
|
6503
|
+
}
|
|
6504
|
+
if (options.maxP95LatencyIncreaseMs !== void 0) {
|
|
6505
|
+
policy.maximumP95LatencyIncreaseMs = parseNonNegativeInteger2(
|
|
6506
|
+
options.maxP95LatencyIncreaseMs,
|
|
6507
|
+
"--max-p95-latency-increase-ms"
|
|
6508
|
+
);
|
|
6509
|
+
}
|
|
6510
|
+
return policy;
|
|
6511
|
+
}
|
|
6512
|
+
var CASE_SET_CHANGED_STATUSES = /* @__PURE__ */ new Set(["new_case", "removed_case"]);
|
|
6513
|
+
function deterministicRegressionsFrom(cases) {
|
|
6514
|
+
const regressions = [];
|
|
6515
|
+
for (const row of cases) {
|
|
6516
|
+
for (const delta of row.scoreDeltas) {
|
|
6517
|
+
if (!delta.gating || !delta.deterministic) continue;
|
|
6518
|
+
if (delta.definitionChanged) continue;
|
|
6519
|
+
if (delta.base?.passed === true && delta.compare?.passed === false) {
|
|
6520
|
+
regressions.push({ caseKey: row.caseKey, scorerId: delta.scorerId });
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
}
|
|
6524
|
+
return regressions;
|
|
6525
|
+
}
|
|
6526
|
+
function iterationWeightingEqualFrom(cases) {
|
|
6527
|
+
for (const row of cases) {
|
|
6528
|
+
if (row.base.outcome === "absent" || row.compare.outcome === "absent") {
|
|
6529
|
+
continue;
|
|
6530
|
+
}
|
|
6531
|
+
if (row.base.iterationIds.length !== row.compare.iterationIds.length) {
|
|
6532
|
+
return false;
|
|
6533
|
+
}
|
|
6534
|
+
}
|
|
6535
|
+
return true;
|
|
6536
|
+
}
|
|
6537
|
+
function sideFromRun(summary, integrity, e2eP95Ms) {
|
|
6538
|
+
return {
|
|
6539
|
+
iterations: {
|
|
6540
|
+
total: summary?.total ?? 0,
|
|
6541
|
+
passed: summary?.passed ?? 0
|
|
6542
|
+
},
|
|
6543
|
+
...integrity ? { scoreIntegrity: integrity } : {},
|
|
6544
|
+
...e2eP95Ms !== void 0 ? { totals: { e2eP95Ms } } : {}
|
|
6545
|
+
};
|
|
6546
|
+
}
|
|
6547
|
+
function compareGateInputFrom(compare, latency = {}) {
|
|
6548
|
+
const cases = compare.cases;
|
|
6549
|
+
return {
|
|
6550
|
+
base: sideFromRun(
|
|
6551
|
+
compare.baseRun.summary,
|
|
6552
|
+
compare.scoreContract.base.scoreIntegrity,
|
|
6553
|
+
latency.baseP95Ms
|
|
6554
|
+
),
|
|
6555
|
+
compare: sideFromRun(
|
|
6556
|
+
compare.compareRun.summary,
|
|
6557
|
+
compare.scoreContract.compare.scoreIntegrity,
|
|
6558
|
+
latency.compareP95Ms
|
|
6559
|
+
),
|
|
6560
|
+
deterministicScoreRegressions: deterministicRegressionsFrom(cases),
|
|
6561
|
+
scoreDeltasAvailable: cases.some((row) => row.scoreDeltas.length > 0),
|
|
6562
|
+
caseSetChanged: cases.some(
|
|
6563
|
+
(row) => CASE_SET_CHANGED_STATUSES.has(row.status)
|
|
6564
|
+
),
|
|
6565
|
+
scenarioConfigChanged: cases.some((row) => row.configChanged),
|
|
6566
|
+
// Run-level OR any single case's own. A suite that re-grades ONE case has
|
|
6567
|
+
// changed what that case measures, and the whole-run rate now mixes two
|
|
6568
|
+
// measurements — the run-level hash alone would miss it.
|
|
6569
|
+
evaluationConfigChanged: compare.scoreContract.evaluationConfigChanged || cases.some((row) => row.evaluationConfigChanged),
|
|
6570
|
+
iterationWeightingEqual: iterationWeightingEqualFrom(cases)
|
|
6571
|
+
};
|
|
6572
|
+
}
|
|
6573
|
+
function flakyInputFrom(iterations) {
|
|
6574
|
+
return iterations.filter(
|
|
6575
|
+
(iteration) => iteration.result === "passed" || iteration.result === "failed"
|
|
6576
|
+
).map((iteration) => ({
|
|
6577
|
+
// Falls back to the iteration's own id, never a shared literal: a
|
|
6578
|
+
// single "unknown" bucket would pool unrelated iterations, and one pass
|
|
6579
|
+
// plus one fail from two DIFFERENT cases would be reported as a flake
|
|
6580
|
+
// that never existed.
|
|
6581
|
+
caseKey: iteration.testCaseId ?? iteration.title ?? iteration.id,
|
|
6582
|
+
passed: iteration.result === "passed"
|
|
6583
|
+
}));
|
|
6584
|
+
}
|
|
6140
6585
|
|
|
6141
6586
|
// src/lib/terminal-image.ts
|
|
6142
6587
|
var ESC = "\x1B";
|
|
@@ -6417,6 +6862,418 @@ function resolveScreenshotPath(out, shot, index, total) {
|
|
|
6417
6862
|
}
|
|
6418
6863
|
return out;
|
|
6419
6864
|
}
|
|
6865
|
+
function collectRepeatable2(value, previous) {
|
|
6866
|
+
return [...previous, value];
|
|
6867
|
+
}
|
|
6868
|
+
var DEFAULT_GATE_WAIT_TIMEOUT_MS = 6e5;
|
|
6869
|
+
async function runEvalGate(options, command) {
|
|
6870
|
+
const globalOptions = getGlobalOptions(command);
|
|
6871
|
+
const policy = policyFromOptions({
|
|
6872
|
+
...options,
|
|
6873
|
+
noGatingScoreErrors: options.gatingScoreErrors === false
|
|
6874
|
+
});
|
|
6875
|
+
const waitTimeoutMs = options.waitTimeout !== void 0 ? parsePositiveInteger(options.waitTimeout, "--wait-timeout") : DEFAULT_GATE_WAIT_TIMEOUT_MS;
|
|
6876
|
+
let report;
|
|
6877
|
+
try {
|
|
6878
|
+
report = await runPlatformCommand7(
|
|
6879
|
+
options,
|
|
6880
|
+
Math.max(globalOptions.timeout, options.wait ? waitTimeoutMs : 0),
|
|
6881
|
+
async ({ client, signal }) => {
|
|
6882
|
+
const projects = await client.listProjects({}, { signal });
|
|
6883
|
+
const resolution = resolveProject(projects.items, options.project);
|
|
6884
|
+
if (!resolution.ok) {
|
|
6885
|
+
throw usageError(resolution.message);
|
|
6886
|
+
}
|
|
6887
|
+
const project = resolution.project;
|
|
6888
|
+
const deadline = Date.now() + waitTimeoutMs;
|
|
6889
|
+
let run = await client.getEvalRun(
|
|
6890
|
+
{ projectId: project.id, runId: options.run },
|
|
6891
|
+
{ signal }
|
|
6892
|
+
);
|
|
6893
|
+
while (!TERMINAL_RUN_STATUSES.has(run.status)) {
|
|
6894
|
+
if (!options.wait) {
|
|
6895
|
+
return {
|
|
6896
|
+
outcome: "incomplete",
|
|
6897
|
+
scoreIntegrity: "unknown",
|
|
6898
|
+
verdicts: [
|
|
6899
|
+
{
|
|
6900
|
+
gate: "run",
|
|
6901
|
+
status: "non_gateable",
|
|
6902
|
+
message: `run is ${run.status}; pass --wait, or gate it once it finishes`
|
|
6903
|
+
}
|
|
6904
|
+
]
|
|
6905
|
+
};
|
|
6906
|
+
}
|
|
6907
|
+
if (Date.now() >= deadline) {
|
|
6908
|
+
return {
|
|
6909
|
+
outcome: "incomplete",
|
|
6910
|
+
scoreIntegrity: "unknown",
|
|
6911
|
+
verdicts: [
|
|
6912
|
+
{
|
|
6913
|
+
gate: "wait",
|
|
6914
|
+
status: "non_gateable",
|
|
6915
|
+
message: `run still ${run.status} after ${waitTimeoutMs}ms`
|
|
6916
|
+
}
|
|
6917
|
+
]
|
|
6918
|
+
};
|
|
6919
|
+
}
|
|
6920
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
6921
|
+
run = await client.getEvalRun(
|
|
6922
|
+
{ projectId: project.id, runId: options.run },
|
|
6923
|
+
{ signal }
|
|
6924
|
+
);
|
|
6925
|
+
}
|
|
6926
|
+
if (isNonVerdictRunStatus(run.status)) {
|
|
6927
|
+
return {
|
|
6928
|
+
outcome: "incomplete",
|
|
6929
|
+
scoreIntegrity: "unknown",
|
|
6930
|
+
verdicts: [
|
|
6931
|
+
{
|
|
6932
|
+
gate: "run",
|
|
6933
|
+
status: "non_gateable",
|
|
6934
|
+
message: `run is ${run.status}; no verdict was established`
|
|
6935
|
+
}
|
|
6936
|
+
]
|
|
6937
|
+
};
|
|
6938
|
+
}
|
|
6939
|
+
const iterations = policyNeedsIterations(policy) ? await fetchAllIterations(client, signal, project.id, options.run) : void 0;
|
|
6940
|
+
return reportForRun(run, iterations, policy);
|
|
6941
|
+
}
|
|
6942
|
+
);
|
|
6943
|
+
} catch (error) {
|
|
6944
|
+
if (error instanceof Error && error.exitCode === EVAL_GATE_USAGE_EXIT_CODE) {
|
|
6945
|
+
throw error;
|
|
6946
|
+
}
|
|
6947
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
6948
|
+
writeResult(
|
|
6949
|
+
{
|
|
6950
|
+
gate: {
|
|
6951
|
+
outcome: "incomplete",
|
|
6952
|
+
scoreIntegrity: "unknown",
|
|
6953
|
+
verdicts: [
|
|
6954
|
+
{
|
|
6955
|
+
gate: "fetch",
|
|
6956
|
+
status: "non_gateable",
|
|
6957
|
+
message: `could not read the run: ${detail}`
|
|
6958
|
+
}
|
|
6959
|
+
]
|
|
6960
|
+
},
|
|
6961
|
+
exitCode: EVAL_GATE_INCOMPLETE_EXIT_CODE
|
|
6962
|
+
},
|
|
6963
|
+
globalOptions.format
|
|
6964
|
+
);
|
|
6965
|
+
setProcessExitCode(EVAL_GATE_INCOMPLETE_EXIT_CODE);
|
|
6966
|
+
return;
|
|
6967
|
+
}
|
|
6968
|
+
const exitCode = evalGateExitCode(report);
|
|
6969
|
+
writeResult({ gate: report, exitCode }, globalOptions.format);
|
|
6970
|
+
if (globalOptions.format === "human") {
|
|
6971
|
+
process.stderr.write(`${formatGateReport(report)}
|
|
6972
|
+
`);
|
|
6973
|
+
}
|
|
6974
|
+
if (exitCode !== 0) {
|
|
6975
|
+
setProcessExitCode(exitCode);
|
|
6976
|
+
}
|
|
6977
|
+
}
|
|
6978
|
+
async function runEvalCompare(options, command) {
|
|
6979
|
+
const globalOptions = getGlobalOptions(command);
|
|
6980
|
+
const policy = comparePolicyFromOptions(options);
|
|
6981
|
+
const reporter = parseReporterFormat(options.reporter);
|
|
6982
|
+
let outcome;
|
|
6983
|
+
try {
|
|
6984
|
+
outcome = await runPlatformCommand7(
|
|
6985
|
+
options,
|
|
6986
|
+
globalOptions.timeout,
|
|
6987
|
+
async ({ client, signal }) => {
|
|
6988
|
+
const projects = await client.listProjects({}, { signal });
|
|
6989
|
+
const resolution = resolveProject(projects.items, options.project);
|
|
6990
|
+
if (!resolution.ok) {
|
|
6991
|
+
throw usageError(resolution.message);
|
|
6992
|
+
}
|
|
6993
|
+
const project = resolution.project;
|
|
6994
|
+
const compare = await client.compareEvalRun(
|
|
6995
|
+
{
|
|
6996
|
+
projectId: project.id,
|
|
6997
|
+
runId: options.run,
|
|
6998
|
+
...options.baseRun ? { baseRunId: options.baseRun } : {}
|
|
6999
|
+
},
|
|
7000
|
+
{ signal }
|
|
7001
|
+
);
|
|
7002
|
+
const needsIterations = policy.maximumP95LatencyIncreaseMs !== void 0;
|
|
7003
|
+
const [baseIterations, compareIterations] = needsIterations ? await Promise.all([
|
|
7004
|
+
fetchAllIterations(
|
|
7005
|
+
client,
|
|
7006
|
+
signal,
|
|
7007
|
+
project.id,
|
|
7008
|
+
compare.baseRun.id
|
|
7009
|
+
),
|
|
7010
|
+
fetchAllIterations(
|
|
7011
|
+
client,
|
|
7012
|
+
signal,
|
|
7013
|
+
project.id,
|
|
7014
|
+
compare.compareRun.id
|
|
7015
|
+
)
|
|
7016
|
+
]) : [
|
|
7017
|
+
void 0,
|
|
7018
|
+
await fetchAllIterations(
|
|
7019
|
+
client,
|
|
7020
|
+
signal,
|
|
7021
|
+
project.id,
|
|
7022
|
+
compare.compareRun.id
|
|
7023
|
+
)
|
|
7024
|
+
];
|
|
7025
|
+
if (compare.baseRun.completedAt === null || compare.compareRun.completedAt === null) {
|
|
7026
|
+
return {
|
|
7027
|
+
report: {
|
|
7028
|
+
outcome: "incomplete",
|
|
7029
|
+
scoreIntegrity: "unknown",
|
|
7030
|
+
verdicts: [
|
|
7031
|
+
{
|
|
7032
|
+
gate: "run",
|
|
7033
|
+
status: "non_gateable",
|
|
7034
|
+
message: "both runs must be completed before they can be compared"
|
|
7035
|
+
}
|
|
7036
|
+
]
|
|
7037
|
+
},
|
|
7038
|
+
compare,
|
|
7039
|
+
flakyCases: []
|
|
7040
|
+
};
|
|
7041
|
+
}
|
|
7042
|
+
const input = compareGateInputFrom(compare, {
|
|
7043
|
+
baseP95Ms: p95Of(baseIterations),
|
|
7044
|
+
compareP95Ms: p95Of(compareIterations)
|
|
7045
|
+
});
|
|
7046
|
+
return {
|
|
7047
|
+
report: evaluateCompareGates(input, policy),
|
|
7048
|
+
compare,
|
|
7049
|
+
// Reported, NEVER gated. See `detectFlakyCases`.
|
|
7050
|
+
flakyCases: compareIterations?.complete ? detectFlakyCases(flakyInputFrom(compareIterations.items)) : []
|
|
7051
|
+
};
|
|
7052
|
+
}
|
|
7053
|
+
);
|
|
7054
|
+
} catch (error) {
|
|
7055
|
+
if (error instanceof Error && error.exitCode === EVAL_GATE_USAGE_EXIT_CODE) {
|
|
7056
|
+
throw error;
|
|
7057
|
+
}
|
|
7058
|
+
const reason = baselineNotFoundReason(error);
|
|
7059
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
7060
|
+
const report = {
|
|
7061
|
+
outcome: "incomplete",
|
|
7062
|
+
scoreIntegrity: "unknown",
|
|
7063
|
+
verdicts: [
|
|
7064
|
+
{
|
|
7065
|
+
gate: reason ? "baseline" : "fetch",
|
|
7066
|
+
status: "non_gateable",
|
|
7067
|
+
message: reason ? `no baseline to compare against: ${detail}` : `could not compare the runs: ${detail}`
|
|
7068
|
+
}
|
|
7069
|
+
]
|
|
7070
|
+
};
|
|
7071
|
+
await writeCompareResult(
|
|
7072
|
+
{ report, reporter, out: options.out, format: globalOptions.format },
|
|
7073
|
+
// Built whenever EITHER output channel was requested. `--reporter` needs
|
|
7074
|
+
// it to emit JUnit rather than JSON; `--out` needs it so a CI step
|
|
7075
|
+
// reading the artifact finds the verdict instead of a missing file.
|
|
7076
|
+
reporter || options.out ? emptyCompareReport(report) : void 0
|
|
7077
|
+
);
|
|
7078
|
+
setProcessExitCode(EVAL_GATE_INCOMPLETE_EXIT_CODE);
|
|
7079
|
+
return;
|
|
7080
|
+
}
|
|
7081
|
+
const exitCode = evalGateExitCode(outcome.report);
|
|
7082
|
+
await writeCompareResult(
|
|
7083
|
+
{
|
|
7084
|
+
report: outcome.report,
|
|
7085
|
+
reporter,
|
|
7086
|
+
out: options.out,
|
|
7087
|
+
format: globalOptions.format
|
|
7088
|
+
},
|
|
7089
|
+
outcome.compare ? buildRunCompareReport(outcome.compare, outcome.report, {
|
|
7090
|
+
flakyCases: outcome.flakyCases
|
|
7091
|
+
}) : void 0
|
|
7092
|
+
);
|
|
7093
|
+
if (globalOptions.format === "human" && !reporter) {
|
|
7094
|
+
process.stderr.write(`${formatGateReport(outcome.report)}
|
|
7095
|
+
`);
|
|
7096
|
+
}
|
|
7097
|
+
if (exitCode !== 0) {
|
|
7098
|
+
setProcessExitCode(exitCode);
|
|
7099
|
+
}
|
|
7100
|
+
}
|
|
7101
|
+
async function runEvalPull(options, command) {
|
|
7102
|
+
const globalOptions = getGlobalOptions(command);
|
|
7103
|
+
const lockPath = resolveCorpusLockPath(options.lock);
|
|
7104
|
+
const locked = options.frozen ? await readCorpusLock(lockPath) : void 0;
|
|
7105
|
+
let fetched;
|
|
7106
|
+
try {
|
|
7107
|
+
fetched = await runPlatformCommand7(
|
|
7108
|
+
options,
|
|
7109
|
+
globalOptions.timeout,
|
|
7110
|
+
async ({ client, signal }) => {
|
|
7111
|
+
const selector = {
|
|
7112
|
+
...options.project ? { project: options.project } : {},
|
|
7113
|
+
suite: options.suite
|
|
7114
|
+
};
|
|
7115
|
+
const [detail, page] = await Promise.all([
|
|
7116
|
+
getEvalSuiteOperation.execute(selector, { client, signal }),
|
|
7117
|
+
listEvalCasesOperation.execute(selector, { client, signal })
|
|
7118
|
+
]);
|
|
7119
|
+
if (page.nextCursor) {
|
|
7120
|
+
throw cliError(
|
|
7121
|
+
"CORPUS_TRUNCATED",
|
|
7122
|
+
`Suite "${options.suite}" returned more cases than one page and this CLI cannot follow the cursor. Upgrade @mcpjam/cli.`,
|
|
7123
|
+
CORPUS_INCOMPLETE_EXIT_CODE
|
|
7124
|
+
);
|
|
7125
|
+
}
|
|
7126
|
+
return {
|
|
7127
|
+
suite: {
|
|
7128
|
+
id: detail.id,
|
|
7129
|
+
...detail.name ? { name: detail.name } : {}
|
|
7130
|
+
},
|
|
7131
|
+
cases: page.items,
|
|
7132
|
+
suiteChecks: detail.settings.checks ?? [],
|
|
7133
|
+
...detail.settings.matchOptions ? { suiteMatchOptions: detail.settings.matchOptions } : {}
|
|
7134
|
+
};
|
|
7135
|
+
}
|
|
7136
|
+
);
|
|
7137
|
+
} catch (error) {
|
|
7138
|
+
throw corpusFetchFailure(error);
|
|
7139
|
+
}
|
|
7140
|
+
let corpus;
|
|
7141
|
+
try {
|
|
7142
|
+
corpus = buildCorpus({
|
|
7143
|
+
...options.project ? { project: options.project } : {},
|
|
7144
|
+
suite: fetched.suite,
|
|
7145
|
+
cases: fetched.cases,
|
|
7146
|
+
suiteChecks: fetched.suiteChecks,
|
|
7147
|
+
...fetched.suiteMatchOptions ? { suiteMatchOptions: fetched.suiteMatchOptions } : {},
|
|
7148
|
+
unsupported: options.skipUnsupported ? "skip" : "error",
|
|
7149
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7150
|
+
});
|
|
7151
|
+
} catch (error) {
|
|
7152
|
+
if (error instanceof HostedOnlyCaseError) {
|
|
7153
|
+
throw cliError(
|
|
7154
|
+
"CORPUS_HOSTED_ONLY_CASE",
|
|
7155
|
+
`${error.message} Pass --skip-unsupported to omit cases like this from the corpus and the lock.`,
|
|
7156
|
+
CORPUS_USAGE_EXIT_CODE,
|
|
7157
|
+
{ caseId: error.caseId, caseTitle: error.caseTitle }
|
|
7158
|
+
);
|
|
7159
|
+
}
|
|
7160
|
+
throw cliError(
|
|
7161
|
+
"CORPUS_INVALID_CASE",
|
|
7162
|
+
error instanceof Error ? error.message : String(error),
|
|
7163
|
+
CORPUS_USAGE_EXIT_CODE
|
|
7164
|
+
);
|
|
7165
|
+
}
|
|
7166
|
+
const summary = {
|
|
7167
|
+
suite: corpus.suite,
|
|
7168
|
+
cases: corpus.cases.length,
|
|
7169
|
+
skipped: corpus.skipped,
|
|
7170
|
+
evaluationConfigHash: corpus.lock.evaluationConfigHash
|
|
7171
|
+
};
|
|
7172
|
+
if (locked) {
|
|
7173
|
+
const drift = verifyCorpusLock(locked, corpus.lock);
|
|
7174
|
+
writeResult(
|
|
7175
|
+
{ ...summary, lockPath, frozen: true, drift },
|
|
7176
|
+
globalOptions.format
|
|
7177
|
+
);
|
|
7178
|
+
if (globalOptions.format === "human") {
|
|
7179
|
+
process.stderr.write(`${renderCorpusDrift(drift)}
|
|
7180
|
+
`);
|
|
7181
|
+
}
|
|
7182
|
+
if (drift.length > 0) {
|
|
7183
|
+
setProcessExitCode(CORPUS_DRIFT_EXIT_CODE);
|
|
7184
|
+
}
|
|
7185
|
+
return;
|
|
7186
|
+
}
|
|
7187
|
+
const written = await writeCorpusLockAtomic(lockPath, corpus.lock);
|
|
7188
|
+
writeResult(
|
|
7189
|
+
{ ...summary, lockPath: written, written: true },
|
|
7190
|
+
globalOptions.format
|
|
7191
|
+
);
|
|
7192
|
+
}
|
|
7193
|
+
function emptyCompareReport(report) {
|
|
7194
|
+
return buildRunCompareReport(
|
|
7195
|
+
{
|
|
7196
|
+
suite: { id: "", name: "" },
|
|
7197
|
+
baseline: { policy: "previous_completed", baseRunId: "" },
|
|
7198
|
+
baseRun: {
|
|
7199
|
+
id: "",
|
|
7200
|
+
runNumber: 0,
|
|
7201
|
+
result: "",
|
|
7202
|
+
createdAt: 0,
|
|
7203
|
+
completedAt: null,
|
|
7204
|
+
summary: null
|
|
7205
|
+
},
|
|
7206
|
+
compareRun: {
|
|
7207
|
+
id: "",
|
|
7208
|
+
runNumber: 0,
|
|
7209
|
+
result: "",
|
|
7210
|
+
createdAt: 0,
|
|
7211
|
+
completedAt: null,
|
|
7212
|
+
summary: null
|
|
7213
|
+
},
|
|
7214
|
+
passSummary: {
|
|
7215
|
+
passRatePercent: EMPTY_DIFF,
|
|
7216
|
+
total: EMPTY_DIFF,
|
|
7217
|
+
passed: EMPTY_DIFF,
|
|
7218
|
+
failed: EMPTY_DIFF
|
|
7219
|
+
},
|
|
7220
|
+
metrics: {
|
|
7221
|
+
wallDurationMs: EMPTY_DIFF,
|
|
7222
|
+
totalTokens: EMPTY_DIFF,
|
|
7223
|
+
estimatedCostUsd: EMPTY_DIFF
|
|
7224
|
+
},
|
|
7225
|
+
scoreContract: {
|
|
7226
|
+
base: {
|
|
7227
|
+
evaluationConfigHash: null,
|
|
7228
|
+
scoreIntegrity: null,
|
|
7229
|
+
scoredIterations: 0,
|
|
7230
|
+
quarantinedIterations: 0
|
|
7231
|
+
},
|
|
7232
|
+
compare: {
|
|
7233
|
+
evaluationConfigHash: null,
|
|
7234
|
+
scoreIntegrity: null,
|
|
7235
|
+
scoredIterations: 0,
|
|
7236
|
+
quarantinedIterations: 0
|
|
7237
|
+
},
|
|
7238
|
+
evaluationConfigChanged: false,
|
|
7239
|
+
scorers: []
|
|
7240
|
+
},
|
|
7241
|
+
cases: []
|
|
7242
|
+
},
|
|
7243
|
+
report
|
|
7244
|
+
);
|
|
7245
|
+
}
|
|
7246
|
+
var EMPTY_DIFF = {
|
|
7247
|
+
base: null,
|
|
7248
|
+
compare: null,
|
|
7249
|
+
delta: null,
|
|
7250
|
+
percentDelta: null
|
|
7251
|
+
};
|
|
7252
|
+
function p95Of(iterations) {
|
|
7253
|
+
if (!iterations?.complete) return void 0;
|
|
7254
|
+
const durations = iterations.items.map((iteration) => iteration.durationMs).filter((ms) => typeof ms === "number");
|
|
7255
|
+
if (durations.length === 0 || durations.length !== iterations.items.length) {
|
|
7256
|
+
return void 0;
|
|
7257
|
+
}
|
|
7258
|
+
return calculateLatencyStats(durations).p95;
|
|
7259
|
+
}
|
|
7260
|
+
function baselineNotFoundReason(error) {
|
|
7261
|
+
const details = error?.details;
|
|
7262
|
+
return typeof details === "object" && details !== null && details.reason === "BASELINE_NOT_FOUND";
|
|
7263
|
+
}
|
|
7264
|
+
async function writeCompareResult(args, structured) {
|
|
7265
|
+
if (args.out && structured) {
|
|
7266
|
+
await writeJsonArtifact(args.out, structured);
|
|
7267
|
+
}
|
|
7268
|
+
if (args.reporter && structured) {
|
|
7269
|
+
writeReporterResult(args.reporter, structured);
|
|
7270
|
+
return;
|
|
7271
|
+
}
|
|
7272
|
+
writeResult(
|
|
7273
|
+
{ compare: args.report, exitCode: evalGateExitCode(args.report) },
|
|
7274
|
+
args.format
|
|
7275
|
+
);
|
|
7276
|
+
}
|
|
6420
7277
|
function registerEvalCommands(program) {
|
|
6421
7278
|
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
6422
7279
|
addPlatformOptions7(
|
|
@@ -6584,6 +7441,91 @@ function registerEvalCommands(program) {
|
|
|
6584
7441
|
await executeOp2(listEvalRunIterationsOperation, input, options, command);
|
|
6585
7442
|
}
|
|
6586
7443
|
);
|
|
7444
|
+
addPlatformOptions7(
|
|
7445
|
+
evals.command("gate").description(
|
|
7446
|
+
"Apply a pass/fail policy to a finished eval run and set an exit code (0 pass, 1 eval failure, 2 usage, 3 incomplete)"
|
|
7447
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
7448
|
+
"--project <id-or-name>",
|
|
7449
|
+
"Project the run belongs to (name or ID)"
|
|
7450
|
+
).option(
|
|
7451
|
+
"--min-pass-rate-percent <0-100>",
|
|
7452
|
+
"Minimum share of iterations that must pass, as a percentage"
|
|
7453
|
+
).option(
|
|
7454
|
+
"--no-gating-score-errors",
|
|
7455
|
+
"Fail if any gating scorer errored during the run"
|
|
7456
|
+
).option(
|
|
7457
|
+
"--min-scorer-pass-rate <scorerId=percent>",
|
|
7458
|
+
"Minimum pass rate for one scorer (repeatable)",
|
|
7459
|
+
collectRepeatable2,
|
|
7460
|
+
[]
|
|
7461
|
+
).option(
|
|
7462
|
+
"--min-mean-score <scorerId=0..1>",
|
|
7463
|
+
"Minimum mean score for one scorer (repeatable)",
|
|
7464
|
+
collectRepeatable2,
|
|
7465
|
+
[]
|
|
7466
|
+
).option("--wait", "Poll until the run reaches a terminal status").option(
|
|
7467
|
+
"--wait-timeout <ms>",
|
|
7468
|
+
"Give up waiting after this many milliseconds (default 600000)"
|
|
7469
|
+
)
|
|
7470
|
+
).action(
|
|
7471
|
+
async (options, command) => {
|
|
7472
|
+
await runEvalGate(options, command);
|
|
7473
|
+
}
|
|
7474
|
+
);
|
|
7475
|
+
addPlatformOptions7(
|
|
7476
|
+
evals.command("compare").description(
|
|
7477
|
+
"Compare a finished eval run against a baseline and set an exit code (0 pass, 1 regression, 2 usage, 3 incomplete)"
|
|
7478
|
+
).requiredOption("--run <id>", "Eval run ID to compare").requiredOption(
|
|
7479
|
+
"--project <id-or-name>",
|
|
7480
|
+
"Project the run belongs to (name or ID)"
|
|
7481
|
+
).option(
|
|
7482
|
+
"--base-run <id>",
|
|
7483
|
+
"Baseline run ID (defaults to the nearest earlier completed run in the same suite)"
|
|
7484
|
+
).option(
|
|
7485
|
+
"--gate-regressions",
|
|
7486
|
+
"Fail on a statistically significant pass-rate regression"
|
|
7487
|
+
).option(
|
|
7488
|
+
"--min-sample-size <n>",
|
|
7489
|
+
"Iterations required on EACH side before a pass-rate regression is decidable (default 5)"
|
|
7490
|
+
).option(
|
|
7491
|
+
"--min-effect-size-percent <0-100>",
|
|
7492
|
+
"Smallest pass-rate drop worth failing on, as a percentage (default 1)"
|
|
7493
|
+
).option(
|
|
7494
|
+
"--gate-deterministic-regressions",
|
|
7495
|
+
"Fail if a deterministic gating scorer flipped from passed to failed"
|
|
7496
|
+
).option(
|
|
7497
|
+
"--max-p95-latency-increase-ms <ms>",
|
|
7498
|
+
"Fail if p95 end-to-end latency rose by more than this many milliseconds"
|
|
7499
|
+
).option(
|
|
7500
|
+
"--reporter <json-summary|junit-xml>",
|
|
7501
|
+
"Write a structured report to stdout instead of the default output"
|
|
7502
|
+
).option("--out <path>", "Write the structured report to a JSON file")
|
|
7503
|
+
).action(
|
|
7504
|
+
async (options, command) => {
|
|
7505
|
+
await runEvalCompare(options, command);
|
|
7506
|
+
}
|
|
7507
|
+
);
|
|
7508
|
+
addPlatformOptions7(
|
|
7509
|
+
evals.command("pull").description(
|
|
7510
|
+
"Materialize a hosted eval suite into a local corpus lock (0 clean, 1 drift under --frozen, 2 usage, 3 incomplete)"
|
|
7511
|
+
).requiredOption("--suite <id-or-name>", "Eval suite to pull (name or ID)").option(
|
|
7512
|
+
"--project <id-or-name>",
|
|
7513
|
+
"Project the suite belongs to (defaults to the most recently updated project)"
|
|
7514
|
+
).option(
|
|
7515
|
+
"--lock <path>",
|
|
7516
|
+
`Lock file path (default ${DEFAULT_CORPUS_LOCK_PATH})`
|
|
7517
|
+
).option(
|
|
7518
|
+
"--frozen",
|
|
7519
|
+
"Verify the lock matches the hosted suite without writing; exit 1 on drift"
|
|
7520
|
+
).option(
|
|
7521
|
+
"--skip-unsupported",
|
|
7522
|
+
"Omit cases a local run cannot execute instead of failing"
|
|
7523
|
+
)
|
|
7524
|
+
).action(
|
|
7525
|
+
async (options, command) => {
|
|
7526
|
+
await runEvalPull(options, command);
|
|
7527
|
+
}
|
|
7528
|
+
);
|
|
6587
7529
|
addPlatformOptions7(
|
|
6588
7530
|
evals.command("trace").description(
|
|
6589
7531
|
"Fetch the full trace for one eval iteration (large: full message history + spans)"
|
|
@@ -6684,15 +7626,15 @@ function registerEvalCommands(program) {
|
|
|
6684
7626
|
shot.screenshotUrl,
|
|
6685
7627
|
globalOptions.timeout
|
|
6686
7628
|
);
|
|
6687
|
-
const
|
|
7629
|
+
const path7 = resolveScreenshotPath(
|
|
6688
7630
|
options.out,
|
|
6689
7631
|
shot,
|
|
6690
7632
|
i,
|
|
6691
7633
|
shots.length
|
|
6692
7634
|
);
|
|
6693
|
-
mkdirSync(dirname(
|
|
6694
|
-
writeFileSync(
|
|
6695
|
-
saved.push({ ...shot, savedTo:
|
|
7635
|
+
mkdirSync(dirname(path7), { recursive: true });
|
|
7636
|
+
writeFileSync(path7, bytes);
|
|
7637
|
+
saved.push({ ...shot, savedTo: path7 });
|
|
6696
7638
|
}
|
|
6697
7639
|
if (isJson) {
|
|
6698
7640
|
writeResult({ ...base, items: saved });
|
|
@@ -8094,6 +9036,64 @@ function registerOrganizationsCommands(program) {
|
|
|
8094
9036
|
}
|
|
8095
9037
|
});
|
|
8096
9038
|
}
|
|
9039
|
+
function requireQuery(value) {
|
|
9040
|
+
const trimmed = value?.trim() ?? "";
|
|
9041
|
+
if (trimmed.length === 0) {
|
|
9042
|
+
throw usageError("--query needs search terms.");
|
|
9043
|
+
}
|
|
9044
|
+
return trimmed;
|
|
9045
|
+
}
|
|
9046
|
+
function parseSources(value) {
|
|
9047
|
+
if (value === void 0) return void 0;
|
|
9048
|
+
const parsed = value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
9049
|
+
if (parsed.length === 0) {
|
|
9050
|
+
throw usageError(
|
|
9051
|
+
"--source was given but names no surfaces. Pass a comma-separated list (direct, scenario, eval, swarm), or omit the flag to search all of them."
|
|
9052
|
+
);
|
|
9053
|
+
}
|
|
9054
|
+
return parsed;
|
|
9055
|
+
}
|
|
9056
|
+
function registerSessionsCommands(program) {
|
|
9057
|
+
const sessions = program.command("sessions").description(
|
|
9058
|
+
"Search the conversations recorded in a project \u2014 Playground, user testing, evals and swarms in one place."
|
|
9059
|
+
);
|
|
9060
|
+
bindOperation(
|
|
9061
|
+
addProjectOption(
|
|
9062
|
+
sessions.command("search").description(
|
|
9063
|
+
"Search a project's sessions by relevance. Searches titles and opening messages by default; pass --scope transcripts to search what was actually said inside the conversations. Every result carries a link you can open."
|
|
9064
|
+
).requiredOption("--query <text>", "Search terms").option(
|
|
9065
|
+
"--scope <scope>",
|
|
9066
|
+
"titles (default) or transcripts. Transcript search excludes sessions created before 2026-08-14."
|
|
9067
|
+
).option(
|
|
9068
|
+
"--source <types>",
|
|
9069
|
+
"Comma-separated surfaces: direct, scenario, eval, swarm. Defaults to all."
|
|
9070
|
+
).option("--status <status>", "active (default) or archived").option("--limit <n>", "Results per page (1-200)").option(
|
|
9071
|
+
"--cursor <cursor>",
|
|
9072
|
+
"Opaque cursor from a previous page's nextCursor. Page with the same --query and --scope you started with."
|
|
9073
|
+
)
|
|
9074
|
+
),
|
|
9075
|
+
searchSessionsOperation,
|
|
9076
|
+
(options) => ({
|
|
9077
|
+
// `.requiredOption` guarantees the flag is PRESENT, not that it says
|
|
9078
|
+
// anything — `--query ""` satisfies Commander. The operation rejects a
|
|
9079
|
+
// blank query too (it is search-only), but failing here names the flag
|
|
9080
|
+
// the user typed instead of reporting a validation error about `q`.
|
|
9081
|
+
query: requireQuery(options.query),
|
|
9082
|
+
project: options.project,
|
|
9083
|
+
// Passed through unvalidated: the operation's schema owns the vocabulary
|
|
9084
|
+
// for these, and re-listing the allowed values here would be a second
|
|
9085
|
+
// place to update when one is added.
|
|
9086
|
+
scope: options.scope,
|
|
9087
|
+
sourceTypes: parseSources(options.source),
|
|
9088
|
+
status: options.status,
|
|
9089
|
+
limit: parseIntegerOption(options.limit, "--limit", {
|
|
9090
|
+
min: 1,
|
|
9091
|
+
max: 200
|
|
9092
|
+
}),
|
|
9093
|
+
cursor: options.cursor
|
|
9094
|
+
})
|
|
9095
|
+
);
|
|
9096
|
+
}
|
|
8097
9097
|
function addPlatformOptions10(command) {
|
|
8098
9098
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
8099
9099
|
"--api-url <url>",
|
|
@@ -13089,7 +14089,7 @@ function buildCompactInspectorRender(uiResult, options = {}) {
|
|
|
13089
14089
|
hasCommandError = true;
|
|
13090
14090
|
}
|
|
13091
14091
|
}
|
|
13092
|
-
const topLevelError = options.skipped ? options.issue ? { warning: options.issue } : uiResult.status === "error" &&
|
|
14092
|
+
const topLevelError = options.skipped ? options.issue ? { warning: options.issue } : uiResult.status === "error" && isRecord4(uiResult.error) ? { warning: uiResult.error } : {} : options.issue ? { error: options.issue } : uiResult.status === "error" && isRecord4(uiResult.error) ? { error: uiResult.error } : {};
|
|
13093
14093
|
return {
|
|
13094
14094
|
status: options.skipped ? "skipped" : hasCommandError || uiResult.status === "error" ? "error" : "rendered",
|
|
13095
14095
|
remediation: options.remediation ?? "none",
|
|
@@ -13118,18 +14118,18 @@ function parseInspectorFrontendUrl(value) {
|
|
|
13118
14118
|
return frontendUrl;
|
|
13119
14119
|
}
|
|
13120
14120
|
function compactInspectorCommandResponse(value) {
|
|
13121
|
-
if (!
|
|
14121
|
+
if (!isRecord4(value) || !isCompactInspectorCommandStatus(value.status)) {
|
|
13122
14122
|
return void 0;
|
|
13123
14123
|
}
|
|
13124
14124
|
return {
|
|
13125
14125
|
status: value.status,
|
|
13126
|
-
...value.status === "error" &&
|
|
14126
|
+
...value.status === "error" && isRecord4(value.error) ? { error: value.error } : {}
|
|
13127
14127
|
};
|
|
13128
14128
|
}
|
|
13129
14129
|
function isCompactInspectorCommandStatus(value) {
|
|
13130
14130
|
return value === "success" || value === "error";
|
|
13131
14131
|
}
|
|
13132
|
-
function
|
|
14132
|
+
function isRecord4(value) {
|
|
13133
14133
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
13134
14134
|
}
|
|
13135
14135
|
function tunnelPathPrefix(serverId) {
|
|
@@ -14265,6 +15265,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
14265
15265
|
registerProjectsCommands(program);
|
|
14266
15266
|
registerEvalCommands(program);
|
|
14267
15267
|
registerChatCommands(program);
|
|
15268
|
+
registerSessionsCommands(program);
|
|
14268
15269
|
registerHostsCommands(program);
|
|
14269
15270
|
registerEnvironmentsCommands(program);
|
|
14270
15271
|
const journeys = registerJourneysCommands(program);
|