Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ Metrics/MethodLength:
Max: 25
Exclude:
- "lib/plan_driven/configuration.rb"
- "lib/plan_driven/charts.rb"
- "lib/plan_driven/renderer/html.rb"

# CLI commands read top to bottom as the conversation they print, and the Markdown and
# Gherkin readers are line-by-line state machines. Splitting them would hide the flow.
# Gherkin readers are line-by-line state machines. Splitting them would hide the flow. A chart
# is one drawing: its coordinates read best in one place.
Metrics/AbcSize:
Max: 30
Exclude:
- "lib/plan_driven/cli/*_commands.rb"
- "lib/plan_driven/renderer/html.rb"
- "lib/plan_driven/gherkin.rb"
- "lib/plan_driven/configuration.rb"
- "lib/plan_driven/charts.rb"

Metrics/CyclomaticComplexity:
Max: 12
Expand Down Expand Up @@ -81,6 +85,8 @@ Naming/MethodParameterName:
- at
- by
- pr
- x
- y

Naming/PredicateMethod:
AllowedMethods:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ All notable changes to this project are documented here. The format follows

## [Unreleased]

### Added

- Statistics, computed from the audit trail: how long planning, tickets, development and proof
took, each ticket's time split into queued, agent coding, waiting for review, agent fixing
feedback and approved but not merged, the agents' share of the work, first-time approvals,
and acceptance criteria merged and proven over time. `plan-driven stats PLAN` prints them,
the wizard has a Statistics page with charts, and the delivery report has a Statistics
section.
- Charts drawn in Ruby as SVG, with no JavaScript: a burn-up of criteria merged and proven,
a timeline of each ticket, the split between agents and people, and a bar of every
criterion's result. The delivery report writes them next to the Markdown, so GitHub shows
them, and inlines them in the HTML and the PDF.

### Changed

- The delivery report has colour: every acceptance criterion's result is a green, red, amber
or grey pill with a matching edge on its row, failed rows are tinted red, merged tickets are
marked green, and the Markdown shows ✅, ❌, ⏸️ or ⚠️ before each result.

## [0.2.0] - 2026-09-30

