slak 0.1.0__py3-none-any.whl

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.
slak/__init__.py ADDED
@@ -0,0 +1,16 @@
1
+ # slak — Terminal Slack client
2
+ # Copyright (C) 2026 Toni Leino
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+
slak/__main__.py ADDED
@@ -0,0 +1,161 @@
1
+ # slak — Terminal Slack client
2
+ # Copyright (C) 2026 Toni Leino
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+
17
+ """slak entry point + workspace CLI.
18
+
19
+ slak run (real workspace if a token exists, else demo)
20
+ slak --demo force the seeded demo workspace
21
+ slak --add-workspace paste xoxc token + d cookie to add a workspace
22
+ slak --list-workspaces list configured workspaces
23
+ slak --diagnose print terminal image protocol + custom-emoji status
24
+ slak --mcp run the stdio MCP adapter (bridges to a running slak)
25
+ """
26
+
27
+ from __future__ import annotations
28
+
29
+ import argparse
30
+ import asyncio
31
+ import os
32
+ from pathlib import Path
33
+
34
+ from slak.app import PyslkApp
35
+ from slak.cache import Cache
36
+ from slak.config import Config
37
+ from slak.images import detect_protocol
38
+ from slak.slack import Token, demo_client
39
+ from slak.slack.http import HttpSlackClient, fetch_team_info, token_from_auth_test
40
+ from slak.slack.tokens import load_tokens, save_token
41
+ from slak.workspace import WorkspaceRouter
42
+
43
+ CONFIG_PATH = Path.home() / ".config" / "slak" / "config.toml"
44
+ CACHE_PATH = Path.home() / ".local" / "share" / "slak" / "cache.db"
45
+ THEMES_DIR = Path.home() / ".config" / "slak" / "themes"
46
+
47
+
48
+ def load_config() -> Config:
49
+ if CONFIG_PATH.exists():
50
+ return Config.loads(CONFIG_PATH.read_text())
51
+ return Config()
52
+
53
+
54
+ def pick_token(tokens: list[Token], cfg: Config) -> Token:
55
+ if cfg.default_workspace:
56
+ for ws in cfg.workspaces:
57
+ if ws.slug == cfg.default_workspace and ws.team_id:
58
+ for t in tokens:
59
+ if t.team_id == ws.team_id:
60
+ return t
61
+ return tokens[0]
62
+
63
+
64
+ async def add_workspace_flow() -> None:
65
+ print("Add a Slack workspace using a browser session.")
66
+ print("In your browser dev tools, copy the workspace token and `d` cookie.\n")
67
+ access = input("xoxc token: ").strip()
68
+ cookie = input("d cookie value: ").strip()
69
+ info = await fetch_team_info(access, cookie)
70
+ tok = token_from_auth_test(info, access, cookie)
71
+ save_token(tok)
72
+ print(f"\nāœ“ Saved {tok.team_name} ({tok.team_id}) at {tok.team_domain}.slack.com")
73
+
74
+
75
+ def list_workspaces() -> None:
76
+ tokens = load_tokens()
77
+ if not tokens:
78
+ print("No workspaces. Add one with: slak --add-workspace")
79
+ return
80
+ for t in tokens:
81
+ print(f"{t.team_id}\t{t.team_name}\t{t.team_domain}.slack.com")
82
+
83
+
84
+ async def diagnose() -> None:
85
+ print("=== terminal ===")
86
+ print("detected image protocol:", detect_protocol(dict(os.environ)))
87
+ for var in ("TERM", "TERM_PROGRAM", "KITTY_WINDOW_ID", "COLORTERM"):
88
+ print(f" {var} = {os.environ.get(var)!r}")
89
+ print("=== custom emoji ===")
90
+ tokens = load_tokens()
91
+ if not tokens:
92
+ print("no workspaces configured")
93
+ return
94
+ tok = pick_token(tokens, load_config())
95
+ client = HttpSlackClient(tok)
96
+ try:
97
+ customs = await client.list_custom_emoji()
98
+ except Exception as exc:
99
+ print(f"emoji.list FAILED: {exc!r}")
100
+ return
101
+ finally:
102
+ await client.aclose()
103
+ print(f"workspace: {tok.team_name} ({tok.team_domain})")
104
+ print(f"custom emoji fetched: {len(customs)}")
105
+ for name in list(customs)[:10]:
106
+ print(f" :{name}: -> {customs[name][:70]}")
107
+
108
+
109
+ def main() -> None:
110
+ parser = argparse.ArgumentParser(prog="slak")
111
+ parser.add_argument("--add-workspace", action="store_true")
112
+ parser.add_argument("--list-workspaces", action="store_true")
113
+ parser.add_argument("--diagnose", action="store_true")
114
+ parser.add_argument("--demo", action="store_true")
115
+ parser.add_argument(
116
+ "--mcp", action="store_true",
117
+ help="run the stdio MCP adapter that bridges to a running slak",
118
+ )
119
+ args = parser.parse_args()
120
+
121
+ if args.mcp:
122
+ from slak.mcp import default_socket_path
123
+ from slak.mcp.adapter import run_adapter
124
+
125
+ run_adapter(load_config().mcp_socket_path or default_socket_path())
126
+ return
127
+
128
+ if args.add_workspace:
129
+ asyncio.run(add_workspace_flow())
130
+ return
131
+ if args.list_workspaces:
132
+ list_workspaces()
133
+ return
134
+ if args.diagnose:
135
+ asyncio.run(diagnose())
136
+ return
137
+
138
+ cfg = load_config()
139
+ from slak.themes import load_theme_files
140
+ load_theme_files(THEMES_DIR) # user themes override built-ins by name
141
+ tokens = load_tokens()
142
+ if args.demo or not tokens:
143
+ router = WorkspaceRouter.single(demo_client())
144
+ cache = Cache.open(":memory:")
145
+ config_path = None # don't let a demo session rewrite the real config
146
+ else:
147
+ clients = [HttpSlackClient(t) for t in tokens]
148
+ order = cfg.order_team_ids([t.team_id for t in tokens])
149
+ # honour default_workspace by making it active
150
+ router = WorkspaceRouter(clients, order)
151
+ default = pick_token(tokens, cfg).team_id
152
+ router.set_active(default)
153
+ CACHE_PATH.parent.mkdir(parents=True, exist_ok=True)
154
+ cache = Cache.open(str(CACHE_PATH))
155
+ config_path = CONFIG_PATH
156
+
157
+ PyslkApp(router=router, cache=cache, config=cfg, config_path=config_path).run()
158
+
159
+
160
+ if __name__ == "__main__":
161
+ main()