harnis 1.0.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.
- harnis/__init__.py +9 -0
- harnis/alerts.py +69 -0
- harnis/api.py +650 -0
- harnis/auth.py +313 -0
- harnis/backup.py +175 -0
- harnis/cache.py +206 -0
- harnis/cli.py +164 -0
- harnis/config.py +250 -0
- harnis/db.py +54 -0
- harnis/egress_proxy.py +221 -0
- harnis/evals.py +603 -0
- harnis/guardrails.py +153 -0
- harnis/infra.py +89 -0
- harnis/k8s_sandbox.py +726 -0
- harnis/llm/__init__.py +7 -0
- harnis/llm/pricing.py +119 -0
- harnis/llm/providers.py +505 -0
- harnis/llm/router.py +194 -0
- harnis/llm/types.py +109 -0
- harnis/maintenance.py +85 -0
- harnis/metrics.py +65 -0
- harnis/migrate.py +104 -0
- harnis/migrations/001_schema.sql +213 -0
- harnis/migrations/002_grants.sql +21 -0
- harnis/migrations/003_more_providers.sql +19 -0
- harnis/migrations/004_admin_and_api_keys.sql +119 -0
- harnis/migrations/005_provider_wildcard.sql +36 -0
- harnis/migrations/006_data_lifecycle.sql +194 -0
- harnis/migrations/__init__.py +2 -0
- harnis/orchestrator.py +519 -0
- harnis/plugins.py +267 -0
- harnis/sandbox.py +557 -0
- harnis/static/console.css +229 -0
- harnis/static/console.js +957 -0
- harnis/static/favicon.svg +1 -0
- harnis/static/index.html +19 -0
- harnis/store.py +319 -0
- harnis/telemetry.py +163 -0
- harnis/tools.py +397 -0
- harnis-1.0.0.dist-info/METADATA +402 -0
- harnis-1.0.0.dist-info/RECORD +46 -0
- harnis-1.0.0.dist-info/WHEEL +5 -0
- harnis-1.0.0.dist-info/entry_points.txt +2 -0
- harnis-1.0.0.dist-info/licenses/LICENSE +202 -0
- harnis-1.0.0.dist-info/licenses/NOTICE +10 -0
- harnis-1.0.0.dist-info/top_level.txt +1 -0
harnis/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Ahmad Karawash
|
|
3
|
+
"""Harnis: a multi-tenant agent harness."""
|
|
4
|
+
from importlib import metadata as _metadata
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
__version__ = _metadata.version("harnis")
|
|
8
|
+
except _metadata.PackageNotFoundError: # running from a source tree without installing
|
|
9
|
+
__version__ = "0.0.0+unknown"
|
harnis/alerts.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Ahmad Karawash
|
|
3
|
+
"""Incident alerts to Slack or Discord.
|
|
4
|
+
|
|
5
|
+
* Non-blocking: sends on a background thread with a short timeout.
|
|
6
|
+
* De-duplicated: the same (type, tenant) alerts at most once per window
|
|
7
|
+
(shared via Redis when available), so a loop doesn't spam the channel.
|
|
8
|
+
* Minimal data: IDs and the incident type only — never user content.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import logging
|
|
13
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
import httpx
|
|
17
|
+
|
|
18
|
+
log = logging.getLogger(__name__)
|
|
19
|
+
_executor = ThreadPoolExecutor(max_workers=2, thread_name_prefix="alerts")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def slack_payload(kind: str, tenant: str, session: str | None, detail: dict[str, Any]) -> dict[str, Any]:
|
|
23
|
+
fields = [{"type": "mrkdwn", "text": f"*Type*\n`{kind}`"},
|
|
24
|
+
{"type": "mrkdwn", "text": f"*Tenant*\n`{tenant}`"},
|
|
25
|
+
{"type": "mrkdwn", "text": f"*Session*\n`{session or '-'}`"}]
|
|
26
|
+
fields += [{"type": "mrkdwn", "text": f"*{k}*\n`{v}`"} for k, v in list(detail.items())[:4]]
|
|
27
|
+
return {"text": f"Harnis alert: {kind} ({tenant})",
|
|
28
|
+
"blocks": [{"type": "header", "text": {"type": "plain_text", "text": f"Harnis alert: {kind}"}},
|
|
29
|
+
{"type": "section", "fields": fields}]}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def discord_payload(kind: str, tenant: str, session: str | None, detail: dict[str, Any]) -> dict[str, Any]:
|
|
33
|
+
fields = [{"name": "Tenant", "value": tenant, "inline": True},
|
|
34
|
+
{"name": "Session", "value": session or "-", "inline": True}]
|
|
35
|
+
fields += [{"name": str(k), "value": str(v), "inline": True} for k, v in list(detail.items())[:4]]
|
|
36
|
+
return {"username": "Harnis",
|
|
37
|
+
"embeds": [{"title": f"Harnis alert: {kind}", "color": 0xE5484D, "fields": fields}]}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class AlertDispatcher:
|
|
41
|
+
def __init__(self, webhook_url: str = "", kind: str = "slack", redis=None, dedupe_seconds: int = 300):
|
|
42
|
+
self.url = webhook_url
|
|
43
|
+
self.kind = kind
|
|
44
|
+
self.redis = redis
|
|
45
|
+
self.dedupe = dedupe_seconds
|
|
46
|
+
self.sent: list[dict[str, Any]] = [] # recent payloads, handy in tests
|
|
47
|
+
|
|
48
|
+
def _should_send(self, key: str) -> bool:
|
|
49
|
+
if self.redis is None:
|
|
50
|
+
return True
|
|
51
|
+
return bool(self.redis.set(f"alert:dedupe:{key}", 1, nx=True, ex=self.dedupe))
|
|
52
|
+
|
|
53
|
+
def __call__(self, kind: str, tenant: str, session: str | None, detail: dict[str, Any]) -> None:
|
|
54
|
+
if not self._should_send(f"{kind}:{tenant}"):
|
|
55
|
+
return
|
|
56
|
+
build = discord_payload if self.kind == "discord" else slack_payload
|
|
57
|
+
payload = build(kind, tenant, session, detail)
|
|
58
|
+
self.sent = (self.sent + [payload])[-50:]
|
|
59
|
+
log.warning("ALERT %s tenant=%s session=%s %s", kind, tenant, session, detail)
|
|
60
|
+
if self.url:
|
|
61
|
+
_executor.submit(self._post, payload)
|
|
62
|
+
|
|
63
|
+
def _post(self, payload: dict[str, Any]) -> None:
|
|
64
|
+
try:
|
|
65
|
+
r = httpx.post(self.url, json=payload, timeout=5.0)
|
|
66
|
+
if r.status_code >= 300:
|
|
67
|
+
log.error("alert webhook returned %s", r.status_code)
|
|
68
|
+
except httpx.HTTPError as exc:
|
|
69
|
+
log.error("alert webhook failed: %s", exc)
|