openloops.runbook_run#
Run an approved run plan: exactly the approved commands, no model, close on the check.
ADR-018. A plan (openloops.runbook.Plan) is written by an agent and approved by
the owner once, by its hash. This module is the executor, and it holds no judgement:
it refuses a plan with no approval for its current hash, an approval older than
DFLT_APPROVAL_HOURS, or a planopenloops.runbook.validate()rejects (therisk floor is recomputed from the text, so a plan cannot talk its way past it);
it runs each step’s command exactly as written, in order, with a time limit, its output captured to a local log (mode 0600) and never posted anywhere;
before a step it runs the step’s check, and skips the command when the check already passes, so running a plan twice is harmless;
a step whose dependencies did not succeed is skipped; a step that needs a person at a terminal (
Step.interactive) runs only when the owner started the run from one (tty=True), on his own terminal and with no time limit (DFLT_ATTENDED_TIMEOUT): he is there, and Ctrl-C stops the run (what succeeded stays done; the same line resumes);at a terminal,
say=is told what each step is before it runs (its id, issue and note: what to have ready) and how it ended after, andask=is asked before going on past a step that failed, so no step’s end runs silently into the next one’s prompt;after an issue’s last step it hands the outcome to
openloops.closer, which closes the issue only on a passing check (ADR-015).
ol runbook run PLAN --only-checks needs no approval: it runs no command, only the
checks, and closes what already passes (the closer’s four conditions still apply).
Nothing in the core imports this module. run_step() is the one place a step’s
command is run; ol do (ADR-015 §2) is meant to call it too.
Functions
|
|
|
Write plan under |
|
A plan by id, or by the path of a plan file. |
|
Record the owner's approval of plan's current hash. |
|
The live approval of plan's current hash, or |
|
The stored plans, newest first, each |
|
Run one step's command; |
|
One task step end to end, short of reporting: check first, then run. |
|
Run plan's approved steps, in order; return the run report (also stored). |
|
Run command with |
|
The one command that approves a plan's current text and runs it at the terminal. |
- openloops.runbook_run.approval_of(plan, *, store, now=None, hours=48)[source]#
The live approval of plan’s current hash, or
None.Nonetoo for an approval of another plan with the same steps, one dated in the future or without a time zone, and one older thanhours.
- openloops.runbook_run.approve(plan, *, via, discussed=(), store, now=None)[source]#
Record the owner’s approval of plan’s current hash.
viasays how the owner approved ("terminal","board:<event id>","session: <the owner's words>");discussednames thediscuss-level steps the owner said yes to by name. A plan that does not validate is not approvable.
- openloops.runbook_run.approve_line(plan_id, hash12)[source]#
The one command that approves a plan’s current text and runs it at the terminal.
>>> approve_line("p1", "abc123def456") 'cd ~ && ol runbook-run p1 --tty --approve abc123def456'
- Return type:
- openloops.runbook_run.load_plan(ref, *, store)[source]#
A plan by id, or by the path of a plan file.
- Return type:
- openloops.runbook_run.plans(*, store, now=None, include_ran=False)[source]#
The stored plans, newest first, each
{plan, title, hash12, state, counts, page, created, issues, approve}(issues: every issue it covers;approve:approve_line()).stateiswaiting(no live approval for its current hash: it needs the owner),approved(approved, no run since), orran(a report exists since the approval).ranplans are left out unlessinclude_ran.
- openloops.runbook_run.run_plan(plan, *, store, runner=<function shell_runner>, run_check=<function default_run_check>, close=None, log_dir=None, tty=False, only_checks=False, only=None, dry_run=False, now=None, say=None, ask=None, attended_timeout=None)[source]#
Run plan’s approved steps, in order; return the run report (also stored).
say(the owner’s terminal) is told what each step is before it runs and how it ended after;askis asked, after a step fails, whether to go on:qholds the rest (rerun the same line later: what succeeded does not run twice).onlylimits the run to some step ids (a pilot): the others areheld, and an issue with a held step is not reported (it closes when its last step has run).only_checksruns no command, needs no approval, and closes only on the issue’s own Verify line (a check the planner wrote needs the owner’s approval of the plan).dry_runruns nothing and writes nothing.closedefaults toopenloops.closer.report()with the owners and login resolved once per run;log_dirto~/.local/share/openloops/runbooks/logs.
- openloops.runbook_run.run_step(step, *, runner=<function shell_runner>, tty=False, log_path=None, attended_timeout=None)[source]#
Run one step’s command;
okwhen it exits 0 and its output matchesexpect.Returns
{status, ok, why, tail};tailis the end of the output, for the local report only. A step that needs the owner’s hands, run at his terminal, getsattended_timeoutinstead of its own limit (default: none).
- openloops.runbook_run.run_task(step, *, runner=<function shell_runner>, run_check=<function default_run_check>, tty=False, log_path=None, checks_only=False, attended_timeout=None)[source]#
One task step end to end, short of reporting: check first, then run.
resultisalready-done(its check passes: the command did not run),not-run(checks_only),needs-terminal(an interactive step withouttty),okorfailed. ADR-015 §2’sol dois this plusopenloops.closer.report().
- openloops.runbook_run.runbooks_store(root=None)[source]#
~/.local/share/openloops/runbooks/:plans/,approvals/,reports/.- Return type:
- openloops.runbook_run.save_plan(plan, *, store)[source]#
Write plan under
plans/<id>.json; returns its hash.- Return type:
- openloops.runbook_run.shell_runner(command, *, cwd, timeout, tty, log_path)[source]#
Run command with
bash; return(exit status, output).Output goes to log_path (created 0600). With
ttythe step runs on the owner’s own terminal, as if he had typed it: his keys reach it (a paste, a one-time code, ay), and his Ctrl-C reaches it and this process (which then stops the run). Its output is shown there and not kept. Withoutttyinput is closed, so a step that waits for input fails instead of hanging, and its output is captured.Noneis a step that could not run, ran out of time, or was stopped with Ctrl-C (timeout=Nonewaits for as long as it takes).