harn-stdlib 0.10.177

Embedded Harn standard library source catalog
Documentation
/** Network grants captured for one child after host policy normalization. */
pub type CommandNetworkGrants = {
  status: "policy",
  direct_network: bool,
  tcp_loopback: bool,
  managed_proxy: bool,
} \
  | {status: "inherited" | "unavailable" | "unknown"}

/** Sandbox coverage and the grants retained for the spawned command. */
pub type CommandSandboxReport = {
  kind: string,
  enforced: bool,
  denial_reporting: "not_enforced" | "backend_unavailable" | "inferred_only",
  network: CommandNetworkGrants,
}

/** Common fields guaranteed by normalized command results. */
pub type CommandResult = {
  success: bool,
  ok: bool,
  status: string,
  exit_code: int?,
  cwd: string,
  stdout: string,
  stderr: string,
  sandbox?: CommandSandboxReport,
  ...rest,
}

/**
 * Build a normalized successful command-result dict for tests and harness adapters.
 *
 * @effects: []
 * @errors: []
 */
pub fn command_result_ok(stdout: string = "", extra: dict? = nil) -> CommandResult {
  const base = extra ?? {}
  return base
    + {
      success: true,
      ok: true,
      status: "completed",
      exit_code: 0,
      cwd: base?.cwd ?? "",
      stdout: stdout,
      stderr: "",
    }
}

/**
 * Build a normalized failed command-result dict for tests and harness adapters.
 *
 * @effects: []
 * @errors: []
 */
pub fn command_result_fail(
  exit_code: int = 1,
  stderr: string = "",
  extra: dict? = nil,
) -> CommandResult {
  const base = extra ?? {}
  return base
    + {
      success: false,
      ok: false,
      status: "failed",
      exit_code: exit_code,
      cwd: base?.cwd ?? "",
      stdout: base?.stdout ?? "",
      stderr: stderr,
    }
}