fix first command history gate

This commit is contained in:
Violin
2026-07-12 09:57:02 +01:00
parent 283f2683a9
commit 5030b32d3f
3 changed files with 50 additions and 2 deletions
+4 -1
View File
@@ -192,7 +192,10 @@ def _check_command_core(args: argparse.Namespace) -> CheckResult:
skill_result = check_skill_load_gate(skill_loaded_file, mandatory=False)
merge_result(result, skill_result, prefix="skill guard")
ptt_result = _ptt_staleness_guard(eng_dir_path / "state" / "ptt.md")
ptt_result = _ptt_staleness_guard(
eng_dir_path / "state" / "ptt.md",
eng_dir_path / "state" / "history.md",
)
merge_result(result, ptt_result, prefix="ptt guard")
# Freshness guard: PTT "Last updated" + phase desync
+14 -1
View File
@@ -380,7 +380,7 @@ def record_history(args: argparse.Namespace) -> int:
return 0
def _ptt_staleness_guard(ptt_path: Path) -> CheckResult:
def _ptt_staleness_guard(ptt_path: Path, history_path: Path | None = None) -> CheckResult:
result = CheckResult()
if not ptt_path.exists() or not ptt_path.is_file():
result.add_error(f"PTT missing: {ptt_path}")
@@ -389,6 +389,19 @@ def _ptt_staleness_guard(ptt_path: Path) -> CheckResult:
)
return result
if _ptt_is_stale(ptt_path):
# On a fresh engagement, the first command necessarily runs before the
# executor can append its history record. Requiring a PTT transition at
# this point creates a bootstrap deadlock: the task must look started
# before any work has actually happened. Keep the exception narrow: as
# soon as history contains a recorded command, normal PTT enforcement
# resumes.
if history_path is not None and history_path.is_file():
history = history_path.read_text(encoding="utf-8")
if not re.findall(r"`([^`]+)`", history):
result.add_info(
"PTT is pristine; the first command may run before task progress is recorded"
)
return result
result.add_error("PTT is stale: no PT-XXX row has moved past [ ]; update before advancing")
result.add_info(
'run: python scripts/violin_guard.py record-ptt --eng-dir "$ENG_DIR" --id <PT-XXX> --status [~] --note "<batch result>"'
+32
View File
@@ -207,6 +207,38 @@ def test_fresh_history_allows_first_command(tmp_path):
assert any("recorded after it runs" in info for info in result.infos)
def test_first_command_does_not_require_preemptive_ptt_progress(tmp_path):
"""A pristine PTT is valid until the executor records the first command."""
skill_file = tmp_path / ".skill-loaded-ts"
eng = _init_e2e(tmp_path, skill_file)
ptt = eng / "state" / "ptt.md"
ptt.write_text(
ptt.read_text(encoding="utf-8").replace("| PT-001 | [~] |", "| PT-001 | [ ] |"),
encoding="utf-8",
)
args = SimpleNamespace(
command="nmap -sV 10.10.10.10",
phase="recon",
eng_dir=str(eng),
scope=str(eng / "scope" / "scope.yaml"),
skill_loaded_file=str(skill_file),
session_id="ts",
)
first = _check_command_core(args)
assert not first.errors
assert any("first command may run" in info for info in first.infos)
(eng / "state" / "history.md").write_text(
"# Command History\n- [2026-07-12T09:00:00Z] [RECON] exit=0 `nmap -sV 10.10.10.10`\n",
encoding="utf-8",
)
second = _check_command_core(args)
assert any("PTT is stale" in error for error in second.errors)
def test_exec_blocked_without_skill_load(monkeypatch, tmp_path):
"""Skill-load gate: check-command BLOCKs when the SKILL.md marker is absent,
and handle_exec honours that BLOCK (status 'denied')."""