diff --git a/.rubocop.yml b/.rubocop.yml
index 3bac330..4aee1ac 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -20,9 +20,12 @@ 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:
@@ -30,6 +33,7 @@ Metrics/AbcSize:
- "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
@@ -81,6 +85,8 @@ Naming/MethodParameterName:
- at
- by
- pr
+ - x
+ - y
Naming/PredicateMethod:
AllowedMethods:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c897b4..c502cd8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/README.md b/README.md
index 855b9dd..4929119 100644
--- a/README.md
+++ b/README.md
@@ -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)
@@ -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.

@@ -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` |
@@ -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.
+
+
+
+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.
+
+
+
## How it compares
plan_driven sits next to spec-driven tools such as GitHub's Spec Kit and Kiro, which also start
diff --git a/app/controllers/plan_driven/wizard/plans_controller.rb b/app/controllers/plan_driven/wizard/plans_controller.rb
index b3e79d8..be37c25 100644
--- a/app/controllers/plan_driven/wizard/plans_controller.rb
+++ b/app/controllers/plan_driven/wizard/plans_controller.rb
@@ -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)
@@ -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
@@ -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
diff --git a/app/views/layouts/plan_driven/wizard/application.html.erb b/app/views/layouts/plan_driven/wizard/application.html.erb
index 2fbb690..6acc79a 100644
--- a/app/views/layouts/plan_driven/wizard/application.html.erb
+++ b/app/views/layouts/plan_driven/wizard/application.html.erb
@@ -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); }
diff --git a/app/views/plan_driven/wizard/plans/_finish.html.erb b/app/views/plan_driven/wizard/plans/_finish.html.erb
index 975031d..dbfe002 100644
--- a/app/views/plan_driven/wizard/plans/_finish.html.erb
+++ b/app/views/plan_driven/wizard/plans/_finish.html.erb
@@ -15,6 +15,13 @@
<% end %>
+
+ Statistics
+ Where the time went, criteria merged and proven, agents and people.
+
+ <%= link_to "Open the statistics →", plan_statistics_path(@plan.key), class: "button" %>
+
+ The same numbers in the terminal, and the charts in the delivery report.
+
+ <%= run_button "Print in the terminal", "stats" %>
+ <%= run_button "Write the delivery report", "report", {}, primary: true %>
+
diff --git a/config/routes.rb b/config/routes.rb
index 04319e4..9a141c8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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)/ }
diff --git a/docs/images/statistics-report.png b/docs/images/statistics-report.png
new file mode 100644
index 0000000..20b1d7b
Binary files /dev/null and b/docs/images/statistics-report.png differ
diff --git a/docs/images/statistics.png b/docs/images/statistics.png
new file mode 100644
index 0000000..3b57c80
Binary files /dev/null and b/docs/images/statistics.png differ
diff --git a/lib/plan_driven.rb b/lib/plan_driven.rb
index 363137c..0e73d65 100644
--- a/lib/plan_driven.rb
+++ b/lib/plan_driven.rb
@@ -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)
diff --git a/lib/plan_driven/charts.rb b/lib/plan_driven/charts.rb
new file mode 100644
index 0000000..6860139
--- /dev/null
+++ b/lib/plan_driven/charts.rb
@@ -0,0 +1,252 @@
+# frozen_string_literal: true
+
+require "cgi"
+
+module PlanDriven
+ # A plan's statistics as SVG, drawn in Ruby. The same file shows in the wizard, on GitHub next
+ # to the delivery report and in its PDF: no JavaScript, nothing to install.
+ module Charts
+ COLORS = {
+ "queued" => "#d1d5db", "agent" => "#3b82f6", "review" => "#f59e0b", "fixes" => "#8b5cf6",
+ "merge" => "#10b981", "passed" => "#16a34a", "failed" => "#dc2626", "not run" => "#f59e0b",
+ "no scenario" => "#9ca3af"
+ }.freeze
+ INK = "#1f2330"
+ MUTED = "#6b7280"
+ GRID = "#eef0f3"
+ FONT = "-apple-system, 'Segoe UI', Helvetica, Arial, sans-serif"
+ TICKS = [60, 300, 600, 900, 1800, 3600, 7200, 10_800, 21_600, 43_200, 86_400, 172_800, 604_800].freeze
+ STATUSES = ["passed", "failed", "not run", "no scenario"].freeze
+
+ # The report's charts by file name, leaving out any the plan has no data for yet.
+ def self.report(plan, stats: Statistics.new(plan))
+ { "statistics-proof.svg" => proof(Evidence.matrix(plan)), "statistics-burnup.svg" => burnup(stats),
+ "statistics-timeline.svg" => timeline(stats), "statistics-time.svg" => breakdown(stats) }.compact
+ end
+
+ module_function
+
+ # Criteria merged (blue) and proven by a passing test (green), against the plan's scope.
+ def burnup(stats)
+ data = stats.burnup or return
+ width = 760
+ height = 320
+ box = { left: 44, right: 24, top: 84, bottom: 36 }
+ x = scale_time(data[:from], data[:to], box[:left], width - box[:right])
+ top = [data[:scope], 1].max
+ y = ->(value) { box[:top] + ((1 - (value.to_f / top)) * (height - box[:top] - box[:bottom])) }
+ parts = [heading("Acceptance criteria, merged and proven", "#{data[:scope]} in scope")]
+ parts << legend([["Merged", COLORS["agent"]], ["Proven by a passing test", COLORS["passed"]],
+ ["Scope", MUTED]], 20, 70)
+ parts << value_grid(top, y, box[:left], width - box[:right])
+ parts << time_axis(data[:from], data[:to], x, height - box[:bottom], box[:top])
+ parts << (%())
+ parts << step_series(data[:merged], data[:to], x, y, COLORS["agent"], fill: true)
+ parts << step_series(data[:proven], data[:to], x, y, COLORS["passed"])
+ parts << run_dots(data[:proven].drop(1), x, y)
+ svg(width, height, parts.join("\n"), title: "Acceptance criteria merged and proven over time")
+ end
+
+ # One row per ticket on a shared clock: queued, agent coding, waiting for review, fixing
+ # feedback, approved but not merged.
+ def timeline(stats)
+ rows = stats.tickets.select { |row| row.segments.any? }
+ return if rows.empty?
+
+ from, to = stats.window
+ width = 760
+ box = { left: 190, right: 100, top: 84, bottom: 36 }
+ row_height = 30
+ height = box[:top] + (rows.size * row_height) + box[:bottom]
+ x = scale_time(from, to, box[:left], width - box[:right])
+ phases = Statistics::PHASES.select { |phase, _| rows.any? { |row| row.seconds(phase).positive? } }
+ parts = [heading("Where the time went, ticket by ticket", "#{Statistics.duration(to - from)} in development")]
+ parts << legend(phases.map { |phase, label| [label, COLORS[phase]] }, 20, 70)
+ parts << time_axis(from, to, x, height - box[:bottom], box[:top])
+ rows.each_with_index do |row, index|
+ parts << ticket_row(row, box[:top] + (index * row_height), x, box[:left])
+ end
+ svg(width, height, parts.join("\n"), title: "Where the time went, ticket by ticket")
+ end
+
+ # How the time tickets were worked on splits between agents and people.
+ def breakdown(stats)
+ totals = stats.totals.slice(*Statistics::WORK).select { |_, seconds| seconds.positive? }
+ sum = totals.values.sum
+ return if sum.zero?
+
+ width = 760
+ height = 250
+ center = [130, 150]
+ radius = 72
+ circumference = 2 * Math::PI * radius
+ offset = 0.0
+ rings = totals.map do |phase, seconds|
+ length = circumference * seconds / sum
+ ring = %() +
+ %(#{esc(Statistics::PHASES[phase])}: #{Statistics.duration(seconds)})
+ offset += length
+ ring
+ end
+ share = stats.agent_share
+ parts = [heading("Agents and people", "while tickets were being worked on")]
+ parts += rings
+ parts << (%(#{share}%))
+ parts << %(agents)
+ totals.each_with_index do |(phase, seconds), index|
+ top = 100 + (index * 30)
+ percent = (seconds * 100.0 / sum).round
+ parts << %()
+ parts << %(#{esc(Statistics::PHASES[phase])})
+ parts << (%(#{Statistics.duration(seconds)}))
+ parts << %(#{percent}%)
+ end
+ svg(width, height, parts.join("\n"), title: "Time split between agents and people")
+ end
+
+ # Every acceptance criterion's result in one bar.
+ def proof(rows)
+ return if rows.empty?
+
+ width = 760
+ height = 104
+ counts = STATUSES.to_h { |status| [status, rows.count { |row| row.status == status }] }
+ passed = counts["passed"]
+ color = if passed == rows.size then COLORS["passed"]
+ elsif counts["failed"].positive? then COLORS["failed"]
+ else INK
+ end
+ parts = [%() +
+ %(#{passed} of #{rows.size} acceptance criteria proven)]
+ left = 20.0
+ span = width - 40.0
+ parts << %()
+ segments = counts.filter_map do |status, count|
+ next if count.zero?
+
+ length = span * count / rows.size
+ bar = %() +
+ %(#{count} #{status})
+ left += length
+ bar
+ end
+ parts << %(#{segments.join})
+ shown = counts.reject { |_, count| count.zero? }
+ parts << legend(shown.map { |status, count| ["#{count} #{status}", COLORS[status]] }, 20, 90)
+ svg(width, height, parts.join("\n"), title: "#{passed} of #{rows.size} acceptance criteria proven")
+ end
+
+ def svg(width, height, body, title:)
+ <<~SVG
+
+ SVG
+ end
+
+ def heading(text, note)
+ %(#{esc(text)}) +
+ %(#{esc(note)})
+ end
+
+ def legend(items, left, top)
+ x = left
+ items.map do |label, color|
+ item = %() +
+ %(#{esc(label)})
+ x += (label.length * 6.6) + 40
+ item
+ end.join
+ end
+
+ def scale_time(from, to, left, right)
+ start = from.to_f
+ length = [to.to_f - start, 1].max
+ ->(time) { left + ((time.to_f - start) / length * (right - left)) }
+ end
+
+ # Round values up the axis: 0, 10, 20, 30, 40 rather than 0, 11, 21, 32, 42.
+ def value_grid(top, y, left, right)
+ step = [1, 2, 5, 10, 20, 25, 50, 100, 200, 500].find { |size| top / size <= 5 } || (top / 5.0).ceil
+ (0..top).step(step).map do |value|
+ %() +
+ %(#{value})
+ end.join
+ end
+
+ # Clock ticks at a round interval, labelled in the plan's own time zone.
+ def time_axis(from, to, x, bottom, top)
+ length = to.to_f - from.to_f
+ step = TICKS.find { |seconds| length / seconds <= 7 } || TICKS.last
+ format = step >= 86_400 || length > 86_400 ? "%-d %b" : "%H:%M"
+ first = (from.to_f / step).ceil * step
+ (first..to.to_f).step(step).map do |seconds|
+ time = local(seconds, from)
+ %() +
+ %() +
+ %(#{time.strftime(format)})
+ end.join
+ end
+
+ # A whole number of seconds as a time in the same zone as `like`, without float drift.
+ def local(seconds, like)
+ time = Time.at(seconds)
+ like.respond_to?(:time_zone) ? time.in_time_zone(like.time_zone) : time.getlocal(like.utc_offset)
+ end
+
+ def step_series(points, to, x, y, color, fill: false)
+ path = "M#{f(x[points.first.at])},#{f(y[points.first.value])}"
+ points.drop(1).each { |point| path << " H#{f(x[point.at])} V#{f(y[point.value])}" }
+ path << " H#{f(x[to])}"
+ area = ""
+ area = %() if fill
+ %(#{area})
+ end
+
+ # One dot per evidence run, red when it failed, with the count on the last one.
+ def run_dots(points, x, y)
+ points.each_with_index.map do |point, index|
+ color = point.status == "passed" ? COLORS["passed"] : COLORS["failed"]
+ label = if index == points.size - 1
+ %(#{point.value} proven)
+ end
+ %(Evidence #{point.status}: #{point.value} proven#{label})
+ end.join
+ end
+
+ def ticket_row(row, top, x, left)
+ ticket = row.ticket
+ label = "#{ticket.key} #{ticket.title.to_s.truncate(24)}"
+ bars = row.segments.map do |segment|
+ start = x[segment.from]
+ length = [x[segment.to] - start, 2].max
+ %() +
+ %(#{esc(ticket.key)} · #{esc(Statistics::PHASES[segment.phase])} · ) +
+ %(#{Statistics.duration(segment.seconds)})
+ end
+ finish = x[row.segments.last.to]
+ total = row.merged? ? Statistics.duration(row.cycle_time) : "open"
+ rounds = row.review_rounds.positive? ? " · #{row.review_rounds} fix" : ""
+ %(#{esc(label)}) +
+ bars.join + %(#{esc(total + rounds)})
+ end
+
+ def f(number)
+ number.to_f.round(1).to_s.delete_suffix(".0")
+ end
+
+ def esc(text)
+ CGI.escapeHTML(text.to_s)
+ end
+ end
+end
diff --git a/lib/plan_driven/cli.rb b/lib/plan_driven/cli.rb
index cdc78ec..3863162 100644
--- a/lib/plan_driven/cli.rb
+++ b/lib/plan_driven/cli.rb
@@ -41,6 +41,7 @@ class CLI
"report" => ["PLAN", "Write the delivery report"],
"log" => ["PLAN", "The audit trail"],
"usage" => ["PLAN", "Tokens 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, with the team's changes"],
"question" => ["KEY", "Change or add a question (--title, --ask, --group, --required, --optional, --remove)"],
"configure" => ["", "Store API keys in ~/.plan_driven/config"],
diff --git a/lib/plan_driven/cli/ticket_commands.rb b/lib/plan_driven/cli/ticket_commands.rb
index 2896a2d..321b69d 100644
--- a/lib/plan_driven/cli/ticket_commands.rb
+++ b/lib/plan_driven/cli/ticket_commands.rb
@@ -143,6 +143,26 @@ def cmd_usage(reference = nil)
ui.muted "No price for #{totals[:unpriced].join(", ")}; set config.token_prices to see dollars."
end
+ def cmd_stats(reference = nil)
+ plan = find_plan(reference)
+ stats = Statistics.new(plan)
+ duration = ->(seconds) { Statistics.duration(seconds) }
+ ui.heading "#{plan.key} #{plan.title}: statistics"
+ stats.phases.each { |label, seconds| ui.say " #{label.ljust(22)}#{seconds ? duration[seconds] : "not yet"}" }
+ return ui.muted("Ticket statistics start when the tickets are approved.") unless stats.started?
+
+ show_summary(stats.summary)
+ show_time_split(stats)
+ ui.say
+ ui.table(%w[# Est Queued Agent Review Fixes Merge Rounds Total], stats.tickets.map do |row|
+ [row.ticket.key, row.ticket.estimate.to_s,
+ *%w[queued agent review fixes merge].map do |phase|
+ row.seconds(phase).positive? ? duration[row.seconds(phase)] : "-"
+ end,
+ row.review_rounds.to_s, row.merged? ? duration[row.cycle_time] : row.ticket.status.tr("_", " ")]
+ end)
+ end
+
def cmd_report(reference = nil)
plan = find_plan(reference)
paths = delivery.report(plan)
@@ -152,6 +172,27 @@ def cmd_report(reference = nil)
private
+ def show_summary(summary)
+ ui.say " #{"Idea to delivery".ljust(22)}#{Statistics.duration(summary[:lead_time])}"
+ ui.say " #{"Tickets merged".ljust(22)}#{summary[:merged]} of #{summary[:tickets]}, " \
+ "#{summary[:first_time]} approved the first time"
+ proven = "#{summary[:proven]} of #{summary[:criteria]} acceptance criteria proven"
+ summary[:proven] == summary[:criteria] ? ui.success(proven) : ui.warn(proven)
+ end
+
+ def show_time_split(stats)
+ work = stats.work_seconds
+ return if work.zero?
+
+ ui.say
+ ui.say "Where the time went while tickets were worked on (agents #{stats.agent_share}%):"
+ stats.totals.slice(*Statistics::WORK).each do |phase, seconds|
+ share = seconds * 100.0 / work
+ ui.say " #{Statistics::PHASES[phase].ljust(22)}#{Statistics.duration(seconds).rjust(10)} " \
+ "#{"█" * (share / 4).ceil} #{share.round}%"
+ end
+ end
+
def explain_waiting(plan)
running = plan.tickets.count(&:active_agent?)
if plan.tickets.any?(&:ready?) && running >= PlanDriven.configuration.max_parallel_agents
diff --git a/lib/plan_driven/evidence.rb b/lib/plan_driven/evidence.rb
index e5dc551..adfcd53 100644
--- a/lib/plan_driven/evidence.rb
+++ b/lib/plan_driven/evidence.rb
@@ -21,6 +21,9 @@ def status
# when plan-driven itself was started from a development server (the wizard).
CUCUMBER_ENV = { "RAILS_ENV" => "test", "RACK_ENV" => "test" }.freeze
+ # Shown before each result in the Markdown report, so it reads at a glance on GitHub too.
+ MARKS = { "passed" => "✅", "failed" => "❌", "not run" => "⏸️", "no scenario" => "⚠️" }.freeze
+
module_function
def tag_expression(plan)
@@ -76,8 +79,8 @@ def scenario_status(element)
"not run"
end
- def matrix(plan)
- scenarios = plan.evidence_runs.last&.scenarios || []
+ def matrix(plan, run = plan.evidence_runs.last)
+ scenarios = run&.scenarios || []
plan.tickets.flat_map do |ticket|
ticket.criteria.each_with_index.map do |criterion, index|
matching = scenarios.select do |scenario|
@@ -94,7 +97,7 @@ def matrix_markdown(plan)
rows = matrix(plan).map do |row|
scenario = row.scenarios.map { |s| "#{s["name"]} (`#{s["file"]}`)" }.join("; ").presence || "-"
- ["#{row.ticket.key}.#{row.number}", row.criterion, scenario, row.status]
+ ["#{row.ticket.key}.#{row.number}", row.criterion, scenario, "#{MARKS[row.status]} #{row.status}"]
end
commit = run.commit_sha.present? ? " on commit `#{run.commit_sha[0, 7]}`" : ""
intro = "Cucumber, run #{run.created_at.strftime("%-d %b %Y %H:%M")}#{commit}: `#{run.command}`"
diff --git a/lib/plan_driven/renderer.rb b/lib/plan_driven/renderer.rb
index e47ed60..40187f9 100644
--- a/lib/plan_driven/renderer.rb
+++ b/lib/plan_driven/renderer.rb
@@ -17,23 +17,30 @@ def write_plan(plan, config: PlanDriven.configuration)
write(plan, "plan", Markdown.plan(plan, config: config), title: "#{plan.key} #{plan.title}", config: config)
end
+ # The charts are SVG files beside the report, so GitHub shows them in the Markdown; the HTML
+ # and the PDF carry them inline.
def write_report(plan, config: PlanDriven.configuration)
- write(plan, "delivery-report", Markdown.report(plan),
- title: "#{plan.key} delivery report", config: config)
+ charts = Charts.report(plan)
+ dir = directory(plan, config: config)
+ FileUtils.mkdir_p(dir)
+ Dir[dir.join("statistics-*.svg")].each { |file| File.delete(file) }
+ charts.each { |name, svg| File.write(dir.join(name), svg) }
+ write(plan, "delivery-report", Markdown.report(plan, charts: charts.keys),
+ title: "#{plan.key} delivery report", config: config, images: charts)
end
def directory(plan, config: PlanDriven.configuration)
config.docs_root.join(plan.slug)
end
- def write(plan, name, markdown, title:, config:)
+ def write(plan, name, markdown, title:, config:, images: {})
dir = directory(plan, config: config)
FileUtils.mkdir_p(dir)
md = dir.join("#{name}.md")
html = dir.join("#{name}.html")
pdf = dir.join("#{name}.pdf")
File.write(md, markdown)
- File.write(html, HTML.document(markdown, title: title))
+ File.write(html, HTML.document(markdown, title: title, images: images))
written = PDF.render(html, pdf, config: config)
{ markdown: md, html: html, pdf: written ? pdf : nil }
end
diff --git a/lib/plan_driven/renderer/html.rb b/lib/plan_driven/renderer/html.rb
index 082e1f2..2195511 100644
--- a/lib/plan_driven/renderer/html.rb
+++ b/lib/plan_driven/renderer/html.rb
@@ -7,10 +7,14 @@ module Renderer
# and doesn't need to be.
module HTML
STYLE = File.read(File.expand_path("style.css", __dir__))
+ IMAGE = /\A!\[([^\]]*)\]\(([^)\s]+)\)\z/
+ # A table cell that is only a result becomes a coloured pill, and colours its row.
+ RESULT = /\A(?:#{Evidence::MARKS.values.map { |mark| Regexp.escape(mark) }.join("|")})?\s*
+ (passed|failed|not\ run|no\ scenario|merged)\z/x
module_function
- def document(markdown, title:)
+ def document(markdown, title:, images: {})
<<~HTML
@@ -21,19 +25,22 @@ def document(markdown, title:)
- #{convert(markdown)}
+ #{convert(markdown, images: images)}