aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/src/meshbay_cli/commands/leave.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-15 00:56:04 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-15 00:56:04 +0200
commit6f68bb6c1970e26de1f66c073ea5d7fecd21840d (patch)
tree859c74db5819f1d49046e71a53e12afe5eb4193a /packages/meshbay-cli/src/meshbay_cli/commands/leave.py
parent16d92c96bde3a65fc54a93b4662df30cafc831e4 (diff)
downloadmeshbay-6f68bb6c1970e26de1f66c073ea5d7fecd21840d.tar.gz
feat(cli): invitations, join, decline, leave, devices, browser access
join accepts an invitation or redeems a link pasted as sent, then has the node admit a key pair made here, with the invitation's code (a link's code goes only to the node it names; one for a node that is away is kept for the next connection). decline, leave and devices revoke ask first, and refuse without --yes where there is no terminal. devices approve countersigns the one waiting request a code matches, none when several do. browser-access is the application's setting, kept per machine and never enabled from the hub's mirror: on leaves a copy sealed under M on each node, off withdraws it, unset touches nothing. A key pair made for a first contact is now kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/commands/leave.py')
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/commands/leave.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/commands/leave.py b/packages/meshbay-cli/src/meshbay_cli/commands/leave.py
new file mode 100644
index 0000000..e9a529e
--- /dev/null
+++ b/packages/meshbay-cli/src/meshbay_cli/commands/leave.py
@@ -0,0 +1,55 @@
+"""
+`leave`: give up a membership. Asked first; `--yes` answers for a script.
+
+The hub's half only, as in the application: the account stops being a member,
+so its nodes can no longer be reached. The node keeps what it holds — the
+identity it pinned, its copy of the keys, the files uploaded — until its
+operator unpins them, and the group key already served opens what it opened
+until the operator rotates it. The owner cannot leave a group.
+"""
+
+import json
+
+from ..client.groups import my_groups
+from ..client.hub import HubError
+from ..client.paths import group_arg, handle, resolve_group
+from ..errors import REFUSED, CliError
+from ..output import confirm, safe, sentence
+from .context import Context
+
+HELP = "leave a group"
+
+
+def add_parser(sub, parent) -> None:
+ p = sub.add_parser("leave", parents=[parent], help=HELP, description=sentence(HELP)
+ + ". Its files and its chat are no longer reachable from this "
+ "account; only a new invitation brings it back. The owner cannot "
+ "leave a group.")
+ p.add_argument("group", metavar="GROUP", help="the group, as `groups` lists it")
+ p.add_argument("-y", "--yes", action="store_true", help="do not ask for confirmation")
+
+
+async def run(ctx: Context) -> int:
+ await ctx.hub.check_version()
+ account = ctx.account()
+ try:
+ group = resolve_group(await my_groups(account), group_arg(ctx.args.group))
+ name = handle(group)
+ if group.get("is_admin"):
+ raise CliError(REFUSED, f"You own {safe(name)}, so you cannot leave it: it "
+ "would be left with nobody able to manage it.")
+ confirm(f"Leave {safe(name)}? Its files and chat will no longer be reachable "
+ "from your account.", ctx.args.yes)
+ try:
+ await account.call(account.hub.leave_group, group["id"])
+ except HubError as e:
+ if e.status == 409:
+ raise CliError(REFUSED, e.detail) from e
+ raise
+ finally:
+ await account.close()
+ if ctx.args.json:
+ print(json.dumps({"left": True, "path": name, "id": group["id"]}))
+ else:
+ print(f"Left {safe(name)}.")
+ return 0