import { filter_nil } from "std/collections"
/** runtime_task. */
pub fn runtime_task() -> string {
return host_call("runtime.task", {}) ?? ""
}
/** runtime_pipeline_input. */
pub fn runtime_pipeline_input() {
return host_call("runtime.pipeline_input", {})
}
/** runtime_dry_run. */
pub fn runtime_dry_run() -> bool {
return host_call("runtime.dry_run", {}) ?? false
}
/** runtime_approved_plan. */
pub fn runtime_approved_plan() -> string {
return host_call("runtime.approved_plan", {}) ?? ""
}
/** process_run. */
pub fn process_run(argv: list<string>, options = nil) {
let opts = options ?? {}
return host_call("process.exec", filter_nil(opts + {mode: "argv", argv: argv})) ?? {}
}
/** process_shell. */
pub fn process_shell(command: string, options = nil) {
let opts = options ?? {}
return host_call("process.exec", filter_nil(opts + {mode: "shell", command: command})) ?? {}
}
/** process_result_text. */
pub fn process_result_text(result: dict) -> string {
let stdout = result?.stdout ?? ""
let stderr = result?.stderr ?? ""
if stdout && stderr {
return "${stdout}\n${stderr}"
}
if stdout {
return stdout
}
if stderr {
return stderr
}
return result?.combined ?? result?.inline_output ?? ""
}
/** process_result_success. */
pub fn process_result_success(result: dict) -> bool {
if result?.success != nil {
return result?.success ? true : false
}
let status = result?.status ?? "completed"
let exit_code = result?.exit_code ?? -1
return status == "completed" && exit_code == 0
}
/** shell_quote. */
pub fn shell_quote(value) -> string {
return "'" + to_string(value ?? "").replace("'", "'\"'\"'") + "'"
}
/** interaction_ask. */
pub fn interaction_ask(question) -> string {
return host_call("interaction.ask", {question: question}) ?? ""
}
/** interaction_ask_with_kind. */
pub fn interaction_ask_with_kind(question, kind) -> string {
return host_call("interaction.ask", {question: question, type: kind}) ?? ""
}
/** record_run_metadata. */
pub fn record_run_metadata(run, workflow_name) {
if run?.path {
host_call(
"runtime.record_run",
{
workflow: workflow_name,
path: run?.path,
status: run?.status ?? "",
fixture_type: run?.run?.replay_fixture?._type,
usage: run?.usage,
persisted_path: run?.persisted_path,
summary: transcript_summary(run?.transcript),
transcript_state: run?.transcript?.state ?? "",
message_count: len(transcript_messages(run?.transcript)),
event_count: len(transcript_events(run?.transcript)),
asset_count: len(transcript_assets(run?.transcript)),
},
)
}
}