fix(8139): a shape the agent walked past at the end-of-turn check is named again in its next notes

The after phase answers `left`, the asked lines still unjudged; the Stop hook
carries them as `earlier=` into the next checks, each up to two more asks, and
the note names them apart from the last turn's writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 09:41:09 -05:00
co-authored by Claude Opus 5.5
parent 69f3adae2c
commit 55f53de92d
7 changed files with 260 additions and 40 deletions
+58 -15
View File
@@ -68,31 +68,62 @@ def _evidence_note(evidence: dict) -> str:
return f" ({'; '.join(parts)})" if parts else ""
def note_text(unjudged: list[dict], *, project_id: int, repo: str) -> str:
"""What the agent reads at the start of the turn after one that wrote
unjudged shapes.
Phrased as a practice: what to decide and the one
call that records it, not a prohibition. The reusing-code skill owns the
longer version of what each verdict means.
"""
def _shape_lines(items: list[dict], *, project_id: int) -> list[str]:
lines = []
for item in unjudged[:_LISTED]:
for item in items[:_LISTED]:
new = " — new" if item.get("status") == "new" else ""
lines.append(
f"- {item['path']} · {item['symbol']} ({item['kind']}){new}"
f"{_evidence_note(item.get('evidence') or {})}"
)
more = len(unjudged) - _LISTED
more = len(items) - _LISTED
if more > 0:
lines.append(f"- … and {more} more (list_shapes(project_id={project_id}, path=…) shows them)")
return lines
def _count(n: int) -> str:
return f"{n} definition{'s' if n != 1 else ''}"
def note_text(unjudged: list[dict], *, project_id: int, repo: str,
earlier: list[dict] | None = None) -> str:
"""What the agent reads at the start of the turn after one that wrote
unjudged shapes.
``earlier`` is what this session wrote in an earlier turn, was asked
about, and walked past. The per-turn ledger forgets a line once its note
has been answered, and nothing else names a shape by name — the coverage
line carries only a count — so the hook carries walked-past lines into
a bounded number of later asks. The note says plainly that they are a
repeat, and why.
Phrased as a practice: what to decide and the one
call that records it, not a prohibition. The reusing-code skill owns the
longer version of what each verdict means.
"""
earlier = earlier or []
parts = []
if unjudged:
parts.append(
f"Your last turn wrote {_count(len(unjudged))} that nobody has judged yet. "
"You built them, so you know what each one is — record it alongside this "
"turn's work, while that is still true, so the next session starts from your "
"answer instead of rebuilding it:\n"
+ "\n".join(_shape_lines(unjudged, project_id=project_id))
)
if earlier:
verb = "is" if len(earlier) == 1 else "are"
parts.append(
f"{'Also: ' if unjudged else ''}{_count(len(earlier))} you wrote earlier in this "
f"session {verb} still unjudged. You were asked and moved on; nothing else will "
"name them again, so they are asked once more while you still know what they "
"are:\n"
+ "\n".join(_shape_lines(earlier, project_id=project_id))
)
repo_arg = f', repo="{repo}"' if repo else ""
return (
f"Your last turn wrote {len(unjudged)} definition{'s' if len(unjudged) != 1 else ''} "
"that nobody has judged yet. You built them, so you know what each one is — "
"record it alongside this turn's work, while that is still true, so the next "
"session starts from your answer instead of rebuilding it:\n"
+ "\n".join(lines)
"\n\n".join(parts)
+ "\n\nFor each: something another part of the code should reuse → record it "
"with create_snippet (name, code, when to reach for it, location); built from a "
"recorded snippet → `instance` of it; a deliberate departure from one → "
@@ -105,6 +136,13 @@ def note_text(unjudged: list[dict], *, project_id: int, repo: str) -> str:
)
def ledger_lines(items: list[dict]) -> str:
"""``items`` back as the hook's own `path<TAB>kind<TAB>name` lines — what
the after phase hands the hook so it can carry the walked-past shapes
forward without parsing a JSON list in shell."""
return "\n".join(f"{i['path']}\t{i['kind']}\t{i['symbol']}" for i in items)
async def record_shape_check(
user_id: int | None,
outcome: str,
@@ -112,12 +150,17 @@ async def record_shape_check(
written: int,
unjudged: int,
project_id: int | None = None,
earlier: int = 0,
) -> None:
if outcome not in OUTCOMES:
raise ValueError(f"unknown shape-check outcome {outcome!r}")
details: dict = {"outcome": outcome, "written": written, "unjudged": unjudged}
if project_id:
details["project_id"] = project_id
# How many of `unjudged` were carried from an earlier turn's walked-past
# ask — so a window can tell a fresh ask from a repeat.
if earlier:
details["earlier"] = earlier
async with async_session() as session:
session.add(AppLog(
category="plugin",