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_trust.py

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

"""Tests for `_lib.trust`: which devices an encrypted send shares the room key with.

Run directly (stdlib only, no nio):

    python3 skills/matrix-communication/scripts/_lib/test_trust.py
"""

import asyncio
import os
import sys
import unittest

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

from trust import UntrustedDevicesError, send_checked, untrusted_devices


class FakeDevice:
    def __init__(
        self, user_id, device_id, verified=False, blacklisted=False, ignored=False
    ):
        self.user_id = user_id
        self.id = device_id
        self.display_name = f"{device_id} name"
        self.verified = verified
        self.blacklisted = blacklisted
        self.ignored = ignored


class FakeDeviceStore:
    def __init__(self, devices):
        self.devices = devices

    def active_user_devices(self, user_id):
        return [d for d in self.devices if d.user_id == user_id]


class FakeClient:
    def __init__(self, devices, device_id="SELF"):
        self.device_id = device_id
        self.device_store = FakeDeviceStore(devices)
        self.sent = []
        self.unignored = []
        self.verified_calls = []

    async def room_send(self, **kwargs):
        self.sent.append(kwargs)
        return "response"

    def unignore_device(self, device):
        self.unignored.append(device.id)

    def verify_device(self, device):  # must never be called
        self.verified_calls.append(device.id)


ME = "@agent:example.org"
OTHER = "@other:example.org"


def run(coro):
    return asyncio.run(coro)


class UntrustedDevicesTests(unittest.TestCase):
    def test_lists_unverified_and_ignored_devices_only(self):
        client = FakeClient(
            [
                FakeDevice(ME, "SELF"),
                FakeDevice(ME, "PHONE", verified=True),
                FakeDevice(OTHER, "BLOCKED", blacklisted=True),
                FakeDevice(OTHER, "KNOWN", ignored=True),
                FakeDevice(OTHER, "NEW"),
            ]
        )
        self.assertEqual(
            [d.id for d in untrusted_devices(client, [ME, OTHER])], ["KNOWN", "NEW"]
        )


class SendCheckedTests(unittest.TestCase):
    def test_refuses_and_sends_nothing_while_unverified_devices_are_present(self):
        client = FakeClient([FakeDevice(OTHER, "NEW")])
        sending = send_checked(client, "!r:example.org", [OTHER], "m.room.message", {})
        with self.assertRaises(UntrustedDevicesError) as caught:
            run(sending)
        self.assertEqual(client.sent, [])
        self.assertIn("NEW", str(caught.exception))
        self.assertIn("--trust-unverified-devices", str(caught.exception))

    def test_sends_strictly_when_every_device_is_verified(self):
        client = FakeClient([FakeDevice(OTHER, "PHONE", verified=True)])
        run(
            send_checked(
                client, "!r:example.org", [OTHER], "m.room.message", {"body": "x"}
            )
        )
        self.assertEqual(len(client.sent), 1)
        self.assertIs(client.sent[0]["ignore_unverified_devices"], False)
        self.assertEqual(client.unignored, [])

    def test_opt_in_shares_for_this_send_only_and_never_verifies(self):
        client = FakeClient([FakeDevice(OTHER, "NEW")])
        run(
            send_checked(
                client,
                "!r:example.org",
                [OTHER],
                "m.room.message",
                {},
                trust_unverified=True,
            )
        )
        self.assertIs(client.sent[0]["ignore_unverified_devices"], True)
        self.assertEqual(client.unignored, ["NEW"])
        self.assertEqual(client.verified_calls, [])

    def test_opt_in_is_undone_when_the_send_fails(self):
        class Failing(FakeClient):
            async def room_send(self, **kwargs):
                raise RuntimeError("network")

        client = Failing([FakeDevice(OTHER, "NEW")])
        sending = send_checked(
            client, "!r", [OTHER], "m.room.message", {}, trust_unverified=True
        )
        with self.assertRaises(RuntimeError):
            run(sending)
        self.assertEqual(client.unignored, ["NEW"])


