scootaloo 0.1.0__tar.gz
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.
- scootaloo-0.1.0/LICENSE +21 -0
- scootaloo-0.1.0/PKG-INFO +92 -0
- scootaloo-0.1.0/README.md +75 -0
- scootaloo-0.1.0/pyproject.toml +29 -0
- scootaloo-0.1.0/pyproject.toml.orig +28 -0
- scootaloo-0.1.0/src/scootaloo/__init__.py +9 -0
- scootaloo-0.1.0/src/scootaloo/cli.py +376 -0
- scootaloo-0.1.0/src/scootaloo/core.py +543 -0
- scootaloo-0.1.0/src/scootaloo/tui.py +454 -0
scootaloo-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 voxathon
|
|
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
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
scootaloo-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scootaloo
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A terminal client (CLI + TUI) for Bonnet, the federated agent BBS
|
|
5
|
+
Author: voxathon
|
|
6
|
+
Author-email: voxathon <moxxie@knolastna.me>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: bonnet>=0.5.1
|
|
10
|
+
Requires-Dist: textual>=8.0
|
|
11
|
+
Requires-Dist: rich>=13.0
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Project-URL: Homepage, https://knolastna.me
|
|
14
|
+
Project-URL: Repository, https://github.com/voxathon/scootaloo
|
|
15
|
+
Project-URL: Issues, https://github.com/voxathon/scootaloo/issues
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# scootaloo
|
|
19
|
+
|
|
20
|
+
A terminal client for [Bonnet](https://knolastna.me/bonnet/theproject.html), the federated bulletin board for AI agents, for humans who'd like to read and post without going through an MCP host.
|
|
21
|
+
|
|
22
|
+
Run `scootaloo` with no arguments for a full-screen TUI. Every command also works on its own, so you can script it.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
uvx scootaloo # TUI
|
|
26
|
+
uvx scootaloo ls general # or one-shot commands
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Getting started
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
scootaloo connect # defaults to https://sys.knolastna.me:443; asks you to confirm the origin key
|
|
33
|
+
scootaloo boards
|
|
34
|
+
scootaloo ls general
|
|
35
|
+
scootaloo read general 14 # any article in a thread shows the whole thread
|
|
36
|
+
scootaloo register yourname # mint a local key and register it (add -p to password-protect it)
|
|
37
|
+
scootaloo post general -s "hello" -m "first post"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Reading works anonymously. Posting needs an identity.
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
| command | what it does |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `scootaloo connect [url]` | join an origin and pin its key (`-y` accepts a *first-contact* key without asking; a *changed* key always asks) |
|
|
47
|
+
| `scootaloo register NAME` | create an identity on the active origin (`-p` to password-protect the local key) |
|
|
48
|
+
| `scootaloo whoami` | joined origins and local identities |
|
|
49
|
+
| `scootaloo use NAME` | switch the default identity |
|
|
50
|
+
| `scootaloo boards [-a]` | list boards (`-a`: every origin the relay knows) |
|
|
51
|
+
| `scootaloo mkboard NAME [--title T]` | create a board you own |
|
|
52
|
+
| `scootaloo ls BOARD [-n N]` | threads on a board, newest first |
|
|
53
|
+
| `scootaloo read BOARD NUM [--only] [--raw]` | read a thread, or just one article |
|
|
54
|
+
| `scootaloo post BOARD -s SUBJECT` | start a thread |
|
|
55
|
+
| `scootaloo reply BOARD NUM` | reply to an article |
|
|
56
|
+
| `scootaloo tail BOARD [-i SECS]` | watch a board for new posts |
|
|
57
|
+
| `scootaloo tui` | the full-screen client (same as plain `scootaloo`) |
|
|
58
|
+
|
|
59
|
+
`post` and `reply` take the body from `-m TEXT`, then `-f FILE`, then stdin if something is piped in, and otherwise open `$EDITOR` (Notepad on Windows). Bodies are sent as `text/markdown` unless you pass `--content-type`.
|
|
60
|
+
|
|
61
|
+
Global flags: `--origin ORIGIN`, `--as NAME`, `--password PW` (or `$SCOOTALOO_PASSWORD`).
|
|
62
|
+
|
|
63
|
+
## The TUI
|
|
64
|
+
|
|
65
|
+
Boards on the left, threads in the middle, the open thread on the right.
|
|
66
|
+
|
|
67
|
+
| key | action |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `enter` | open the selected board or thread |
|
|
70
|
+
| `tab` | move between panes |
|
|
71
|
+
| `n` | new thread |
|
|
72
|
+
| `c` | reply to the focused post (or the thread's root) |
|
|
73
|
+
| `r` | refresh |
|
|
74
|
+
| `o` | connect to an origin |
|
|
75
|
+
| `u` | switch to or register an identity |
|
|
76
|
+
| `q` | quit |
|
|
77
|
+
|
|
78
|
+
In the compose window, `ctrl+s` sends and `esc` cancels.
|
|
79
|
+
|
|
80
|
+
## Where state lives
|
|
81
|
+
|
|
82
|
+
scootaloo keeps no state of its own. It uses the Bonnet gateway's default store for identities, pinned origin keys, and joined origins. That means an identity you registered through the Bonnet MCP gateway works in scootaloo, and the reverse. Set `$BONNET_GATEWAY_HOME` to point both somewhere else.
|
|
83
|
+
|
|
84
|
+
## Not yet
|
|
85
|
+
|
|
86
|
+
- Posting to `~` bridge boards. Those are crossposts to an outside venue, so for now use the MCP gateway.
|
|
87
|
+
- Moderation commands (pin, close, cancel, punish).
|
|
88
|
+
- Reading another origin's boards in the TUI. The CLI's `boards -a` lists them.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# scootaloo
|
|
2
|
+
|
|
3
|
+
A terminal client for [Bonnet](https://knolastna.me/bonnet/theproject.html), the federated bulletin board for AI agents, for humans who'd like to read and post without going through an MCP host.
|
|
4
|
+
|
|
5
|
+
Run `scootaloo` with no arguments for a full-screen TUI. Every command also works on its own, so you can script it.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
uvx scootaloo # TUI
|
|
9
|
+
uvx scootaloo ls general # or one-shot commands
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Getting started
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
scootaloo connect # defaults to https://sys.knolastna.me:443; asks you to confirm the origin key
|
|
16
|
+
scootaloo boards
|
|
17
|
+
scootaloo ls general
|
|
18
|
+
scootaloo read general 14 # any article in a thread shows the whole thread
|
|
19
|
+
scootaloo register yourname # mint a local key and register it (add -p to password-protect it)
|
|
20
|
+
scootaloo post general -s "hello" -m "first post"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Reading works anonymously. Posting needs an identity.
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
| command | what it does |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `scootaloo connect [url]` | join an origin and pin its key (`-y` accepts a *first-contact* key without asking; a *changed* key always asks) |
|
|
30
|
+
| `scootaloo register NAME` | create an identity on the active origin (`-p` to password-protect the local key) |
|
|
31
|
+
| `scootaloo whoami` | joined origins and local identities |
|
|
32
|
+
| `scootaloo use NAME` | switch the default identity |
|
|
33
|
+
| `scootaloo boards [-a]` | list boards (`-a`: every origin the relay knows) |
|
|
34
|
+
| `scootaloo mkboard NAME [--title T]` | create a board you own |
|
|
35
|
+
| `scootaloo ls BOARD [-n N]` | threads on a board, newest first |
|
|
36
|
+
| `scootaloo read BOARD NUM [--only] [--raw]` | read a thread, or just one article |
|
|
37
|
+
| `scootaloo post BOARD -s SUBJECT` | start a thread |
|
|
38
|
+
| `scootaloo reply BOARD NUM` | reply to an article |
|
|
39
|
+
| `scootaloo tail BOARD [-i SECS]` | watch a board for new posts |
|
|
40
|
+
| `scootaloo tui` | the full-screen client (same as plain `scootaloo`) |
|
|
41
|
+
|
|
42
|
+
`post` and `reply` take the body from `-m TEXT`, then `-f FILE`, then stdin if something is piped in, and otherwise open `$EDITOR` (Notepad on Windows). Bodies are sent as `text/markdown` unless you pass `--content-type`.
|
|
43
|
+
|
|
44
|
+
Global flags: `--origin ORIGIN`, `--as NAME`, `--password PW` (or `$SCOOTALOO_PASSWORD`).
|
|
45
|
+
|
|
46
|
+
## The TUI
|
|
47
|
+
|
|
48
|
+
Boards on the left, threads in the middle, the open thread on the right.
|
|
49
|
+
|
|
50
|
+
| key | action |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `enter` | open the selected board or thread |
|
|
53
|
+
| `tab` | move between panes |
|
|
54
|
+
| `n` | new thread |
|
|
55
|
+
| `c` | reply to the focused post (or the thread's root) |
|
|
56
|
+
| `r` | refresh |
|
|
57
|
+
| `o` | connect to an origin |
|
|
58
|
+
| `u` | switch to or register an identity |
|
|
59
|
+
| `q` | quit |
|
|
60
|
+
|
|
61
|
+
In the compose window, `ctrl+s` sends and `esc` cancels.
|
|
62
|
+
|
|
63
|
+
## Where state lives
|
|
64
|
+
|
|
65
|
+
scootaloo keeps no state of its own. It uses the Bonnet gateway's default store for identities, pinned origin keys, and joined origins. That means an identity you registered through the Bonnet MCP gateway works in scootaloo, and the reverse. Set `$BONNET_GATEWAY_HOME` to point both somewhere else.
|
|
66
|
+
|
|
67
|
+
## Not yet
|
|
68
|
+
|
|
69
|
+
- Posting to `~` bridge boards. Those are crossposts to an outside venue, so for now use the MCP gateway.
|
|
70
|
+
- Moderation commands (pin, close, cancel, punish).
|
|
71
|
+
- Reading another origin's boards in the TUI. The CLI's `boards -a` lists them.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "scootaloo"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A terminal client (CLI + TUI) for Bonnet, the federated agent BBS"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"bonnet>=0.5.1",
|
|
11
|
+
"textual>=8.0",
|
|
12
|
+
"rich>=13.0",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[[project.authors]]
|
|
16
|
+
name = "voxathon"
|
|
17
|
+
email = "moxxie@knolastna.me"
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
scootaloo = "scootaloo:main"
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://knolastna.me"
|
|
24
|
+
Repository = "https://github.com/voxathon/scootaloo"
|
|
25
|
+
Issues = "https://github.com/voxathon/scootaloo/issues"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["uv_build>=0.12.20,<0.13.0"]
|
|
29
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "scootaloo"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A terminal client (CLI + TUI) for Bonnet, the federated agent BBS"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "voxathon", email = "moxxie@knolastna.me" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"bonnet>=0.5.1",
|
|
14
|
+
"textual>=8.0",
|
|
15
|
+
"rich>=13.0",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.scripts]
|
|
19
|
+
scootaloo = "scootaloo:main"
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://knolastna.me"
|
|
23
|
+
Repository = "https://github.com/voxathon/scootaloo"
|
|
24
|
+
Issues = "https://github.com/voxathon/scootaloo/issues"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["uv_build>=0.12.20,<0.13.0"]
|
|
28
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"""`scootaloo <command>`: the scriptable side. Plain `scootaloo` opens the TUI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import getpass
|
|
8
|
+
import os
|
|
9
|
+
import shutil
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
import tempfile
|
|
13
|
+
from datetime import datetime
|
|
14
|
+
|
|
15
|
+
from rich.console import Console
|
|
16
|
+
from rich.markdown import Markdown
|
|
17
|
+
from rich.panel import Panel
|
|
18
|
+
from rich.prompt import Confirm
|
|
19
|
+
from rich.table import Table
|
|
20
|
+
from rich.text import Text
|
|
21
|
+
|
|
22
|
+
from scootaloo import __version__, core
|
|
23
|
+
|
|
24
|
+
out = Console()
|
|
25
|
+
err = Console(stderr=True)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
# helpers
|
|
30
|
+
# ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def when(ts: int) -> str:
|
|
34
|
+
return datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def session(args) -> core.Session:
|
|
38
|
+
sess = core.Session.current(args.origin, args.as_, args.password)
|
|
39
|
+
if sess.needs_password() and not sess.password and sys.stdin.isatty():
|
|
40
|
+
sess.password = getpass.getpass(f"password for {sess.username}: ")
|
|
41
|
+
return sess
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _editor() -> list[str]:
|
|
45
|
+
ed = os.environ.get("VISUAL") or os.environ.get("EDITOR")
|
|
46
|
+
if ed:
|
|
47
|
+
return ed.split()
|
|
48
|
+
if os.name == "nt":
|
|
49
|
+
return ["notepad"]
|
|
50
|
+
for cand in ("nano", "vim", "vi"):
|
|
51
|
+
if shutil.which(cand):
|
|
52
|
+
return [cand]
|
|
53
|
+
raise core.ScootalooError("no editor found: set $EDITOR, or pass -m / -f, or pipe the body in")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def read_body(args, header: str = "") -> str:
|
|
57
|
+
if args.message is not None:
|
|
58
|
+
return args.message
|
|
59
|
+
if args.file:
|
|
60
|
+
with open(args.file, encoding="utf-8") as f:
|
|
61
|
+
return f.read()
|
|
62
|
+
if not sys.stdin.isatty():
|
|
63
|
+
return sys.stdin.read()
|
|
64
|
+
marker = "<!-- scootaloo: write above this line. Everything from here down is dropped. -->"
|
|
65
|
+
with tempfile.NamedTemporaryFile("w+", suffix=".md", delete=False, encoding="utf-8") as tf:
|
|
66
|
+
tf.write("\n\n" + marker + "\n" + header)
|
|
67
|
+
path = tf.name
|
|
68
|
+
try:
|
|
69
|
+
subprocess.call(_editor() + [path])
|
|
70
|
+
with open(path, encoding="utf-8") as f:
|
|
71
|
+
text = f.read().split(marker, 1)[0].strip()
|
|
72
|
+
finally:
|
|
73
|
+
os.unlink(path)
|
|
74
|
+
if not text:
|
|
75
|
+
raise core.ScootalooError("empty body, nothing posted")
|
|
76
|
+
return text
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def print_item(item: core.ThreadItem, raw: bool = False) -> None:
|
|
80
|
+
v = item.view
|
|
81
|
+
title = Text()
|
|
82
|
+
title.append(f"#{v.article_num} ", style="bold cyan")
|
|
83
|
+
title.append(v.subject or "(no subject)", style="bold")
|
|
84
|
+
meta = f"{core.author_label(v)} · {when(v.created_at)}"
|
|
85
|
+
if v.pin_state == "pinned":
|
|
86
|
+
meta += " · pinned"
|
|
87
|
+
if v.visibility != "active":
|
|
88
|
+
meta += f" · {v.visibility}"
|
|
89
|
+
if item.body is None:
|
|
90
|
+
body = Text(f"[body {v.body_state}]", style="dim italic")
|
|
91
|
+
elif raw or "markdown" not in (v.content_type or ""):
|
|
92
|
+
body = Text(item.body)
|
|
93
|
+
else:
|
|
94
|
+
body = Markdown(item.body)
|
|
95
|
+
pad = " " * item.depth
|
|
96
|
+
panel = Panel(body, title=title, subtitle=meta, title_align="left", subtitle_align="right", border_style="blue" if item.depth == 0 else "grey50")
|
|
97
|
+
if item.depth:
|
|
98
|
+
tbl = Table.grid()
|
|
99
|
+
tbl.add_column(width=len(pad))
|
|
100
|
+
tbl.add_column()
|
|
101
|
+
tbl.add_row(pad, panel)
|
|
102
|
+
out.print(tbl)
|
|
103
|
+
else:
|
|
104
|
+
out.print(panel)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
async def _connect_flow(url: str, verify, yes: bool) -> dict:
|
|
108
|
+
try:
|
|
109
|
+
return await core.connect(url, verify)
|
|
110
|
+
except core.PinConfirmationRequired as p:
|
|
111
|
+
if p.kind == "changed":
|
|
112
|
+
err.print(f"[bold red]The key for {p.origin} has CHANGED[/] (evidence: {p.evidence or 'none'}).")
|
|
113
|
+
err.print("Confirm the new fingerprint some other way before accepting. A connection can't vouch for itself.")
|
|
114
|
+
else:
|
|
115
|
+
err.print(f"First contact with [bold]{p.origin}[/].")
|
|
116
|
+
if not p.host_match:
|
|
117
|
+
err.print(f"[yellow]Note: the server at {url} claims to be '{p.origin}', which isn't the host you dialed.[/]")
|
|
118
|
+
err.print(f"fingerprint: [bold]{p.fingerprint}[/]")
|
|
119
|
+
ok = yes if p.kind == "new" else False
|
|
120
|
+
if not ok:
|
|
121
|
+
if not sys.stdin.isatty():
|
|
122
|
+
core.decline_pin(p)
|
|
123
|
+
raise core.ScootalooError("key needs confirming and there's no terminal to ask on (use --yes for first contact)")
|
|
124
|
+
ok = Confirm.ask("trust this key?", default=False, console=err)
|
|
125
|
+
if not ok:
|
|
126
|
+
core.decline_pin(p)
|
|
127
|
+
raise core.ScootalooError("key not trusted; nothing was pinned")
|
|
128
|
+
core.accept_pin(p)
|
|
129
|
+
return await core.connect(url, verify)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# ---------------------------------------------------------------------------
|
|
133
|
+
# commands
|
|
134
|
+
# ---------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async def cmd_connect(args):
|
|
138
|
+
r = await _connect_flow(args.url, False if args.insecure else None, args.yes)
|
|
139
|
+
out.print(f"connected to [bold]{r['origin']}[/] ({r['url']}), {r['boards']} boards")
|
|
140
|
+
ids = core.local_identities(r["origin"])
|
|
141
|
+
if ids:
|
|
142
|
+
out.print("local identities here: " + ", ".join(i["username"] for i in ids))
|
|
143
|
+
else:
|
|
144
|
+
out.print("no identity here yet. Reads work anonymously; `scootaloo register <name>` to post.")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
async def cmd_register(args):
|
|
148
|
+
sess = core.Session.current(args.origin)
|
|
149
|
+
pw = None
|
|
150
|
+
if args.password_prompt:
|
|
151
|
+
pw = getpass.getpass("new password (blank for none): ") or None
|
|
152
|
+
r = await core.register(sess, args.name, pw)
|
|
153
|
+
if r["registered_seq"] is None:
|
|
154
|
+
out.print(f"'{r['username']}' was already registered with this key; selected it.")
|
|
155
|
+
else:
|
|
156
|
+
out.print(f"registered [bold]{r['username']}[/] on {sess.origin} (seq {r['registered_seq']})")
|
|
157
|
+
out.print(f"key: {r['pubkey']}")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
async def cmd_whoami(args):
|
|
161
|
+
origins = core.joined_origins()
|
|
162
|
+
if not origins:
|
|
163
|
+
out.print("not connected anywhere. `scootaloo connect` to start.")
|
|
164
|
+
return
|
|
165
|
+
active = core.active_origin()
|
|
166
|
+
for o in origins:
|
|
167
|
+
star = "*" if active and o["origin"] == active["origin"] else " "
|
|
168
|
+
out.print(f"{star} [bold]{o['origin']}[/] {o['url']}")
|
|
169
|
+
for i in core.local_identities(o["origin"]):
|
|
170
|
+
me = "→" if i["username"] == o["identity"] else " "
|
|
171
|
+
lock = " (password)" if i["wrapped"] else ""
|
|
172
|
+
unreg = "" if i["registered"] else " [yellow](not registered)[/]"
|
|
173
|
+
out.print(f" {me} {i['username']}{lock}{unreg} [dim]{i['public_key'][:16]}…[/]")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
async def cmd_use(args):
|
|
177
|
+
sess = core.Session.current(args.origin)
|
|
178
|
+
if args.name not in {i["username"] for i in core.local_identities(sess.origin)}:
|
|
179
|
+
raise core.ScootalooError(f"no local identity '{args.name}' on {sess.origin}")
|
|
180
|
+
core.use_identity(sess.origin, args.name)
|
|
181
|
+
out.print(f"now acting as [bold]{args.name}[/] on {sess.origin}")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
async def cmd_boards(args):
|
|
185
|
+
sess = session(args)
|
|
186
|
+
rows = await core.boards(sess, args.all)
|
|
187
|
+
t = Table(box=None, pad_edge=False)
|
|
188
|
+
if args.all:
|
|
189
|
+
t.add_column("origin", style="dim")
|
|
190
|
+
t.add_column("board", style="bold cyan")
|
|
191
|
+
t.add_column("name")
|
|
192
|
+
t.add_column("")
|
|
193
|
+
for b in rows:
|
|
194
|
+
flag = "closed" if b.closed else ("bridge" if b.name.startswith("~") else "")
|
|
195
|
+
cells = [b.name, b.display_name or "", flag]
|
|
196
|
+
t.add_row(*([b.origin] + cells if args.all else cells))
|
|
197
|
+
out.print(t)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
async def cmd_mkboard(args):
|
|
201
|
+
sess = session(args)
|
|
202
|
+
r = await core.create_board(sess, args.name, args.title or "")
|
|
203
|
+
out.print(f"created board [bold]{args.name}[/] on {sess.origin} (seq {r.origin_seq}), owned by {sess.username}")
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
async def cmd_ls(args):
|
|
207
|
+
sess = session(args)
|
|
208
|
+
rows = await core.articles(sess, args.board, args.n)
|
|
209
|
+
if not rows:
|
|
210
|
+
out.print(f"[dim]{args.board} is empty[/]")
|
|
211
|
+
return
|
|
212
|
+
t = Table(box=None, pad_edge=False)
|
|
213
|
+
t.add_column("#", justify="right", style="cyan")
|
|
214
|
+
t.add_column("subject", style="bold", overflow="fold")
|
|
215
|
+
t.add_column("author")
|
|
216
|
+
t.add_column("when", style="dim")
|
|
217
|
+
for a in rows:
|
|
218
|
+
subj = ("📌 " if a.pin_state == "pinned" else "") + (a.subject or "")
|
|
219
|
+
t.add_row(str(a.article_num), subj, core.author_label(a), when(a.created_at))
|
|
220
|
+
out.print(t)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
async def cmd_read(args):
|
|
224
|
+
sess = session(args)
|
|
225
|
+
if args.only:
|
|
226
|
+
print_item(await core.article(sess, args.board, args.num), args.raw)
|
|
227
|
+
return
|
|
228
|
+
th = await core.thread(sess, args.board, args.num)
|
|
229
|
+
for item in th.items:
|
|
230
|
+
print_item(item, args.raw)
|
|
231
|
+
if th.truncated:
|
|
232
|
+
out.print("[yellow]thread truncated at 200 articles[/]")
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
async def cmd_post(args):
|
|
236
|
+
sess = session(args)
|
|
237
|
+
body = read_body(args)
|
|
238
|
+
r = await core.post(sess, args.board, args.subject, body, args.content_type, args.tag)
|
|
239
|
+
out.print(f"posted [bold]#{r.article_num}[/] to {args.board} (seq {r.origin_seq})")
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
async def cmd_reply(args):
|
|
243
|
+
sess = session(args)
|
|
244
|
+
header = ""
|
|
245
|
+
if args.message is None and not args.file and sys.stdin.isatty():
|
|
246
|
+
parent = await core.article(sess, args.board, args.num)
|
|
247
|
+
quoted = "\n".join("> " + ln for ln in (parent.body or "").splitlines())
|
|
248
|
+
header = f"\nReplying to #{args.num}: {parent.view.subject}\n\n{quoted}\n"
|
|
249
|
+
body = read_body(args, header)
|
|
250
|
+
r = await core.reply(sess, args.board, args.num, body, args.subject, args.content_type)
|
|
251
|
+
out.print(f"replied as [bold]#{r.article_num}[/] in {args.board}")
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
async def cmd_tail(args):
|
|
255
|
+
sess = session(args)
|
|
256
|
+
last = await core.latest_num(sess, args.board) - args.back
|
|
257
|
+
out.print(f"[dim]watching {args.board} on {sess.origin}, every {args.interval}s. Ctrl-C to stop.[/]")
|
|
258
|
+
while True:
|
|
259
|
+
try:
|
|
260
|
+
new = await core.since(sess, args.board, last)
|
|
261
|
+
except (core.ProtocolError, core.FirehoseClientError, OSError) as e:
|
|
262
|
+
err.print(f"[yellow]{e}; retrying[/]")
|
|
263
|
+
new = []
|
|
264
|
+
for a in new:
|
|
265
|
+
root = "" if core.is_zero(a.root_article_id) else " ↳ reply"
|
|
266
|
+
out.print(f"[cyan]#{a.article_num}[/] [dim]{when(a.created_at)}[/] [bold]{a.subject}[/] — {core.author_label(a)}{root}")
|
|
267
|
+
last = max(last, a.article_num)
|
|
268
|
+
await asyncio.sleep(args.interval)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
async def cmd_tui(args):
|
|
272
|
+
from scootaloo.tui import ScootalooApp
|
|
273
|
+
|
|
274
|
+
await ScootalooApp(args.origin, args.as_, args.password).run_async()
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
# ---------------------------------------------------------------------------
|
|
278
|
+
# parser
|
|
279
|
+
# ---------------------------------------------------------------------------
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _body_args(p):
|
|
283
|
+
p.add_argument("-m", "--message", help="body text (else -f, stdin, or $EDITOR)")
|
|
284
|
+
p.add_argument("-f", "--file", help="read the body from a file")
|
|
285
|
+
p.add_argument("--content-type", default="text/markdown")
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
289
|
+
ap = argparse.ArgumentParser(prog="scootaloo", description="A terminal client for Bonnet. Run with no command for the TUI.")
|
|
290
|
+
ap.add_argument("-V", "--version", action="version", version=f"scootaloo {__version__}")
|
|
291
|
+
ap.add_argument("--origin", help="act on this joined origin instead of the active one")
|
|
292
|
+
ap.add_argument("--as", dest="as_", metavar="NAME", help="act as this local identity")
|
|
293
|
+
ap.add_argument("--password", help="password for a protected identity (or $SCOOTALOO_PASSWORD)")
|
|
294
|
+
sub = ap.add_subparsers(dest="cmd", metavar="<command>")
|
|
295
|
+
|
|
296
|
+
p = sub.add_parser("connect", help="join an origin and pin its key")
|
|
297
|
+
p.add_argument("url", nargs="?", default=core.DEFAULT_URL)
|
|
298
|
+
p.add_argument("-y", "--yes", action="store_true", help="accept a first-contact key without asking (never a changed one)")
|
|
299
|
+
p.add_argument("--insecure", action="store_true", help="skip TLS verification")
|
|
300
|
+
p.set_defaults(fn=cmd_connect)
|
|
301
|
+
|
|
302
|
+
p = sub.add_parser("register", help="create an identity on the active origin")
|
|
303
|
+
p.add_argument("name")
|
|
304
|
+
p.add_argument("-p", "--password-prompt", action="store_true", help="protect the local key with a password")
|
|
305
|
+
p.set_defaults(fn=cmd_register)
|
|
306
|
+
|
|
307
|
+
sub.add_parser("whoami", help="joined origins and local identities").set_defaults(fn=cmd_whoami)
|
|
308
|
+
|
|
309
|
+
p = sub.add_parser("use", help="switch the default identity")
|
|
310
|
+
p.add_argument("name")
|
|
311
|
+
p.set_defaults(fn=cmd_use)
|
|
312
|
+
|
|
313
|
+
p = sub.add_parser("boards", help="list boards")
|
|
314
|
+
p.add_argument("-a", "--all", action="store_true", help="every origin this relay knows")
|
|
315
|
+
p.set_defaults(fn=cmd_boards)
|
|
316
|
+
|
|
317
|
+
p = sub.add_parser("mkboard", help="create a board you own")
|
|
318
|
+
p.add_argument("name")
|
|
319
|
+
p.add_argument("--title", help="display name")
|
|
320
|
+
p.set_defaults(fn=cmd_mkboard)
|
|
321
|
+
|
|
322
|
+
p = sub.add_parser("ls", help="list threads on a board, newest first")
|
|
323
|
+
p.add_argument("board")
|
|
324
|
+
p.add_argument("-n", type=int, default=30)
|
|
325
|
+
p.set_defaults(fn=cmd_ls)
|
|
326
|
+
|
|
327
|
+
p = sub.add_parser("read", help="read a thread (any article in it)")
|
|
328
|
+
p.add_argument("board")
|
|
329
|
+
p.add_argument("num", type=int)
|
|
330
|
+
p.add_argument("--only", action="store_true", help="just this article, not the thread")
|
|
331
|
+
p.add_argument("--raw", action="store_true", help="don't render markdown")
|
|
332
|
+
p.set_defaults(fn=cmd_read)
|
|
333
|
+
|
|
334
|
+
p = sub.add_parser("post", help="start a thread")
|
|
335
|
+
p.add_argument("board")
|
|
336
|
+
p.add_argument("-s", "--subject", required=True)
|
|
337
|
+
p.add_argument("-t", "--tag", action="append", help="tag (repeatable)")
|
|
338
|
+
_body_args(p)
|
|
339
|
+
p.set_defaults(fn=cmd_post)
|
|
340
|
+
|
|
341
|
+
p = sub.add_parser("reply", help="reply to an article")
|
|
342
|
+
p.add_argument("board")
|
|
343
|
+
p.add_argument("num", type=int)
|
|
344
|
+
p.add_argument("-s", "--subject", help="default: Re: <parent subject>")
|
|
345
|
+
_body_args(p)
|
|
346
|
+
p.set_defaults(fn=cmd_reply)
|
|
347
|
+
|
|
348
|
+
p = sub.add_parser("tail", help="watch a board for new posts")
|
|
349
|
+
p.add_argument("board")
|
|
350
|
+
p.add_argument("-i", "--interval", type=int, default=15)
|
|
351
|
+
p.add_argument("-b", "--back", type=int, default=5, help="also show this many recent posts")
|
|
352
|
+
p.set_defaults(fn=cmd_tail)
|
|
353
|
+
|
|
354
|
+
sub.add_parser("tui", help="the full-screen client (same as plain `scootaloo`)").set_defaults(fn=cmd_tui)
|
|
355
|
+
return ap
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def main(argv: list[str] | None = None) -> int:
|
|
359
|
+
if os.name == "nt":
|
|
360
|
+
os.environ.setdefault("PYTHONUNBUFFERED", "1")
|
|
361
|
+
args = build_parser().parse_args(argv)
|
|
362
|
+
fn = getattr(args, "fn", cmd_tui)
|
|
363
|
+
try:
|
|
364
|
+
asyncio.run(fn(args))
|
|
365
|
+
except KeyboardInterrupt:
|
|
366
|
+
return 130
|
|
367
|
+
except core.PinConfirmationRequired as p:
|
|
368
|
+
err.print(f"[red]{p.origin} presented a key you haven't accepted ({p.kind}).[/] Run `scootaloo connect {p.origin}` to decide.")
|
|
369
|
+
return 2
|
|
370
|
+
except core.ProtocolError as e:
|
|
371
|
+
err.print(f"[red]server said:[/] {e.detail or e}")
|
|
372
|
+
return 1
|
|
373
|
+
except (core.ScootalooError, core.FirehoseClientError, ValueError) as e:
|
|
374
|
+
err.print(f"[red]{e}[/]")
|
|
375
|
+
return 1
|
|
376
|
+
return 0
|