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
+23 -5
View File
@@ -755,17 +755,28 @@ async def shape_check():
Query:
written (str) — newline-separated `path<TAB>kind<TAB>name` lines,
repo-relative, kind css|sym|file.
earlier (opt) — the same lines for shapes this session wrote in an
earlier turn, was asked about and walked past. The
hook carries them for a bounded number of asks;
the note names them apart from this turn's.
phase (str) — check | after. Anything else is a 400.
repo (opt) — working repo remote, resolved like the other arms.
project_id (opt) — explicit scope override.
The after phase also answers `left`: the asked lines still unjudged, as
ledger lines, which the hook carries into its next ask.
"""
phase = (request.args.get("phase") or "check").strip()
if phase not in shape_check_svc.PHASES:
return jsonify({"error": f"phase must be one of {list(shape_check_svc.PHASES)}"}), 400
written = shape_check_svc.parse_written(request.args.get("written") or "")
earlier = [
line for line in shape_check_svc.parse_written(request.args.get("earlier") or "")
if line not in written
]
project_id, repo, _unbound = await _project_scope()
body: dict = {"status": "ok", "unjudged": []}
if not project_id or not written:
if not project_id or not (written or earlier):
return jsonify(body)
from grimoire.services import access
from grimoire.services import coverage as coverage_svc
@@ -774,7 +785,9 @@ async def shape_check():
if not await access.can_read_project(g.user.id, project_id):
return jsonify(body)
repo_key = repo_bindings_svc.normalize_repo_key(repo) if repo else ""
unjudged = await shape_ledger_svc.unjudged_shapes(project_id, written, repo_key=repo_key)
unjudged = await shape_ledger_svc.unjudged_shapes(
project_id, written + earlier, repo_key=repo_key,
)
# A snippet recorded AT a shape is the strongest verdict there is — the
# next refresh stamps that row canonical. Until then the ledger cannot
# know, so the recorded locations answer for it: an agent who just
@@ -786,17 +799,22 @@ async def shape_check():
}
unjudged = [u for u in unjudged if (u["path"], u["symbol"]) not in recorded
and not (u["kind"] == "file" and (u["path"], "") in recorded)]
carried = set(earlier)
fresh = [u for u in unjudged if (u["path"], u["kind"], u["symbol"]) not in carried]
repeat = [u for u in unjudged if (u["path"], u["kind"], u["symbol"]) in carried]
outcome = shape_check_svc.outcome_for(phase, unjudged)
await shape_check_svc.record_shape_check(
g.user.id, outcome, written=len(written), unjudged=len(unjudged),
project_id=project_id,
g.user.id, outcome, written=len(written) + len(earlier), unjudged=len(unjudged),
project_id=project_id, earlier=len(repeat),
)
body["outcome"] = outcome
body["unjudged"] = unjudged
if outcome == "noted":
body["note"] = shape_check_svc.note_text(
unjudged, project_id=project_id, repo=repo_key or repo,
fresh, project_id=project_id, repo=repo_key or repo, earlier=repeat,
)
if phase == "after":
body["left"] = shape_check_svc.ledger_lines(unjudged)
return jsonify(body)