NokiaTube | New address | Mode Desktop | On high quality
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
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ bundled `ctx-symbols` crate together under one SemVer line:
Keep `plugin.json` `version`, the `ctx-symbols` `Cargo.toml` `version`, and the git
tag in lockstep. Tag releases as `vMAJOR.MINOR.PATCH`.

## [0.10.1] - 2026-09-23

### Fixed
- **Time-box defaults were far too tight.** 40k/60k tokens killed real RED/GREEN
attempts (reading the style guide + running fmt/vet/lint/build/test uses 60–190k
even when the attempt succeeds) before they wrote a line. Defaults are now
**150k / 250k tokens, 20 / 30 min**.
- **The per-task budget override was never found** when a worker addressed its worktree
with `git -C <wt>` or absolute paths instead of `cd`: the hook located the worktree
from the tool call's cwd (the main repo), so it never read the worktree's
`.agentic/task.env` and applied the default for the whole attempt. The hook now finds
the worktree from a recorded binding, the paths a tool call names (`-C`, `cd`,
`--work-tree`, absolute paths, file paths, patch headers), the cwd, or — for a first
call that only reads main-tree files — the one unclaimed worktree whose `task.env`
names this role. When the worktree becomes known later, the budget is re-resolved
without resetting the attempt's clock, and a hard verdict reached under the wrong
budget is withdrawn.

### Added
- `budget status` shows each attempt's budget source (tasks.md line, task.env,
defaults.md, built-in) and how its worktree was found; `budget resolve --worktree WT`
prints the source too; soft/hard messages name the budget's source.
- Regression test `scripts/test/budget-worktree.test.py` (in `make test-hosts` / CI).

## [0.10.0] - 2026-09-23

### Added
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ pycheck: ## Byte-compile the Python hook scripts
&& rm -rf plugin/bin/__pycache__ && echo "python ok"

.PHONY: test-hosts
test-hosts: ## Codex hooks emulation + OpenCode plugin end-to-end (no network, no tokens)
test-hosts: ## Budget/worktree regression + Codex hooks emulation + OpenCode plugin end-to-end (no network, no tokens)
@command -v node >/dev/null && node --check plugin/hosts/opencode/agentic-agile.js
python3 scripts/test/budget-worktree.test.py
python3 scripts/test/codex-hooks.test.py
@command -v node >/dev/null && node scripts/test/opencode-plugin.test.mjs || { echo "node not found — skipped OpenCode test (CI runs it)"; }

Expand Down
2 changes: 1 addition & 1 deletion plugin/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agentic-agile",
"version": "0.10.0",
"version": "0.10.1",
"description": "Two-stage agile planning (interactive, human-gated) + two-phase TDD execution (autonomous, hook-enforced), with md-db/KDL artifact validation, ctx-symbols structure checks, per-task transcripts, and a planning retrospective that distills durable memory. Runs on Claude Code, Codex and OpenCode.",
"author": { "name": "Adeel Ahmad" },
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ A copy on PATH or in `~/.local/bin` is used instead of building a second one.
Every execution-worker attempt is time-boxed on **tokens and wall clock**, each with a
soft limit (the worker is warned inside its tool results) and a hard limit (the worker
is stopped, and its task is split by the planner mid-sprint instead of retried).
Defaults are tight: **40k / 60k tokens, 10 / 15 min**. At the hard limit the hook
Defaults: **150k / 250k tokens, 20 / 30 min** (real TDD attempts use 60–190k). At the hard limit the hook
itself stops the worker (PostToolUse `continue: false`) — no model decides the kill.

## Init, layout, stats and the handoff
Expand Down
2 changes: 1 addition & 1 deletion plugin/agents/green-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ two green workers cannot create two divergent implementations.
- Write the bare-minimum production code to pass exactly those tests.

