From 6520628fefb54c196c9f589668066a9b65d0516a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 13 Nov 2026 20:38:53 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20product-owner=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20print=20env?= =?UTF-8?q?-file=20from=20project-config,=20say=20mattermost-dm=20runs=20i?= =?UTF-8?q?nside=20a=20checkout,=20and=20lead=20the=20changelog=20with=20t?= =?UTF-8?q?he=20upgrade=20step?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/mattermost_dm/dm.py | 7 ++++--- bin/mattermost_dm/main.py | 15 ++++++++------- bin/mattermost_dm/test_mattermost_dm.py | 4 ++-- bin/project_config/main.py | 18 ++++++++++++------ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3502dcf5..6eae700b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- A project's config can name an `env-file`, outside the checkout and the config's folder, that holds its credentials; `mattermost-dm` and loop-claude's DMs read that file instead of `~/.claude/.env`, and a project that sets none gets no DMs. Failures name each missing key and never hold a value. +- To keep Mattermost DMs, move the keys from `~/.claude/.env` into a file outside the checkout and the config's folder, such as `~/.claude-projects/.env`, and name it in the project's config as `env-file`; `mattermost-dm` and loop-claude's DMs no longer read `~/.claude/.env`, and a project with no `env-file` gets none. A failure names each missing key and holds no token. ## 0.10.0 diff --git a/bin/mattermost_dm/dm.py b/bin/mattermost_dm/dm.py index 0c25ad3d..068df948 100644 --- a/bin/mattermost_dm/dm.py +++ b/bin/mattermost_dm/dm.py @@ -124,9 +124,10 @@ def error_message(failure: urllib.error.HTTPError) -> str: def dm(text: str, directory: str | None, home: pathlib.Path, http: Http) -> Failure | None: - """Sends text as the env file that the config of the project holding directory names configures it. A project whose config names none, or has none, hasn't asked for DMs, so there the DM is skipped.""" + """Sends text to the recipient that the project's env file names. The project is the one whose checkout holds directory, and its config names the file. + + The DM is skipped where the config sets no env-file, since the project hasn't asked for DMs. It is skipped too where no config can be read: loop-claude has stopped with that reason, and without a config there is no file to read the recipient from.""" project = located(directory, home) - # A config that cannot be read has already stopped loop-claude with its own reason, so it needs no second notice here. if isinstance(project, Failure) or project.env_file is None: return None config = read_config(project.env_file) @@ -139,5 +140,5 @@ def config_of(directory: str | None, home: pathlib.Path) -> Config | Failure: if isinstance(project, Failure): return project if project.env_file is None: - return Failure(f"{project.folder / 'config.toml'} sets no `env-file`; it needs the file that holds {', '.join(KEYS[:-1])} and {KEYS[-1]}") + return Failure(f"{project.folder / 'config.toml'} sets no `env-file`; set it to the file that holds {', '.join(KEYS[:-1])} and {KEYS[-1]}") return read_config(project.env_file) diff --git a/bin/mattermost_dm/main.py b/bin/mattermost_dm/main.py index f2970fa6..fb0a2aa0 100644 --- a/bin/mattermost_dm/main.py +++ b/bin/mattermost_dm/main.py @@ -2,10 +2,11 @@ usage: mattermost-dm [] -Sends , or else stdin, from the bot to the recipient that the project's env file names. The -project's config, ~/.claude-projects//config.toml, names that file in `env-file`, a path outside -the checkout and the config's folder, such as "~/.claude-projects/.env". It holds three KEY=value -lines, and only its owner may read it, since it holds the bot's token: +Sends , or else stdin, from the bot to the recipient that a project's env file names. Run it +inside the project's checkout, or a worktree of it. The project's config, +~/.claude-projects//config.toml, names the env file in `env-file`, a path outside the checkout +and the config's folder, such as "~/.claude-projects/.env". The file holds three KEY=value lines, +and only its owner may read it, since it holds the bot's token: MATTERMOST_URL=https://chat.example MATTERMOST_TOKEN= @@ -13,9 +14,9 @@ lines, and only its owner may read it, since it holds the bot's token: Exit 0 once the message is sent. Exit 1, saying why, when Mattermost cannot be reached or refuses the message. -Exit 2, saying why, on misuse: bad arguments, an empty message, a config that names no env file, or -an env file that is missing or unreadable, lacks a key, names a server off https, or that others may read. -No message, failure or log line holds the token. +Exit 2, saying why, on misuse: bad arguments, an empty message, a directory with no project config, +a config that sets no `env-file`, or an env file that is missing or unreadable, lacks a key, names a +server off https, or that others may read. None of these messages holds the token. """ import typing diff --git a/bin/mattermost_dm/test_mattermost_dm.py b/bin/mattermost_dm/test_mattermost_dm.py index afd74d4a..de13ca2c 100644 --- a/bin/mattermost_dm/test_mattermost_dm.py +++ b/bin/mattermost_dm/test_mattermost_dm.py @@ -254,13 +254,13 @@ class Dm(Project): def test_config_of_names_the_setting_to_add_where_the_config_names_no_env_file(self): failed = dm.config_of(str(self.checkout), self.home) assert isinstance(failed, Failure), failed - self.assertEqual(failed.reason, f"{self.folder / 'config.toml'} sets no `env-file`; it needs the file that holds MATTERMOST_URL, MATTERMOST_TOKEN and MATTERMOST_RECIPIENT") + self.assertEqual(failed.reason, f"{self.folder / 'config.toml'} sets no `env-file`; set it to the file that holds MATTERMOST_URL, MATTERMOST_TOKEN and MATTERMOST_RECIPIENT") def test_config_of_reads_the_env_file_the_config_names(self): self.name_env_file("MATTERMOST_URL=https://chat.example/\nMATTERMOST_TOKEN=secret-token\nMATTERMOST_RECIPIENT=lilleman\n") self.assertEqual(dm.config_of(str(self.checkout), self.home), CONFIG) - def test_no_failure_it_gives_holds_the_token_however_the_request_fails(self): + def test_the_failure_for_an_unreachable_server_names_the_server_and_not_the_token(self): self.name_env_file("MATTERMOST_URL=https://127.0.0.1:1\nMATTERMOST_TOKEN=secret-token\nMATTERMOST_RECIPIENT=lilleman\n") failed = dm.dm("Which one?", str(self.checkout), self.home, dm.http_json) assert isinstance(failed, Failure), failed diff --git a/bin/project_config/main.py b/bin/project_config/main.py index 5223bafb..f6c4c42d 100644 --- a/bin/project_config/main.py +++ b/bin/project_config/main.py @@ -23,31 +23,37 @@ starts with / or ~/. In a worktree, a "checkout:" path is the worktree's own fil `env-file` is the one optional setting: the file of KEY=value credentials the project's tools read, a path that starts with / or ~/ and lies outside the checkout and the config's folder, such as -"~/.claude-projects/acme-billing.env". Where it is left out, the project has asked for none. +"~/.claude-projects/acme-billing.env". Where it is left out, the project has no credentials file, and +a tool that needs one fails naming the setting. It is printed with the others only where it is set. Exit 1, naming each fault on stderr, where no config names the checkout, or its config leaves out a -setting, names an unknown one or misspells a path. No setting has a default. +setting, names an unknown one or misspells a path, and where `env-file` is asked for and not set. +No setting has a default. """ import pathlib import sys +from project_config.settings import CONFIG, ENV_FILE, load, ProjectConfig, SETTINGS from failure import Failure from git_cli.git_repo import git, Git -from project_config.settings import load, ProjectConfig, SETTINGS def main(argv: list[str]) -> int: if argv[:1] in (["-h"], ["--help"]): print(__doc__.strip()) return 0 - if len(argv) > 1 or (argv and argv[0] not in SETTINGS): - print(f"usage: project-config [], where is one of {', '.join(SETTINGS)}", file=sys.stderr) + if len(argv) > 1 or (argv and argv[0] not in (*SETTINGS, ENV_FILE)): + print(f"usage: project-config [], where is one of {', '.join((*SETTINGS, ENV_FILE))}", file=sys.stderr) return 1 config = located(None, pathlib.Path.home()) if isinstance(config, Failure): print(config.reason, file=sys.stderr) return 1 - print(config.paths[argv[0]] if argv else "\n".join(f"{name}: {config.paths[name]}" for name in SETTINGS)) + paths = {**config.paths, **({ENV_FILE: config.env_file} if config.env_file else {})} + if argv and argv[0] not in paths: + print(f"{config.folder / CONFIG} sets no `{ENV_FILE}`", file=sys.stderr) + return 1 + print(paths[argv[0]] if argv else "\n".join(f"{name}: {path}" for name, path in paths.items())) return 0