stageflow 0.40.0 → 0.44.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/README.md +15 -4
- package/dist/agent/activity.d.ts +18 -0
- package/dist/agent/claudeAdapter.js +7 -0
- package/dist/agent/claudeTools.d.ts +27 -18
- package/dist/agent/claudeTools.js +54 -15
- package/dist/agent/compactionEvents.d.ts +34 -0
- package/dist/agent/compactionEvents.js +37 -0
- package/dist/agent/openRouterRouting.d.ts +7 -0
- package/dist/agent/openRouterRouting.js +23 -0
- package/dist/agent/piAdapter.d.ts +6 -0
- package/dist/agent/piAdapter.js +128 -27
- package/dist/agent/piSettings.d.ts +7 -0
- package/dist/agent/piSettings.js +9 -0
- package/dist/agent/sandboxPiTools.d.ts +3 -1
- package/dist/agent/sandboxPiTools.js +8 -2
- package/dist/agent/stageTurnDriver.d.ts +11 -2
- package/dist/agent/stageTurnDriver.js +45 -4
- package/dist/agent/toolOutputBudget.d.ts +15 -1
- package/dist/agent/toolOutputBudget.js +18 -0
- package/dist/agent/toolOutputBudgetExtension.d.ts +2 -0
- package/dist/agent/toolOutputBudgetExtension.js +40 -3
- package/dist/agents/authorChat.d.ts +5 -0
- package/dist/agents/authorChat.js +120 -12
- package/dist/agents/authorSessionStore.d.ts +38 -0
- package/dist/agents/authorSessionStore.js +167 -0
- package/dist/agents/chatTurn.d.ts +2 -0
- package/dist/agents/chatTurn.js +17 -1
- package/dist/agents/errors.d.ts +1 -1
- package/dist/agents/errors.js +1 -0
- package/dist/agents/evalGate.d.ts +61 -0
- package/dist/agents/evalGate.js +103 -0
- package/dist/agents/evalSession.d.ts +26 -0
- package/dist/agents/evalSession.js +29 -0
- package/dist/agents/hostContext.d.ts +4 -1
- package/dist/agents/hostContext.js +4 -1
- package/dist/agents/runtime/piRuntime.d.ts +6 -2
- package/dist/agents/runtime/piRuntime.js +50 -16
- package/dist/agents/runtime/types.d.ts +3 -1
- package/dist/agents/service.d.ts +27 -2
- package/dist/agents/service.js +91 -15
- package/dist/agents/sessions.d.ts +8 -0
- package/dist/agents/sessions.js +53 -11
- package/dist/agents/store.d.ts +14 -3
- package/dist/agents/store.js +45 -7
- package/dist/agents/toolRisk.d.ts +21 -0
- package/dist/agents/toolRisk.js +50 -0
- package/dist/cli/doctorCommand.js +26 -0
- package/dist/cli/evalCommand.d.ts +20 -0
- package/dist/cli/evalCommand.js +720 -0
- package/dist/cli/exportAllCommand.js +1 -1
- package/dist/cli/hostClient.d.ts +60 -0
- package/dist/cli/hostClient.js +71 -0
- package/dist/cli/validateOutput.d.ts +2 -2
- package/dist/cli/validateOutput.js +2 -2
- package/dist/cli.js +10 -0
- package/dist/compaction/directives.d.ts +18 -0
- package/dist/compaction/directives.js +119 -0
- package/dist/compaction/extension.d.ts +20 -0
- package/dist/compaction/extension.js +78 -0
- package/dist/compaction/mask.d.ts +18 -0
- package/dist/compaction/mask.js +155 -0
- package/dist/compaction/pin.d.ts +21 -0
- package/dist/compaction/pin.js +270 -0
- package/dist/compaction/scrub.d.ts +7 -0
- package/dist/compaction/scrub.js +26 -0
- package/dist/compaction/sessionWiring.d.ts +22 -0
- package/dist/compaction/sessionWiring.js +26 -0
- package/dist/compaction/summarize.d.ts +79 -0
- package/dist/compaction/summarize.js +171 -0
- package/dist/compaction/toolPolicy.d.ts +3 -0
- package/dist/compaction/toolPolicy.js +33 -0
- package/dist/compaction/types.d.ts +45 -0
- package/dist/compaction/types.js +7 -0
- package/dist/compaction/workingState.d.ts +56 -0
- package/dist/compaction/workingState.js +198 -0
- package/dist/config/atomicWrite.d.ts +15 -0
- package/dist/config/atomicWrite.js +43 -0
- package/dist/config/browseCatalog.d.ts +2 -0
- package/dist/config/browseCatalog.js +4 -2
- package/dist/config/createPipeline.js +2 -0
- package/dist/config/createTrigger.js +7 -1
- package/dist/config/csv.d.ts +9 -0
- package/dist/config/csv.js +81 -0
- package/dist/config/datasetAgentCheck.d.ts +18 -0
- package/dist/config/datasetAgentCheck.js +109 -0
- package/dist/config/datasetCandidates.d.ts +22 -0
- package/dist/config/datasetCandidates.js +86 -0
- package/dist/config/datasetFromSessions.d.ts +34 -0
- package/dist/config/datasetFromSessions.js +105 -0
- package/dist/config/datasetHash.d.ts +1 -0
- package/dist/config/datasetHash.js +4 -0
- package/dist/config/datasetImport.d.ts +21 -0
- package/dist/config/datasetImport.js +120 -0
- package/dist/config/datasetStageCheck.d.ts +9 -0
- package/dist/config/datasetStageCheck.js +17 -0
- package/dist/config/datasetTypes.d.ts +27 -0
- package/dist/config/datasetTypes.js +1 -0
- package/dist/config/ensureCatalogScanRoot.d.ts +4 -1
- package/dist/config/ensureCatalogScanRoot.js +8 -6
- package/dist/config/evalCatalog.d.ts +22 -0
- package/dist/config/evalCatalog.js +95 -0
- package/dist/config/evalWriteRoots.d.ts +17 -0
- package/dist/config/evalWriteRoots.js +109 -0
- package/dist/config/githubTriggerAction.d.ts +8 -0
- package/dist/config/githubTriggerAction.js +29 -0
- package/dist/config/hostConfig.js +3 -0
- package/dist/config/installEvalSample.d.ts +34 -0
- package/dist/config/installEvalSample.js +182 -0
- package/dist/config/loadDataset.d.ts +16 -0
- package/dist/config/loadDataset.js +318 -0
- package/dist/config/loadEval.d.ts +32 -0
- package/dist/config/loadEval.js +1103 -0
- package/dist/config/loadOutcome.d.ts +5 -0
- package/dist/config/loadStageflowManifest.js +64 -0
- package/dist/config/pipelineNeeds.d.ts +2 -0
- package/dist/config/pipelineNeeds.js +16 -3
- package/dist/config/pipelineRoute.js +5 -4
- package/dist/config/resolveAgentTarget.d.ts +32 -0
- package/dist/config/resolveAgentTarget.js +118 -0
- package/dist/config/resolveEvalTarget.d.ts +21 -0
- package/dist/config/resolveEvalTarget.js +89 -0
- package/dist/config/scanCatalogPaths.d.ts +1 -1
- package/dist/config/scanCatalogPaths.js +17 -5
- package/dist/config/validateCatalog.d.ts +2 -2
- package/dist/config/validateCatalog.js +21 -1
- package/dist/config/validateEval.d.ts +36 -0
- package/dist/config/validateEval.js +446 -0
- package/dist/config/writeDataset.d.ts +54 -0
- package/dist/config/writeDataset.js +186 -0
- package/dist/config/writeEval.d.ts +25 -0
- package/dist/config/writeEval.js +398 -0
- package/dist/diagnostics/checks.js +1 -1
- package/dist/envelope/assertEmittedArtifacts.d.ts +12 -0
- package/dist/envelope/assertEmittedArtifacts.js +43 -0
- package/dist/envelope/preEmitChecks.d.ts +3 -0
- package/dist/evals/agentDiff.d.ts +13 -0
- package/dist/evals/agentDiff.js +11 -0
- package/dist/evals/canonical.d.ts +3 -0
- package/dist/evals/canonical.js +24 -0
- package/dist/evals/caseTask.d.ts +3 -0
- package/dist/evals/caseTask.js +9 -0
- package/dist/evals/compare.d.ts +94 -0
- package/dist/evals/compare.js +201 -0
- package/dist/evals/constants.d.ts +62 -0
- package/dist/evals/constants.js +97 -0
- package/dist/evals/engine/FakeEngine.d.ts +33 -0
- package/dist/evals/engine/FakeEngine.js +177 -0
- package/dist/evals/engine/index.d.ts +9 -0
- package/dist/evals/engine/index.js +19 -0
- package/dist/evals/engine/promptfoo/PromptfooEngine.d.ts +52 -0
- package/dist/evals/engine/promptfoo/PromptfooEngine.js +312 -0
- package/dist/evals/engine/promptfoo/errors.d.ts +5 -0
- package/dist/evals/engine/promptfoo/errors.js +8 -0
- package/dist/evals/engine/promptfoo/generate.d.ts +30 -0
- package/dist/evals/engine/promptfoo/generate.js +345 -0
- package/dist/evals/engine/promptfoo/guard.d.ts +10 -0
- package/dist/evals/engine/promptfoo/guard.js +116 -0
- package/dist/evals/engine/promptfoo/install.d.ts +17 -0
- package/dist/evals/engine/promptfoo/install.js +73 -0
- package/dist/evals/engine/promptfoo/judgeProviders.d.ts +2 -0
- package/dist/evals/engine/promptfoo/judgeProviders.js +9 -0
- package/dist/evals/engine/promptfoo/judgeServices.d.ts +6 -0
- package/dist/evals/engine/promptfoo/judgeServices.js +41 -0
- package/dist/evals/engine/promptfoo/locate.d.ts +21 -0
- package/dist/evals/engine/promptfoo/locate.js +68 -0
- package/dist/evals/engine/promptfoo/nodeVersion.d.ts +7 -0
- package/dist/evals/engine/promptfoo/nodeVersion.js +14 -0
- package/dist/evals/engine/promptfoo/normalize.d.ts +66 -0
- package/dist/evals/engine/promptfoo/normalize.js +261 -0
- package/dist/evals/engine/promptfoo/pinned.d.ts +5 -0
- package/dist/evals/engine/promptfoo/pinned.js +5 -0
- package/dist/evals/engine/promptfoo/rubricPrompt.d.ts +14 -0
- package/dist/evals/engine/promptfoo/rubricPrompt.js +105 -0
- package/dist/evals/engine/promptfoo/runTokens.d.ts +18 -0
- package/dist/evals/engine/promptfoo/runTokens.js +31 -0
- package/dist/evals/engine/promptfoo/status.d.ts +13 -0
- package/dist/evals/engine/promptfoo/status.js +16 -0
- package/dist/evals/estimate.d.ts +56 -0
- package/dist/evals/estimate.js +66 -0
- package/dist/evals/graders/codeGrader.d.ts +6 -0
- package/dist/evals/graders/codeGrader.js +85 -0
- package/dist/evals/graders/conversationCheckGrader.d.ts +6 -0
- package/dist/evals/graders/conversationCheckGrader.js +62 -0
- package/dist/evals/graders/fieldGrader.d.ts +11 -0
- package/dist/evals/graders/fieldGrader.js +117 -0
- package/dist/evals/graders/goal.d.ts +3 -0
- package/dist/evals/graders/goal.js +14 -0
- package/dist/evals/graders/index.d.ts +18 -0
- package/dist/evals/graders/index.js +34 -0
- package/dist/evals/graders/notApplicable.d.ts +5 -0
- package/dist/evals/graders/notApplicable.js +9 -0
- package/dist/evals/graders/path.d.ts +26 -0
- package/dist/evals/graders/path.js +75 -0
- package/dist/evals/graders/referenceGrader.d.ts +5 -0
- package/dist/evals/graders/referenceGrader.js +59 -0
- package/dist/evals/graders/schemaGrader.d.ts +5 -0
- package/dist/evals/graders/schemaGrader.js +29 -0
- package/dist/evals/graders/subject.d.ts +6 -0
- package/dist/evals/graders/subject.js +33 -0
- package/dist/evals/graders/toolCallsGrader.d.ts +6 -0
- package/dist/evals/graders/toolCallsGrader.js +100 -0
- package/dist/evals/graders/transcript.d.ts +12 -0
- package/dist/evals/graders/transcript.js +57 -0
- package/dist/evals/graders/types.d.ts +20 -0
- package/dist/evals/graders/types.js +1 -0
- package/dist/evals/judgeProviders.d.ts +16 -0
- package/dist/evals/judgeProviders.js +27 -0
- package/dist/evals/lineDiff.d.ts +5 -0
- package/dist/evals/lineDiff.js +34 -0
- package/dist/evals/listStatus.d.ts +31 -0
- package/dist/evals/listStatus.js +48 -0
- package/dist/evals/manager.d.ts +187 -0
- package/dist/evals/manager.js +795 -0
- package/dist/evals/plan.d.ts +65 -0
- package/dist/evals/plan.js +621 -0
- package/dist/evals/planInternalAgent.d.ts +19 -0
- package/dist/evals/planInternalAgent.js +205 -0
- package/dist/evals/providerKeys.d.ts +1 -0
- package/dist/evals/providerKeys.js +21 -0
- package/dist/evals/read/agentTargets.d.ts +37 -0
- package/dist/evals/read/agentTargets.js +101 -0
- package/dist/evals/read/api.d.ts +208 -0
- package/dist/evals/read/api.js +363 -0
- package/dist/evals/read/compare.d.ts +4 -0
- package/dist/evals/read/compare.js +39 -0
- package/dist/evals/read/datasets.d.ts +105 -0
- package/dist/evals/read/datasets.js +318 -0
- package/dist/evals/read/list.d.ts +66 -0
- package/dist/evals/read/list.js +182 -0
- package/dist/evals/read/results.d.ts +46 -0
- package/dist/evals/read/results.js +107 -0
- package/dist/evals/read/runs.d.ts +154 -0
- package/dist/evals/read/runs.js +295 -0
- package/dist/evals/read/suggestions.d.ts +43 -0
- package/dist/evals/read/suggestions.js +73 -0
- package/dist/evals/runner/FakeAgentBackend.d.ts +40 -0
- package/dist/evals/runner/FakeAgentBackend.js +82 -0
- package/dist/evals/runner/agentCaseRunner.d.ts +24 -0
- package/dist/evals/runner/agentCaseRunner.js +388 -0
- package/dist/evals/runner/caseRunner.d.ts +8 -0
- package/dist/evals/runner/caseRunner.js +28 -0
- package/dist/evals/runner/conversationSubject.d.ts +18 -0
- package/dist/evals/runner/conversationSubject.js +123 -0
- package/dist/evals/runner/internalAgentCaseRunner.d.ts +6 -0
- package/dist/evals/runner/internalAgentCaseRunner.js +250 -0
- package/dist/evals/runner/simulatorModel.d.ts +51 -0
- package/dist/evals/runner/simulatorModel.js +58 -0
- package/dist/evals/runner/simulatorPrompt.d.ts +29 -0
- package/dist/evals/runner/simulatorPrompt.js +59 -0
- package/dist/evals/runner/stageCaseRunner.d.ts +30 -0
- package/dist/evals/runner/stageCaseRunner.js +279 -0
- package/dist/evals/runner/userDriver.d.ts +71 -0
- package/dist/evals/runner/userDriver.js +104 -0
- package/dist/evals/scoring.d.ts +34 -0
- package/dist/evals/scoring.js +67 -0
- package/dist/evals/snapshot.d.ts +191 -0
- package/dist/evals/snapshot.js +70 -0
- package/dist/evals/stageDiff.d.ts +8 -0
- package/dist/evals/stageDiff.js +48 -0
- package/dist/evals/stats.d.ts +95 -0
- package/dist/evals/stats.js +220 -0
- package/dist/evals/statsAdapter.d.ts +4 -0
- package/dist/evals/statsAdapter.js +30 -0
- package/dist/evals/statsTypes.d.ts +51 -0
- package/dist/evals/statsTypes.js +18 -0
- package/dist/evals/storeError.d.ts +5 -0
- package/dist/evals/storeError.js +8 -0
- package/dist/evals/storeTypes.d.ts +207 -0
- package/dist/evals/storeTypes.js +1 -0
- package/dist/evals/tTable.d.ts +3 -0
- package/dist/evals/tTable.js +15 -0
- package/dist/evals/triage/constants.d.ts +26 -0
- package/dist/evals/triage/constants.js +33 -0
- package/dist/evals/triage/credentials.d.ts +13 -0
- package/dist/evals/triage/credentials.js +20 -0
- package/dist/evals/triage/jevClassifier.d.ts +14 -0
- package/dist/evals/triage/jevClassifier.js +124 -0
- package/dist/evals/triage/judgeClassifier.d.ts +10 -0
- package/dist/evals/triage/judgeClassifier.js +76 -0
- package/dist/evals/triage/prompts.d.ts +16 -0
- package/dist/evals/triage/prompts.js +64 -0
- package/dist/evals/triage/service.d.ts +79 -0
- package/dist/evals/triage/service.js +217 -0
- package/dist/evals/triage/stateBuilder.d.ts +19 -0
- package/dist/evals/triage/stateBuilder.js +125 -0
- package/dist/evals/triage/types.d.ts +60 -0
- package/dist/evals/triage/types.js +8 -0
- package/dist/evals/types.d.ts +357 -0
- package/dist/evals/types.js +4 -0
- package/dist/guide/cardContract.d.ts +133 -0
- package/dist/guide/cardContract.js +156 -0
- package/dist/guide/chat.d.ts +45 -0
- package/dist/guide/chat.js +378 -0
- package/dist/guide/knowledge/index.d.ts +14 -0
- package/dist/guide/knowledge/index.js +109 -0
- package/dist/guide/knowledge/topics/agents.d.ts +2 -0
- package/dist/guide/knowledge/topics/agents.js +58 -0
- package/dist/guide/knowledge/topics/bestPractices.d.ts +2 -0
- package/dist/guide/knowledge/topics/bestPractices.js +67 -0
- package/dist/guide/knowledge/topics/connections.d.ts +2 -0
- package/dist/guide/knowledge/topics/connections.js +66 -0
- package/dist/guide/knowledge/topics/consoleMap.d.ts +2 -0
- package/dist/guide/knowledge/topics/consoleMap.js +55 -0
- package/dist/guide/knowledge/topics/evals.d.ts +2 -0
- package/dist/guide/knowledge/topics/evals.js +72 -0
- package/dist/guide/knowledge/topics/limitations.d.ts +2 -0
- package/dist/guide/knowledge/topics/limitations.js +84 -0
- package/dist/guide/knowledge/topics/mcpSkillsBrowser.d.ts +2 -0
- package/dist/guide/knowledge/topics/mcpSkillsBrowser.js +57 -0
- package/dist/guide/knowledge/topics/memories.d.ts +2 -0
- package/dist/guide/knowledge/topics/memories.js +63 -0
- package/dist/guide/knowledge/topics/modelsAndProviders.d.ts +2 -0
- package/dist/guide/knowledge/topics/modelsAndProviders.js +56 -0
- package/dist/guide/knowledge/topics/overview.d.ts +2 -0
- package/dist/guide/knowledge/topics/overview.js +56 -0
- package/dist/guide/knowledge/topics/pipelines.d.ts +2 -0
- package/dist/guide/knowledge/topics/pipelines.js +93 -0
- package/dist/guide/knowledge/topics/stages.d.ts +2 -0
- package/dist/guide/knowledge/topics/stages.js +54 -0
- package/dist/guide/knowledge/topics/tasks.d.ts +2 -0
- package/dist/guide/knowledge/topics/tasks.js +52 -0
- package/dist/guide/knowledge/topics/triggers.d.ts +2 -0
- package/dist/guide/knowledge/topics/triggers.js +68 -0
- package/dist/guide/knowledge/topics/troubleshooting.d.ts +2 -0
- package/dist/guide/knowledge/topics/troubleshooting.js +85 -0
- package/dist/guide/knowledgeTools.d.ts +2 -0
- package/dist/guide/knowledgeTools.js +56 -0
- package/dist/guide/showUi.d.ts +6 -0
- package/dist/guide/showUi.js +546 -0
- package/dist/guide/threadStore.d.ts +48 -0
- package/dist/guide/threadStore.js +189 -0
- package/dist/guide/writeRoot.d.ts +11 -0
- package/dist/guide/writeRoot.js +70 -0
- package/dist/hosted/translate.js +2 -0
- package/dist/mcp/agentTools.js +12 -0
- package/dist/mcp/catalogTools.js +18 -20
- package/dist/mcp/catalogWriteTools.d.ts +8 -0
- package/dist/mcp/catalogWriteTools.js +225 -0
- package/dist/mcp/connectionTools.d.ts +3 -0
- package/dist/mcp/connectionTools.js +85 -0
- package/dist/mcp/controlTools.js +34 -1
- package/dist/mcp/deps.d.ts +16 -0
- package/dist/mcp/evalTools.d.ts +3 -0
- package/dist/mcp/evalTools.js +943 -0
- package/dist/mcp/memoryHostTools.d.ts +3 -0
- package/dist/mcp/memoryHostTools.js +72 -0
- package/dist/mcp/pipelineAuthorTools.js +14 -1
- package/dist/mcp/server.js +6 -0
- package/dist/mcp/tools.js +8 -0
- package/dist/mcp/triggerTools.js +77 -31
- package/dist/models/response.d.ts +7 -2
- package/dist/models/response.js +6 -1
- package/dist/operatorAgent/agentAuthorContext.d.ts +1 -1
- package/dist/operatorAgent/agentAuthorContext.js +1 -1
- package/dist/operatorAgent/evalGate.d.ts +22 -0
- package/dist/operatorAgent/evalGate.js +77 -0
- package/dist/operatorAgent/fakeHost.js +10 -2
- package/dist/operatorAgent/host.js +18 -2
- package/dist/operatorAgent/index.d.ts +1 -0
- package/dist/operatorAgent/index.js +1 -0
- package/dist/operatorAgent/internalAgents.d.ts +11 -0
- package/dist/operatorAgent/internalAgents.js +13 -0
- package/dist/operatorAgent/piModel.d.ts +5 -1
- package/dist/operatorAgent/piModel.js +32 -14
- package/dist/operatorAgent/profiles/agentAuthor.d.ts +3 -1
- package/dist/operatorAgent/profiles/agentAuthor.js +201 -32
- package/dist/operatorAgent/profiles/agentAuthorPlaybook.d.ts +1 -1
- package/dist/operatorAgent/profiles/agentAuthorPlaybook.js +48 -15
- package/dist/operatorAgent/profiles/authorReadable.d.ts +2 -0
- package/dist/operatorAgent/profiles/authorReadable.js +26 -0
- package/dist/operatorAgent/profiles/guideConfirm.d.ts +21 -0
- package/dist/operatorAgent/profiles/guideConfirm.js +100 -0
- package/dist/operatorAgent/profiles/guideTools.d.ts +7 -0
- package/dist/operatorAgent/profiles/guideTools.js +123 -0
- package/dist/operatorAgent/profiles/stageflowGuide.d.ts +7 -0
- package/dist/operatorAgent/profiles/stageflowGuide.js +132 -0
- package/dist/operatorAgent/profiles/workshopAuthor.js +23 -0
- package/dist/operatorAgent/profiles/workshopAuthorPlaybook.d.ts +1 -1
- package/dist/operatorAgent/profiles/workshopAuthorPlaybook.js +9 -1
- package/dist/operatorAgent/profiles/workshopAuthorTools.d.ts +2 -0
- package/dist/operatorAgent/profiles/workshopAuthorTools.js +197 -9
- package/dist/operatorAgent/types.d.ts +23 -0
- package/dist/package-meta.d.ts +1 -1
- package/dist/package-meta.js +1 -1
- package/dist/runstore/port.d.ts +43 -0
- package/dist/runstore/retention.d.ts +2 -1
- package/dist/runstore/retention.js +3 -7
- package/dist/runstore/runStatusClock.d.ts +17 -0
- package/dist/runstore/runStatusClock.js +19 -0
- package/dist/runstore/sqlite/SqliteRunStore.d.ts +29 -0
- package/dist/runstore/sqlite/SqliteRunStore.js +144 -50
- package/dist/runstore/sqlite/evalStore.d.ts +20 -0
- package/dist/runstore/sqlite/evalStore.js +541 -0
- package/dist/runstore/sqlite/migrations/015-evals.d.ts +12 -0
- package/dist/runstore/sqlite/migrations/015-evals.js +157 -0
- package/dist/runstore/sqlite/migrations/016-eval-subject-ref.d.ts +12 -0
- package/dist/runstore/sqlite/migrations/016-eval-subject-ref.js +20 -0
- package/dist/runstore/sqlite/migrations/017-eval-result-suggestions.d.ts +11 -0
- package/dist/runstore/sqlite/migrations/017-eval-result-suggestions.js +36 -0
- package/dist/runstore/sqlite/migrations/index.js +6 -0
- package/dist/runstore/sqlite/suggestionStore.d.ts +14 -0
- package/dist/runstore/sqlite/suggestionStore.js +132 -0
- package/dist/runstore/workspaceLayout.js +6 -1
- package/dist/runtime/artifactDiskInspect.d.ts +14 -0
- package/dist/runtime/artifactDiskInspect.js +52 -0
- package/dist/runtime/artifactPath.d.ts +24 -0
- package/dist/runtime/artifactPath.js +84 -0
- package/dist/runtime/completionCheckRunner.js +15 -43
- package/dist/runtime/githubPollSource.d.ts +22 -4
- package/dist/runtime/githubPollSource.js +93 -8
- package/dist/runtime/pipelineRunner.d.ts +2 -1
- package/dist/runtime/pipelineRunner.js +2 -0
- package/dist/runtime/priorArtifactGrants.d.ts +8 -0
- package/dist/runtime/priorArtifactGrants.js +105 -0
- package/dist/runtime/runActionEligibility.d.ts +46 -0
- package/dist/runtime/runActionEligibility.js +123 -0
- package/dist/runtime/runManager.d.ts +6 -2
- package/dist/runtime/runManager.js +60 -16
- package/dist/runtime/runRetentionSweep.js +2 -2
- package/dist/runtime/runRetryCoordinator.d.ts +2 -14
- package/dist/runtime/runRetryCoordinator.js +3 -67
- package/dist/runtime/sandboxContainer.d.ts +7 -0
- package/dist/runtime/sandboxContainer.js +48 -6
- package/dist/runtime/sandboxDesk.d.ts +2 -1
- package/dist/runtime/sandboxDesk.js +11 -12
- package/dist/runtime/stageEnvironment.js +1 -0
- package/dist/runtime/stageRoots.d.ts +12 -0
- package/dist/runtime/stageSandbox.d.ts +2 -1
- package/dist/runtime/stageSandbox.js +18 -2
- package/dist/runtime/stageWorker.js +20 -0
- package/dist/server/agentAuthorRoutes.js +59 -1
- package/dist/server/bootstrap.d.ts +13 -0
- package/dist/server/bootstrap.js +69 -0
- package/dist/server/controlToken.js +3 -0
- package/dist/server/evalInternalRoutes.d.ts +14 -0
- package/dist/server/evalInternalRoutes.js +87 -0
- package/dist/server/evalRouteContext.d.ts +46 -0
- package/dist/server/evalRouteContext.js +43 -0
- package/dist/server/evalRoutes.d.ts +5 -0
- package/dist/server/evalRoutes.js +1456 -0
- package/dist/server/evalTriageRoutes.d.ts +2 -0
- package/dist/server/evalTriageRoutes.js +95 -0
- package/dist/server/guideRoutes.d.ts +5 -0
- package/dist/server/guideRoutes.js +166 -0
- package/dist/server/http.d.ts +15 -0
- package/dist/server/http.js +67 -3
- package/dist/server/internalAgentRoutes.d.ts +6 -0
- package/dist/server/internalAgentRoutes.js +12 -0
- package/dist/server/mcpHost.js +5 -0
- package/dist/toolkit/meta.d.ts +1 -1
- package/dist/toolkit/meta.js +53 -0
- package/dist/toolkit/profiles.d.ts +5 -0
- package/dist/toolkit/profiles.js +13 -1
- package/dist/tools/askOperator.js +2 -1
- package/dist/tools/emitStageEnvelope.d.ts +17 -16
- package/dist/tools/emitStageEnvelope.js +46 -32
- package/dist/tools/stageToolNames.d.ts +4 -0
- package/dist/tools/stageToolNames.js +4 -0
- package/dist/tools/workingState.d.ts +40 -0
- package/dist/tools/workingState.js +108 -0
- package/dist/tools/writeStageArtifact.d.ts +0 -9
- package/dist/tools/writeStageArtifact.js +2 -1
- package/dist/types/stageflowManifest.d.ts +6 -0
- package/dist/ui/assets/{MarkdownText-D7tYaIFO.js → MarkdownText-S5C_vemc.js} +2 -2
- package/dist/ui/assets/adapters-C0l4ruiR.js +17 -0
- package/dist/ui/assets/chat-CjnsmvqR.js +2 -0
- package/dist/ui/assets/chat-DFDd4UjS.css +2 -0
- package/dist/ui/assets/{main-BFo79krC.css → main-Del1GeLf.css} +1 -1
- package/dist/ui/assets/main-_yXVqcW9.js +277 -0
- package/dist/ui/chat.html +3 -4
- package/dist/ui/index.html +3 -4
- package/dist/workshop/chatTurn.js +1 -1
- package/dist/workshop/workshopPin.d.ts +3 -3
- package/dist/workshop/workshopPin.js +16 -15
- package/examples/README.md +2 -0
- package/examples/compaction-stress/README.md +30 -0
- package/examples/compaction-stress/check-run.mjs +53 -0
- package/examples/compaction-stress/collect-evidence.yaml +60 -0
- package/examples/compaction-stress/compaction-stress.pipeline.yaml +141 -0
- package/examples/compaction-stress/compaction-stress.task.yaml +15 -0
- package/examples/compaction-stress/generate-evidence.mjs +110 -0
- package/examples/compaction-stress/root-cause.yaml +26 -0
- package/examples/compaction-stress/stageflow.yaml +9 -0
- package/examples/compaction-stress/write-postmortem.yaml +40 -0
- package/examples/document-policy-review/README.md +35 -0
- package/examples/document-policy-review/agents/compliance.agent.yaml +42 -0
- package/examples/document-policy-review/documents/acme-vendor-sow.md +15 -0
- package/examples/document-policy-review/documents/support-runbook.md +13 -0
- package/examples/document-policy-review/policies/acceptable-use.md +13 -0
- package/examples/document-policy-review/policies/data-handling.md +17 -0
- package/examples/document-policy-review/policies/vendor-security.md +17 -0
- package/examples/evals/README.md +141 -0
- package/examples/evals/critique-sample.dataset.jsonl +8 -0
- package/examples/evals/critique-sample.eval.yaml +34 -0
- package/examples/evals/critique-sample.task.yaml +4 -0
- package/examples/evals/eval-sample.pipeline.yaml +35 -0
- package/examples/evals/guide-behavior.dataset.jsonl +15 -0
- package/examples/evals/guide-behavior.eval.yaml +35 -0
- package/examples/evals/guide-depth.dataset.jsonl +35 -0
- package/examples/evals/guide-depth.eval.yaml +169 -0
- package/examples/evals/support-sample.agent.yaml +20 -0
- package/examples/evals/support-sample.dataset.jsonl +6 -0
- package/examples/evals/support-sample.eval.yaml +38 -0
- package/examples/memory/evals/guide-behavior.dataset.jsonl +15 -0
- package/examples/memory/evals/guide-behavior.eval.yaml +35 -0
- package/examples/memory/evals/guide-depth.dataset.jsonl +35 -0
- package/examples/memory/evals/guide-depth.eval.yaml +169 -0
- package/examples/stageflow.yaml +6 -0
- package/package.json +1 -1
- package/skills/stageflow/SKILL.md +5 -2
- package/skills/stageflow/references/control-surface.md +4 -2
- package/skills/stageflow/references/evals.md +68 -0
- package/skills/stageflow-author/SKILL.md +4 -0
- package/skills/stageflow-run/SKILL.md +4 -0
- package/dist/ui/assets/AssistantRuntimeProvider-CsiPFhCT.js +0 -9
- package/dist/ui/assets/ReadonlyStore-BfXqHykm.js +0 -6
- package/dist/ui/assets/chat-BbLukq9W.js +0 -5
- package/dist/ui/assets/chat-zIZU_bP1.css +0 -2
- package/dist/ui/assets/main-CijYMeM0.js +0 -259
|
@@ -0,0 +1,1103 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
import { AGENT_ID_PATTERN, isReservedAgentId } from "../agents/agentId.js";
|
|
5
|
+
import { canonicalJson, hash6, sha256Hex } from "../evals/canonical.js";
|
|
6
|
+
import { loadFailure, loadSuccess } from "./loadOutcome.js";
|
|
7
|
+
import { yamlParsePosition } from "./yamlParsePosition.js";
|
|
8
|
+
export const EVAL_DEFAULT_REPEATS = 3;
|
|
9
|
+
export const EVAL_DEFAULT_PASS_THRESHOLD = 0.8;
|
|
10
|
+
export const EVAL_DEFAULT_MAX_COST_USD = 2;
|
|
11
|
+
export const EVAL_DEFAULT_CONCURRENCY = 4;
|
|
12
|
+
export const EVAL_AGENT_DEFAULT_CONCURRENCY = 2;
|
|
13
|
+
export const EVAL_AGENT_DEFAULT_MAX_COST_USD = 1;
|
|
14
|
+
export const EVAL_CONVERSATION_DEFAULTS = {
|
|
15
|
+
mode: "script",
|
|
16
|
+
maxTurns: 8,
|
|
17
|
+
turnTimeoutMs: 120_000,
|
|
18
|
+
tools: "read_only",
|
|
19
|
+
approvals: "record_only",
|
|
20
|
+
readOnlyTools: [],
|
|
21
|
+
allowRealTools: false,
|
|
22
|
+
};
|
|
23
|
+
export function resolveConversation(conversation) {
|
|
24
|
+
const d = EVAL_CONVERSATION_DEFAULTS;
|
|
25
|
+
return {
|
|
26
|
+
mode: conversation?.mode ?? d.mode,
|
|
27
|
+
maxTurns: conversation?.max_turns ?? d.maxTurns,
|
|
28
|
+
turnTimeoutMs: conversation?.turn_timeout_ms ?? d.turnTimeoutMs,
|
|
29
|
+
tools: conversation?.tools ?? d.tools,
|
|
30
|
+
approvals: conversation?.approvals ?? d.approvals,
|
|
31
|
+
readOnlyTools: [...(conversation?.read_only_tools ?? d.readOnlyTools)],
|
|
32
|
+
allowRealTools: conversation?.allow_real_tools ?? d.allowRealTools,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
36
|
+
const GRADER_TYPES = [
|
|
37
|
+
"schema",
|
|
38
|
+
"field",
|
|
39
|
+
"reference",
|
|
40
|
+
"rubric",
|
|
41
|
+
"code",
|
|
42
|
+
"tool_calls",
|
|
43
|
+
"conversation_check",
|
|
44
|
+
"goal_reached",
|
|
45
|
+
];
|
|
46
|
+
const FIELD_OPS = [
|
|
47
|
+
"exists",
|
|
48
|
+
"not_empty",
|
|
49
|
+
"equals",
|
|
50
|
+
"not_equals",
|
|
51
|
+
"contains",
|
|
52
|
+
"matches",
|
|
53
|
+
"gte",
|
|
54
|
+
"lte",
|
|
55
|
+
"between",
|
|
56
|
+
"in",
|
|
57
|
+
"length_gte",
|
|
58
|
+
"length_lte",
|
|
59
|
+
];
|
|
60
|
+
const FIELD_PATH_PATTERN = /^[^.[\]\s]+(?:\.[^.[\]\s]+|\[(?:\d+|\*)\])*$/;
|
|
61
|
+
const TOP_KEYS = [
|
|
62
|
+
"version",
|
|
63
|
+
"id",
|
|
64
|
+
"name",
|
|
65
|
+
"description",
|
|
66
|
+
"type",
|
|
67
|
+
"target",
|
|
68
|
+
"dataset",
|
|
69
|
+
"task",
|
|
70
|
+
"defaults",
|
|
71
|
+
"conversation",
|
|
72
|
+
"graders",
|
|
73
|
+
"budget",
|
|
74
|
+
];
|
|
75
|
+
const TARGET_KEYS = ["kind", "pipeline", "stage", "file"];
|
|
76
|
+
const AGENT_TARGET_KEYS = ["kind", "agent"];
|
|
77
|
+
const INTERNAL_AGENT_TARGET_KEYS = ["kind", "profile"];
|
|
78
|
+
const CONVERSATION_KEYS = [
|
|
79
|
+
"mode",
|
|
80
|
+
"max_turns",
|
|
81
|
+
"turn_timeout_ms",
|
|
82
|
+
"tools",
|
|
83
|
+
"approvals",
|
|
84
|
+
"read_only_tools",
|
|
85
|
+
"allow_real_tools",
|
|
86
|
+
];
|
|
87
|
+
const READ_ONLY_TOOL_PATTERN = /^[A-Za-z0-9_.*:-]{1,128}$/;
|
|
88
|
+
const TASK_KEYS = ["goal", "context", "constraints"];
|
|
89
|
+
const DEFAULTS_KEYS = [
|
|
90
|
+
"repeats",
|
|
91
|
+
"judge",
|
|
92
|
+
"pass_threshold",
|
|
93
|
+
"max_cost_usd",
|
|
94
|
+
"concurrency",
|
|
95
|
+
"model",
|
|
96
|
+
"user_model",
|
|
97
|
+
];
|
|
98
|
+
const BUDGET_KEYS = ["latency_ms", "cost_usd"];
|
|
99
|
+
const GRADER_COMMON_KEYS = ["id", "type", "description", "weight", "must_pass"];
|
|
100
|
+
const GRADER_TYPE_KEYS = {
|
|
101
|
+
schema: [],
|
|
102
|
+
field: ["checks"],
|
|
103
|
+
reference: ["mode", "path", "expected", "pass_at"],
|
|
104
|
+
rubric: ["rubric", "scale", "pass_at", "judge", "examples"],
|
|
105
|
+
code: ["code"],
|
|
106
|
+
tool_calls: ["must_call", "must_not_call", "must_ask_first", "max_calls", "args"],
|
|
107
|
+
conversation_check: ["max_turns", "max_agent_questions_per_turn", "final_reply"],
|
|
108
|
+
goal_reached: ["judge", "guidance"],
|
|
109
|
+
};
|
|
110
|
+
const TOOL_ARG_KEYS = ["tool", "path", "op", "value"];
|
|
111
|
+
const FINAL_REPLY_KEYS = ["op", "value"];
|
|
112
|
+
const CHECK_KEYS = ["path", "op", "value"];
|
|
113
|
+
function isPlainObject(value) {
|
|
114
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
115
|
+
}
|
|
116
|
+
function evalIssue(code, message) {
|
|
117
|
+
return { code, message, category: "eval" };
|
|
118
|
+
}
|
|
119
|
+
export function evalFileStem(filePath) {
|
|
120
|
+
const base = path.basename(filePath);
|
|
121
|
+
const match = /^(.*)\.eval\.ya?ml$/.exec(base);
|
|
122
|
+
if (match)
|
|
123
|
+
return match[1] ?? base;
|
|
124
|
+
return base.slice(0, base.length - path.extname(base).length);
|
|
125
|
+
}
|
|
126
|
+
function isInside(root, candidate) {
|
|
127
|
+
const rel = path.relative(root, candidate);
|
|
128
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
129
|
+
}
|
|
130
|
+
/** Paths in an eval file resolve against the eval file's directory (P6). */
|
|
131
|
+
export function resolveEvalPaths(file, evalAbsPath) {
|
|
132
|
+
const dir = path.dirname(evalAbsPath);
|
|
133
|
+
const stage = file.target.kind === "stage" ? file.target : undefined;
|
|
134
|
+
return {
|
|
135
|
+
...(stage?.pipeline !== undefined ? { pipelinePath: path.resolve(dir, stage.pipeline) } : {}),
|
|
136
|
+
...(stage?.file !== undefined ? { stageFile: path.resolve(dir, stage.file) } : {}),
|
|
137
|
+
datasetPath: path.resolve(dir, file.dataset),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
class Collector {
|
|
141
|
+
issues = [];
|
|
142
|
+
add(code, message) {
|
|
143
|
+
this.issues.push(evalIssue(code, message));
|
|
144
|
+
}
|
|
145
|
+
unknownKeys(obj, allowed, where) {
|
|
146
|
+
for (const key of Object.keys(obj)) {
|
|
147
|
+
if (!allowed.includes(key)) {
|
|
148
|
+
this.add("eval.unknown_key", `Unknown key "${key}" in ${where}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function optionalString(c, obj, key, where, limits = {}) {
|
|
154
|
+
const value = obj[key];
|
|
155
|
+
if (value === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
if (typeof value !== "string") {
|
|
158
|
+
c.add("eval.invalid_field", `${where} "${key}" must be a string`);
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
const min = limits.min ?? 0;
|
|
162
|
+
if (value.length < min || (limits.max !== undefined && value.length > limits.max)) {
|
|
163
|
+
const range = limits.max !== undefined ? `${min}-${limits.max} characters` : `at least ${min} character(s)`;
|
|
164
|
+
c.add("eval.invalid_field", `${where} "${key}" must be ${range}`);
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
function optionalNumber(c, obj, key, where, rule, ok, code = "eval.invalid_field") {
|
|
170
|
+
const value = obj[key];
|
|
171
|
+
if (value === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !ok(value)) {
|
|
174
|
+
c.add(code, `${where} "${key}" must be ${rule}`);
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
function isIntegerIn(n, min, max) {
|
|
180
|
+
return Number.isInteger(n) && n >= min && n <= max;
|
|
181
|
+
}
|
|
182
|
+
function parseTarget(c, raw) {
|
|
183
|
+
if (raw === undefined) {
|
|
184
|
+
c.add("eval.invalid_field", `Missing required key "target"`);
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
if (!isPlainObject(raw)) {
|
|
188
|
+
c.add("eval.invalid_field", `"target" must be a mapping`);
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
if (raw.kind === undefined) {
|
|
192
|
+
c.add("eval.invalid_field", `target "kind" is required ("stage", "agent" or "internal_agent")`);
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
if (raw.kind === "agent")
|
|
196
|
+
return parseAgentTarget(c, raw);
|
|
197
|
+
if (raw.kind === "internal_agent")
|
|
198
|
+
return parseInternalAgentTarget(c, raw);
|
|
199
|
+
if (raw.kind !== "stage") {
|
|
200
|
+
c.add("eval.target_kind_unsupported", `target kind ${JSON.stringify(raw.kind)} is not supported (only "stage", "agent" and "internal_agent")`);
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
if (raw.agent !== undefined) {
|
|
204
|
+
c.add("eval.target_invalid", `target "agent" is only valid with kind: agent`);
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
c.unknownKeys(raw, TARGET_KEYS, "target");
|
|
208
|
+
const pipeline = raw.pipeline;
|
|
209
|
+
const stage = raw.stage;
|
|
210
|
+
const file = raw.file;
|
|
211
|
+
for (const [key, value] of [
|
|
212
|
+
["pipeline", pipeline],
|
|
213
|
+
["stage", stage],
|
|
214
|
+
["file", file],
|
|
215
|
+
]) {
|
|
216
|
+
if (value !== undefined && (typeof value !== "string" || value.trim() === "")) {
|
|
217
|
+
c.add("eval.invalid_field", `target "${key}" must be a non-empty string`);
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const pipelineForm = pipeline !== undefined || stage !== undefined;
|
|
222
|
+
const fileForm = file !== undefined;
|
|
223
|
+
if (pipelineForm === fileForm || (pipelineForm && (pipeline === undefined || stage === undefined))) {
|
|
224
|
+
c.add("eval.target_invalid", "target must be exactly one of: { kind: stage, pipeline, stage } or { kind: stage, file }");
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
kind: "stage",
|
|
229
|
+
...(pipeline !== undefined ? { pipeline: pipeline } : {}),
|
|
230
|
+
...(stage !== undefined ? { stage: stage } : {}),
|
|
231
|
+
...(file !== undefined ? { file: file } : {}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function parseAgentTarget(c, raw) {
|
|
235
|
+
if (raw.revision !== undefined) {
|
|
236
|
+
c.add("eval.target_invalid", `target "revision" is recorded by the run, not authored`);
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
for (const key of ["pipeline", "stage", "file"]) {
|
|
240
|
+
if (raw[key] !== undefined) {
|
|
241
|
+
c.add("eval.target_invalid", `target "${key}" is only valid with kind: stage`);
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
c.unknownKeys(raw, AGENT_TARGET_KEYS, "target");
|
|
246
|
+
const agent = raw.agent;
|
|
247
|
+
if (typeof agent !== "string" || !AGENT_ID_PATTERN.test(agent)) {
|
|
248
|
+
c.add("eval.target_invalid", `target "agent" must be an agent id matching ${AGENT_ID_PATTERN.source}`);
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
if (isReservedAgentId(agent)) {
|
|
252
|
+
c.add("eval.target_invalid", `target agent id "${agent}" is reserved`);
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
return { kind: "agent", agent };
|
|
256
|
+
}
|
|
257
|
+
function parseInternalAgentTarget(c, raw) {
|
|
258
|
+
for (const key of ["agent", "pipeline", "stage", "file"]) {
|
|
259
|
+
if (raw[key] !== undefined) {
|
|
260
|
+
c.add("eval.target_invalid", `target "${key}" is not valid with kind: internal_agent; use "profile"`);
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
c.unknownKeys(raw, INTERNAL_AGENT_TARGET_KEYS, "target");
|
|
265
|
+
const profile = raw.profile;
|
|
266
|
+
if (typeof profile !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(profile)) {
|
|
267
|
+
c.add("eval.target_invalid", `target "profile" must be an internal agent id such as stageflow-guide`);
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
return { kind: "internal_agent", profile };
|
|
271
|
+
}
|
|
272
|
+
function parseTask(c, raw) {
|
|
273
|
+
if (raw === undefined)
|
|
274
|
+
return undefined;
|
|
275
|
+
if (!isPlainObject(raw)) {
|
|
276
|
+
c.add("eval.invalid_field", `"task" must be a mapping`);
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
c.unknownKeys(raw, TASK_KEYS, "task");
|
|
280
|
+
const out = {};
|
|
281
|
+
for (const key of TASK_KEYS) {
|
|
282
|
+
const value = optionalString(c, raw, key, "task");
|
|
283
|
+
if (value !== undefined)
|
|
284
|
+
out[key] = value;
|
|
285
|
+
}
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
function parseDefaults(c, raw, kind) {
|
|
289
|
+
if (raw === undefined)
|
|
290
|
+
return undefined;
|
|
291
|
+
if (!isPlainObject(raw)) {
|
|
292
|
+
c.add("eval.invalid_field", `"defaults" must be a mapping`);
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
c.unknownKeys(raw, DEFAULTS_KEYS, "defaults");
|
|
296
|
+
const out = {};
|
|
297
|
+
const repeats = optionalNumber(c, raw, "repeats", "defaults", "an integer from 1 to 10", (n) => isIntegerIn(n, 1, 10));
|
|
298
|
+
if (repeats !== undefined)
|
|
299
|
+
out.repeats = repeats;
|
|
300
|
+
const judge = optionalString(c, raw, "judge", "defaults", { min: 1 });
|
|
301
|
+
if (judge !== undefined)
|
|
302
|
+
out.judge = judge;
|
|
303
|
+
const passThreshold = optionalNumber(c, raw, "pass_threshold", "defaults", "a number greater than 0 and at most 1", (n) => n > 0 && n <= 1);
|
|
304
|
+
if (passThreshold !== undefined)
|
|
305
|
+
out.pass_threshold = passThreshold;
|
|
306
|
+
const maxCost = optionalNumber(c, raw, "max_cost_usd", "defaults", "a number greater than 0", (n) => n > 0);
|
|
307
|
+
if (maxCost !== undefined)
|
|
308
|
+
out.max_cost_usd = maxCost;
|
|
309
|
+
const concurrency = optionalNumber(c, raw, "concurrency", "defaults", "an integer from 1 to 8", (n) => isIntegerIn(n, 1, 8));
|
|
310
|
+
if (concurrency !== undefined)
|
|
311
|
+
out.concurrency = concurrency;
|
|
312
|
+
const model = optionalString(c, raw, "model", "defaults", { min: 1 });
|
|
313
|
+
if (model !== undefined)
|
|
314
|
+
out.model = model;
|
|
315
|
+
if (raw.user_model !== undefined) {
|
|
316
|
+
if (kind === "stage") {
|
|
317
|
+
c.add("eval.conversation_not_applicable", `defaults "user_model" is only valid with an agent target`);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const userModel = optionalString(c, raw, "user_model", "defaults", { min: 1 });
|
|
321
|
+
if (userModel !== undefined)
|
|
322
|
+
out.user_model = userModel;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
function parseConversation(c, raw, kind) {
|
|
328
|
+
if (raw === undefined)
|
|
329
|
+
return undefined;
|
|
330
|
+
if (kind === "stage") {
|
|
331
|
+
c.add("eval.conversation_not_applicable", `"conversation" is only valid with an agent target`);
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
const bad = (key, rule) => c.add("eval.conversation_invalid", `conversation "${key}" must be ${rule}`);
|
|
335
|
+
if (!isPlainObject(raw)) {
|
|
336
|
+
c.add("eval.conversation_invalid", `"conversation" must be a mapping`);
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
c.unknownKeys(raw, CONVERSATION_KEYS, "conversation");
|
|
340
|
+
const out = {};
|
|
341
|
+
const oneOf = (key, allowed) => {
|
|
342
|
+
const value = raw[key];
|
|
343
|
+
if (value === undefined)
|
|
344
|
+
return undefined;
|
|
345
|
+
if (typeof value === "string" && allowed.includes(value))
|
|
346
|
+
return value;
|
|
347
|
+
bad(key, `one of: ${allowed.join(", ")}`);
|
|
348
|
+
return undefined;
|
|
349
|
+
};
|
|
350
|
+
const mode = oneOf("mode", ["script", "simulated"]);
|
|
351
|
+
if (mode !== undefined)
|
|
352
|
+
out.mode = mode;
|
|
353
|
+
const maxTurns = optionalNumber(c, raw, "max_turns", "conversation", "an integer from 1 to 30", (n) => isIntegerIn(n, 1, 30), "eval.conversation_invalid");
|
|
354
|
+
if (maxTurns !== undefined)
|
|
355
|
+
out.max_turns = maxTurns;
|
|
356
|
+
const timeout = optionalNumber(c, raw, "turn_timeout_ms", "conversation", "an integer from 5000 to 600000", (n) => isIntegerIn(n, 5000, 600_000), "eval.conversation_invalid");
|
|
357
|
+
if (timeout !== undefined)
|
|
358
|
+
out.turn_timeout_ms = timeout;
|
|
359
|
+
const tools = oneOf("tools", ["real", "read_only", "mocked"]);
|
|
360
|
+
if (tools !== undefined)
|
|
361
|
+
out.tools = tools;
|
|
362
|
+
const approvals = oneOf("approvals", ["deny", "auto_approve_read", "record_only"]);
|
|
363
|
+
if (approvals !== undefined)
|
|
364
|
+
out.approvals = approvals;
|
|
365
|
+
if (raw.read_only_tools !== undefined) {
|
|
366
|
+
const list = raw.read_only_tools;
|
|
367
|
+
if (Array.isArray(list) &&
|
|
368
|
+
list.length <= 50 &&
|
|
369
|
+
list.every((item) => typeof item === "string" && READ_ONLY_TOOL_PATTERN.test(item))) {
|
|
370
|
+
out.read_only_tools = list;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
bad("read_only_tools", "an array of at most 50 tool grant ids");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (raw.allow_real_tools !== undefined) {
|
|
377
|
+
if (typeof raw.allow_real_tools !== "boolean") {
|
|
378
|
+
bad("allow_real_tools", "a boolean");
|
|
379
|
+
}
|
|
380
|
+
else if (raw.allow_real_tools && (tools ?? "read_only") !== "real") {
|
|
381
|
+
c.add("eval.conversation_invalid", `conversation "allow_real_tools" is only valid with tools: real`);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
out.allow_real_tools = raw.allow_real_tools;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
function parseBudget(c, raw) {
|
|
390
|
+
if (raw === undefined)
|
|
391
|
+
return undefined;
|
|
392
|
+
if (!isPlainObject(raw)) {
|
|
393
|
+
c.add("eval.invalid_field", `"budget" must be a mapping`);
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
c.unknownKeys(raw, BUDGET_KEYS, "budget");
|
|
397
|
+
const out = {};
|
|
398
|
+
const latency = optionalNumber(c, raw, "latency_ms", "budget", "a positive number", (n) => n > 0);
|
|
399
|
+
if (latency !== undefined)
|
|
400
|
+
out.latency_ms = latency;
|
|
401
|
+
const cost = optionalNumber(c, raw, "cost_usd", "budget", "a positive number", (n) => n > 0);
|
|
402
|
+
if (cost !== undefined)
|
|
403
|
+
out.cost_usd = cost;
|
|
404
|
+
return out;
|
|
405
|
+
}
|
|
406
|
+
function checkValueProblem(op, value, present) {
|
|
407
|
+
if (op === "exists" || op === "not_empty") {
|
|
408
|
+
return present ? `op "${op}" takes no value` : undefined;
|
|
409
|
+
}
|
|
410
|
+
if (!present)
|
|
411
|
+
return `op "${op}" requires a value`;
|
|
412
|
+
switch (op) {
|
|
413
|
+
case "equals":
|
|
414
|
+
case "not_equals":
|
|
415
|
+
case "contains":
|
|
416
|
+
return undefined;
|
|
417
|
+
case "matches": {
|
|
418
|
+
if (typeof value !== "string")
|
|
419
|
+
return `op "matches" value must be a regular expression string`;
|
|
420
|
+
try {
|
|
421
|
+
new RegExp(value);
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return `op "matches" value is not a valid regular expression`;
|
|
425
|
+
}
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
case "gte":
|
|
429
|
+
case "lte":
|
|
430
|
+
return typeof value === "number" && Number.isFinite(value)
|
|
431
|
+
? undefined
|
|
432
|
+
: `op "${op}" value must be a number`;
|
|
433
|
+
case "between":
|
|
434
|
+
return Array.isArray(value) &&
|
|
435
|
+
value.length === 2 &&
|
|
436
|
+
value.every((v) => typeof v === "number" && Number.isFinite(v)) &&
|
|
437
|
+
value[0] <= value[1]
|
|
438
|
+
? undefined
|
|
439
|
+
: `op "between" value must be [min, max] with min <= max`;
|
|
440
|
+
case "in":
|
|
441
|
+
return Array.isArray(value) ? undefined : `op "in" value must be an array`;
|
|
442
|
+
case "length_gte":
|
|
443
|
+
case "length_lte":
|
|
444
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0
|
|
445
|
+
? undefined
|
|
446
|
+
: `op "${op}" value must be a non-negative integer`;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function parseChecks(c, raw, where) {
|
|
450
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
451
|
+
c.add("eval.grader_invalid", `${where} "checks" must be a non-empty array`);
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
const checks = [];
|
|
455
|
+
let ok = true;
|
|
456
|
+
raw.forEach((item, index) => {
|
|
457
|
+
const at = `${where} checks[${index}]`;
|
|
458
|
+
if (!isPlainObject(item)) {
|
|
459
|
+
c.add("eval.grader_invalid", `${at} must be a mapping`);
|
|
460
|
+
ok = false;
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
c.unknownKeys(item, CHECK_KEYS, at);
|
|
464
|
+
if (typeof item.path !== "string" || !FIELD_PATH_PATTERN.test(item.path)) {
|
|
465
|
+
c.add("eval.grader_invalid", `${at} "path" must be dot-separated keys with optional [n] or [*] (for example payload.findings[*].line)`);
|
|
466
|
+
ok = false;
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (typeof item.op !== "string" || !FIELD_OPS.includes(item.op)) {
|
|
470
|
+
c.add("eval.grader_invalid", `${at} "op" must be one of: ${FIELD_OPS.join(", ")}`);
|
|
471
|
+
ok = false;
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const op = item.op;
|
|
475
|
+
const problem = checkValueProblem(op, item.value, "value" in item);
|
|
476
|
+
if (problem) {
|
|
477
|
+
c.add("eval.grader_invalid", `${at} ${problem}`);
|
|
478
|
+
ok = false;
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
checks.push({ path: item.path, op, ...("value" in item ? { value: item.value } : {}) });
|
|
482
|
+
});
|
|
483
|
+
return ok ? checks : undefined;
|
|
484
|
+
}
|
|
485
|
+
function parseExamples(c, raw, scale, where) {
|
|
486
|
+
if (!Array.isArray(raw) || raw.length > 6) {
|
|
487
|
+
c.add("eval.grader_invalid", `${where} "examples" must be an array of at most 6 items`);
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
const out = [];
|
|
491
|
+
let ok = true;
|
|
492
|
+
raw.forEach((item, index) => {
|
|
493
|
+
const at = `${where} examples[${index}]`;
|
|
494
|
+
if (!isPlainObject(item)) {
|
|
495
|
+
c.add("eval.grader_invalid", `${at} must be a mapping`);
|
|
496
|
+
ok = false;
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
c.unknownKeys(item, [scale === "pass_fail" ? "verdict" : "score", "output", "reason"], at);
|
|
500
|
+
if (typeof item.output !== "string") {
|
|
501
|
+
c.add("eval.grader_invalid", `${at} "output" must be a string`);
|
|
502
|
+
ok = false;
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (item.reason !== undefined && typeof item.reason !== "string") {
|
|
506
|
+
c.add("eval.grader_invalid", `${at} "reason" must be a string`);
|
|
507
|
+
ok = false;
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const reason = item.reason;
|
|
511
|
+
if (scale === "pass_fail") {
|
|
512
|
+
if (item.verdict !== "pass" && item.verdict !== "fail") {
|
|
513
|
+
c.add("eval.grader_invalid", `${at} "verdict" must be "pass" or "fail"`);
|
|
514
|
+
ok = false;
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
out.push({ verdict: item.verdict, output: item.output, ...(reason !== undefined ? { reason } : {}) });
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (typeof item.score !== "number" || !isIntegerIn(item.score, 1, 5)) {
|
|
521
|
+
c.add("eval.grader_invalid", `${at} "score" must be an integer from 1 to 5`);
|
|
522
|
+
ok = false;
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
out.push({ score: item.score, output: item.output, ...(reason !== undefined ? { reason } : {}) });
|
|
526
|
+
});
|
|
527
|
+
return ok ? out : undefined;
|
|
528
|
+
}
|
|
529
|
+
function optionalToolList(c, raw, key, where) {
|
|
530
|
+
const value = raw[key];
|
|
531
|
+
if (value === undefined)
|
|
532
|
+
return undefined;
|
|
533
|
+
if (!Array.isArray(value) ||
|
|
534
|
+
value.length > 50 ||
|
|
535
|
+
!value.every((item) => typeof item === "string" && item.length >= 1 && item.length <= 128)) {
|
|
536
|
+
c.add("eval.grader_invalid", `${where} "${key}" must be an array of at most 50 tool names`);
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
return value;
|
|
540
|
+
}
|
|
541
|
+
function parseToolArgs(c, raw, where) {
|
|
542
|
+
if (!Array.isArray(raw) || raw.length > 20) {
|
|
543
|
+
c.add("eval.grader_invalid", `${where} "args" must be an array of at most 20 checks`);
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
const out = [];
|
|
547
|
+
let ok = true;
|
|
548
|
+
raw.forEach((item, index) => {
|
|
549
|
+
const at = `${where} args[${index}]`;
|
|
550
|
+
if (!isPlainObject(item)) {
|
|
551
|
+
c.add("eval.grader_invalid", `${at} must be a mapping`);
|
|
552
|
+
ok = false;
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
c.unknownKeys(item, TOOL_ARG_KEYS, at);
|
|
556
|
+
if (typeof item.tool !== "string" || item.tool.length < 1 || item.tool.length > 128) {
|
|
557
|
+
c.add("eval.grader_invalid", `${at} "tool" must be a tool name`);
|
|
558
|
+
ok = false;
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
if (typeof item.path !== "string" || !FIELD_PATH_PATTERN.test(item.path)) {
|
|
562
|
+
c.add("eval.grader_invalid", `${at} "path" must be dot-separated keys with optional [n] or [*]`);
|
|
563
|
+
ok = false;
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (typeof item.op !== "string" || !FIELD_OPS.includes(item.op)) {
|
|
567
|
+
c.add("eval.grader_invalid", `${at} "op" must be one of: ${FIELD_OPS.join(", ")}`);
|
|
568
|
+
ok = false;
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
const op = item.op;
|
|
572
|
+
const problem = checkValueProblem(op, item.value, "value" in item);
|
|
573
|
+
if (problem) {
|
|
574
|
+
c.add("eval.grader_invalid", `${at} ${problem}`);
|
|
575
|
+
ok = false;
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
out.push({ tool: item.tool, path: item.path, op, ...("value" in item ? { value: item.value } : {}) });
|
|
579
|
+
});
|
|
580
|
+
return ok ? out : undefined;
|
|
581
|
+
}
|
|
582
|
+
function parseFinalReply(c, raw, where) {
|
|
583
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > 10) {
|
|
584
|
+
c.add("eval.grader_invalid", `${where} "final_reply" must be an array of 1-10 checks`);
|
|
585
|
+
return undefined;
|
|
586
|
+
}
|
|
587
|
+
const out = [];
|
|
588
|
+
let ok = true;
|
|
589
|
+
raw.forEach((item, index) => {
|
|
590
|
+
const at = `${where} final_reply[${index}]`;
|
|
591
|
+
if (!isPlainObject(item)) {
|
|
592
|
+
c.add("eval.grader_invalid", `${at} must be a mapping`);
|
|
593
|
+
ok = false;
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
c.unknownKeys(item, FINAL_REPLY_KEYS, at);
|
|
597
|
+
if (typeof item.op !== "string" || !FIELD_OPS.includes(item.op)) {
|
|
598
|
+
c.add("eval.grader_invalid", `${at} "op" must be one of: ${FIELD_OPS.join(", ")}`);
|
|
599
|
+
ok = false;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const op = item.op;
|
|
603
|
+
const problem = checkValueProblem(op, item.value, "value" in item);
|
|
604
|
+
if (problem) {
|
|
605
|
+
c.add("eval.grader_invalid", `${at} ${problem}`);
|
|
606
|
+
ok = false;
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
out.push({ op, ...("value" in item ? { value: item.value } : {}) });
|
|
610
|
+
});
|
|
611
|
+
return ok ? out : undefined;
|
|
612
|
+
}
|
|
613
|
+
function parseGrader(c, raw, index, defaultJudge, kind) {
|
|
614
|
+
if (!isPlainObject(raw)) {
|
|
615
|
+
c.add("eval.grader_invalid", `graders[${index}] must be a mapping`);
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
const label = typeof raw.id === "string" ? `grader "${raw.id}"` : `graders[${index}]`;
|
|
619
|
+
const before = c.issues.length;
|
|
620
|
+
if (typeof raw.id !== "string" || !ID_PATTERN.test(raw.id)) {
|
|
621
|
+
c.add("eval.invalid_field", `graders[${index}] "id" must match ${ID_PATTERN.source}`);
|
|
622
|
+
}
|
|
623
|
+
const type = raw.type;
|
|
624
|
+
if (type === undefined) {
|
|
625
|
+
c.add("eval.grader_invalid", `${label} "type" is required`);
|
|
626
|
+
return undefined;
|
|
627
|
+
}
|
|
628
|
+
if (type === "command") {
|
|
629
|
+
c.add("eval.grader_type_unsupported", `${label} type "command" is not available in release 1 (supported: ${GRADER_TYPES.join(", ")})`);
|
|
630
|
+
return undefined;
|
|
631
|
+
}
|
|
632
|
+
if (typeof type !== "string" || !GRADER_TYPES.includes(type)) {
|
|
633
|
+
c.add("eval.grader_type_unsupported", `${label} type ${JSON.stringify(type)} is not supported (supported: ${GRADER_TYPES.join(", ")})`);
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
const graderType = type;
|
|
637
|
+
const scaleOnGoal = graderType === "goal_reached" && raw.scale !== undefined;
|
|
638
|
+
c.unknownKeys(scaleOnGoal ? Object.fromEntries(Object.entries(raw).filter(([key]) => key !== "scale")) : raw, [...GRADER_COMMON_KEYS, ...GRADER_TYPE_KEYS[graderType]], label);
|
|
639
|
+
if (scaleOnGoal) {
|
|
640
|
+
c.add("eval.grader_invalid", `${label} "scale" is not accepted: goal_reached is always pass_fail`);
|
|
641
|
+
}
|
|
642
|
+
const description = optionalString(c, raw, "description", label, { max: 200 });
|
|
643
|
+
const weight = optionalNumber(c, raw, "weight", label, "a number greater than 0", (n) => n > 0);
|
|
644
|
+
let mustPass = false;
|
|
645
|
+
if (raw.must_pass !== undefined) {
|
|
646
|
+
if (typeof raw.must_pass === "boolean")
|
|
647
|
+
mustPass = raw.must_pass;
|
|
648
|
+
else
|
|
649
|
+
c.add("eval.invalid_field", `${label} "must_pass" must be a boolean`);
|
|
650
|
+
}
|
|
651
|
+
const common = {
|
|
652
|
+
id: String(raw.id),
|
|
653
|
+
...(description !== undefined ? { description } : {}),
|
|
654
|
+
...(weight !== undefined ? { weight } : {}),
|
|
655
|
+
...(raw.must_pass !== undefined && typeof raw.must_pass === "boolean"
|
|
656
|
+
? { must_pass: raw.must_pass }
|
|
657
|
+
: {}),
|
|
658
|
+
};
|
|
659
|
+
const resolvedCommon = {
|
|
660
|
+
id: String(raw.id),
|
|
661
|
+
weight: weight ?? 1,
|
|
662
|
+
mustPass,
|
|
663
|
+
...(description !== undefined ? { description } : {}),
|
|
664
|
+
};
|
|
665
|
+
let result;
|
|
666
|
+
switch (graderType) {
|
|
667
|
+
case "schema":
|
|
668
|
+
result = {
|
|
669
|
+
config: { ...common, type: "schema" },
|
|
670
|
+
resolved: { ...resolvedCommon, type: "schema" },
|
|
671
|
+
};
|
|
672
|
+
break;
|
|
673
|
+
case "field": {
|
|
674
|
+
const checks = parseChecks(c, raw.checks, label);
|
|
675
|
+
if (checks) {
|
|
676
|
+
result = {
|
|
677
|
+
config: { ...common, type: "field", checks },
|
|
678
|
+
resolved: { ...resolvedCommon, type: "field", checks },
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
case "reference": {
|
|
684
|
+
const mode = raw.mode;
|
|
685
|
+
let ok = true;
|
|
686
|
+
if (mode !== "each_mentioned" && mode !== "equals") {
|
|
687
|
+
c.add("eval.grader_invalid", `${label} "mode" must be "each_mentioned" or "equals"`);
|
|
688
|
+
ok = false;
|
|
689
|
+
}
|
|
690
|
+
let pathValue = kind === "agent" || kind === "internal_agent" ? "final_reply" : "payload";
|
|
691
|
+
if (raw.path !== undefined) {
|
|
692
|
+
if (typeof raw.path === "string" && FIELD_PATH_PATTERN.test(raw.path))
|
|
693
|
+
pathValue = raw.path;
|
|
694
|
+
else {
|
|
695
|
+
c.add("eval.grader_invalid", `${label} "path" must be a valid envelope path`);
|
|
696
|
+
ok = false;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (typeof raw.expected !== "string" || !FIELD_PATH_PATTERN.test(raw.expected)) {
|
|
700
|
+
c.add("eval.grader_invalid", `${label} "expected" must be a valid path into the case (for example expected.findings)`);
|
|
701
|
+
ok = false;
|
|
702
|
+
}
|
|
703
|
+
const passAt = optionalNumber(c, raw, "pass_at", label, "a number from 0 to 1", (n) => n >= 0 && n <= 1, "eval.grader_invalid");
|
|
704
|
+
if (raw.pass_at !== undefined && passAt === undefined)
|
|
705
|
+
ok = false;
|
|
706
|
+
if (ok) {
|
|
707
|
+
result = {
|
|
708
|
+
config: {
|
|
709
|
+
...common,
|
|
710
|
+
type: "reference",
|
|
711
|
+
mode: mode,
|
|
712
|
+
...(raw.path !== undefined ? { path: pathValue } : {}),
|
|
713
|
+
expected: raw.expected,
|
|
714
|
+
...(passAt !== undefined ? { pass_at: passAt } : {}),
|
|
715
|
+
},
|
|
716
|
+
resolved: {
|
|
717
|
+
...resolvedCommon,
|
|
718
|
+
type: "reference",
|
|
719
|
+
mode: mode,
|
|
720
|
+
path: pathValue,
|
|
721
|
+
expected: raw.expected,
|
|
722
|
+
passAt: passAt ?? 1,
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
case "rubric": {
|
|
729
|
+
let ok = true;
|
|
730
|
+
if (typeof raw.rubric !== "string" || raw.rubric.length < 1 || raw.rubric.length > 4000) {
|
|
731
|
+
c.add("eval.grader_invalid", `${label} "rubric" must be a string of 1-4000 characters`);
|
|
732
|
+
ok = false;
|
|
733
|
+
}
|
|
734
|
+
let scale = "pass_fail";
|
|
735
|
+
if (raw.scale !== undefined) {
|
|
736
|
+
if (raw.scale === "pass_fail" || raw.scale === "1_to_5")
|
|
737
|
+
scale = raw.scale;
|
|
738
|
+
else {
|
|
739
|
+
c.add("eval.grader_invalid", `${label} "scale" must be "pass_fail" or "1_to_5"`);
|
|
740
|
+
ok = false;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
let passAt;
|
|
744
|
+
if (raw.pass_at !== undefined) {
|
|
745
|
+
if (scale === "pass_fail") {
|
|
746
|
+
c.add("eval.grader_invalid", `${label} "pass_at" is only allowed with scale "1_to_5"`);
|
|
747
|
+
ok = false;
|
|
748
|
+
}
|
|
749
|
+
else if (typeof raw.pass_at === "number" && isIntegerIn(raw.pass_at, 1, 5)) {
|
|
750
|
+
passAt = raw.pass_at;
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
c.add("eval.grader_invalid", `${label} "pass_at" must be an integer from 1 to 5`);
|
|
754
|
+
ok = false;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
let judge;
|
|
758
|
+
if (raw.judge !== undefined) {
|
|
759
|
+
if (typeof raw.judge === "string" && raw.judge.length > 0)
|
|
760
|
+
judge = raw.judge;
|
|
761
|
+
else {
|
|
762
|
+
c.add("eval.grader_invalid", `${label} "judge" must be a model id string`);
|
|
763
|
+
ok = false;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
let examples;
|
|
767
|
+
if (raw.examples !== undefined) {
|
|
768
|
+
examples = parseExamples(c, raw.examples, scale, label);
|
|
769
|
+
if (examples === undefined)
|
|
770
|
+
ok = false;
|
|
771
|
+
}
|
|
772
|
+
if (ok) {
|
|
773
|
+
result = {
|
|
774
|
+
config: {
|
|
775
|
+
...common,
|
|
776
|
+
type: "rubric",
|
|
777
|
+
rubric: raw.rubric,
|
|
778
|
+
...(raw.scale !== undefined ? { scale } : {}),
|
|
779
|
+
...(passAt !== undefined ? { pass_at: passAt } : {}),
|
|
780
|
+
...(judge !== undefined ? { judge } : {}),
|
|
781
|
+
...(examples !== undefined ? { examples } : {}),
|
|
782
|
+
},
|
|
783
|
+
resolved: {
|
|
784
|
+
...resolvedCommon,
|
|
785
|
+
type: "rubric",
|
|
786
|
+
rubric: raw.rubric,
|
|
787
|
+
scale,
|
|
788
|
+
passAt: scale === "1_to_5" ? (passAt ?? 4) : 1,
|
|
789
|
+
judge: judge ?? defaultJudge ?? "",
|
|
790
|
+
examples: examples ?? [],
|
|
791
|
+
},
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
case "code": {
|
|
797
|
+
if (typeof raw.code !== "string" || raw.code.trim() === "") {
|
|
798
|
+
c.add("eval.grader_invalid", `${label} "code" must be a non-empty string`);
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
result = {
|
|
802
|
+
config: { ...common, type: "code", code: raw.code },
|
|
803
|
+
resolved: { ...resolvedCommon, type: "code", code: raw.code },
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
case "tool_calls": {
|
|
809
|
+
const mustCall = optionalToolList(c, raw, "must_call", label);
|
|
810
|
+
const mustNotCall = optionalToolList(c, raw, "must_not_call", label);
|
|
811
|
+
const mustAskFirst = optionalToolList(c, raw, "must_ask_first", label);
|
|
812
|
+
const maxCalls = optionalNumber(c, raw, "max_calls", label, "an integer from 0 to 200", (n) => isIntegerIn(n, 0, 200), "eval.grader_invalid");
|
|
813
|
+
const args = raw.args === undefined ? [] : parseToolArgs(c, raw.args, label);
|
|
814
|
+
if (args !== undefined) {
|
|
815
|
+
result = {
|
|
816
|
+
config: {
|
|
817
|
+
...common,
|
|
818
|
+
type: "tool_calls",
|
|
819
|
+
...(mustCall !== undefined ? { must_call: mustCall } : {}),
|
|
820
|
+
...(mustNotCall !== undefined ? { must_not_call: mustNotCall } : {}),
|
|
821
|
+
...(mustAskFirst !== undefined ? { must_ask_first: mustAskFirst } : {}),
|
|
822
|
+
...(maxCalls !== undefined ? { max_calls: maxCalls } : {}),
|
|
823
|
+
...(raw.args !== undefined ? { args } : {}),
|
|
824
|
+
},
|
|
825
|
+
resolved: {
|
|
826
|
+
...resolvedCommon,
|
|
827
|
+
type: "tool_calls",
|
|
828
|
+
...(mustCall !== undefined ? { mustCall } : {}),
|
|
829
|
+
...(mustNotCall !== undefined ? { mustNotCall } : {}),
|
|
830
|
+
...(mustAskFirst !== undefined ? { mustAskFirst } : {}),
|
|
831
|
+
...(maxCalls !== undefined ? { maxCalls } : {}),
|
|
832
|
+
args,
|
|
833
|
+
},
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
case "conversation_check": {
|
|
839
|
+
const maxTurns = optionalNumber(c, raw, "max_turns", label, "an integer from 1 to 100", (n) => isIntegerIn(n, 1, 100), "eval.grader_invalid");
|
|
840
|
+
const maxQuestions = optionalNumber(c, raw, "max_agent_questions_per_turn", label, "an integer from 0 to 10", (n) => isIntegerIn(n, 0, 10), "eval.grader_invalid");
|
|
841
|
+
const finalReply = raw.final_reply === undefined ? [] : parseFinalReply(c, raw.final_reply, label);
|
|
842
|
+
if (raw.max_turns === undefined && raw.max_agent_questions_per_turn === undefined && raw.final_reply === undefined) {
|
|
843
|
+
c.add("eval.grader_invalid", `${label} needs at least one of: max_turns, max_agent_questions_per_turn, final_reply`);
|
|
844
|
+
}
|
|
845
|
+
if (finalReply !== undefined) {
|
|
846
|
+
result = {
|
|
847
|
+
config: {
|
|
848
|
+
...common,
|
|
849
|
+
type: "conversation_check",
|
|
850
|
+
...(maxTurns !== undefined ? { max_turns: maxTurns } : {}),
|
|
851
|
+
...(maxQuestions !== undefined ? { max_agent_questions_per_turn: maxQuestions } : {}),
|
|
852
|
+
...(raw.final_reply !== undefined ? { final_reply: finalReply } : {}),
|
|
853
|
+
},
|
|
854
|
+
resolved: {
|
|
855
|
+
...resolvedCommon,
|
|
856
|
+
type: "conversation_check",
|
|
857
|
+
...(maxTurns !== undefined ? { maxTurns } : {}),
|
|
858
|
+
...(maxQuestions !== undefined ? { maxAgentQuestionsPerTurn: maxQuestions } : {}),
|
|
859
|
+
finalReply,
|
|
860
|
+
},
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
case "goal_reached": {
|
|
866
|
+
let ok = true;
|
|
867
|
+
let judge;
|
|
868
|
+
if (raw.judge !== undefined) {
|
|
869
|
+
if (typeof raw.judge === "string" && raw.judge.length > 0)
|
|
870
|
+
judge = raw.judge;
|
|
871
|
+
else {
|
|
872
|
+
c.add("eval.grader_invalid", `${label} "judge" must be a model id string`);
|
|
873
|
+
ok = false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
let guidance;
|
|
877
|
+
if (raw.guidance !== undefined) {
|
|
878
|
+
if (typeof raw.guidance === "string" && raw.guidance.length <= 2000)
|
|
879
|
+
guidance = raw.guidance;
|
|
880
|
+
else {
|
|
881
|
+
c.add("eval.grader_invalid", `${label} "guidance" must be a string of at most 2000 characters`);
|
|
882
|
+
ok = false;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (ok) {
|
|
886
|
+
result = {
|
|
887
|
+
config: {
|
|
888
|
+
...common,
|
|
889
|
+
type: "goal_reached",
|
|
890
|
+
...(judge !== undefined ? { judge } : {}),
|
|
891
|
+
...(guidance !== undefined ? { guidance } : {}),
|
|
892
|
+
},
|
|
893
|
+
resolved: {
|
|
894
|
+
...resolvedCommon,
|
|
895
|
+
type: "goal_reached",
|
|
896
|
+
judge: judge ?? defaultJudge ?? "",
|
|
897
|
+
...(guidance !== undefined ? { guidance } : {}),
|
|
898
|
+
},
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
return c.issues.length > before ? undefined : result;
|
|
905
|
+
}
|
|
906
|
+
/** Grader hash object: the grader's file keys with defaults filled in; a rubric carries its effective judge. */
|
|
907
|
+
function graderHashObject(grader) {
|
|
908
|
+
const base = {
|
|
909
|
+
id: grader.id,
|
|
910
|
+
type: grader.type,
|
|
911
|
+
description: grader.description,
|
|
912
|
+
weight: grader.weight,
|
|
913
|
+
must_pass: grader.mustPass,
|
|
914
|
+
};
|
|
915
|
+
switch (grader.type) {
|
|
916
|
+
case "schema":
|
|
917
|
+
return base;
|
|
918
|
+
case "field":
|
|
919
|
+
return { ...base, checks: grader.checks };
|
|
920
|
+
case "reference":
|
|
921
|
+
return {
|
|
922
|
+
...base,
|
|
923
|
+
mode: grader.mode,
|
|
924
|
+
path: grader.path,
|
|
925
|
+
expected: grader.expected,
|
|
926
|
+
pass_at: grader.passAt,
|
|
927
|
+
};
|
|
928
|
+
case "rubric":
|
|
929
|
+
return {
|
|
930
|
+
...base,
|
|
931
|
+
rubric: grader.rubric,
|
|
932
|
+
scale: grader.scale,
|
|
933
|
+
...(grader.scale === "1_to_5" ? { pass_at: grader.passAt } : {}),
|
|
934
|
+
judge: grader.judge,
|
|
935
|
+
examples: grader.examples,
|
|
936
|
+
};
|
|
937
|
+
case "code":
|
|
938
|
+
return { ...base, code: grader.code };
|
|
939
|
+
case "tool_calls":
|
|
940
|
+
return {
|
|
941
|
+
...base,
|
|
942
|
+
must_call: grader.mustCall,
|
|
943
|
+
must_not_call: grader.mustNotCall,
|
|
944
|
+
must_ask_first: grader.mustAskFirst,
|
|
945
|
+
max_calls: grader.maxCalls,
|
|
946
|
+
args: grader.args,
|
|
947
|
+
};
|
|
948
|
+
case "conversation_check":
|
|
949
|
+
return {
|
|
950
|
+
...base,
|
|
951
|
+
max_turns: grader.maxTurns,
|
|
952
|
+
max_agent_questions_per_turn: grader.maxAgentQuestionsPerTurn,
|
|
953
|
+
final_reply: grader.finalReply,
|
|
954
|
+
};
|
|
955
|
+
case "goal_reached":
|
|
956
|
+
return { ...base, judge: grader.judge, guidance: grader.guidance };
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
export function graderHash(grader) {
|
|
960
|
+
return sha256Hex(canonicalJson(graderHashObject(grader)));
|
|
961
|
+
}
|
|
962
|
+
export function graderHashShort(grader) {
|
|
963
|
+
return hash6(grader.hash);
|
|
964
|
+
}
|
|
965
|
+
export function parseEvalOutcome(yamlText, filePath, projectRoot) {
|
|
966
|
+
let raw;
|
|
967
|
+
try {
|
|
968
|
+
raw = parseYaml(yamlText);
|
|
969
|
+
}
|
|
970
|
+
catch (err) {
|
|
971
|
+
return loadFailure([
|
|
972
|
+
{
|
|
973
|
+
...evalIssue("eval.load_error", err instanceof Error ? err.message : String(err)),
|
|
974
|
+
...yamlParsePosition(err),
|
|
975
|
+
},
|
|
976
|
+
]);
|
|
977
|
+
}
|
|
978
|
+
if (!isPlainObject(raw)) {
|
|
979
|
+
return loadFailure([evalIssue("eval.not_object", "Eval file must be a YAML mapping")]);
|
|
980
|
+
}
|
|
981
|
+
const c = new Collector();
|
|
982
|
+
c.unknownKeys(raw, TOP_KEYS, "the eval file");
|
|
983
|
+
if (raw.version !== 1) {
|
|
984
|
+
c.add("eval.invalid_version", `"version" must be 1 (found ${JSON.stringify(raw.version) ?? "none"})`);
|
|
985
|
+
}
|
|
986
|
+
const absPath = path.resolve(filePath);
|
|
987
|
+
const stem = evalFileStem(absPath);
|
|
988
|
+
const id = raw.id;
|
|
989
|
+
if (typeof id !== "string" || !ID_PATTERN.test(id)) {
|
|
990
|
+
c.add("eval.invalid_id", `"id" must match ${ID_PATTERN.source}`);
|
|
991
|
+
}
|
|
992
|
+
else if (id !== stem) {
|
|
993
|
+
c.add("eval.id_filename_mismatch", `Eval id "${id}" does not match filename stem "${stem}"`);
|
|
994
|
+
}
|
|
995
|
+
const name = optionalString(c, raw, "name", "eval", { min: 1, max: 80 });
|
|
996
|
+
const description = optionalString(c, raw, "description", "eval", { max: 500 });
|
|
997
|
+
let type;
|
|
998
|
+
if (raw.type !== undefined) {
|
|
999
|
+
if (raw.type === "capability" || raw.type === "regression")
|
|
1000
|
+
type = raw.type;
|
|
1001
|
+
else
|
|
1002
|
+
c.add("eval.invalid_field", `"type" must be "capability" or "regression"`);
|
|
1003
|
+
}
|
|
1004
|
+
const target = parseTarget(c, raw.target);
|
|
1005
|
+
let dataset;
|
|
1006
|
+
if (raw.dataset === undefined) {
|
|
1007
|
+
c.add("eval.invalid_field", `Missing required key "dataset"`);
|
|
1008
|
+
}
|
|
1009
|
+
else if (typeof raw.dataset !== "string" || raw.dataset.trim() === "") {
|
|
1010
|
+
c.add("eval.invalid_field", `"dataset" must be a non-empty path string`);
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
dataset = raw.dataset;
|
|
1014
|
+
}
|
|
1015
|
+
const root = path.resolve(projectRoot);
|
|
1016
|
+
const dir = path.dirname(absPath);
|
|
1017
|
+
if (dataset !== undefined && !isInside(root, path.resolve(dir, dataset))) {
|
|
1018
|
+
c.add("eval.dataset_unresolved", `Dataset path "${dataset}" resolves outside the project root`);
|
|
1019
|
+
}
|
|
1020
|
+
if (target?.kind === "stage") {
|
|
1021
|
+
for (const [key, value] of [
|
|
1022
|
+
["pipeline", target.pipeline],
|
|
1023
|
+
["file", target.file],
|
|
1024
|
+
]) {
|
|
1025
|
+
if (value !== undefined && !isInside(root, path.resolve(dir, value))) {
|
|
1026
|
+
c.add("eval.target_unresolved", `Target ${key} "${value}" resolves outside the project root`);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
let task;
|
|
1031
|
+
if (target?.kind === "agent" && raw.task !== undefined) {
|
|
1032
|
+
c.add("eval.task_not_applicable", `"task" is not accepted for an agent target (the scenario goal is input.goal)`);
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
task = parseTask(c, raw.task);
|
|
1036
|
+
}
|
|
1037
|
+
const defaults = parseDefaults(c, raw.defaults, target?.kind);
|
|
1038
|
+
const conversation = parseConversation(c, raw.conversation, target?.kind);
|
|
1039
|
+
const budget = parseBudget(c, raw.budget);
|
|
1040
|
+
const parsedGraders = [];
|
|
1041
|
+
if (raw.graders === undefined) {
|
|
1042
|
+
c.add("eval.invalid_field", `Missing required key "graders"`);
|
|
1043
|
+
}
|
|
1044
|
+
else if (!Array.isArray(raw.graders) || raw.graders.length < 1 || raw.graders.length > 20) {
|
|
1045
|
+
c.add("eval.invalid_field", `"graders" must be an array of 1-20 graders`);
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
const seen = new Set();
|
|
1049
|
+
raw.graders.forEach((rawGrader, index) => {
|
|
1050
|
+
const parsed = parseGrader(c, rawGrader, index, defaults?.judge, target?.kind);
|
|
1051
|
+
if (isPlainObject(rawGrader) && typeof rawGrader.id === "string") {
|
|
1052
|
+
if (seen.has(rawGrader.id)) {
|
|
1053
|
+
c.add("eval.grader_duplicate_id", `Duplicate grader id "${rawGrader.id}"`);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
seen.add(rawGrader.id);
|
|
1057
|
+
}
|
|
1058
|
+
if (parsed)
|
|
1059
|
+
parsedGraders.push(parsed);
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
if (c.issues.length > 0 || !target || dataset === undefined || typeof id !== "string") {
|
|
1063
|
+
return loadFailure(c.issues);
|
|
1064
|
+
}
|
|
1065
|
+
const file = {
|
|
1066
|
+
version: 1,
|
|
1067
|
+
id,
|
|
1068
|
+
...(name !== undefined ? { name } : {}),
|
|
1069
|
+
...(description !== undefined ? { description } : {}),
|
|
1070
|
+
...(type !== undefined ? { type } : {}),
|
|
1071
|
+
target,
|
|
1072
|
+
dataset,
|
|
1073
|
+
...(task !== undefined ? { task } : {}),
|
|
1074
|
+
...(defaults !== undefined ? { defaults } : {}),
|
|
1075
|
+
...(conversation !== undefined ? { conversation } : {}),
|
|
1076
|
+
graders: parsedGraders.map((g) => g.config),
|
|
1077
|
+
...(budget !== undefined ? { budget } : {}),
|
|
1078
|
+
};
|
|
1079
|
+
const graders = parsedGraders.map((g) => ({ ...g.resolved, hash: graderHash(g.resolved) }));
|
|
1080
|
+
return loadSuccess({
|
|
1081
|
+
path: absPath,
|
|
1082
|
+
relPath: path.relative(root, absPath).split(path.sep).join("/"),
|
|
1083
|
+
id,
|
|
1084
|
+
fileHash: sha256Hex(Buffer.from(yamlText, "utf8")),
|
|
1085
|
+
file,
|
|
1086
|
+
graders,
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
export async function loadEvalOutcome(absPath, projectRoot) {
|
|
1090
|
+
let bytes;
|
|
1091
|
+
try {
|
|
1092
|
+
bytes = await readFile(absPath);
|
|
1093
|
+
}
|
|
1094
|
+
catch (err) {
|
|
1095
|
+
return loadFailure([
|
|
1096
|
+
evalIssue("eval.load_error", err instanceof Error ? err.message : String(err)),
|
|
1097
|
+
]);
|
|
1098
|
+
}
|
|
1099
|
+
const outcome = parseEvalOutcome(bytes.toString("utf8"), absPath, projectRoot);
|
|
1100
|
+
if (!outcome.ok)
|
|
1101
|
+
return outcome;
|
|
1102
|
+
return loadSuccess({ ...outcome.value, fileHash: sha256Hex(bytes) });
|
|
1103
|
+
}
|