harn-stdlib 0.10.201

Embedded Harn standard library source catalog
Documentation
/**
 * Typed wire contract for the content linked into a Harn runtime.
 *
 * The native runtime owns how these values are computed. This module owns the
 * Harn projection and rejects malformed values before consumers inspect them.
 */
import { get_typed_value } from "std/schema"
import { ToolCatalogEntry } from "std/tools"

pub type RuntimeBuildFeatures = {
  default: bool,
  full: bool,
  llm_bench_internals: bool,
  vm_bench_internals: bool,
  vm_test_support: bool,
  content: bool,
  compression: bool,
  http_compression: bool,
  cloud_aws: bool,
  native_keyring: bool,
  postgres: bool,
  sqlite: bool,
  otel: bool,
  testbench_wasi: bool,
}

pub type RuntimeCompatibilityFingerprint = {
  codegen_fingerprint: string,
  bytecode_schema_version: int,
  linked_program_schema_version: int,
  linker_algorithm_version: int,
  build_features: RuntimeBuildFeatures,
}

pub type RuntimeContentFingerprint = {
  schema: "harn.runtime_content_fingerprint.v1",
  content_sha256: string,
  artifact_id: string?,
  harn_version: string,
  embedded_stdlib_sha256: string,
  compatibility: RuntimeCompatibilityFingerprint,
  source_revision: string?,
}

/**
 * Validate an untrusted runtime receipt and return its closed typed value.
 *
 * @effects: []
 * @errors: [validation]
 */
pub fn runtime_content_fingerprint_value(value: unknown) -> RuntimeContentFingerprint {
  return get_typed_value(value, schema_of(RuntimeContentFingerprint))
}

/**
 * Read the connected Harn MCP server's measured runtime, without starting a
 * second process. Servers without this receipt fail validation.
 * @effects: []
 * @errors: [validation]
 */
pub fn mcp_runtime_content_fingerprint(tool: ToolCatalogEntry) -> RuntimeContentFingerprint {
  const metadata = tool._meta ?? {}
  return runtime_content_fingerprint_value(metadata["dev.harn/runtime-content"])
}

/**
 * Read the identity of the runtime linked into this process, before inference.
 * The native owner computes this receipt from the embedded stdlib, compiler
 * contract, runtime version, enabled features, and containing executable or
 * shared library's linker identity. A missing artifact_id is unmeasured.
 * @effects: []
 * @errors: [validation]
 */
pub fn runtime_content_fingerprint(runtime: HarnessRuntime) -> RuntimeContentFingerprint {
  const snapshot = runtime.introspection()
  return runtime_content_fingerprint_value(snapshot.runtime_content_fingerprint)
}