From 988a0eecd522431980174910db28e45a63ff2710 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Thu, 15 Oct 2026 12:32:24 +0200 Subject: feat(cli): account, rm -r and mkdir, Tab completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit account shows the account and does what the sign-up form and the Profile page do: register (the passphrase floor and the hub's proof of work checked here, the recovery key printed once), verify, change the passphrase, reset a forgotten one, change the e-mail address, sign out everywhere, delete. A new passphrase carries the copy of the account's keys each node keeps for browsers first — opened under the old M, the same keys sealed under the new one — and only then tells the hub; a refusal sets the copies back. A reset restores them from the recovery copy. The connections that do it never make keys nor ask for a device approval. This machine keeps the M it changed away from, so a node out of reach is carried at its next connection; a copy under an M it does not know is no longer rewritten, which locked the browsers out after a passphrase changed elsewhere. rm -r removes a folder and all it holds, from the node's operator key: the files, then the folders deepest first, one confirmation that counts them. mkdir makes folders, --parents the missing ones (not -p, the passphrase). completion bash|powershell prints the script that makes Tab complete actions, verbs, options and the paths of the groups this machine is signed in to, cached two minutes; the deb and rpm packages install the bash one. Co-Authored-By: Claude Opus 5.5 --- .../meshbay-cli/src/meshbay_cli/client/remove.py | 40 ++++++++++++++-------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'packages/meshbay-cli/src/meshbay_cli/client/remove.py') diff --git a/packages/meshbay-cli/src/meshbay_cli/client/remove.py b/packages/meshbay-cli/src/meshbay_cli/client/remove.py index 370cf95..ed9c65a 100644 --- a/packages/meshbay-cli/src/meshbay_cli/client/remove.py +++ b/packages/meshbay-cli/src/meshbay_cli/client/remove.py @@ -1,15 +1,17 @@ """ -Deleting a file from a group (docs/MESHBAY_DESIGN.md §5.4). +Deleting a file, or an empty folder, from a group (docs/MESHBAY_DESIGN.md §5.4). The node decides, and on two grounds only: a key paired with it as operator, or a live device of the account that uploaded the file — any of them, so a file sent from a phone is deleted from the laptop. Being the group's owner on the hub -is neither. The request is answered with a challenge the client signs with its -key on the node; the node rebuilds what was signed itself. +is neither. A folder has no uploader: only the operator removes one, and only +an empty one — the node never deletes recursively. The request is answered with +a challenge the client signs with its key on the node; the node rebuilds what +was signed itself. """ from meshbay_common import MNP_VERSION -from meshbay_common.adminop import OP_FILE_DELETE, admin_transcript +from meshbay_common.adminop import OP_DIR_DELETE, OP_FILE_DELETE, admin_transcript from ..errors import NODE, CliError from .keys import b64, unb64 @@ -24,22 +26,32 @@ def may_delete(session: GroupSession, entry: dict, user_id: str) -> bool: async def delete_file(session: GroupSession, file_id: str) -> None: """Delete one file. Raises `NodeRefusal` with the node's reason.""" - reply = await session.ch.request({"type": "file_delete", "v": MNP_VERSION, - "file_id": file_id}, - "admin_challenge", "file_delete_ack") - if reply["type"] == "file_delete_ack": + await _signed(session, {"type": "file_delete", "v": MNP_VERSION, "file_id": file_id}, + OP_FILE_DELETE, file_id, "file_delete_ack") + + +async def delete_dir(session: GroupSession, path: str) -> None: + """Remove one empty folder (root/folders), as the node's operator.""" + await _signed(session, {"type": "dir_delete", "v": MNP_VERSION, "dir": path}, + OP_DIR_DELETE, path, "dir_delete_ack") + + +async def _signed(session: GroupSession, msg: dict, op: str, subject: str, + ack: str) -> None: + reply = await session.ch.request(msg, "admin_challenge", ack) + if reply["type"] == ack: return # What is signed is checked against what was asked, never taken from the - # node: a challenge for another operation, file, group or node is refused. - if (reply.get("op") != OP_FILE_DELETE or reply.get("subject") != file_id + # node: a challenge for another operation, subject, group or node is refused. + if (reply.get("op") != op or reply.get("subject") != subject or reply.get("group_id") != session.group_id or reply.get("node_pk") != session.node_pk): raise CliError(NODE, "The node asked to sign something other than this deletion; " "nothing was signed.") - transcript = admin_transcript(op=OP_FILE_DELETE, node_pk_b64=session.node_pk, - group_id=session.group_id, subject=file_id, + transcript = admin_transcript(op=op, node_pk_b64=session.node_pk, + group_id=session.group_id, subject=subject, nonce=unb64(reply["nonce"]), ts=int(reply["ts"])) await session.ch.request({"type": "admin_response", "v": MNP_VERSION, - "op_id": reply["op_id"], "op": OP_FILE_DELETE, + "op_id": reply["op_id"], "op": op, "signature": b64(session.identity.sk_ed.sign(transcript))}, - "file_delete_ack") + ack) -- cgit v1.2.3