// ../core/src/contextQuery/types.ts
var CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION = 1;
// ../core/src/contextQuery/builders.ts
function uniqueContextQueryStrings(values) {
  return Array.from(new Set(values.filter((value) => typeof value === "string" && value.length > 0)));
}
function definedRecord(record) {
  return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined));
}
function buildContextQueryAuthorityV1(reasonCodes = []) {
  return {
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_authority",
    noAuthority: true,
    reportOnly: true,
    advisoryOnly: true,
    noApply: true,
    noPromotion: true,
    applyAvailable: false,
    promotionAvailable: false,
    writesAvailable: false,
    providerWritesAvailable: false,
    memoryPromotionAvailable: false,
    grantsSourceWriteAuthority: false,
    grantsProviderExecutionAuthority: false,
    grantsTruthPromotionAuthority: false,
    grantsMemoryPromotionAuthority: false,
    grantsApplyAuthority: false,
    authorityBoundary: [
      "read_explain_only",
      "context_handoff_only",
      "review_evidence_only",
      "impact_evidence_only",
      "domain_read_model_only"
    ],
    domainReadModelsUnchanged: true,
    reasonCodes: uniqueContextQueryStrings(["authority:no_authority", "authority:no_apply", "authority:no_promotion", ...reasonCodes])
  };
}
function buildContextQueryFreshnessV1(args = {}) {
  const state = args.stale ? "stale" : args.sourceFresh === true ? "fresh" : args.partial ? "partial" : args.readiness === "ready" || args.readiness === "context_ready" ? "likely_fresh" : args.sourceFresh === false ? "stale" : "unknown";
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_freshness",
    state,
    readiness: args.readiness,
    generatedAt: args.generatedAt,
    updatedAt: args.updatedAt,
    watermark: args.watermark,
    watermarks: args.watermarks && args.watermarks.length > 0 ? uniqueContextQueryStrings(args.watermarks) : undefined,
    readinessRef: args.readinessRef,
    contentHash: args.contentHash,
    contentHashes: args.contentHashes && args.contentHashes.length > 0 ? uniqueContextQueryStrings(args.contentHashes) : undefined,
    epoch: args.epoch,
    sourceFresh: args.sourceFresh,
    reasonCodes: uniqueContextQueryStrings([`freshness:${state}`, ...args.reasonCodes ?? []])
  });
}
function buildContextQueryProvenanceV1(args) {
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_provenance",
    providerId: args.providerId,
    sources: uniqueContextQueryStrings(args.sources ?? []),
    receiptRefs: args.receiptRefs && args.receiptRefs.length > 0 ? uniqueContextQueryStrings(args.receiptRefs) : undefined,
    trailRefs: args.trailRefs && args.trailRefs.length > 0 ? uniqueContextQueryStrings(args.trailRefs) : undefined,
    contentHashes: args.contentHashes && args.contentHashes.length > 0 ? uniqueContextQueryStrings(args.contentHashes) : undefined,
    watermarks: args.watermarks && args.watermarks.length > 0 ? uniqueContextQueryStrings(args.watermarks) : undefined,
    readinessRef: args.readinessRef,
    receipts: args.receipts,
    generatedAt: args.generatedAt,
    reasonCodes: uniqueContextQueryStrings([`provider:${args.providerId}`, ...args.reasonCodes ?? []])
  });
}
function buildContextQuerySourceScopeV1(args) {
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_source_scope",
    source: args.source,
    scopes: uniqueContextQueryStrings(args.scopes ?? []),
    searchedFiles: args.searchedFiles,
    matchedFiles: args.matchedFiles,
    complete: args.complete,
    truncated: args.truncated,
    indexFresh: args.indexFresh,
    reasonCodes: uniqueContextQueryStrings([`source:${args.source}`, ...args.reasonCodes ?? []])
  });
}
function buildContextQueryResultRefV1(args) {
  const refId = args.refId ?? (args.path ? `file:${args.path}` : args.label ?? "unknown");
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_result_ref",
    refId,
    path: args.path,
    refKind: args.refKind,
    label: args.label,
    rank: args.rank,
    score: args.score,
    source: args.source,
    reasonCodes: uniqueContextQueryStrings(args.reasonCodes ?? []),
    evidenceRefs: args.evidenceRefs && args.evidenceRefs.length > 0 ? uniqueContextQueryStrings(args.evidenceRefs) : undefined,
    suggestedReadSlices: args.suggestedReadSlices && args.suggestedReadSlices.length > 0 ? args.suggestedReadSlices : undefined,
    metadata: args.metadata
  });
}
function buildContextQueryTruncationV1(args) {
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_truncation",
    sourceKey: args.sourceKey,
    truncated: args.truncated,
    limit: args.limit,
    returned: args.returned,
    omittedCount: args.omittedCount,
    reason: args.reason,
    reasonCodes: uniqueContextQueryStrings([args.truncated ? "truncation:truncated" : "truncation:complete", ...args.reasonCodes ?? []])
  });
}
function buildContextQueryMissV1(args) {
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_miss",
    ref: args.ref,
    claim: args.claim,
    query: args.query,
    scope: args.scope,
    reason: args.reason,
    confidence: args.confidence,
    reasonCodes: uniqueContextQueryStrings(args.reasonCodes ?? [])
  });
}
function buildContextQueryRequestSummaryV1(args) {
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_request_summary",
    surface: args.surface,
    query: args.query,
    goal: args.goal,
    repoPath: args.repoPath,
    repoId: args.repoId,
    projectId: args.projectId,
    filters: args.filters,
    limit: args.limit,
    requestedAt: args.requestedAt,
    reasonCodes: uniqueContextQueryStrings([`surface:${args.surface}`, ...args.reasonCodes ?? []])
  });
}
function buildContextQueryExplainV1(args = {}) {
  return definedRecord({
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "context_query_explain",
    summary: args.summary,
    reasonCodes: uniqueContextQueryStrings(args.reasonCodes ?? []),
    ranking: args.ranking,
    candidateAccounting: args.candidateAccounting,
    graphExpansionReceipt: args.graphExpansionReceipt,
    coverageReceipt: args.coverageReceipt,
    liveEvidence: args.liveEvidence,
    noLive: args.noLive,
    nextReadPlan: args.nextReadPlan,
    warnings: args.warnings && args.warnings.length > 0 ? uniqueContextQueryStrings(args.warnings) : undefined
  });
}
function buildContextQueryEnvelopeV1(args) {
  const authority = args.authority ?? buildContextQueryAuthorityV1();
  return {
    schemaVersion: CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION,
    kind: "rhei_context_query_envelope",
    envelopeId: args.envelopeId,
    surface: args.surface,
    request: args.request,
    authority,
    freshness: args.freshness ?? buildContextQueryFreshnessV1(),
    provenance: args.provenance,
    sourceScopes: args.sourceScopes ?? [],
    results: args.results ?? [],
    explain: args.explain ?? buildContextQueryExplainV1(),
    truncation: args.truncation ?? [],
    misses: args.misses ?? [],
    warnings: uniqueContextQueryStrings(args.warnings ?? []),
    generatedAt: args.generatedAt ?? Date.now()
  };
}
// ../core/src/contextQuery/runtime.ts
function isRecord(value) {
  return value !== null && typeof value === "object" && !Array.isArray(value);
}
function isString(value) {
  return typeof value === "string" && value.length > 0;
}
function isStringArray(value) {
  return Array.isArray(value) && value.every((item) => typeof item === "string");
}
function isNumber(value) {
  return typeof value === "number" && Number.isFinite(value);
}
function hasSchemaKind(record, kind) {
  return record["schemaVersion"] === CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION && record["kind"] === kind;
}
function hasRequiredAuthorityBoundary(value) {
  return isStringArray(value) && value.length > 0;
}
function isContextQueryAuthorityV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_authority"))
    return false;
  return value["noAuthority"] === true && value["reportOnly"] === true && value["advisoryOnly"] === true && value["noApply"] === true && value["noPromotion"] === true && value["applyAvailable"] === false && value["promotionAvailable"] === false && value["writesAvailable"] === false && value["providerWritesAvailable"] === false && value["memoryPromotionAvailable"] === false && value["grantsSourceWriteAuthority"] === false && value["grantsProviderExecutionAuthority"] === false && value["grantsTruthPromotionAuthority"] === false && value["grantsMemoryPromotionAuthority"] === false && value["grantsApplyAuthority"] === false && value["domainReadModelsUnchanged"] === true && hasRequiredAuthorityBoundary(value["authorityBoundary"]) && isStringArray(value["reasonCodes"]);
}
function isContextQueryRequestSummaryV1(value, surface) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_request_summary"))
    return false;
  return isString(value["surface"]) && value["surface"] === surface && isStringArray(value["reasonCodes"]);
}
function isContextQueryFreshnessV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_freshness"))
    return false;
  return isString(value["state"]) && isStringArray(value["reasonCodes"]);
}
function isContextQueryProvenanceV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_provenance"))
    return false;
  return isString(value["providerId"]) && isStringArray(value["sources"]) && (value["receiptRefs"] === undefined || isStringArray(value["receiptRefs"])) && (value["trailRefs"] === undefined || isStringArray(value["trailRefs"])) && (value["contentHashes"] === undefined || isStringArray(value["contentHashes"])) && (value["watermarks"] === undefined || isStringArray(value["watermarks"])) && isStringArray(value["reasonCodes"]);
}
function isContextQuerySourceScopeV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_source_scope"))
    return false;
  return isString(value["source"]) && isStringArray(value["scopes"]) && isStringArray(value["reasonCodes"]);
}
function isContextQueryResultRefV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_result_ref"))
    return false;
  return isString(value["refId"]) && (value["rank"] === undefined || isNumber(value["rank"])) && (value["score"] === undefined || isNumber(value["score"])) && isStringArray(value["reasonCodes"]) && (value["evidenceRefs"] === undefined || isStringArray(value["evidenceRefs"]));
}
function isContextQueryExplainV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_explain"))
    return false;
  return isStringArray(value["reasonCodes"]) && (value["warnings"] === undefined || isStringArray(value["warnings"]));
}
function isContextQueryTruncationV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_truncation"))
    return false;
  return typeof value["truncated"] === "boolean" && isStringArray(value["reasonCodes"]);
}
function isContextQueryMissV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "context_query_miss"))
    return false;
  return isStringArray(value["reasonCodes"]);
}
function isContextQueryEnvelopeV1(value) {
  if (!isRecord(value) || !hasSchemaKind(value, "rhei_context_query_envelope"))
    return false;
  return isString(value["envelopeId"]) && isString(value["surface"]) && isContextQueryRequestSummaryV1(value["request"], value["surface"]) && isContextQueryAuthorityV1(value["authority"]) && isContextQueryFreshnessV1(value["freshness"]) && isContextQueryProvenanceV1(value["provenance"]) && Array.isArray(value["sourceScopes"]) && value["sourceScopes"].every(isContextQuerySourceScopeV1) && Array.isArray(value["results"]) && value["results"].every(isContextQueryResultRefV1) && isContextQueryExplainV1(value["explain"]) && Array.isArray(value["truncation"]) && value["truncation"].every(isContextQueryTruncationV1) && Array.isArray(value["misses"]) && value["misses"].every(isContextQueryMissV1) && isStringArray(value["warnings"]) && isNumber(value["generatedAt"]);
}
function assertContextQueryEnvelopeV1(value) {
  if (isContextQueryEnvelopeV1(value))
    return value;
  throw new TypeError("Invalid ContextQueryEnvelopeV1 runtime payload");
}
// ../core/src/contextQuery/provenance.ts
function asRecord(value) {
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
}
function directString(value) {
  return typeof value === "string" && value.length > 0 ? [value] : [];
}
function stringList(value) {
  if (!Array.isArray(value))
    return directString(value);
  return uniqueContextQueryStrings(value.flatMap((item) => directString(item)));
}
function refsFromRecord(record, keys) {
  const allowedKeys = new Set(keys);
  return Object.entries(record).flatMap(([key, value]) => {
    if (!allowedKeys.has(key))
      return [];
    if (Array.isArray(value)) {
      return value.flatMap((item) => {
        if (typeof item === "string")
          return [item];
        const itemRecord = asRecord(item);
        return itemRecord ? refsFromRecord(itemRecord, keys) : [];
      });
    }
    return stringList(value);
  });
}
function normalizeRefs(values, keys) {
  return uniqueContextQueryStrings(values.flatMap((value) => {
    if (Array.isArray(value))
      return normalizeRefs(value, keys);
    if (typeof value === "string")
      return [value];
    const record = asRecord(value);
    return record ? refsFromRecord(record, keys) : [];
  }));
}
function normalizeReceiptRefs(...values) {
  return normalizeRefs(values, [
    "receiptRefs",
    "receipts",
    "sourceReceipts",
    "sourceReceiptRefs",
    "receiptRef",
    "receiptId",
    "id",
    "ref"
  ]);
}
function normalizeEvidenceRefs(...values) {
  return normalizeRefs(values, [
    "evidenceRefs",
    "evidenceRef",
    "sourceEvidenceRefs",
    "sourceReceipts",
    "receiptRefs",
    "receipts",
    "receiptRef",
    "receiptId",
    "id",
    "ref"
  ]);
}
function normalizeTrailRefs(...values) {
  return normalizeRefs(values, [
    "trailRefs",
    "trailRef",
    "trailId",
    "codeTrailRefs",
    "codeTrailRef",
    "refs",
    "id",
    "ref"
  ]);
}
// ../core/src/contextQuery/adapters/shared.ts
function asRecord2(value) {
  return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
}
function asRecords(value) {
  return Array.isArray(value) ? value.filter((item) => Boolean(asRecord2(item))) : [];
}
function sourceForLocalIndex(coverageReceipt) {
  return coverageReceipt?.indexFresh === false ? "local_mcp" : "local_mcp";
}
function coverageSourceScope(coverageReceipt, source) {
  if (!coverageReceipt) {
    return buildContextQuerySourceScopeV1({ source, reasonCodes: ["coverage:missing"] });
  }
  return buildContextQuerySourceScopeV1({
    source,
    scopes: coverageReceipt.searchedScopes,
    searchedFiles: coverageReceipt.searchedFiles,
    matchedFiles: coverageReceipt.matchedFiles,
    complete: coverageReceipt.truncated === false,
    truncated: coverageReceipt.truncated,
    indexFresh: coverageReceipt.indexFresh,
    reasonCodes: coverageReceipt.reasonCodes
  });
}
function coverageTruncation(coverageReceipt) {
  return [buildContextQueryTruncationV1({
    sourceKey: "coverage_receipt",
    truncated: coverageReceipt?.truncated === true,
    omittedCount: coverageReceipt?.omittedCount,
    reason: coverageReceipt?.truncated ? "coverage receipt reported truncation" : undefined,
    reasonCodes: coverageReceipt?.reasonCodes
  })];
}
function coverageMisses(coverageReceipt) {
  return (coverageReceipt?.absenceClaims ?? []).map((claim) => buildContextQueryMissV1({
    claim: claim.claim,
    query: claim.query,
    scope: claim.scope,
    confidence: claim.confidence,
    reason: "absence_claim",
    reasonCodes: claim.reasonCodes
  }));
}
function recordString(record, key) {
  const value = record?.[key];
  return typeof value === "string" && value.length > 0 ? value : undefined;
}
function recordNumber(record, key) {
  const value = record?.[key];
  return typeof value === "number" && Number.isFinite(value) ? value : undefined;
}
function stringList2(value) {
  if (!Array.isArray(value))
    return [];
  return uniqueContextQueryStrings(value.filter((item) => typeof item === "string" && item.length > 0));
}
function pathRefsFromRecords(records, keys) {
  return uniqueContextQueryStrings(records.flatMap((record) => keys.flatMap((key) => {
    const value = record[key];
    if (typeof value === "string")
      return [value];
    if (Array.isArray(value))
      return value.filter((item) => typeof item === "string");
    return [];
  })));
}
function receiptsFromUnknown(value) {
  return normalizeReceiptRefs(value);
}

