zchat-protocol 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zchat_protocol-0.1.0/.github/workflows/publish.yml +17 -0
- zchat_protocol-0.1.0/LICENSE +21 -0
- zchat_protocol-0.1.0/PKG-INFO +10 -0
- zchat_protocol-0.1.0/pyproject.toml +21 -0
- zchat_protocol-0.1.0/tests/test_naming.py +17 -0
- zchat_protocol-0.1.0/tests/test_sys_messages.py +37 -0
- zchat_protocol-0.1.0/uv.lock +79 -0
- zchat_protocol-0.1.0/zchat_protocol/__init__.py +3 -0
- zchat_protocol-0.1.0/zchat_protocol/naming.py +13 -0
- zchat_protocol-0.1.0/zchat_protocol/sys_messages.py +45 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags: ["v*"]
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: pypi
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: astral-sh/setup-uv@v4
|
|
16
|
+
- run: uv build
|
|
17
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ezagent42
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zchat-protocol
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Protocol definitions for zchat multi-agent collaboration
|
|
5
|
+
Project-URL: Homepage, https://github.com/ezagent42/zchat-protocol
|
|
6
|
+
Project-URL: Repository, https://github.com/ezagent42/zchat-protocol
|
|
7
|
+
Author: ezagent42
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.11
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "zchat-protocol"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Protocol definitions for zchat multi-agent collaboration"
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
dependencies = []
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [{ name = "ezagent42" }]
|
|
9
|
+
|
|
10
|
+
[project.urls]
|
|
11
|
+
Homepage = "https://github.com/ezagent42/zchat-protocol"
|
|
12
|
+
Repository = "https://github.com/ezagent42/zchat-protocol"
|
|
13
|
+
|
|
14
|
+
[build-system]
|
|
15
|
+
requires = ["hatchling"]
|
|
16
|
+
build-backend = "hatchling.build"
|
|
17
|
+
|
|
18
|
+
[dependency-groups]
|
|
19
|
+
dev = [
|
|
20
|
+
"pytest>=9.0.2",
|
|
21
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from zchat_protocol.naming import scoped_name, AGENT_SEPARATOR
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_separator_is_dash():
|
|
5
|
+
assert AGENT_SEPARATOR == "-"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_scoped_name_adds_prefix():
|
|
9
|
+
assert scoped_name("helper", "alice") == "alice-helper"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_scoped_name_no_double_prefix():
|
|
13
|
+
assert scoped_name("alice-helper", "alice") == "alice-helper"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_scoped_name_different_prefix():
|
|
17
|
+
assert scoped_name("bob-helper", "alice") == "bob-helper"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from zchat_protocol.sys_messages import (
|
|
2
|
+
is_sys_message, make_sys_message,
|
|
3
|
+
encode_sys_for_irc, decode_sys_from_irc,
|
|
4
|
+
IRC_SYS_PREFIX,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_sys_prefix():
|
|
9
|
+
assert IRC_SYS_PREFIX == "__zchat_sys:"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_make_sys_message_fields():
|
|
13
|
+
msg = make_sys_message("alice-agent0", "sys.stop_request", {"reason": "test"})
|
|
14
|
+
assert msg["nick"] == "alice-agent0"
|
|
15
|
+
assert msg["type"] == "sys.stop_request"
|
|
16
|
+
assert msg["body"]["reason"] == "test"
|
|
17
|
+
assert "id" in msg
|
|
18
|
+
assert "ts" in msg
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_is_sys_message():
|
|
22
|
+
assert is_sys_message({"type": "sys.stop_request"})
|
|
23
|
+
assert not is_sys_message({"type": "msg"})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_irc_roundtrip():
|
|
27
|
+
msg = make_sys_message("alice-agent0", "sys.stop_request", {"reason": "test"})
|
|
28
|
+
encoded = encode_sys_for_irc(msg)
|
|
29
|
+
assert encoded.startswith("__zchat_sys:")
|
|
30
|
+
decoded = decode_sys_from_irc(encoded)
|
|
31
|
+
assert decoded["type"] == "sys.stop_request"
|
|
32
|
+
assert decoded["body"]["reason"] == "test"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_decode_non_sys():
|
|
36
|
+
assert decode_sys_from_irc("hello world") is None
|
|
37
|
+
assert decode_sys_from_irc("{json-like}") is None
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
version = 1
|
|
2
|
+
revision = 3
|
|
3
|
+
requires-python = ">=3.11"
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "colorama"
|
|
7
|
+
version = "0.4.6"
|
|
8
|
+
source = { registry = "https://pypi.org/simple" }
|
|
9
|
+
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
|
|
10
|
+
wheels = [
|
|
11
|
+
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[package]]
|
|
15
|
+
name = "iniconfig"
|
|
16
|
+
version = "2.3.0"
|
|
17
|
+
source = { registry = "https://pypi.org/simple" }
|
|
18
|
+
sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503, upload-time = "2025-10-18T21:55:43.219Z" }
|
|
19
|
+
wheels = [
|
|
20
|
+
{ url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "packaging"
|
|
25
|
+
version = "26.0"
|
|
26
|
+
source = { registry = "https://pypi.org/simple" }
|
|
27
|
+
sdist = { url = "https://files.pythonhosted.org/packages/65/ee/299d360cdc32edc7d2cf530f3accf79c4fca01e96ffc950d8a52213bd8e4/packaging-26.0.tar.gz", hash = "sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4", size = 143416, upload-time = "2026-01-21T20:50:39.064Z" }
|
|
28
|
+
wheels = [
|
|
29
|
+
{ url = "https://files.pythonhosted.org/packages/b7/b9/c538f279a4e237a006a2c98387d081e9eb060d203d8ed34467cc0f0b9b53/packaging-26.0-py3-none-any.whl", hash = "sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529", size = 74366, upload-time = "2026-01-21T20:50:37.788Z" },
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "pluggy"
|
|
34
|
+
version = "1.6.0"
|
|
35
|
+
source = { registry = "https://pypi.org/simple" }
|
|
36
|
+
sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
|
|
37
|
+
wheels = [
|
|
38
|
+
{ url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[[package]]
|
|
42
|
+
name = "pygments"
|
|
43
|
+
version = "2.19.2"
|
|
44
|
+
source = { registry = "https://pypi.org/simple" }
|
|
45
|
+
sdist = { url = "https://files.pythonhosted.org/packages/b0/77/a5b8c569bf593b0140bde72ea885a803b82086995367bf2037de0159d924/pygments-2.19.2.tar.gz", hash = "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887", size = 4968631, upload-time = "2025-06-21T13:39:12.283Z" }
|
|
46
|
+
wheels = [
|
|
47
|
+
{ url = "https://files.pythonhosted.org/packages/c7/21/705964c7812476f378728bdf590ca4b771ec72385c533964653c68e86bdc/pygments-2.19.2-py3-none-any.whl", hash = "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b", size = 1225217, upload-time = "2025-06-21T13:39:07.939Z" },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[[package]]
|
|
51
|
+
name = "pytest"
|
|
52
|
+
version = "9.0.2"
|
|
53
|
+
source = { registry = "https://pypi.org/simple" }
|
|
54
|
+
dependencies = [
|
|
55
|
+
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
|
56
|
+
{ name = "iniconfig" },
|
|
57
|
+
{ name = "packaging" },
|
|
58
|
+
{ name = "pluggy" },
|
|
59
|
+
{ name = "pygments" },
|
|
60
|
+
]
|
|
61
|
+
sdist = { url = "https://files.pythonhosted.org/packages/d1/db/7ef3487e0fb0049ddb5ce41d3a49c235bf9ad299b6a25d5780a89f19230f/pytest-9.0.2.tar.gz", hash = "sha256:75186651a92bd89611d1d9fc20f0b4345fd827c41ccd5c299a868a05d70edf11", size = 1568901, upload-time = "2025-12-06T21:30:51.014Z" }
|
|
62
|
+
wheels = [
|
|
63
|
+
{ url = "https://files.pythonhosted.org/packages/3b/ab/b3226f0bd7cdcf710fbede2b3548584366da3b19b5021e74f5bde2a8fa3f/pytest-9.0.2-py3-none-any.whl", hash = "sha256:711ffd45bf766d5264d487b917733b453d917afd2b0ad65223959f59089f875b", size = 374801, upload-time = "2025-12-06T21:30:49.154Z" },
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[[package]]
|
|
67
|
+
name = "zchat-protocol"
|
|
68
|
+
version = "0.1.0"
|
|
69
|
+
source = { editable = "." }
|
|
70
|
+
|
|
71
|
+
[package.dev-dependencies]
|
|
72
|
+
dev = [
|
|
73
|
+
{ name = "pytest" },
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
[package.metadata]
|
|
77
|
+
|
|
78
|
+
[package.metadata.requires-dev]
|
|
79
|
+
dev = [{ name = "pytest", specifier = ">=9.0.2" }]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Agent naming conventions."""
|
|
2
|
+
|
|
3
|
+
AGENT_SEPARATOR = "-"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def scoped_name(name: str, username: str) -> str:
|
|
7
|
+
"""Add username prefix to agent name if not already scoped.
|
|
8
|
+
'helper' + 'alice' → 'alice-helper'
|
|
9
|
+
'alice-helper' + 'alice' → 'alice-helper' (no change)
|
|
10
|
+
"""
|
|
11
|
+
if AGENT_SEPARATOR in name:
|
|
12
|
+
return name
|
|
13
|
+
return f"{username}{AGENT_SEPARATOR}{name}"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""System message protocol for machine-to-machine control over IRC PRIVMSG."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
SYS_PREFIX = "sys."
|
|
9
|
+
IRC_SYS_PREFIX = "__zchat_sys:"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _random_hex(n: int) -> str:
|
|
13
|
+
return os.urandom(n // 2 + 1).hex()[:n]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def is_sys_message(msg: dict) -> bool:
|
|
17
|
+
"""Check if a message is a system control message."""
|
|
18
|
+
return msg.get("type", "").startswith(SYS_PREFIX)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def make_sys_message(nick: str, type: str, body: dict, ref_id: str | None = None) -> dict:
|
|
22
|
+
"""Create a system message. Caller provides nick."""
|
|
23
|
+
return {
|
|
24
|
+
"id": _random_hex(8),
|
|
25
|
+
"nick": nick,
|
|
26
|
+
"type": type,
|
|
27
|
+
"body": body,
|
|
28
|
+
"ref_id": ref_id,
|
|
29
|
+
"ts": time.time(),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def encode_sys_for_irc(msg: dict) -> str:
|
|
34
|
+
"""Encode a sys message for IRC PRIVMSG transport."""
|
|
35
|
+
return f"{IRC_SYS_PREFIX}{json.dumps(msg)}"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def decode_sys_from_irc(text: str) -> dict | None:
|
|
39
|
+
"""Decode a sys message from IRC PRIVMSG. Returns None if not a sys message."""
|
|
40
|
+
if not text.startswith(IRC_SYS_PREFIX):
|
|
41
|
+
return None
|
|
42
|
+
try:
|
|
43
|
+
return json.loads(text[len(IRC_SYS_PREFIX):])
|
|
44
|
+
except json.JSONDecodeError:
|
|
45
|
+
return None
|