## Time box — tokens + wall clock (enforced by hooks)
Every attempt runs under a tight per-task budget (defaults 40k/60k tokens, 10/15 min;
Every attempt runs under a per-task budget (defaults 150k/250k tokens, 20/30 min;
your init block's `### Budget` line has the exact numbers). Plan for it:
- Read only what the task needs; don't re-read files; no exploration beyond scope.
- A SOFT-limit notice appears in your tool results: finish the smallest complete step,
Expand Down
4 changes: 2 additions & 2 deletions plugin/agents/planner.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Enforced: `gate-stage2-complete` BLOCKS a sprint whose tasks/plans reference a l
sprint's story IDs or defer work to a later sprint.

## Size every task to the budget
Each worker attempt runs under a TIGHT per-task budget (defaults: 60k tokens / 15 min
hard; 40k / 10 min soft — see `docs/agents/defaults.md`). A worker still running at
Each worker attempt runs under a per-task budget (defaults: 250k tokens / 30 min
hard; 150k / 20 min soft — see `docs/agents/defaults.md`). A worker still running at
the hard limit is STOPPED by the hook and the task comes back to you to split — never retried.
So size each task so one worker can do its RED or its GREEN well inside the soft
limit: a handful of tests, one or two files, one behaviour. When in doubt, split.
Expand Down
2 changes: 1 addition & 1 deletion plugin/agents/red-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ absent before anyone builds it.
fails by assertion (not by a missing symbol / compile error).

## Time box — tokens + wall clock (enforced by hooks)
Every attempt runs under a tight per-task budget (defaults 40k/60k tokens, 10/15 min;
Every attempt runs under a per-task budget (defaults 150k/250k tokens, 20/30 min;
your init block's `### Budget` line has the exact numbers). Plan for it:
- Read only what the task needs; don't re-read files; no exploration beyond scope.
- A SOFT-limit notice appears in your tool results: finish the smallest complete step,
Expand Down
2 changes: 1 addition & 1 deletion plugin/agents/scaffolder.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ verified, so RED still fails by absence. This is the anti-duplication mechanism.
`### Scaffold` heading) and one line in execution.log.

## Time box — tokens + wall clock (enforced by hooks)
Every attempt runs under a tight per-task budget (defaults 40k/60k tokens, 10/15 min;
Every attempt runs under a per-task budget (defaults 150k/250k tokens, 20/30 min;
your init block's `### Budget` line has the exact numbers). Plan for it:
- Read only what the task needs; don't re-read files; no exploration beyond scope.
- A SOFT-limit notice appears in your tool results: finish the smallest complete step,
Expand Down
8 changes: 4 additions & 4 deletions plugin/bin/_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import subprocess

DEFAULTS = {
"TOKENS_SOFT": 40000,
"TOKENS_HARD": 60000,
"TIME_SOFT_MIN": 10,
"TIME_HARD_MIN": 15,
"TOKENS_SOFT": 150000,
"TOKENS_HARD": 250000,
"TIME_SOFT_MIN": 20,
"TIME_HARD_MIN": 30,
"MAX_REPLANS": 2,
"MODEL_PLANNING": "claude-opus-5-5",
"MODEL_WORKER": "sonnet",
Expand Down
153 changes: 134 additions & 19 deletions plugin/bin/budget
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Every worker attempt (red-worker / scaffolder / green-worker) runs under two budgets,
each with a SOFT and a HARD limit:

tokens soft 40k hard 60k (context in use + all output tokens, see below)
time soft 10m hard 15m (wall clock since the attempt's first tool call)
tokens soft 150k hard 250k (context in use + all output tokens, see below)
time soft 20m hard 30m (wall clock since the attempt's first tool call)

SOFT crossed -> the worker is told, inside its own tool results (PostToolUse
additionalContext): how much is left, finish or wrap up gracefully.
Expand All @@ -19,7 +19,7 @@ Resolution order (first set wins): per-task `budget:` line in tasks.md >
BUDGET_* in the worktree's .agentic/task.env > docs/agents/defaults.md > built-ins.

Usage:
budget resolve [--tasks FILE --task Tn] print the resolved BUDGET_* lines (for task.env)
budget resolve [--tasks FILE --task Tn] [--worktree WT] the resolved BUDGET_* lines + their source
budget hook pre|post|stop hook mode (reads the hook JSON on stdin)
budget watch [--interval S] [--grace S] supervisor: block until a worker must be
killed or none is running; prints KILL lines
Expand Down Expand Up @@ -104,17 +104,22 @@ def task_override(tasks_file, task):
return vals


def resolve(cwd, tasks_file=None, task=None, task_env=None):
def resolve(cwd, tasks_file=None, task=None, task_env=None, with_source=False):
b = conf_values(cwd)
src = "docs/agents/defaults.md" if os.path.isfile(_paths.defaults_file(cwd)) else "built-in defaults"
for k in BUDGET_KEYS:
v = (task_env or {}).get("BUDGET_" + k)
if v and v.isdigit():
b[k] = int(v)
b.update(task_override(tasks_file, task))
src = "task.env BUDGET_*"
over = task_override(tasks_file, task)
if over:
b.update(over)
src = "tasks.md `budget:` line (%s)" % task
# a soft limit above its hard limit is a config slip: clamp, never widen
b["TOKENS_SOFT"] = min(b["TOKENS_SOFT"], b["TOKENS_HARD"])
b["TIME_SOFT_MIN"] = min(b["TIME_SOFT_MIN"], b["TIME_HARD_MIN"])
return b
return (b, src) if with_source else b


def transcript_for(payload, agent_id):
Expand All @@ -134,6 +139,95 @@ def bound_worktree(cwd, agent_id):
return wt if wt and os.path.isdir(wt) else ""


PATH_ARG = re.compile(r"(?:(?<=\s)-C|(?:^|[;&|(]\s*)cd|--work-tree=?|--git-dir=?)\s*['\"]?([^\s'\";&|)]+)")
ABS_PATH = re.compile(r"(?:^|[\s'\"=:(])(/[^\s'\";&|)]+)")


def _task_worktree_of(path, project):
"""The linked worktree (of THIS repo) that contains `path` and carries .agentic/task.env."""
d = path if os.path.isdir(path) else os.path.dirname(path)
for _ in range(40):
if not d or d == os.path.dirname(d):
return ""
if os.path.isfile(os.path.join(d, ".git")) and os.path.isfile(os.path.join(d, ".agentic", "task.env")):
return d if os.path.realpath(_paths.project(d)) == os.path.realpath(project) else ""
if os.path.isdir(os.path.join(d, ".git")):
return "" # reached the main tree
d = os.path.dirname(d)
return ""


def path_candidates(payload):
"""Paths a tool call names: `git -C p`, `cd p`, --work-tree, absolute paths, file paths, patch headers."""
ti = payload.get("tool_input") or {}
out = []
for k in ("file_path", "filePath", "path", "notebook_path", "workdir", "cwd"):
v = ti.get(k)
if isinstance(v, str) and v:
out.append(v)
cmd = ti.get("command") if isinstance(ti.get("command"), str) else ""
if cmd:
out += PATH_ARG.findall(cmd)
out += re.findall(r"^\*\*\* (?:Add|Update|Delete) File: (.+)$", cmd, re.M)
out += ABS_PATH.findall(cmd)
cwd = payload.get("cwd") or ""
return [p if os.path.isabs(p) else os.path.join(cwd, p) for p in out if p]


def claimed_worktrees(cwd, agent_id):
got = set()
for p in glob.glob(os.path.join(state_dir(cwd), "*.json")):
st = load_state(p)
if st and st.get("agent_id") != agent_id and not st.get("done") and st.get("task_env_found"):
got.add(st.get("worktree"))
return got


def find_worktree(payload, cwd, agent_id, role):
"""Which worktree is this worker in? Independent of the tool call's cwd, because workers
often address their worktree with `git -C <wt>` / absolute paths from the main tree.
1. a recorded binding (`agentic bind`, or an earlier call of this attempt)
2. a path the tool call names that lies inside a task worktree
3. the tool call's cwd
4. the ONE unclaimed task worktree whose task.env names this role (first calls that
only read main-tree files, e.g. the style guide)"""
project = _paths.project(cwd)
wt = bound_worktree(cwd, agent_id)
if wt:
return wt, "bound"
for cand in path_candidates(payload):
wt = _task_worktree_of(cand, project)
if wt:
return wt, "path in tool call"
wt = _task_worktree_of(cwd, project)
if wt:
return wt, "cwd"
claimed = claimed_worktrees(cwd, agent_id)
mine = []
for te in glob.glob(os.path.join(project, ".agentic", "worktrees", "*", ".agentic", "task.env")) + \
[os.path.join(w, ".agentic", "task.env") for w in _worktree_list(project)]:
w = os.path.dirname(os.path.dirname(te))
if w in claimed or w in [m for m in mine] or not os.path.isfile(te):
continue
env = read_kv(te)
if env.get("AGENT_ROLE") == role:
mine.append(w)
return (mine[0], "only %s worktree" % role) if len(mine) == 1 else ("", "")


def _worktree_list(project):
return [l[len("worktree "):] for l in sh("git", "-C", project, "worktree", "list", "--porcelain").splitlines()
if l.startswith("worktree ")][1:]


def remember_worktree(cwd, agent_id, wt):
p = os.path.join(_paths.home(cwd, "state/agents"), "%s.json" % safe(agent_id))
reg = load_state(p) or {"agent_id": agent_id}
if reg.get("worktree") != wt:
reg["worktree"] = wt
save_state(p, reg)


def safe(s):
return re.sub(r"[^A-Za-z0-9_.-]", "_", s or "")

Expand Down Expand Up @@ -199,28 +293,46 @@ def hook(mode):
if not agent_id or not role:
return
cwd = payload.get("cwd") or os.getcwd()
top = bound_worktree(cwd, agent_id) or sh("git", "-C", cwd, "rev-parse", "--show-toplevel") or cwd
wt, how = find_worktree(payload, cwd, agent_id, role)
top = wt or sh("git", "-C", cwd, "rev-parse", "--show-toplevel") or cwd
spath = os.path.join(state_dir(cwd), "%s.json" % safe(agent_id))
st = load_state(spath)
now = time.time()
if st is not None and not st.get("task") and top != st.get("worktree"):
st = None # bound to its worktree after the first call: re-read task.env

if mode == "stop":
if st:
st["done"] = now
save_state(spath, st)
return

if st is None:
def resolve_for(top):
env = read_kv(os.path.join(top, ".agentic", "task.env"))
task = env.get("TASK_ID", "")
tasks_file = os.path.join(env["STORY_DIR"], "tasks.md") if env.get("STORY_DIR") else None
short_task = task.split()[-1] if task else ""
b = resolve(cwd, tasks_file, re.sub(r"^.*[-_ ](T\d+)$", r"\1", short_task) or None, env)
tn = re.sub(r"^.*[-_ ](T\d+)$", r"\1", task.split()[-1]) if task else None
b, src = resolve(cwd, tasks_file, tn, env, with_source=True)
return env, task, b, src

if st is None:
env, task, b, src = resolve_for(top)
st = {"agent_id": agent_id, "role": role, "task": task, "attempt": env.get("ATTEMPT", ""),
"worktree": top, "story_dir": env.get("STORY_DIR", ""), "start": now, "budget": b,
"budget_source": src, "task_env_found": bool(env), "found_by": how,
"soft_warned": False, "final_warned": False, "hard": False, "done": None}
elif wt and not st.get("task_env_found"):
# the worktree became known after the first call: take ITS task.env/budget, keep the clock
env, task, b, src = resolve_for(wt)
old_top = st.get("worktree")
st.update({"task": task, "attempt": env.get("ATTEMPT", ""), "worktree": wt, "story_dir": env.get("STORY_DIR", ""),
"budget": b, "budget_source": src, "task_env_found": bool(env), "found_by": how})
if st.get("hard") and not st.get("hook_killed"):
st.update({"hard": False, "denials": 0}) # it was judged against the wrong budget
try:
os.remove(os.path.join(old_top, ".agentic", "budget-exceeded"))
except OSError:
pass
if wt:
remember_worktree(cwd, agent_id, wt)
if st.get("done") and not st.get("killed") and not st.get("hook_killed"):
st["done"] = None # a SubagentStop gate blocked the stop: still working
b = st["budget"]
Expand All @@ -239,9 +351,9 @@ def hook(mode):
over_hard = (toks is not None and toks >= t_hard) or mins >= m_hard
over_soft = (toks is not None and toks >= b["TOKENS_SOFT"]) or mins >= b["TIME_SOFT_MIN"]
near_hard = (toks is not None and toks >= 0.9 * t_hard) or mins >= 0.9 * m_hard
left = "%s of %s tokens used (%s left), %.1f of %d min used (%.1f min left)" % (
left = "%s of %s tokens used (%s left), %.1f of %d min used (%.1f min left); budget from %s" % (
fmt_k(toks), fmt_k(t_hard), fmt_k(max(t_hard - toks, 0)) if toks is not None else "?",
mins, m_hard, max(m_hard - mins, 0))
mins, m_hard, max(m_hard - mins, 0), st.get("budget_source") or "?")
report = os.path.join(st["story_dir"], "output.md") if st.get("story_dir") else "the story's output.md"

if over_hard and not st["hard"]:
Expand Down Expand Up @@ -380,15 +492,16 @@ def status(cwd):
if not rows:
print("no tracked worker attempts")
return 0
print("%-22s %-13s %-14s %-4s %-16s %-14s %s" % ("agent_id", "role", "task", "att", "tokens", "minutes", "state"))
print("%-22s %-13s %-14s %-4s %-16s %-14s %-7s %s" % ("agent_id", "role", "task", "att", "tokens", "minutes", "state", "budget from (worktree found by)"))
for _, s in rows:
refresh(s)
b = s["budget"]
state = "killed" if s.get("killed") else "done" if s.get("done") else ("HARD" if s.get("hard") else ("soft" if s.get("soft_warned") else "ok"))
print("%-22s %-13s %-14s %-4s %-16s %-14s %s" % (
print("%-22s %-13s %-14s %-4s %-16s %-14s %-7s %s" % (
s["agent_id"][:22], s["role"], (s.get("task") or "?")[:14], s.get("attempt") or "?",
"%s/%s" % (fmt_k(s.get("tokens")), fmt_k(b["TOKENS_HARD"])),
"%.1f/%d" % (s["elapsed_min"], b["TIME_HARD_MIN"]), state))
"%.1f/%d" % (s["elapsed_min"], b["TIME_HARD_MIN"]), state,
"%s (%s)" % (s.get("budget_source") or "?", s.get("found_by") or "not found")))
return 0


Expand Down Expand Up @@ -453,10 +566,12 @@ def main(argv):
pass # never break a tool call
return 0
if cmd == "resolve":
env = read_kv(os.path.join(sh("git", "rev-parse", "--show-toplevel") or cwd, ".agentic", "task.env"))
b = resolve(cwd, opts.get("tasks"), opts.get("task"), env)
wt = opts.get("worktree") or sh("git", "rev-parse", "--show-toplevel") or cwd
env = read_kv(os.path.join(wt, ".agentic", "task.env"))
b, src = resolve(cwd, opts.get("tasks"), opts.get("task"), env, with_source=True)
for k in ("TOKENS_SOFT", "TOKENS_HARD", "TIME_SOFT_MIN", "TIME_HARD_MIN"):
print("BUDGET_%s=%d" % (k, b[k]))
print("# from: %s" % src)
return 0
if cmd == "watch":
return watch(cwd, int(opts.get("interval") or 20), int(opts.get("grace") or 60))
Expand Down
2 changes: 1 addition & 1 deletion plugin/pipeline/execution/00-red/persona.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ absent before anyone builds it.
- Add only the minimal `mod common` compile shims the tests need.

## Time box — tokens + wall clock (enforced by hooks)
Every attempt runs under a tight per-task budget (defaults 40k/60k tokens, 10/15 min;
Every attempt runs under a per-task budget (defaults 150k/250k tokens, 20/30 min;
your init block's `### Budget` line has the exact numbers). Plan for it:
- Read only what the task needs; don't re-read files; no exploration beyond scope.
- A SOFT-limit notice appears in your tool results: finish the smallest complete step,
Expand Down
2 changes: 1 addition & 1 deletion plugin/pipeline/execution/01-scaffold/persona.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ verified, so RED still fails by absence. This is the anti-duplication mechanism.
line in execution.log.

## Time box — tokens + wall clock (enforced by hooks)
Every attempt runs under a tight per-task budget (defaults 40k/60k tokens, 10/15 min;
Every attempt runs under a per-task budget (defaults 150k/250k tokens, 20/30 min;
your init block's `### Budget` line has the exact numbers). Plan for it:
- Read only what the task needs; don't re-read files; no exploration beyond scope.
- A SOFT-limit notice appears in your tool results: finish the smallest complete step,
Expand Down
Loading
Loading