Skip to content

netresearch/matrix-skill / skills/matrix-communication

matrix-communication

Flagged

Use when communicating via Matrix chat, notifying teams, or managing E2EE. Triggers on #room:server references, Matrix URLs, and chat requests.

FileKindSize
README.mdmarkdown2.9 KB
SKILL.mdskill md6.7 KB
evals/evals.jsonconfig12.6 KB
references/agent-governance.mdmarkdown2.0 KB
references/api-reference.mdmarkdown7.3 KB
references/command-reference.mdmarkdown8.9 KB
references/e2ee-guide.mdmarkdown17.2 KB
references/hookshot-integration.mdmarkdown10.7 KB
references/messaging-guide.mdmarkdown13.8 KB
references/no-editorializing.mdmarkdown331 B
references/setup-guide.mdmarkdown11.1 KB
references/troubleshooting.mdmarkdown7.8 KB
scripts/_lib/__init__.pyscript3.6 KB
scripts/_lib/backup_mac.pyscript1.2 KB
scripts/_lib/config.pyscript4.6 KB
scripts/_lib/daemon_client.pyscript3.0 KB
scripts/_lib/deps.pyscript1.9 KB
scripts/_lib/downloads.pyscript1.1 KB
scripts/_lib/e2ee.pyscript13.2 KB
scripts/_lib/formatting.pyscript14.4 KB
scripts/_lib/http.pyscript4.8 KB
scripts/_lib/reactions.pyscript2.9 KB
scripts/_lib/roomlog.pyscript13.7 KB
scripts/_lib/rooms.pyscript15.5 KB
scripts/_lib/secret_input.pyscript2.0 KB
scripts/_lib/test_backup_mac.pyscript1.5 KB
scripts/_lib/test_config.pyscript7.1 KB
scripts/_lib/test_daemon_client.pyscript5.9 KB
scripts/_lib/test_downloads.pyscript2.3 KB
scripts/_lib/test_e2ee.pyscript14.3 KB
scripts/_lib/test_formatting.pyscript15.5 KB
scripts/_lib/test_http.pyscript4.1 KB
scripts/_lib/test_reactions.pyscript15.2 KB
scripts/_lib/test_roomlog.pyscript20.2 KB
scripts/_lib/test_rooms.pyscript13.7 KB
scripts/_lib/test_secret_input.pyscript2.2 KB
scripts/_lib/test_trust.pyscript8.3 KB
scripts/_lib/trust.pyscript5.3 KB
scripts/_lib/utils.pyscript1.7 KB
scripts/matrix-create-room.pyexecutablescript4.7 KB
scripts/matrix-doctor.pyexecutablescript22.2 KB
scripts/matrix-download-e2ee.pyexecutablescript7.7 KB
scripts/matrix-e2ee-setup.pyexecutablescript9.2 KB
scripts/matrix-e2ee-verify.pyexecutablescript29.2 KB
scripts/matrix-edit-e2ee.pyexecutablescript7.9 KB
scripts/matrix-edit.pyexecutablescript5.3 KB
scripts/matrix-fetch-keys.pyexecutablescript9.1 KB
scripts/matrix-invite.pyexecutablescript3.0 KB
scripts/matrix-key-backup.pyexecutablescript21.3 KB
scripts/matrix-power-level.pyexecutablescript7.0 KB
scripts/matrix-react.pyexecutablescript14.1 KB
scripts/matrix-read-e2ee.pyexecutablescript12.8 KB
scripts/matrix-read.pyexecutablescript4.7 KB
scripts/matrix-redact.pyexecutablescript5.0 KB
scripts/matrix-resolve.pyexecutablescript1.7 KB
scripts/matrix-rooms.pyexecutablescript3.8 KB
scripts/matrix-send-e2ee.pyexecutablescript19.4 KB
scripts/matrix-send.pyexecutablescript9.4 KB
scripts/matrix-watch.pyexecutablescript5.3 KB
scripts/matrix-watchd.pyexecutablescript23.5 KB
scripts/test_matrix_doctor.pyscript14.2 KB
scripts/test_matrix_read_e2ee.pyscript2.7 KB

scripts/_lib/test_daemon_client.py

View on GitHub
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Netresearch DTT GmbH

"""Tests for `_lib.daemon_client`.

The point under test is the routing decision: a command may only delegate to a
daemon that actually answers. Deciding on the store lock instead would be wrong
in a way that is easy to miss - a direct send holds that same lock for its
couple of seconds.

Run directly: python3 skills/matrix-communication/scripts/_lib/test_daemon_client.py
"""

import json
import os
import pathlib
import shutil
import socket
import sys
import tempfile
import threading
import unittest

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

import daemon_client
from daemon_client import daemon_request


