From d652ab20d37244519e219b567e71b9cd3f7cee88 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 19 Nov 2026 02:44:22 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20product-owner=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(1=20misread);=20DM=20throug?= =?UTF-8?q?h=20the=20checkout=20of=20a=20held-up=20issue's=20repo=20and=20?= =?UTF-8?q?show=20the=20DM=20in=20the=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/agent_cycle/direct_message.py | 7 ++++--- bin/loop_claude/test_loop_claude.py | 7 +++++-- bin/loop_effects/effects.py | 6 +++--- bin/notifier/test_notifier.py | 9 ++++++++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/bin/agent_cycle/direct_message.py b/bin/agent_cycle/direct_message.py index 86cf10cf..32d3da83 100644 --- a/bin/agent_cycle/direct_message.py +++ b/bin/agent_cycle/direct_message.py @@ -1,7 +1,8 @@ from loop_effects.effects import Effects, say -def tell(text: str, effects: Effects) -> None: - """DMs text to the human. Where the DM fails, it says why on stderr and goes on: the DM only copies what the terminal shows, so its failure never stops the loop.""" - if failed := effects.dm(text): +def tell(text: str, effects: Effects, directory: str | None = None) -> bool: + """DMs text to the human through the notifier of the project whose checkout holds directory, else the current directory, and returns whether it went out. Where the DM fails, it says why on stderr and goes on: the DM only copies what the terminal shows, so its failure never stops the loop.""" + if failed := effects.dm(text, directory): say(f"could not DM you: {failed.reason}", effects) + return not failed diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index a3268f58..acf0f94c 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -109,6 +109,8 @@ class FakeEffects: self.owner = owner # Each direct message sent. They stay out of self.calls, so a test that lists every call doesn't list them. Without a script, each is sent. self.dms = [] + # The directory each DM named, in the order of self.dms; None where it named none. + self.dm_directories = [] self.dm_failures = list(dm_failures) self.scripts = {"claude": list(claude), "claude_on_terminal": list(on_terminal_claude), "git": list(git), "input": list(inputs), "python": list(python), "stream_claude": list(streams)} # Without a script, every read finds all memory available. @@ -144,8 +146,9 @@ class FakeEffects: return subprocess.CompletedProcess(args, 1 if self.windows is None else 0, self.windows or "", "no server") return subprocess.CompletedProcess(args, 0, {"-V": self.tmux_version + "\n", "show-options": self.owner + "\n"}.get(args[0], "@9\n"), "") - def dm(self, text): + def dm(self, text, directory): self.dms.append(text) + self.dm_directories.append(directory) return self.dm_failures.pop(0) if self.dm_failures else None def memory(self): @@ -832,7 +835,7 @@ class Interrupts(unittest.TestCase): def test_drops_the_keys_typed_before_the_question_ahead_of_the_dm_so_an_answer_typed_while_it_sends_counts(self): fake = FakeEffects(inputs=["Use B."]) seen = [] - effects = dataclasses.replace(fake.effects(), dm=lambda text: seen.append(list(fake.calls))) + effects = dataclasses.replace(fake.effects(), dm=lambda text, directory: seen.append(list(fake.calls))) self.assertEqual(self.put(fake, effects=effects)[0], "Use B.") self.assertEqual(seen, [[("discard_typed", None)]]) diff --git a/bin/loop_effects/effects.py b/bin/loop_effects/effects.py index 457ef24e..ebec0392 100644 --- a/bin/loop_effects/effects.py +++ b/bin/loop_effects/effects.py @@ -36,8 +36,8 @@ class Effects: claude_on_terminal: typing.Callable[[list[str], str, dict[str, str]], int] # Drops what was typed on the terminal and not yet read. discard_typed: typing.Callable[[], None] - # Sends the human a direct message through the notifier the project's config names, as `notify` does, for the project whose checkout holds the current directory; a Failure where it could not. - dm: typing.Callable[[str], Failure | None] + # Sends the human a direct message through the notifier the project's config names, as `notify` does, for the project whose checkout holds the given directory, else the current directory; a Failure where it could not. + dm: typing.Callable[[str, str | None], Failure | None] execv: typing.Callable[[str, list[str]], None] git: git_repo.Git input: typing.Callable[[str], str] @@ -75,7 +75,7 @@ def system_effects(backends: typing.Mapping[Notifier, Backend[typing.Any]] = BAC claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, input=stdin, text=True), claude_on_terminal=claude_on_terminal, discard_typed=lambda: termios.tcflush(sys.stdin, termios.TCIFLUSH), - dm=lambda text: notify(text, None, pathlib.Path.home(), backends), + dm=lambda text, directory: notify(text, directory, pathlib.Path.home(), backends), execv=os.execv, git=git_repo.git, input=input, diff --git a/bin/notifier/test_notifier.py b/bin/notifier/test_notifier.py index 44b1bd3c..ee563e57 100644 --- a/bin/notifier/test_notifier.py +++ b/bin/notifier/test_notifier.py @@ -73,7 +73,14 @@ class Notify(Project): self.name_notifier("slack", SLACK_KEYS) slack = Slack({"ok": True}) with contextlib.chdir(self.checkout): - self.assertIsNone(system_effects(through("slack", slack)).dm("Which one?")) + self.assertIsNone(system_effects(through("slack", slack)).dm("Which one?", None)) + self.assertEqual(slack.requests, [SLACK_POST]) + + def test_a_dm_that_names_a_directory_goes_through_the_notifier_for_the_project_holding_it_from_any_current_directory(self): + self.name_notifier("slack", SLACK_KEYS) + slack = Slack({"ok": True}) + with contextlib.chdir(self.home): + self.assertIsNone(system_effects(through("slack", slack)).dm("Which one?", str(self.checkout))) self.assertEqual(slack.requests, [SLACK_POST]) def test_skips_the_notice_for_a_project_that_names_no_notifier_even_where_its_env_file_holds_the_keys(self):