aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/src/meshbay_cli/commands/invitations.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/invitations.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/invitations.py')
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/commands/invitations.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/commands/invitations.py b/packages/meshbay-cli/src/meshbay_cli/commands/invitations.py
new file mode 100644
index 0000000..df2a23e
--- /dev/null
+++ b/packages/meshbay-cli/src/meshbay_cli/commands/invitations.py
@@ -0,0 +1,66 @@
+"""
+`invitations`: the groups somebody added this account to, waiting for an answer.
+
+Until it is accepted an invitation is not a membership: the group is not in
+`groups`, and its nodes cannot be reached. `join` accepts one, `decline` refuses
+it.
+"""
+
+import json
+import sys
+
+from ..client.paths import group_arg, handle, resolve_group
+from ..errors import NOT_FOUND, CliError
+from ..output import safe, sentence
+from .context import Context
+from .groups import local_time
+
+HELP = "list the invitations waiting for your answer"
+
+
+def add_parser(sub, parent) -> None:
+ sub.add_parser("invitations", parents=[parent], help=HELP, description=sentence(HELP)
+ + ". The GROUP column is what `join` and `decline` take.")
+
+
+def as_group(inv: dict) -> dict:
+ """An invitation row in the shape `groups` rows have, for `handle` and lookups."""
+ return {"id": inv["group_id"], "name": inv["name"],
+ "owner_username": inv.get("owner_username") or "", "invitation": inv}
+
+
+def find_invitation(invitations: list[dict], spec: str) -> dict:
+ try:
+ return resolve_group([as_group(i) for i in invitations], group_arg(spec))
+ except CliError as e:
+ if e.code != NOT_FOUND:
+ raise
+ raise CliError(NOT_FOUND, f"No invitation to a group called {spec!r} is "
+ "waiting; `meshbay-cli invitations` lists them.") from None
+
+
+async def run(ctx: Context) -> int:
+ await ctx.hub.check_version()
+ account = ctx.account()
+ try:
+ invitations = await account.call(account.hub.invitations)
+ finally:
+ await account.close()
+ rows = sorted((as_group(i) for i in invitations),
+ key=lambda g: (g["name"].lower(), g["owner_username"]))
+ if ctx.args.json:
+ json.dump([{"group": g["name"], "owner": g["owner_username"], "id": g["id"],
+ "path": handle(g), "invited_by": g["invitation"].get("invited_by") or "",
+ "created_at": g["invitation"].get("created_at")}
+ for g in rows], sys.stdout, indent=1)
+ print()
+ return 0
+ if not rows:
+ print("No invitation is waiting.", file=sys.stderr)
+ return 0
+ print(f"{'INVITED BY':<22}{'DATE':<18}GROUP")
+ for g in rows:
+ inv = g["invitation"]
+ print(f"{safe(inv.get('invited_by') or ''):<22}{local_time(inv.get('created_at')):<18}"
+ f"{safe(handle(g))}")
+ return 0