class FakeDaemon:
    """One-shot listener answering with a canned payload."""

    def __init__(self, path, response, reply=True):
        self.path = str(path)
        self.response = response
        self.reply = reply
        self.received = None
        self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.sock.bind(self.path)
        self.sock.listen(1)
        self.thread = threading.Thread(target=self._serve, daemon=True)
        self.thread.start()

    def _serve(self):
        try:
            conn, _ = self.sock.accept()
        except OSError:
            return
        with conn:
            data = b""
            while not data.endswith(b"\n"):
                chunk = conn.recv(4096)
                if not chunk:
                    return
                data += chunk
            self.received = json.loads(data)
            if self.reply:
                conn.sendall(json.dumps(self.response).encode() + b"\n")

    def close(self):
        self.sock.close()


class RoutingTests(unittest.TestCase):
    def setUp(self):
        self.dir = pathlib.Path(tempfile.mkdtemp())
        self.addCleanup(shutil.rmtree, self.dir, True)
        self.path = self.dir / "daemon.sock"
        real = daemon_client.socket_path
        daemon_client.socket_path = lambda: self.path
        self.addCleanup(setattr, daemon_client, "socket_path", real)

    def test_no_socket_file_means_no_daemon(self):
        self.assertIsNone(daemon_request({"op": "status"}))

    def test_stale_socket_means_no_daemon(self):
        """A crashed daemon leaves the file behind with nothing listening. The
        caller must fall back, not hang or crash."""
        self.path.touch()
        self.assertIsNone(daemon_request({"op": "status"}))

    def test_request_round_trips(self):
        fake = FakeDaemon(self.path, {"ok": True, "event_id": "$x"})
        self.addCleanup(fake.close)
        got = daemon_request({"op": "send", "room": "!r:e", "body": "hi"})
        self.assertEqual(got, {"ok": True, "event_id": "$x"})
        fake.thread.join(timeout=5)
        self.assertEqual(fake.received["op"], "send")
        self.assertEqual(fake.received["body"], "hi")

    def test_error_response_is_returned_not_swallowed(self):
        """An error from the daemon is an answer. Returning None would send the
        caller down the direct path and send the message twice."""
        fake = FakeDaemon(self.path, {"ok": False, "error": "no such room"})
        self.addCleanup(fake.close)
        got = daemon_request({"op": "send", "room": "!r:e", "body": "hi"})
        self.assertIsNotNone(got)
        self.assertFalse(got["ok"])
        self.assertIn("no such room", got["error"])

    def test_daemon_closing_without_answering_reads_as_no_daemon(self):
        fake = FakeDaemon(self.path, {}, reply=False)
        self.addCleanup(fake.close)
        self.assertIsNone(daemon_request({"op": "status"}))

    def test_unicode_survives_the_round_trip(self):
        fake = FakeDaemon(self.path, {"ok": True, "event_id": "$x"})
        self.addCleanup(fake.close)
        daemon_request({"op": "send", "room": "!r:e", "body": "Grüße 🎁"})
        fake.thread.join(timeout=5)
        self.assertEqual(fake.received["body"], "Grüße 🎁")


class SocketPathTests(unittest.TestCase):
    def setUp(self):
        self.previous = os.environ.get("XDG_RUNTIME_DIR")
        self.addCleanup(self._restore)

    def _restore(self):
        if self.previous is None:
            os.environ.pop("XDG_RUNTIME_DIR", None)
        else:
            os.environ["XDG_RUNTIME_DIR"] = self.previous

    def test_an_existing_runtime_dir_is_preferred(self):
        directory = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, directory, True)
        os.environ["XDG_RUNTIME_DIR"] = directory
        self.assertEqual(
            str(daemon_client.socket_path()),
            f"{directory}/matrix-skill/daemon.sock",
        )

    def test_a_runtime_dir_that_does_not_exist_is_not_used(self):
        """WSL and containers export XDG_RUNTIME_DIR for a directory nobody
        created. Trusting the variable crashed the daemon on startup."""
        os.environ["XDG_RUNTIME_DIR"] = "/run/user/does-not-exist-99999"
        path = daemon_client.socket_path()
        self.assertNotIn("does-not-exist", str(path))
        self.assertTrue(str(path).endswith("matrix-skill/daemon.sock"))

    def test_falls_back_when_there_is_no_runtime_dir(self):
        os.environ.pop("XDG_RUNTIME_DIR", None)
        self.assertTrue(str(daemon_client.socket_path()).endswith("daemon.sock"))


class RunningDaemonPidTests(unittest.TestCase):
    """--stop signals only a pid the daemon itself reported."""

    def test_pid_from_a_status_answer(self):
        self.assertEqual(
            daemon_client.running_daemon_pid({"ok": True, "pid": 4242}), 4242
        )

    def test_no_answer_means_nothing_to_stop(self):
        self.assertIsNone(daemon_client.running_daemon_pid(None))
        self.assertIsNone(daemon_client.running_daemon_pid({"ok": False, "error": "x"}))

    def test_implausible_pid_is_not_signalled(self):
        for pid in (0, -1, "123", True, None):
            self.assertIsNone(
                daemon_client.running_daemon_pid({"ok": True, "pid": pid}), pid
            )


if __name__ == "__main__":
    unittest.main(verbosity=2)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall