fix(goal): the re-paste pointer applies only to a near-whole re-paste, and on every surface

Independent review: substring matching lost the selected objective (after a
message offering API or UI work, '/goal ship the API' and '/goal ship the UI'
kicked identically), and the gateway and TUI /goal paths still re-sent the
full goal. The rule now lives once in hermes_cli.goals.goal_kick_prompt:
the pointer replaces the goal only when the goal is >= 400 chars, contained
in the last user message, and >= 80% of it. The CLI reads the last user
message from its history; the gateway and TUI read it from the SessionDB
(fail-safe: goal sent verbatim).

Tests: a fragment that selects one option is kicked verbatim; a long goal
that is a minority of a longer message is kicked verbatim; all three
surfaces call the shared function.
This commit is contained in:
Teknium
2026-09-05 06:36:52 -07:00
parent 7e2dbcfb33
commit d3fdcef132
5 changed files with 93 additions and 26 deletions
+32 -4
View File
@@ -6,6 +6,7 @@ a user message; the kickoff re-sent it and the agent spent 11 API calls / 6 min
import queue
from hermes_cli.cli_commands_mixin import CLICommandsMixin
from hermes_cli.goals import GOAL_ALREADY_SEEN_KICK
def _cli(history):
@@ -15,16 +16,16 @@ def _cli(history):
return cli
HANDOFF = "HANDOFF: resume round 3 integration.\n - merge r3-16 first\n - then run the full suite"
HANDOFF = "HANDOFF: resume round 3 integration.\n" + "\n".join(f" - step {i}: merge r3-{i} and run its targeted suite, then the full suite" for i in range(8))
def test_goal_that_the_user_just_pasted_kicks_with_a_pointer_not_the_text():
cli = _cli([{"role": "user", "content": "Here is the plan.\n\n" + HANDOFF + "\n\nGo."},
cli = _cli([{"role": "user", "content": HANDOFF + "\n\nGo."},
{"role": "assistant", "content": "ok"}])
assert cli._goal_kick_prompt(HANDOFF) == CLICommandsMixin._GOAL_ALREADY_SEEN_KICK
assert cli._goal_kick_prompt(HANDOFF) == GOAL_ALREADY_SEEN_KICK
# block-style content is handled too
cli = _cli([{"role": "user", "content": [{"type": "text", "text": HANDOFF}]}])
assert cli._goal_kick_prompt(HANDOFF) == CLICommandsMixin._GOAL_ALREADY_SEEN_KICK
assert cli._goal_kick_prompt(HANDOFF) == GOAL_ALREADY_SEEN_KICK
def test_a_new_goal_or_a_goal_from_an_older_turn_is_kicked_verbatim():
@@ -35,3 +36,30 @@ def test_a_new_goal_or_a_goal_from_an_older_turn_is_kicked_verbatim():
cli = _cli([{"role": "user", "content": HANDOFF}, {"role": "assistant", "content": "done"},
{"role": "user", "content": "now something else"}])
assert cli._goal_kick_prompt(HANDOFF) == HANDOFF
def test_a_short_goal_that_selects_one_option_from_the_last_message_is_kicked_verbatim():
"""Independent-review witness: after a message offering API or UI work, `/goal ship the API` and
`/goal ship the UI` produced identical kickoffs. A goal that is a fragment of the last message
carries the selection; only a near-whole re-paste is replaced by the pointer."""
offer = "I can either ship the API or ship the UI next; which do you want? " * 8
cli = _cli([{"role": "user", "content": offer}])
assert cli._goal_kick_prompt("ship the API") == "ship the API"
assert cli._goal_kick_prompt("ship the UI") == "ship the UI"
# a long goal that is only a minority of a much longer message is also kept verbatim
long_goal = "x" * 500
cli = _cli([{"role": "user", "content": long_goal + " " + "y" * 2000}])
assert cli._goal_kick_prompt(long_goal) == long_goal
def test_gateway_and_tui_surfaces_use_the_same_rule(tmp_path, monkeypatch):
"""Independent review: other surfaces still duplicated the full goal. One shared function now."""
from hermes_cli import goals
long_goal = "HANDOFF " + "step; " * 120
assert goals.goal_kick_prompt(long_goal, long_goal) == goals.GOAL_ALREADY_SEEN_KICK
assert goals.goal_kick_prompt("ship the API", "ship the API or ship the UI? " * 8) == "ship the API"
# DB-backed lookup fails safe to "" (goal kicked verbatim) when no session/db
assert goals.last_user_message_from_db(None) == ""
import gateway.slash_commands_goals as g, tui_gateway.methods_tools as m # noqa: E401
import inspect
assert "goal_kick_prompt" in inspect.getsource(g) and "goal_kick_prompt" in inspect.getsource(m)