@hivey/cli 0.0.0-stage → 0.9.36
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.
- package/README.md +235 -2
- package/bin/hivey.js +98 -0
- package/native/darwin-arm64/hivey +0 -0
- package/package.json +36 -4
- package/platforms.json +3 -0
- package/repo/LICENSE +201 -0
- package/repo/NOTICE +18 -0
- package/repo/README.md +148 -0
- package/repo/install.sh +365 -0
- package/repo/pets/README.md +25 -0
- package/repo/pets/hivey-dot/CLAUDE.md +55 -0
- package/repo/pets/hivey-dot/build.sh +34 -0
- package/repo/pets/hivey-dot/main.swift +750 -0
- package/repo/pets/hivey-h/CLAUDE.md +75 -0
- package/repo/pets/hivey-h/build.sh +34 -0
- package/repo/pets/hivey-h/main.swift +739 -0
- package/repo/pets/hivey-prompt/CLAUDE.md +59 -0
- package/repo/pets/hivey-prompt/build.sh +34 -0
- package/repo/pets/hivey-prompt/main.swift +691 -0
- package/repo/pets/pet.py +288 -0
- package/repo/pets/shared/HiveyWatch.swift +437 -0
- package/repo/pets/test_pet.py +122 -0
- package/repo/plugins/README.md +108 -0
- package/repo/plugins/agent-creator/herdr-plugin.toml +17 -0
- package/repo/plugins/dashboard/dashboard.py +507 -0
- package/repo/plugins/dashboard/herdr-plugin.toml +14 -0
- package/repo/plugins/dashboard/test_dashboard.py +134 -0
- package/repo/plugins/github/github.py +261 -0
- package/repo/plugins/github/herdr-plugin.toml +14 -0
- package/repo/plugins/github/test_github.py +49 -0
- package/repo/plugins/skills/herdr-plugin.toml +11 -0
- package/repo/plugins/skills/skills.md +41 -0
- package/repo/plugins/slack-relay/connect.py +198 -0
- package/repo/plugins/slack-relay/create_channel.py +134 -0
- package/repo/plugins/slack-relay/herdr-plugin.toml +15 -0
- package/repo/plugins/slack-relay/relay.py +401 -0
- package/repo/plugins/slack-relay/slack-app-manifest.json +30 -0
- package/repo/plugins/slack-relay/test_connect.py +66 -0
- package/repo/plugins/slack-relay/test_create_channel.py +61 -0
- package/repo/plugins/slack-relay/test_relay.py +254 -0
- package/repo/plugins/swarm-creator/herdr-plugin.toml +17 -0
- package/repo/plugins/swarm-watcher/dashboard.py +333 -0
- package/repo/plugins/swarm-watcher/herdr-plugin.toml +16 -0
- package/repo/plugins/swarm-watcher/usage.py +129 -0
- package/repo/plugins/swarm-watcher/watcher.py +191 -0
- package/repo/plugins/team-template/herdr-plugin.toml +15 -0
- package/repo/plugins/team-template/setup.py +211 -0
- package/repo/plugins/team-template/test_setup.py +73 -0
- package/repo/plugins/tts/herdr-plugin.toml +15 -0
- package/repo/skills/herdr/SKILL.md +214 -0
- package/repo/skills/hivey/SKILL.md +322 -0
- package/repo/skills/hivey/scripts/handoff.py +27 -0
- package/repo/skills/hivey/scripts/new_wiki.py +143 -0
- package/repo/skills/hivey-agent-creator/SKILL.md +303 -0
- package/repo/skills/hivey-agent-creator/references/agent-claude-md.md +256 -0
- package/repo/skills/hivey-agent-creator/references/global-guidelines.md +67 -0
- package/repo/skills/hivey-agent-creator/references/reviewer-agent.md +35 -0
- package/repo/skills/hivey-agent-creator/scripts/agent_context.py +76 -0
- package/repo/skills/hivey-agent-creator/scripts/agent_gate.py +78 -0
- package/repo/skills/hivey-agent-creator/scripts/setup_agent.py +288 -0
- package/repo/skills/hivey-agy/SKILL.md +123 -0
- package/repo/skills/hivey-agy/references/gemini-prompting.md +134 -0
- package/repo/skills/hivey-agy/scripts/agy_run.py +146 -0
- package/repo/skills/hivey-codex/SKILL.md +66 -0
- package/repo/skills/hivey-context7/SKILL.md +56 -0
- package/repo/skills/hivey-create-wiki/SKILL.md +329 -0
- package/repo/skills/hivey-grok/SKILL.md +101 -0
- package/repo/skills/hivey-grok/scripts/grok_run.py +139 -0
- package/repo/skills/hivey-swarm-creator/SKILL.md +384 -0
- package/repo/skills/hivey-swarm-creator/references/agent-claude-md.md +313 -0
- package/repo/skills/hivey-swarm-creator/references/archify-report.md +24 -0
- package/repo/skills/hivey-swarm-creator/references/dashboard.md +46 -0
- package/repo/skills/hivey-swarm-creator/references/retrospective.md +23 -0
- package/repo/skills/hivey-swarm-creator/references/shared-rules.md +39 -0
- package/repo/skills/hivey-swarm-creator/references/wiki-memory.md +30 -0
- package/repo/skills/hivey-swarm-creator/scripts/setup_agent.py +76 -0
- package/repo/skills/hivey-swarm-creator/scripts/shared_rules.py +50 -0
- package/repo/skills/hivey-swarm-creator/scripts/swarm_tasks.py +171 -0
- package/repo/skills/hivey-wiki-ingest/SKILL.md +45 -0
- package/repo/skills/hivey-wiki-lint/SKILL.md +38 -0
- package/repo/skills/hivey-wiki-list/SKILL.md +46 -0
- package/repo/skills/hivey-wiki-log/SKILL.md +45 -0
- package/repo/skills/hivey-wiki-query/SKILL.md +44 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""hivey.swarm-watcher: watches a swarm's workers and tells its master when one needs it.
|
|
3
|
+
|
|
4
|
+
Every --interval seconds it reads the swarm's manifest (<root>/.swarm/agents.json) and the
|
|
5
|
+
agents' states (`hivey agent list`), and sends the master a message (`hivey msg send`,
|
|
6
|
+
delivered when the master is idle) when a worker
|
|
7
|
+
- is blocked (a dialog or question waits): at once, once per episode;
|
|
8
|
+
- stopped (idle/done) for --idle-after seconds after working: it may be done, waiting on
|
|
9
|
+
someone, or have asked something in its output (the tail of its screen is included);
|
|
10
|
+
- kept working --stall-after seconds with no sign of progress (no task-board or event-log
|
|
11
|
+
change mentioning it): possibly looping or lost;
|
|
12
|
+
- is gone (its pane closed or the agent exited);
|
|
13
|
+
and when the swarm's time budget (manifest budget_minutes) reaches 80% and 100%.
|
|
14
|
+
It also rebuilds the swarm's Gantt dashboard (dashboard.py) every minute; --open shows it in
|
|
15
|
+
the browser once. Everything it reports goes to <root>/.swarm/events.jsonl too. A paused
|
|
16
|
+
swarm (`hivey swarm pause`) is left alone. Standard library only.
|
|
17
|
+
|
|
18
|
+
Usage: watcher.py <swarm_root> [--interval 10] [--idle-after 60] [--stall-after 2700] [--open]
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import json
|
|
22
|
+
import subprocess
|
|
23
|
+
import sys
|
|
24
|
+
import time
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
HERE = Path(__file__).resolve().parent
|
|
28
|
+
PREFIX = "[hivey.swarm-watcher]"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def hivey(*args):
|
|
32
|
+
"""Runs hivey with args; its stdout, or "" when it failed."""
|
|
33
|
+
try:
|
|
34
|
+
done = subprocess.run(["hivey", *args], capture_output=True, text=True, timeout=30)
|
|
35
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
36
|
+
return ""
|
|
37
|
+
return done.stdout if done.returncode == 0 else ""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def agent_states():
|
|
41
|
+
"""{hivey agent name: status}, or None when hivey could not be asked."""
|
|
42
|
+
text = hivey("agent", "list")
|
|
43
|
+
try:
|
|
44
|
+
agents = json.loads(text)["result"]["agents"]
|
|
45
|
+
except (ValueError, KeyError, TypeError):
|
|
46
|
+
return None
|
|
47
|
+
return {a.get("name"): a.get("agent_status", "unknown") for a in agents}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def screen_tail(name, lines=20):
|
|
51
|
+
text = hivey("agent", "read", name, "--source", "recent-unwrapped", "--lines", str(lines))
|
|
52
|
+
try:
|
|
53
|
+
text = json.loads(text)["result"]["read"]["text"]
|
|
54
|
+
except (ValueError, KeyError, TypeError):
|
|
55
|
+
pass
|
|
56
|
+
return "\n".join(line for line in text.splitlines() if line.strip())[-1500:]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def log_event(root, **event):
|
|
60
|
+
event.setdefault("ts", time.time())
|
|
61
|
+
event.setdefault("type", "watcher")
|
|
62
|
+
try:
|
|
63
|
+
with open(root / ".swarm" / "events.jsonl", "a") as log:
|
|
64
|
+
log.write(json.dumps(event) + "\n")
|
|
65
|
+
except OSError:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def tell_master(root, manifest, text):
|
|
70
|
+
slug = manifest.get("slug", "")
|
|
71
|
+
message = f"{PREFIX} {text}"
|
|
72
|
+
sent = hivey("msg", "send", "@role:master", message, "--swarm", slug)
|
|
73
|
+
log_event(root, what=text, delivered=bool(sent))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def activity_mark(root, key):
|
|
77
|
+
"""Something that changes when the agent makes visible progress: the task board's and the
|
|
78
|
+
event log's size and mtime, counted only for lines that mention the agent."""
|
|
79
|
+
mark = []
|
|
80
|
+
for name in ("events.jsonl", "tasks.json"):
|
|
81
|
+
path = root / ".swarm" / name
|
|
82
|
+
try:
|
|
83
|
+
text = path.read_text(errors="ignore")
|
|
84
|
+
except OSError:
|
|
85
|
+
continue
|
|
86
|
+
mark.append(sum(1 for line in text.splitlines() if key in line))
|
|
87
|
+
return tuple(mark)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def watch_once(root, manifest, seen, args):
|
|
91
|
+
states = agent_states()
|
|
92
|
+
if states is None: # hivey didn't answer: skip this pass rather than report everyone gone
|
|
93
|
+
return
|
|
94
|
+
now = time.time()
|
|
95
|
+
for key, info in (manifest.get("agents") or {}).items():
|
|
96
|
+
name = info.get("herdr_name") or f"{manifest.get('slug')}-{key}"
|
|
97
|
+
if name == manifest.get("coordinator"):
|
|
98
|
+
continue
|
|
99
|
+
status = states.get(name, "gone")
|
|
100
|
+
mark = activity_mark(root, key)
|
|
101
|
+
last = seen.setdefault(name, {"status": None, "since": now, "alerted": None,
|
|
102
|
+
"mark": mark, "progress": now, "worked": False})
|
|
103
|
+
if mark != last["mark"]:
|
|
104
|
+
last["mark"], last["progress"] = mark, now
|
|
105
|
+
if status != last["status"]:
|
|
106
|
+
last.update(status=status, since=now, alerted=None)
|
|
107
|
+
if status == "working":
|
|
108
|
+
last["worked"] = True
|
|
109
|
+
if status != "gone":
|
|
110
|
+
last["alive"] = True
|
|
111
|
+
held = now - last["since"]
|
|
112
|
+
if status == "blocked" and last["alerted"] != "blocked":
|
|
113
|
+
tell_master(root, manifest, f"{key} is blocked (a dialog or question is waiting). "
|
|
114
|
+
f"Read it: hivey agent read {name} --source visible\n{screen_tail(name, 15)}")
|
|
115
|
+
last["alerted"] = "blocked"
|
|
116
|
+
elif status in ("idle", "done") and last["worked"] and held >= args.idle_after \
|
|
117
|
+
and last["alerted"] != "stopped":
|
|
118
|
+
tell_master(root, manifest, f"{key} stopped ({status}) {int(held)}s ago: it may be done, "
|
|
119
|
+
f"waiting on someone, or have asked something. Its last output:\n"
|
|
120
|
+
f"{screen_tail(name)}")
|
|
121
|
+
last["alerted"] = "stopped"
|
|
122
|
+
elif status == "working" and now - last["progress"] >= args.stall_after \
|
|
123
|
+
and last["alerted"] != "stalled":
|
|
124
|
+
minutes = int((now - last["progress"]) / 60)
|
|
125
|
+
tell_master(root, manifest, f"{key} has been working {minutes} min with no task-board "
|
|
126
|
+
f"or event-log progress: it may be looping or lost. "
|
|
127
|
+
f"Read it: hivey agent read {name} --source recent-unwrapped --lines 120")
|
|
128
|
+
last["alerted"] = "stalled"
|
|
129
|
+
last["progress"] = now # remind again after another stall-after
|
|
130
|
+
# Only an agent seen alive can be "gone" (not a swarm that isn't running, nor one starting).
|
|
131
|
+
elif status == "gone" and last.get("alive") and last["alerted"] != "gone":
|
|
132
|
+
tell_master(root, manifest, f"{key} is gone (its pane closed or the agent exited). "
|
|
133
|
+
f"Restart it with: hivey swarm relaunch {manifest.get('slug')} {key}")
|
|
134
|
+
last["alerted"] = "gone"
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def budget_check(root, manifest, sent):
|
|
138
|
+
minutes = manifest.get("budget_minutes")
|
|
139
|
+
start = manifest.get("first_launched_at") or manifest.get("launched_at")
|
|
140
|
+
if not minutes or not start:
|
|
141
|
+
return
|
|
142
|
+
used = (time.time() - float(start)) / 60 / float(minutes)
|
|
143
|
+
for mark in (0.8, 1.0):
|
|
144
|
+
if used >= mark and mark not in sent:
|
|
145
|
+
sent.add(mark)
|
|
146
|
+
tell_master(root, manifest, f"time budget {int(mark * 100)}% used "
|
|
147
|
+
f"({int(used * float(minutes))} of {minutes} min). "
|
|
148
|
+
+ ("Wrap up: get final reports, then the final summary." if mark >= 1
|
|
149
|
+
else "Plan the remaining work to fit."))
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def rebuild_dashboard(root, open_it):
|
|
153
|
+
command = [sys.executable, str(HERE / "dashboard.py"), str(root)]
|
|
154
|
+
if open_it:
|
|
155
|
+
command.append("--open")
|
|
156
|
+
try:
|
|
157
|
+
subprocess.run(command, capture_output=True, timeout=60)
|
|
158
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def main():
|
|
163
|
+
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
|
|
164
|
+
parser.add_argument("root", help="the swarm's folder (with .swarm/agents.json)")
|
|
165
|
+
parser.add_argument("--interval", type=float, default=10)
|
|
166
|
+
parser.add_argument("--idle-after", type=float, default=60)
|
|
167
|
+
parser.add_argument("--stall-after", type=float, default=2700)
|
|
168
|
+
parser.add_argument("--open", action="store_true", help="open the dashboard once at start")
|
|
169
|
+
parser.add_argument("--once", action="store_true", help="one pass, then exit (tests)")
|
|
170
|
+
args = parser.parse_args()
|
|
171
|
+
root = Path(args.root).expanduser().resolve()
|
|
172
|
+
seen, budget_sent, last_dashboard, first = {}, set(), 0.0, True
|
|
173
|
+
print(f"hivey.swarm-watcher: watching {root} (every {args.interval:g}s)", flush=True)
|
|
174
|
+
while True:
|
|
175
|
+
try:
|
|
176
|
+
manifest = json.loads((root / ".swarm" / "agents.json").read_text())
|
|
177
|
+
except (OSError, ValueError):
|
|
178
|
+
manifest = None
|
|
179
|
+
if manifest and manifest.get("state") != "paused":
|
|
180
|
+
watch_once(root, manifest, seen, args)
|
|
181
|
+
budget_check(root, manifest, budget_sent)
|
|
182
|
+
if time.time() - last_dashboard >= 60:
|
|
183
|
+
rebuild_dashboard(root, args.open and first)
|
|
184
|
+
last_dashboard, first = time.time(), False
|
|
185
|
+
if args.once:
|
|
186
|
+
return 0
|
|
187
|
+
time.sleep(args.interval)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
if __name__ == "__main__":
|
|
191
|
+
sys.exit(main())
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
id = "hivey.team-template"
|
|
2
|
+
name = "Team template"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
min_herdr_version = "0.9.0"
|
|
5
|
+
description = "Example setup provider: a fixed builder + critic team (copy it to write your own)"
|
|
6
|
+
platforms = ["linux", "macos"]
|
|
7
|
+
|
|
8
|
+
# A setup provider is any plugin with a pane entrypoint "setup".
|
|
9
|
+
# `hivey swarm new --provider hivey.team-template "<task>"` opens it with HIVEY_SETUP_TASK
|
|
10
|
+
# and HIVEY_SETUP_CWD set, in the folder you ran the command from.
|
|
11
|
+
[[panes]]
|
|
12
|
+
id = "setup"
|
|
13
|
+
title = "team template"
|
|
14
|
+
placement = "tab"
|
|
15
|
+
command = ["sh", "-c", "exec python3 \"$HERDR_PLUGIN_ROOT/setup.py\""]
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""hivey.team-template: the smallest useful swarm setup provider (an example to copy).
|
|
3
|
+
|
|
4
|
+
What every setup provider does, in four steps:
|
|
5
|
+
1. DESIGN decide the team for the task (here: a fixed builder + critic)
|
|
6
|
+
2. BRIEF write each agent's brief to <root>/<agent>/CLAUDE.md
|
|
7
|
+
3. LAUNCH run `hivey swarm launch …` (space, panes, addons, schedules)
|
|
8
|
+
4. MASTER turn this pane into the master (here: a Claude coordinator)
|
|
9
|
+
|
|
10
|
+
hivey opens this pane for `hivey swarm new --provider hivey.team-template "<task>"` with
|
|
11
|
+
HIVEY_SETUP_TASK and HIVEY_SETUP_CWD set. Settings (all optional) in
|
|
12
|
+
$HERDR_PLUGIN_CONFIG_DIR/config.json:
|
|
13
|
+
{"model": "sonnet", "master_model": "opus", "heartbeat": "30m",
|
|
14
|
+
"addons": ["hivey.dashboard"], "claude_args": "--dangerously-skip-permissions",
|
|
15
|
+
"slack": "ask", "wiki": "ask"}
|
|
16
|
+
slack: "ask" (when Slack is connected: offer a channel #<slug>), true, or false.
|
|
17
|
+
wiki: "ask" (offer an Obsidian wiki vault, <root>/<slug>-wiki, as the team's memory), true,
|
|
18
|
+
or false.
|
|
19
|
+
"""
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import shlex
|
|
24
|
+
import subprocess
|
|
25
|
+
import sys
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
DEFAULTS = {
|
|
29
|
+
"model": "sonnet",
|
|
30
|
+
"master_model": "opus",
|
|
31
|
+
"heartbeat": "30m",
|
|
32
|
+
"addons": ["hivey.dashboard"],
|
|
33
|
+
"claude_args": "--dangerously-skip-permissions",
|
|
34
|
+
"slack": "ask",
|
|
35
|
+
"wiki": "ask",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# --- 1. DESIGN ------------------------------------------------------------------
|
|
39
|
+
TEAM = {
|
|
40
|
+
"builder": "Build what the task asks for in {root}/app. Commit small steps. When a piece "
|
|
41
|
+
"works, tell the critic: hivey msg send critic \"DONE <what> → <path>\".",
|
|
42
|
+
"critic": "Review everything the builder marks DONE: correctness, tests, clarity. Send "
|
|
43
|
+
"concrete fixes to the builder; when it's good, tell the coordinator APPROVED.",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
BRIEF = """# {agent} — swarm "{slug}"
|
|
47
|
+
|
|
48
|
+
**Task of the swarm:** {task}
|
|
49
|
+
|
|
50
|
+
## Your job
|
|
51
|
+
{job}
|
|
52
|
+
|
|
53
|
+
## Team
|
|
54
|
+
- `coordinator` (master): plans, answers questions, reports to the user
|
|
55
|
+
- `builder`: builds the product in `{root}/app`
|
|
56
|
+
- `critic`: reviews the builder's work
|
|
57
|
+
|
|
58
|
+
## Talking to teammates (hivey)
|
|
59
|
+
- `hivey msg send <agent> "<msg>"`: delivered when they're idle
|
|
60
|
+
- `hivey msg send <agent> --fyi "<msg>"`: acknowledgements and status, never wakes anyone
|
|
61
|
+
- `hivey msg inbox`: messages waiting for you
|
|
62
|
+
Ask when something is unclear; don't guess.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
MASTER = """You are the coordinator (master) of the swarm "{slug}" in {root}.
|
|
66
|
+
Task: {task}
|
|
67
|
+
Team: builder (builds in {root}/app), critic (reviews). They are running now.
|
|
68
|
+
Plan the work, send each agent its first assignment with `hivey msg send <agent> "…"`,
|
|
69
|
+
answer their questions, and report progress to the user. `hivey swarm list` shows the team;
|
|
70
|
+
`hivey msg log` shows the conversation. The user may also write from Slack: those messages
|
|
71
|
+
arrive from `human`; answer them with `hivey msg send human "…"`. If you need a Slack channel,
|
|
72
|
+
use `hivey slack add {slug}`: it creates #{slug} and invites the user at once."""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def slugify(task):
|
|
76
|
+
words = re.sub(r"[^a-z0-9]+", "-", task.lower()).strip("-").split("-")
|
|
77
|
+
slug = "-".join(w for w in words if w)[:18].strip("-")
|
|
78
|
+
return slug or "swarm"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
NAME_RE = re.compile(r"^[a-z][a-z0-9-]{0,31}$")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def ask_name(task):
|
|
85
|
+
"""The swarm's name, asked with a suggestion from the task. One name for everything: the
|
|
86
|
+
swarm slug, its folder swarm-<name> and its Slack channel #<name>."""
|
|
87
|
+
suggestion = slugify(task)
|
|
88
|
+
while True:
|
|
89
|
+
answer = input(f"Name (swarm, Slack channel #name) "
|
|
90
|
+
f"[{suggestion}]: ").strip()
|
|
91
|
+
name = re.sub(r"[^a-z0-9]+", "-", answer.lower()).strip("-") if answer else suggestion
|
|
92
|
+
if NAME_RE.match(name):
|
|
93
|
+
return name
|
|
94
|
+
print(" a-z, 0-9 and -, starting with a letter, at most 32 characters")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def config():
|
|
98
|
+
path = Path(os.environ.get("HERDR_PLUGIN_CONFIG_DIR", ".")) / "config.json"
|
|
99
|
+
try:
|
|
100
|
+
return {**DEFAULTS, **json.loads(path.read_text())}
|
|
101
|
+
except (OSError, json.JSONDecodeError):
|
|
102
|
+
return dict(DEFAULTS)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def new_wiki_script():
|
|
106
|
+
"""The hivey skill's new_wiki.py: next to this plugin in the repo, else installed."""
|
|
107
|
+
here = Path(__file__).resolve().parents[2] / "skills" / "hivey" / "scripts" / "new_wiki.py"
|
|
108
|
+
installed = Path.home() / ".claude" / "skills" / "hivey" / "scripts" / "new_wiki.py"
|
|
109
|
+
return next((p for p in (here, installed) if p.is_file()), None)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def want_wiki(cfg):
|
|
113
|
+
"""Whether the team gets an Obsidian wiki vault (in its own folder) as memory."""
|
|
114
|
+
if cfg["wiki"] is False or new_wiki_script() is None:
|
|
115
|
+
return False
|
|
116
|
+
if cfg["wiki"] is True:
|
|
117
|
+
return True
|
|
118
|
+
return input("Give it an Obsidian wiki as memory (a vault in its own folder, where the "
|
|
119
|
+
"team keeps what it learns)? [Y/n] ").strip().lower() not in ("n", "no")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def make_wiki(slug, task, root, agent_dirs):
|
|
123
|
+
"""Creates (or reuses) <root>/<slug>-wiki and links every agent's CLAUDE.md to it; its path."""
|
|
124
|
+
cmd = [sys.executable, str(new_wiki_script()), slug, "--root", str(root), "--about", task[:80]]
|
|
125
|
+
for agent_dir in agent_dirs:
|
|
126
|
+
cmd += ["--agent", str(agent_dir)]
|
|
127
|
+
done = subprocess.run(cmd, capture_output=True, text=True)
|
|
128
|
+
try:
|
|
129
|
+
return json.loads(done.stdout)["path"]
|
|
130
|
+
except (ValueError, KeyError):
|
|
131
|
+
sys.stderr.write(done.stderr or "could not create the wiki\n")
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def want_slack(cfg, hivey, slug):
|
|
136
|
+
"""Whether the swarm gets its own Slack channel #<slug> (`hivey swarm launch --slack`)."""
|
|
137
|
+
if cfg["slack"] is False:
|
|
138
|
+
return False
|
|
139
|
+
if subprocess.run([hivey, "slack", "status"], capture_output=True).returncode != 0:
|
|
140
|
+
print(f"Slack is not connected, so no channel (later: hivey slack connect, "
|
|
141
|
+
f"then hivey slack add {slug})")
|
|
142
|
+
return False
|
|
143
|
+
if cfg["slack"] is True:
|
|
144
|
+
return True
|
|
145
|
+
return input(f"Give it a Slack channel #{slug}, to talk to it from Slack? [Y/n] "
|
|
146
|
+
).strip().lower() not in ("n", "no")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def main():
|
|
150
|
+
cfg = config()
|
|
151
|
+
hivey = os.environ.get("HERDR_BIN_PATH", "hivey")
|
|
152
|
+
task = os.environ.get("HIVEY_SETUP_TASK", "").strip() or input("What should the swarm do? ").strip()
|
|
153
|
+
if not task:
|
|
154
|
+
sys.exit("no task")
|
|
155
|
+
slug = ask_name(task)
|
|
156
|
+
root = Path(os.environ.get("HIVEY_SETUP_CWD") or os.getcwd()) / f"swarm-{slug}"
|
|
157
|
+
|
|
158
|
+
print(f"hivey team template\n\n name {slug}\n task {task}\n root {root}")
|
|
159
|
+
print(f" team coordinator ({cfg['master_model']}) · builder ({cfg['model']}) · critic ({cfg['model']})")
|
|
160
|
+
print(f" addons {', '.join(cfg['addons']) or 'none'} · heartbeat {cfg['heartbeat'] or 'none'}\n")
|
|
161
|
+
if input("Launch this swarm? [Y/n] ").strip().lower() in ("n", "no"):
|
|
162
|
+
sys.exit("cancelled")
|
|
163
|
+
slack = want_slack(cfg, hivey, slug)
|
|
164
|
+
wiki = want_wiki(cfg)
|
|
165
|
+
|
|
166
|
+
# --- 2. BRIEF -----------------------------------------------------------------
|
|
167
|
+
(root / "app").mkdir(parents=True, exist_ok=True)
|
|
168
|
+
for agent, job in TEAM.items():
|
|
169
|
+
(root / agent).mkdir(exist_ok=True)
|
|
170
|
+
(root / agent / "CLAUDE.md").write_text(
|
|
171
|
+
BRIEF.format(agent=agent, slug=slug, task=task, root=root, job=job.format(root=root)))
|
|
172
|
+
wiki = make_wiki(slug, task, root, [root / agent for agent in TEAM]) if wiki else None
|
|
173
|
+
if wiki:
|
|
174
|
+
print(f"wiki memory: {wiki}")
|
|
175
|
+
|
|
176
|
+
# --- 3. LAUNCH ----------------------------------------------------------------
|
|
177
|
+
cmd = [hivey, "swarm", "launch", str(root), "--slug", slug, *TEAM,
|
|
178
|
+
"--models", ",".join(f"{a}={cfg['model']}" for a in TEAM),
|
|
179
|
+
"--claude-args", cfg["claude_args"]]
|
|
180
|
+
for addon in cfg["addons"]:
|
|
181
|
+
cmd += ["--addon", addon]
|
|
182
|
+
if cfg["heartbeat"]:
|
|
183
|
+
cmd += ["--heartbeat", cfg["heartbeat"]]
|
|
184
|
+
if slack:
|
|
185
|
+
cmd += ["--slack"]
|
|
186
|
+
launched = subprocess.run(cmd, capture_output=True, text=True)
|
|
187
|
+
sys.stderr.write(launched.stderr)
|
|
188
|
+
if launched.returncode != 0:
|
|
189
|
+
sys.exit(f"launch failed ({launched.returncode})")
|
|
190
|
+
# Facts for hivey's hover card / `hivey swarm info`.
|
|
191
|
+
manifest_path = root / ".swarm" / "agents.json"
|
|
192
|
+
manifest = json.loads(manifest_path.read_text())
|
|
193
|
+
manifest["info"] = {"setup": "hivey.team-template", "task": task[:70]}
|
|
194
|
+
manifest_path.write_text(json.dumps(manifest, indent=2) + "\n")
|
|
195
|
+
|
|
196
|
+
# --- 4. MASTER ----------------------------------------------------------------
|
|
197
|
+
# Launch moved this pane into the swarm's space as pane 1; it becomes the coordinator.
|
|
198
|
+
# Claude asks to trust the new folder first: let hivey answer that in the background.
|
|
199
|
+
pane = os.environ.get("HERDR_PANE_ID", "")
|
|
200
|
+
subprocess.Popen([hivey, "swarm", "accept-trust", "--pane", pane, "--kind", "claude"],
|
|
201
|
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
|
202
|
+
os.chdir(root)
|
|
203
|
+
args = ["claude", *shlex.split(cfg["claude_args"]), "--model", cfg["master_model"],
|
|
204
|
+
MASTER.format(slug=slug, root=root, task=task)
|
|
205
|
+
+ (f"\nThe team's memory is the Obsidian wiki {wiki} (rules in its CLAUDE.md): "
|
|
206
|
+
"read it before planning and keep it updated." if wiki else "")]
|
|
207
|
+
os.execvp("claude", args)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
if __name__ == "__main__":
|
|
211
|
+
main()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Tests for the example provider: python3 -m unittest plugins/team-template/test_setup.py"""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
10
|
+
import setup # noqa: E402
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TemplateTests(unittest.TestCase):
|
|
14
|
+
def test_slug_is_short_and_safe(self):
|
|
15
|
+
self.assertEqual(setup.slugify("Build a TODO app, quickly!"), "build-a-todo-app-q")
|
|
16
|
+
self.assertEqual(setup.slugify("¿?"), "swarm")
|
|
17
|
+
self.assertLessEqual(len(setup.slugify("x" * 50)), 18)
|
|
18
|
+
|
|
19
|
+
def test_name_is_asked_with_a_suggestion_and_normalized(self):
|
|
20
|
+
from unittest import mock
|
|
21
|
+
cases = [([""], "build-a-todo-app-q"), (["Digital Marketer"], "digital-marketer"),
|
|
22
|
+
(["9lives", "x" * 40, "ok"], "ok")]
|
|
23
|
+
for answers, expected in cases:
|
|
24
|
+
replies = iter(answers)
|
|
25
|
+
with mock.patch("builtins.input", lambda *_: next(replies)), \
|
|
26
|
+
mock.patch("builtins.print"):
|
|
27
|
+
self.assertEqual(setup.ask_name("Build a TODO app, quickly!"), expected)
|
|
28
|
+
|
|
29
|
+
def test_config_overrides_defaults(self):
|
|
30
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
31
|
+
Path(tmp, "config.json").write_text(json.dumps({"model": "haiku", "heartbeat": ""}))
|
|
32
|
+
os.environ["HERDR_PLUGIN_CONFIG_DIR"] = tmp
|
|
33
|
+
try:
|
|
34
|
+
cfg = setup.config()
|
|
35
|
+
finally:
|
|
36
|
+
del os.environ["HERDR_PLUGIN_CONFIG_DIR"]
|
|
37
|
+
self.assertEqual(cfg["model"], "haiku")
|
|
38
|
+
self.assertEqual(cfg["heartbeat"], "")
|
|
39
|
+
self.assertEqual(cfg["master_model"], "opus")
|
|
40
|
+
|
|
41
|
+
def test_wiki_is_asked_without_asking_for_a_folder(self):
|
|
42
|
+
from unittest import mock
|
|
43
|
+
cases = [("ask", "n", False), ("ask", "", True), (True, None, True), (False, None, False)]
|
|
44
|
+
for mode, answer, expected in cases:
|
|
45
|
+
with mock.patch("builtins.input", lambda *_: answer):
|
|
46
|
+
self.assertEqual(setup.want_wiki({"wiki": mode}), expected)
|
|
47
|
+
|
|
48
|
+
def test_make_wiki_puts_the_vault_in_the_swarm_folder(self):
|
|
49
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
50
|
+
root = Path(tmp).resolve() / "swarm-demo"
|
|
51
|
+
agents = [root / name for name in ("builder", "critic")]
|
|
52
|
+
for agent in agents:
|
|
53
|
+
agent.mkdir(parents=True)
|
|
54
|
+
(agent / "CLAUDE.md").write_text(f"# {agent.name}\n")
|
|
55
|
+
from unittest import mock
|
|
56
|
+
with mock.patch.dict(os.environ, {"HOME": tmp}):
|
|
57
|
+
path = setup.make_wiki("demo", "a task", root, agents)
|
|
58
|
+
self.assertEqual(path, str(root / "demo-wiki"))
|
|
59
|
+
self.assertTrue(Path(path, "index.md").is_file())
|
|
60
|
+
self.assertTrue(Path(path, ".obsidian").is_dir())
|
|
61
|
+
for agent in agents:
|
|
62
|
+
# relative, so the folder can be moved or shared as a whole
|
|
63
|
+
self.assertIn("`../demo-wiki`", (agent / "CLAUDE.md").read_text())
|
|
64
|
+
|
|
65
|
+
def test_briefs_name_the_team_and_hivey_messaging(self):
|
|
66
|
+
brief = setup.BRIEF.format(agent="critic", slug="s", task="t", root="/r",
|
|
67
|
+
job=setup.TEAM["critic"].format(root="/r"))
|
|
68
|
+
self.assertIn("hivey msg send", brief)
|
|
69
|
+
self.assertIn("`builder`", brief)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
unittest.main()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
id = "hivey.tts"
|
|
2
|
+
name = "Local voices (tts)"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
min_herdr_version = "0.9.0"
|
|
5
|
+
description = "Optional: installs the local tts tool (Kokoro voices, macOS on Apple Silicon, ~3 GB of models) so hivey speaks agents' summaries with it; nothing is installed until you open it"
|
|
6
|
+
platforms = ["macos"]
|
|
7
|
+
|
|
8
|
+
# Opened by settings → voice when a tts voice is picked and tts isn't installed, or by
|
|
9
|
+
# `hivey plugin pane open --plugin hivey.tts --entrypoint install`. It runs
|
|
10
|
+
# `hivey voice install` (https://github.com/jcsancho/hivey-tts) in this tab.
|
|
11
|
+
[[panes]]
|
|
12
|
+
id = "install"
|
|
13
|
+
title = "install local voices"
|
|
14
|
+
placement = "tab"
|
|
15
|
+
command = ["sh", "-c", "hivey voice install; echo; printf 'Press Enter to close this tab. '; read _"]
|