commune-cli 0.1.9__tar.gz → 0.2.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.
Files changed (33) hide show
  1. commune_cli-0.2.0/.gitignore +8 -0
  2. commune_cli-0.2.0/LICENSE +191 -0
  3. {commune_cli-0.1.9 → commune_cli-0.2.0}/PKG-INFO +18 -1
  4. {commune_cli-0.1.9 → commune_cli-0.2.0}/README.md +16 -0
  5. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/__init__.py +1 -1
  6. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/banner.py +52 -20
  7. commune_cli-0.2.0/commune_cli/commands/context.py +282 -0
  8. commune_cli-0.2.0/commune_cli/commands/describe.py +856 -0
  9. commune_cli-0.2.0/commune_cli/commands/doctor.py +403 -0
  10. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/sms.py +117 -59
  11. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/main.py +9 -0
  12. {commune_cli-0.1.9 → commune_cli-0.2.0}/pyproject.toml +1 -1
  13. commune_cli-0.1.9/.gitignore +0 -89
  14. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/client.py +0 -0
  15. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/__init__.py +0 -0
  16. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/attachments.py +0 -0
  17. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/config_cmd.py +0 -0
  18. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/credits.py +0 -0
  19. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/data.py +0 -0
  20. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/delivery.py +0 -0
  21. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/dmarc.py +0 -0
  22. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/domains.py +0 -0
  23. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/inboxes.py +0 -0
  24. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/messages.py +0 -0
  25. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/phone_numbers.py +0 -0
  26. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/search.py +0 -0
  27. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/threads.py +0 -0
  28. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/commands/webhooks.py +0 -0
  29. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/config.py +0 -0
  30. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/errors.py +0 -0
  31. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/output.py +0 -0
  32. {commune_cli-0.1.9 → commune_cli-0.2.0}/commune_cli/state.py +0 -0
  33. {commune_cli-0.1.9 → commune_cli-0.2.0}/uv.lock +0 -0
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.pyc
3
+ dist/
4
+ *.egg-info/
5
+ .venv/
6
+ venv/
7
+ .env
8
+ .DS_Store
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2024-2026 Commune
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commune-cli
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: Official CLI for the Commune email API — agent-native, pipe-friendly, covers every API surface.
5
5
  Project-URL: Homepage, https://commune.email
6
6
  Project-URL: Documentation, https://docs.commune.email
7
7
  Project-URL: Repository, https://github.com/commune-email/commune
8
8
  License: MIT
9
+ License-File: LICENSE
9
10
  Keywords: agent,ai,cli,commune,email
10
11
  Classifier: Development Status :: 4 - Beta
11
12
  Classifier: Environment :: Console
@@ -241,3 +242,19 @@ fi
241
242
  ```
242
243
 
243
244
  Full API reference: https://docs.commune.email
245
+
246
+ ---
247
+
248
+ ## Ecosystem
249
+
250
+ | Package | Description |
251
+ |---------|-------------|
252
+ | [commune](https://github.com/shanjai-raj/commune) | Email & SMS infrastructure — self-hostable backend |
253
+ | [commune-ai](https://github.com/shanjai-raj/commune-ai) | TypeScript/Node.js SDK |
254
+ | [commune-python](https://github.com/shanjai-raj/commune-python) | Python SDK |
255
+ | [commune-mcp](https://github.com/shanjai-raj/commune-mcp) | MCP server for Claude Desktop, Cursor, Windsurf |
256
+ | **[commune-cli](https://github.com/shanjai-raj/commune-cli)** | **Command-line interface** |
257
+
258
+ ## License
259
+
260
+ Apache-2.0
@@ -212,3 +212,19 @@ fi
212
212
  ```
213
213
 
214
214
  Full API reference: https://docs.commune.email
