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
4 changes: 2 additions & 2 deletions .workflow/tasks/WB-58.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"key": "WB-58",
"title": "Critical-zone and misleading tickets still cost 3-7x a plain session",
"type": "chore",
"status": "open",
"status": "done",
"desc": "The clean bench run (bench/results/2026-09-27-9abd3c9) met WB-53's 2x target on BN-7 and on BN-3's wall time and cost, not elsewhere. BN-4 (bug in shop/users.py, user-data zone) cost 6.7x tokens: wb finish only learns the change is in a critical zone after it is made, sends it to the standard route, and the session discarded its working fix to re-plan it. BN-6 cost 2.8x, spent tracing the live code path that plain skipped.\n\nACCEPTANCE:\n- a ticket whose change lands in a critical zone keeps the change it already made when it moves to the standard route, and the plan starts from that diff instead of from scratch\n- wb start says up front when the ticket's likely files are in a critical zone, so the session plans first instead of finishing twice\n- the bench's BN-4 ratio is measured again and the README table updated",
"created": "2026-09-27T03:04:45Z",
"updated": "2026-09-27T03:04:45Z",
"updated": "2026-09-27T03:48:20Z",
"comments": [],
"linked": [
{
Expand Down
16 changes: 16 additions & 0 deletions .workflow/tasks/WB-60.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"key": "WB-60",
"title": "The billing zone matches any path containing plan",
"type": "bug",
"status": "open",
"desc": "profile.CRITICAL_ZONES['billing'] is billing|payment|invoice|subscription|checkout|stripe|paddle|quota|plan, matched anywhere in a path. skills/plan-change/SKILL.md, planner.py or explanation.md read as billing and are held to the critical bar; wb finish sent WB-58 to the standard route for it.\n\nACCEPTANCE:\n- plan matches a pricing plan (plans/, plan_limits, subscription_plan) and not plan-change, planner or explanation\n- a test pins both sides; plans already audited with the old zones re-audit cleanly or say why",
"created": "2026-09-27T03:48:12Z",
"updated": "2026-09-27T03:48:12Z",
"comments": [],
"linked": [
{
"key": "WB-58",
"type": "relates"
}
]
}
5 changes: 3 additions & 2 deletions lib/workbench/cli/finish.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def run(args: argparse.Namespace) -> int:
if result.outgrew:
light.unmark(key, root)
raise WbError(
f"{key} outgrew the light path: {result.outgrew}. It now takes the standard route; the change stays",
f"{key} outgrew the light path: {result.outgrew}. It now takes the standard route. "
"Keep the change on disk and do not revert it: the plan cites the code at HEAD, so plan around it",
code=EXIT_AUDIT,
fix=[f"plan it: (plan-change) then wb sdd audit {key}"],
fix=[f"plan it: (plan-change) then wb sdd audit {key}, then wb impl verify {key} on the change already made"],
)
if not result.ok:
raise WbError(f"{key}: " + "; ".join(result.blocked), code=EXIT_AUDIT, fix=result.fix)
Expand Down
8 changes: 5 additions & 3 deletions lib/workbench/cli/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(args: argparse.Namespace) -> int:
print("triage already read (--refresh to read it again)")
print(f"branch {where}")

_choose_path(key, kind, root)
_choose_path(key, kind, root, f"{title}\n{triage.get('desc') or ''}")
tier, reason, steps = route_cli.compute(key, root)
print(f"route {tier}: {', '.join(name for name, _, _ in steps)} ({reason})")
if light.marker(key, root) is not None:
Expand All @@ -73,7 +73,7 @@ def run(args: argparse.Namespace) -> int:
return 0


def _choose_path(key: str, kind: str, root: Path) -> None:
def _choose_path(key: str, kind: str, root: Path, text: str = "") -> None:
"""Put eligible work on the light path, once, before anything is planned.

A ticket that already has a plan keeps it: the path is chosen at the start,
Expand All @@ -86,9 +86,11 @@ def _choose_path(key: str, kind: str, root: Path) -> None:
if not light.enabled(root):
light.unmark(key, root)
return
allowed, _ = light.eligible(key, kind, root)
allowed, reason = light.eligible(key, kind, root, text)
if allowed:
light.mark(key, root)
elif "zone" in reason:
print(f"light no: {reason}")


def _triage(key: str, root: Path, *, refresh: bool) -> tuple[dict, bool]:
Expand Down
46 changes: 44 additions & 2 deletions lib/workbench/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from __future__ import annotations

import json
import re
import shlex
from dataclasses import dataclass, field
from pathlib import Path
Expand Down Expand Up @@ -64,8 +65,14 @@ def enabled(root: Path) -> bool:
return profile.repo_config(root).get(CONFIG_KEY) is not False


def eligible(key: str, kind: str, root: Path) -> tuple[bool, str]:
"""Whether a ticket may start on the light path, and why (not)."""
def eligible(key: str, kind: str, root: Path, text: str = "") -> tuple[bool, str]:
"""Whether a ticket may start on the light path, and why (not).

``text`` is the ticket's own words. A function it names that is defined in
a critical zone sends it to the standard route before any change is made:
found out at wb finish instead, the zone cost a finished fix and a second
pass (WB-58).
"""
if not enabled(root):
return False, f'"{CONFIG_KEY}": false in .workflow/config.json'
if key.startswith(("incident-", "idea-")):
Expand All @@ -75,9 +82,44 @@ def eligible(key: str, kind: str, root: Path) -> tuple[bool, str]:
return False, f"{lowered} work owes a product frame"
if lowered in AUDIENCE:
return False, f"{lowered} work has a reader outside engineering"
zoned = zone_named(text, root) if text else None
if zoned:
name, path, zone = zoned
return False, f"the ticket names {name}, defined in {path}, which is in the {zone} zone: plan it first"
return True, "no plan up front; wb finish holds the change to the floor"


# Names worth looking up: in backticks, snake_case or CamelCase. A plain word
# ("total", "name") would match half the repo and predict nothing.
_NAMED = re.compile(
r"`([A-Za-z_][A-Za-z0-9_]*)(?:\(\))?`|\b([a-z][a-z0-9]*_[a-z0-9_]+)\b|\b([A-Z][a-z0-9]+[A-Z][A-Za-z0-9]*)\b"
)
MAX_NAMES = 6
DEFINERS = ("def {name}(", "class {name}", "function {name}(")


def names(text: str) -> list[str]:
"""Identifiers the ticket names, first mention first, at most MAX_NAMES."""
found: list[str] = []
for match in _NAMED.finditer(text):
name = next(group for group in match.groups() if group)
if name not in found:
found.append(name)
return found[:MAX_NAMES]


def zone_named(text: str, root: Path) -> tuple[str, str, str] | None:
"""(name, file, zone) for the first name the ticket gives that is defined in a critical zone."""
for name in names(text):
for definer in DEFINERS:
files = gitctx.grep_files(root, "HEAD", definer.format(name=name), []) or []
zones = profile.critical_zones(files)
if zones:
zone = sorted(zones)[0]
return name, zones[zone][0], zone
return None


def marker(key: str, root: Path) -> dict | None:
"""The light record for ``key``, or ``None`` when it is not on this path."""
path = artifacts.ticket_dir(key, root) / MARKER
Expand Down
3 changes: 3 additions & 0 deletions skills/plan-change/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ python "${CLAUDE_PLUGIN_ROOT}/lib/wb.py" <args>
3. **Pick a persona** from `references/personas.md`. It shapes what counts as
done, not the format.

A change already on disk (a light-path ticket `finish` moved here) stays:
plan around it, never revert it to plan from scratch.

4. **Confirm everything in the code.** Assume nothing. Every claim about this
codebase needs a `file:line` and the text of that line, because the audit in
step 7 reopens each one. A claim you cannot cite is a question, not a fact —
Expand Down
29 changes: 29 additions & 0 deletions tests/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def test_a_change_past_the_bound_leaves_the_path_for_a_plan(self) -> None:
self.assertEqual(EXIT_AUDIT, code)
self.assertIn("outgrew the light path", err)
self.assertIn("plan-change", err)
self.assertIn("do not revert it", err)
self.assertIsNone(light.marker("ABC-1", self.root))
_, nxt, _ = run("next", "ABC-1")
self.assertIn("plan", nxt)
Expand Down Expand Up @@ -238,6 +239,34 @@ def test_a_bug_s_regression_test_is_proven(self) -> None:
self.assertIn("1 regression test(s) proven", out)


class ZoneNamed(LightPath):
"""WB-58: a ticket naming a function in a critical zone plans first, instead of finishing twice."""

KIND = "bug"

def test_a_named_function_in_a_critical_zone_starts_on_the_standard_route(self) -> None:
self.write("shop/billing/__init__.py", "")
self.write("shop/billing/charge.py", "def charge_card(total):" + chr(10) + " return total" + chr(10))
self.git("add", "-A")
self.git("commit", "-q", "-m", "chore: billing")
code, out, err = run("task", "new", "Cards are charged twice", "--type", "bug",
"--desc", "charge_card runs twice on a retry.", "--key", "ABC-2")
self.assertEqual(0, code, out + err)
code, out, err = run("start", "ABC-2")
self.assertEqual(0, code, out + err)
self.assertIsNone(light.marker("ABC-2", self.root))
self.assertIn("names charge_card, defined in shop/billing/charge.py, which is in the billing zone", out)
self.assertIn("standard", out)

def test_a_named_function_outside_every_zone_keeps_the_light_path(self) -> None:
run("start", "ABC-1")
self.assertIsNotNone(light.marker("ABC-1", self.root), "format_money lives in shop/money.py, no zone")

def test_names_are_the_identifiers_a_ticket_spells_not_its_plain_words(self) -> None:
text = "display_name keeps stray whitespace; `in_stock` and ChargeError, the total and the name."
self.assertEqual(["display_name", "in_stock", "ChargeError"], light.names(text))


class Feature(LightPath):
KIND = "feature"

Expand Down
Loading