cat-herdr 0.1.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.
- cat_herdr/__init__.py +1 -0
- cat_herdr/__main__.py +4 -0
- cat_herdr/adapters/claude.json +93 -0
- cat_herdr/adapters/codex.json +59 -0
- cat_herdr/adapters/opencode.js +41 -0
- cat_herdr/adapters/pi.ts +19 -0
- cat_herdr/als_alerts.py +153 -0
- cat_herdr/als_pane.py +2469 -0
- cat_herdr/als_runs.py +499 -0
- cat_herdr/als_tmux.py +143 -0
- cat_herdr/cat-herdr.1 +287 -0
- cat_herdr/claude-statusline.sh +164 -0
- cat_herdr/cli.py +341 -0
- cat_herdr/config.py +96 -0
- cat_herdr/native.py +295 -0
- cat_herdr/usage.py +155 -0
- cat_herdr-0.1.0.data/data/share/doc/cat-herdr/CONTRIBUTING.md +36 -0
- cat_herdr-0.1.0.data/data/share/doc/cat-herdr/docs/ai-configuration.md +58 -0
- cat_herdr-0.1.0.data/data/share/doc/cat-herdr/hooks/hooks.md +206 -0
- cat_herdr-0.1.0.data/data/share/man/man1/cat-herdr.1 +287 -0
- cat_herdr-0.1.0.dist-info/METADATA +269 -0
- cat_herdr-0.1.0.dist-info/RECORD +26 -0
- cat_herdr-0.1.0.dist-info/WHEEL +5 -0
- cat_herdr-0.1.0.dist-info/entry_points.txt +2 -0
- cat_herdr-0.1.0.dist-info/licenses/LICENSE +21 -0
- cat_herdr-0.1.0.dist-info/top_level.txt +1 -0
cat_herdr/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Cat Herdr: a terminal dashboard for Claude Code and Codex sessions in tmux."""
|
cat_herdr/__main__.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
9
|
+
"timeout": 3
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"UserPromptSubmit": [
|
|
15
|
+
{
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
20
|
+
"timeout": 3
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"Stop": [
|
|
26
|
+
{
|
|
27
|
+
"hooks": [
|
|
28
|
+
{
|
|
29
|
+
"type": "command",
|
|
30
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
31
|
+
"timeout": 3
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"SessionEnd": [
|
|
37
|
+
{
|
|
38
|
+
"hooks": [
|
|
39
|
+
{
|
|
40
|
+
"type": "command",
|
|
41
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
42
|
+
"timeout": 3
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"PreToolUse": [
|
|
48
|
+
{
|
|
49
|
+
"matcher": "AskUserQuestion",
|
|
50
|
+
"hooks": [
|
|
51
|
+
{
|
|
52
|
+
"type": "command",
|
|
53
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
54
|
+
"timeout": 3
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"PermissionRequest": [
|
|
60
|
+
{
|
|
61
|
+
"hooks": [
|
|
62
|
+
{
|
|
63
|
+
"type": "command",
|
|
64
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
65
|
+
"timeout": 3
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"PostToolUse": [
|
|
71
|
+
{
|
|
72
|
+
"hooks": [
|
|
73
|
+
{
|
|
74
|
+
"type": "command",
|
|
75
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
76
|
+
"timeout": 3
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"PostToolUseFailure": [
|
|
82
|
+
{
|
|
83
|
+
"hooks": [
|
|
84
|
+
{
|
|
85
|
+
"type": "command",
|
|
86
|
+
"command": "CAT_HERDR_HOOK_PID=$PPID cat-herdr hook-event claude >/dev/null 2>&1 || true",
|
|
87
|
+
"timeout": 3
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "cat-herdr hook-event codex >/dev/null 2>&1 || true",
|
|
9
|
+
"timeout": 3
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"UserPromptSubmit": [
|
|
15
|
+
{
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "cat-herdr hook-event codex >/dev/null 2>&1 || true",
|
|
20
|
+
"timeout": 3
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"Stop": [
|
|
26
|
+
{
|
|
27
|
+
"hooks": [
|
|
28
|
+
{
|
|
29
|
+
"type": "command",
|
|
30
|
+
"command": "cat-herdr hook-event codex >/dev/null 2>&1 || true",
|
|
31
|
+
"timeout": 3
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"SessionEnd": [
|
|
37
|
+
{
|
|
38
|
+
"hooks": [
|
|
39
|
+
{
|
|
40
|
+
"type": "command",
|
|
41
|
+
"command": "cat-herdr hook-event codex >/dev/null 2>&1 || true",
|
|
42
|
+
"timeout": 3
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"Interrupt": [
|
|
48
|
+
{
|
|
49
|
+
"hooks": [
|
|
50
|
+
{
|
|
51
|
+
"type": "command",
|
|
52
|
+
"command": "cat-herdr hook-event codex >/dev/null 2>&1 || true",
|
|
53
|
+
"timeout": 3
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
const watched = new Set([
|
|
5
|
+
"session.created", "session.deleted", "session.status", "session.idle",
|
|
6
|
+
"question.asked", "question.replied", "question.rejected",
|
|
7
|
+
"permission.asked", "permission.replied",
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export const CatHerdr = async () => {
|
|
11
|
+
const sessions = new Set();
|
|
12
|
+
const observer = randomUUID();
|
|
13
|
+
function send(type, properties) {
|
|
14
|
+
spawnSync("cat-herdr", ["hook-event", "opencode"], {
|
|
15
|
+
env: { ...process.env, CAT_HERDR_OBSERVER: observer },
|
|
16
|
+
input: JSON.stringify({ type, properties }),
|
|
17
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
18
|
+
timeout: 2500,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
event: async ({ event }) => {
|
|
23
|
+
if (!watched.has(event.type)) return;
|
|
24
|
+
const p = event.properties;
|
|
25
|
+
const sessionID = p.sessionID ?? p.info?.id;
|
|
26
|
+
if (!sessionID || (p.info?.id && p.sessionID && p.info.id !== p.sessionID)) return;
|
|
27
|
+
if (event.type === "session.deleted") sessions.delete(sessionID);
|
|
28
|
+
else sessions.add(sessionID);
|
|
29
|
+
send(event.type, { sessionID, id: p.id, requestID: p.requestID,
|
|
30
|
+
status: p.status && { type: p.status.type } });
|
|
31
|
+
},
|
|
32
|
+
"chat.message": async ({ sessionID }) => {
|
|
33
|
+
sessions.add(sessionID);
|
|
34
|
+
send("chat.message", { sessionID });
|
|
35
|
+
},
|
|
36
|
+
dispose: async () => {
|
|
37
|
+
for (const sessionID of sessions) send("adapter.dispose", { sessionID });
|
|
38
|
+
sessions.clear();
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
};
|
cat_herdr/adapters/pi.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
export default function catHerdr(pi: ExtensionAPI) {
|
|
5
|
+
function observe(event: { type: string; reason?: string }, ctx: ExtensionContext) {
|
|
6
|
+
if (!ctx.hasUI) return;
|
|
7
|
+
spawnSync("cat-herdr", ["hook-event", "pi"], {
|
|
8
|
+
env: { ...process.env, CAT_HERDR_HOOK_PID: String(process.pid) },
|
|
9
|
+
input: JSON.stringify({ type: event.type, reason: event.type === "session_start" ? event.reason : undefined,
|
|
10
|
+
session_id: ctx.sessionManager.getSessionId() }),
|
|
11
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
12
|
+
timeout: 2500,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
pi.on("session_start", observe);
|
|
16
|
+
pi.on("agent_start", observe);
|
|
17
|
+
pi.on("agent_end", observe);
|
|
18
|
+
pi.on("session_shutdown", observe);
|
|
19
|
+
}
|
cat_herdr/als_alerts.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Read the Autometta operator inbox and live integration requests."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
from datetime import datetime, timedelta, timezone
|
|
7
|
+
from functools import lru_cache
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
LABELS = {"verifier_failed": "verifier fail", "failed": "failed", "stalled": "stalled",
|
|
12
|
+
"halted": "halted", "awaiting": "integrate", "queue-successor": "next card"}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@lru_cache(maxsize=128)
|
|
16
|
+
def load_document(path, stamp):
|
|
17
|
+
if path.suffix == ".md":
|
|
18
|
+
with path.open(encoding="utf-8") as stream:
|
|
19
|
+
if stream.readline().strip() != "---":
|
|
20
|
+
return {}
|
|
21
|
+
fields = {}
|
|
22
|
+
for line in stream:
|
|
23
|
+
if line.strip() == "---":
|
|
24
|
+
break
|
|
25
|
+
key, sep, value = line.partition(":")
|
|
26
|
+
if sep:
|
|
27
|
+
value = value.strip()
|
|
28
|
+
fields[key] = json.loads(value) if value.startswith('"') else value
|
|
29
|
+
fields["body"] = stream.read().strip()
|
|
30
|
+
fields["summary"] = next(iter(fields["body"].splitlines()), "").strip()
|
|
31
|
+
return fields
|
|
32
|
+
if path.suffix == ".json":
|
|
33
|
+
data = json.loads(path.read_text())
|
|
34
|
+
else:
|
|
35
|
+
proc = subprocess.run(["yq", "-o=json", ".", str(path)], capture_output=True,
|
|
36
|
+
text=True, timeout=3, check=True)
|
|
37
|
+
data = json.loads(proc.stdout)
|
|
38
|
+
return data if isinstance(data, dict) else {}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def document(path):
|
|
42
|
+
try:
|
|
43
|
+
stat = path.stat()
|
|
44
|
+
return load_document(path, (stat.st_ino, stat.st_mtime_ns, stat.st_size))
|
|
45
|
+
except (OSError, ValueError, subprocess.SubprocessError):
|
|
46
|
+
return {}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def controller_home():
|
|
50
|
+
default = Path.home() / ".autometta"
|
|
51
|
+
legacy = Path.home() / ".phat-controller"
|
|
52
|
+
return Path(os.environ.get("AUTOMETTA_HOME") or os.environ.get("PHAT_CONTROLLER_HOME")
|
|
53
|
+
or (legacy if legacy.exists() and not default.exists() else default)).expanduser()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def subscribers(home, enabled_only=True):
|
|
57
|
+
for path in sorted((home / "subscribers").glob("*.yaml")):
|
|
58
|
+
if path.name == "template.yaml":
|
|
59
|
+
continue
|
|
60
|
+
config = document(path)
|
|
61
|
+
if config.get("repo_path") and (not enabled_only or config.get("enabled") is True):
|
|
62
|
+
yield Path(config["repo_path"])
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def current_alerts():
|
|
66
|
+
home = controller_home()
|
|
67
|
+
inbox = Path(os.environ.get("AUTOMETTA_ESCALATIONS") or home / "escalations") / "pending"
|
|
68
|
+
alerts = {}
|
|
69
|
+
for path in sorted(inbox.glob("*.md")):
|
|
70
|
+
entry = document(path)
|
|
71
|
+
if not entry.get("repo") or not entry.get("kind"):
|
|
72
|
+
continue
|
|
73
|
+
repo = Path(entry["repo"])
|
|
74
|
+
stage, kind = entry.get("stage", ""), entry["kind"]
|
|
75
|
+
if stage and kind in ("failed", "verifier_failed", "stalled"):
|
|
76
|
+
stages = document(repo / "state/state.yaml").get("stages")
|
|
77
|
+
if isinstance(stages, list) and not any(s.get("id") == stage and s.get("status") == kind
|
|
78
|
+
and (not entry.get("run_id") or s.get("run_id") == entry["run_id"])
|
|
79
|
+
for s in stages if isinstance(s, dict)):
|
|
80
|
+
continue
|
|
81
|
+
if kind == "halted" and document(repo / "state/budget.json").get("halted") is False:
|
|
82
|
+
continue
|
|
83
|
+
alerts[(str(repo), stage, kind, entry.get("run_id"))] = entry
|
|
84
|
+
|
|
85
|
+
for repo in subscribers(home):
|
|
86
|
+
budget = document(repo / "state/budget.json")
|
|
87
|
+
if budget.get("halted") is True:
|
|
88
|
+
key = (str(repo), "", "halted", None)
|
|
89
|
+
event = alerts.get(key, {})
|
|
90
|
+
alerts[key] = dict(event, repo=str(repo), stage="", kind="halted",
|
|
91
|
+
created=budget.get("halted_at") or event.get("created") or "",
|
|
92
|
+
summary=budget.get("halt_reason") or event.get("summary") or "")
|
|
93
|
+
stages = document(repo / "state/state.yaml").get("stages") or []
|
|
94
|
+
for stage in stages:
|
|
95
|
+
if not isinstance(stage, dict) or not stage.get("id") or stage.get("status") != "completed":
|
|
96
|
+
continue
|
|
97
|
+
integration = stage.get("integration") or {}
|
|
98
|
+
if not isinstance(integration, dict):
|
|
99
|
+
continue
|
|
100
|
+
if integration.get("state") == "awaiting":
|
|
101
|
+
kind, summary = "awaiting", "Verifier passed. Integration is waiting for a decision."
|
|
102
|
+
elif (stage is stages[-1] and stage.get("landing_action") == "queue-successor"
|
|
103
|
+
and integration.get("state") == "merged" and stage.get("run_id")
|
|
104
|
+
and not any(s.get("run_id") == stage["run_id"] and s.get("status") in ("pending", "in_progress")
|
|
105
|
+
for s in stages if isinstance(s, dict))):
|
|
106
|
+
kind, summary = "queue-successor", "Stage landed. The run is waiting for a successor card."
|
|
107
|
+
else:
|
|
108
|
+
continue
|
|
109
|
+
alerts[(str(repo), stage["id"], kind)] = dict(repo=str(repo), stage=stage["id"],
|
|
110
|
+
kind=kind, created=stage.get("completed_at") or "", summary=summary)
|
|
111
|
+
return sorted(alerts.values(), key=lambda a: (a.get("created") or "", a["repo"], a.get("stage", "")))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _notice_timestamp(entry):
|
|
115
|
+
try:
|
|
116
|
+
stamp = datetime.fromisoformat(entry["created_at"].replace("Z", "+00:00"))
|
|
117
|
+
return stamp.astimezone(timezone.utc) if stamp.tzinfo is not None else None
|
|
118
|
+
except (AttributeError, KeyError, TypeError, ValueError, OverflowError):
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _valid_notice_repo(entry, enabled):
|
|
123
|
+
repo = entry.get("repo")
|
|
124
|
+
if repo == "fleet":
|
|
125
|
+
kind = entry.get("kind")
|
|
126
|
+
return isinstance(kind, str) and kind.startswith("quota")
|
|
127
|
+
return isinstance(repo, str) and repo in enabled
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def current_notices(home=None):
|
|
131
|
+
home = home or controller_home()
|
|
132
|
+
enabled = {str(path) for path in subscribers(home)}
|
|
133
|
+
cutoff = datetime.now(timezone.utc) - timedelta(days=7)
|
|
134
|
+
best = {}
|
|
135
|
+
for path in (home / "lifecycle-events").glob("*.json"):
|
|
136
|
+
entry = document(path)
|
|
137
|
+
notice_id, kind, summary = entry.get("id"), entry.get("kind"), entry.get("summary")
|
|
138
|
+
if not isinstance(notice_id, str) or not isinstance(kind, str):
|
|
139
|
+
continue
|
|
140
|
+
if summary is not None and not isinstance(summary, str):
|
|
141
|
+
continue
|
|
142
|
+
stage = entry.get("stage")
|
|
143
|
+
if stage is not None and not isinstance(stage, str):
|
|
144
|
+
continue
|
|
145
|
+
if not _valid_notice_repo(entry, enabled):
|
|
146
|
+
continue
|
|
147
|
+
created = _notice_timestamp(entry)
|
|
148
|
+
if created is None or created < cutoff:
|
|
149
|
+
continue
|
|
150
|
+
current = best.get(notice_id)
|
|
151
|
+
if current is None or created > _notice_timestamp(current):
|
|
152
|
+
best[notice_id] = entry
|
|
153
|
+
return sorted(best.values(), key=_notice_timestamp, reverse=True)
|