@vaudience/aigentflow-flow-validator 0.15.3 → 0.18.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/cli.js CHANGED
@@ -436,7 +436,7 @@ function validateBasicStructure(flow, issues) {
436
436
  // src/spec/aigentflow-spec.json
437
437
  var aigentflow_spec_default = {
438
438
  $comment: "Vendored enum surface mirrored from the AIgentFlow Go reference implementation. Regenerate / review on every flow-YAML schema change. See PARITY.md. Values here are public protocol/type names only.",
439
- specVersion: "2.802.0",
439
+ specVersion: "2.819.0",
440
440
  inputSchemaVersion: 1,
441
441
  executorSchemes: [
442
442
  "a2a",
@@ -467,7 +467,6 @@ var aigentflow_spec_default = {
467
467
  "messenger",
468
468
  "mock",
469
469
  "mqtt",
470
- "nexus",
471
470
  "opencorporates",
472
471
  "openmeteo",
473
472
  "overpass",
@@ -770,12 +769,6 @@ var aigentflow_spec_default = {
770
769
  fields: ["api_key", "base_url", "organization"],
771
770
  extraKey: "extra",
772
771
  scopes: {
773
- aigentchat: [
774
- "AIGENTFLOW_AIGENTCHAT_API_KEY",
775
- "AIGENTFLOW_AIGENTCHAT_BASE_URL",
776
- "AIGENTFLOW_NEXUS_API_KEY",
777
- "AIGENTFLOW_NEXUS_BASE_URL"
778
- ],
779
772
  anthropic: [
780
773
  "AIGENTFLOW_ANTHROPIC_API_KEY",
781
774
  "AIGENTFLOW_ANTHROPIC_BASE_URL"
@@ -883,12 +876,6 @@ var aigentflow_spec_default = {
883
876
  "AIGENTFLOW_MQTT_PASSWORD",
884
877
  "AIGENTFLOW_MQTT_USERNAME"
885
878
  ],
886
- nexus: [
887
- "AIGENTFLOW_AIGENTCHAT_API_KEY",
888
- "AIGENTFLOW_AIGENTCHAT_BASE_URL",
889
- "AIGENTFLOW_NEXUS_API_KEY",
890
- "AIGENTFLOW_NEXUS_BASE_URL"
891
- ],
892
879
  ollama: [
893
880
  "AIGENTFLOW_OLLAMA_API_KEY",
894
881
  "AIGENTFLOW_OLLAMA_BASE_URL"
@@ -959,7 +946,7 @@ var aigentflow_spec_default = {
959
946
  loopStepFieldFormat: "steps.%s.loop.steps.%s.query.%s"
960
947
  },
961
948
  credentialEndpointPairing: {
962
- $comment: "credential_endpoint_unpaired (WARNING, never an error): the one statically certain shape of AIgentFlow's run-time credential/endpoint pairing refusal. ai: an ai://<provider>/... step (top-level or loop sub-step) whose query holds a non-empty string <provider>+providerBaseUrlParamSuffix while neither its query (genericKeyParam or <provider>+providerKeyParamSuffix, non-empty strings) nor executor_config.<provider>.api_key (a literal, not an env reference) supplies a key; and executor_config.<provider>.base_url for a provider in executorConfigProviders when it is a literal, the block has no literal api_key, and it is not the case that at least one step uses the provider and every such step brings its own query key. keylessProviders are exempt from both. families: a step whose executor resolves (protocolAliases first, then the key protocol+familyKeySeparator+driver, else protocol) to a row. implicitServerCredential rows are never judged. A row with storedKeyShape warns on the first non-empty string endpointParam in the query unless the query holds an own key (a non-empty string in ownKeyParams, or a mapping under ownCredentialsMapParam). Any other row warns when its secret (the first non-empty string secretParam in the query, else per configKey in order: executor_config api_key when configApiKeyParam is a secretParam, else the first non-empty string secretParam under extra) is exactly an env reference to a serverEnv name on a row with expandsServerEnvReferences, and its endpoint (the first non-empty string endpointParam in the query, else per configKey: base_url when configBaseUrlParam is an endpointParam, else the first non-empty string endpointParam under extra) is a literal: no templateActionOpen, not an env reference, and not of the same origin as a defaultEndpoint (lower-cased scheme://host:port, defaultPorts filled). serverEnv is the reference's per-family server-variable set, evaluated. Field formats are the reference's. Reference: validateCredentialEndpointPairing (DC-FORGE-231) and validateFamilyCredentialEndpointPairing (DC-FORGE-233).",
949
+ $comment: "credential_endpoint_unpaired (WARNING, never an error): the one statically certain shape of AIgentFlow's run-time credential/endpoint pairing refusal. ai: an ai://<provider>/... step (top-level or loop sub-step) whose query holds a non-empty string <provider>+providerBaseUrlParamSuffix while neither its query (genericKeyParam or <provider>+providerKeyParamSuffix, non-empty strings) nor executor_config.<provider>.api_key (a literal, not an env reference) supplies a key; and executor_config.<provider>.base_url for a provider in executorConfigProviders when it is a literal, the block has no literal api_key, and it is not the case that at least one step uses the provider and every such step brings its own query key. keylessProviders are exempt from both. families: a step whose executor resolves (the key protocol+familyKeySeparator+driver, else protocol) to a row. implicitServerCredential rows are never judged. A row warns when its secret (the first non-empty string secretParam in the query, else per configKey in order: executor_config api_key when configApiKeyParam is a secretParam, else the first non-empty string secretParam under extra) is exactly an env reference to a serverEnv name on a row with expandsServerEnvReferences, and its endpoint (the first non-empty string endpointParam in the query, else per configKey: base_url when configBaseUrlParam is an endpointParam, else the first non-empty string endpointParam under extra) is a literal: no templateActionOpen, not an env reference, and not of the same origin as a defaultEndpoint (lower-cased scheme://host:port, defaultPorts filled). serverEnv is the reference's per-family server-variable set, evaluated. Field formats are the reference's. Reference: validateCredentialEndpointPairing (DC-FORGE-231) and validateFamilyCredentialEndpointPairing (DC-FORGE-233).",
963
950
  stepFieldFormat: "steps.%s.query.%s",
964
951
  loopStepFieldFormat: "steps.%s.loop.steps.%s.query.%s",
965
952
  executorConfigBaseUrlFieldFormat: "executor_config.%s.base_url",
@@ -1010,9 +997,6 @@ var aigentflow_spec_default = {
1010
997
  ]
1011
998
  },
1012
999
  familyKeySeparator: "/",
1013
- protocolAliases: {
1014
- aigentchat: "nexus"
1015
- },
1016
1000
  families: {
1017
1001
  db: {
1018
1002
  protocol: "db",
@@ -1171,40 +1155,6 @@ var aigentflow_spec_default = {
1171
1155
  "AIGENTFLOW_MQTT_PASSWORD"
1172
1156
  ]
1173
1157
  },
1174
- nexus: {
1175
- protocol: "nexus",
1176
- configKeys: [
1177
- "nexus",
1178
- "aigentchat"
1179
- ],
1180
- secretParams: [
1181
- "aigentchat_api_key",
1182
- "api_key"
1183
- ],
1184
- endpointParams: [
1185
- "aigentchat_base_url",
1186
- "base_url"
1187
- ],
1188
- defaultEndpoints: [],
1189
- configApiKeyParam: "",
1190
- configBaseUrlParam: "",
1191
- implicitServerCredential: false,
1192
- expandsServerEnvReferences: false,
1193
- serverEnv: [
1194
- "AIGENTFLOW_NEXUS_BASE_URL",
1195
- "AIGENTFLOW_NEXUS_API_KEY",
1196
- "AIGENTFLOW_AIGENTCHAT_API_KEY",
1197
- "AIGENTFLOW_AIGENTCHAT_BASE_URL"
1198
- ],
1199
- storedKeyShape: {
1200
- ownKeyParams: [
1201
- "aigentchat_api_key",
1202
- "api_key"
1203
- ],
1204
- ownCredentialsMapParam: "credentials",
1205
- provider: "aigentchat"
1206
- }
1207
- },
1208
1158
  opencorporates: {
1209
1159
  protocol: "opencorporates",
1210
1160
  configKeys: [
@@ -1325,6 +1275,160 @@ var aigentflow_spec_default = {
1325
1275
  }
1326
1276
  }
1327
1277
  },
1278
+ examples: {
1279
+ $comment: "The examples: block. Derived from the reference's constants, never hand-typed: limits, vocabularies, the credential-shaped-literal pattern set and each code's severity. example_ref_blocked_host is listed for completeness but is raised by the reference implementation only; the ports never raise it. See PARITY.md, 'The examples block'.",
1280
+ limits: {
1281
+ maxPerFlow: 50,
1282
+ maxBlockBytes: 262144,
1283
+ maxInlineInputBytes: 32768,
1284
+ maxReferenceTextBytes: 32768,
1285
+ maxVariants: 10,
1286
+ maxTags: 8,
1287
+ maxMustNot: 12,
1288
+ maxMustNotContain: 20,
1289
+ maxRubricRunes: 4e3,
1290
+ maxGuidanceRunes: 2e3,
1291
+ maxNotesRunes: 2e3,
1292
+ titleMaxRunes: 80,
1293
+ maxMustNotRunes: 300,
1294
+ maxMustNotContainLength: 200,
1295
+ maxProvenanceRunes: 200,
1296
+ maxNoteRunes: 300,
1297
+ maxUrlBytes: 2048,
1298
+ maxPatternLength: 512,
1299
+ weightMax: 10,
1300
+ minScoreMin: 0,
1301
+ minScoreMax: 1
1302
+ },
1303
+ idPattern: "^[a-z][a-z0-9_]{1,47}$",
1304
+ tagPattern: "^[a-z][a-z0-9_-]{0,31}$",
1305
+ sha256Pattern: "^[0-9a-f]{64}$",
1306
+ mediaTypePattern: "^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$",
1307
+ signedUrlQueryKeyPattern: "^(x-amz-signature|signature|sig|token|access_token|key|x-goog-signature|se|sp)$",
1308
+ origins: [
1309
+ "author",
1310
+ "synthetic"
1311
+ ],
1312
+ sideEffects: [
1313
+ "refuse",
1314
+ "allow"
1315
+ ],
1316
+ statuses: [
1317
+ "completed",
1318
+ "failed",
1319
+ "paused_for_human"
1320
+ ],
1321
+ reservedRefSchemes: [
1322
+ "artifact",
1323
+ "trove",
1324
+ "aiv",
1325
+ "s3",
1326
+ "gs"
1327
+ ],
1328
+ secretPatterns: [
1329
+ {
1330
+ name: "an API key",
1331
+ expr: "\\bsk-[A-Za-z0-9_-]{20,}",
1332
+ flags: ""
1333
+ },
1334
+ {
1335
+ name: "a platform API key",
1336
+ expr: "\\bcrn_[A-Za-z0-9]{16,}",
1337
+ flags: ""
1338
+ },
1339
+ {
1340
+ name: "an AWS access key",
1341
+ expr: "\\bAKIA[0-9A-Z]{16}\\b",
1342
+ flags: ""
1343
+ },
1344
+ {
1345
+ name: "a private key",
1346
+ expr: "-----BEGIN [A-Z ]*PRIVATE KEY-----",
1347
+ flags: ""
1348
+ },
1349
+ {
1350
+ name: "a bearer token",
1351
+ expr: "\\bbearer\\s+[A-Za-z0-9._~+/-]{20,}",
1352
+ flags: "i"
1353
+ },
1354
+ {
1355
+ name: "a Slack token",
1356
+ expr: "\\bxox[abprs]-[A-Za-z0-9-]{10,}",
1357
+ flags: ""
1358
+ },
1359
+ {
1360
+ name: "a GitHub token",
1361
+ expr: "\\bgh[pousr]_[A-Za-z0-9]{30,}",
1362
+ flags: ""
1363
+ },
1364
+ {
1365
+ name: "a retired registry key",
1366
+ expr: "\\baivk_[A-Za-z0-9]{20,}",
1367
+ flags: ""
1368
+ }
1369
+ ],
1370
+ codes: {
1371
+ example_checkpoint_status: "error",
1372
+ example_checkpoint_step_composite: "error",
1373
+ example_checkpoint_step_unknown: "error",
1374
+ example_expectation_contradiction: "warning",
1375
+ example_expected_conflict: "error",
1376
+ example_expected_empty: "error",
1377
+ example_expected_field_unchecked: "warning",
1378
+ example_expected_field_unknown: "error",
1379
+ example_expected_missing: "error",
1380
+ example_field_matcher_invalid: "error",
1381
+ example_file_input_needs_ref: "error",
1382
+ example_guidance_missing: "warning",
1383
+ example_guidance_too_long: "error",
1384
+ example_holdout_in_public_flow: "error",
1385
+ example_id_duplicate: "error",
1386
+ example_id_invalid: "error",
1387
+ example_id_missing: "error",
1388
+ example_input_conflict: "error",
1389
+ example_input_invalid: "error",
1390
+ example_input_missing: "error",
1391
+ example_input_too_large: "error",
1392
+ example_input_unvalidated: "warning",
1393
+ example_min_score_range: "error",
1394
+ example_must_not_contain_invalid: "error",
1395
+ example_must_not_invalid: "error",
1396
+ example_notes_too_long: "error",
1397
+ example_ref_blocked_host: "error",
1398
+ example_ref_invalid: "error",
1399
+ example_ref_media_type_invalid: "error",
1400
+ example_ref_scheme: "error",
1401
+ example_ref_scheme_reserved: "error",
1402
+ example_ref_sha256_invalid: "error",
1403
+ example_ref_signed_url: "warning",
1404
+ example_ref_unpinned: "warning",
1405
+ example_reference_binary: "warning",
1406
+ example_reference_invalid: "error",
1407
+ example_rubric_empty: "error",
1408
+ example_rubric_too_long: "error",
1409
+ example_secret_like_value: "error",
1410
+ example_secret_value: "error",
1411
+ example_side_effects_invalid: "error",
1412
+ example_status_invalid: "error",
1413
+ example_tag_invalid: "error",
1414
+ example_title_missing: "error",
1415
+ example_title_too_long: "error",
1416
+ example_variant_empty: "error",
1417
+ example_variant_id_duplicate: "error",
1418
+ example_variant_id_invalid: "error",
1419
+ example_variant_input_conflict: "error",
1420
+ example_variant_input_invalid: "error",
1421
+ example_variant_origin_invalid: "error",
1422
+ example_variant_unchecked: "warning",
1423
+ example_variants_too_many: "error",
1424
+ example_weight_range: "error",
1425
+ examples_all_held_out: "warning",
1426
+ examples_block_too_large: "error",
1427
+ examples_published_with_public_flow: "warning",
1428
+ examples_too_many: "error",
1429
+ examples_unreadable_by_judge: "warning"
1430
+ }
1431
+ },
1328
1432
  knownKeys: {
1329
1433
  $comment: "Derived by reflection over the reference's Flow type, following yaml.v3's field rules (yaml tag, lowercased field name, inline structs merged). KnownFields(true) refuses any key a struct type does not declare. A shape is scalar | any | map<S> | list<S> | a type name below. any is never inspected (a Go interface, or a type with its own unmarshaller). How it is derived and checked, and how to regenerate it: PARITY.md, 'Unknown keys and value kinds'.",
1330
1434
  root: "Flow",
@@ -1346,6 +1450,17 @@ var aigentflow_spec_default = {
1346
1450
  on_children_complete: "scalar",
1347
1451
  shared_memory: "scalar"
1348
1452
  },
1453
+ Checkpoint: {
1454
+ exact: "map<any>",
1455
+ fields: "map<FieldMatcher>",
1456
+ min_score: "scalar",
1457
+ must_not: "list<scalar>",
1458
+ must_not_contain: "list<scalar>",
1459
+ optional: "scalar",
1460
+ reference: "ExampleReference",
1461
+ rubric: "scalar",
1462
+ status: "scalar"
1463
+ },
1349
1464
  CheckpointConfig: {
1350
1465
  enabled: "scalar",
1351
1466
  interval_steps: "scalar",
@@ -1368,6 +1483,37 @@ var aigentflow_spec_default = {
1368
1483
  retry_delay: "scalar",
1369
1484
  retry_on: "list<scalar>"
1370
1485
  },
1486
+ ExampleDefinition: {
1487
+ checkpoints: "map<Checkpoint>",
1488
+ expected: "Expectation",
1489
+ guidance: "scalar",
1490
+ hold_out: "scalar",
1491
+ id: "scalar",
1492
+ input: "map<any>",
1493
+ input_ref: "FileRef",
1494
+ min_score: "scalar",
1495
+ notes: "scalar",
1496
+ side_effects: "scalar",
1497
+ tags: "list<scalar>",
1498
+ title: "scalar",
1499
+ variants: "list<ExampleVariant>",
1500
+ weight: "scalar"
1501
+ },
1502
+ ExampleReference: {
1503
+ ref: "FileRef",
1504
+ text: "scalar"
1505
+ },
1506
+ ExampleVariant: {
1507
+ expected: "Expectation",
1508
+ guidance: "scalar",
1509
+ id: "scalar",
1510
+ input_patch: "map<any>",
1511
+ input_ref: "FileRef",
1512
+ origin: "scalar",
1513
+ provenance: "scalar",
1514
+ title: "scalar",
1515
+ weight: "scalar"
1516
+ },
1371
1517
  ExecutorDefaultsDefinition: {
1372
1518
  frequency_penalty: "scalar",
1373
1519
  max_tokens: "scalar",
@@ -1390,6 +1536,16 @@ var aigentflow_spec_default = {
1390
1536
  allowed_models: "list<scalar>",
1391
1537
  allowed_providers: "list<scalar>"
1392
1538
  },
1539
+ Expectation: {
1540
+ exact: "map<any>",
1541
+ fields: "map<FieldMatcher>",
1542
+ min_score: "scalar",
1543
+ must_not: "list<scalar>",
1544
+ must_not_contain: "list<scalar>",
1545
+ reference: "ExampleReference",
1546
+ rubric: "scalar",
1547
+ status: "scalar"
1548
+ },
1393
1549
  FailoverBreakerConfig: {
1394
1550
  failure_threshold: "scalar",
1395
1551
  open_duration: "scalar",
@@ -1408,6 +1564,22 @@ var aigentflow_spec_default = {
1408
1564
  type: "scalar",
1409
1565
  validation: "scalar"
1410
1566
  },
1567
+ FieldMatcher: {
1568
+ approx: "scalar",
1569
+ contains: "scalar",
1570
+ equals: "any",
1571
+ matches: "scalar",
1572
+ not_contains: "scalar",
1573
+ one_of: "list<any>",
1574
+ present: "scalar",
1575
+ tolerance: "scalar"
1576
+ },
1577
+ FileRef: {
1578
+ media_type: "scalar",
1579
+ note: "scalar",
1580
+ sha256: "scalar",
1581
+ url: "scalar"
1582
+ },
1411
1583
  Flow: {
1412
1584
  aigentflow_version: "scalar",
1413
1585
  billing: "BillingConfig",
@@ -1421,6 +1593,7 @@ var aigentflow_spec_default = {
1421
1593
  discoverable_tools: "list<scalar>",
1422
1594
  display_name: "scalar",
1423
1595
  error_strategy: "ErrorStrategyDefinition",
1596
+ examples: "list<ExampleDefinition>",
1424
1597
  executor_config: "map<ExecutorInstanceDefinition>",
1425
1598
  exons_uploads: "ExonsUploadsFlowConfig",
1426
1599
  expression_functions: "list<map<scalar>>",
@@ -1498,6 +1671,7 @@ var aigentflow_spec_default = {
1498
1671
  pattern: "scalar",
1499
1672
  required: "scalar",
1500
1673
  type: "scalar",
1674
+ untrusted: "scalar",
1501
1675
  visible_when: "VisibleWhenPredicate"
1502
1676
  },
1503
1677
  LoopDefinition: {
@@ -1507,6 +1681,7 @@ var aigentflow_spec_default = {
1507
1681
  while: "scalar"
1508
1682
  },
1509
1683
  LoopStepDefinition: {
1684
+ allow_untrusted: "list<scalar>",
1510
1685
  condition: "scalar",
1511
1686
  credential: "scalar",
1512
1687
  credentials: "map<StepCredentialBinding>",
@@ -1519,7 +1694,8 @@ var aigentflow_spec_default = {
1519
1694
  post_processing: "list<any>",
1520
1695
  pre_processing: "list<any>",
1521
1696
  query: "map<any>",
1522
- response_evaluation: "scalar"
1697
+ response_evaluation: "scalar",
1698
+ trusted_output: "scalar"
1523
1699
  },
1524
1700
  MockBinaryAsset: {
1525
1701
  filename: "scalar",
@@ -1607,6 +1783,7 @@ var aigentflow_spec_default = {
1607
1783
  properties: "map<PropertyDefinition>",
1608
1784
  required: "scalar",
1609
1785
  type: "scalar",
1786
+ untrusted: "scalar",
1610
1787
  validation: "scalar"
1611
1788
  },
1612
1789
  StepCredentialBinding: {
@@ -1614,6 +1791,7 @@ var aigentflow_spec_default = {
1614
1791
  source: "scalar"
1615
1792
  },
1616
1793
  StepDefinition: {
1794
+ allow_untrusted: "list<scalar>",
1617
1795
  condition: "scalar",
1618
1796
  credential: "scalar",
1619
1797
  credentials: "map<StepCredentialBinding>",
@@ -1631,7 +1809,8 @@ var aigentflow_spec_default = {
1631
1809
  quality_gate: "QualityGateDefinition",
1632
1810
  query: "map<any>",
1633
1811
  response_evaluation: "scalar",
1634
- response_expectation: "map<FieldExpectationDefinition>"
1812
+ response_expectation: "map<FieldExpectationDefinition>",
1813
+ trusted_output: "scalar"
1635
1814
  },
1636
1815
  ThrottleDefinition: {
1637
1816
  batch_delay: "scalar",
@@ -1760,9 +1939,27 @@ var CREDENTIAL_ENDPOINT_PAIRING = {
1760
1939
  executorConfigProviders: aigentflow_spec_default.credentialEndpointPairing.ai.executorConfigProviders
1761
1940
  },
1762
1941
  familyKeySeparator: aigentflow_spec_default.credentialEndpointPairing.familyKeySeparator,
1763
- protocolAliases: aigentflow_spec_default.credentialEndpointPairing.protocolAliases,
1764
1942
  families: aigentflow_spec_default.credentialEndpointPairing.families
1765
1943
  };
1944
+ var EXAMPLES = {
1945
+ limits: aigentflow_spec_default.examples.limits,
1946
+ idPattern: new RegExp(aigentflow_spec_default.examples.idPattern),
1947
+ tagPattern: new RegExp(aigentflow_spec_default.examples.tagPattern),
1948
+ sha256Pattern: new RegExp(aigentflow_spec_default.examples.sha256Pattern),
1949
+ mediaTypePattern: new RegExp(aigentflow_spec_default.examples.mediaTypePattern),
1950
+ // The reference writes this pattern case-insensitively (`(?i)`); the spec
1951
+ // carries the bare expression, so the flag is applied here.
1952
+ signedUrlQueryKeyPattern: new RegExp(aigentflow_spec_default.examples.signedUrlQueryKeyPattern, "i"),
1953
+ origins: new Set(aigentflow_spec_default.examples.origins),
1954
+ sideEffects: new Set(aigentflow_spec_default.examples.sideEffects),
1955
+ statuses: new Set(aigentflow_spec_default.examples.statuses),
1956
+ reservedRefSchemes: new Set(aigentflow_spec_default.examples.reservedRefSchemes),
1957
+ secretPatterns: aigentflow_spec_default.examples.secretPatterns.map((p) => ({
1958
+ name: p.name,
1959
+ re: new RegExp(p.expr, p.flags)
1960
+ })),
1961
+ codes: aigentflow_spec_default.examples.codes
1962
+ };
1766
1963
 
1767
1964
  // src/validators/executors.ts
1768
1965
  var SCHEME_SEPARATOR = "://";
@@ -3231,29 +3428,29 @@ function validateField(f, schemaPath, i, seen, issues) {
3231
3428
  });
3232
3429
  }
3233
3430
  const stringy = INPUT_SCHEMA.stringTypes.has(type);
3234
- const mismatch = (constraint) => issues.error({
3431
+ const mismatch2 = (constraint) => issues.error({
3235
3432
  field: `${base}.${constraint}`,
3236
3433
  message: `constraint '${constraint}' is not meaningful for field '${shownName}' of type '${type}'`,
3237
3434
  code: "input_schema_constraint_type_mismatch"
3238
3435
  });
3239
3436
  if (!stringy) {
3240
- if (f.min_length !== void 0) mismatch("min_length");
3241
- if (f.max_length !== void 0) mismatch("max_length");
3242
- if (pattern !== null && pattern !== "") mismatch("pattern");
3437
+ if (f.min_length !== void 0) mismatch2("min_length");
3438
+ if (f.max_length !== void 0) mismatch2("max_length");
3439
+ if (pattern !== null && pattern !== "") mismatch2("pattern");
3243
3440
  }
3244
3441
  if (type !== TYPE_NUMBER) {
3245
- if (f.min !== void 0) mismatch("min");
3246
- if (f.max !== void 0) mismatch("max");
3442
+ if (f.min !== void 0) mismatch2("min");
3443
+ if (f.max !== void 0) mismatch2("max");
3247
3444
  }
3248
3445
  if (type !== TYPE_ARRAY_OF_STRINGS) {
3249
- if (f.min_items !== void 0) mismatch("min_items");
3250
- if (f.max_items !== void 0) mismatch("max_items");
3446
+ if (f.min_items !== void 0) mismatch2("min_items");
3447
+ if (f.max_items !== void 0) mismatch2("max_items");
3251
3448
  }
3252
3449
  if (type !== TYPE_FILE) {
3253
- if (Array.isArray(f.accept) && f.accept.length > 0) mismatch("accept");
3254
- if (f.max_size !== void 0) mismatch("max_size");
3450
+ if (Array.isArray(f.accept) && f.accept.length > 0) mismatch2("accept");
3451
+ if (f.max_size !== void 0) mismatch2("max_size");
3255
3452
  }
3256
- if (type !== TYPE_ENUM && Array.isArray(f.enum) && f.enum.length > 0) mismatch("enum");
3453
+ if (type !== TYPE_ENUM && Array.isArray(f.enum) && f.enum.length > 0) mismatch2("enum");
3257
3454
  const cap = (constraint, val) => issues.error({
3258
3455
  field: `${base}.${constraint}`,
3259
3456
  message: `constraint '${constraint}' (${val}) for field '${shownName}' exceeds the maximum of ${INPUT_SCHEMA.maxConstraintValue}`,
@@ -4535,7 +4732,8 @@ function parseHost(host) {
4535
4732
  function parseAuthority(authority) {
4536
4733
  const at = authority.lastIndexOf("@");
4537
4734
  const host = parseHost(at < 0 ? authority : authority.slice(at + 1));
4538
- if (host === null || at < 0) return host;
4735
+ if (host === null) return null;
4736
+ if (at < 0) return { host, hasUser: false };
4539
4737
  const userinfo = authority.slice(0, at);
4540
4738
  if (!validUserinfo(userinfo)) return null;
4541
4739
  const colon = userinfo.indexOf(":");
@@ -4543,7 +4741,7 @@ function parseAuthority(authority) {
4543
4741
  for (const part of parts) {
4544
4742
  if (unescapeText(part, Mode.UserPassword) === null) return null;
4545
4743
  }
4546
- return host;
4744
+ return { host, hasUser: true };
4547
4745
  }
4548
4746
  function getScheme(raw) {
4549
4747
  for (let i = 0; i < raw.length; i++) {
@@ -4569,28 +4767,37 @@ function containsCTL(s) {
4569
4767
  return false;
4570
4768
  }
4571
4769
  function goParseSchemeHost(rawURL) {
4770
+ const u = goParseURLParts(rawURL);
4771
+ return u === null ? null : { scheme: u.scheme, host: u.host };
4772
+ }
4773
+ function goParseURLParts(rawURL) {
4572
4774
  const hash = rawURL.indexOf("#");
4573
4775
  const main2 = hash < 0 ? rawURL : rawURL.slice(0, hash);
4574
4776
  const frag = hash < 0 ? "" : rawURL.slice(hash + 1);
4575
4777
  if (containsCTL(main2)) return null;
4576
- if (main2 === "*") return { scheme: "", host: "" };
4778
+ if (main2 === "*") {
4779
+ return { scheme: "", host: "", hasUser: false, rawQuery: "", fragment: frag };
4780
+ }
4577
4781
  const split = getScheme(main2);
4578
4782
  if (split === null) return null;
4579
4783
  const scheme = split.scheme.toLowerCase();
4580
4784
  let rest = split.rest;
4581
4785
  const questionMarks = rest.split("?").length - 1;
4786
+ let rawQuery = "";
4582
4787
  if (rest.endsWith("?") && questionMarks === 1) {
4583
4788
  rest = rest.slice(0, -1);
4584
4789
  } else if (questionMarks > 0) {
4790
+ rawQuery = rest.slice(rest.indexOf("?") + 1);
4585
4791
  rest = rest.slice(0, rest.indexOf("?"));
4586
4792
  }
4587
4793
  if (!rest.startsWith("/")) {
4588
- if (scheme !== "") return finish({ scheme, host: "" }, frag);
4794
+ if (scheme !== "") return finish({ scheme, host: "", hasUser: false, rawQuery }, frag);
4589
4795
  const slash = rest.indexOf("/");
4590
4796
  const segment = slash < 0 ? rest : rest.slice(0, slash);
4591
4797
  if (segment.includes(":")) return null;
4592
4798
  }
4593
4799
  let host = "";
4800
+ let hasUser = false;
4594
4801
  if ((scheme !== "" || !rest.startsWith("///")) && rest.startsWith("//")) {
4595
4802
  let authority = rest.slice(2);
4596
4803
  rest = "";
@@ -4601,14 +4808,26 @@ function goParseSchemeHost(rawURL) {
4601
4808
  }
4602
4809
  const parsed = parseAuthority(authority);
4603
4810
  if (parsed === null) return null;
4604
- host = parsed;
4811
+ host = parsed.host;
4812
+ hasUser = parsed.hasUser;
4605
4813
  }
4606
4814
  if (unescapeText(rest, Mode.Path) === null) return null;
4607
- return finish({ scheme, host }, frag);
4815
+ return finish({ scheme, host, hasUser, rawQuery }, frag);
4608
4816
  }
4609
4817
  function finish(u, frag) {
4610
4818
  if (frag !== "" && unescapeText(frag, Mode.Fragment) === null) return null;
4611
- return u;
4819
+ return { ...u, fragment: frag };
4820
+ }
4821
+ function goQueryKeys(rawQuery) {
4822
+ const keys = [];
4823
+ for (const pair of rawQuery.split("&")) {
4824
+ if (pair === "" || pair.includes(";")) continue;
4825
+ const eq = pair.indexOf("=");
4826
+ const rawKey = eq < 0 ? pair : pair.slice(0, eq);
4827
+ const key = unescapeText(rawKey.replace(/\+/g, " "), Mode.Path);
4828
+ if (key !== null) keys.push(key);
4829
+ }
4830
+ return keys;
4612
4831
  }
4613
4832
  function goEndpointOrigin(raw, defaultPorts, protocolSeparator) {
4614
4833
  const trimmed = goTrimSpace(raw);
@@ -4745,12 +4964,10 @@ function warnStoredShape(issues, field, provider) {
4745
4964
  function familyOf(executor) {
4746
4965
  const sep = executor.indexOf(CREDENTIAL_ENDPOINT_PAIRING.protocolSeparator);
4747
4966
  if (sep <= 0) return null;
4748
- let protocol = executor.slice(0, sep);
4967
+ const protocol = executor.slice(0, sep);
4749
4968
  const rest = executor.slice(sep + CREDENTIAL_ENDPOINT_PAIRING.protocolSeparator.length);
4750
4969
  const slash = rest.indexOf("/");
4751
4970
  const driver = slash < 0 ? rest : rest.slice(0, slash);
4752
- const alias = own(CREDENTIAL_ENDPOINT_PAIRING.protocolAliases, protocol);
4753
- if (typeof alias === "string") protocol = alias;
4754
4971
  const candidates = driver === "" ? [protocol] : [protocol + CREDENTIAL_ENDPOINT_PAIRING.familyKeySeparator + driver, protocol];
4755
4972
  for (const key of candidates) {
4756
4973
  const family = own(CREDENTIAL_ENDPOINT_PAIRING.families, key);
@@ -4830,24 +5047,11 @@ function familyAuthorEndpoint(flow, family, step, issues) {
4830
5047
  }
4831
5048
  return null;
4832
5049
  }
4833
- function storedShapeHasOwnKey(family, query) {
4834
- const shape = family.storedKeyShape;
4835
- if (shape === void 0) return false;
4836
- if (shape.ownKeyParams.some((key) => nonEmptyString(query, key) !== null)) return true;
4837
- return isRecord(own(query, shape.ownCredentialsMapParam));
4838
- }
4839
5050
  function validateFamilies(flow, steps, issues) {
4840
5051
  for (const step of steps) {
4841
5052
  const found = familyOf(step.executor);
4842
5053
  if (found === null || found.family.implicitServerCredential) continue;
4843
5054
  const { key: familyKey, family } = found;
4844
- if (family.storedKeyShape !== void 0) {
4845
- if (storedShapeHasOwnKey(family, step.query)) continue;
4846
- const key = family.endpointParams.find((k) => nonEmptyEndpoint(step.query, k) !== null);
4847
- if (key !== void 0)
4848
- warnStoredShape(issues, step.field(key), family.storedKeyShape.provider);
4849
- continue;
4850
- }
4851
5055
  const secret = familySecret(flow, family, step, issues);
4852
5056
  if (secret === null || secret.envName === null) continue;
4853
5057
  const endpointField = familyAuthorEndpoint(flow, family, step, issues);
@@ -5085,6 +5289,1291 @@ function warnOrchestratorToolWithheld(flow, orch, report, issues) {
5085
5289
  }
5086
5290
  }
5087
5291
 
5292
+ // src/validators/examples.ts
5293
+ var KEY_EXAMPLES = "examples";
5294
+ var VISIBILITY_PUBLIC = "public";
5295
+ var STATUS_COMPLETED = "completed";
5296
+ var STATUS_FAILED = "failed";
5297
+ var STATUS_PAUSED_FOR_HUMAN = "paused_for_human";
5298
+ var ORIGIN_NONE = "";
5299
+ var SIDE_EFFECTS_NONE = "";
5300
+ var SCHEME_HTTPS = "https";
5301
+ var FILE_REF_KEYS = /* @__PURE__ */ new Set(["url", "sha256", "media_type", "note"]);
5302
+ var FILE_REF_KEY = "ref";
5303
+ var TYPE_SECRET = "secret";
5304
+ var TYPE_FILE2 = "file";
5305
+ var TYPE_STRING = "string";
5306
+ var TYPE_MULTILINE = "multiline";
5307
+ var TYPE_NUMBER2 = "number";
5308
+ var TYPE_BOOL = "bool";
5309
+ var TYPE_ENUM2 = "enum";
5310
+ var TYPE_ARRAY_OF_STRINGS2 = "array_of_strings";
5311
+ var TYPE_DATE = "date";
5312
+ var MAX_RECURSION_DEPTH = 32;
5313
+ var TEXTUAL_MEDIA_BASES = /* @__PURE__ */ new Set([
5314
+ "application/json",
5315
+ "application/xml",
5316
+ "application/yaml",
5317
+ "application/x-yaml",
5318
+ "application/markdown"
5319
+ ]);
5320
+ var SUGGESTION_ID = "Pick a short stable name such as standard_invoice; it is the key results are filed under, so it never changes once saved";
5321
+ var SUGGESTION_CHECKPOINT = "Did you rename the step? Update the checkpoint to the new name";
5322
+ var SUGGESTION_SECRET_VALUE = "Remove the value; you are asked for it when you run the check";
5323
+ var SUGGESTION_EXPECTED = "Add at least a rubric: one or two sentences on what a good result looks like";
5324
+ var utf8Encoder2 = new TextEncoder();
5325
+ function byteLen(s) {
5326
+ return utf8Encoder2.encode(s).length;
5327
+ }
5328
+ function runeCount(s) {
5329
+ let n = 0;
5330
+ for (const _ of s) n++;
5331
+ return n;
5332
+ }
5333
+ function q(s) {
5334
+ let out = '"';
5335
+ for (const ch of s) {
5336
+ const c = ch.codePointAt(0);
5337
+ if (ch === '"') out += '\\"';
5338
+ else if (ch === "\\") out += "\\\\";
5339
+ else if (c === 7) out += "\\a";
5340
+ else if (c === 8) out += "\\b";
5341
+ else if (c === 12) out += "\\f";
5342
+ else if (c === 10) out += "\\n";
5343
+ else if (c === 13) out += "\\r";
5344
+ else if (c === 9) out += "\\t";
5345
+ else if (c === 11) out += "\\v";
5346
+ else if (c < 32 || c === 127) out += `\\x${c.toString(16).padStart(2, "0")}`;
5347
+ else if (c >= 128 && /[\p{C}\p{Z}]/u.test(ch)) {
5348
+ out += c > 65535 ? `\\U${c.toString(16).padStart(8, "0")}` : `\\u${c.toString(16).padStart(4, "0")}`;
5349
+ } else out += ch;
5350
+ }
5351
+ return `${out}"`;
5352
+ }
5353
+ function num(n) {
5354
+ if (Number.isNaN(n)) return "NaN";
5355
+ if (n === Infinity) return "+Inf";
5356
+ if (n === -Infinity) return "-Inf";
5357
+ if (n === 0) return Object.is(n, -0) ? "-0" : "0";
5358
+ const [mantissa = "", exponent = "0"] = n.toExponential().split("e");
5359
+ const exp = Number(exponent);
5360
+ if (exp < -4 || exp >= 6) {
5361
+ const sign = exp < 0 ? "-" : "+";
5362
+ return `${mantissa}e${sign}${String(Math.abs(exp)).padStart(2, "0")}`;
5363
+ }
5364
+ return String(n);
5365
+ }
5366
+ function has(o, key) {
5367
+ return Object.prototype.hasOwnProperty.call(o, key) && o[key] !== null && o[key] !== void 0;
5368
+ }
5369
+ function own2(o, key) {
5370
+ return Object.prototype.hasOwnProperty.call(o, key) ? o[key] : void 0;
5371
+ }
5372
+ function setOwn(o, key, value) {
5373
+ Object.defineProperty(o, key, {
5374
+ value,
5375
+ enumerable: true,
5376
+ writable: true,
5377
+ configurable: true
5378
+ });
5379
+ }
5380
+ function sortedKeys(o) {
5381
+ return Object.keys(o).sort();
5382
+ }
5383
+ function numberOf(v) {
5384
+ return typeof v === "number" ? v : void 0;
5385
+ }
5386
+ function normalize(v, depth) {
5387
+ if (depth > MAX_RECURSION_DEPTH) return null;
5388
+ if (v instanceof Date) {
5389
+ if (Number.isNaN(v.getTime())) return null;
5390
+ const iso = v.toISOString();
5391
+ if (/T00:00:00\.000Z$/.test(iso)) return iso.slice(0, 10);
5392
+ return iso.replace(/\.000Z$/, "Z");
5393
+ }
5394
+ if (Array.isArray(v)) return v.map((x) => normalize(x, depth + 1));
5395
+ if (isRecord(v)) {
5396
+ const out = {};
5397
+ for (const k of Object.keys(v)) setOwn(out, k, normalize(v[k], depth + 1));
5398
+ return out;
5399
+ }
5400
+ return v;
5401
+ }
5402
+ function deepCopy(v, depth) {
5403
+ if (depth > MAX_RECURSION_DEPTH) return v;
5404
+ if (Array.isArray(v)) return v.map((x) => deepCopy(x, depth + 1));
5405
+ if (isRecord(v)) {
5406
+ const out = {};
5407
+ for (const k of Object.keys(v)) setOwn(out, k, deepCopy(v[k], depth + 1));
5408
+ return out;
5409
+ }
5410
+ return v;
5411
+ }
5412
+ function mergePatch(target, patch, depth) {
5413
+ if (depth > MAX_RECURSION_DEPTH) return;
5414
+ for (const k of Object.keys(patch)) {
5415
+ const pv = patch[k];
5416
+ if (pv === null || pv === void 0) {
5417
+ delete target[k];
5418
+ continue;
5419
+ }
5420
+ if (isRecord(pv)) {
5421
+ const current = own2(target, k);
5422
+ const existing = isRecord(current) ? deepCopy(current, 0) : {};
5423
+ mergePatch(existing, pv, depth + 1);
5424
+ setOwn(target, k, existing);
5425
+ continue;
5426
+ }
5427
+ setOwn(target, k, deepCopy(pv, 0));
5428
+ }
5429
+ }
5430
+ function applyExamplePatch(base, patch) {
5431
+ const out = deepCopy(base, 0);
5432
+ mergePatch(out, patch, 0);
5433
+ return out;
5434
+ }
5435
+ function asFileRef(v) {
5436
+ if (!isRecord(v)) return null;
5437
+ const keys = Object.keys(v);
5438
+ if (keys.length === 0) return null;
5439
+ for (const k of keys) if (!FILE_REF_KEYS.has(k)) return null;
5440
+ const str = (k) => {
5441
+ const x = own2(v, k);
5442
+ return typeof x === "string" ? x : "";
5443
+ };
5444
+ return {
5445
+ url: str("url"),
5446
+ sha256: str("sha256"),
5447
+ mediaType: str("media_type"),
5448
+ note: str("note")
5449
+ };
5450
+ }
5451
+ function isTextualMediaType(mediaType) {
5452
+ const base = goToLower(goTrimSpace((mediaType.split(";")[0] ?? "").toString()));
5453
+ if (base.startsWith("text/")) return true;
5454
+ if (base.endsWith("+json") || base.endsWith("+xml")) return true;
5455
+ return TEXTUAL_MEDIA_BASES.has(base);
5456
+ }
5457
+ var Walker = class _Walker {
5458
+ constructor(flow, issues) {
5459
+ this.flow = flow;
5460
+ this.issues = issues;
5461
+ this.findings = [];
5462
+ }
5463
+ // -- emit -------------------------------------------------------------
5464
+ add(severity, code, field, message, suggestion) {
5465
+ this.findings.push({
5466
+ code,
5467
+ severity,
5468
+ field,
5469
+ message,
5470
+ ...suggestion !== void 0 ? { suggestion } : {}
5471
+ });
5472
+ }
5473
+ err(code, field, message, suggestion) {
5474
+ this.add("error", code, field, message, suggestion);
5475
+ }
5476
+ warn(code, field, message) {
5477
+ this.add("warning", code, field, message);
5478
+ }
5479
+ /** A Go `string` field read by its source text; absent is "". */
5480
+ s(o, key, parentPath) {
5481
+ return this.issues.stringOf(o, key, parentPath) ?? "";
5482
+ }
5483
+ // -- the set ----------------------------------------------------------
5484
+ run(examples) {
5485
+ this.validateSet(examples);
5486
+ const seen = /* @__PURE__ */ new Map();
5487
+ examples.forEach((ex, i) => {
5488
+ if (isRecord(ex)) this.validateExample(i, ex, seen);
5489
+ });
5490
+ }
5491
+ validateSet(examples) {
5492
+ const n = examples.length;
5493
+ const L = EXAMPLES.limits;
5494
+ if (n > L.maxPerFlow) {
5495
+ this.err(
5496
+ "examples_too_many",
5497
+ KEY_EXAMPLES,
5498
+ `flow declares ${n} examples; the limit is ${L.maxPerFlow}`
5499
+ );
5500
+ }
5501
+ const size = blockBytes(examples);
5502
+ if (size !== null && size > L.maxBlockBytes) {
5503
+ this.err(
5504
+ "examples_block_too_large",
5505
+ KEY_EXAMPLES,
5506
+ `the examples block is ${size} bytes; the limit is ${L.maxBlockBytes}. Move large inputs or target outputs to a file reference (https URL).`
5507
+ );
5508
+ }
5509
+ const allHeld = examples.every((e) => isRecord(e) && own2(e, "hold_out") === true);
5510
+ if (allHeld) {
5511
+ this.warn(
5512
+ "examples_all_held_out",
5513
+ KEY_EXAMPLES,
5514
+ "every example is held out, so nothing is left to tune on"
5515
+ );
5516
+ }
5517
+ if (this.isPublic()) {
5518
+ this.warn(
5519
+ "examples_published_with_public_flow",
5520
+ KEY_EXAMPLES,
5521
+ "this flow is public, so everyone who can see it can read its examples, including their expected results. Only publish examples you are happy to show."
5522
+ );
5523
+ }
5524
+ }
5525
+ isPublic() {
5526
+ return this.s(this.flow, "visibility", "") === VISIBILITY_PUBLIC;
5527
+ }
5528
+ // -- one example ------------------------------------------------------
5529
+ validateExample(i, ex, seen) {
5530
+ const L = EXAMPLES.limits;
5531
+ const path = `examples[${i}]`;
5532
+ const id = this.s(ex, "id", path);
5533
+ const label = id === "" ? `#${i + 1}` : id;
5534
+ if (id === "") {
5535
+ this.err("example_id_missing", `${path}.id`, `example #${i + 1} has no id`, SUGGESTION_ID);
5536
+ } else if (!EXAMPLES.idPattern.test(id)) {
5537
+ this.err(
5538
+ "example_id_invalid",
5539
+ `${path}.id`,
5540
+ `example id ${q(id)} is not valid: use lower-case letters, digits and underscores, starting with a letter (2 to 48 characters)`,
5541
+ SUGGESTION_ID
5542
+ );
5543
+ } else {
5544
+ const first = seen.get(id);
5545
+ if (first !== void 0) {
5546
+ this.err(
5547
+ "example_id_duplicate",
5548
+ `${path}.id`,
5549
+ `example id ${q(id)} is used by examples #${first + 1} and #${i + 1}`
5550
+ );
5551
+ } else {
5552
+ seen.set(id, i);
5553
+ }
5554
+ }
5555
+ const title = this.s(ex, "title", path);
5556
+ if (goTrimSpace(title) === "") {
5557
+ this.err(
5558
+ "example_title_missing",
5559
+ `${path}.title`,
5560
+ `example ${q(label)} has no title; the title is what a person sees in the list of examples`
5561
+ );
5562
+ } else {
5563
+ const n = runeCount(title);
5564
+ if (n > L.titleMaxRunes) {
5565
+ this.err(
5566
+ "example_title_too_long",
5567
+ `${path}.title`,
5568
+ `example ${q(label)} title is ${n} characters; the limit is ${L.titleMaxRunes}`
5569
+ );
5570
+ }
5571
+ }
5572
+ const guidance = this.s(ex, "guidance", path);
5573
+ if (goTrimSpace(guidance) === "") {
5574
+ this.warn(
5575
+ "example_guidance_missing",
5576
+ `${path}.guidance`,
5577
+ `example ${q(label)} has no guidance. One sentence on why this case matters helps the judge and the next author.`
5578
+ );
5579
+ } else {
5580
+ const n = runeCount(guidance);
5581
+ if (n > L.maxGuidanceRunes) {
5582
+ this.err(
5583
+ "example_guidance_too_long",
5584
+ `${path}.guidance`,
5585
+ `example ${q(label)} guidance is ${n} characters; the limit is ${L.maxGuidanceRunes}`
5586
+ );
5587
+ }
5588
+ }
5589
+ const notesN = runeCount(this.s(ex, "notes", path));
5590
+ if (notesN > L.maxNotesRunes) {
5591
+ this.err(
5592
+ "example_notes_too_long",
5593
+ `${path}.notes`,
5594
+ `example ${q(label)} notes are ${notesN} characters; the limit is ${L.maxNotesRunes}`
5595
+ );
5596
+ }
5597
+ this.validateTags(path, label, own2(ex, "tags"));
5598
+ this.validateWeight(`${path}.weight`, label, numberOf(own2(ex, "weight")));
5599
+ const minScore = numberOf(own2(ex, "min_score"));
5600
+ if (minScore !== void 0 && !scoreInRange(minScore)) {
5601
+ this.err(
5602
+ "example_min_score_range",
5603
+ `${path}.min_score`,
5604
+ `example ${q(label)} has min_score ${num(minScore)}; use a number from 0 to 1 (0.7 is 7.3 out of 10)`
5605
+ );
5606
+ }
5607
+ const sideEffects = this.s(ex, "side_effects", path);
5608
+ if (sideEffects !== SIDE_EFFECTS_NONE && !EXAMPLES.sideEffects.has(sideEffects)) {
5609
+ this.err(
5610
+ "example_side_effects_invalid",
5611
+ `${path}.side_effects`,
5612
+ `example ${q(label)} has side_effects ${q(sideEffects)}; use refuse or allow`
5613
+ );
5614
+ }
5615
+ const holdOut = own2(ex, "hold_out") === true;
5616
+ if (holdOut && this.isPublic()) {
5617
+ this.err(
5618
+ "example_holdout_in_public_flow",
5619
+ `${path}.hold_out`,
5620
+ `example ${q(label)} is held out but this flow is public: a held-out example must stay private, and a public flow's definition is readable by everyone. Make the flow private or remove hold_out.`
5621
+ );
5622
+ }
5623
+ const hasInput = has(ex, "input");
5624
+ const hasInputRef = has(ex, "input_ref");
5625
+ if (hasInput && hasInputRef) {
5626
+ this.err(
5627
+ "example_input_conflict",
5628
+ path,
5629
+ `example ${q(label)} sets both input and input_ref; use exactly one`
5630
+ );
5631
+ } else if (!hasInput && !hasInputRef) {
5632
+ this.err(
5633
+ "example_input_missing",
5634
+ path,
5635
+ `example ${q(label)} has neither input nor input_ref; use input: {} for a flow that takes no input`
5636
+ );
5637
+ }
5638
+ const rawInput = own2(ex, "input");
5639
+ const baseInput = isRecord(rawInput) ? rawInput : null;
5640
+ if (baseInput !== null) {
5641
+ this.checkInput(`${path}.input`, label, baseInput, "example_input_invalid");
5642
+ }
5643
+ const rawInputRef = own2(ex, "input_ref");
5644
+ if (isRecord(rawInputRef)) {
5645
+ this.validateFileRef(`${path}.input_ref`, this.fileRefOf(rawInputRef, `${path}.input_ref`));
5646
+ }
5647
+ let binaryOnly = false;
5648
+ const expected = own2(ex, "expected");
5649
+ if (!has(ex, "expected")) {
5650
+ this.err(
5651
+ "example_expected_missing",
5652
+ `${path}.expected`,
5653
+ `example ${q(label)} does not say what a good result is: add a rubric, fields, exact or reference`,
5654
+ SUGGESTION_EXPECTED
5655
+ );
5656
+ } else if (isRecord(expected)) {
5657
+ this.validateExpectation(`${path}.expected`, label, expected, "final", "");
5658
+ binaryOnly = this.expectationIsBinaryReferenceOnly(expected, `${path}.expected`);
5659
+ }
5660
+ if (binaryOnly) {
5661
+ this.warn(
5662
+ "examples_unreadable_by_judge",
5663
+ `${path}.expected`,
5664
+ "this example can be run but not scored"
5665
+ );
5666
+ }
5667
+ this.validateCheckpoints(path, label, own2(ex, "checkpoints"));
5668
+ this.validateVariants(i, path, label, ex, hasInput, baseInput);
5669
+ this.scanSecretLike(i, path, ex);
5670
+ }
5671
+ validateTags(path, label, tags) {
5672
+ if (!Array.isArray(tags)) return;
5673
+ if (tags.length > EXAMPLES.limits.maxTags) {
5674
+ this.err(
5675
+ "example_tag_invalid",
5676
+ `${path}.tags`,
5677
+ `example ${q(label)} has ${tags.length} tags; the limit is ${EXAMPLES.limits.maxTags}`
5678
+ );
5679
+ }
5680
+ const seen = /* @__PURE__ */ new Set();
5681
+ tags.forEach((item, j) => {
5682
+ const field = `${path}.tags[${j}]`;
5683
+ const tag = item === null ? "" : this.issues.stringAt(item, field) ?? null;
5684
+ if (tag === null) return;
5685
+ if (!EXAMPLES.tagPattern.test(tag)) {
5686
+ this.err("example_tag_invalid", field, `example ${q(label)} has an invalid tag ${q(tag)}`);
5687
+ } else if (seen.has(tag)) {
5688
+ this.err(
5689
+ "example_tag_invalid",
5690
+ field,
5691
+ `example ${q(label)} lists the tag ${q(tag)} more than once`
5692
+ );
5693
+ }
5694
+ seen.add(tag);
5695
+ });
5696
+ }
5697
+ validateWeight(field, label, weight) {
5698
+ if (weight === void 0) return;
5699
+ if (Number.isNaN(weight) || weight <= 0 || weight > EXAMPLES.limits.weightMax) {
5700
+ this.err(
5701
+ "example_weight_range",
5702
+ field,
5703
+ `example ${q(label)} has weight ${num(weight)}; use a number above 0 and at most 10`
5704
+ );
5705
+ }
5706
+ }
5707
+ // -- input ------------------------------------------------------------
5708
+ /**
5709
+ * Judge one inline input map (an example's `input`, or a variant's patched
5710
+ * input). NARROWED relative to the reference, which runs its full value
5711
+ * validator: here an unknown field, a missing required field, a value of the
5712
+ * wrong KIND and an enum value outside its list are judged; length, range,
5713
+ * pattern and date-format constraints are not (PARITY.md).
5714
+ */
5715
+ checkInput(field, label, raw, code) {
5716
+ const input = normalize(raw, 0) ?? {};
5717
+ const L = EXAMPLES.limits;
5718
+ const size = jsonBytes(input);
5719
+ if (size !== null && size > L.maxInlineInputBytes) {
5720
+ this.err(
5721
+ "example_input_too_large",
5722
+ field,
5723
+ `example ${q(label)} input is ${size} bytes; the limit is ${L.maxInlineInputBytes}. Put the large part behind an https file reference.`
5724
+ );
5725
+ return;
5726
+ }
5727
+ const schema = own2(this.flow, "input_schema");
5728
+ const query = own2(this.flow, "query");
5729
+ if (isRecord(schema)) {
5730
+ this.checkInputAgainstSchema(field, label, input, schema, code);
5731
+ } else if (isRecord(query) && Object.keys(query).length > 0) {
5732
+ const declared = sortedKeys(query);
5733
+ for (const k of sortedKeys(input)) {
5734
+ if (!Object.prototype.hasOwnProperty.call(query, k)) {
5735
+ this.err(
5736
+ code,
5737
+ `${field}.${k}`,
5738
+ `example ${q(label)}: ${q(k)} is not a declared input of this flow (declared: ${declared.join(", ")})`
5739
+ );
5740
+ }
5741
+ }
5742
+ } else {
5743
+ this.warn(
5744
+ "example_input_unvalidated",
5745
+ field,
5746
+ `example ${q(label)} cannot be checked: the flow declares no input_schema and no query parameters.`
5747
+ );
5748
+ }
5749
+ }
5750
+ checkInputAgainstSchema(field, label, input, schema, code) {
5751
+ const fields = this.schemaFields(schema);
5752
+ const byName = /* @__PURE__ */ new Map();
5753
+ for (const f of fields) byName.set(f.name, f);
5754
+ const runInput = {};
5755
+ for (const name of sortedKeys(input)) {
5756
+ const val = input[name];
5757
+ const f = byName.get(name);
5758
+ const present = val !== null && val !== void 0;
5759
+ if (f !== void 0 && f.type === TYPE_SECRET) {
5760
+ if (present) {
5761
+ this.err(
5762
+ "example_secret_value",
5763
+ `${field}.${name}`,
5764
+ `example ${q(label)} gives a value for ${q(name)}, which is a secret field. Examples are saved inside the flow and are never allowed to hold secrets; remove it. The person running the evaluation is asked for it at run time.`,
5765
+ SUGGESTION_SECRET_VALUE
5766
+ );
5767
+ }
5768
+ continue;
5769
+ }
5770
+ if (f !== void 0 && f.type === TYPE_FILE2 && present) {
5771
+ const ref = asFileRef(val);
5772
+ if (ref === null) {
5773
+ this.err(
5774
+ "example_file_input_needs_ref",
5775
+ `${field}.${name}`,
5776
+ `example ${q(label)}: field ${q(name)} is a file; give it as {url: "https://\u2026"}. A pasted upload id would stop working as soon as the session ends.`
5777
+ );
5778
+ continue;
5779
+ }
5780
+ this.validateFileRef(`${field}.${name}`, ref);
5781
+ setOwn(runInput, name, { [FILE_REF_KEY]: ref.url });
5782
+ continue;
5783
+ }
5784
+ setOwn(runInput, name, val);
5785
+ }
5786
+ for (const failure of this.judgeRun(fields, byName, runInput)) {
5787
+ if (failure.required) {
5788
+ const f = byName.get(failure.field);
5789
+ if (f !== void 0 && f.type === TYPE_SECRET) continue;
5790
+ }
5791
+ const at = failure.field !== "" ? `${field}.${failure.field}` : field;
5792
+ this.err(code, at, `example ${q(label)}: ${failure.message}`);
5793
+ }
5794
+ }
5795
+ schemaFields(schema) {
5796
+ const raw = own2(schema, "fields");
5797
+ if (!Array.isArray(raw)) return [];
5798
+ const out = [];
5799
+ raw.forEach((f, i) => {
5800
+ if (!isRecord(f)) return;
5801
+ const base = `input_schema.fields[${i}]`;
5802
+ const enumRaw = own2(f, "enum");
5803
+ const enumValues = [];
5804
+ if (Array.isArray(enumRaw)) {
5805
+ enumRaw.forEach((e, j) => {
5806
+ enumValues.push(e === null ? "" : this.issues.stringAt(e, `${base}.enum[${j}]`) ?? "");
5807
+ });
5808
+ }
5809
+ const vw = own2(f, "visible_when");
5810
+ out.push({
5811
+ name: this.s(f, "name", base),
5812
+ type: this.s(f, "type", base),
5813
+ required: own2(f, "required") === true,
5814
+ enumValues,
5815
+ visibleWhen: isRecord(vw) ? {
5816
+ field: this.s(vw, "field", `${base}.visible_when`),
5817
+ equals: own2(vw, "equals"),
5818
+ in: Array.isArray(own2(vw, "in")) ? own2(vw, "in") : []
5819
+ } : null
5820
+ });
5821
+ });
5822
+ return out;
5823
+ }
5824
+ /** The narrowed run-time judgement: required, kind, enum, unknown field. */
5825
+ judgeRun(fields, byName, runInput) {
5826
+ const failures = [];
5827
+ for (const f of fields) {
5828
+ if (!isVisible(f, runInput)) continue;
5829
+ const raw = own2(runInput, f.name);
5830
+ if (raw === void 0 || raw === null) {
5831
+ if (f.required) {
5832
+ failures.push({
5833
+ field: f.name,
5834
+ message: `input field ${q(f.name)} is required`,
5835
+ required: true
5836
+ });
5837
+ }
5838
+ continue;
5839
+ }
5840
+ failures.push(...inputValueFailures(f, raw));
5841
+ }
5842
+ for (const k of sortedKeys(runInput)) {
5843
+ if (!byName.has(k)) {
5844
+ failures.push({
5845
+ field: k,
5846
+ message: `input field ${q(k)} is not declared in input_schema`,
5847
+ required: false
5848
+ });
5849
+ }
5850
+ }
5851
+ return failures;
5852
+ }
5853
+ // -- file reference ---------------------------------------------------
5854
+ fileRefOf(rec, path) {
5855
+ return {
5856
+ url: this.s(rec, "url", path),
5857
+ sha256: this.s(rec, "sha256", path),
5858
+ mediaType: this.s(rec, "media_type", path),
5859
+ note: this.s(rec, "note", path)
5860
+ };
5861
+ }
5862
+ validateFileRef(field, ref) {
5863
+ const L = EXAMPLES.limits;
5864
+ const raw = ref.url;
5865
+ const invalid = "the file reference needs a url of at most 2048 characters";
5866
+ if (raw === "" || byteLen(raw) > L.maxUrlBytes) {
5867
+ this.err("example_ref_invalid", field, invalid);
5868
+ return;
5869
+ }
5870
+ const u = goParseURLParts(raw);
5871
+ if (u === null) {
5872
+ this.err("example_ref_invalid", field, invalid);
5873
+ return;
5874
+ }
5875
+ const scheme = u.scheme.toLowerCase();
5876
+ if (EXAMPLES.reservedRefSchemes.has(scheme)) {
5877
+ this.err(
5878
+ "example_ref_scheme_reserved",
5879
+ field,
5880
+ `${scheme}: references are not available yet. Use an https URL, or paste the text into the example.`
5881
+ );
5882
+ return;
5883
+ }
5884
+ if (scheme !== SCHEME_HTTPS) {
5885
+ this.err(
5886
+ "example_ref_scheme",
5887
+ field,
5888
+ `only https:// references are allowed (got ${q(scheme)})`
5889
+ );
5890
+ return;
5891
+ }
5892
+ if (u.hasUser || u.fragment !== "" || raw.includes("#") || u.host === "") {
5893
+ this.err("example_ref_invalid", field, "a reference must not carry a login or a fragment");
5894
+ return;
5895
+ }
5896
+ if (ref.sha256 !== "" && !EXAMPLES.sha256Pattern.test(ref.sha256)) {
5897
+ this.err(
5898
+ "example_ref_sha256_invalid",
5899
+ field,
5900
+ "sha256 must be 64 lowercase hexadecimal characters"
5901
+ );
5902
+ }
5903
+ if (ref.mediaType !== "" && !EXAMPLES.mediaTypePattern.test(ref.mediaType)) {
5904
+ this.err(
5905
+ "example_ref_media_type_invalid",
5906
+ field,
5907
+ `media_type ${q(ref.mediaType)} must look like type/subtype`
5908
+ );
5909
+ }
5910
+ const noteN = runeCount(ref.note);
5911
+ if (noteN > L.maxNoteRunes) {
5912
+ this.err(
5913
+ "example_ref_invalid",
5914
+ field,
5915
+ `the note is ${noteN} characters; the limit is ${L.maxNoteRunes}`
5916
+ );
5917
+ }
5918
+ if (ref.sha256 === "") {
5919
+ this.warn(
5920
+ "example_ref_unpinned",
5921
+ field,
5922
+ "this reference is not pinned. If the file at that address changes, your scores change with it. Add sha256 to freeze it."
5923
+ );
5924
+ }
5925
+ for (const key of goQueryKeys(u.rawQuery)) {
5926
+ if (EXAMPLES.signedUrlQueryKeyPattern.test(key)) {
5927
+ this.warn(
5928
+ "example_ref_signed_url",
5929
+ field,
5930
+ "this address looks like a signed link. Anyone who can read the flow can use it until it expires, and it will stop working. Prefer a stable public address."
5931
+ );
5932
+ break;
5933
+ }
5934
+ }
5935
+ }
5936
+ // -- expectation ------------------------------------------------------
5937
+ /** The names `fields` / `exact` may use, and whether such a list is declared at all. */
5938
+ outputNamesFor(kind, stepId) {
5939
+ if (kind === "final") {
5940
+ const out = own2(this.flow, "output");
5941
+ const names2 = [];
5942
+ if (Array.isArray(out)) {
5943
+ out.forEach((item, i) => {
5944
+ names2.push(item === null ? "" : this.issues.stringAt(item, `output[${i}]`) ?? "");
5945
+ });
5946
+ }
5947
+ return { names: names2, declared: names2.length > 0 };
5948
+ }
5949
+ const steps = own2(this.flow, "steps");
5950
+ const step = isRecord(steps) ? own2(steps, stepId) : void 0;
5951
+ const schema = isRecord(step) ? own2(step, "output_schema") : void 0;
5952
+ const fields = isRecord(schema) ? own2(schema, "fields") : void 0;
5953
+ if (!Array.isArray(fields) || fields.length === 0) return { names: [], declared: false };
5954
+ const names = [];
5955
+ fields.forEach((f, i) => {
5956
+ if (isRecord(f)) names.push(this.s(f, "name", `steps.${stepId}.output_schema.fields[${i}]`));
5957
+ });
5958
+ return { names, declared: true };
5959
+ }
5960
+ validateExpectation(path, label, e, kind, stepId) {
5961
+ const L = EXAMPLES.limits;
5962
+ const status = this.s(e, "status", path);
5963
+ if (status !== "" && !EXAMPLES.statuses.has(status)) {
5964
+ this.err(
5965
+ "example_status_invalid",
5966
+ `${path}.status`,
5967
+ "status must be completed, failed or paused_for_human"
5968
+ );
5969
+ }
5970
+ const noOutput = status === STATUS_FAILED || status === STATUS_PAUSED_FOR_HUMAN;
5971
+ const fieldsRec = own2(e, "fields");
5972
+ const exactRec = own2(e, "exact");
5973
+ const fieldKeys = isRecord(fieldsRec) ? sortedKeys(fieldsRec) : [];
5974
+ const exactKeys = isRecord(exactRec) ? sortedKeys(exactRec) : [];
5975
+ const hasFields = fieldKeys.length > 0;
5976
+ const hasExact = exactKeys.length > 0;
5977
+ if (hasFields && hasExact) {
5978
+ this.err(
5979
+ "example_expected_conflict",
5980
+ path,
5981
+ "use fields (some fields) or exact (the whole result), not both"
5982
+ );
5983
+ } else if (noOutput && (hasFields || hasExact)) {
5984
+ this.err(
5985
+ "example_expected_conflict",
5986
+ path,
5987
+ `a case that ends in ${status} has no output to match; remove fields and exact, or expect status completed`
5988
+ );
5989
+ }
5990
+ const minScore = numberOf(own2(e, "min_score"));
5991
+ if (minScore !== void 0 && !scoreInRange(minScore)) {
5992
+ this.err(
5993
+ "example_min_score_range",
5994
+ `${path}.min_score`,
5995
+ `min_score ${num(minScore)} is out of range; use a number from 0 to 1`
5996
+ );
5997
+ }
5998
+ const rubric = this.s(e, "rubric", path);
5999
+ if (rubric !== "") {
6000
+ if (goTrimSpace(rubric) === "") {
6001
+ this.err(
6002
+ "example_rubric_empty",
6003
+ `${path}.rubric`,
6004
+ "the rubric is empty; write what a good result looks like, or remove it"
6005
+ );
6006
+ } else {
6007
+ const n = runeCount(rubric);
6008
+ if (n > L.maxRubricRunes) {
6009
+ this.err(
6010
+ "example_rubric_too_long",
6011
+ `${path}.rubric`,
6012
+ `the rubric is ${n} characters; the limit is ${L.maxRubricRunes}`
6013
+ );
6014
+ }
6015
+ }
6016
+ }
6017
+ const reference = own2(e, "reference");
6018
+ if (isRecord(reference)) this.validateReference(`${path}.reference`, reference);
6019
+ const { names, declared } = this.outputNamesFor(kind, stepId);
6020
+ const checkKey = (field, key) => {
6021
+ if (!declared && kind === "final") {
6022
+ this.warn(
6023
+ "example_expected_field_unchecked",
6024
+ field,
6025
+ `this flow declares no output list, so ${q(key)} cannot be checked against it`
6026
+ );
6027
+ } else if (!declared) {
6028
+ this.warn(
6029
+ "example_expected_field_unchecked",
6030
+ field,
6031
+ `this step declares no output_schema, so ${q(key)} cannot be checked against it`
6032
+ );
6033
+ } else if (!names.includes(key)) {
6034
+ this.err(
6035
+ "example_expected_field_unknown",
6036
+ field,
6037
+ kind === "checkpoint" ? `${q(key)} is not a field this step declares in its output_schema (declared: ${names.join(", ")})` : `${q(key)} is not an output of this flow (outputs: ${names.join(", ")})`
6038
+ );
6039
+ }
6040
+ };
6041
+ for (const key of fieldKeys) {
6042
+ const fpath = `${path}.fields.${key}`;
6043
+ checkKey(fpath, key);
6044
+ const matcher = own2(fieldsRec, key);
6045
+ if (isRecord(matcher)) this.validateFieldMatcher(fpath, matcher);
6046
+ }
6047
+ for (const key of exactKeys) checkKey(`${path}.exact.${key}`, key);
6048
+ const mustNot = this.stringList(own2(e, "must_not"), `${path}.must_not`);
6049
+ const mustNotContain = this.stringList(own2(e, "must_not_contain"), `${path}.must_not_contain`);
6050
+ const mustNotMsg = `must_not takes up to ${L.maxMustNot} statements of at most ${L.maxMustNotRunes} characters each, none empty`;
6051
+ if (mustNot.length > L.maxMustNot) {
6052
+ this.err("example_must_not_invalid", `${path}.must_not`, mustNotMsg);
6053
+ }
6054
+ mustNot.forEach((item, j) => {
6055
+ if (goTrimSpace(item) === "" || runeCount(item) > L.maxMustNotRunes) {
6056
+ this.err("example_must_not_invalid", `${path}.must_not[${j}]`, mustNotMsg);
6057
+ }
6058
+ });
6059
+ const mncMsg = `must_not_contain takes up to ${L.maxMustNotContain} literals of 1 to ${L.maxMustNotContainLength} characters each`;
6060
+ if (mustNotContain.length > L.maxMustNotContain) {
6061
+ this.err("example_must_not_contain_invalid", `${path}.must_not_contain`, mncMsg);
6062
+ }
6063
+ mustNotContain.forEach((item, j) => {
6064
+ const n = runeCount(item);
6065
+ if (n === 0 || n > L.maxMustNotContainLength) {
6066
+ this.err("example_must_not_contain_invalid", `${path}.must_not_contain[${j}]`, mncMsg);
6067
+ }
6068
+ });
6069
+ for (const key of fieldKeys) {
6070
+ const matcher = own2(fieldsRec, key);
6071
+ if (!isRecord(matcher)) continue;
6072
+ const eq = own2(matcher, "equals");
6073
+ if (typeof eq !== "string" || eq === "") continue;
6074
+ for (const banned of mustNotContain) {
6075
+ if (banned !== "" && equalFold(banned, eq)) {
6076
+ this.warn(
6077
+ "example_expectation_contradiction",
6078
+ `${path}.fields.${key}`,
6079
+ `${q(banned)} is required by ${q(key)} and forbidden by must_not_contain`
6080
+ );
6081
+ }
6082
+ }
6083
+ }
6084
+ if (kind === "checkpoint" && status !== "") {
6085
+ this.err(
6086
+ "example_checkpoint_status",
6087
+ `${path}.status`,
6088
+ `example ${q(label)}: a checkpoint cannot set status; status describes how the whole run ends`
6089
+ );
6090
+ }
6091
+ if (rubric === "" && !has(e, "reference") && !hasFields && !hasExact && mustNot.length === 0 && mustNotContain.length === 0 && (status === "" || status === STATUS_COMPLETED)) {
6092
+ this.err(
6093
+ "example_expected_empty",
6094
+ path,
6095
+ "this expectation checks nothing; add a rubric, fields, exact, reference, must_not or must_not_contain",
6096
+ SUGGESTION_EXPECTED
6097
+ );
6098
+ }
6099
+ }
6100
+ /** A Go `[]string` read: scalars by their text, null as "", anything else dropped. */
6101
+ stringList(v, path) {
6102
+ if (!Array.isArray(v)) return [];
6103
+ const out = [];
6104
+ v.forEach((item, j) => {
6105
+ if (item === null) out.push("");
6106
+ else {
6107
+ const t = this.issues.stringAt(item, `${path}[${j}]`);
6108
+ if (t !== null) out.push(t);
6109
+ }
6110
+ });
6111
+ return out;
6112
+ }
6113
+ validateReference(path, r) {
6114
+ const text = this.s(r, "text", path);
6115
+ const hasText = text !== "";
6116
+ const hasRef = has(r, "ref");
6117
+ if (hasText === hasRef) {
6118
+ this.err("example_reference_invalid", path, "a reference needs exactly one of text or ref");
6119
+ return;
6120
+ }
6121
+ if (hasText) {
6122
+ const n = byteLen(text);
6123
+ if (n > EXAMPLES.limits.maxReferenceTextBytes) {
6124
+ this.err(
6125
+ "example_reference_invalid",
6126
+ path,
6127
+ `the reference text is ${n} bytes; the limit is ${EXAMPLES.limits.maxReferenceTextBytes}. Put it behind an https file reference.`
6128
+ );
6129
+ }
6130
+ return;
6131
+ }
6132
+ const refRec = own2(r, "ref");
6133
+ if (!isRecord(refRec)) return;
6134
+ const ref = this.fileRefOf(refRec, `${path}.ref`);
6135
+ this.validateFileRef(`${path}.ref`, ref);
6136
+ if (ref.mediaType !== "" && !isTextualMediaType(ref.mediaType)) {
6137
+ this.warn(
6138
+ "example_reference_binary",
6139
+ path,
6140
+ "this reference is not text, so it cannot be compared in this version; the example will be skipped, not failed."
6141
+ );
6142
+ }
6143
+ }
6144
+ expectationIsBinaryReferenceOnly(e, path) {
6145
+ const reference = own2(e, "reference");
6146
+ const refRec = isRecord(reference) ? own2(reference, "ref") : void 0;
6147
+ if (!isRecord(refRec)) return false;
6148
+ const mediaType = this.s(refRec, "media_type", `${path}.reference.ref`);
6149
+ if (mediaType === "" || isTextualMediaType(mediaType)) return false;
6150
+ const status = this.s(e, "status", path);
6151
+ const fields = own2(e, "fields");
6152
+ const exact = own2(e, "exact");
6153
+ return this.s(e, "rubric", path) === "" && !(isRecord(fields) && Object.keys(fields).length > 0) && !(isRecord(exact) && Object.keys(exact).length > 0) && this.stringList(own2(e, "must_not"), `${path}.must_not`).length === 0 && this.stringList(own2(e, "must_not_contain"), `${path}.must_not_contain`).length === 0 && (status === "" || status === STATUS_COMPLETED);
6154
+ }
6155
+ validateFieldMatcher(path, m) {
6156
+ const L = EXAMPLES.limits;
6157
+ const matches = this.s(m, "matches", path);
6158
+ const oneOf = own2(m, "one_of");
6159
+ const approx = numberOf(own2(m, "approx"));
6160
+ const tolerance = numberOf(own2(m, "tolerance"));
6161
+ let operators = 0;
6162
+ if (has(m, "equals")) operators++;
6163
+ if (this.s(m, "contains", path) !== "") operators++;
6164
+ if (this.s(m, "not_contains", path) !== "") operators++;
6165
+ if (matches !== "") operators++;
6166
+ if (Array.isArray(oneOf) && oneOf.length > 0) operators++;
6167
+ if (approx !== void 0) operators++;
6168
+ if (typeof own2(m, "present") === "boolean") operators++;
6169
+ if (operators !== 1) {
6170
+ this.err(
6171
+ "example_field_matcher_invalid",
6172
+ path,
6173
+ "write exactly one of equals, contains, not_contains, matches, one_of, approx, present"
6174
+ );
6175
+ return;
6176
+ }
6177
+ if (matches !== "" && byteLen(matches) > L.maxPatternLength) {
6178
+ this.err(
6179
+ "example_field_matcher_invalid",
6180
+ path,
6181
+ `the pattern in matches must be a valid regular expression of at most ${L.maxPatternLength} characters`
6182
+ );
6183
+ }
6184
+ if (approx !== void 0 !== (tolerance !== void 0) || tolerance !== void 0 && (Number.isNaN(tolerance) || tolerance < 0)) {
6185
+ this.err(
6186
+ "example_field_matcher_invalid",
6187
+ path,
6188
+ "approx needs a tolerance (a number, zero or more) beside it, and tolerance is only for approx"
6189
+ );
6190
+ }
6191
+ }
6192
+ // -- checkpoints ------------------------------------------------------
6193
+ validateCheckpoints(path, label, cps) {
6194
+ if (!isRecord(cps) || Object.keys(cps).length === 0) return;
6195
+ const stepsRaw = own2(this.flow, "steps");
6196
+ const steps = isRecord(stepsRaw) ? stepsRaw : {};
6197
+ const stepIds = sortedKeys(steps);
6198
+ for (const id of sortedKeys(cps)) {
6199
+ const cpath = `${path}.checkpoints.${id}`;
6200
+ const step = own2(steps, id);
6201
+ if (!isRecord(step)) {
6202
+ this.err(
6203
+ "example_checkpoint_step_unknown",
6204
+ cpath,
6205
+ `example ${q(label)}: checkpoint ${q(id)} is not a step of this flow (steps: ${stepIds.join(", ")})`,
6206
+ SUGGESTION_CHECKPOINT
6207
+ );
6208
+ continue;
6209
+ }
6210
+ const next = own2(step, "next");
6211
+ if (has(step, "for_each") || has(step, "loop") || isRecord(next) && has(next, "parallel")) {
6212
+ this.err(
6213
+ "example_checkpoint_step_composite",
6214
+ cpath,
6215
+ `example ${q(label)}: step ${q(id)} repeats or branches, so there is no single result to check; put the checkpoint on a plain step or check the final output`
6216
+ );
6217
+ continue;
6218
+ }
6219
+ const cp = own2(cps, id);
6220
+ if (cp === null || cp === void 0) {
6221
+ this.validateExpectation(cpath, label, {}, "checkpoint", id);
6222
+ } else if (isRecord(cp)) {
6223
+ this.validateExpectation(cpath, label, cp, "checkpoint", id);
6224
+ }
6225
+ }
6226
+ }
6227
+ // -- variants ---------------------------------------------------------
6228
+ validateVariants(i, path, label, ex, hasInput, baseInput) {
6229
+ const L = EXAMPLES.limits;
6230
+ const variants = own2(ex, "variants");
6231
+ if (!Array.isArray(variants) || variants.length === 0) return;
6232
+ if (variants.length > L.maxVariants) {
6233
+ this.err(
6234
+ "example_variants_too_many",
6235
+ `${path}.variants`,
6236
+ `example ${q(label)} has ${variants.length} variants; the limit is ${L.maxVariants}`
6237
+ );
6238
+ }
6239
+ const seen = /* @__PURE__ */ new Set();
6240
+ variants.forEach((v, j) => {
6241
+ if (!isRecord(v)) return;
6242
+ const vpath = `examples[${i}].variants[${j}]`;
6243
+ const vid = this.s(v, "id", vpath);
6244
+ const vlabel = vid === "" ? `#${j + 1}` : vid;
6245
+ const both = `${label}/${vlabel}`;
6246
+ if (!EXAMPLES.idPattern.test(vid)) {
6247
+ this.err(
6248
+ "example_variant_id_invalid",
6249
+ `${vpath}.id`,
6250
+ `variant id ${q(vid)} of example ${q(label)} is not valid: use lower-case letters, digits and underscores, starting with a letter (2 to 48 characters)`,
6251
+ SUGGESTION_ID
6252
+ );
6253
+ } else if (seen.has(vid)) {
6254
+ this.err(
6255
+ "example_variant_id_duplicate",
6256
+ `${vpath}.id`,
6257
+ `variant id ${q(vid)} is used twice in example ${q(label)}`
6258
+ );
6259
+ }
6260
+ seen.add(vid);
6261
+ const origin = this.s(v, "origin", vpath);
6262
+ if (origin === ORIGIN_NONE || !EXAMPLES.origins.has(origin)) {
6263
+ this.err(
6264
+ "example_variant_origin_invalid",
6265
+ `${vpath}.origin`,
6266
+ `variant ${q(vlabel)} of example ${q(label)} has origin ${q(origin)}; use author (a person wrote or approved it) or synthetic (generated)`
6267
+ );
6268
+ }
6269
+ const vtitleN = runeCount(this.s(v, "title", vpath));
6270
+ if (vtitleN > L.titleMaxRunes) {
6271
+ this.err(
6272
+ "example_title_too_long",
6273
+ `${vpath}.title`,
6274
+ `example ${q(both)} title is ${vtitleN} characters; the limit is ${L.titleMaxRunes}`
6275
+ );
6276
+ }
6277
+ const vguidanceN = runeCount(this.s(v, "guidance", vpath));
6278
+ if (vguidanceN > L.maxGuidanceRunes) {
6279
+ this.err(
6280
+ "example_guidance_too_long",
6281
+ `${vpath}.guidance`,
6282
+ `example ${q(both)} guidance is ${vguidanceN} characters; the limit is ${L.maxGuidanceRunes}`
6283
+ );
6284
+ }
6285
+ const provN = runeCount(this.s(v, "provenance", vpath));
6286
+ if (provN > L.maxProvenanceRunes) {
6287
+ this.err(
6288
+ "example_notes_too_long",
6289
+ `${vpath}.provenance`,
6290
+ `example ${q(both)} notes are ${provN} characters; the limit is ${L.maxProvenanceRunes}`
6291
+ );
6292
+ }
6293
+ this.validateWeight(`${vpath}.weight`, both, numberOf(own2(v, "weight")));
6294
+ const patch = own2(v, "input_patch");
6295
+ const patchRec = isRecord(patch) ? patch : null;
6296
+ const hasPatch = patchRec !== null && Object.keys(patchRec).length > 0;
6297
+ const hasRef = has(v, "input_ref");
6298
+ if (hasPatch && hasRef) {
6299
+ this.err(
6300
+ "example_variant_input_conflict",
6301
+ vpath,
6302
+ `variant ${q(vlabel)} of example ${q(label)} sets both input_patch and input_ref; use one`
6303
+ );
6304
+ } else if (!hasPatch && !hasRef && !has(v, "expected")) {
6305
+ this.err(
6306
+ "example_variant_empty",
6307
+ vpath,
6308
+ `variant ${q(vlabel)} of example ${q(label)} changes neither the input nor the expectation`
6309
+ );
6310
+ }
6311
+ const refRec = own2(v, "input_ref");
6312
+ if (isRecord(refRec)) {
6313
+ this.validateFileRef(`${vpath}.input_ref`, this.fileRefOf(refRec, `${vpath}.input_ref`));
6314
+ }
6315
+ if (hasPatch && patchRec !== null) {
6316
+ if (!hasInput) {
6317
+ this.warn(
6318
+ "example_variant_unchecked",
6319
+ `${vpath}.input_patch`,
6320
+ `variant ${q(vlabel)} of example ${q(label)} cannot be checked: its parent takes its input from input_ref.`
6321
+ );
6322
+ } else if (baseInput !== null) {
6323
+ this.checkVariantPatch(vpath, label, vlabel, baseInput, patchRec);
6324
+ }
6325
+ }
6326
+ const expected = own2(v, "expected");
6327
+ if (isRecord(expected)) {
6328
+ this.validateExpectation(`${vpath}.expected`, both, expected, "final", "");
6329
+ }
6330
+ });
6331
+ }
6332
+ /**
6333
+ * Judge the PATCHED input like a live run, and report a secret the patch
6334
+ * itself supplies. A null patch value deleting a secret is fine.
6335
+ */
6336
+ checkVariantPatch(vpath, label, vlabel, base, patch) {
6337
+ const schema = own2(this.flow, "input_schema");
6338
+ if (isRecord(schema)) {
6339
+ for (const f of this.schemaFields(schema)) {
6340
+ if (f.type !== TYPE_SECRET) continue;
6341
+ const val = own2(patch, f.name);
6342
+ if (val !== void 0 && val !== null) {
6343
+ this.err(
6344
+ "example_secret_value",
6345
+ `${vpath}.input_patch.${f.name}`,
6346
+ `example ${q(`${label}/${vlabel}`)} gives a value for ${q(f.name)}, which is a secret field. Examples are saved inside the flow and are never allowed to hold secrets; remove it. The person running the evaluation is asked for it at run time.`,
6347
+ SUGGESTION_SECRET_VALUE
6348
+ );
6349
+ }
6350
+ }
6351
+ }
6352
+ const patched = applyExamplePatch(base, patch);
6353
+ const scratch = new _Walker(this.flow, this.issues);
6354
+ scratch.checkInput(
6355
+ `${vpath}.input_patch`,
6356
+ `${label}/${vlabel}`,
6357
+ patched,
6358
+ "example_variant_input_invalid"
6359
+ );
6360
+ for (const f of scratch.findings) {
6361
+ if (f.code === "example_secret_value") continue;
6362
+ this.findings.push(f);
6363
+ }
6364
+ }
6365
+ // -- credential-shaped literals ----------------------------------------
6366
+ scanSecretLike(i, path, ex) {
6367
+ const emit = (field, s) => {
6368
+ const name = secretMatch(s);
6369
+ if (name !== "") {
6370
+ this.err(
6371
+ "example_secret_like_value",
6372
+ field,
6373
+ `${field} looks like a credential (${name}). Examples are saved in the flow definition and must never contain keys or tokens. Replace it with a made-up value.`,
6374
+ SUGGESTION_SECRET_VALUE
6375
+ );
6376
+ }
6377
+ };
6378
+ emit(`${path}.title`, this.s(ex, "title", path));
6379
+ emit(`${path}.guidance`, this.s(ex, "guidance", path));
6380
+ emit(`${path}.notes`, this.s(ex, "notes", path));
6381
+ const input = own2(ex, "input");
6382
+ if (isRecord(input)) scanLeaves(`${path}.input`, input, 0, emit);
6383
+ const expected = own2(ex, "expected");
6384
+ if (isRecord(expected)) this.scanExpectationLeaves(`${path}.expected`, expected, emit);
6385
+ const cps = own2(ex, "checkpoints");
6386
+ if (isRecord(cps)) {
6387
+ for (const id of sortedKeys(cps)) {
6388
+ const cp = own2(cps, id);
6389
+ if (isRecord(cp)) this.scanExpectationLeaves(`${path}.checkpoints.${id}`, cp, emit);
6390
+ }
6391
+ }
6392
+ const variants = own2(ex, "variants");
6393
+ if (Array.isArray(variants)) {
6394
+ variants.forEach((v, j) => {
6395
+ if (!isRecord(v)) return;
6396
+ const vpath = `examples[${i}].variants[${j}]`;
6397
+ emit(`${vpath}.title`, this.s(v, "title", vpath));
6398
+ emit(`${vpath}.guidance`, this.s(v, "guidance", vpath));
6399
+ emit(`${vpath}.provenance`, this.s(v, "provenance", vpath));
6400
+ scanLeaves(`${vpath}.input_patch`, own2(v, "input_patch"), 0, emit);
6401
+ const vexp = own2(v, "expected");
6402
+ if (isRecord(vexp)) this.scanExpectationLeaves(`${vpath}.expected`, vexp, emit);
6403
+ });
6404
+ }
6405
+ }
6406
+ scanExpectationLeaves(path, e, emit) {
6407
+ emit(`${path}.rubric`, this.s(e, "rubric", path));
6408
+ const reference = own2(e, "reference");
6409
+ if (isRecord(reference)) {
6410
+ emit(`${path}.reference.text`, this.s(reference, "text", `${path}.reference`));
6411
+ }
6412
+ this.stringList(own2(e, "must_not"), `${path}.must_not`).forEach(
6413
+ (s, j) => emit(`${path}.must_not[${j}]`, s)
6414
+ );
6415
+ this.stringList(own2(e, "must_not_contain"), `${path}.must_not_contain`).forEach(
6416
+ (s, j) => emit(`${path}.must_not_contain[${j}]`, s)
6417
+ );
6418
+ const fields = own2(e, "fields");
6419
+ if (isRecord(fields)) {
6420
+ for (const key of sortedKeys(fields)) {
6421
+ const m = own2(fields, key);
6422
+ if (!isRecord(m)) continue;
6423
+ const fpath = `${path}.fields.${key}`;
6424
+ scanLeaves(`${fpath}.equals`, own2(m, "equals"), 0, emit);
6425
+ emit(`${fpath}.contains`, this.s(m, "contains", fpath));
6426
+ emit(`${fpath}.not_contains`, this.s(m, "not_contains", fpath));
6427
+ const oneOf = own2(m, "one_of");
6428
+ if (Array.isArray(oneOf)) {
6429
+ oneOf.forEach(
6430
+ (one, j) => scanLeaves(`${fpath}.one_of[${j}]`, one, 0, emit)
6431
+ );
6432
+ }
6433
+ }
6434
+ }
6435
+ scanLeaves(`${path}.exact`, own2(e, "exact"), 0, emit);
6436
+ }
6437
+ };
6438
+ function scoreInRange(v) {
6439
+ return !Number.isNaN(v) && v >= EXAMPLES.limits.minScoreMin && v <= EXAMPLES.limits.minScoreMax;
6440
+ }
6441
+ function equalFold(a, b) {
6442
+ const ca = [...a];
6443
+ const cb = [...b];
6444
+ if (ca.length !== cb.length) return false;
6445
+ return ca.every((c, i) => {
6446
+ const d = cb[i];
6447
+ return c === d || c.toLowerCase() === d.toLowerCase() || c.toUpperCase() === d.toUpperCase();
6448
+ });
6449
+ }
6450
+ function secretMatch(s) {
6451
+ for (const p of EXAMPLES.secretPatterns) {
6452
+ if (p.re.test(s)) return p.name;
6453
+ }
6454
+ return "";
6455
+ }
6456
+ function scanLeaves(path, v, depth, emit) {
6457
+ if (depth > MAX_RECURSION_DEPTH) return;
6458
+ if (isRecord(v)) {
6459
+ for (const k of sortedKeys(v)) scanLeaves(`${path}.${k}`, v[k], depth + 1, emit);
6460
+ return;
6461
+ }
6462
+ if (typeof v === "string") emit(path, v);
6463
+ else if (Array.isArray(v)) {
6464
+ v.forEach((item, i) => scanLeaves(`${path}[${i}]`, item, depth + 1, emit));
6465
+ }
6466
+ }
6467
+ function jsonBytes(v) {
6468
+ try {
6469
+ const text = JSON.stringify(v);
6470
+ return text === void 0 ? null : byteLen(text);
6471
+ } catch {
6472
+ return null;
6473
+ }
6474
+ }
6475
+ function blockBytes(examples) {
6476
+ try {
6477
+ const text = JSON.stringify(normalize(examples, 0), function(_k, v) {
6478
+ if (Array.isArray(this)) return v;
6479
+ if (v === null || v === "" || v === false) return void 0;
6480
+ if (Array.isArray(v) && v.length === 0) return void 0;
6481
+ return v;
6482
+ });
6483
+ return text === void 0 ? null : byteLen(text);
6484
+ } catch {
6485
+ return null;
6486
+ }
6487
+ }
6488
+ function isVisible(f, input) {
6489
+ const vw = f.visibleWhen;
6490
+ if (vw === null) return true;
6491
+ if (!Object.prototype.hasOwnProperty.call(input, vw.field)) return false;
6492
+ const dep = input[vw.field];
6493
+ if (vw.equals !== void 0 && vw.equals !== null) return valuesEqual(dep, vw.equals);
6494
+ return vw.in.some((candidate) => valuesEqual(dep, candidate));
6495
+ }
6496
+ function valuesEqual(a, b) {
6497
+ const aNil = a === null || a === void 0;
6498
+ const bNil = b === null || b === void 0;
6499
+ if (aNil || bNil) return aNil && bNil;
6500
+ if (typeof a === "number") return typeof b === "number" && a === b;
6501
+ if (typeof a === "boolean") return typeof b === "boolean" && a === b;
6502
+ if (typeof a === "string") return typeof b === "string" && a === b;
6503
+ return false;
6504
+ }
6505
+ function mismatch(f, expected) {
6506
+ return {
6507
+ field: f.name,
6508
+ message: `input field ${q(f.name)} is not a valid ${expected}`,
6509
+ required: false
6510
+ };
6511
+ }
6512
+ function inputValueFailures(f, raw) {
6513
+ switch (f.type) {
6514
+ case TYPE_STRING:
6515
+ case TYPE_MULTILINE:
6516
+ case TYPE_SECRET:
6517
+ return typeof raw === "string" ? [] : [mismatch(f, TYPE_STRING)];
6518
+ case TYPE_NUMBER2:
6519
+ return typeof raw === "number" ? [] : [mismatch(f, TYPE_NUMBER2)];
6520
+ case TYPE_BOOL:
6521
+ return typeof raw === "boolean" ? [] : [mismatch(f, TYPE_BOOL)];
6522
+ case TYPE_ENUM2:
6523
+ if (typeof raw !== "string") return [mismatch(f, TYPE_ENUM2)];
6524
+ if (f.enumValues.includes(raw)) return [];
6525
+ return [
6526
+ {
6527
+ field: f.name,
6528
+ message: `input field ${q(f.name)} value ${q(raw)} is not one of [${f.enumValues.join(",")}]`,
6529
+ required: false
6530
+ }
6531
+ ];
6532
+ case TYPE_ARRAY_OF_STRINGS2: {
6533
+ if (!Array.isArray(raw)) return [mismatch(f, TYPE_ARRAY_OF_STRINGS2)];
6534
+ const out = [];
6535
+ raw.forEach((item, i) => {
6536
+ if (typeof item !== "string") {
6537
+ out.push({
6538
+ field: f.name,
6539
+ message: `input field ${q(f.name)} index ${i} is not a string`,
6540
+ required: false
6541
+ });
6542
+ }
6543
+ });
6544
+ return out;
6545
+ }
6546
+ case TYPE_DATE:
6547
+ return typeof raw === "string" ? [] : [mismatch(f, TYPE_DATE)];
6548
+ case TYPE_FILE2: {
6549
+ if (typeof raw === "string") return raw === "" ? [mismatch(f, TYPE_FILE2)] : [];
6550
+ if (isRecord(raw)) {
6551
+ const ref = own2(raw, FILE_REF_KEY);
6552
+ return typeof ref === "string" && ref !== "" ? [] : [mismatch(f, TYPE_FILE2)];
6553
+ }
6554
+ return [mismatch(f, TYPE_FILE2)];
6555
+ }
6556
+ default:
6557
+ return [];
6558
+ }
6559
+ }
6560
+ function validateExamples(flow, issues) {
6561
+ const examples = flow[KEY_EXAMPLES];
6562
+ if (!Array.isArray(examples) || examples.length === 0) return;
6563
+ const walker = new Walker(flow, issues);
6564
+ walker.run(examples);
6565
+ for (const f of walker.findings) {
6566
+ const issue = {
6567
+ field: f.field,
6568
+ message: f.message,
6569
+ code: f.code,
6570
+ ...f.suggestion !== void 0 ? { suggestion: f.suggestion } : {}
6571
+ };
6572
+ if (f.severity === "error") issues.error(issue);
6573
+ else issues.warn(issue);
6574
+ }
6575
+ }
6576
+
5088
6577
  // src/index.ts
5089
6578
  function countStepsWithErrors(errors) {
5090
6579
  const ids = /* @__PURE__ */ new Set();
@@ -5137,6 +6626,7 @@ function validateParsed(flow, opts, sources) {
5137
6626
  validateExecutorConfigEnvScopes(f, issues);
5138
6627
  validateServerOwnedQueryKeys(f, issues);
5139
6628
  validateCredentialEndpointPairing(f, issues);
6629
+ validateExamples(f, issues);
5140
6630
  validateOrchestratorExons(f, issues);
5141
6631
  validateUnknownKeys(f, issues);
5142
6632
  const templateStats = validateTemplates(f, issues, opts);