215
+
216
+ ---
217
+
218
+ ## Ecosystem
219
+
220
+ | Package | Description |
221
+ |---------|-------------|
222
+ | [commune](https://github.com/shanjai-raj/commune) | Email & SMS infrastructure — self-hostable backend |
223
+ | [commune-ai](https://github.com/shanjai-raj/commune-ai) | TypeScript/Node.js SDK |
224
+ | [commune-python](https://github.com/shanjai-raj/commune-python) | Python SDK |
225
+ | [commune-mcp](https://github.com/shanjai-raj/commune-mcp) | MCP server for Claude Desktop, Cursor, Windsurf |
226
+ | **[commune-cli](https://github.com/shanjai-raj/commune-cli)** | **Command-line interface** |
227
+
228
+ ## License
229
+
230
+ Apache-2.0
@@ -1,3 +1,3 @@
1
1
  """Commune CLI — official command-line interface for the Commune email API."""
2
2
 
3
- __version__ = "0.1.4"
3
+ __version__ = "0.2.0"
@@ -36,18 +36,27 @@ _COLORS = [
36
36
 
37
37
  # ── Command registry ───────────────────────────────────────────────────────
38
38
 
39
+ _AGENT_COMMANDS = [
40
+ ("describe", "full machine-readable API manifest — one call, full understanding"),
41
+ ("context", "org snapshot — auth, domains, inboxes, delivery, credits"),
42
+ ("doctor", "health diagnostics — auth, connectivity, DNS, webhooks"),
43
+ ]
44
+
39
45
  _COMMANDS = [
40
- ("inboxes", "create · list · update · delete · webhooks · schema"),
41
- ("messages", "send · list (pass --thread-id to reply)"),
42
- ("threads", "list · messages · contacts · companies · set-status · tags · assign"),
43
- ("domains", "list · create · verify · records"),
44
- ("search", "full-text search across threads"),
45
- ("delivery", "metrics · events · suppressions · check"),
46
- ("webhooks", "deliveries · retry · health"),
47
- ("attachments", "upload · get · url"),
48
- ("dmarc", "list · summary"),
49
- ("data", "deletion-request · confirm"),
50
- ("config", "set · show · register · status · keys list · keys revoke"),
46
+ ("inboxes", "create · list · update · delete · webhooks · schema"),
47
+ ("messages", "send · list (pass --thread-id to reply)"),
48
+ ("threads", "list · messages · set-status · tags · assign · contacts"),
49
+ ("domains", "list · create · verify · records"),
50
+ ("search", "semantic full-text search across threads"),
51
+ ("delivery", "metrics · events · suppressions · check"),
52
+ ("webhooks", "deliveries · retry · health"),
53
+ ("sms", "send · conversations · thread · search"),
54
+ ("phone-numbers", "list · get · available · provision"),
55
+ ("attachments", "upload · get · url"),
56
+ ("credits", "balance · bundles · checkout"),
57
+ ("dmarc", "reports · summary"),
58
+ ("data", "deletion-request · confirm · status"),
59
+ ("config", "set · show · register · status · keys"),
51
60
  ]
52
61
 
53
62
  _TAGLINE = "email infrastructure for agents"
@@ -66,9 +75,22 @@ def _ascii_art(n: int) -> Text:
66
75
  return t
67
76
 
68
77
 
78
+ def _agent_commands_table() -> Group:
79
+ """Build the agent-native commands section with a highlighted label."""
80
+ label = Text(" agent-native", style="bold rgb(0,210,255)")
81
+
82
+ tbl = Table(box=None, show_header=False, padding=(0, 1), expand=False)
83
+ tbl.add_column("cmd", style="bold bright_cyan", no_wrap=True, min_width=16)
84
+ tbl.add_column("sep", style="dim", no_wrap=True, width=1)
85
+ tbl.add_column("desc", style="white")
86
+ for cmd, desc in _AGENT_COMMANDS:
87
+ tbl.add_row(cmd, "·", desc)
88
+ return Group(label, tbl)
89
+
90
+
69
91
  def _commands_table() -> Table:
70
92
  tbl = Table(box=None, show_header=False, padding=(0, 1), expand=False)
71
- tbl.add_column("cmd", style="bold bright_cyan", no_wrap=True, min_width=12)
93
+ tbl.add_column("cmd", style="bold bright_cyan", no_wrap=True, min_width=16)
72
94
  tbl.add_column("sep", style="dim", no_wrap=True, width=1)
73
95
  tbl.add_column("desc", style="dim white")
74
96
  for cmd, desc in _COMMANDS:
@@ -79,6 +101,7 @@ def _commands_table() -> Table:
79
101
  def _frame(
80
102
  n: int,
81
103
  tagline: str = "",
104
+ show_agent: bool = False,
82
105
  show_commands: bool = False,
83
106
  show_footer: bool = False,
84
107
  ) -> Group:
@@ -95,7 +118,12 @@ def _frame(
95
118
  sub.append(f" v{__version__}", style="bold yellow")
96
119
  parts.append(Padding(sub, (0, 2, 0, 2)))
97
120
 
98
- # Commands section
121
+ # Agent-native commands (highlighted section)
122
+ if show_agent:
123
+ parts.append(Padding(Rule(characters="─", style="rgb(0,178,255)"), (1, 2, 0, 2)))
124
+ parts.append(Padding(_agent_commands_table(), (0, 2, 0, 2)))
125
+
126
+ # Resource commands
99
127
  if show_commands:
100
128
  parts.append(Padding(Rule(characters="─", style="dim"), (1, 2, 0, 2)))
101
129
  parts.append(Padding(_commands_table(), (0, 2, 0, 2)))
@@ -106,9 +134,9 @@ def _frame(
106
134
  foot.append("\n")
107
135
  foot.append("commune <command> --help", style="bold cyan")
108
136
  foot.append(" · ", style="dim")
109
- foot.append("commune.email", style="dim cyan underline")
137
+ foot.append("commune describe --json", style="bold cyan")
110
138
  foot.append(" · ", style="dim")
111
- foot.append("docs.commune.email", style="dim cyan underline")
139
+ foot.append("commune.email", style="dim cyan underline")
112
140
  parts.append(Padding(foot, (0, 2, 1, 2)))
113
141
 
114
142
  return Group(*parts)
@@ -126,7 +154,7 @@ def show_banner(no_color: bool = False) -> None:
126
154
 
127
155
  if not console.is_terminal:
128
156
  # Pipe / agent mode — static, no ANSI escape sequences
129
- console.print(_frame(len(_ASCII_LINES), _TAGLINE, True, True))
157
+ console.print(_frame(len(_ASCII_LINES), _TAGLINE, True, True, True))
130
158
  return
131
159
 
132
160
  tagline = _TAGLINE
@@ -147,11 +175,15 @@ def show_banner(no_color: bool = False) -> None:
147
175
  time.sleep(0.013)
148
176
  live.update(_frame(len(_ASCII_LINES), tagline[:i]))
149
177
 
178
+ time.sleep(0.12)
179
+
180
+ # Stage 3: Agent-native commands (highlighted)
181
+ live.update(_frame(len(_ASCII_LINES), tagline, show_agent=True))
150
182
  time.sleep(0.15)
151
183
 
152
- # Stage 3: Commands drop in
153
- live.update(_frame(len(_ASCII_LINES), tagline, show_commands=True))
184
+ # Stage 4: Resource commands drop in
185
+ live.update(_frame(len(_ASCII_LINES), tagline, show_agent=True, show_commands=True))
154
186
  time.sleep(0.08)
155
187
 
156
- # Stage 4: Footer appears
157
- live.update(_frame(len(_ASCII_LINES), tagline, True, True))
188
+ # Stage 5: Footer appears
189
+ live.update(_frame(len(_ASCII_LINES), tagline, True, True, True))
@@ -0,0 +1,282 @@
1
+ """commune context — full org state snapshot in one call.
2
+
3
+ The equivalent of opening a dashboard and seeing every widget at once.
4
+ Fetches auth, domains, inboxes, delivery health, and credits in parallel
5
+ and presents them as a single unified view.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import time
11
+ from typing import Any, Optional
12
+
13
+ import typer
14
+
15
+ from ..output import print_json
16
+
17
+ app = typer.Typer(help="Full org state snapshot — auth, domains, inboxes, delivery, credits.", no_args_is_help=False)
18
+
19
+
20
+ def _fetch_context(client: Any) -> dict:
21
+ """Fetch all org context from multiple endpoints. Never raises."""
22
+ ctx: dict = {
23
+ "auth": {},
24
+ "domains": [],
25
+ "inboxes": [],
26
+ "delivery": {},
27
+ "webhooks": {},
28
+ "credits": {},
29
+ "phone_numbers": [],
30
+ }
31
+
32
+ # Auth / org info
33
+ try:
34
+ r = client.get("/v1/agent/org")
35
+ if r.is_success:
36
+ org = r.json()
37
+ ctx["auth"] = {
38
+ "org_name": org.get("name", ""),
39
+ "org_id": org.get("id", ""),
40
+ "tier": org.get("tier", ""),
41
+ "status": org.get("status", ""),
42
+ }
43
+ except Exception:
44
+ ctx["auth"] = {"error": "could not reach API"}
45
+
46
+ # Domains
47
+ try:
48
+ r = client.get("/v1/domains")
49
+ if r.is_success:
50
+ data = r.json()
51
+ items = data.get("data", data) if isinstance(data, dict) else data
52
+ if isinstance(items, list):
53
+ ctx["domains"] = [
54
+ {
55
+ "id": d.get("id", ""),
56
+ "name": d.get("name", ""),
57
+ "status": d.get("status", ""),
58
+ }
59
+ for d in items
60
+ ]
61
+ except Exception:
62
+ pass
63
+
64
+ # Inboxes
65
+ try:
66
+ r = client.get("/v1/inboxes")
67
+ if r.is_success:
68
+ data = r.json()
69
+ items = data.get("data", data) if isinstance(data, dict) else data
70
+ if isinstance(items, list):
71
+ ctx["inboxes"] = [
72
+ {
73
+ "id": d.get("id", ""),
74
+ "address": d.get("address", ""),
75
+ "display_name": d.get("displayName") or d.get("display_name"),
76
+ "webhook": bool(d.get("webhook")),
77
+ "domain_name": d.get("domain_name", ""),
78
+ }
79
+ for d in items
80
+ ]
81
+ except Exception:
82
+ pass
83
+
84
+ # Delivery metrics (7d)
85
+ try:
86
+ # Need a domain_id for metrics
87
+ domain_id = ctx["domains"][0]["id"] if ctx["domains"] else None
88
+ if domain_id:
89
+ r = client.get("/v1/delivery/metrics", params={"domain_id": domain_id, "period": "7d"})
90
+ if r.is_success:
91
+ ctx["delivery"] = r.json()
92
+ except Exception:
93
+ pass
94
+
95
+ # Webhook health
96
+ try:
97
+ r = client.get("/v1/webhooks/health")
98
+ if r.is_success:
99
+ ctx["webhooks"] = r.json()
100
+ except Exception:
101
+ pass
102
+
103
+ # Credits
104
+ try:
105
+ r = client.get("/v1/credits/balance")
106
+ if r.is_success:
107
+ ctx["credits"] = r.json()
108
+ except Exception:
109
+ pass
110
+
111
+ # Phone numbers
112
+ try:
113
+ r = client.get("/v1/phone-numbers")
114
+ if r.is_success:
115
+ data = r.json()
116
+ items = data.get("data", data) if isinstance(data, dict) else data
117
+ if isinstance(items, list):
118
+ ctx["phone_numbers"] = [
119
+ {
120
+ "id": d.get("id", ""),
121
+ "number": d.get("phoneNumber") or d.get("phone_number", ""),
122
+ "friendly_name": d.get("friendlyName") or d.get("friendly_name"),
123
+ "type": d.get("type", ""),
124
+ }
125
+ for d in items
126
+ ]
127
+ except Exception:
128
+ pass
129
+
130
+ return ctx
131
+
132
+
133
+ # ── Animated TTY display ──────────────────────────────────────────────────────
134
+
135
+
136
+ def _show_context_tty(ctx_data: dict) -> None:
137
+ """Animated section-by-section reveal of org context."""
138
+ from rich.console import Console, Group
139
+ from rich.live import Live
140
+ from rich.padding import Padding
141
+ from rich.panel import Panel
142
+ from rich.rule import Rule
143
+ from rich.table import Table
144
+ from rich.text import Text
145
+
146
+ console = Console(highlight=False)
147
+
148
+ # ── Build sections ────────────────────────────────────────────────
149
+
150
+ def _header() -> Text:
151
+ t = Text(no_wrap=True)
152
+ t.append(" COMMUNE", style="bold rgb(0,210,255)")
153
+ t.append(" · ", style="dim")
154
+ t.append("Organization Context", style="italic white")
155
+ return t
156
+
157
+ def _auth_section() -> Panel:
158
+ auth = ctx_data.get("auth", {})
159
+ tbl = Table.grid(padding=(0, 2))
160
+ tbl.add_column("key", style="bold dim", no_wrap=True)
161
+ tbl.add_column("value")
162
+ tbl.add_row("org", auth.get("org_name", "[dim]—[/dim]"))
163
+ tbl.add_row("id", auth.get("org_id", "[dim]—[/dim]"))
164
+ tbl.add_row("tier", f"[bold]{auth.get('tier', '—')}[/bold]")
165
+ tbl.add_row("status", auth.get("status", "[dim]—[/dim]"))
166
+ return Panel(tbl, title="[bold bright_cyan]Auth[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
167
+
168
+ def _domains_section() -> Panel:
169
+ domains = ctx_data.get("domains", [])
170
+ if not domains:
171
+ return Panel("[dim]No domains configured[/dim]", title="[bold bright_cyan]Domains[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
172
+ tbl = Table.grid(padding=(0, 2))
173
+ tbl.add_column("name", style="bold white")
174
+ tbl.add_column("status")
175
+ tbl.add_column("id", style="dim")
176
+ for d in domains:
177
+ status = d.get("status", "")
178
+ style = "green" if status == "verified" else "yellow"
179
+ tbl.add_row(d.get("name", ""), f"[{style}]{status}[/{style}]", d.get("id", "")[:12] + "…")
180
+ return Panel(tbl, title="[bold bright_cyan]Domains[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
181
+
182
+ def _inboxes_section() -> Panel:
183
+ inboxes = ctx_data.get("inboxes", [])
184
+ if not inboxes:
185
+ return Panel("[dim]No inboxes[/dim]", title="[bold bright_cyan]Inboxes[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
186
+ tbl = Table.grid(padding=(0, 2))
187
+ tbl.add_column("address", style="bold white")
188
+ tbl.add_column("webhook")
189
+ tbl.add_column("id", style="dim")
190
+ for inbox in inboxes:
191
+ wh = "[green]✓[/green]" if inbox.get("webhook") else "[dim]—[/dim]"
192
+ tbl.add_row(inbox.get("address", ""), wh, inbox.get("id", "")[:12] + "…")
193
+ return Panel(tbl, title=f"[bold bright_cyan]Inboxes ({len(inboxes)})[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
194
+
195
+ def _delivery_section() -> Panel:
196
+ delivery = ctx_data.get("delivery", {})
197
+ if not delivery:
198
+ return Panel("[dim]No delivery data[/dim]", title="[bold bright_cyan]Delivery (7d)[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
199
+ tbl = Table.grid(padding=(0, 2))
200
+ tbl.add_column("metric", style="bold dim")
201
+ tbl.add_column("value")
202
+ for key in ["sent", "delivered", "bounced", "complained", "failed"]:
203
+ val = delivery.get(key, "—")
204
+ style = "red" if key in ("bounced", "complained", "failed") and val and val != "—" and int(str(val)) > 0 else "white"
205
+ tbl.add_row(key, f"[{style}]{val}[/{style}]")
206
+ return Panel(tbl, title="[bold bright_cyan]Delivery (7d)[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
207
+
208
+ def _phone_section() -> Optional[Panel]:
209
+ phones = ctx_data.get("phone_numbers", [])
210
+ if not phones:
211
+ return None
212
+ tbl = Table.grid(padding=(0, 2))
213
+ tbl.add_column("number", style="bold white")
214
+ tbl.add_column("name", style="dim")
215
+ tbl.add_column("type", style="dim")
216
+ for p in phones:
217
+ tbl.add_row(p.get("number", ""), p.get("friendly_name") or "—", p.get("type", ""))
218
+ return Panel(tbl, title=f"[bold bright_cyan]Phone Numbers ({len(phones)})[/bold bright_cyan]", border_style="rgb(0,178,255)", padding=(0, 1))
219
+
220
+ # ── Sections to reveal ────────────────────────────────────────────
221
+
222
+ sections = [
223
+ _auth_section,
224
+ _domains_section,
225
+ _inboxes_section,
226
+ _delivery_section,
227
+ ]
228
+ phone = _phone_section()
229
+ if phone:
230
+ sections.append(lambda: phone) # type: ignore[arg-type]
231
+
232
+ def build_frame(n: int) -> Group:
233
+ parts: list = []
234
+ parts.append(Padding(Rule(characters="─", style="rgb(0,178,255)"), (0, 2, 0, 2)))
235
+ parts.append(Padding(_header(), (0, 2, 0, 2)))
236
+ parts.append(Text())
237
+ for i in range(min(n, len(sections))):
238
+ parts.append(Padding(sections[i](), (0, 2, 0, 2)))
239
+ if n > len(sections):
240
+ parts.append(Padding(Rule(characters="─", style="dim"), (0, 2, 0, 2)))
241
+ return Group(*parts)
242
+
243
+ if not console.is_terminal:
244
+ console.print(build_frame(len(sections) + 1))
245
+ return
246
+
247
+ with Live(build_frame(0), console=console, refresh_per_second=30, transient=False) as live:
248
+ for i in range(1, len(sections) + 2):
249
+ time.sleep(0.1)
250
+ live.update(build_frame(i))
251
+
252
+
253
+ # ── Command ───────────────────────────────────────────────────────────────────
254
+
255
+
256
+ @app.callback(invoke_without_command=True)
257
+ def context(
258
+ ctx: typer.Context,
259
+ json_output: bool = typer.Option(False, "--json", help="Output JSON."),
260
+ ) -> None:
261
+ """Full org state snapshot — auth, domains, inboxes, delivery, credits.
262
+
263
+ Fetches everything in one call so an agent can orient itself immediately.
264
+
265
+ For JSON: commune context --json
266
+ """
267
+ from ..client import CommuneClient
268
+ from ..errors import auth_required_error
269
+ from ..state import AppState
270
+
271
+ state: AppState = ctx.obj or AppState()
272
+ if not state.has_any_auth():
273
+ auth_required_error(json_output=json_output or state.should_json())
274
+
275
+ client = CommuneClient.from_state(state)
276
+ ctx_data = _fetch_context(client)
277
+
278
+ if json_output or state.should_json():
279
+ print_json(ctx_data)
280
+ return
281
+
282
+ _show_context_tty(ctx_data)