From a8d0a9011cc6411a269437ae75fa1a02e88ff31a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 14 Nov 2026 23:36:30 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20product-owner=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20escape=20th?= =?UTF-8?q?e=20characters=20Slack=20reads=20as=20control=20characters,=20a?= =?UTF-8?q?nd=20say=20the=20DM=20isn't=20only=20Mattermost's?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/slack_dm/dm.py | 7 ++++--- bin/slack_dm/test_slack_dm.py | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab930e50..7dfe9172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - The technical principles ask for code in files and folders before `// --- name ---` banner comments. They also ask for an entry point a newcomer finds at once: the root holds it, the README and the files a tool reads only from there. - In a client project, the loop reads the team's own `CLAUDE.md` and `AGENTS.md` and proposes each change that aligns them with this setup in a pull request of its own. Where the team declines or doesn't answer, the loop follows the team's rule unless it breaks a project goal, and records the conflict as a decision in the `decisions` record. - The new `project-record open ` prints the file in which an agent reads and edits one of a project's five records (`decisions`, `score-anchors`, `comprehension-history`, `reading-cost` and `changelog`), and `project-record save ` stores the edit. Every tool now reads and writes a record the same one way, so that a later release can keep a record outside files. No config needs a change. -- `loop-inbox` is gone. loop-claude now asks its questions only on its own terminal. A line typed there answers a question, and `/talk` opens the worker's session. The Mattermost DM still tells you a loop waits. To upgrade, quit any `loop-inbox` still open and remove your `~/.local/bin/loop-inbox` link. Once every loop started before the upgrade has reloaded or ended, remove the folder `~/.local/state/loop-claude/`, which nothing reads any more. +- `loop-inbox` is gone. loop-claude now asks its questions only on its own terminal. A line typed there answers a question, and `/talk` opens the worker's session. The DM still tells you a loop waits. To upgrade, quit any `loop-inbox` still open and remove your `~/.local/bin/loop-inbox` link. Once every loop started before the upgrade has reloaded or ended, remove the folder `~/.local/state/loop-claude/`, which nothing reads any more. - rule-hook refuses a Read or a Grep of `~/.claude/.env` or of the `env-file` any project's config names, and a Bash command that names either or searches a folder holding either with `ag`, `grep -r` or `rg`, unless the tool skips the file as hidden or ignored, so that a worker doesn't put a credential in its transcript in passing. A command that hides the path, such as behind a glob or a variable, still goes through. - A project's config names the service for loop-claude's DMs: `notifier = "mattermost"` or `"slack"`, with the bot's token and the recipient in the `env-file`. Slack's keys are `SLACK_TOKEN` and `SLACK_RECIPIENT`, a bot token with the `chat:write` scope and a member ID. To upgrade, move the Mattermost keys from `~/.claude/.env` into a file outside the checkout and the config's folder, such as `~/.claude-projects/.env`, name it as `env-file` and add `notifier = "mattermost"`. A project with no `notifier` gets no DM, and `~/.claude/.env` is no longer read. A failure names each missing key and holds no token. - `mattermost-dm` is now `notify`, which sends through the project's `notifier`; `notify --help` names the keys. diff --git a/bin/slack_dm/dm.py b/bin/slack_dm/dm.py index b6c7a05f..201c5fd7 100644 --- a/bin/slack_dm/dm.py +++ b/bin/slack_dm/dm.py @@ -1,5 +1,6 @@ -"""Sends a direct message from a Slack app's bot to one user, through Slack's Web API. `notifier` picks it where a project's config names `slack`.""" +"""Sends a direct message from a Slack app's bot to one user, through Slack's Web API. The `notifier` setting `slack` picks it.""" import dataclasses +import html import pathlib from failure import Failure @@ -29,8 +30,8 @@ def read_config(path: pathlib.Path) -> Config | Failure: def send(config: Config, message: str, http: Http) -> Failure | None: - """Posts message to the recipient's member ID, which Slack opens as a DM from the app's bot; the bot needs the `chat:write` scope.""" - answer = http("POST", f"{API}/chat.postMessage", config.token, {"channel": config.recipient, "text": message}) + """Posts message to the recipient's member ID, which Slack opens as a DM from the app's bot; the bot needs the `chat:write` scope. Slack reads `&`, `<` and `>` as control characters, so they are escaped as its docs ask.""" + answer = http("POST", f"{API}/chat.postMessage", config.token, {"channel": config.recipient, "text": html.escape(message, quote=False)}) if isinstance(answer, Failure): return answer if isinstance(answer, dict) and answer.get("ok") is True: diff --git a/bin/slack_dm/test_slack_dm.py b/bin/slack_dm/test_slack_dm.py index 8d941b1e..f6c07b60 100644 --- a/bin/slack_dm/test_slack_dm.py +++ b/bin/slack_dm/test_slack_dm.py @@ -51,6 +51,11 @@ class Send(unittest.TestCase): self.assertIsNone(dm.send(CONFIG, "Which one?", slack)) self.assertEqual(slack.requests, [("POST", "https://slack.com/api/chat.postMessage", "xoxb-secret", {"channel": "U0123ABCD", "text": "Which one?"})]) + def test_escapes_the_three_characters_slack_reads_as_control_characters(self): + slack = Slack({"ok": True}) + self.assertIsNone(dm.send(CONFIG, "Use & []?", slack)) + self.assertEqual(slack.requests[0][3], {"channel": "U0123ABCD", "text": "Use <b> & [<setting>]?"}) + def test_fails_naming_slacks_error_code_where_slack_answers_ok_false(self): self.assertEqual(dm.send(CONFIG, "hi", Slack({"ok": False, "error": "invalid_auth"})), Failure("POST /api/chat.postMessage refused the message: invalid_auth"))