// ../core/src/contextQuery/adapters/mcpSearch.ts
function buildMcpSearchContextQueryEnvelopeV1(args) {
  const generatedAt = args.generatedAt ?? Date.now();
  const source = sourceForLocalIndex(args.coverageReceipt);
  const results = (args.results ?? []).map((result, index) => buildContextQueryResultRefV1({
    refId: result.refId,
    path: result.path,
    refKind: result.kind,
    rank: index + 1,
    score: result.score,
    source,
    reasonCodes: result.reasonCodes,
    evidenceRefs: result.evidenceRefs,
    suggestedReadSlices: result.suggestedReadSlices,
    metadata: {
      surfaceKind: result.surfaceKind,
      matchMode: result.matchMode,
      matchCount: result.matchCount,
      matchCountBasis: result.matchCountBasis
    }
  }));
  const warnings = uniqueContextQueryStrings(args.warnings ?? []);
  return buildContextQueryEnvelopeV1({
    envelopeId: `context-query:mcp-search:${args.searchId ?? args.sessionId ?? generatedAt}`,
    surface: "mcp_search",
    generatedAt,
    request: buildContextQueryRequestSummaryV1({
      surface: "mcp_search",
      query: args.query,
      repoPath: args.repoPath,
      limit: args.searchLimit,
      filters: {
        purpose: args.purpose,
        profile: args.profile,
        searchMode: args.searchMode,
        effectiveResultLimit: args.effectiveResultLimit
      },
      requestedAt: generatedAt
    }),
    freshness: buildContextQueryFreshnessV1({
      generatedAt,
      sourceFresh: args.coverageReceipt?.indexFresh,
      partial: args.coverageReceipt?.truncated,
      reasonCodes: args.coverageReceipt?.reasonCodes
    }),
    provenance: buildContextQueryProvenanceV1({
      providerId: "rhei_code_search",
      sources: [source],
      generatedAt,
      receipts: {
        coverageReceipt: args.coverageReceipt,
        candidateAccounting: args.candidateAccounting,
        graphExpansionReceipt: args.graphExpansionReceipt,
        rankingNoLive: args.rankingNoLive,
        liveEvidence: args.liveEvidence
      }
    }),
    sourceScopes: [coverageSourceScope(args.coverageReceipt, source)],
    results,
    explain: buildContextQueryExplainV1({
      summary: `${args.returnedResultCount ?? results.length}/${args.resultCount ?? results.length} search results returned`,
      reasonCodes: uniqueContextQueryStrings([...args.coverageReceipt?.reasonCodes ?? [], ...args.warnings ?? []]),
      ranking: {
        resultCount: args.resultCount,
        returnedResultCount: args.returnedResultCount,
        omittedResultCount: args.omittedResultCount,
        totalMatchCount: args.totalMatchCount,
        returnedMatchCount: args.returnedMatchCount,
        rankingNoLive: args.rankingNoLive
      },
      candidateAccounting: args.candidateAccounting,
      graphExpansionReceipt: args.graphExpansionReceipt,
      coverageReceipt: args.coverageReceipt,
      liveEvidence: args.liveEvidence,
      noLive: args.rankingNoLive,
      nextReadPlan: args.nextReadPlan,
      warnings
    }),
    truncation: coverageTruncation(args.coverageReceipt),
    misses: coverageMisses(args.coverageReceipt),
    warnings
  });
}
// ../core/src/contextQuery/adapters/contextForGoal.ts
function buildContextForGoalContextQueryEnvelopeV1(args) {
  const coverageReceipt = args.coverageReceipt;
  const generatedAt = args.generatedAt ?? coverageReceipt?.generatedAt ?? args.snapshot?.generatedAt ?? Date.now();
  const source = sourceForLocalIndex(coverageReceipt);
  const symbolResults = (args.selection?.importantSymbols ?? []).map((symbol, index) => buildContextQueryResultRefV1({
    refId: symbol.refId,
    path: symbol.path,
    refKind: symbol.kind ?? "symbol",
    label: symbol.name,
    rank: index + 1,
    source,
    reasonCodes: ["selection:important_symbol"]
  }));
  const fileRefs = uniqueContextQueryStrings([
    ...args.selectedRefIds ?? [],
    ...args.selection?.exactFiles ?? [],
    ...args.selection?.relatedTests ?? [],
    ...args.selection?.docsEvidence ?? []
  ]);
  const fileResults = fileRefs.map((path, index) => buildContextQueryResultRefV1({
    refId: path.startsWith("file:") ? path : `file:${path}`,
    path: path.startsWith("file:") ? path.slice("file:".length) : path,
    refKind: "file",
    rank: symbolResults.length + index + 1,
    source,
    reasonCodes: ["selection:context_for_goal"]
  }));
  const warnings = uniqueContextQueryStrings(args.warnings ?? []);
  return buildContextQueryEnvelopeV1({
    envelopeId: `context-query:mcp-context-for-goal:${args.requestId ?? generatedAt}`,
    surface: "mcp_context_for_goal",
    generatedAt,
    request: buildContextQueryRequestSummaryV1({
      surface: "mcp_context_for_goal",
      goal: args.goal,
      repoPath: args.repoPath,
      requestedAt: generatedAt
    }),
    freshness: buildContextQueryFreshnessV1({
      generatedAt,
      sourceFresh: coverageReceipt?.indexFresh,
      partial: coverageReceipt?.truncated,
      readiness: typeof args.observability?.["readinessStatus"] === "string" ? args.observability["readinessStatus"] : undefined,
      reasonCodes: coverageReceipt?.reasonCodes
    }),
    provenance: buildContextQueryProvenanceV1({
      providerId: "rhei_code_context_for_goal",
      sources: [source, "code_insights"],
      generatedAt,
      receipts: {
        coverageReceipt,
        retrievalAccounting: args.retrievalAccounting,
        graphExpansionReceipt: args.graphExpansionReceipt,
        repoIntelligenceStatus: args.repoIntelligenceStatus,
        editReadiness: args.editReadiness,
        observability: args.observability
      }
    }),
    sourceScopes: [coverageSourceScope(coverageReceipt, source)],
    results: [...fileResults, ...symbolResults],
    explain: buildContextQueryExplainV1({
      summary: args.goal ? `Context-for-goal envelope for: ${args.goal}` : "Context-for-goal envelope",
      reasonCodes: uniqueContextQueryStrings([...coverageReceipt?.reasonCodes ?? [], ...args.warnings ?? []]),
      candidateAccounting: args.retrievalAccounting,
      graphExpansionReceipt: args.graphExpansionReceipt,
      coverageReceipt,
      noLive: asRecord2(args.observability?.["noLive"]),
      nextReadPlan: asRecords(args.relatedFiles?.["nextReadPlan"]),
      warnings
    }),
    truncation: coverageTruncation(coverageReceipt),
    misses: coverageMisses(coverageReceipt),
    warnings
  });
}
// ../core/src/contextQuery/adapters/codeMap.ts
function buildCodeMapContextQueryEnvelopeV1(snapshot) {
  const sourceScopes = snapshot.sourceWatermarks.map((watermark) => buildContextQuerySourceScopeV1({
    source: watermark.kind,
    scopes: [watermark.sourceKey],
    complete: watermark.complete,
    truncated: !watermark.complete,
    reasonCodes: ["code_map:source_watermark"]
  }));
  const results = snapshot.tiles.map((tile, index) => buildContextQueryResultRefV1({
    refId: tile.primaryRef.id,
    path: tile.primaryRef.path,
    refKind: tile.primaryRef.kind,
    label: tile.title,
    rank: index + 1,
    score: tile.controlWeight,
    source: tile.primaryRef.authority,
    reasonCodes: tile.reasonCodes,
    metadata: {
      tileId: tile.id,
      tileKind: tile.kind,
      state: tile.state,
      confidence: tile.confidence
    }
  }));
  const truncation = snapshot.truncation.map((item) => buildContextQueryTruncationV1({
    sourceKey: item.sourceKey,
    truncated: item.truncated,
    limit: item.limit,
    returned: item.returned,
    reason: item.reason
  }));
  const firstWatermark = snapshot.sourceWatermarks[0];
  const watermarks = uniqueContextQueryStrings(snapshot.sourceWatermarks.map((watermark) => watermark.cursor ?? watermark.sourceKey));
  return buildContextQueryEnvelopeV1({
    envelopeId: `context-query:code-map:${snapshot.projectId}:${snapshot.generatedAt}`,
    surface: "code_map",
    generatedAt: snapshot.generatedAt,
    request: buildContextQueryRequestSummaryV1({
      surface: "code_map",
      projectId: snapshot.projectId,
      repoId: snapshot.scope.repoId,
      filters: {
        surface: snapshot.scope.surface,
        groupBy: snapshot.scope.groupBy,
        pathPrefix: snapshot.scope.pathPrefix,
        focusedModuleId: snapshot.scope.focusedModuleId,
        selectedModuleIds: snapshot.scope.selectedModuleIds
      },
      requestedAt: snapshot.generatedAt,
      reasonCodes: snapshot.readiness.reasonCodes
    }),
    freshness: buildContextQueryFreshnessV1({
      readiness: snapshot.readiness.state,
      generatedAt: snapshot.generatedAt,
      updatedAt: firstWatermark?.updatedAt,
      watermark: firstWatermark?.cursor ?? firstWatermark?.sourceKey,
      watermarks,
      sourceFresh: snapshot.readiness.state === "ready" ? true : undefined,
      partial: snapshot.readiness.state === "partial" || snapshot.truncation.some((item) => item.truncated),
      reasonCodes: snapshot.readiness.reasonCodes
    }),
    provenance: buildContextQueryProvenanceV1({
      providerId: "code_map_adapter",
      sources: uniqueContextQueryStrings(snapshot.sources.map((source) => source.kind)),
      generatedAt: snapshot.generatedAt,
      receipts: {
        readiness: snapshot.readiness,
        sourceWatermarks: snapshot.sourceWatermarks,
        truncation: snapshot.truncation
      },
      watermarks,
      reasonCodes: snapshot.readiness.reasonCodes
    }),
    sourceScopes,
    results,
    explain: buildContextQueryExplainV1({
      summary: snapshot.readiness.title,
      reasonCodes: snapshot.readiness.reasonCodes,
      ranking: {
        tileCount: snapshot.tiles.length,
        relationshipCount: snapshot.relationships.length,
        gapCount: snapshot.gaps.length
      },
      warnings: snapshot.gaps.map((gap) => gap.title)
    }),
    truncation,
    misses: snapshot.gaps.map((gap) => buildContextQueryMissV1({
      ref: gap.ref?.id,
      claim: gap.title,
      reason: gap.kind,
      reasonCodes: [gap.severity]
    })),
    warnings: snapshot.gaps.map((gap) => gap.title)
  });
}
// ../core/src/contextQuery/adapters/review.ts
function buildReviewIntelligenceContextQueryEnvelopeV1(args) {
  const generatedAt = args.generatedAt ?? Date.now();
  const reviewDiffs = asRecords(args.reviewDiffs);
  const outcomes = asRecords(args.outcomes);
  const ranking = asRecord2(args.ranking);
  const ledger = asRecord2(args.ledger);
  const memoryCandidateSet = asRecord2(args.memoryCandidateSet);
  const reviewRoomSummary = asRecord2(args.reviewRoomSummary);
  const editReadiness = asRecord2(args.editReadiness);
  const refinementIntelligence = asRecord2(args.refinementIntelligence);
  const pathSummaryResults = reviewDiffs.flatMap((diff, diffIndex) => {
    const pathSummaries = asRecords(diff["pathSummaries"]);
    if (pathSummaries.length === 0) {
      const fallbackId = recordString(diff, "reviewDiffId") ?? recordString(diff, "diffId") ?? `review-diff:${diffIndex + 1}`;
      return [buildContextQueryResultRefV1({
        refId: fallbackId,
        refKind: "review_diff",
        label: recordString(diff, "title") ?? fallbackId,
        rank: diffIndex + 1,
        source: "pr_review_intelligence",
        reasonCodes: ["review:diff"],
        evidenceRefs: receiptsFromUnknown(diff["sourceReceipts"])
      })];
    }
    return pathSummaries.map((summary, pathIndex) => buildContextQueryResultRefV1({
      refId: recordString(summary, "refId") ?? recordString(summary, "path") ?? `review-diff:${diffIndex + 1}:path:${pathIndex + 1}`,
      path: recordString(summary, "path"),
      refKind: "review_path_summary",
      label: recordString(summary, "title") ?? recordString(summary, "path"),
      rank: pathIndex + 1,
      score: recordNumber(summary, "riskScore"),
      source: "pr_review_intelligence",
      reasonCodes: uniqueContextQueryStrings(["review:path_summary", recordString(summary, "riskLevel")]),
      evidenceRefs: normalizeEvidenceRefs(summary["receiptRefs"], summary["evidenceRefs"]),
      metadata: {
        reviewDiffId: recordString(diff, "reviewDiffId") ?? recordString(diff, "diffId"),
        riskLevel: recordString(summary, "riskLevel"),
        stale: summary["stale"]
      }
    }));
  });
  const rankedProposalResults = asRecords(ranking?.["rankedProposals"] ?? ranking?.["proposals"]).map((proposal, index) => buildContextQueryResultRefV1({
    refId: recordString(proposal, "proposalId") ?? recordString(proposal, "id") ?? `ranked-proposal:${index + 1}`,
    refKind: "review_ranked_proposal",
    label: recordString(proposal, "title") ?? recordString(proposal, "recommendedAction") ?? "ranked proposal",
    rank: recordNumber(proposal, "rank") ?? index + 1,
    score: recordNumber(proposal, "score"),
    source: "pr_review_intelligence",
    reasonCodes: uniqueContextQueryStrings(["review:ranking", recordString(proposal, "recommendedAction")]),
    evidenceRefs: normalizeEvidenceRefs(proposal["receiptRefs"], proposal["evidenceRefs"])
  }));
  const outcomeResults = outcomes.map((outcome, index) => buildContextQueryResultRefV1({
    refId: recordString(outcome, "outcomeId") ?? recordString(outcome, "id") ?? `review-outcome:${index + 1}`,
    refKind: "review_outcome",
    label: recordString(outcome, "verdict") ?? recordString(outcome, "status") ?? "review outcome",
    rank: index + 1,
    source: "pr_review_intelligence",
    reasonCodes: uniqueContextQueryStrings(["review:outcome", recordString(outcome, "verdict"), recordString(outcome, "status")]),
    evidenceRefs: normalizeEvidenceRefs(outcome["receiptRefs"], outcome["evidenceRefs"])
  }));
  const resultPaths = uniqueContextQueryStrings(pathSummaryResults.map((result) => result.path));
  const sourceReceiptRefs = normalizeReceiptRefs(...reviewDiffs.map((diff) => diff["sourceReceipts"]), ...reviewDiffs.map((diff) => diff["receiptRefs"]), ...reviewDiffs.map((diff) => diff["evidenceRefs"]), ...outcomes.map((outcome) => outcome["receiptRefs"]), ...outcomes.map((outcome) => outcome["evidenceRefs"]));
  const warnings = args.warnings ?? [];
  return buildContextQueryEnvelopeV1({
    envelopeId: `context-query:review:${args.mode}:${generatedAt}`,
    surface: "review_intelligence",
    generatedAt,
    request: buildContextQueryRequestSummaryV1({
      surface: "review_intelligence",
      filters: { mode: args.mode, reviewDiffCount: reviewDiffs.length, outcomeCount: outcomes.length },
      requestedAt: generatedAt,
      reasonCodes: ["review:bridge"]
    }),
    freshness: buildContextQueryFreshnessV1({
      generatedAt,
      sourceFresh: editReadiness?.["status"] === "ready" ? true : undefined,
      partial: warnings.length > 0,
      reasonCodes: uniqueContextQueryStrings(["review:freshness_from_payload", recordString(editReadiness, "status")])
    }),
    provenance: buildContextQueryProvenanceV1({
      providerId: "review_intelligence_bridge",
      sources: ["pr_review_intelligence"],
      generatedAt,
      receipts: {
        reviewDiffs: reviewDiffs.length,
        outcomes: outcomes.length,
        sourceReceiptRefs,
        ledger,
        memoryCandidateSet,
        reviewRoomSummary,
        refinementIntelligence,
        editReadiness
      },
      receiptRefs: sourceReceiptRefs,
      reasonCodes: ["review:source_receipts"]
    }),
    sourceScopes: [buildContextQuerySourceScopeV1({
      source: "pr_review_intelligence",
      scopes: uniqueContextQueryStrings(["review", args.mode, ...resultPaths]),
      matchedFiles: resultPaths.length || undefined,
      complete: true,
      truncated: false,
      indexFresh: undefined,
      reasonCodes: ["review:domain_payload"]
    })],
    results: [...pathSummaryResults, ...rankedProposalResults, ...outcomeResults],
    explain: buildContextQueryExplainV1({
      summary: `Review intelligence envelope for ${args.mode}`,
      reasonCodes: uniqueContextQueryStrings(["review:explain", ...warnings]),
      ranking: ranking ? { ...ranking, resultPathCount: resultPaths.length } : { resultPathCount: resultPaths.length },
      candidateAccounting: ledger ? { ledger } : undefined,
      coverageReceipt: sourceReceiptRefs.length > 0 ? { receiptRefs: sourceReceiptRefs } : undefined,
      warnings
    }),
    truncation: [buildContextQueryTruncationV1({
      sourceKey: "review_intelligence",
      truncated: false,
      returned: pathSummaryResults.length + rankedProposalResults.length + outcomeResults.length,
      reasonCodes: ["review:not_truncated_by_envelope"]
    })],
    misses: [],
    warnings
  });
}
// ../core/src/contextQuery/adapters/impact.ts
function buildImpactPredictionContextQueryEnvelopeV1(args) {
  const generatedAt = args.generatedAt ?? Date.now();
  const expectedEditScope = asRecords(args.expectedEditScope);
  const baselineRefs = asRecords(args.baselineRefs);
  const advisoryEvidence = asRecord2(args.advisoryEvidence);
  const predictedImpact = asRecord2(args.predictedImpact);
  const historicalReceipts = asRecords(args.historicalReceipts);
  const liveEvidence = asRecord2(args.liveEvidence);
  const selectedRefs = args.selectedRefs ?? [];
  const changedPaths = pathRefsFromRecords(expectedEditScope, ["path"]);
  const impactPaths = uniqueContextQueryStrings([
    ...changedPaths,
    ...selectedRefs,
    ...stringList2(predictedImpact?.["tests"]),
    ...stringList2(predictedImpact?.["docs"]),
    ...stringList2(predictedImpact?.["runtimeContracts"])
  ]);
  const receiptRefs = normalizeReceiptRefs(args.receipts, advisoryEvidence, historicalReceipts);
  const graphRefs = uniqueContextQueryStrings([...stringList2(advisoryEvidence?.["graphRefs"]), ...stringList2(predictedImpact?.["graphRefs"])]);
  const trailRefs = normalizeTrailRefs(args.trailRefs);
  return buildContextQueryEnvelopeV1({
    envelopeId: `context-query:impact:${args.predictionId}`,
    surface: "impact_prediction",
    generatedAt,
    request: buildContextQueryRequestSummaryV1({
      surface: "impact_prediction",
      filters: { sessionId: args.sessionId, proposalId: args.proposalId, riskLevel: args.riskLevel },
      requestedAt: generatedAt,
      reasonCodes: ["impact:bridge"]
    }),
    freshness: buildContextQueryFreshnessV1({
      generatedAt,
      sourceFresh: liveEvidence?.["readOnly"] === true ? true : undefined,
      partial: graphRefs.length === 0 && receiptRefs.length === 0,
      reasonCodes: ["impact:freshness_from_live_evidence"]
    }),
    provenance: buildContextQueryProvenanceV1({
      providerId: "impact_prediction_bridge",
      sources: ["code_insights", "local_mcp"],
      generatedAt,
      receipts: {
        baselineRefs,
        receiptRefs,
        trailRefs,
        graphRefs,
        liveEvidence
      },
      receiptRefs,
      trailRefs,
      reasonCodes: ["impact:receipts", "impact:trail_refs", "impact:graph_refs"]
    }),
    sourceScopes: [
      buildContextQuerySourceScopeV1({
        source: "code_insights",
        scopes: uniqueContextQueryStrings(["impact", args.sessionId, ...args.proposalId ? [args.proposalId] : []]),
        matchedFiles: changedPaths.length || undefined,
        complete: true,
        truncated: false,
        reasonCodes: ["impact:domain_payload"]
      }),
      buildContextQuerySourceScopeV1({
        source: "local_mcp",
        scopes: impactPaths,
        matchedFiles: impactPaths.length || undefined,
        complete: true,
        truncated: false,
        reasonCodes: ["impact:selected_refs"]
      })
    ],
    results: impactPaths.map((path, index) => buildContextQueryResultRefV1({
      refId: `impact-ref:${path}`,
      path,
      refKind: changedPaths.includes(path) ? "impact_changed_path" : "impact_related_path",
      label: path,
      rank: index + 1,
      score: changedPaths.includes(path) ? 1 : undefined,
      source: changedPaths.includes(path) ? "code_insights" : "local_mcp",
      reasonCodes: uniqueContextQueryStrings(["impact:ref", changedPaths.includes(path) ? "impact:changed" : "impact:related"]),
      evidenceRefs: receiptRefs
    })),
    explain: buildContextQueryExplainV1({
      summary: `Impact prediction envelope for ${args.predictionId}`,
      reasonCodes: uniqueContextQueryStrings(["impact:explain", args.riskLevel, ...args.warnings ?? []]),
      ranking: {
        riskLevel: args.riskLevel,
        confidence: args.confidence,
        changedPathCount: changedPaths.length,
        graphRefCount: graphRefs.length,
        receiptCount: receiptRefs.length,
        historicalReceiptCount: historicalReceipts.length
      },
      graphExpansionReceipt: graphRefs.length > 0 ? { graphRefs } : undefined,
      coverageReceipt: receiptRefs.length > 0 ? { receiptRefs } : undefined,
      liveEvidence,
      warnings: args.warnings
    }),
    truncation: [buildContextQueryTruncationV1({
      sourceKey: "impact_prediction",
      truncated: false,
      returned: impactPaths.length,
      reasonCodes: ["impact:not_truncated_by_envelope"]
    })],
    misses: [],
    warnings: args.warnings
  });
}
// ../core/src/contextQuery/adapters/rheiShellCodeMap.ts
function buildRheiShellCodeMapContextQueryEnvelopeV1(args) {
  const generatedAt = args.generatedAt ?? Date.now();
  const selectedTileIds = args.selectedTileIds ?? args.tiles.map((tile) => tile.id);
  const selected = args.tiles.filter((tile) => selectedTileIds.includes(tile.id));
  const warnings = args.warnings ?? [];
  return buildContextQueryEnvelopeV1({
    envelopeId: args.envelopeId ?? `context-query:rhei-shell-code-map:${args.workspaceId ?? "all"}:${generatedAt}`,
    surface: "rhei_shell_code_map",
    generatedAt,
    request: buildContextQueryRequestSummaryV1({
      surface: "rhei_shell_code_map",
      projectId: args.projectId,
      filters: { workspaceId: args.workspaceId, window: args.window, selectedTileCount: selected.length },
      requestedAt: generatedAt,
      reasonCodes: ["rhei_shell_code_map:fixture"]
    }),
    freshness: buildContextQueryFreshnessV1({
      generatedAt,
      sourceFresh: true,
      reasonCodes: ["rhei_shell_code_map:local_fixture"]
    }),
    provenance: buildContextQueryProvenanceV1({
      providerId: "rhei_shell_code_map_fixture",
      sources: ["local_mcp"],
      generatedAt,
      receipts: { tileCount: args.tiles.length, selectedTileIds, window: args.window },
      reasonCodes: ["rhei_shell_code_map:domain_fixture"]
    }),
    sourceScopes: [buildContextQuerySourceScopeV1({
      source: "local_mcp",
      scopes: uniqueContextQueryStrings(["rhei-shell", "code-map", ...args.workspaceId ? [args.workspaceId] : [], ...args.window ? [args.window] : []]),
      matchedFiles: selected.length,
      complete: selected.length === selectedTileIds.length,
      truncated: false,
      indexFresh: true,
      reasonCodes: ["rhei_shell_code_map:selected_tiles"]
    })],
    results: selected.map((tile, index) => buildContextQueryResultRefV1({
      refId: tile.id,
      path: tile.path,
      refKind: "rhei_shell_code_map_tile",
      label: tile.label,
      rank: index + 1,
      score: tile.weight,
      source: "local_mcp",
      reasonCodes: uniqueContextQueryStrings(["rhei_shell_code_map:tile", tile.group, tile.workspaceId]),
      metadata: { group: tile.group, workspaceId: tile.workspaceId, weight: tile.weight }
    })),
    explain: buildContextQueryExplainV1({
      summary: "rhei-shell Code Map explain envelope",
      reasonCodes: uniqueContextQueryStrings(["rhei_shell_code_map:explain", ...warnings]),
      ranking: { tileCount: args.tiles.length, selectedTileCount: selected.length, window: args.window },
      warnings
    }),
    truncation: [buildContextQueryTruncationV1({
      sourceKey: "rhei_shell_code_map_tiles",
      truncated: false,
      returned: selected.length,
      reasonCodes: ["rhei_shell_code_map:not_truncated_by_envelope"]
    })],
    misses: selected.length === selectedTileIds.length ? [] : [buildContextQueryMissV1({
      claim: "Some selected tile ids were not present in the rhei-shell map fixture.",
      reason: "missing_tile_fixture",
      reasonCodes: ["rhei_shell_code_map:missing_selected_tile"]
    })],
    warnings
  });
}
// ../core/src/contextQuery/publicReadRegistry.ts
var CONTEXT_QUERY_PUBLIC_READ_REGISTRY_V1 = [
  {
    surface: "mcp_search",
    producer: "rhei_code_search",
    path: "packages/mcp-server/src/codeSessionTools.ts",
    status: "envelope_required",
    envelopeRequired: true,
    authorityRequired: true,
    notes: "First MCP producer: maps search results, coverage, graph expansion, no-live policy, and next reads."
  },
  {
    surface: "mcp_context_for_goal",
    producer: "rhei_code_context_for_goal",
    path: "packages/mcp-server/src/localCodeContextForGoal.ts",
    status: "envelope_required",
    envelopeRequired: true,
    authorityRequired: true,
    notes: "Agent-facing context pack producer: maps Code Market context-for-goal output."
  },
  {
    surface: "code_map",
    producer: "code_map_adapter",
    path: "apps/web/src/components/code-context/codeMapAdapter.ts",
    status: "envelope_required",
    envelopeRequired: true,
    authorityRequired: true,
    notes: "Web Code Map adapter proof point; domain snapshot remains authoritative."
  },
  {
    surface: "rhei_shell_code_map",
    producer: "rhei_shell_code_map_adapter",
    path: "apps/expo/src/rhei-shell/map/mapContextQuery.ts",
    status: "envelope_required",
    envelopeRequired: true,
    authorityRequired: true,
    notes: "Current Code Map UI consumer in rhei-shell; local adapter can swap fixture/live data without UI changes."
  },
  {
    surface: "review_intelligence",
    producer: "rhei_code_review",
    path: "packages/mcp-server/src/codeReviewIntelligenceTools.ts",
    status: "envelope_required",
    envelopeRequired: true,
    authorityRequired: true,
    notes: "Review provenance bridge only; review ranking/domain payloads remain authoritative."
  },
  {
    surface: "impact_prediction",
    producer: "code_session_impact_prediction",
    path: "packages/mcp-server/src/codeSessionTools.ts",
    status: "envelope_required",
    envelopeRequired: true,
    authorityRequired: true,
    notes: "Impact provenance bridge only; apply/proof/write gates remain separate."
  },
  {
    surface: "truth_candidate_read",
    producer: "truth_candidate_queries",
    path: "convex/truthCandidatesRuntime/queries.ts",
    status: "explicit_exemption",
    envelopeRequired: false,
    authorityRequired: true,
    exemptionReason: "Truth candidate queues are canonical domain read models; promotion/write paths remain separate and are not normalized in this rollout."
  },
  {
    surface: "workroom_state",
    producer: "workroom_state_reads",
    path: "apps/*/workroom",
    status: "deferred",
    envelopeRequired: false,
    authorityRequired: true,
    exemptionReason: "Deferred until a public consumer needs cross-surface explain metadata."
  },
  {
    surface: "pulse_read",
    producer: "pulse_reads",
    path: "apps/*/pulse",
    status: "deferred",
    envelopeRequired: false,
    authorityRequired: true,
    exemptionReason: "Deferred; Pulse governance and scheduling stay domain-local."
  },
  {
    surface: "context_lens",
    producer: "context_lens_reads",
    path: "packages/core/src/contextLens",
    status: "deferred",
    envelopeRequired: false,
    authorityRequired: true,
    exemptionReason: "Context Lens is semantically broader than Code Map; adapt after MCP and Code Map prove value."
  }
];
function contextQueryRegistryEntryForSurface(surface) {
  return CONTEXT_QUERY_PUBLIC_READ_REGISTRY_V1.find((entry) => entry.surface === surface);
}
function contextQueryEnvelopeRequiredForSurface(surface) {
  return contextQueryRegistryEntryForSurface(surface)?.envelopeRequired === true;
}
function contextQueryAuthorityRequiredForSurface(surface) {
  const entry = contextQueryRegistryEntryForSurface(surface);
  return entry ? entry.authorityRequired : true;
}
function assertContextQueryPublicReadEnvelopeV1(args) {
  const entry = contextQueryRegistryEntryForSurface(args.surface);
  if (!entry) {
    return { ok: false, reason: "context_query_registry:unknown_surface", warnings: [`unknown public read surface: ${args.surface}`] };
  }
  if (!entry.envelopeRequired) {
    return { ok: true, warnings: entry.exemptionReason ? [entry.exemptionReason] : [] };
  }
  if (!args.envelope) {
    return { ok: false, reason: "context_query_registry:missing_envelope", warnings: [`${entry.producer} must include ContextQueryEnvelopeV1`] };
  }
  if (args.envelope.kind !== "rhei_context_query_envelope" || args.envelope.schemaVersion !== 1) {
    return { ok: false, reason: "context_query_registry:invalid_envelope", warnings: [`${entry.producer} returned an invalid context query envelope`] };
  }
  if (args.envelope.surface !== args.surface) {
    return { ok: false, reason: "context_query_registry:surface_mismatch", warnings: [`envelope surface ${args.envelope.surface} does not match registry surface ${args.surface}`] };
  }
  if (entry.authorityRequired) {
    const authority = args.envelope.authority;
    if (!authority?.noAuthority || !authority.noApply || !authority.noPromotion || authority.grantsApplyAuthority !== false || authority.grantsTruthPromotionAuthority !== false || authority.grantsMemoryPromotionAuthority !== false) {
      return { ok: false, reason: "context_query_registry:invalid_authority", warnings: [`${entry.producer} envelope must be explicit no-authority/no-apply/no-promotion`] };
    }
  }
  return { ok: true, warnings: [] };
}
export {
  uniqueContextQueryStrings,
  normalizeTrailRefs,
  normalizeReceiptRefs,
  normalizeEvidenceRefs,
  isContextQueryEnvelopeV1,
  contextQueryRegistryEntryForSurface,
  contextQueryEnvelopeRequiredForSurface,
  contextQueryAuthorityRequiredForSurface,
  buildRheiShellCodeMapContextQueryEnvelopeV1,
  buildReviewIntelligenceContextQueryEnvelopeV1,
  buildMcpSearchContextQueryEnvelopeV1,
  buildImpactPredictionContextQueryEnvelopeV1,
  buildContextQueryTruncationV1,
  buildContextQuerySourceScopeV1,
  buildContextQueryResultRefV1,
  buildContextQueryRequestSummaryV1,
  buildContextQueryProvenanceV1,
  buildContextQueryMissV1,
  buildContextQueryFreshnessV1,
  buildContextQueryExplainV1,
  buildContextQueryEnvelopeV1,
  buildContextQueryAuthorityV1,
  buildContextForGoalContextQueryEnvelopeV1,
  buildCodeMapContextQueryEnvelopeV1,
  assertContextQueryPublicReadEnvelopeV1,
  assertContextQueryEnvelopeV1,
  CONTEXT_QUERY_PUBLIC_READ_REGISTRY_V1,
  CONTEXT_QUERY_ENVELOPE_SCHEMA_VERSION
};
