diff --git a/CHANGELOG.md b/CHANGELOG.md index 201c2404..98895424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ` 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 diff --git a/Makefile b/Makefile index 0b0c47e3..d103066b 100644 --- a/Makefile +++ b/Makefile @@ -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)"; } diff --git a/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json index 702043d3..08026c49 100644 --- a/plugin/.claude-plugin/plugin.json +++ b/plugin/.claude-plugin/plugin.json @@ -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", diff --git a/plugin/README.md b/plugin/README.md index 3999c512..ea24702e 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -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 diff --git a/plugin/agents/green-worker.md b/plugin/agents/green-worker.md index c5a6c031..04a361af 100644 --- a/plugin/agents/green-worker.md +++ b/plugin/agents/green-worker.md @@ -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, diff --git a/plugin/agents/planner.md b/plugin/agents/planner.md index ffdc2e2e..9711931b 100644 --- a/plugin/agents/planner.md +++ b/plugin/agents/planner.md @@ -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. diff --git a/plugin/agents/red-worker.md b/plugin/agents/red-worker.md index e08c55d1..a90df647 100644 --- a/plugin/agents/red-worker.md +++ b/plugin/agents/red-worker.md @@ -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, diff --git a/plugin/agents/scaffolder.md b/plugin/agents/scaffolder.md index 7db976ac..4a04b4de 100644 --- a/plugin/agents/scaffolder.md +++ b/plugin/agents/scaffolder.md @@ -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, diff --git a/plugin/bin/_paths.py b/plugin/bin/_paths.py index 00da6415..bbfcd0f6 100644 --- a/plugin/bin/_paths.py +++ b/plugin/bin/_paths.py @@ -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", diff --git a/plugin/bin/budget b/plugin/bin/budget index b18c041c..451c1ca1 100755 --- a/plugin/bin/budget +++ b/plugin/bin/budget @@ -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. @@ -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 @@ -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): @@ -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 ` / 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 "") @@ -199,12 +293,11 @@ 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: @@ -212,15 +305,34 @@ def hook(mode): 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"] @@ -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"]: @@ -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 @@ -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)) diff --git a/plugin/pipeline/execution/00-red/persona.md b/plugin/pipeline/execution/00-red/persona.md index b3f88a64..364c489a 100644 --- a/plugin/pipeline/execution/00-red/persona.md +++ b/plugin/pipeline/execution/00-red/persona.md @@ -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, diff --git a/plugin/pipeline/execution/01-scaffold/persona.md b/plugin/pipeline/execution/01-scaffold/persona.md index 7ece5267..fb719696 100644 --- a/plugin/pipeline/execution/01-scaffold/persona.md +++ b/plugin/pipeline/execution/01-scaffold/persona.md @@ -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, diff --git a/plugin/pipeline/execution/02-green/persona.md b/plugin/pipeline/execution/02-green/persona.md index 4153160e..d4b1b668 100644 --- a/plugin/pipeline/execution/02-green/persona.md +++ b/plugin/pipeline/execution/02-green/persona.md @@ -18,7 +18,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, diff --git a/plugin/pipeline/planning/02-planner/persona.md b/plugin/pipeline/planning/02-planner/persona.md index d78818b6..fde97d7e 100644 --- a/plugin/pipeline/planning/02-planner/persona.md +++ b/plugin/pipeline/planning/02-planner/persona.md @@ -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. diff --git a/plugin/skills/agentic-agile/SKILL.md b/plugin/skills/agentic-agile/SKILL.md index c0f7627f..4a1dac16 100644 --- a/plugin/skills/agentic-agile/SKILL.md +++ b/plugin/skills/agentic-agile/SKILL.md @@ -278,7 +278,7 @@ future sprint's Stage-2 and chain straight into execution. Connections). A story missing failure-scenarios or connections is rejected. 2. **tasks.md** per story — decompose into right-sized tasks (reviewable in one sitting, revertable as one change, demo describable in one sentence) that ONE worker - attempt can finish inside the time box (default hard 60k tokens / 15 min). + attempt can finish inside the time box (default hard 250k tokens / 30 min). 3. **validate.md** per story — the rubric, no judgement calls. 4. **plan.md** per story — tests-only; both acceptance criteria and edge/failure cases; static-invariant tests where relevant; each bullet has a real @@ -407,10 +407,15 @@ retried — see "Budget overrun" below.) ### Per-attempt time box (tokens + wall clock) Every `red-worker` / `scaffolder` / `green-worker` attempt runs under two budgets, each -with a soft and a hard limit. Defaults are deliberately tight — **40k / 60k tokens, -10 / 15 min** — and the project's confirmed values live in `docs/agents/defaults.md`; a single task -may carry a planner-authored `budget:` override line in tasks.md. Tokens = the worker's -current context + all its output tokens; time = wall clock since its first tool call. +with a soft and a hard limit. Defaults — **150k / 250k tokens, +20 / 30 min** (a real RED/GREEN attempt that reads the style guide and runs the +fmt/vet/lint/build/test matrix uses 60–190k) — and the project's confirmed values live in `docs/agents/defaults.md`; a single task +may carry a planner-authored `budget:` override line in tasks.md (or `BUDGET_*` lines in +its worktree's `task.env`). Tokens = the worker's current context + all its output +tokens; time = wall clock since its first tool call. The hook finds the worker's +worktree from the paths its tool calls name (`git -C `, `cd `, absolute paths), +not only from the call's cwd; `agentic budget status` shows, per attempt, where its +budget came from and how its worktree was found. The hooks enforce it — you don't: `budget hook` (PreToolUse/PostToolUse on every tool call, SubagentStop) measures the worker from its own transcript and diff --git a/plugin/skills/init/SKILL.md b/plugin/skills/init/SKILL.md index ebf25167..a4bb37aa 100644 --- a/plugin/skills/init/SKILL.md +++ b/plugin/skills/init/SKILL.md @@ -29,8 +29,8 @@ It prints a table of the proposed settings (the current ones if ask — one question per topic, the default first (Claude Code: `AskUserQuestion`; OpenCode: the `question` tool; Codex: ask in chat and wait): -1. **Limits** — per worker attempt: tokens soft/hard (default 40k / 60k), minutes - soft/hard (10 / 15), re-plan cap (2). Keep the defaults, or which values? +1. **Limits** — per worker attempt: tokens soft/hard (default 150k / 250k), minutes + soft/hard (20 / 30), re-plan cap (2). Keep the defaults, or which values? 2. **Models** — planning agents `claude-opus-5-5`, workers `sonnet` (the orchestrator runs on `sonnet`). Keep, or which? 3. **`.gitignore`** — may I add `.agentic/` and `.transcripts/` (run data: transcripts, diff --git a/plugin/tools/ctx-symbols/Cargo.lock b/plugin/tools/ctx-symbols/Cargo.lock index 94029260..56341c66 100644 --- a/plugin/tools/ctx-symbols/Cargo.lock +++ b/plugin/tools/ctx-symbols/Cargo.lock @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "ctx-symbols" -version = "0.10.0" +version = "0.10.1" dependencies = [ "anyhow", "sha2", diff --git a/plugin/tools/ctx-symbols/Cargo.toml b/plugin/tools/ctx-symbols/Cargo.toml index 22a520b1..c5c9a9b4 100644 --- a/plugin/tools/ctx-symbols/Cargo.toml +++ b/plugin/tools/ctx-symbols/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ctx-symbols" -version = "0.10.0" +version = "0.10.1" edition = "2021" description = "Minimal AST symbol resolver for agentic-agile gates (count/locate/search/conflicts). Harvested from ctxconfig's code-intelligence layer." license = "MIT" diff --git a/scripts/test/budget-worktree.test.py b/scripts/test/budget-worktree.test.py new file mode 100644 index 00000000..ab8ae787 --- /dev/null +++ b/scripts/test/budget-worktree.test.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Regression: the time box must find a worker's worktree (and its task.env budget) even +when every tool call reports the MAIN repo as cwd — workers that use `git -C ` or +absolute paths instead of `cd`. Before the fix the hook never saw the override and killed +real TDD attempts at the tiny default. python3 scripts/test/budget-worktree.test.py +""" +import json +import os +import subprocess +import tempfile + +ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "plugin")) +BIN = os.path.join(ROOT, "bin") +T = tempfile.mkdtemp(prefix="agentic-budget-") +ENV = dict(os.environ, HOME=os.path.join(T, "home")) +ENV.pop("AGENTIC_HOST", None) +PASS = [0] + + +def ok(name): + PASS[0] += 1 + print("ok -", name) + + +def sh(*args, cwd=T, inp=None): + return subprocess.run(args, cwd=cwd, env=ENV, capture_output=True, text=True, input=inp, check=True).stdout.strip() + + +def state(agent): + return json.load(open(os.path.join(T, ".agentic", "budget", agent + ".json"))) + + +def call(agent, tool, tool_input, mode="post", tokens=None, role="green-worker"): + tp = os.path.join(T, "cc", "sess.jsonl") + sub = os.path.join(T, "cc", "sess", "subagents", "agent-%s.jsonl" % agent) + os.makedirs(os.path.dirname(sub), exist_ok=True) + if tokens is not None: + with open(sub, "a") as f: + f.write(json.dumps({"timestamp": "2026-09-23T10:00:00Z", "message": {"id": "m%d" % tokens, "model": "claude-sonnet-5", + "usage": {"input_tokens": tokens, "output_tokens": 0}}}) + "\n") + payload = {"hook_event_name": "PostToolUse" if mode == "post" else "PreToolUse", "session_id": "sess", + "transcript_path": tp, "cwd": T, "agent_id": agent, "agent_type": "agentic-agile:" + role, + "tool_name": tool, "tool_input": tool_input, "tool_response": "ok"} + return sh(os.path.join(BIN, "budget"), "hook", mode, inp=json.dumps(payload)) + + +sh("git", "init", "-q"); sh("git", "config", "user.email", "a@a"); sh("git", "config", "user.name", "A") +sh("git", "commit", "-q", "--allow-empty", "-m", "init") +os.makedirs(os.path.join(T, "docs", "agents", "sprint1", "s1-01-x")) +open(os.path.join(T, "docs", "STYLE.md"), "w").write("style\n") +wt = sh(os.path.join(BIN, "task-worktree"), "add", "S1-01-T1") +open(os.path.join(wt, ".agentic", "task.env"), "w").write( + "TASK_ID=S1-01-T1\nATTEMPT=1\nAGENT_ROLE=green-worker\nSTORY_DIR=%s\nBUDGET_TOKENS_SOFT=300000\nBUDGET_TOKENS_HARD=400000\n" + % os.path.join(T, "docs", "agents", "sprint1", "s1-01-x")) + +# defaults are no longer the 40k/60k that killed real attempts +b = sh(os.path.join(BIN, "budget"), "resolve") +assert "BUDGET_TOKENS_SOFT=150000" in b and "BUDGET_TOKENS_HARD=250000" in b and "BUDGET_TIME_HARD_MIN=30" in b +ok("built-in defaults are 150k/250k tokens, 20/30 min") + +# 1) cwd = main repo, the worker addresses its worktree with `git -C`: override found +call("a1", "Bash", {"command": "git -C %s status" % wt}, tokens=5000) +s = state("a1") +assert s["worktree"] == wt and s["budget"]["TOKENS_HARD"] == 400000 and s["budget_source"] == "task.env BUDGET_*", s +ok("git -C from the main repo: task.env override applied") + +# 2) absolute file path +call("a2", "Edit", {"file_path": os.path.join(wt, "pkg", "x.go"), "old_string": "a", "new_string": "b"}, tokens=5000) +assert state("a2")["budget"]["TOKENS_HARD"] == 400000; ok("absolute file path into the worktree: override applied") + +# (a1/a2 still hold that worktree; finish them so it is unclaimed again) +for a in ("a1", "a2"): + call(a, "Bash", {"command": "true"}, mode="stop") + +# 3) first call reads a MAIN-tree file (style guide) -> the only unclaimed green worktree is used +call("a3", "Read", {"file_path": os.path.join(T, "docs", "STYLE.md")}, tokens=5000) +s3 = state("a3") +assert s3["worktree"] == wt and s3["budget"]["TOKENS_HARD"] == 400000, s3; ok("first call only reads main-tree files: the single matching worktree is used") + +# 4) worktree ambiguous at first (two green worktrees), found on a later call: budget re-resolved, clock kept, +# and a hard verdict reached under the default budget is withdrawn +wt2 = sh(os.path.join(BIN, "task-worktree"), "add", "S1-01-T2") +open(os.path.join(wt2, ".agentic", "task.env"), "w").write("TASK_ID=S1-01-T2\nATTEMPT=1\nAGENT_ROLE=green-worker\nBUDGET_TOKENS_HARD=500000\n") +for a in ("a1", "a2", "a3"): + os.remove(os.path.join(T, ".agentic", "budget", a + ".json")) + os.remove(os.path.join(T, ".agentic", "state", "agents", a + ".json")) +out = call("a4", "Read", {"file_path": os.path.join(T, "docs", "STYLE.md")}, tokens=260000) +s4 = state("a4") +assert s4["budget"]["TOKENS_HARD"] == 250000 and s4["hard"] and not s4["task_env_found"], s4 +start = s4["start"] +out = call("a4", "Bash", {"command": "go test ./... -C %s" % wt2}, tokens=260001) +s4 = state("a4") +assert s4["worktree"] == wt2 and s4["budget"]["TOKENS_HARD"] == 500000 and not s4["hard"] and s4["start"] == start, s4 +assert "HARD BUDGET" not in out +ok("worktree found late: budget re-resolved, clock kept, premature hard verdict withdrawn") + +# 5) budget status explains where the budget came from +st = sh(os.path.join(BIN, "budget"), "status") +assert "task.env BUDGET_*" in st and "path in tool call" in st; ok("budget status shows the budget source and how the worktree was found") + +# 6) docs/agents/defaults.md still applies from the first call (the user's working fix) +sh(os.path.join(BIN, "agentic-init"), "--apply", "TOKENS_SOFT=180000", "TOKENS_HARD=260000") +b = sh(os.path.join(BIN, "budget"), "resolve") +assert "BUDGET_TOKENS_HARD=260000" in b and "defaults.md" in b; ok("defaults.md applies project-wide") + +print("\n%d checks passed" % PASS[0])