class OlmUnverifiedDeviceError(Exception):
    """Stand-in for nio's exception, recognised by name."""

    def __init__(self, device):
        super().__init__(f"Device {device.id} is not verified")
        self.device = device


class NioLikeClient(FakeClient):
    """room_send behaves like nio 0.25: it may discover a device, then either
    refuses an unverified one or marks every unverified one ignored."""

    def __init__(self, devices, discovered=None):
        super().__init__(devices)
        self.discovered = discovered

    async def room_send(self, **kwargs):
        if self.discovered is not None:
            self.device_store.devices.append(self.discovered)
        for device in self.device_store.devices:
            if device.id == self.device_id or device.verified or device.ignored:
                continue
            if not kwargs["ignore_unverified_devices"]:
                raise OlmUnverifiedDeviceError(device)
            device.ignored = True
        self.sent.append(kwargs)
        return "response"

    def unignore_device(self, device):
        super().unignore_device(device)
        device.ignored = False


class DevicesFoundDuringSendTests(unittest.TestCase):
    def test_opt_in_resets_a_device_found_during_the_send(self):
        late = FakeDevice(OTHER, "LATE")
        client = NioLikeClient([FakeDevice(OTHER, "NEW")], discovered=late)
        run(
            send_checked(
                client, "!r", [OTHER], "m.room.message", {}, trust_unverified=True
            )
        )
        self.assertEqual(sorted(client.unignored), ["LATE", "NEW"])
        self.assertFalse(late.ignored)

    def test_strict_send_reports_a_device_found_during_the_send(self):
        late = FakeDevice(OTHER, "LATE")
        client = NioLikeClient(
            [FakeDevice(OTHER, "PHONE", verified=True)], discovered=late
        )
        sending = send_checked(client, "!r", [OTHER], "m.room.message", {})
        with self.assertRaises(UntrustedDevicesError) as caught:
            run(sending)
        self.assertIn("LATE", str(caught.exception))
        self.assertEqual(client.sent, [])

    def test_ignored_device_from_an_older_version_is_refused_without_opt_in(self):
        legacy = FakeDevice(OTHER, "LEGACY", ignored=True)
        client = NioLikeClient([legacy, FakeDevice(OTHER, "PHONE", verified=True)])
        sending = send_checked(client, "!r", [OTHER], "m.room.message", {})
        with self.assertRaises(UntrustedDevicesError) as caught:
            run(sending)
        self.assertIn("LEGACY", str(caught.exception))
        self.assertEqual(client.sent, [])

    def test_opt_in_also_resets_an_older_ignored_mark(self):
        legacy = FakeDevice(OTHER, "LEGACY", ignored=True)
        client = NioLikeClient([legacy])
        run(
            send_checked(
                client, "!r", [OTHER], "m.room.message", {}, trust_unverified=True
            )
        )
        self.assertFalse(legacy.ignored)


class SlowNioLikeClient(NioLikeClient):
    """Yields to the event loop after marking devices ignored, like a network round trip."""

    async def room_send(self, **kwargs):
        result = await super().room_send(**kwargs)
        for _ in range(5):
            await asyncio.sleep(0)
        return result


class ConcurrentSendTests(unittest.TestCase):
    def test_strict_send_waits_for_an_opted_in_send_on_the_same_client(self):
        client = SlowNioLikeClient([FakeDevice(OTHER, "NEW")])

        async def both():
            flagged = asyncio.create_task(
                send_checked(
                    client,
                    "!r",
                    [OTHER],
                    "m.room.message",
                    {"n": 1},
                    trust_unverified=True,
                )
            )
            await asyncio.sleep(0)
            strict = send_checked(client, "!r", [OTHER], "m.room.message", {"n": 2})
            return await asyncio.gather(flagged, strict, return_exceptions=True)

        flagged_result, strict_result = run(both())
        self.assertEqual(flagged_result, "response")
        self.assertIsInstance(strict_result, UntrustedDevicesError)
        self.assertEqual([sent["content"] for sent in client.sent], [{"n": 1}])


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