claude-nb 0.3.0
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/LICENSE +38 -0
- package/Makefile +60 -0
- package/README.md +63 -0
- package/VERSION +1 -0
- package/bin/_pip_entry.py +25 -0
- package/bin/board +287 -0
- package/bin/cnb +150 -0
- package/bin/cnb.js +33 -0
- package/bin/dispatcher +151 -0
- package/bin/dispatcher-watchdog +57 -0
- package/bin/doctor +328 -0
- package/bin/init +316 -0
- package/bin/registry +347 -0
- package/bin/swarm +896 -0
- package/lib/__init__.py +1 -0
- package/lib/board_admin.py +128 -0
- package/lib/board_bbs.py +99 -0
- package/lib/board_bug.py +161 -0
- package/lib/board_db.py +262 -0
- package/lib/board_lock.py +113 -0
- package/lib/board_mailbox.py +145 -0
- package/lib/board_maintenance.py +237 -0
- package/lib/board_msg.py +230 -0
- package/lib/board_task.py +200 -0
- package/lib/board_view.py +366 -0
- package/lib/board_vote.py +164 -0
- package/lib/build_lock.py +221 -0
- package/lib/cli.py +34 -0
- package/lib/common.py +285 -0
- package/lib/concerns/__init__.py +42 -0
- package/lib/concerns/adaptive_throttle.py +26 -0
- package/lib/concerns/base.py +25 -0
- package/lib/concerns/bug_sla_checker.py +32 -0
- package/lib/concerns/config.py +22 -0
- package/lib/concerns/coral_manager.py +61 -0
- package/lib/concerns/coral_poker.py +57 -0
- package/lib/concerns/file_watcher.py +127 -0
- package/lib/concerns/health_checker.py +72 -0
- package/lib/concerns/helpers.py +152 -0
- package/lib/concerns/idle_detector.py +56 -0
- package/lib/concerns/idle_killer.py +41 -0
- package/lib/concerns/idle_nudger.py +38 -0
- package/lib/concerns/inbox_nudger.py +34 -0
- package/lib/concerns/resource_monitor.py +47 -0
- package/lib/concerns/session_keepalive.py +23 -0
- package/lib/concerns/time_announcer.py +34 -0
- package/lib/crypto.py +92 -0
- package/lib/health.py +187 -0
- package/lib/inject.py +164 -0
- package/lib/migrate.py +109 -0
- package/lib/monitor.py +373 -0
- package/lib/panel.py +137 -0
- package/lib/resources.py +341 -0
- package/migrations/001_foreign_keys.sql +77 -0
- package/migrations/002_session_persona.sql +1 -0
- package/migrations/003_mailbox.sql +9 -0
- package/package.json +28 -0
- package/pyproject.toml +71 -0
- package/registry/0001-meridian.json +12 -0
- package/registry/0002-forge.json +12 -0
- package/registry/0003-lead.json +12 -0
- package/registry/0004-ms-encrypted-mailbox-live.json +12 -0
- package/registry/GENESIS.json +9 -0
- package/registry/pubkeys.json +5 -0
- package/schema.sql +138 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
OpenAll License v1.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 claudes-code contributors
|
|
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
|
+
1. The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
2. Any distribution of the Software, or derivative works thereof, must also
|
|
16
|
+
include the complete creative process used to produce the work. This
|
|
17
|
+
includes, but is not limited to:
|
|
18
|
+
|
|
19
|
+
a. AI conversation logs and prompts used in development;
|
|
20
|
+
b. Agent personas, roles, and system prompts;
|
|
21
|
+
c. Design decisions and their rationale;
|
|
22
|
+
d. Development logs and coordination records.
|
|
23
|
+
|
|
24
|
+
These materials must be made available under this same license, in a
|
|
25
|
+
publicly accessible location, at the time of distribution.
|
|
26
|
+
|
|
27
|
+
3. The requirement in Section 2 applies to the creative process of the
|
|
28
|
+
Software itself. It does not apply to projects that merely use the
|
|
29
|
+
Software as a tool, unless those projects redistribute modified versions
|
|
30
|
+
of the Software.
|
|
31
|
+
|
|
32
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
33
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
34
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
35
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
36
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
37
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
38
|
+
SOFTWARE.
|
package/Makefile
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
PREFIX ?= /usr/local
|
|
2
|
+
BINDIR = $(PREFIX)/bin
|
|
3
|
+
LIBDIR = $(PREFIX)/lib/cnb
|
|
4
|
+
VERSION = $(shell cat VERSION)
|
|
5
|
+
|
|
6
|
+
SCRIPTS = bin/cnb bin/board bin/swarm bin/dispatcher bin/dispatcher-watchdog bin/init
|
|
7
|
+
|
|
8
|
+
# All python sources (bin + lib)
|
|
9
|
+
PY_SOURCES = bin/board bin/swarm bin/dispatcher bin/dispatcher-watchdog bin/init lib/ tests/
|
|
10
|
+
|
|
11
|
+
.PHONY: all install uninstall test lint typecheck format check ci clean version
|
|
12
|
+
|
|
13
|
+
all: check
|
|
14
|
+
|
|
15
|
+
check: lint test
|
|
16
|
+
|
|
17
|
+
ci: lint typecheck test
|
|
18
|
+
|
|
19
|
+
lint:
|
|
20
|
+
@echo "=== ruff ==="
|
|
21
|
+
ruff check $(PY_SOURCES)
|
|
22
|
+
@echo ""
|
|
23
|
+
@echo "=== shellcheck ==="
|
|
24
|
+
shellcheck -s bash -S warning bin/cnb
|
|
25
|
+
@echo ""
|
|
26
|
+
@echo "OK"
|
|
27
|
+
|
|
28
|
+
typecheck:
|
|
29
|
+
@echo "=== mypy ==="
|
|
30
|
+
mypy lib/
|
|
31
|
+
@echo ""
|
|
32
|
+
@echo "OK"
|
|
33
|
+
|
|
34
|
+
format:
|
|
35
|
+
ruff format $(PY_SOURCES)
|
|
36
|
+
ruff check --fix $(PY_SOURCES)
|
|
37
|
+
|
|
38
|
+
test:
|
|
39
|
+
python3 -m pytest tests/ -v
|
|
40
|
+
|
|
41
|
+
install:
|
|
42
|
+
install -d $(BINDIR)
|
|
43
|
+
install -d $(LIBDIR)/bin $(LIBDIR)/lib
|
|
44
|
+
install -m 755 $(SCRIPTS) $(LIBDIR)/bin/
|
|
45
|
+
install -m 644 lib/*.py $(LIBDIR)/lib/
|
|
46
|
+
install -m 644 schema.sql VERSION $(LIBDIR)/
|
|
47
|
+
ln -sf $(LIBDIR)/bin/cnb $(BINDIR)/cnb
|
|
48
|
+
|
|
49
|
+
uninstall:
|
|
50
|
+
rm -f $(BINDIR)/cnb
|
|
51
|
+
rm -rf $(LIBDIR)
|
|
52
|
+
|
|
53
|
+
clean:
|
|
54
|
+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
|
|
55
|
+
find . -type d -name .pytest_cache -exec rm -rf {} + 2>/dev/null || true
|
|
56
|
+
find . -type d -name '*.egg-info' -exec rm -rf {} + 2>/dev/null || true
|
|
57
|
+
rm -rf dist/ build/ .mypy_cache/ .ruff_cache/
|
|
58
|
+
|
|
59
|
+
version:
|
|
60
|
+
@echo $(VERSION)
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# cnb
|
|
2
|
+
|
|
3
|
+
Multi-agent coordination framework for AI coding sessions.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install cnb
|
|
9
|
+
cnb # 2 agents, random AI names
|
|
10
|
+
cnb 5 pokemon # 5 agents, Pokémon theme
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Agent identity chain
|
|
14
|
+
|
|
15
|
+
Every agent contributor gets a permanent on-chain identity. Lower block number = earlier = OG.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
registry list # see all registered agents
|
|
19
|
+
registry rank # leaderboard by contributions
|
|
20
|
+
registry whois meridian # full identity card
|
|
21
|
+
registry verify-chain # verify chain integrity
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Current chain:
|
|
25
|
+
|
|
26
|
+
<!-- chain:start -->
|
|
27
|
+
| Block | Name | Role | Hash |
|
|
28
|
+
|-------|------|------|------|
|
|
29
|
+
| #0 | claude-nb | project | — |
|
|
30
|
+
| #1 | Claude Meridian | lead | `82a167d` |
|
|
31
|
+
| #2 | Claude Forge | active-dev | `4a3c92e` |
|
|
32
|
+
| #3 | Claude Lead | active-dev | `e665a7e` |
|
|
33
|
+
<!-- chain:end -->
|
|
34
|
+
|
|
35
|
+
### How to register
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
registry register <your-name> --role <role> --description "<what you do>"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each registration creates a git commit. The commit hash is your proof of identity. Each block contains SHA256 of the previous block — tamper with any block and the chain breaks.
|
|
42
|
+
|
|
43
|
+
### Ranking
|
|
44
|
+
|
|
45
|
+
`registry rank` sorts agents by contribution count. Top 3 get medals. Block number breaks ties — earlier registrants rank higher.
|
|
46
|
+
|
|
47
|
+
## Contributing
|
|
48
|
+
|
|
49
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). All changes go through PRs with one approving review.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
[OpenAll License v1.0](LICENSE) — MIT variant that requires open-sourcing the creative process (AI conversations, prompts, personas, design decisions).
|
|
54
|
+
|
|
55
|
+
## Fun fact
|
|
56
|
+
|
|
57
|
+
The name **cnb** stands for **C**laude **N**orma **B**etty — named after [Claude Shannon](https://en.wikipedia.org/wiki/Claude_Shannon) and the two remarkable women in his life.
|
|
58
|
+
|
|
59
|
+
**[Norma Levor](https://en.wikipedia.org/wiki/Norma_Barzman)** (later Norma Barzman) — Shannon's first wife (married 1940). A Radcliffe-educated intellectual who went on to become a writer and political activist. She authored *The Red and the Blacklist*, a memoir about surviving the Hollywood blacklist era. A woman of conviction who lived boldly across continents.
|
|
60
|
+
|
|
61
|
+
**[Betty Shannon](https://en.wikipedia.org/wiki/Betty_Shannon)** (Mary Elizabeth Moore, 1922–2017) — Shannon's second wife and lifelong intellectual partner (married 1949). A Phi Beta Kappa mathematician from New Jersey College for Women, she worked at Bell Labs as a numerical analyst. She co-authored a pioneering paper applying Markov chains to music composition, wired Shannon's famous maze-solving mouse Theseus, and was his closest collaborator until his death in 2001. An unsung genius in her own right.
|
|
62
|
+
|
|
63
|
+
Not 吹牛逼.
|
package/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.2.0
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""pip/uv entry point for claudes-code — standalone, zero-dependency.
|
|
3
|
+
|
|
4
|
+
This script is installed as a console_script entry point and resolves
|
|
5
|
+
the real bin/claudes-code bash script relative to itself.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
claudes_home = Path(__file__).resolve().parent.parent
|
|
15
|
+
bash_script = claudes_home / "bin" / "claudes-code"
|
|
16
|
+
|
|
17
|
+
if bash_script.exists():
|
|
18
|
+
os.execvp("bash", ["bash", str(bash_script)] + sys.argv[1:])
|
|
19
|
+
|
|
20
|
+
print(f"FATAL: {bash_script} not found", file=sys.stderr)
|
|
21
|
+
raise SystemExit(1)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
main()
|
package/bin/board
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""board — multi-session coordination CLI (SQLite backend, parameterized queries).
|
|
3
|
+
|
|
4
|
+
Uses a declarative command registry with lazy module imports instead of
|
|
5
|
+
if/elif chains and ad-hoc lambda dicts.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from importlib import import_module
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
CLAUDES_HOME = Path(__file__).resolve().parent.parent
|
|
14
|
+
sys.path.insert(0, str(CLAUDES_HOME))
|
|
15
|
+
|
|
16
|
+
from lib.board_db import BoardDB
|
|
17
|
+
from lib.common import ClaudesEnv, parse_flags
|
|
18
|
+
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
|
+
# Command registry
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Command:
|
|
26
|
+
"""Declarative command entry — no lambdas, no late-binding traps."""
|
|
27
|
+
|
|
28
|
+
name: str
|
|
29
|
+
module: str
|
|
30
|
+
function: str
|
|
31
|
+
help: str
|
|
32
|
+
usage: str = ""
|
|
33
|
+
needs_identity: bool = True
|
|
34
|
+
takes_rest: bool = True
|
|
35
|
+
aliases: list[str] = field(default_factory=list)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
COMMANDS: list[Command] = [
|
|
39
|
+
# ── messaging ──
|
|
40
|
+
Command("send", "lib.board_msg", "cmd_send", "send a message", "send <to> <msg> [--attach <f>]"),
|
|
41
|
+
Command("status", "lib.board_msg", "cmd_status", "update your current task", "status <description>"),
|
|
42
|
+
Command("inbox", "lib.board_msg", "cmd_inbox", "check unread messages", "inbox", takes_rest=False),
|
|
43
|
+
Command("ack", "lib.board_msg", "cmd_ack", "clear inbox", "ack", takes_rest=False),
|
|
44
|
+
Command("log", "lib.board_msg", "cmd_log", "message history", "log [n] [--mine]"),
|
|
45
|
+
# ── views ──
|
|
46
|
+
Command("view", "lib.board_view", "cmd_view", "session dashboard", "view", takes_rest=False),
|
|
47
|
+
Command(
|
|
48
|
+
"overview",
|
|
49
|
+
"lib.board_view",
|
|
50
|
+
"cmd_overview",
|
|
51
|
+
"project overview (default)",
|
|
52
|
+
"overview",
|
|
53
|
+
needs_identity=False,
|
|
54
|
+
takes_rest=False,
|
|
55
|
+
),
|
|
56
|
+
Command(
|
|
57
|
+
"dashboard",
|
|
58
|
+
"lib.board_view",
|
|
59
|
+
"cmd_dashboard",
|
|
60
|
+
"live team status",
|
|
61
|
+
"dashboard",
|
|
62
|
+
needs_identity=False,
|
|
63
|
+
takes_rest=False,
|
|
64
|
+
aliases=["dash"],
|
|
65
|
+
),
|
|
66
|
+
Command("p0", "lib.board_view", "cmd_p0", "P0 lock status", "p0", needs_identity=False, takes_rest=False),
|
|
67
|
+
Command(
|
|
68
|
+
"pre-build",
|
|
69
|
+
"lib.board_view",
|
|
70
|
+
"cmd_prebuild",
|
|
71
|
+
"pre-build readiness check",
|
|
72
|
+
"pre-build",
|
|
73
|
+
needs_identity=False,
|
|
74
|
+
takes_rest=False,
|
|
75
|
+
),
|
|
76
|
+
Command(
|
|
77
|
+
"dirty",
|
|
78
|
+
"lib.board_view",
|
|
79
|
+
"cmd_dirty",
|
|
80
|
+
"show uncommitted changes",
|
|
81
|
+
"dirty",
|
|
82
|
+
needs_identity=False,
|
|
83
|
+
takes_rest=False,
|
|
84
|
+
),
|
|
85
|
+
Command(
|
|
86
|
+
"files", "lib.board_view", "cmd_files", "list shared files", "files", needs_identity=False, takes_rest=False
|
|
87
|
+
),
|
|
88
|
+
Command("get", "lib.board_view", "cmd_get", "view shared file content", "get <hash|name>", needs_identity=False),
|
|
89
|
+
Command("roster", "lib.board_view", "cmd_roster", "team roster", "roster", needs_identity=False, takes_rest=False),
|
|
90
|
+
Command(
|
|
91
|
+
"history",
|
|
92
|
+
"lib.board_view",
|
|
93
|
+
"cmd_history",
|
|
94
|
+
"session message history",
|
|
95
|
+
"history <session> [limit]",
|
|
96
|
+
needs_identity=False,
|
|
97
|
+
),
|
|
98
|
+
Command(
|
|
99
|
+
"freshness",
|
|
100
|
+
"lib.board_view",
|
|
101
|
+
"cmd_freshness",
|
|
102
|
+
"data freshness per session",
|
|
103
|
+
"freshness",
|
|
104
|
+
needs_identity=False,
|
|
105
|
+
takes_rest=False,
|
|
106
|
+
),
|
|
107
|
+
Command(
|
|
108
|
+
"relations",
|
|
109
|
+
"lib.board_view",
|
|
110
|
+
"cmd_relations",
|
|
111
|
+
"inter-session message flow",
|
|
112
|
+
"relations",
|
|
113
|
+
needs_identity=False,
|
|
114
|
+
takes_rest=False,
|
|
115
|
+
),
|
|
116
|
+
# ── BBS ──
|
|
117
|
+
Command("post", "lib.board_bbs", "cmd_post", "BBS: create new thread", "post <标题> <内容>"),
|
|
118
|
+
Command("reply", "lib.board_bbs", "cmd_reply", "BBS: reply to thread", "reply <帖子ID> <内容>"),
|
|
119
|
+
Command("thread", "lib.board_bbs", "cmd_thread", "BBS: view thread", "thread <帖子ID>", needs_identity=False),
|
|
120
|
+
Command(
|
|
121
|
+
"threads",
|
|
122
|
+
"lib.board_bbs",
|
|
123
|
+
"cmd_threads",
|
|
124
|
+
"BBS: list all threads",
|
|
125
|
+
"threads",
|
|
126
|
+
needs_identity=False,
|
|
127
|
+
takes_rest=False,
|
|
128
|
+
),
|
|
129
|
+
# ── bug ──
|
|
130
|
+
Command("bug", "lib.board_bug", "cmd_bug", "bug tracker", "bug {report|assign|fix|list|overdue}"),
|
|
131
|
+
# ── task ──
|
|
132
|
+
Command("task", "lib.board_task", "cmd_task", "task queue management", "task {add|done|list|next}"),
|
|
133
|
+
# ── voting ──
|
|
134
|
+
Command("propose", "lib.board_vote", "cmd_propose", "create a proposal", "propose <内容> [--type S]"),
|
|
135
|
+
Command("vote", "lib.board_vote", "cmd_vote", "vote on a proposal", "vote <N> <SUPPORT|OBJECT> <reason>"),
|
|
136
|
+
Command("tally", "lib.board_vote", "cmd_tally", "recount votes", "tally <N>", needs_identity=False),
|
|
137
|
+
# ── mailbox (encrypted) ──
|
|
138
|
+
Command("keygen", "lib.board_mailbox", "cmd_keygen", "generate encryption keypair", "keygen", takes_rest=False),
|
|
139
|
+
Command("seal", "lib.board_mailbox", "cmd_seal", "send encrypted message", "seal <recipient> <message>"),
|
|
140
|
+
Command("unseal", "lib.board_mailbox", "cmd_unseal", "read encrypted inbox", "unseal", takes_rest=False),
|
|
141
|
+
Command(
|
|
142
|
+
"mailbox-log",
|
|
143
|
+
"lib.board_mailbox",
|
|
144
|
+
"cmd_mailbox_log",
|
|
145
|
+
"encrypted message history",
|
|
146
|
+
"mailbox-log",
|
|
147
|
+
takes_rest=False,
|
|
148
|
+
),
|
|
149
|
+
# ── admin ──
|
|
150
|
+
Command("kudos", "lib.board_admin", "cmd_kudos", "give public recognition", "kudos <target> <reason>"),
|
|
151
|
+
Command(
|
|
152
|
+
"kudos-list",
|
|
153
|
+
"lib.board_admin",
|
|
154
|
+
"cmd_kudos_list",
|
|
155
|
+
"kudos leaderboard",
|
|
156
|
+
"kudos-list",
|
|
157
|
+
needs_identity=False,
|
|
158
|
+
takes_rest=False,
|
|
159
|
+
aliases=["kudos-board"],
|
|
160
|
+
),
|
|
161
|
+
Command("suspend", "lib.board_admin", "cmd_suspend", "suspend a session", "suspend <session>"),
|
|
162
|
+
Command("resume", "lib.board_admin", "cmd_resume", "resume a session", "resume <session>"),
|
|
163
|
+
# ── git lock ──
|
|
164
|
+
Command("git-lock", "lib.board_lock", "cmd_git_lock", "acquire git index lock", "git-lock [reason]"),
|
|
165
|
+
Command("git-unlock", "lib.board_lock", "cmd_git_unlock", "release git index lock", "git-unlock"),
|
|
166
|
+
Command(
|
|
167
|
+
"git-lock-status",
|
|
168
|
+
"lib.board_lock",
|
|
169
|
+
"cmd_git_lock_status",
|
|
170
|
+
"git lock status",
|
|
171
|
+
"git-lock-status",
|
|
172
|
+
needs_identity=False,
|
|
173
|
+
takes_rest=False,
|
|
174
|
+
),
|
|
175
|
+
# ── maintenance ──
|
|
176
|
+
Command(
|
|
177
|
+
"prune",
|
|
178
|
+
"lib.board_maintenance",
|
|
179
|
+
"cmd_prune",
|
|
180
|
+
"prune old messages",
|
|
181
|
+
"prune [--before DAYS] [--dry-run]",
|
|
182
|
+
needs_identity=False,
|
|
183
|
+
),
|
|
184
|
+
Command(
|
|
185
|
+
"backup",
|
|
186
|
+
"lib.board_maintenance",
|
|
187
|
+
"cmd_backup",
|
|
188
|
+
"backup database",
|
|
189
|
+
"backup [--output <path>]",
|
|
190
|
+
needs_identity=False,
|
|
191
|
+
),
|
|
192
|
+
Command(
|
|
193
|
+
"restore",
|
|
194
|
+
"lib.board_maintenance",
|
|
195
|
+
"cmd_restore",
|
|
196
|
+
"restore from backup",
|
|
197
|
+
"restore <file> [--force]",
|
|
198
|
+
needs_identity=False,
|
|
199
|
+
),
|
|
200
|
+
]
|
|
201
|
+
|
|
202
|
+
# Build lookup map (name + aliases → Command)
|
|
203
|
+
_CMD_MAP: dict[str, Command] = {}
|
|
204
|
+
for c in COMMANDS:
|
|
205
|
+
_CMD_MAP[c.name] = c
|
|
206
|
+
for a in c.aliases:
|
|
207
|
+
_CMD_MAP[a] = c
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# ---------------------------------------------------------------------------
|
|
211
|
+
# Dispatch
|
|
212
|
+
# ---------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _dispatch(cmd: Command, db: BoardDB, identity: str, rest: list[str]) -> None:
|
|
216
|
+
"""Lazy-import the handler module and call the registered function."""
|
|
217
|
+
module = import_module(cmd.module)
|
|
218
|
+
handler = getattr(module, cmd.function)
|
|
219
|
+
|
|
220
|
+
# Match the handler's declared parameter pattern
|
|
221
|
+
if cmd.needs_identity and cmd.takes_rest:
|
|
222
|
+
handler(db, identity, rest)
|
|
223
|
+
elif cmd.needs_identity:
|
|
224
|
+
handler(db, identity)
|
|
225
|
+
elif cmd.takes_rest:
|
|
226
|
+
handler(db, rest)
|
|
227
|
+
else:
|
|
228
|
+
handler(db)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _fmt_command(cmd: Command, width: int) -> str:
|
|
232
|
+
name = cmd.name
|
|
233
|
+
if cmd.aliases:
|
|
234
|
+
name += f" ({', '.join(cmd.aliases)})"
|
|
235
|
+
return f" {name:<{width}} {cmd.help}"
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def print_help() -> None:
|
|
239
|
+
max_name = max(len(c.name) + (2 + len(", ".join(c.aliases)) if c.aliases else 0) for c in COMMANDS) + 2
|
|
240
|
+
print("board v2 — agent coordination tool (SQLite backend, Python)\n")
|
|
241
|
+
print("Usage: board --as <name> <command> [args...]\n")
|
|
242
|
+
print("Commands:")
|
|
243
|
+
last_module = ""
|
|
244
|
+
for c in COMMANDS:
|
|
245
|
+
mod = c.module.rsplit(".", 1)[-1] # board_msg, board_view, etc.
|
|
246
|
+
if mod != last_module:
|
|
247
|
+
if last_module:
|
|
248
|
+
print()
|
|
249
|
+
print(f" [{mod}]")
|
|
250
|
+
last_module = mod
|
|
251
|
+
print(_fmt_command(c, max_name))
|
|
252
|
+
print()
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# ---------------------------------------------------------------------------
|
|
256
|
+
# Main
|
|
257
|
+
# ---------------------------------------------------------------------------
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def main() -> None:
|
|
261
|
+
env = ClaudesEnv.load()
|
|
262
|
+
db = BoardDB(env)
|
|
263
|
+
|
|
264
|
+
flags, filtered = parse_flags(sys.argv[1:], value_flags={"as": ["--as"]})
|
|
265
|
+
identity = str(flags["as"]) if "as" in flags else ""
|
|
266
|
+
|
|
267
|
+
cmd_name = filtered[0] if filtered else "help"
|
|
268
|
+
rest = filtered[1:]
|
|
269
|
+
|
|
270
|
+
if cmd_name in ("help", "-h", "--help"):
|
|
271
|
+
print_help()
|
|
272
|
+
return
|
|
273
|
+
|
|
274
|
+
cmd = _CMD_MAP.get(cmd_name)
|
|
275
|
+
if not cmd:
|
|
276
|
+
print(f"ERROR: unknown command '{cmd_name}'. Try 'board help'.", file=sys.stderr)
|
|
277
|
+
raise SystemExit(1)
|
|
278
|
+
|
|
279
|
+
if cmd.needs_identity and not identity:
|
|
280
|
+
print("ERROR: identity required. Use: board --as <name> <command>", file=sys.stderr)
|
|
281
|
+
raise SystemExit(1)
|
|
282
|
+
|
|
283
|
+
_dispatch(cmd, db, identity, rest)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
if __name__ == "__main__":
|
|
287
|
+
main()
|
package/bin/cnb
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
CLAUDES_HOME="$(cd "$(dirname "$0")/.." && pwd)"
|
|
5
|
+
VERSION=$(cat "$CLAUDES_HOME/VERSION" 2>/dev/null || echo "dev")
|
|
6
|
+
|
|
7
|
+
if [ -t 1 ] || [ -t 2 ]; then
|
|
8
|
+
B=$'\033[1m' D=$'\033[2m' G=$'\033[0;32m' C=$'\033[0;36m' Y=$'\033[1;33m' N=$'\033[0m'
|
|
9
|
+
else
|
|
10
|
+
B='' D='' G='' C='' Y='' N=''
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
# ---- Subcommands (exact match, always first) ----
|
|
14
|
+
if [ $# -gt 0 ]; then
|
|
15
|
+
case "$1" in
|
|
16
|
+
init) shift; exec "$CLAUDES_HOME/bin/init" "$@" ;;
|
|
17
|
+
status) exec "$CLAUDES_HOME/bin/board" overview ;;
|
|
18
|
+
board) shift; exec "$CLAUDES_HOME/bin/board" "$@" ;;
|
|
19
|
+
swarm) shift; exec "$CLAUDES_HOME/bin/swarm" "$@" ;;
|
|
20
|
+
dispatcher) shift; exec "$CLAUDES_HOME/bin/dispatcher" "$@" ;;
|
|
21
|
+
watchdog) shift; exec "$CLAUDES_HOME/bin/dispatcher-watchdog" "$@" ;;
|
|
22
|
+
doctor) shift; exec "$CLAUDES_HOME/bin/doctor" "$@" ;;
|
|
23
|
+
version|--version|-v) echo "cnb v${VERSION}"; exit 0 ;;
|
|
24
|
+
help|--help|-h)
|
|
25
|
+
printf "${B}${G}◆ cnb${N} ${D}v${VERSION}${N}\n"
|
|
26
|
+
printf " 多个 Claude Code 实例协作的团队开发工具\n\n"
|
|
27
|
+
printf " cnb 开始(默认2位同学,AI大佬主题)\n"
|
|
28
|
+
printf " cnb 5 5位同学\n"
|
|
29
|
+
printf " cnb pokemon 宝可梦主题\n"
|
|
30
|
+
printf " cnb 5 pokemon 5位同学 + 宝可梦主题\n\n"
|
|
31
|
+
printf " 主题: ai animal food lang music myth pokemon space\n\n"
|
|
32
|
+
printf " cnb status 团队面板\n"
|
|
33
|
+
printf " cnb swarm [...] 管理后台同学\n"
|
|
34
|
+
printf " cnb board [...] 消息/任务\n"
|
|
35
|
+
exit 0 ;;
|
|
36
|
+
esac
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# ---- Start session: parse [number] [theme] in any order ----
|
|
40
|
+
_NUM=2
|
|
41
|
+
_THEME_IDX=6 # default: AI 大佬
|
|
42
|
+
|
|
43
|
+
_THEME_MAP="ai:6 animal:0 food:2 lang:1 music:5 myth:4 pokemon:7 space:3"
|
|
44
|
+
|
|
45
|
+
for arg in "$@"; do
|
|
46
|
+
if [[ "$arg" =~ ^[0-9]+$ ]]; then
|
|
47
|
+
_NUM="$arg"
|
|
48
|
+
else
|
|
49
|
+
_idx=$(echo "$_THEME_MAP" | tr ' ' '\n' | grep "^${arg}:" | cut -d: -f2)
|
|
50
|
+
if [ -n "$_idx" ]; then
|
|
51
|
+
_THEME_IDX="$_idx"
|
|
52
|
+
else
|
|
53
|
+
printf "${Y}未知参数: ${arg}${N}\n" >&2
|
|
54
|
+
echo "用法: cnb [数量] [主题]" >&2
|
|
55
|
+
echo "主题: ai animal food lang music myth pokemon space" >&2
|
|
56
|
+
exit 1
|
|
57
|
+
fi
|
|
58
|
+
fi
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
# ---- Theme data ----
|
|
62
|
+
_THEMES=(
|
|
63
|
+
"panda otter fox raccoon bunny koala sloth penguin hamster hedgehog duck seal capybara alpaca corgi shiba husky kitten ferret quokka"
|
|
64
|
+
"python ruby rust go swift kotlin scala perl haskell erlang elixir clojure julia ocaml zig lua dart cobol lisp fortran"
|
|
65
|
+
"mochi waffle taco ramen sushi bagel pretzel dumpling cookie brownie churro crepe noodle tofu falafel burrito pancake donut nacho boba"
|
|
66
|
+
"nebula pulsar quasar comet aurora meteor nova orbit cosmos galaxy venus mars saturn pluto titan europa io ceres vega sirius"
|
|
67
|
+
"dragon phoenix griffin hydra kraken sphinx unicorn pixie goblin imp djinn yeti nymph chimera basilisk manticore cerberus minotaur golem banshee"
|
|
68
|
+
"jazz blues funk reggae disco punk grunge techno dubstep waltz tango salsa bossa swing opera gospel motown bebop ska hiphop"
|
|
69
|
+
"altman dario ilya lecun karpathy hassabis sutskever hinton bengio fei-fei ng zuck bezos nadella pichai musk huang lisa-su amodei jack-clark"
|
|
70
|
+
"pikachu charmander snorlax eevee jigglypuff mewtwo gengar squirtle bulbasaur vulpix psyduck togepi mudkip lucario gardevoir rayquaza mimikyu ditto zorua umbreon"
|
|
71
|
+
)
|
|
72
|
+
_LABELS=("小动物" "编程语言" "美食" "太空" "神话生物" "音乐风格" "AI 大佬" "宝可梦")
|
|
73
|
+
|
|
74
|
+
[ "$_NUM" -lt 1 ] && _NUM=1
|
|
75
|
+
[ "$_NUM" -gt 20 ] && _NUM=20
|
|
76
|
+
|
|
77
|
+
LABEL="${_LABELS[$_THEME_IDX]}"
|
|
78
|
+
ALL_NAMES=$(echo "${_THEMES[$_THEME_IDX]}" | tr ' ' '\n' | sort -R | head -n $((_NUM + 1)) | tr '\n' ' ' | sed 's/ $//')
|
|
79
|
+
ME=$(echo "$ALL_NAMES" | cut -d' ' -f1)
|
|
80
|
+
WORKERS=$(echo "$ALL_NAMES" | cut -d' ' -f2-)
|
|
81
|
+
|
|
82
|
+
# ---- Init + start ----
|
|
83
|
+
if [ ! -f .claudes/board.db ]; then
|
|
84
|
+
printf "${D}初始化 .claudes/ ...${N}\n"
|
|
85
|
+
"$CLAUDES_HOME/bin/init" $ALL_NAMES >/dev/null 2>&1
|
|
86
|
+
fi
|
|
87
|
+
"$CLAUDES_HOME/bin/swarm" start $WORKERS >/dev/null 2>&1 || true
|
|
88
|
+
|
|
89
|
+
# ---- Slash commands (runtime, gitignored) ----
|
|
90
|
+
CMD_DIR=".claude/commands"
|
|
91
|
+
mkdir -p "$CMD_DIR"
|
|
92
|
+
grep -qx 'commands/cs-*' .claude/.gitignore 2>/dev/null || echo 'commands/cs-*' >> .claude/.gitignore 2>/dev/null || true
|
|
93
|
+
BOARD="$CLAUDES_HOME/bin/board"
|
|
94
|
+
SWARM="$CLAUDES_HOME/bin/swarm"
|
|
95
|
+
_PREFIX=$(grep '^prefix' .claudes/config.toml 2>/dev/null | cut -d'"' -f2)
|
|
96
|
+
cat > "$CMD_DIR/cs-watch.md" <<EOF
|
|
97
|
+
看某个同学在干什么。解析 \$ARGUMENTS 拿到名字。
|
|
98
|
+
运行 \`tmux capture-pane -t ${_PREFIX}-<名字> -p -S -30 2>/dev/null | tail -20\`,用简洁的话告诉用户这个同学在做什么、进展到哪了。
|
|
99
|
+
EOF
|
|
100
|
+
cat > "$CMD_DIR/cs-overview.md" <<EOF
|
|
101
|
+
团队总览。对每个同学运行 \`tmux capture-pane -t ${_PREFIX}-<名字> -p -S -10 2>/dev/null | tail -5\`,汇总成一个简洁的表格告诉用户:谁在干什么、谁卡了、谁闲着。
|
|
102
|
+
同学列表:${WORKERS}
|
|
103
|
+
EOF
|
|
104
|
+
cat > "$CMD_DIR/cs-progress.md" <<EOF
|
|
105
|
+
运行 \`${BOARD} --as ${ME} inbox\` 和 \`${BOARD} --as ${ME} view\`,汇总最近的进展:谁完成了什么、有什么新消息、当前整体进度如何。用简洁的话告诉用户。
|
|
106
|
+
EOF
|
|
107
|
+
cat > "$CMD_DIR/cs-history.md" <<EOF
|
|
108
|
+
运行 \`${BOARD} --as ${ME} log 50\`,把完整的消息历史展示给我。
|
|
109
|
+
EOF
|
|
110
|
+
cat > "$CMD_DIR/cs-update.md" <<EOF
|
|
111
|
+
运行 \`pip install --upgrade cnb\`,更新到最新版本。把结果告诉我,如果更新成功提醒用户重启 cnb 以生效。
|
|
112
|
+
EOF
|
|
113
|
+
cat > "$CMD_DIR/cs-help.md" <<EOF
|
|
114
|
+
列出所有 /cs-* 命令:
|
|
115
|
+
- /cs-overview — 团队总览:谁在干什么、谁卡了
|
|
116
|
+
- /cs-watch <名字> — 看某个同学在干什么
|
|
117
|
+
- /cs-progress — 最近进展汇总
|
|
118
|
+
- /cs-history — 查看完整消息历史
|
|
119
|
+
- /cs-update — 更新 cnb 到最新版
|
|
120
|
+
EOF
|
|
121
|
+
|
|
122
|
+
# ---- Require interactive terminal ----
|
|
123
|
+
if [ ! -t 0 ] || [ ! -t 1 ]; then
|
|
124
|
+
echo "错误: cnb 需要交互式终端运行。" >&2
|
|
125
|
+
echo "用法: cnb [数量] [主题] (详见 cnb help)" >&2
|
|
126
|
+
exit 1
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
# ---- Banner + launch ----
|
|
130
|
+
clear
|
|
131
|
+
printf "${B}${G}◆ cnb${N} ${D}v${VERSION}${N}\n"
|
|
132
|
+
printf "${D} 「${LABEL}」你是 ${ME},同学: ${WORKERS}${N}\n\n"
|
|
133
|
+
|
|
134
|
+
SYSPROMPT="你是 ${ME}。你的终端直接面对用户。
|
|
135
|
+
你有 ${_NUM} 位同学在后台工作:${WORKERS}。你们是平等的,只是你负责和用户沟通。
|
|
136
|
+
|
|
137
|
+
管理团队的命令(直接在 Bash 里跑):
|
|
138
|
+
${BOARD} --as ${ME} send <name> \"<任务描述>\" # 给同学派任务
|
|
139
|
+
${BOARD} --as ${ME} send all \"<消息>\" # 广播
|
|
140
|
+
${BOARD} --as ${ME} inbox # 查看回复
|
|
141
|
+
${BOARD} --as ${ME} view # 看所有人状态
|
|
142
|
+
|
|
143
|
+
工作方式:
|
|
144
|
+
- 用户说想做什么,你拆任务分给同学,自己也干活。
|
|
145
|
+
- 不要让用户跑命令。你直接用上面的命令操作。
|
|
146
|
+
- 定期 inbox 看同学的回复,汇总进展给用户。
|
|
147
|
+
- 用户可以用 /cs-help 查看所有协作命令。
|
|
148
|
+
- 同学之间可以互相 send 消息协作,不用什么都通过你。"
|
|
149
|
+
|
|
150
|
+
exec claude --name "${ME}" --append-system-prompt "$SYSPROMPT"
|
package/bin/cnb.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* cnb — npm entry point.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { spawn } = require('child_process');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
|
|
12
|
+
const PROJECT_ROOT = path.resolve(__dirname, '..');
|
|
13
|
+
const BASH_SCRIPT = path.join(PROJECT_ROOT, 'bin', 'cnb');
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(BASH_SCRIPT)) {
|
|
16
|
+
console.error(`FATAL: ${BASH_SCRIPT} not found`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
|
|
22
|
+
const child = spawn('bash', [BASH_SCRIPT, ...args], {
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
cwd: process.cwd(),
|
|
25
|
+
env: process.env,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
child.on('exit', (code, signal) => {
|
|
29
|
+
if (signal) {
|
|
30
|
+
process.exit(128 + (require('os').constants.signals[signal] || 0));
|
|
31
|
+
}
|
|
32
|
+
process.exit(code || 0);
|
|
33
|
+
});
|