feat(7729): one assembler per hook — rule statements first, then the reply shape, then records, under a budget
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m47s
CI & Build / integration (push) Failing after 2m0s
CI & Build / Build & push image (push) Skipped
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Python tests (push) Failing after 1m47s
CI & Build / integration (push) Failing after 2m0s
CI & Build / Build & push image (push) Skipped
A rule line on first mention now carries the rule's own statement, written as
a statement about the rule ("Rule 11 … may apply here; it binds: …") rather
than an instruction to go read it; a repeat or lower-ranked line is a
reference ("Also relevant: Rule 11 …"). Every line ends with where the session
stands with the rule and get_rule(id) for the full text.
services/hook_payload.py fits every injecting door's payload (prompt,
pre-tool rules, moment, write path) to the user's budget: parts in one order,
kept while they fit, dropped whole otherwise. A dropped part's ids leave the
response lists, so the plugin ledgers mark only what was shown, and rule
deliveries are buffered per request and written only for kept lines.
Budget: Settings, default 4,500 characters (the full core reply shape is
2,343 and a full rule line up to ~750, so 3,000 would have crowded the shape
out of most turns), clamped to 1,000-7,500 — under the lower of the two
recorded hook caps (10,000 in the docs, 8,000 read from an installed build).
check_plugin asserts the ceiling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1149,14 +1149,14 @@ _HELD = fake_rule(
|
||||
statement="Every wait on something that can fail to answer carries a deadline.",
|
||||
when_to_apply="writing any call that crosses a process boundary",
|
||||
)
|
||||
_FRESH_TAIL = "not in this session's loaded set"
|
||||
_FRESH_TAIL = "First mention this session"
|
||||
# `seen` WITHOUT `held` is the middle state: an arm named this rule earlier,
|
||||
# and the session never opened it. Every test below drives the arms with
|
||||
# `exclude_rule_ids` alone — the naming ledger — so this is the tail they
|
||||
# produce, and it must not claim the session read a teaser nobody opened.
|
||||
_SEEN_TAIL = "Mentioned earlier this session but not opened"
|
||||
_SEEN_TAIL = "Named earlier this session, not opened"
|
||||
# The third state, reached only when the opened ledger names the rule too.
|
||||
_HELD_TAIL = "You opened it earlier this session"
|
||||
_HELD_TAIL = "Opened earlier this session"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("source", "run"), _ARMS, ids=["write_path", "pre_tool", "prompt"])
|
||||
@@ -1235,8 +1235,8 @@ _PREF = fake_rule(
|
||||
statement="Advance one investigative step per turn.",
|
||||
when_to_apply="during hard debugging",
|
||||
)
|
||||
_RULE_FORCE = "before deciding it does not apply"
|
||||
_PREF_FORCE = "for how this has been done before"
|
||||
_RULE_FORCE = "it binds"
|
||||
_PREF_FORCE = "how this has been done before"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("source", "run"), _ARMS, ids=["write_path", "pre_tool", "prompt"])
|
||||
@@ -1251,7 +1251,7 @@ async def test_a_preference_does_not_speak_in_the_rules_voice(source, run):
|
||||
"""
|
||||
ctx = (await run([(0.81, _PREF)], MagicMock()))["context"]
|
||||
|
||||
assert "Preference that may apply" in ctx, (
|
||||
assert "Preference 177" in ctx, (
|
||||
f"{source} announced a preference as something else. The noun is the "
|
||||
f"one word a skimming reader gets to place the register, so it is the "
|
||||
f"word that has to move. Context was: {ctx!r}"
|
||||
@@ -1297,7 +1297,7 @@ async def test_kind_and_seen_do_not_read_each_other(source, run):
|
||||
)
|
||||
# And the head still differs in the seen case — a repeat of a preference
|
||||
# is still a preference.
|
||||
assert "Preference that may apply" in pref_seen, (
|
||||
assert "Preference 177" in pref_seen, (
|
||||
f"{source} lost the preference register on a repeat, so a preference "
|
||||
f"seen twice reads as a rule the second time"
|
||||
)
|
||||
@@ -1305,25 +1305,24 @@ async def test_kind_and_seen_do_not_read_each_other(source, run):
|
||||
|
||||
@pytest.mark.parametrize(("source", "run"), _ARMS, ids=["write_path", "pre_tool", "prompt"])
|
||||
@pytest.mark.asyncio
|
||||
async def test_neither_tail_injects_the_rule_statement(source, run):
|
||||
"""The budget, pinned on both branches.
|
||||
async def test_a_first_mention_carries_the_statement_and_a_repeat_does_not(source, run):
|
||||
"""What a line is for, pinned on both branches.
|
||||
|
||||
A reference costs the same ~40 tokens as a first surfacing precisely
|
||||
because neither carries the statement. If a repeat ever starts inlining the
|
||||
body "since we are re-showing it anyway", this arm stops being cheap enough
|
||||
to always emit — and always emitting is the whole mechanism.
|
||||
A first mention carries the rule's own words, so the reader has what it
|
||||
says without a second call. A repeat is a reference: the session was
|
||||
handed the statement already, and quoting it again on every call is the
|
||||
cost this line is built to avoid.
|
||||
"""
|
||||
for excluded in ([], [156]):
|
||||
ctx = (await run([(0.81, _HELD)], MagicMock(),
|
||||
exclude_rule_ids=excluded))["context"]
|
||||
assert _HELD.statement not in ctx, (
|
||||
f"{source} inlined the rule statement (excluded={excluded!r}); the "
|
||||
f"line carries title, trigger and a pull pointer and nothing more"
|
||||
)
|
||||
assert _HELD.title in ctx and "process boundary" in ctx, (
|
||||
"the line dropped the title or the trigger — those are what let a "
|
||||
"reader decide whether to pull without pulling"
|
||||
)
|
||||
fresh = (await run([(0.81, _HELD)], MagicMock()))["context"]
|
||||
assert _HELD.statement in fresh, (
|
||||
f"{source} named the rule without saying what it says"
|
||||
)
|
||||
repeat = (await run([(0.81, _HELD)], MagicMock(), exclude_rule_ids=[156]))["context"]
|
||||
assert _HELD.statement not in repeat, (
|
||||
f"{source} quoted the statement again on a repeat"
|
||||
)
|
||||
for ctx in (fresh, repeat):
|
||||
assert _HELD.title in ctx and "get_rule(156)" in ctx
|
||||
|
||||
|
||||
# ── What a reference IS in the telemetry: nothing new ──────────────────────
|
||||
@@ -1449,7 +1448,7 @@ async def test_a_preference_that_lost_the_ranking_still_gets_a_line():
|
||||
"dropped — which is the outcome with no symptom: the rules that won "
|
||||
"are legitimate hits and nothing in the telemetry looks wrong"
|
||||
)
|
||||
assert "Preference that may apply" in out["context"]
|
||||
assert "Preference 140" in out["context"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1466,7 +1465,7 @@ async def test_the_slot_is_not_spent_when_a_preference_already_placed():
|
||||
"reserved line for a kind already represented is noise the general "
|
||||
"ranking had already decided against"
|
||||
)
|
||||
assert out["context"].count("Preference that may apply") == 1
|
||||
assert out["context"].count("Preference 140") == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user