harn-stdlib 0.10.2

Embedded Harn standard library source catalog
Documentation
/** Shared render helpers for `harn models lora *` commands. */
import { print_list, safe_dict, safe_list, safe_string } from "std/cli/render"

/**
 * Render the PEFT save policy carried by a LoRA training contract.
 *
 * @effects: [stdio.write]
 * @errors: []
 */
pub fn render_peft_save_policy(harness: Harness, policy: dict) {
  const modules_to_save = safe_list(policy["modules_to_save"])
  if len(modules_to_save) > 0 {
    harness.stdio
      .println(
      "  modules to save: " + join(modules_to_save.map({ item -> safe_string(item, "") }), ", "),
    )
  } else {
    harness.stdio.println("  modules to save: none")
  }
  harness.stdio
    .println("  embedding save policy: " + safe_string(policy["save_embedding_layers"], ""))
  harness.stdio
    .println("  weight tying policy: " + safe_string(policy["tied_embedding_policy"], ""))
  print_list(harness, "PEFT save notes", safe_list(policy["notes"]))
}

fn __probe_case_line(value: unknown) -> string {
  const probe = safe_dict(value)
  const id = safe_string(probe["id"], "")
  if id == "" {
    return ""
  }
  const requirement = safe_string(probe["requirement"], "")
  const expected = safe_string(probe["expected"], "")
  const receipt = safe_string(probe["receipt"], "")
  const rationale = safe_string(probe["rationale"], "")
  let line = id
  if requirement != "" {
    line = line + " [" + requirement + "]"
  }
  if expected != "" {
    line = line + ": " + expected
  }
  if receipt != "" {
    line = line + " (receipt " + receipt + ")"
  }
  if rationale != "" {
    line = line + " - " + rationale
  }
  return line
}

/**
 * Render the behavioral probe matrix required before a LoRA promotion.
 *
 * @effects: [stdio.write]
 * @errors: []
 */
pub fn render_required_probe_cases(harness: Harness, value: unknown) {
  const probe_cases = safe_list(value)
  if len(probe_cases) == 0 {
    return
  }
  harness.stdio.println("  required probe cases:")
  for item in probe_cases {
    const line = __probe_case_line(item)
    if line != "" {
      harness.stdio.println("    - " + line)
    }
  }
}