polyctl 0.7.0__py3-none-any.whl
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.
- polyctl/__init__.py +7 -0
- polyctl/__main__.py +5 -0
- polyctl/a2a.py +226 -0
- polyctl/a2a_mcp.py +546 -0
- polyctl/acp.py +417 -0
- polyctl/adapters/README.md +101 -0
- polyctl/adapters/aider.json +32 -0
- polyctl/adapters/amazon-q.json +15 -0
- polyctl/adapters/amp.json +16 -0
- polyctl/adapters/antigravity.json +120 -0
- polyctl/adapters/claude-code.json +229 -0
- polyctl/adapters/cloud-generic.json +57 -0
- polyctl/adapters/codex.json +47 -0
- polyctl/adapters/command-code.json +45 -0
- polyctl/adapters/copilot.json +17 -0
- polyctl/adapters/cursor-agent.json +29 -0
- polyctl/adapters/deepseek.json +13 -0
- polyctl/adapters/droid.json +34 -0
- polyctl/adapters/gemini.json +30 -0
- polyctl/adapters/grok.json +22 -0
- polyctl/adapters/hermes.json +34 -0
- polyctl/adapters/kilocode.json +30 -0
- polyctl/adapters/kimi.json +23 -0
- polyctl/adapters/kiro.json +332 -0
- polyctl/adapters/ollama.json +29 -0
- polyctl/adapters/omp.json +34 -0
- polyctl/adapters/openai-api.json +68 -0
- polyctl/adapters/opencode.json +162 -0
- polyctl/adapters/pi.json +24 -0
- polyctl/adapters/pr-agent.json +54 -0
- polyctl/adapters/profiles.json +9 -0
- polyctl/adapters/qoder.json +163 -0
- polyctl/adapters/qwen.json +27 -0
- polyctl/adapters/reasonix.json +25 -0
- polyctl/adapters/rewriters/rtk.json +24 -0
- polyctl/adapters/trae.json +31 -0
- polyctl/adapters/vendors.json +42 -0
- polyctl/adapters/warp.json +88 -0
- polyctl/allowlist.py +1756 -0
- polyctl/api_review.py +920 -0
- polyctl/cli.py +835 -0
- polyctl/conformance_harness.py +9 -0
- polyctl/demo.py +503 -0
- polyctl/drivers.py +146 -0
- polyctl/email.py +160 -0
- polyctl/features.py +98 -0
- polyctl/journal.py +144 -0
- polyctl/language.py +945 -0
- polyctl/lib.py +1296 -0
- polyctl/matrix.py +660 -0
- polyctl/mcp.py +1362 -0
- polyctl/ntfy.py +169 -0
- polyctl/outbound.py +39 -0
- polyctl/parts/__init__.py +5 -0
- polyctl/parts/cli_authority.py +2615 -0
- polyctl/parts/cli_channels.py +1325 -0
- polyctl/parts/cli_checks.py +2293 -0
- polyctl/parts/cli_completion.py +686 -0
- polyctl/parts/cli_evidence.py +141 -0
- polyctl/parts/cli_gain.py +375 -0
- polyctl/parts/cli_harness.py +392 -0
- polyctl/parts/cli_hooks.py +1816 -0
- polyctl/parts/cli_install.py +638 -0
- polyctl/parts/cli_lanes.py +106 -0
- polyctl/parts/cli_maintenance.py +2536 -0
- polyctl/parts/cli_next.py +248 -0
- polyctl/parts/cli_pr.py +53 -0
- polyctl/parts/cli_project.py +2857 -0
- polyctl/parts/cli_review.py +5158 -0
- polyctl/parts/cli_status.py +898 -0
- polyctl/parts/lib_adapters.py +2933 -0
- polyctl/parts/lib_alarms.py +2106 -0
- polyctl/parts/lib_events.py +224 -0
- polyctl/parts/lib_evidence.py +412 -0
- polyctl/parts/lib_gates.py +2099 -0
- polyctl/parts/lib_lanes.py +829 -0
- polyctl/parts/lib_mail.py +1541 -0
- polyctl/parts/lib_next.py +652 -0
- polyctl/parts/lib_pr.py +331 -0
- polyctl/parts/lib_slices.py +3337 -0
- polyctl/parts/lib_state.py +2415 -0
- polyctl/parts/lib_transcript.py +4118 -0
- polyctl/pressure.py +325 -0
- polyctl/prices.json +47 -0
- polyctl/procs.py +1194 -0
- polyctl/settings.py +505 -0
- polyctl/skill/SKILL.md +365 -0
- polyctl/skillkit.py +503 -0
- polyctl/storage.py +2055 -0
- polyctl/telegram.py +327 -0
- polyctl/tiers.py +123 -0
- polyctl/verdicts.py +41 -0
- polyctl/watchdog.py +3887 -0
- polyctl/web.py +337 -0
- polyctl-0.7.0.dist-info/METADATA +235 -0
- polyctl-0.7.0.dist-info/RECORD +99 -0
- polyctl-0.7.0.dist-info/WHEEL +4 -0
- polyctl-0.7.0.dist-info/entry_points.txt +5 -0
- polyctl-0.7.0.dist-info/licenses/LICENSE +21 -0
polyctl/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""polyctl — your agents commit, every change is granted first or flagged.
|
|
2
|
+
|
|
3
|
+
Standard library only, deliberately. This tool watches agents on machines it does
|
|
4
|
+
not control, and a dependency is a thing that can be missing exactly there.
|
|
5
|
+
"""
|
|
6
|
+
# The one place the version is written: pyproject.toml reads it, and so does `polyctl --version`.
|
|
7
|
+
__version__ = "0.7.0"
|
polyctl/__main__.py
ADDED
polyctl/a2a.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""polyctl-a2a — serve this project's board as A2A tasks.
|
|
3
|
+
|
|
4
|
+
A2A (Agent2Agent) gives agents from different vendors a shared vocabulary for
|
|
5
|
+
work in flight. Its task states map onto this board almost exactly, and the
|
|
6
|
+
match is not a coincidence: `input-required` is precisely a slice parked on a
|
|
7
|
+
human decision, which is the state this tool was built to make visible.
|
|
8
|
+
|
|
9
|
+
Two states do not map cleanly, and the mapping table says so rather than
|
|
10
|
+
pretending otherwise. `inbox` and `queued` are both A2A `submitted` — A2A has no
|
|
11
|
+
notion of an item that arrived but has not been *admitted*, which is this tool's
|
|
12
|
+
central gate. And `verified` has no A2A equivalent at all: gates passed,
|
|
13
|
+
authority to land not yet granted. Renaming our states to match would delete the
|
|
14
|
+
distinction the tool exists to draw.
|
|
15
|
+
|
|
16
|
+
Read-only by design. Accepting work over A2A means letting a remote agent put
|
|
17
|
+
items on this board, and admission — deciding what may be worked unattended — is
|
|
18
|
+
not a thing to expose on a network port. Pull from a tracker instead; see
|
|
19
|
+
docs/sources.md.
|
|
20
|
+
|
|
21
|
+
Standard library only.
|
|
22
|
+
"""
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import socket
|
|
26
|
+
import socketserver
|
|
27
|
+
import sys
|
|
28
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
29
|
+
|
|
30
|
+
from . import __version__, lib as A
|
|
31
|
+
|
|
32
|
+
CFG = {}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def agent_card(base):
|
|
36
|
+
root = CFG["root"]
|
|
37
|
+
return {
|
|
38
|
+
"protocolVersion": "1.0",
|
|
39
|
+
"name": f"polyctl:{CFG.get('project') or os.path.basename(root)}",
|
|
40
|
+
"description": "Orchestration state for one repository: what the implementer is "
|
|
41
|
+
"doing, what is blocked and on what, and what has been measured.",
|
|
42
|
+
"url": base,
|
|
43
|
+
"preferredTransport": "JSONRPC",
|
|
44
|
+
"interfaces": [{"url": base, "protocolBinding": "JSONRPC",
|
|
45
|
+
"protocolVersion": "1.0"}],
|
|
46
|
+
"version": __version__,
|
|
47
|
+
"capabilities": {"streaming": False, "pushNotifications": False},
|
|
48
|
+
"defaultInputModes": ["text/plain"],
|
|
49
|
+
"defaultOutputModes": ["application/json"],
|
|
50
|
+
"skills": [
|
|
51
|
+
{"id": "board", "name": "Work board",
|
|
52
|
+
"description": "Every work item and its state, including what a blocked item "
|
|
53
|
+
"is waiting on.",
|
|
54
|
+
"tags": ["status", "planning"]},
|
|
55
|
+
{"id": "status", "name": "Implementer status",
|
|
56
|
+
"description": "Live state of the agent working this repository.",
|
|
57
|
+
"tags": ["status", "telemetry"]},
|
|
58
|
+
],
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def tasks(v1=True):
|
|
63
|
+
"""Board items as A2A tasks. The id is the board id, so it is stable.
|
|
64
|
+
|
|
65
|
+
1.0 prefixes and upper-cases every state (`input-required` becomes
|
|
66
|
+
`TASK_STATE_INPUT_REQUIRED`) and re-cases roles. Emit whichever the caller
|
|
67
|
+
asked for, keyed off the method name it used, rather than picking one and
|
|
68
|
+
making half the callers wrong.
|
|
69
|
+
"""
|
|
70
|
+
root = CFG["root"]
|
|
71
|
+
out = []
|
|
72
|
+
for state, items in A.board(root).items():
|
|
73
|
+
for it in items:
|
|
74
|
+
note = it["notes"]
|
|
75
|
+
a2a = A.A2A_STATE.get(state, "unknown")
|
|
76
|
+
wire = ("TASK_STATE_" + a2a.upper().replace("-", "_")) if v1 else a2a
|
|
77
|
+
task = {"id": it["id"], "contextId": os.path.basename(root),
|
|
78
|
+
"status": {"state": wire},
|
|
79
|
+
"metadata": {"polyctlState": state, "title": it["title"], **note}}
|
|
80
|
+
if state == "blocked":
|
|
81
|
+
# A2A calls it input-required; the useful part is *what* input.
|
|
82
|
+
part = {"text": note.get("needs") or "reason not recorded"}
|
|
83
|
+
if not v1:
|
|
84
|
+
part["kind"] = "text"
|
|
85
|
+
task["status"]["message"] = {
|
|
86
|
+
"role": "ROLE_AGENT" if v1 else "agent", "parts": [part]}
|
|
87
|
+
out.append(task)
|
|
88
|
+
return out
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# The largest request the board's methods take: one names a method and a task id. A body's declared length
|
|
92
|
+
# was read whole, however large (A2A-HARDEN).
|
|
93
|
+
MAX_REQUEST_BYTES = 1 << 20
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Handler(BaseHTTPRequestHandler):
|
|
97
|
+
# A connection that sends nothing, or less than its Content-Length said, is closed rather than kept: the
|
|
98
|
+
# server read a declared body with no limit in time, one connection at a time, so one stalled client held
|
|
99
|
+
# every other (A2A-HARDEN).
|
|
100
|
+
timeout = 30
|
|
101
|
+
|
|
102
|
+
def parse_request(self):
|
|
103
|
+
"""Refuse any Host but this server's own before anything is read or computed (A2A-HARDEN).
|
|
104
|
+
|
|
105
|
+
The server binds loopback alone, and a page from another site can still point its own name at
|
|
106
|
+
127.0.0.1 and read the board through a person's browser (DNS rebinding): `polyctl watch --web` refused
|
|
107
|
+
such a request, this server answered it.
|
|
108
|
+
"""
|
|
109
|
+
if not super().parse_request():
|
|
110
|
+
return False
|
|
111
|
+
if (self.headers.get("Host") or "").strip().lower() not in self.server.hosts():
|
|
112
|
+
self._send(403, {"error": f"this A2A server answers only to {' or '.join(sorted(self.server.hosts()))}"})
|
|
113
|
+
return False
|
|
114
|
+
return True
|
|
115
|
+
|
|
116
|
+
def _send(self, code, payload):
|
|
117
|
+
body = json.dumps(payload, ensure_ascii=False, default=str).encode()
|
|
118
|
+
self.send_response(code)
|
|
119
|
+
self.send_header("Content-Type", "application/a2a+json; charset=utf-8")
|
|
120
|
+
self.send_header("Content-Length", str(len(body)))
|
|
121
|
+
self.end_headers()
|
|
122
|
+
self.wfile.write(body)
|
|
123
|
+
|
|
124
|
+
def log_message(self, *a):
|
|
125
|
+
pass # the access log is noise here
|
|
126
|
+
|
|
127
|
+
def do_GET(self):
|
|
128
|
+
base = f"http://{self.headers.get('Host', 'localhost')}"
|
|
129
|
+
if self.path in ("/.well-known/agent-card.json", "/.well-known/agent.json"):
|
|
130
|
+
return self._send(200, agent_card(base))
|
|
131
|
+
if self.path == "/tasks":
|
|
132
|
+
return self._send(200, {"tasks": tasks()})
|
|
133
|
+
self._send(404, {"error": "not found"})
|
|
134
|
+
|
|
135
|
+
def _error(self, rid, code, message, status=200):
|
|
136
|
+
return self._send(status, {"jsonrpc": "2.0", "id": rid, "error": {"code": code, "message": message}})
|
|
137
|
+
|
|
138
|
+
def do_POST(self):
|
|
139
|
+
try:
|
|
140
|
+
n = int(self.headers.get("Content-Length") or 0)
|
|
141
|
+
except ValueError:
|
|
142
|
+
n = -1
|
|
143
|
+
# A negative length read until the client closed; a large one was read whole (A2A-HARDEN).
|
|
144
|
+
if n < 0:
|
|
145
|
+
return self._error(None, -32700, "Content-Length is not a length", 400)
|
|
146
|
+
if n > MAX_REQUEST_BYTES:
|
|
147
|
+
return self._error(None, -32600, f"a request of {n} bytes is past the {MAX_REQUEST_BYTES} this server "
|
|
148
|
+
"reads", 413)
|
|
149
|
+
try:
|
|
150
|
+
req = json.loads(self.rfile.read(n) or b"{}")
|
|
151
|
+
except Exception as e:
|
|
152
|
+
return self._error(None, -32700, str(e), 400)
|
|
153
|
+
# A JSON array or a scalar, or params that are no object, ended the request with no answer (A2A-HARDEN).
|
|
154
|
+
if not isinstance(req, dict):
|
|
155
|
+
return self._error(None, -32600, "a request is a JSON object")
|
|
156
|
+
rid, method = req.get("id"), req.get("method")
|
|
157
|
+
params = req.get("params") or {}
|
|
158
|
+
if not isinstance(params, dict):
|
|
159
|
+
return self._error(rid, -32602, "params is a JSON object")
|
|
160
|
+
if method in ("ListTasks", "tasks/list"):
|
|
161
|
+
return self._send(200, {"jsonrpc": "2.0", "id": rid,
|
|
162
|
+
"result": {"tasks": tasks(method[0].isupper())}})
|
|
163
|
+
if method in ("GetTask", "tasks/get"):
|
|
164
|
+
want = params.get("id")
|
|
165
|
+
for t in tasks(method[0].isupper()):
|
|
166
|
+
if t["id"] == want:
|
|
167
|
+
return self._send(200, {"jsonrpc": "2.0", "id": rid, "result": t})
|
|
168
|
+
return self._send(200, {"jsonrpc": "2.0", "id": rid,
|
|
169
|
+
"error": {"code": -32001, "message": "task not found"}})
|
|
170
|
+
if method in ("message/send", "message/stream", "tasks/cancel",
|
|
171
|
+
"SendMessage", "SubscribeToTask", "CancelTask"):
|
|
172
|
+
return self._send(200, {"jsonrpc": "2.0", "id": rid, "error": {
|
|
173
|
+
"code": -32004,
|
|
174
|
+
"message": "this endpoint is read-only: admitting work is a local decision, "
|
|
175
|
+
"not a network-exposed one. See docs/sources.md."}})
|
|
176
|
+
self._send(200, {"jsonrpc": "2.0", "id": rid,
|
|
177
|
+
"error": {"code": -32601, "message": f"method not found: {method}"}})
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class _Server(ThreadingHTTPServer):
|
|
181
|
+
"""The A2A listener, named by its address: the resolver is not asked for the loopback address's name,
|
|
182
|
+
which on a machine whose resolver is slow to answer held the server back from listening (LOOPBACK-BIND).
|
|
183
|
+
|
|
184
|
+
Each connection has a thread of its own, so a client that stalls holds up no other, as in `polyctl watch --web`
|
|
185
|
+
(A2A-HARDEN).
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
daemon_threads = True
|
|
189
|
+
# As in the web view: elsewhere the option only lets a restarted server take its port back at once; on
|
|
190
|
+
# Windows it lets the bind succeed on a port another program already listens on, where it must fail.
|
|
191
|
+
allow_reuse_address = os.name != "nt"
|
|
192
|
+
|
|
193
|
+
def server_bind(self):
|
|
194
|
+
socketserver.TCPServer.server_bind(self)
|
|
195
|
+
self.server_name, self.server_port = self.server_address[:2]
|
|
196
|
+
|
|
197
|
+
def hosts(self):
|
|
198
|
+
"""The Host values a request may carry: this server's address, by number or as localhost."""
|
|
199
|
+
host, port = self.server_address[:2]
|
|
200
|
+
names = {host, "localhost"}
|
|
201
|
+
return {f"{name}:{port}" for name in names} | (names if port == 80 else set())
|
|
202
|
+
|
|
203
|
+
def handle_error(self, request, client_address):
|
|
204
|
+
"""A client gone, or closed for sending nothing in time, is no error worth a traceback."""
|
|
205
|
+
if isinstance(sys.exc_info()[1], (ConnectionError, socket.timeout)):
|
|
206
|
+
return
|
|
207
|
+
super().handle_error(request, client_address)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def main():
|
|
211
|
+
global CFG
|
|
212
|
+
A.utf8_streams() # what it prints is UTF-8, as every polyctl process's is (#71)
|
|
213
|
+
root = sys.argv[sys.argv.index("-C") + 1] if "-C" in sys.argv else None
|
|
214
|
+
port = int(sys.argv[sys.argv.index("--port") + 1]) if "--port" in sys.argv else 8731
|
|
215
|
+
CFG = A.load_config(A.find_root(root))
|
|
216
|
+
# Bind loopback only. This exposes project state; it is not for a network.
|
|
217
|
+
srv = _Server(("127.0.0.1", port), Handler)
|
|
218
|
+
print(f"A2A on http://127.0.0.1:{port} card: /.well-known/agent-card.json", flush=True)
|
|
219
|
+
try:
|
|
220
|
+
srv.serve_forever()
|
|
221
|
+
except KeyboardInterrupt:
|
|
222
|
+
pass
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if __name__ == "__main__":
|
|
226
|
+
main()
|