@tsantosfp_2026/piece-coach-migration-ai 1.1.1 → 2.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +599 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsantosfp_2026/piece-coach-migration-ai",
3
- "version": "1.1.1",
3
+ "version": "2.1.0",
4
4
  "main": "./src/index.js",
5
5
  "dependencies": {},
6
6
  "files": [
package/src/index.js CHANGED
@@ -52772,7 +52772,7 @@ var require_output_schemas = __commonJS({
52772
52772
  "dist/src/lib/output-schemas.js"(exports2) {
52773
52773
  "use strict";
52774
52774
  Object.defineProperty(exports2, "__esModule", { value: true });
52775
- exports2.transformNarrativeJobOutputSchema = exports2.extractPreAiPackageOutputSchema = void 0;
52775
+ exports2.transformHomeNarrativeOutputSchema = exports2.transformNarrativeJobOutputSchema = exports2.extractPreAiPackageOutputSchema = void 0;
52776
52776
  var evidenceFields = [
52777
52777
  { key: "evidence_reference", label: "Evidence Reference" },
52778
52778
  { key: "canonical_field", label: "Canonical Field" },
@@ -52843,6 +52843,337 @@ var require_output_schemas = __commonJS({
52843
52843
  { key: "errors", label: "Errors", listItems: [] }
52844
52844
  ]
52845
52845
  };
52846
+ exports2.transformHomeNarrativeOutputSchema = {
52847
+ fields: [
52848
+ { key: "contract", label: "Generation Result Contract" },
52849
+ { key: "candidate", label: "Validated Home Candidate", children: [
52850
+ { key: "candidate_digest", label: "Candidate Digest" },
52851
+ { key: "request_digest", label: "Request Digest" },
52852
+ { key: "output_digest", label: "Output Digest" },
52853
+ { key: "outputs", label: "Exactly Two Home Outputs", dynamicKey: true },
52854
+ { key: "provenance", label: "Bound Home Provenance", listItems: [
52855
+ { key: "canonical_field", label: "Canonical Field" },
52856
+ { key: "template_element_id", label: "Template Element ID" },
52857
+ { key: "verified_context_refs", label: "Verified Context References", listItems: [] }
52858
+ ] },
52859
+ { key: "no_new_facts_attestation", label: "No New Facts Attestation", format: "boolean" }
52860
+ ] },
52861
+ { key: "checkpoint", label: "Needs Review Checkpoint", children: [
52862
+ { key: "checkpoint_kind", label: "Checkpoint Kind" },
52863
+ { key: "review_state", label: "Review State" },
52864
+ { key: "review_binding_digest", label: "Review Binding Digest" },
52865
+ { key: "staged_outputs", label: "Staged Home Outputs", dynamicKey: true },
52866
+ { key: "staging_columns", label: "Existing Monday Columns", dynamicKey: true }
52867
+ ] }
52868
+ ]
52869
+ };
52870
+ }
52871
+ });
52872
+
52873
+ // dist/src/lib/source-policy.generated.js
52874
+ var require_source_policy_generated = __commonJS({
52875
+ "dist/src/lib/source-policy.generated.js"(exports2) {
52876
+ "use strict";
52877
+ Object.defineProperty(exports2, "__esModule", { value: true });
52878
+ exports2.SOURCE_EVIDENCE_POLICY = exports2.SOURCE_POLICY_AUTHORITY = void 0;
52879
+ exports2.SOURCE_POLICY_AUTHORITY = {
52880
+ contractId: "OPENCODE_AI_ENRICHMENT_V1_2",
52881
+ contractVersion: "1.2.0",
52882
+ sha256: "b0529ae1d72659e5b1d211d9d7ac500550e9cf65aca971dd0cc1f3df6acbd15b",
52883
+ producerRelevanceSha256: "200d2b9b876bd6d00806e9161b2d2a7cdbf976441b56ab0c5047337fff7a15cc"
52884
+ };
52885
+ exports2.SOURCE_EVIDENCE_POLICY = {
52886
+ "ABOUT_V1": {
52887
+ "groundingFieldAllowlist": [
52888
+ "about.hero.heading",
52889
+ "about.intro.body",
52890
+ "about.bio.long",
52891
+ "about.philosophy.heading",
52892
+ "about.philosophy.body",
52893
+ "about.why_coaching.heading",
52894
+ "about.why_coaching.body",
52895
+ "about.industries.heading",
52896
+ "about.industry_1.title",
52897
+ "about.industry_1.description",
52898
+ "about.industry_2.title",
52899
+ "about.industry_2.description",
52900
+ "about.industry_3.title",
52901
+ "about.industry_3.description",
52902
+ "coach.title",
52903
+ "coach.location.city",
52904
+ "coach.location.state",
52905
+ "coach.city_state",
52906
+ "coach.service_area_heading",
52907
+ "coach.service_area_line"
52908
+ ],
52909
+ "factFieldAllowlist": [
52910
+ "coach.title",
52911
+ "coach.first_name",
52912
+ "coach.last_name",
52913
+ "verified_context.approved_career_facts",
52914
+ "verified_context.verified_media",
52915
+ "verified_context.approved_service_labels"
52916
+ ],
52917
+ "destinationGroundingMap": {
52918
+ "about.hero.heading": {
52919
+ "relevant_relevance_classes": [
52920
+ "ABOUT_BIOGRAPHY_NARRATIVE",
52921
+ "IDENTITY_FACT",
52922
+ "PRACTICE_FACT"
52923
+ ],
52924
+ "missing_value_authority": "NONE"
52925
+ },
52926
+ "about.intro.body": {
52927
+ "relevant_relevance_classes": [
52928
+ "ABOUT_BIOGRAPHY_NARRATIVE",
52929
+ "IDENTITY_FACT",
52930
+ "PRACTICE_FACT"
52931
+ ],
52932
+ "missing_value_authority": "NONE"
52933
+ },
52934
+ "about.bio.long": {
52935
+ "relevant_relevance_classes": [
52936
+ "ABOUT_BIOGRAPHY_NARRATIVE",
52937
+ "PRACTICE_FACT"
52938
+ ],
52939
+ "missing_value_authority": "NONE"
52940
+ },
52941
+ "about.philosophy.heading": {
52942
+ "relevant_relevance_classes": [
52943
+ "ABOUT_PHILOSOPHY_NARRATIVE"
52944
+ ],
52945
+ "missing_value_authority": "NONE"
52946
+ },
52947
+ "about.philosophy.body": {
52948
+ "relevant_relevance_classes": [
52949
+ "ABOUT_PHILOSOPHY_NARRATIVE"
52950
+ ],
52951
+ "missing_value_authority": "NONE"
52952
+ },
52953
+ "about.why_coaching.heading": {
52954
+ "relevant_relevance_classes": [
52955
+ "ABOUT_WHY_COACHING_NARRATIVE"
52956
+ ],
52957
+ "missing_value_authority": "NONE"
52958
+ },
52959
+ "about.why_coaching.body": {
52960
+ "relevant_relevance_classes": [
52961
+ "ABOUT_WHY_COACHING_NARRATIVE"
52962
+ ],
52963
+ "missing_value_authority": "NONE"
52964
+ },
52965
+ "about.industries.heading": {
52966
+ "relevant_relevance_classes": [
52967
+ "INDUSTRIES_FACT"
52968
+ ],
52969
+ "missing_value_authority": "CONDITIONAL_OMISSION_INDUSTRIES_HEADING"
52970
+ }
52971
+ },
52972
+ "sourceFieldRelevanceMap": {
52973
+ "about.hero.heading": "ABOUT_BIOGRAPHY_NARRATIVE",
52974
+ "about.intro.body": "ABOUT_BIOGRAPHY_NARRATIVE",
52975
+ "about.bio.long": "ABOUT_BIOGRAPHY_NARRATIVE",
52976
+ "about.philosophy.heading": "ABOUT_PHILOSOPHY_NARRATIVE",
52977
+ "about.philosophy.body": "ABOUT_PHILOSOPHY_NARRATIVE",
52978
+ "about.why_coaching.heading": "ABOUT_WHY_COACHING_NARRATIVE",
52979
+ "about.why_coaching.body": "ABOUT_WHY_COACHING_NARRATIVE",
52980
+ "about.industries.heading": "INDUSTRIES_FACT",
52981
+ "about.industry_1.title": "INDUSTRIES_FACT",
52982
+ "about.industry_1.description": "INDUSTRIES_FACT",
52983
+ "about.industry_2.title": "INDUSTRIES_FACT",
52984
+ "about.industry_2.description": "INDUSTRIES_FACT",
52985
+ "about.industry_3.title": "INDUSTRIES_FACT",
52986
+ "about.industry_3.description": "INDUSTRIES_FACT",
52987
+ "coach.title": "PRACTICE_FACT",
52988
+ "coach.city_state": "PRACTICE_FACT",
52989
+ "coach.service_area_heading": "PRACTICE_FACT",
52990
+ "coach.service_area_line": "PRACTICE_FACT",
52991
+ "coach.first_name": "IDENTITY_FACT",
52992
+ "coach.last_name": "IDENTITY_FACT",
52993
+ "verified_context.approved_career_facts": "ABOUT_BIOGRAPHY_NARRATIVE",
52994
+ "verified_context.verified_media": "ABOUT_BIOGRAPHY_NARRATIVE",
52995
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
52996
+ }
52997
+ },
52998
+ "BUSINESS_COACHING_V1": {
52999
+ "groundingFieldAllowlist": [
53000
+ "business_coaching.hero.heading",
53001
+ "business_coaching.hero.body",
53002
+ "business_coaching.intro.body",
53003
+ "coach.title",
53004
+ "coach.location.city",
53005
+ "coach.location.state",
53006
+ "coach.city_state",
53007
+ "coach.service_area_heading",
53008
+ "coach.service_area_line"
53009
+ ],
53010
+ "factFieldAllowlist": [
53011
+ "coach.title",
53012
+ "verified_context.approved_service_labels"
53013
+ ],
53014
+ "destinationGroundingMap": {
53015
+ "business_coaching.hero.heading": {
53016
+ "relevant_relevance_classes": [
53017
+ "BUSINESS_COACHING_NARRATIVE",
53018
+ "PRACTICE_FACT"
53019
+ ],
53020
+ "missing_value_authority": "NONE"
53021
+ },
53022
+ "business_coaching.hero.body": {
53023
+ "relevant_relevance_classes": [
53024
+ "BUSINESS_COACHING_NARRATIVE",
53025
+ "PRACTICE_FACT"
53026
+ ],
53027
+ "missing_value_authority": "NONE"
53028
+ },
53029
+ "business_coaching.intro.body": {
53030
+ "relevant_relevance_classes": [
53031
+ "BUSINESS_COACHING_NARRATIVE"
53032
+ ],
53033
+ "missing_value_authority": "NONE"
53034
+ }
53035
+ },
53036
+ "sourceFieldRelevanceMap": {
53037
+ "business_coaching.hero.heading": "BUSINESS_COACHING_NARRATIVE",
53038
+ "business_coaching.hero.body": "BUSINESS_COACHING_NARRATIVE",
53039
+ "business_coaching.intro.body": "BUSINESS_COACHING_NARRATIVE",
53040
+ "coach.title": "PRACTICE_FACT",
53041
+ "coach.city_state": "PRACTICE_FACT",
53042
+ "coach.service_area_heading": "PRACTICE_FACT",
53043
+ "coach.service_area_line": "PRACTICE_FACT",
53044
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53045
+ }
53046
+ },
53047
+ "EXECUTIVE_COACHING_V1": {
53048
+ "groundingFieldAllowlist": [
53049
+ "executive_coaching.hero.heading",
53050
+ "executive_coaching.hero.body",
53051
+ "coach.title",
53052
+ "coach.location.city",
53053
+ "coach.location.state",
53054
+ "coach.city_state",
53055
+ "coach.service_area_heading",
53056
+ "coach.service_area_line"
53057
+ ],
53058
+ "factFieldAllowlist": [
53059
+ "coach.title",
53060
+ "verified_context.approved_service_labels"
53061
+ ],
53062
+ "destinationGroundingMap": {
53063
+ "executive_coaching.hero.heading": {
53064
+ "relevant_relevance_classes": [
53065
+ "EXECUTIVE_COACHING_NARRATIVE",
53066
+ "PRACTICE_FACT"
53067
+ ],
53068
+ "missing_value_authority": "NONE"
53069
+ },
53070
+ "executive_coaching.hero.body": {
53071
+ "relevant_relevance_classes": [
53072
+ "EXECUTIVE_COACHING_NARRATIVE",
53073
+ "PRACTICE_FACT"
53074
+ ],
53075
+ "missing_value_authority": "NONE"
53076
+ }
53077
+ },
53078
+ "sourceFieldRelevanceMap": {
53079
+ "executive_coaching.hero.heading": "EXECUTIVE_COACHING_NARRATIVE",
53080
+ "executive_coaching.hero.body": "EXECUTIVE_COACHING_NARRATIVE",
53081
+ "coach.title": "PRACTICE_FACT",
53082
+ "coach.city_state": "PRACTICE_FACT",
53083
+ "coach.service_area_heading": "PRACTICE_FACT",
53084
+ "coach.service_area_line": "PRACTICE_FACT",
53085
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53086
+ }
53087
+ },
53088
+ "RESULTS_V1": {
53089
+ "groundingFieldAllowlist": [
53090
+ "results.intro.body"
53091
+ ],
53092
+ "factFieldAllowlist": [
53093
+ "coach.full_name",
53094
+ "coach.first_name",
53095
+ "coach.last_name",
53096
+ "verified_context.approved_career_facts",
53097
+ "verified_context.approved_service_labels"
53098
+ ],
53099
+ "destinationGroundingMap": {
53100
+ "results.intro.body": {
53101
+ "relevant_relevance_classes": [
53102
+ "RESULTS_NARRATIVE"
53103
+ ],
53104
+ "missing_value_authority": "D14_RESULTS_BASELINE"
53105
+ }
53106
+ },
53107
+ "sourceFieldRelevanceMap": {
53108
+ "results.intro.body": "RESULTS_NARRATIVE",
53109
+ "coach.full_name": "IDENTITY_FACT",
53110
+ "coach.first_name": "IDENTITY_FACT",
53111
+ "coach.last_name": "IDENTITY_FACT",
53112
+ "verified_context.approved_career_facts": "ABOUT_BIOGRAPHY_NARRATIVE",
53113
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53114
+ }
53115
+ },
53116
+ "CONTACT_V1": {
53117
+ "groundingFieldAllowlist": [
53118
+ "contact.hero.heading",
53119
+ "contact.intro.body"
53120
+ ],
53121
+ "factFieldAllowlist": [
53122
+ "coach.full_name",
53123
+ "coach.first_name",
53124
+ "coach.last_name",
53125
+ "verified_context.approved_service_labels"
53126
+ ],
53127
+ "destinationGroundingMap": {
53128
+ "contact.hero.heading": {
53129
+ "relevant_relevance_classes": [
53130
+ "CONTACT_NARRATIVE"
53131
+ ],
53132
+ "missing_value_authority": "D15_CONTACT_BASELINE"
53133
+ },
53134
+ "contact.intro.body": {
53135
+ "relevant_relevance_classes": [
53136
+ "CONTACT_NARRATIVE"
53137
+ ],
53138
+ "missing_value_authority": "D15_CONTACT_BASELINE"
53139
+ }
53140
+ },
53141
+ "sourceFieldRelevanceMap": {
53142
+ "contact.hero.heading": "CONTACT_NARRATIVE",
53143
+ "contact.intro.body": "CONTACT_NARRATIVE",
53144
+ "coach.full_name": "IDENTITY_FACT",
53145
+ "coach.first_name": "IDENTITY_FACT",
53146
+ "coach.last_name": "IDENTITY_FACT",
53147
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53148
+ }
53149
+ },
53150
+ "DISCOVERY_CALL_V1": {
53151
+ "groundingFieldAllowlist": [
53152
+ "discovery_call.hero.body"
53153
+ ],
53154
+ "factFieldAllowlist": [
53155
+ "coach.full_name",
53156
+ "coach.first_name",
53157
+ "coach.last_name",
53158
+ "verified_context.approved_service_labels"
53159
+ ],
53160
+ "destinationGroundingMap": {
53161
+ "discovery_call.hero.body": {
53162
+ "relevant_relevance_classes": [
53163
+ "DISCOVERY_CALL_NARRATIVE"
53164
+ ],
53165
+ "missing_value_authority": "D16_DISCOVERY_CALL_BASELINE"
53166
+ }
53167
+ },
53168
+ "sourceFieldRelevanceMap": {
53169
+ "discovery_call.hero.body": "DISCOVERY_CALL_NARRATIVE",
53170
+ "coach.full_name": "IDENTITY_FACT",
53171
+ "coach.first_name": "IDENTITY_FACT",
53172
+ "coach.last_name": "IDENTITY_FACT",
53173
+ "verified_context.approved_service_labels": "PRACTICE_FACT"
53174
+ }
53175
+ }
53176
+ };
52846
53177
  }
52847
53178
  });
52848
53179
 
@@ -52865,6 +53196,7 @@ var require_contract = __commonJS({
52865
53196
  exports2.validateNarrativeResponse = validateNarrativeResponse;
52866
53197
  exports2.narrativeFailure = narrativeFailure;
52867
53198
  var node_crypto_1 = require("node:crypto");
53199
+ var source_policy_generated_1 = require_source_policy_generated();
52868
53200
  exports2.CONTRACT_ID = "OPENCODE_AI_ENRICHMENT_V1_2";
52869
53201
  exports2.CONTRACT_VERSION = "1.2.0";
52870
53202
  exports2.PROMPT_IDS = ["ABOUT_V1", "BUSINESS_COACHING_V1", "EXECUTIVE_COACHING_V1", "RESULTS_V1", "CONTACT_V1", "DISCOVERY_CALL_V1"];
@@ -52886,7 +53218,8 @@ var require_contract = __commonJS({
52886
53218
  },
52887
53219
  exactCopyKeys: [],
52888
53220
  conditionalKeys: [{ canonicalField: "about.industries.heading", requiredWhen: "INDUSTRIES_GROUP populated_fields >= 1" }],
52889
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "about.industry_1.title", "about.industry_1.description", "about.industry_2.title", "about.industry_2.description", "about.industry_3.title", "about.industry_3.description", "verified_context.approved_career_facts", "verified_context.verified_media", "verified_context.approved_service_labels"]
53221
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "about.industry_1.title", "about.industry_1.description", "about.industry_2.title", "about.industry_2.description", "about.industry_3.title", "about.industry_3.description", "verified_context.approved_career_facts", "verified_context.verified_media", "verified_context.approved_service_labels"],
53222
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.ABOUT_V1
52890
53223
  },
52891
53224
  BUSINESS_COACHING_V1: {
52892
53225
  packetName: "AI Source \u2014 Business Coaching",
@@ -52894,7 +53227,8 @@ var require_contract = __commonJS({
52894
53227
  formats: { "business_coaching.hero.heading": "PLAIN_TEXT_STRING", "business_coaching.hero.body": "PLAIN_TEXT_STRING", "business_coaching.intro.body": "HTML_FRAGMENT_STRING" },
52895
53228
  exactCopyKeys: [],
52896
53229
  conditionalKeys: [],
52897
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"]
53230
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"],
53231
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.BUSINESS_COACHING_V1
52898
53232
  },
52899
53233
  EXECUTIVE_COACHING_V1: {
52900
53234
  packetName: "AI Source \u2014 Executive Coaching",
@@ -52902,7 +53236,8 @@ var require_contract = __commonJS({
52902
53236
  formats: { "executive_coaching.hero.heading": "PLAIN_TEXT_STRING", "executive_coaching.hero.body": "PLAIN_TEXT_STRING" },
52903
53237
  exactCopyKeys: [],
52904
53238
  conditionalKeys: [],
52905
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"]
53239
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels", "verified_context.approved_career_facts"],
53240
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.EXECUTIVE_COACHING_V1
52906
53241
  },
52907
53242
  RESULTS_V1: {
52908
53243
  packetName: "AI Source \u2014 Results",
@@ -52910,7 +53245,8 @@ var require_contract = __commonJS({
52910
53245
  formats: { "results.intro.body": "PLAIN_TEXT_STRING" },
52911
53246
  exactCopyKeys: [],
52912
53247
  conditionalKeys: [],
52913
- allowedContextKeys: [...COMMON_CONTEXT, "verified_context.approved_career_facts", "verified_context.approved_service_labels"]
53248
+ allowedContextKeys: [...COMMON_CONTEXT, "verified_context.approved_career_facts", "verified_context.approved_service_labels"],
53249
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.RESULTS_V1
52914
53250
  },
52915
53251
  CONTACT_V1: {
52916
53252
  packetName: "AI Source \u2014 Contact",
@@ -52918,7 +53254,8 @@ var require_contract = __commonJS({
52918
53254
  formats: { "contact.hero.heading": "PLAIN_TEXT_STRING", "contact.intro.body": "PLAIN_TEXT_STRING" },
52919
53255
  exactCopyKeys: ["contact.hero.heading", "contact.intro.body"],
52920
53256
  conditionalKeys: [],
52921
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"]
53257
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"],
53258
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.CONTACT_V1
52922
53259
  },
52923
53260
  DISCOVERY_CALL_V1: {
52924
53261
  packetName: "AI Source \u2014 Discovery Call",
@@ -52926,7 +53263,8 @@ var require_contract = __commonJS({
52926
53263
  formats: { "discovery_call.hero.body": "PLAIN_TEXT_STRING" },
52927
53264
  exactCopyKeys: ["discovery_call.hero.body"],
52928
53265
  conditionalKeys: [],
52929
- allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"]
53266
+ allowedContextKeys: [...COMMON_CONTEXT, ...LOCATION_CONTEXT, "verified_context.approved_service_labels"],
53267
+ sourcePolicy: source_policy_generated_1.SOURCE_EVIDENCE_POLICY.DISCOVERY_CALL_V1
52930
53268
  }
52931
53269
  };
52932
53270
  exports2.ALL_OUTPUT_KEYS = exports2.PROMPT_IDS.flatMap((id) => [...exports2.PROMPT_DEFINITIONS[id].outputKeys]);
@@ -53035,18 +53373,90 @@ var require_contract = __commonJS({
53035
53373
  properties: Object.fromEntries(effective.map((key) => [key, { type: "string", minLength: 1, output_format: definition.formats[key] }]))
53036
53374
  };
53037
53375
  }
53038
- function assertEvidence(evidence, definition, index) {
53376
+ function assertEvidence(evidence, index) {
53039
53377
  assertExactKeys(evidence, EVIDENCE_KEYS, `SOURCE_EVIDENCE_${index}`);
53040
53378
  const { evidence_reference: reference, ...digestInput } = evidence;
53041
53379
  if (reference !== sha256Canonical(digestInput))
53042
53380
  throw new Error(`SOURCE_EVIDENCE_${index}_DIGEST_INVALID`);
53043
- if (typeof evidence.canonical_field !== "string" || !definition.outputKeys.includes(evidence.canonical_field))
53381
+ if (typeof evidence.canonical_field !== "string" || !evidence.canonical_field.trim())
53044
53382
  throw new Error(`SOURCE_EVIDENCE_${index}_FIELD_INVALID`);
53045
53383
  for (const key of ["page_url", "page_title", "source_locator", "source_text"])
53046
53384
  if (typeof evidence[key] !== "string" || !evidence[key].trim())
53047
53385
  throw new Error(`SOURCE_EVIDENCE_${index}_${key.toUpperCase()}_INVALID`);
53048
53386
  }
53049
- function assertCanonicalSourcePacket(value, expectedPromptId, requireReady = true) {
53387
+ var VERIFIED_CONTEXT_STATUSES = ["EXACT_SOURCE", "VERIFIED_FACT", "DERIVED"];
53388
+ var UNVERIFIED_CONTEXT_AUTHORITIES = ["LEGACY_WEBSITE_EXACT", "AI_REWRITE_FROM_SOURCE"];
53389
+ function verifiedContextAuthority(value, factualProvenance) {
53390
+ if (!isObject(value) || !isObject(value.values) || !isObject(value.evidence))
53391
+ throw new Error("SOURCE_PACKET_VERIFIED_CONTEXT_INVALID");
53392
+ const provenance = factualProvenance === void 0 ? void 0 : factualProvenance;
53393
+ if (provenance !== void 0 && !Array.isArray(provenance))
53394
+ throw new Error("SOURCE_PACKET_FACTUAL_PROVENANCE_INVALID");
53395
+ const eligibleProvenance = (Array.isArray(provenance) ? provenance : []).filter((entry) => isObject(entry) && VERIFIED_CONTEXT_STATUSES.includes(String(entry.status)) && typeof entry.source_authority === "string" && !UNVERIFIED_CONTEXT_AUTHORITIES.includes(entry.source_authority) && !(entry.source_authority === "DERIVED_DETERMINISTIC" && entry.requires_human_review === true) && Array.isArray(entry.source_refs));
53396
+ const provenanceByField = new Map(eligibleProvenance.map((entry) => [String(entry.canonical_field), entry]));
53397
+ const provenanceSourceRefs = new Set(eligibleProvenance.flatMap((entry) => entry.source_refs.map((ref) => JSON.stringify(canonicalize(ref)))));
53398
+ const keys = /* @__PURE__ */ new Set();
53399
+ for (const [key, rawEvidence] of Object.entries(value.evidence)) {
53400
+ const rawValue = getPath(value.values, key);
53401
+ if (rawValue === void 0 || !isObject(rawEvidence))
53402
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_ENTRY_INVALID:${key}`);
53403
+ assertExactKeys(rawEvidence, ["value", "source_authority", "source_refs", "status"], `SOURCE_PACKET_VERIFIED_CONTEXT_ENTRY:${key}`);
53404
+ if (JSON.stringify(canonicalize(rawEvidence.value)) !== JSON.stringify(canonicalize(rawValue)))
53405
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_VALUE_MISMATCH:${key}`);
53406
+ if (!VERIFIED_CONTEXT_STATUSES.includes(String(rawEvidence.status)))
53407
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_STATUS_INVALID:${key}`);
53408
+ if (typeof rawEvidence.source_authority !== "string" || UNVERIFIED_CONTEXT_AUTHORITIES.includes(rawEvidence.source_authority))
53409
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AUTHORITY_INVALID:${key}`);
53410
+ if (!Array.isArray(rawEvidence.source_refs) || rawEvidence.source_refs.length === 0 || rawEvidence.source_refs.some((ref) => !isObject(ref)))
53411
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_SOURCE_REFS_INVALID:${key}`);
53412
+ if (provenance !== void 0) {
53413
+ for (const ref of rawEvidence.source_refs)
53414
+ if (!provenanceSourceRefs.has(JSON.stringify(canonicalize(ref))))
53415
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_SOURCE_REF_UNBOUND:${key}`);
53416
+ const provenanceField = key.replace(/^coach_identity\.location\./, "coach.location.");
53417
+ const direct = provenanceByField.get(provenanceField);
53418
+ const requiresDirectProvenance = !key.startsWith("verified_context.") && !key.startsWith("coach_identity.location.");
53419
+ if (requiresDirectProvenance && !direct)
53420
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_PROVENANCE_UNRESOLVED:${key}`);
53421
+ if (direct) {
53422
+ for (const member of ["value", "source_authority", "source_refs", "status"]) {
53423
+ if (JSON.stringify(canonicalize(rawEvidence[member])) !== JSON.stringify(canonicalize(direct[member])))
53424
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_PROVENANCE_MISMATCH:${key}:${member}`);
53425
+ }
53426
+ }
53427
+ if (key.startsWith("verified_context.")) {
53428
+ const aggregateDomains = {
53429
+ "verified_context.approved_career_facts": (entry) => String(entry.canonical_field).startsWith("about.stat_"),
53430
+ "verified_context.verified_media": (entry) => String(entry.canonical_field).startsWith("about.media."),
53431
+ "verified_context.approved_service_labels": (entry) => ["coach.title", "coach.service_area_heading", "coach.service_area_line"].includes(String(entry.canonical_field))
53432
+ };
53433
+ const inDomain = aggregateDomains[key];
53434
+ if (!inDomain || rawEvidence.source_authority !== "DERIVED_DETERMINISTIC" || rawEvidence.status !== "DERIVED")
53435
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AGGREGATE_AUTHORITY_INVALID:${key}`);
53436
+ const records = key === "verified_context.approved_service_labels" ? ["coach.title", "coach.service_area_heading", "coach.service_area_line"].map((field) => provenanceByField.get(field)).filter((entry) => Boolean(entry)) : eligibleProvenance.filter(inDomain);
53437
+ const expectedValue = records.map((entry) => ({ canonical_field: entry.canonical_field, value: entry.value }));
53438
+ const expectedRefs = records.flatMap((entry) => entry.source_refs);
53439
+ if (JSON.stringify(canonicalize(rawEvidence.value)) !== JSON.stringify(canonicalize(expectedValue)))
53440
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AGGREGATE_VALUE_INVALID:${key}`);
53441
+ if (JSON.stringify(canonicalize(rawEvidence.source_refs)) !== JSON.stringify(canonicalize(expectedRefs)))
53442
+ throw new Error(`SOURCE_PACKET_VERIFIED_CONTEXT_AGGREGATE_REFS_INVALID:${key}`);
53443
+ }
53444
+ }
53445
+ keys.add(key);
53446
+ }
53447
+ return { keys, values: value.values };
53448
+ }
53449
+ function sourceFieldAllowedForClass(definition, evidenceClass, canonicalField) {
53450
+ if (evidenceClass === "FIELD_EVIDENCE" || evidenceClass === "PAGE_SECTION_EXCERPT")
53451
+ return definition.sourcePolicy.groundingFieldAllowlist.includes(canonicalField);
53452
+ if (evidenceClass === "DETERMINISTIC_FACT" || evidenceClass === "VERIFIED_FACTUAL_CONTEXT" || evidenceClass === "PRACTICE_CONTEXT")
53453
+ return definition.sourcePolicy.factFieldAllowlist.includes(canonicalField);
53454
+ return false;
53455
+ }
53456
+ function jobSourceFieldAllowed(definition, canonicalField) {
53457
+ return definition.sourcePolicy.groundingFieldAllowlist.includes(canonicalField) || definition.sourcePolicy.factFieldAllowlist.includes(canonicalField);
53458
+ }
53459
+ function assertCanonicalSourcePacket(value, expectedPromptId, requireReady = true, verifiedFactualContext, factualProvenance) {
53050
53460
  assertExactKeys(value, PACKET_KEYS, "SOURCE_PACKET");
53051
53461
  const definition = promptDefinition(value.prompt_id);
53052
53462
  if (expectedPromptId && value.prompt_id !== expectedPromptId)
@@ -53057,13 +53467,19 @@ var require_contract = __commonJS({
53057
53467
  throw new Error("SOURCE_PACKET_EVIDENCE_STATUS_INVALID");
53058
53468
  if (requireReady && value.evidence_status !== "READY")
53059
53469
  throw new Error("SOURCE_PACKET_INSUFFICIENT_EVIDENCE");
53060
- if (!Array.isArray(value.source_evidence_references) || value.evidence_status === "READY" && value.source_evidence_references.length === 0)
53470
+ if (!Array.isArray(value.source_evidence_references))
53061
53471
  throw new Error("SOURCE_PACKET_EVIDENCE_REQUIRED");
53062
- value.source_evidence_references.forEach((entry, index) => assertEvidence(entry, definition, index));
53063
- const evidenceReferenceSet2 = new Set(value.source_evidence_references.map((entry) => String(entry.evidence_reference)));
53064
- const verifiedContextKeySet = new Set(Object.keys(isObject(value.verified_factual_context) ? value.verified_factual_context : {}));
53065
- assertGroundingRecords(value.grounding, definition, evidenceReferenceSet2, verifiedContextKeySet);
53066
- assertEvidencePool(value.evidence_pool);
53472
+ const sourceReferences = /* @__PURE__ */ new Map();
53473
+ value.source_evidence_references.forEach((entry, index) => {
53474
+ assertEvidence(entry, index);
53475
+ const reference = String(entry.evidence_reference);
53476
+ if (sourceReferences.has(reference))
53477
+ throw new Error(`SOURCE_EVIDENCE_${index}_DUPLICATE_ID`);
53478
+ sourceReferences.set(reference, entry);
53479
+ });
53480
+ const contextAuthority = verifiedContextAuthority(verifiedFactualContext, factualProvenance);
53481
+ const pool = assertEvidencePool(value.evidence_pool, definition, sourceReferences, contextAuthority);
53482
+ assertGroundingRecords(value.grounding, definition, new Set(pool.pageEntries.keys()), new Set(pool.contextEntries.keys()), pool.relevanceByReference);
53067
53483
  const unresolved = (Array.isArray(value.grounding) ? value.grounding : []).filter((record) => record.grounding_status === "NO_SUPPORTING_EVIDENCE" && String(record.grounding_basis).endsWith("UNRESOLVED_POLICY"));
53068
53484
  if (value.evidence_status === "READY" && unresolved.length)
53069
53485
  throw new Error(`SOURCE_PACKET_UNRESOLVED_POLICY:${unresolved.map((record) => String(record.canonical_field)).join(",")}`);
@@ -53080,7 +53496,7 @@ var require_contract = __commonJS({
53080
53496
  if (digest !== sha256Canonical(digestInput))
53081
53497
  throw new Error("SOURCE_PACKET_DIGEST_INVALID");
53082
53498
  }
53083
- function assertGroundingRecords(grounding, definition, evidenceReferences, verifiedContextKeys) {
53499
+ function assertGroundingRecords(grounding, definition, evidenceReferences, verifiedContextKeys, relevanceByReference) {
53084
53500
  if (!Array.isArray(grounding) || grounding.length !== definition.outputKeys.length)
53085
53501
  throw new Error("SOURCE_PACKET_GROUNDING_COUNT_INVALID");
53086
53502
  const seen = /* @__PURE__ */ new Set();
@@ -53101,9 +53517,17 @@ var require_contract = __commonJS({
53101
53517
  throw new Error("SOURCE_PACKET_GROUNDED_REQUIRES_REFERENCES");
53102
53518
  if (status !== "GROUNDED" && refs.length)
53103
53519
  throw new Error("SOURCE_PACKET_GROUNDING_REFS_UNEXPECTED");
53104
- for (const ref of refs)
53520
+ for (const ref of refs) {
53105
53521
  if (!evidenceReferences.has(ref) && !verifiedContextKeys.has(ref))
53106
53522
  throw new Error(`SOURCE_PACKET_GROUNDING_REFERENCE_UNRESOLVED:${ref}`);
53523
+ if (relevanceByReference) {
53524
+ const destinationPolicy = definition.sourcePolicy.destinationGroundingMap[field];
53525
+ const relevance = relevanceByReference.get(ref);
53526
+ if (!destinationPolicy || !relevance || !destinationPolicy.relevant_relevance_classes.includes(relevance)) {
53527
+ throw new Error(`SOURCE_PACKET_GROUNDING_RELEVANCE_INVALID:${field}:${ref}`);
53528
+ }
53529
+ }
53530
+ }
53107
53531
  if (typeof record.grounding_basis !== "string" || !record.grounding_basis.trim())
53108
53532
  throw new Error("SOURCE_PACKET_GROUNDING_BASIS_INVALID");
53109
53533
  });
@@ -53111,53 +53535,103 @@ var require_contract = __commonJS({
53111
53535
  if (!seen.has(key))
53112
53536
  throw new Error(`SOURCE_PACKET_GROUNDING_MISSING:${key}`);
53113
53537
  }
53114
- function assertEvidencePool(pool) {
53538
+ function assertEvidencePool(pool, definition, sourceReferences, verifiedContext) {
53115
53539
  if (!Array.isArray(pool))
53116
53540
  throw new Error("SOURCE_PACKET_EVIDENCE_POOL_REQUIRED");
53117
53541
  const pageAttributedClasses = ["FIELD_EVIDENCE", "PAGE_SECTION_EXCERPT", "DETERMINISTIC_FACT"];
53118
53542
  const contextClasses = ["VERIFIED_FACTUAL_CONTEXT", "PRACTICE_CONTEXT"];
53543
+ const pageEntries = /* @__PURE__ */ new Map();
53544
+ const contextEntries = /* @__PURE__ */ new Map();
53545
+ const relevanceByReference = /* @__PURE__ */ new Map();
53119
53546
  for (const raw of pool) {
53120
53547
  assertExactKeys(raw, ["evidence_reference", "evidence_class", "canonical_field", "page_url", "page_title", "source_locator", "source_text", "relevance_class"], "SOURCE_PACKET_EVIDENCE_POOL_ENTRY");
53121
53548
  const entry = raw;
53549
+ const reference = String(entry.evidence_reference ?? "");
53550
+ if (!reference)
53551
+ throw new Error("SOURCE_PACKET_EVIDENCE_REFERENCE_INVALID");
53552
+ if (pageEntries.has(reference) || contextEntries.has(reference))
53553
+ throw new Error(`SOURCE_PACKET_EVIDENCE_POOL_DUPLICATE_ID:${reference}`);
53122
53554
  const evidenceClass = String(entry.evidence_class);
53123
53555
  if (![...pageAttributedClasses, ...contextClasses].includes(evidenceClass))
53124
53556
  throw new Error(`SOURCE_PACKET_EVIDENCE_CLASS_INVALID:${evidenceClass}`);
53557
+ const canonicalField = String(entry.canonical_field ?? "");
53558
+ if (!canonicalField || !sourceFieldAllowedForClass(definition, evidenceClass, canonicalField))
53559
+ throw new Error(`SOURCE_PACKET_EVIDENCE_FIELD_INVALID:${evidenceClass}:${canonicalField}`);
53560
+ const relevance = String(entry.relevance_class ?? "");
53561
+ const authoritativeRelevance = definition.sourcePolicy.sourceFieldRelevanceMap[canonicalField];
53562
+ if (!authoritativeRelevance || relevance !== authoritativeRelevance)
53563
+ throw new Error(`SOURCE_PACKET_EVIDENCE_RELEVANCE_INVALID:${canonicalField}:${relevance}`);
53125
53564
  if (pageAttributedClasses.includes(evidenceClass)) {
53126
- if (entry.page_url === null || entry.source_locator === null)
53565
+ if (typeof entry.page_url !== "string" || !entry.page_url.trim() || typeof entry.page_title !== "string" || !entry.page_title.trim() || typeof entry.source_locator !== "string" || !entry.source_locator.trim())
53127
53566
  throw new Error(`SOURCE_PACKET_EVIDENCE_PROVENANCE_INVALID:${evidenceClass}`);
53128
53567
  const digestInput = { canonical_field: entry.canonical_field, page_url: entry.page_url, page_title: entry.page_title, source_locator: entry.source_locator, source_text: entry.source_text };
53129
53568
  if (entry.evidence_reference !== sha256Canonical(digestInput))
53130
53569
  throw new Error(`SOURCE_PACKET_EVIDENCE_DIGEST_INVALID:${String(entry.canonical_field)}`);
53570
+ pageEntries.set(reference, entry);
53131
53571
  } else {
53132
- if (entry.page_url !== null || entry.source_locator !== null)
53572
+ if (entry.page_url !== null || entry.page_title !== null || entry.source_locator !== null)
53133
53573
  throw new Error("SOURCE_PACKET_EVIDENCE_CONTEXT_PROVENANCE_UNEXPECTED");
53134
53574
  if (entry.evidence_reference !== String(entry.canonical_field ?? ""))
53135
53575
  throw new Error("SOURCE_PACKET_EVIDENCE_CONTEXT_KEY_INVALID");
53576
+ if (!verifiedContext.keys.has(canonicalField))
53577
+ throw new Error(`SOURCE_PACKET_EVIDENCE_CONTEXT_UNRESOLVED:${canonicalField}`);
53578
+ const contextValue = getPath(verifiedContext.values, canonicalField);
53579
+ if (entry.source_text !== JSON.stringify(canonicalize(contextValue)))
53580
+ throw new Error(`SOURCE_PACKET_EVIDENCE_CONTEXT_PROJECTION_INVALID:${canonicalField}`);
53581
+ contextEntries.set(reference, entry);
53136
53582
  }
53137
53583
  if (typeof entry.source_text !== "string" || !entry.source_text.trim())
53138
53584
  throw new Error("SOURCE_PACKET_EVIDENCE_TEXT_REQUIRED");
53139
53585
  if (entry.source_text.length > 2e3)
53140
53586
  throw new Error("SOURCE_PACKET_EVIDENCE_EXCERPT_OVERBOUND");
53141
- if (typeof entry.relevance_class !== "string" || !entry.relevance_class.trim())
53142
- throw new Error("SOURCE_PACKET_EVIDENCE_RELEVANCE_INVALID");
53587
+ relevanceByReference.set(reference, relevance);
53143
53588
  }
53144
53589
  if (pool.length > 48)
53145
53590
  throw new Error("SOURCE_PACKET_EVIDENCE_POOL_OVERBOUND");
53591
+ if (pageEntries.size !== sourceReferences.size)
53592
+ throw new Error("SOURCE_PACKET_EVIDENCE_POOL_PROJECTION_COUNT_INVALID");
53593
+ for (const [reference, source] of sourceReferences) {
53594
+ const entry = pageEntries.get(reference);
53595
+ if (!entry)
53596
+ throw new Error(`SOURCE_PACKET_EVIDENCE_POOL_REFERENCE_UNRESOLVED:${reference}`);
53597
+ for (const key of ["evidence_reference", "canonical_field", "page_url", "page_title", "source_locator", "source_text"]) {
53598
+ if (entry[key] !== source[key])
53599
+ throw new Error(`SOURCE_PACKET_EVIDENCE_PROJECTION_MISMATCH:${reference}:${key}`);
53600
+ }
53601
+ }
53602
+ return { pageEntries, contextEntries, relevanceByReference };
53603
+ }
53604
+ function assertPreAiPackageOwnership(input, promptId) {
53605
+ if (!isObject(input.pre_ai_package))
53606
+ throw new Error("BOUNDARY_PRE_AI_PACKAGE_MUST_BE_OBJECT");
53607
+ const { package_digest: packageDigest, ...packageBody } = input.pre_ai_package;
53608
+ if (typeof packageDigest !== "string" || packageDigest !== sha256Canonical(packageBody))
53609
+ throw new Error("BOUNDARY_PRE_AI_PACKAGE_DIGEST_INVALID");
53610
+ if (!Array.isArray(packageBody.aiSourcePackets))
53611
+ throw new Error("BOUNDARY_PRE_AI_PACKAGE_PACKETS_INVALID");
53612
+ const ownedPacket = packageBody.aiSourcePackets.find((packet) => isObject(packet) && packet.prompt_id === promptId && JSON.stringify(canonicalize(packet)) === JSON.stringify(canonicalize(input.source_packet)));
53613
+ if (!ownedPacket)
53614
+ throw new Error(`BOUNDARY_SOURCE_PACKET_NOT_OWNED_BY_PRE_AI_PACKAGE:${promptId}`);
53615
+ if (JSON.stringify(canonicalize(packageBody.verifiedFactualContext)) !== JSON.stringify(canonicalize(input.verified_factual_context))) {
53616
+ throw new Error("BOUNDARY_VERIFIED_CONTEXT_NOT_OWNED_BY_PRE_AI_PACKAGE");
53617
+ }
53618
+ return packageBody;
53146
53619
  }
53147
53620
  function buildBoundedNarrativeJob(input) {
53148
- assertExactKeys(input, ["contract_id", "prompt_id", "source_packet", "verified_factual_context", "required_output_schema", "template_baseline"], "BOUNDARY_INPUT");
53621
+ assertExactKeys(input, ["contract_id", "prompt_id", "source_packet", "verified_factual_context", "pre_ai_package", "required_output_schema", "template_baseline"], "BOUNDARY_INPUT");
53149
53622
  if (input.contract_id !== exports2.CONTRACT_ID)
53150
53623
  throw new Error("BOUNDED_AI_CONTRACT_ID_INVALID");
53151
53624
  const definition = promptDefinition(input.prompt_id);
53152
53625
  const promptId = input.prompt_id;
53153
- assertCanonicalSourcePacket(input.source_packet, promptId);
53626
+ const owningPackage = assertPreAiPackageOwnership(input, promptId);
53627
+ assertCanonicalSourcePacket(input.source_packet, promptId, true, input.verified_factual_context, owningPackage.factualProvenance);
53154
53628
  const packet = input.source_packet;
53155
- if (!isObject(packet.verified_factual_context) && !isObject(input.verified_factual_context))
53629
+ if (!isObject(input.verified_factual_context))
53156
53630
  throw new Error("BOUNDED_AI_VERIFIED_CONTEXT_INVALID");
53157
53631
  const expectedSchema = effectiveOutputSchemaForPrompt(promptId, Array.isArray(packet.grounding) ? packet.grounding : []);
53158
53632
  if (JSON.stringify(canonicalize(input.required_output_schema)) !== JSON.stringify(canonicalize(expectedSchema)))
53159
53633
  throw new Error("BOUNDED_AI_OUTPUT_SCHEMA_INVALID");
53160
- const contextSource = isObject(input.verified_factual_context) ? input.verified_factual_context : packet.verified_factual_context ?? {};
53634
+ const contextSource = input.verified_factual_context;
53161
53635
  if (!isObject(contextSource))
53162
53636
  throw new Error("BOUNDED_AI_VERIFIED_CONTEXT_INVALID");
53163
53637
  const values = isObject(contextSource.values) ? contextSource.values : {};
@@ -53217,18 +53691,32 @@ var require_contract = __commonJS({
53217
53691
  throw new Error("BOUNDED_AI_SOURCE_TEXT_REQUIRED");
53218
53692
  if (!Array.isArray(value.source_evidence))
53219
53693
  throw new Error("BOUNDED_AI_SOURCE_EVIDENCE_REQUIRED");
53220
- if (value.source_evidence.length === 0) {
53221
- const evidenceReferenceSet2 = /* @__PURE__ */ new Set();
53222
- const contextKeySet = new Set(Object.keys(isObject(value.verified_factual_context) ? value.verified_factual_context : {}));
53223
- const groundedByEvidence = (value.grounding ?? []).filter((record) => String(record.grounding_status) === "GROUNDED").filter((record) => (record.grounding_evidence_references ?? []).some((ref) => evidenceReferenceSet2.has(ref) && !contextKeySet.has(ref)));
53224
- if (groundedByEvidence.length)
53225
- throw new Error("BOUNDED_AI_EMPTY_EVIDENCE_WITH_GROUNDED_DESTINATION");
53226
- } else {
53227
- value.source_evidence.forEach((entry, index) => assertEvidence(entry, definition, index));
53694
+ if (value.source_evidence.length > 0) {
53695
+ const seenEvidence = /* @__PURE__ */ new Set();
53696
+ value.source_evidence.forEach((entry, index) => {
53697
+ assertEvidence(entry, index);
53698
+ if (!jobSourceFieldAllowed(definition, String(entry.canonical_field)))
53699
+ throw new Error(`SOURCE_EVIDENCE_${index}_FIELD_INVALID`);
53700
+ const reference = String(entry.evidence_reference);
53701
+ if (seenEvidence.has(reference))
53702
+ throw new Error(`SOURCE_EVIDENCE_${index}_DUPLICATE_ID`);
53703
+ seenEvidence.add(reference);
53704
+ });
53228
53705
  if (typeof value.source_text !== "string" || !value.source_text.trim())
53229
53706
  throw new Error("BOUNDED_AI_SOURCE_TEXT_REQUIRED");
53230
53707
  if (!Array.isArray(value.source_locators) || value.source_locators.some((entry) => typeof entry !== "string") || new Set(value.source_locators).size !== value.source_locators.length)
53231
53708
  throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53709
+ const expectedText = value.source_evidence.map((entry) => entry.source_text).join("\n\n");
53710
+ if (value.source_text !== expectedText)
53711
+ throw new Error("BOUNDED_AI_SOURCE_TEXT_INVALID");
53712
+ const expectedLocators = [...new Set(value.source_evidence.map((entry) => `${String(entry.page_url)}#${String(entry.source_locator)}`))].sort();
53713
+ if (JSON.stringify(value.source_locators) !== JSON.stringify(expectedLocators))
53714
+ throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53715
+ } else {
53716
+ if (value.source_text !== "")
53717
+ throw new Error("BOUNDED_AI_SOURCE_TEXT_INVALID");
53718
+ if (!Array.isArray(value.source_locators) || value.source_locators.length !== 0)
53719
+ throw new Error("BOUNDED_AI_SOURCE_LOCATORS_INVALID");
53232
53720
  }
53233
53721
  if (!DIGEST.test(String(value.source_packet_digest)))
53234
53722
  throw new Error("BOUNDED_AI_PACKET_DIGEST_INVALID");
@@ -53368,15 +53856,14 @@ var require_contract = __commonJS({
53368
53856
  seen.add(field);
53369
53857
  const groundingRecord = job.grounding.find((record) => record.canonical_field === field);
53370
53858
  const groundingRefs = new Set(groundingRecord?.grounding_evidence_references ?? []);
53371
- const evidenceRefs = new Set(job.source_evidence.filter((entry) => entry.canonical_field === field).map((entry) => String(entry.evidence_reference)));
53372
- if (!Array.isArray(raw.source_refs) || raw.source_refs.some((ref) => typeof ref !== "string" || !evidenceRefs.has(ref) || !groundingRefs.has(ref))) {
53373
- const contextOnly = Array.isArray(raw.source_refs) && raw.source_refs.length === 0 && (Array.isArray(raw.verified_context_refs) ? raw.verified_context_refs.length : 0) > 0;
53374
- if (!contextOnly)
53375
- issues.push(`PROVENANCE_${index}_SOURCE_REFS_INVALID`);
53376
- }
53377
- if (!Array.isArray(raw.verified_context_refs) || raw.verified_context_refs.some((ref) => typeof ref !== "string" || !Object.hasOwn(job.verified_factual_context, ref)))
53859
+ const requestEvidenceRefs = new Set(job.source_evidence.map((entry) => String(entry.evidence_reference)));
53860
+ const authorizedEvidenceRefs = new Set([...groundingRefs].filter((ref) => requestEvidenceRefs.has(ref)));
53861
+ const authorizedContextRefs = new Set([...groundingRefs].filter((ref) => Object.hasOwn(job.verified_factual_context, ref)));
53862
+ if (!Array.isArray(raw.source_refs) || raw.source_refs.some((ref) => typeof ref !== "string" || !authorizedEvidenceRefs.has(ref)) || new Set(raw.source_refs).size !== raw.source_refs.length)
53863
+ issues.push(`PROVENANCE_${index}_SOURCE_REFS_INVALID`);
53864
+ if (!Array.isArray(raw.verified_context_refs) || raw.verified_context_refs.some((ref) => typeof ref !== "string" || !authorizedContextRefs.has(ref)) || new Set(raw.verified_context_refs).size !== raw.verified_context_refs.length)
53378
53865
  issues.push(`PROVENANCE_${index}_CONTEXT_REFS_INVALID`);
53379
- if (Array.isArray(raw.source_refs) && raw.source_refs.length === 0 && (Array.isArray(raw.verified_context_refs) ? raw.verified_context_refs.length : 0) === 0)
53866
+ if (groundingRecord?.grounding_status === "GROUNDED" && Array.isArray(raw.source_refs) && raw.source_refs.length === 0 && Array.isArray(raw.verified_context_refs) && raw.verified_context_refs.length === 0)
53380
53867
  issues.push(`PROVENANCE_${index}_NO_GROUNDING`);
53381
53868
  }
53382
53869
  for (const key of effectiveKeys)
@@ -53386,7 +53873,9 @@ var require_contract = __commonJS({
53386
53873
  if (!effectiveKeys.includes(key))
53387
53874
  continue;
53388
53875
  const output = value.outputs[key];
53389
- const evidenceMatch = job.source_evidence.filter((entry) => entry.canonical_field === key).some((entry) => String(entry.source_text).replace(/\s+/g, " ").trim() === String(output).replace(/\s+/g, " ").trim());
53876
+ const groundingRecord = job.grounding.find((record) => record.canonical_field === key);
53877
+ const groundingRefs = new Set(groundingRecord?.grounding_evidence_references ?? []);
53878
+ const evidenceMatch = job.source_evidence.filter((entry) => groundingRefs.has(String(entry.evidence_reference))).some((entry) => String(entry.source_text).replace(/\s+/g, " ").trim() === String(output).replace(/\s+/g, " ").trim());
53390
53879
  const baselineMatch = (job.template_baseline.elements ?? []).some((element) => String(element.captured_content).replace(/\s+/g, " ").trim() === String(output).replace(/\s+/g, " ").trim());
53391
53880
  if (!evidenceMatch && !baselineMatch)
53392
53881
  issues.push(`${key}:EXACT_COPY_MISMATCH`);
@@ -53525,11 +54014,13 @@ var require_pre_ai_contract = __commonJS({
53525
54014
  throw new Error("PRE_AI_PACKAGE_AI_CONTRACT_INVALID");
53526
54015
  if (!["PRE_AI_READY", "PRE_AI_BLOCKED"].includes(String(value.status)))
53527
54016
  throw new Error("PRE_AI_PACKAGE_STATUS_INVALID");
54017
+ if (!(0, contract_1.isObject)(value.verifiedFactualContext) || !(0, contract_1.isObject)(value.verifiedFactualContext.values) || !(0, contract_1.isObject)(value.verifiedFactualContext.evidence))
54018
+ throw new Error("PRE_AI_PACKAGE_VERIFIED_CONTEXT_INVALID");
53528
54019
  if (!Array.isArray(value.aiSourcePackets) || value.aiSourcePackets.length !== 6)
53529
54020
  throw new Error("PRE_AI_PACKAGE_PACKET_COUNT_INVALID");
53530
54021
  const seenPrompts = /* @__PURE__ */ new Set();
53531
54022
  for (const packet of value.aiSourcePackets) {
53532
- (0, contract_1.assertCanonicalSourcePacket)(packet, void 0, false);
54023
+ (0, contract_1.assertCanonicalSourcePacket)(packet, void 0, false, value.verifiedFactualContext, value.factualProvenance);
53533
54024
  seenPrompts.add(String(packet.prompt_id));
53534
54025
  }
53535
54026
  if (seenPrompts.size !== 6 || contract_1.PROMPT_IDS.some((promptId) => !seenPrompts.has(promptId)))
@@ -53550,8 +54041,6 @@ var require_pre_ai_contract = __commonJS({
53550
54041
  throw new Error("PRE_AI_PACKAGE_TESTIMONIAL_COUNT_INVALID");
53551
54042
  if (!(0, contract_1.isObject)(value.frozenCountEvidence) || value.frozenCountEvidence.canonical_fields !== 76 || value.frozenCountEvidence.active_custom_values !== 67 || value.frozenCountEvidence.automated_ai_prompt_groups !== 6 || value.frozenCountEvidence.automated_ai_output_fields !== 17)
53552
54043
  throw new Error("PRE_AI_PACKAGE_FROZEN_COUNTS_INVALID");
53553
- if (!(0, contract_1.isObject)(value.verifiedFactualContext) || !(0, contract_1.isObject)(value.verifiedFactualContext.values) || !(0, contract_1.isObject)(value.verifiedFactualContext.evidence))
53554
- throw new Error("PRE_AI_PACKAGE_VERIFIED_CONTEXT_INVALID");
53555
54044
  const narrativePath = containsFinalNarrative(value.factualCanonicalValues);
53556
54045
  if (narrativePath)
53557
54046
  throw new Error(`PRE_AI_PACKAGE_FINAL_NARRATIVE_PRESENT:${narrativePath}`);
@@ -53613,6 +54102,7 @@ var require_transform_narrative_job = __commonJS({
53613
54102
  var pieces_framework_12 = require_src2();
53614
54103
  var pieces_common_1 = require_src4();
53615
54104
  var contract_1 = require_contract();
54105
+ var pre_ai_contract_1 = require_pre_ai_contract();
53616
54106
  var output_schemas_1 = require_output_schemas();
53617
54107
  var PRIVATE_RUNTIME_URL = "http://coach-migration-runtime:3010/narrative/transform";
53618
54108
  exports2.transformNarrativeJob = (0, pieces_framework_12.createAction)({
@@ -53639,13 +54129,15 @@ var require_transform_narrative_job = __commonJS({
53639
54129
  options: { disabled: false, options: contract_1.PROMPT_IDS.map((value) => ({ label: value, value })) }
53640
54130
  }),
53641
54131
  source_packet: pieces_framework_12.Property.Json({ displayName: "Canonical Source Packet", description: "Exactly one packet from Extract Canonical PREAI Package.", required: true }),
53642
- verified_factual_context: pieces_framework_12.Property.Json({ displayName: "Verified Factual Context", description: "The verifiedFactualContext object from the same PREAI package. It is filtered to the prompt allowlist.", required: true }),
54132
+ verified_factual_context: pieces_framework_12.Property.Json({ displayName: "Verified Factual Context", description: "The verifiedFactualContext object from the same PREAI package. It is filtered to the prompt allowlist and enforced as owned by the supplied PREAI package (B-1).", required: true }),
54133
+ pre_ai_package: pieces_framework_12.Property.Json({ displayName: "Owning PREAI Package", description: "The full PREAI package from the same Extract Canonical PREAI Package run as the source packet; its package_digest is the ownership identity binding the packet, verified factual context, and factual provenance (B-1).", required: true }),
53643
54134
  required_output_schema: pieces_framework_12.Property.Json({ displayName: "Required Output Schema", description: "Effective schema for the selected prompt; must match the contract-derived effective set exactly.", required: true }),
53644
54135
  template_baseline: pieces_framework_12.Property.Json({ displayName: "Template Narrative Baseline", description: "Verified FOCALPOINT_STANDARD template FORM baseline with its manifest digest; form authority only, never factual source.", required: true })
53645
54136
  },
53646
54137
  outputSchema: output_schemas_1.transformNarrativeJobOutputSchema,
53647
54138
  run: async (context) => {
53648
- const job = (0, contract_1.buildBoundedNarrativeJob)(context.propsValue);
54139
+ const validatedPackage = (0, pre_ai_contract_1.validatePreAiPackage)(context.propsValue.pre_ai_package);
54140
+ const job = (0, contract_1.buildBoundedNarrativeJob)({ ...context.propsValue, pre_ai_package: validatedPackage });
53649
54141
  try {
53650
54142
  const response = await pieces_common_1.httpClient.sendRequest({
53651
54143
  method: pieces_common_1.HttpMethod.POST,
@@ -53663,12 +54155,69 @@ var require_transform_narrative_job = __commonJS({
53663
54155
  }
53664
54156
  });
53665
54157
 
54158
+ // dist/src/lib/transform-home-narrative.js
54159
+ var require_transform_home_narrative = __commonJS({
54160
+ "dist/src/lib/transform-home-narrative.js"(exports2) {
54161
+ "use strict";
54162
+ Object.defineProperty(exports2, "__esModule", { value: true });
54163
+ exports2.transformHomeNarrative = void 0;
54164
+ var pieces_framework_12 = require_src2();
54165
+ var pieces_common_1 = require_src4();
54166
+ var pre_ai_contract_1 = require_pre_ai_contract();
54167
+ var output_schemas_1 = require_output_schemas();
54168
+ var PRIVATE_RUNTIME_URL = "http://coach-migration-runtime:3010/narrative/home/transform";
54169
+ exports2.transformHomeNarrative = (0, pieces_framework_12.createAction)({
54170
+ name: "transform_home_narrative",
54171
+ displayName: "Transform Home Narrative for Review",
54172
+ description: "Builds the additive HOME_V1 request from the exact owned PREAI package, runs the fixed OpenCode provider boundary, and returns a Needs Review checkpoint.",
54173
+ auth: void 0,
54174
+ audience: "human",
54175
+ aiMetadata: {
54176
+ description: "Use before approval. Prompt, baseline, output keys, candidate set, endpoint, provider, model, and process controls are fixed and not user-selectable.",
54177
+ idempotent: true
54178
+ },
54179
+ props: {
54180
+ origin_run_id: pieces_framework_12.Property.ShortText({ displayName: "Origin Runtime Run ID", required: true }),
54181
+ origin_attempt: pieces_framework_12.Property.Number({ displayName: "Origin Attempt", required: true }),
54182
+ event_identity: pieces_framework_12.Property.ShortText({ displayName: "Origin Event Identity", required: true }),
54183
+ board_id: pieces_framework_12.Property.ShortText({ displayName: "Monday Board ID", required: true }),
54184
+ item_id: pieces_framework_12.Property.ShortText({ displayName: "Monday Item ID", required: true }),
54185
+ pre_ai_package: pieces_framework_12.Property.Json({
54186
+ displayName: "Owning PREAI Package",
54187
+ description: "The exact digest-bound PREAI package from the same migration execution. Home verified context is derived server-side from this package.",
54188
+ required: true
54189
+ })
54190
+ },
54191
+ outputSchema: output_schemas_1.transformHomeNarrativeOutputSchema,
54192
+ run: async (context) => {
54193
+ const preAiPackage = (0, pre_ai_contract_1.validatePreAiPackage)(context.propsValue.pre_ai_package);
54194
+ const response = await pieces_common_1.httpClient.sendRequest({
54195
+ method: pieces_common_1.HttpMethod.POST,
54196
+ url: PRIVATE_RUNTIME_URL,
54197
+ headers: { "Content-Type": "application/json" },
54198
+ body: {
54199
+ origin_run_id: context.propsValue.origin_run_id,
54200
+ origin_attempt: context.propsValue.origin_attempt,
54201
+ event_identity: context.propsValue.event_identity,
54202
+ board_id: context.propsValue.board_id,
54203
+ item_id: context.propsValue.item_id,
54204
+ pre_ai_package: preAiPackage
54205
+ },
54206
+ timeout: 125e3
54207
+ });
54208
+ return response.body;
54209
+ }
54210
+ });
54211
+ }
54212
+ });
54213
+
53666
54214
  // dist/src/index.js
53667
54215
  Object.defineProperty(exports, "__esModule", { value: true });
53668
54216
  exports.coachMigrationAi = void 0;
53669
54217
  var pieces_framework_1 = require_src2();
53670
54218
  var extract_pre_ai_package_1 = require_extract_pre_ai_package();
53671
54219
  var transform_narrative_job_1 = require_transform_narrative_job();
54220
+ var transform_home_narrative_1 = require_transform_home_narrative();
53672
54221
  exports.coachMigrationAi = (0, pieces_framework_1.createPiece)({
53673
54222
  displayName: "Coach Migration AI",
53674
54223
  description: "Builds canonical PREAI packages and invokes strict, bounded coach narrative jobs through the private migration runtime.",
@@ -53677,7 +54226,7 @@ exports.coachMigrationAi = (0, pieces_framework_1.createPiece)({
53677
54226
  auth: void 0,
53678
54227
  minimumSupportedRelease: "0.36.0",
53679
54228
  maximumSupportedRelease: "0.999.999",
53680
- actions: [extract_pre_ai_package_1.extractPreAiPackage, transform_narrative_job_1.transformNarrativeJob],
54229
+ actions: [extract_pre_ai_package_1.extractPreAiPackage, transform_narrative_job_1.transformNarrativeJob, transform_home_narrative_1.transformHomeNarrative],
53681
54230
  triggers: []
53682
54231
  });
53683
54232
  /*! Bundled license information: