Vibescript Showcase

Approval chain

Express release approvals with typed states, Duration-based deadlines, and structured review steps.

Showcase
Source showcase/workflows/approval_chain.vibe
# title: Approval chain
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Express release approvals with typed states, Duration-based deadlines, and structured review steps.
# description: This example is workflow code rather than puzzle code: state transitions are explicit, deadlines are semantic, and the output is shaped for downstream systems.
# tags: workflows, durations, enums, approvals
# vibe: 0.2

enum ApprovalState
  Draft
  Review
  Approved
  Blocked
end

def next_state(state: ApprovalState, checks_passed: bool) -> ApprovalState
  if state == ApprovalState::Draft
    ApprovalState::Review
  elsif state == ApprovalState::Review && checks_passed
    ApprovalState::Approved
  elsif state == ApprovalState::Review
    ApprovalState::Blocked
  else
    state
  end
end

def approval_step(label: string, due_in: duration, opened_at: time) -> hash
  {
    label: label,
    due_in: due_in.iso8601,
    due_at: due_in.after(opened_at).format("2006-01-02T15:04:05Z")
  }
end

def approval_chain(change_id: string, state: ApprovalState, checks_passed: bool, opened_at: time) -> hash
  target_state = next_state(state, checks_passed)
  steps = []

  if state == ApprovalState::Draft
    steps = steps.push(approval_step("peer review", 2.hours, opened_at))
  elsif state == ApprovalState::Review
    steps = steps.push(approval_step("security review", 4.hours, opened_at))
    steps = steps.push(approval_step("ops signoff", 8.hours, opened_at))
  else
    steps = steps.push(approval_step("release", 30.minutes, opened_at))
  end

  {
    change_id: change_id,
    state: state.name,
    next_state: target_state.name,
    checks_passed: checks_passed,
    steps: steps
  }
end

def run
  opened_at = Time.at(1701000000)

  {
    pending: approval_chain("change_88", ApprovalState::Review, false, opened_at),
    ready: approval_chain("change_89", ApprovalState::Review, true, opened_at)
  }
end
Output
Press run to execute run from this example.
showcase idiomatic-vibescript workflows durations enums approvals browser-runner