### Added
Expand Down
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ repository. The planner and the five agents ran on Claude Opus 5.5 through Curso
- [Configuration](#configuration)
- [Choosing the coding agents](#choosing-the-coding-agents)
- [Tokens and cost](#tokens-and-cost)
- [Statistics](#statistics)
- [How it compares](#how-it-compares)
- [Keys](#keys)
- [Working as a team](#working-as-a-team)
Expand Down Expand Up @@ -717,8 +718,9 @@ $ bin/plan-driven report PD-1

`evidence` runs the plan's scenarios on your machine and stores the result with the commit it
ran on; `--from cucumber.json` imports a run from CI instead. The delivery report lists each
ticket with its pull request, merge commit and approver, then every acceptance criterion with
the scenario that proves it, the guard findings, every approval and the full timeline. Commit
ticket with its pull request, merge commit and approver, the [statistics](#statistics) with
their charts, then every acceptance criterion with the scenario that proves it, marked passed
or failed in colour, the guard findings, every approval and the full timeline. Commit
`docs/plans/` with it, and the plan and its proof stay next to the code.

![The delivery report](docs/images/15-delivery-report.png)
Expand Down Expand Up @@ -840,6 +842,7 @@ key such as `PD-1`, and `PLAN/TICKET` is a ticket such as `PD-1/T3`.
| `report PLAN` | Write the delivery report |
| `log PLAN` | The audit trail |
| `usage PLAN` | Tokens, time and cost per step and per agent run |
| `stats PLAN` | Where the time went: phases, agents and people, each ticket |
| `questions` | The interview's questions, and which ones the team changed or added |
| `question KEY [--title T] [--ask Q] [--group G] [--required \| --optional] [--remove]` | Change or add an interview question, or put it back |
| `configure` | Store keys in `~/.plan_driven/config` |
Expand Down Expand Up @@ -985,6 +988,90 @@ For scale, these are the five cloud agents from the demo, read back from Cursor'
are code and text the agents wrote. Most of an agent's tokens go into reading the codebase, so
a small, conventional one is cheaper to work on.

## Statistics

Where did the time go? Was it the agents writing code, or the pull requests waiting for a
person? The same numbers are in three places:

- **In the wizard:** every plan has a Statistics page, linked under its title and from the
Proof & report step. In development that's `http://localhost:3000/plan_driven/plans/PD-1/statistics`.
- **In the terminal:** `bin/plan-driven stats PD-1`.
- **In the delivery report:** a Statistics section with the same charts, in the Markdown, the
HTML and the PDF.

![The Statistics page in the wizard, for a delivered plan](docs/images/statistics.png)

This is PD-3 from the demo: six tickets delivered in 1 h 20 min, 42 of 42 criteria proven.

- **Cards:** idea to delivery, development time, criteria proven, pull requests approved the
first time, the agents' share of the work, and tokens.
- **Acceptance criteria, merged and proven:** a burn-up against the plan's scope. The blue
line rises as each ticket merges with its criteria, and the green line rises when an
evidence run proves them. Every run is a dot, red when it failed. Here, two runs failed
around 14:50 and the third proved all 42.
- **Where the time went, ticket by ticket:** one row per ticket on a shared clock. Grey is
queued, waiting for the tickets it depends on. Blue is an agent coding, amber is the pull
request waiting for review, purple is an agent fixing feedback, and green is approved but
not merged. T3 has one round of feedback, and each ticket waited for the one before it.
- **Agents and people:** how the time tickets were worked on splits. Here agents took 91% of
it and reviews took 7%. On a plan where the donut is mostly amber, the bottleneck is review,
not code.
- **Ticket by ticket, and the phases:** the same times as a table, with the estimate and the
review rounds, and how long planning, tickets, development and proof took.

```
$ bin/plan-driven stats PD-3
PD-3 Comments on events: statistics
Planning 2 min
Tickets 2 min
Development 1 h 20 min
Proof 10 min
Idea to delivery 1 h 25 min
Tickets merged 6 of 6, 5 approved the first time
✓ 42 of 42 acceptance criteria proven

Where the time went while tickets were worked on (agents 91%):
Agent coding 1 h 2 min ████████████████████ 79%
Waiting for review 5 min ██ 7%
Agent fixing feedback 9 min ███ 12%
Approved, not merged 1 min █ 2%

# Est Queued Agent Review Fixes Merge Rounds Total
T1 2 53s 10 min 4 min - 23s 0 16 min
T2 2 17 min 10 min 8s - 12s 0 10 min
T3 3 28 min 11 min 28s 9 min 10s 1 21 min
...
```

### How it's worked out

Nothing is estimated, and no model is asked. Every number is the time between two events that
plan-driven already records in the audit trail:

| From | To | Counts as |
| --- | --- | --- |
| `tickets.approved` | `ticket.agent_started` | Queued |
| `ticket.agent_started` | `ticket.pr_opened` | Agent coding |
| `ticket.pr_opened` | `ticket.pr_approved` or `ticket.changes_requested` | Waiting for review |
| `ticket.changes_requested` | the next `ticket.pr_opened` | Agent fixing feedback |
| `ticket.pr_approved` | `ticket.merged` | Approved, not merged |

The phases run from `plan.drafted` to the last `plan.approved` (planning), then to
`tickets.approved` (tickets), then to `plan.delivered` (development), then to the first
passing evidence run (proof). A plan still in development is counted up to now. A plan whose
tickets aren't approved yet shows only its planning time.

The charts are SVG drawn in Ruby, with no JavaScript and nothing to install. `report` writes
them next to `delivery-report.md` (`statistics-burnup.svg`, `statistics-timeline.svg`,
`statistics-time.svg`, `statistics-proof.svg`), so GitHub shows them in the Markdown, and it
inlines them in the HTML and the PDF so both stand alone.

The report also marks every acceptance criterion's result in colour: a green, red, amber or
grey pill with a matching edge on its row, and failed rows tinted red. On GitHub, the Markdown
shows ✅, ❌, ⏸️ or ⚠️ instead.

![Acceptance criteria and proof in the delivery report](docs/images/statistics-report.png)

## How it compares

plan_driven sits next to spec-driven tools such as GitHub's Spec Kit and Kiro, which also start
Expand Down
19 changes: 15 additions & 4 deletions app/controllers/plan_driven/wizard/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module PlanDriven
module Wizard
# Every form posts here, and every post becomes one `plan-driven` command. The pages only read.
class PlansController < ApplicationController
before_action :find_plan, only: %i[show run file]
before_action :find_plan, only: %i[show statistics run file]

def index
@plans = Plan.order(id: :desc)
Expand All @@ -33,12 +33,16 @@ def show
@template = PlanDriven.configuration.template
end

def statistics
@step = "statistics"
@stats = Statistics.new(@plan)
end

def run
job = start(Commands.argv(params[:do], command_fields))
redirect_to plan_path(@plan.key, params[:step].presence, job: job.id, open: params[:open].presence,
anchor: params[:open].presence)
redirect_to after_run(job)
rescue ArgumentError => e
redirect_to plan_path(@plan.key, params[:step].presence), alert: e.message
redirect_to plan_path(@plan.key, params[:step].presence.presence_in(Steps.keys)), alert: e.message
end

def run_global
Expand All @@ -62,6 +66,13 @@ def file

private

def after_run(job)
return plan_statistics_path(@plan.key, job: job.id) if params[:step] == "statistics"

plan_path(@plan.key, params[:step].presence, job: job.id, open: params[:open].presence,
anchor: params[:open].presence)
end

def find_plan
@plan = Plan.find_by_reference!(params[:key])
rescue ActiveRecord::RecordNotFound => e
Expand Down
12 changes: 12 additions & 0 deletions app/views/layouts/plan_driven/wizard/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
.grid2 { display:grid; grid-template-columns:minmax(0, 1fr) minmax(0, 2fr); gap:12px; }
label.check { display:inline-flex; gap:6px; align-items:center; font-weight:400; margin:0; }
.card.unused { opacity:.75; }
.kpis { display:grid; grid-template-columns:repeat(auto-fill, minmax(170px, 1fr)); gap:10px; margin:16px 0 4px; }
.kpi { background:#fff; border:1px solid var(--line); border-top:3px solid #3b82f6; border-radius:10px; padding:12px 14px; display:flex; flex-direction:column; gap:2px; }
.kpi small { color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.04em; }
.kpi strong { font-size:26px; line-height:1.15; } .kpi strong span { font-size:16px; color:var(--muted); font-weight:500; }
.kpi .muted { font-size:12px; }
.kpi.good { border-top-color:var(--ok); } .kpi.good strong { color:var(--ok); }
.kpi.bad { border-top-color:var(--bad); } .kpi.bad strong { color:var(--bad); }
.card.chart { padding:6px; } .card.chart svg { display:block; width:100%; height:auto; }
.swatch { display:inline-block; width:8px; height:8px; border-radius:2px; margin-right:6px; vertical-align:middle; }
.phases { display:flex; gap:0; border-radius:8px; overflow:hidden; border:1px solid var(--line); }
.phases div { flex:1; padding:10px 12px; border-right:1px solid var(--line); display:flex; flex-direction:column; }
.phases div:last-child { border-right:0; } .phases small { color:var(--muted); } .phases .pending { background:#f9fafb; color:var(--muted); }
.flash { padding:10px 14px; border-radius:8px; margin-bottom:12px; background:#fee2e2; color:var(--bad); }
</style>
</head>
Expand Down
7 changes: 7 additions & 0 deletions app/views/plan_driven/wizard/plans/_finish.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
</div>
<% end %>

<div class="card row">
<strong>Statistics</strong>
<span class="muted">Where the time went, criteria merged and proven, agents and people.</span>
<span style="margin-left:auto"></span>
<%= link_to "Open the statistics →", plan_statistics_path(@plan.key), class: "button" %>
</div>

<% files = %w[delivery-report.html delivery-report.pdf].select { |name| PlanDriven::Renderer.directory(@plan).join(name).file? } %>
<% if files.any? %>
<div class="card">
Expand Down
1 change: 1 addition & 0 deletions app/views/plan_driven/wizard/plans/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<p class="muted" style="margin:0">
<span class="pill <%= @plan.status == "delivered" ? "good" : "wait" %>"><%= @plan.status.tr("_", " ") %></span>
revision <%= @plan.revision %> · <%= PlanDriven::Workflow::PLAN_DESCRIPTIONS[@plan.status] %>
· <%= link_to "Statistics", plan_statistics_path(@plan.key) %>
</p>

<ol class="steps">
Expand Down
94 changes: 94 additions & 0 deletions app/views/plan_driven/wizard/plans/statistics.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<% content_for :title, "#{@plan.key} statistics" %>
<% duration = ->(seconds) { PlanDriven::Statistics.duration(seconds) } %>
<p class="muted" style="margin:0"><%= link_to "← #{@plan.key} #{@plan.title}", plan_path(@plan.key) %></p>
<h1>Statistics</h1>
<p class="muted" style="margin:0">
<span class="pill <%= @plan.status == "delivered" ? "good" : "wait" %>"><%= @plan.status.tr("_", " ") %></span>
Computed from the audit trail: every number is a recorded event, nothing is estimated.
</p>

<% if @stats.started? %>
<% s = @stats.summary %>
<div class="kpis">
<div class="kpi">
<small>Idea to delivery</small>
<strong><%= duration[s[:lead_time]] %></strong>
<span class="muted"><%= @plan.status == "delivered" ? "plan drafted to delivered" : "so far" %></span>
</div>
<div class="kpi">
<small>Development</small>
<strong><%= duration[s[:development]] %></strong>
<span class="muted"><%= s[:merged] %> of <%= s[:tickets] %> tickets merged</span>
</div>
<div class="kpi <%= s[:proven] == s[:criteria] && s[:criteria].positive? ? "good" : (s[:evidence] ? "bad" : "") %>">
<small>Criteria proven</small>
<strong><%= s[:proven] %> <span>/ <%= s[:criteria] %></span></strong>
<span class="muted"><%= s[:evidence] ? "by a passing scenario" : "no evidence run yet" %></span>
</div>
<div class="kpi">
<small>Approved the first time</small>
<strong><%= s[:first_time] %> <span>/ <%= s[:merged] %></span></strong>
<span class="muted"><%= pluralize(s[:review_rounds], "review round") %></span>
</div>
<div class="kpi">
<small>Agents' share of the work</small>
<strong><%= s[:agent_share] ? "#{s[:agent_share]}%" : "-" %></strong>
<span class="muted">the rest is waiting on people</span>
</div>
<div class="kpi">
<small>Tokens</small>
<strong><%= PlanDriven::Usage.format_tokens(s[:tokens]) %></strong>
<span class="muted"><%= s[:cost] ? PlanDriven::Usage.format_cost(s[:cost]) : "set config.token_prices for dollars" %></span>
</div>
</div>

<% charts = PlanDriven::Charts.report(@plan, stats: @stats) %>
<% %w[statistics-proof.svg statistics-burnup.svg statistics-timeline.svg statistics-time.svg].each do |name| %>
<% next unless charts[name] %>
<div class="card chart"><%= charts[name].html_safe %></div>
<% end %>

<div class="card">
<h3 style="margin-top:0">Ticket by ticket</h3>
<table>
<thead>
<tr><th>#</th><th>Ticket</th><th>Est.</th><th>Queued</th><th>Agent</th><th>Review</th><th>Fixes</th><th>Merge</th><th>Rounds</th><th>Start to merge</th></tr>
</thead>
<tbody>
<% @stats.tickets.each do |row| %>
<tr>
<td><b><%= row.ticket.key %></b></td>
<td><%= row.ticket.title %></td>
<td><%= row.ticket.estimate %></td>
<% %w[queued agent review fixes merge].each do |phase| %>
<td><span class="swatch" style="background:<%= PlanDriven::Charts::COLORS[phase] %>"></span><%= row.seconds(phase).positive? ? duration[row.seconds(phase)] : "-" %></td>
<% end %>
<td><%= row.review_rounds %></td>
<td><% if row.merged? %><span class="pill good"><%= duration[row.cycle_time] %></span><% else %><span class="pill wait"><%= row.ticket.status.tr("_", " ") %></span><% end %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<div class="card">
<strong>Statistics start when the tickets are approved.</strong>
<p class="muted">Until then, this is how long planning has taken.</p>
</div>
<% end %>

<div class="card">
<h3 style="margin-top:0">Phases</h3>
<div class="phases">
<% @stats.phases.each do |label, seconds| %>
<div class="<%= "pending" unless seconds %>"><small><%= label %></small><b><%= seconds ? duration[seconds] : "not yet" %></b></div>
<% end %>
</div>
</div>

<div class="card row">
<span class="muted">The same numbers in the terminal, and the charts in the delivery report.</span>
<span style="margin-left:auto"></span>
<%= run_button "Print in the terminal", "stats" %>
<%= run_button "Write the delivery report", "report", {}, primary: true %>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
PlanDriven::Wizard::Engine.routes.draw do
root "plans#index"
resources :plans, only: %i[new create], param: :key
get "plans/:key/statistics", to: "plans#statistics", as: :plan_statistics
get "plans/:key(/:step)", to: "plans#show", as: :plan, constraints: { step: /plan|approve|tickets|agents|finish/ }
post "plans/:key/run", to: "plans#run", as: :run_plan
get "plans/:key/files/:name", to: "plans#file", as: :plan_file, constraints: { name: /[a-z-]+\.(pdf|html)/ }
Expand Down
Binary file added docs/images/statistics-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/statistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion lib/plan_driven.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
require_relative "plan_driven/local_agents"
require_relative "plan_driven/usage"
require_relative "plan_driven/repository"
require_relative "plan_driven/renderer"
require_relative "plan_driven/evidence"
require_relative "plan_driven/statistics"
require_relative "plan_driven/charts"
require_relative "plan_driven/renderer"
require_relative "plan_driven/delivery"
require_relative "plan_driven/wizard"
require_relative "plan_driven/railtie" if defined?(Rails::Railtie)
Expand Down
Loading
Loading