tabwright 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.
- tabwright/__init__.py +3 -0
- tabwright/adapters/__init__.py +20 -0
- tabwright/adapters/chromium.py +133 -0
- tabwright/adapters/firefox.py +319 -0
- tabwright/adapters/snss.py +261 -0
- tabwright/cli.py +461 -0
- tabwright/extension/background.js +161 -0
- tabwright/extension/manifest.json +25 -0
- tabwright/gui.py +672 -0
- tabwright/library.py +52 -0
- tabwright/live.py +126 -0
- tabwright/mcp_server.py +107 -0
- tabwright/model.py +183 -0
- tabwright/native_host.py +143 -0
- tabwright/policy.py +36 -0
- tabwright/tools.py +316 -0
- tabwright-0.1.0.dist-info/METADATA +275 -0
- tabwright-0.1.0.dist-info/RECORD +21 -0
- tabwright-0.1.0.dist-info/WHEEL +4 -0
- tabwright-0.1.0.dist-info/entry_points.txt +2 -0
- tabwright-0.1.0.dist-info/licenses/LICENSE +21 -0
tabwright/tools.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"""Tool registry. A tool declares the node kinds it accepts and whether it transforms.
|
|
2
|
+
|
|
3
|
+
Read-only tools return a report. Transforms mutate the node in place and return a
|
|
4
|
+
report of what changed; the CLI then emits the session through the usual sinks.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import collections
|
|
10
|
+
import concurrent.futures
|
|
11
|
+
import urllib.error
|
|
12
|
+
import urllib.parse
|
|
13
|
+
import urllib.request
|
|
14
|
+
from collections.abc import Callable
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from tabwright import model
|
|
19
|
+
from tabwright.model import Group, Node, Session, Tab, Window
|
|
20
|
+
|
|
21
|
+
Report = dict[str, Any]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Tool:
|
|
26
|
+
name: str
|
|
27
|
+
fn: Callable[..., Report]
|
|
28
|
+
scopes: tuple[str, ...]
|
|
29
|
+
transform: bool
|
|
30
|
+
help: str
|
|
31
|
+
options: dict[str, dict] = None # argparse add_argument kwargs by flag
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
REGISTRY: dict[str, Tool] = {}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def tool(name: str, scopes: tuple[str, ...], transform: bool = False, options: dict | None = None):
|
|
38
|
+
def deco(fn):
|
|
39
|
+
REGISTRY[name] = Tool(
|
|
40
|
+
name, fn, scopes, transform, (fn.__doc__ or "").strip().splitlines()[0], options or {}
|
|
41
|
+
)
|
|
42
|
+
return fn
|
|
43
|
+
|
|
44
|
+
return deco
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def containers(node: Node) -> list[list]:
|
|
48
|
+
"""Every list that directly holds tabs within ``node``: window item lists and group tab lists."""
|
|
49
|
+
if isinstance(node, Session):
|
|
50
|
+
return [c for w in node.windows for c in containers(w)]
|
|
51
|
+
if isinstance(node, Window):
|
|
52
|
+
return [node.items, *[g.tabs for g in node.groups()]]
|
|
53
|
+
if isinstance(node, Group):
|
|
54
|
+
return [node.tabs]
|
|
55
|
+
raise TypeError("a tab has no containers")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def tabs_of(node: Node) -> list[Tab]:
|
|
59
|
+
if isinstance(node, Tab):
|
|
60
|
+
return [node]
|
|
61
|
+
if isinstance(node, Group):
|
|
62
|
+
return list(node.tabs)
|
|
63
|
+
return node.tabs()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def domain(url: str) -> str:
|
|
67
|
+
return urllib.parse.urlsplit(url).netloc.lower().removeprefix("www.")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# ---------------------------------------------------------------- read-only
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@tool("find-duplicates", ("session", "window", "group"))
|
|
74
|
+
def find_duplicates(node: Node, **_) -> Report:
|
|
75
|
+
"""Report URLs that occur more than once within the scope."""
|
|
76
|
+
seen = collections.defaultdict(list)
|
|
77
|
+
for t in tabs_of(node):
|
|
78
|
+
seen[t.url].append(t.title)
|
|
79
|
+
dups = {u: ts for u, ts in seen.items() if len(ts) > 1}
|
|
80
|
+
return {"duplicates": dups, "count": sum(len(v) - 1 for v in dups.values())}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@tool("stats", ("session", "window", "group"))
|
|
84
|
+
def stats(node: Node, **_) -> Report:
|
|
85
|
+
"""Count tabs per domain, plus totals."""
|
|
86
|
+
tabs = tabs_of(node)
|
|
87
|
+
by_domain = collections.Counter(domain(t.url) for t in tabs)
|
|
88
|
+
out = {"tabs": len(tabs), "domains": len(by_domain), "by_domain": dict(by_domain.most_common())}
|
|
89
|
+
if isinstance(node, (Session, Window)):
|
|
90
|
+
out["groups"] = sum(len(w.groups()) for w in (node.windows if isinstance(node, Session) else [node]))
|
|
91
|
+
return out
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@tool(
|
|
95
|
+
"export",
|
|
96
|
+
("session", "window", "group", "tab"),
|
|
97
|
+
options={"--format": {"choices": ["md", "urls"], "default": "md"}},
|
|
98
|
+
)
|
|
99
|
+
def export(node: Node, format: str = "md", **_) -> Report:
|
|
100
|
+
"""Render the scope as markdown (groups as headings) or a plain URL list."""
|
|
101
|
+
if format == "urls":
|
|
102
|
+
return {"text": "\n".join(t.url for t in tabs_of(node)) + "\n"}
|
|
103
|
+
lines = []
|
|
104
|
+
|
|
105
|
+
def tab_line(t: Tab) -> str:
|
|
106
|
+
return f"- [{t.title or t.url}]({t.url})"
|
|
107
|
+
|
|
108
|
+
def window(w: Window, i: int):
|
|
109
|
+
lines.append(f"## Window {i}")
|
|
110
|
+
for it in w.items:
|
|
111
|
+
if isinstance(it, Group):
|
|
112
|
+
lines.append(f"\n### {it.title or '(untitled group)'}")
|
|
113
|
+
lines.extend(tab_line(t) for t in it.tabs)
|
|
114
|
+
else:
|
|
115
|
+
lines.append(tab_line(it))
|
|
116
|
+
lines.append("")
|
|
117
|
+
|
|
118
|
+
if isinstance(node, Session):
|
|
119
|
+
for i, w in enumerate(node.windows):
|
|
120
|
+
window(w, i)
|
|
121
|
+
elif isinstance(node, Window):
|
|
122
|
+
window(node, 0)
|
|
123
|
+
elif isinstance(node, Group):
|
|
124
|
+
lines.append(f"### {node.title}")
|
|
125
|
+
lines.extend(tab_line(t) for t in node.tabs)
|
|
126
|
+
else:
|
|
127
|
+
lines.append(tab_line(node))
|
|
128
|
+
return {"text": "\n".join(lines).strip() + "\n"}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _probe(url: str, timeout: float) -> dict:
|
|
132
|
+
req = urllib.request.Request(url, method="HEAD", headers={"User-Agent": "tabwright/0.1"})
|
|
133
|
+
try:
|
|
134
|
+
with urllib.request.urlopen(req, timeout=timeout) as r:
|
|
135
|
+
return {"url": url, "status": r.status, "final_url": r.geturl()}
|
|
136
|
+
except urllib.error.HTTPError as e:
|
|
137
|
+
if e.code in (403, 405): # servers that refuse HEAD get one GET
|
|
138
|
+
try:
|
|
139
|
+
with urllib.request.urlopen(
|
|
140
|
+
urllib.request.Request(url, headers=req.headers), timeout=timeout
|
|
141
|
+
) as r:
|
|
142
|
+
return {"url": url, "status": r.status, "final_url": r.geturl()}
|
|
143
|
+
except urllib.error.HTTPError as e2:
|
|
144
|
+
return {"url": url, "status": e2.code}
|
|
145
|
+
except Exception as e2: # noqa: BLE001
|
|
146
|
+
return {"url": url, "status": None, "error": str(e2)}
|
|
147
|
+
return {"url": url, "status": e.code}
|
|
148
|
+
except Exception as e: # noqa: BLE001
|
|
149
|
+
return {"url": url, "status": None, "error": str(e)[:200]}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@tool(
|
|
153
|
+
"check-urls",
|
|
154
|
+
("session", "window", "group", "tab"),
|
|
155
|
+
options={"--timeout": {"type": float, "default": 10.0}, "--workers": {"type": int, "default": 8}},
|
|
156
|
+
)
|
|
157
|
+
def check_urls(node: Node, timeout: float = 10.0, workers: int = 8, **_) -> Report:
|
|
158
|
+
"""Probe each URL (HEAD, falling back to GET) and report status, redirects and failures."""
|
|
159
|
+
urls = sorted({t.url for t in tabs_of(node) if t.url.startswith(("http://", "https://"))})
|
|
160
|
+
with concurrent.futures.ThreadPoolExecutor(workers) as ex:
|
|
161
|
+
results = list(ex.map(lambda u: _probe(u, timeout), urls))
|
|
162
|
+
bad = [r for r in results if r["status"] is None or r["status"] >= 400]
|
|
163
|
+
moved = [r for r in results if r.get("final_url") not in (None, r["url"])]
|
|
164
|
+
return {"checked": len(results), "bad": bad, "redirected": moved, "results": results}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# ---------------------------------------------------------------- transforms
|
|
168
|
+
|
|
169
|
+
TRACKING = {
|
|
170
|
+
"utm_source",
|
|
171
|
+
"utm_medium",
|
|
172
|
+
"utm_campaign",
|
|
173
|
+
"utm_term",
|
|
174
|
+
"utm_content",
|
|
175
|
+
"utm_id",
|
|
176
|
+
"fbclid",
|
|
177
|
+
"gclid",
|
|
178
|
+
"dclid",
|
|
179
|
+
"msclkid",
|
|
180
|
+
"mc_cid",
|
|
181
|
+
"mc_eid",
|
|
182
|
+
"igshid",
|
|
183
|
+
"ref_src",
|
|
184
|
+
"ref_url",
|
|
185
|
+
"_hsenc",
|
|
186
|
+
"_hsmi",
|
|
187
|
+
"vero_id",
|
|
188
|
+
"yclid",
|
|
189
|
+
"si",
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@tool("dedupe", ("session", "window", "group"), transform=True)
|
|
194
|
+
def dedupe(node: Node, **_) -> Report:
|
|
195
|
+
"""Remove later tabs whose URL already appeared earlier in the scope."""
|
|
196
|
+
seen: set[str] = set()
|
|
197
|
+
removed = []
|
|
198
|
+
for c in containers(node):
|
|
199
|
+
keep = []
|
|
200
|
+
for it in c:
|
|
201
|
+
if isinstance(it, Tab):
|
|
202
|
+
if it.url in seen:
|
|
203
|
+
removed.append(it.url)
|
|
204
|
+
continue
|
|
205
|
+
seen.add(it.url)
|
|
206
|
+
keep.append(it)
|
|
207
|
+
c[:] = keep
|
|
208
|
+
return {"removed": removed, "count": len(removed)}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@tool("strip-tracking-params", ("session", "window", "group", "tab"), transform=True)
|
|
212
|
+
def strip_tracking_params(node: Node, **_) -> Report:
|
|
213
|
+
"""Drop utm_* and similar click-tracking query parameters from URLs."""
|
|
214
|
+
changed = []
|
|
215
|
+
for t in tabs_of(node):
|
|
216
|
+
parts = urllib.parse.urlsplit(t.url)
|
|
217
|
+
q = [
|
|
218
|
+
(k, v)
|
|
219
|
+
for k, v in urllib.parse.parse_qsl(parts.query, keep_blank_values=True)
|
|
220
|
+
if k not in TRACKING
|
|
221
|
+
]
|
|
222
|
+
new = urllib.parse.urlunsplit(parts._replace(query=urllib.parse.urlencode(q)))
|
|
223
|
+
if new != t.url:
|
|
224
|
+
changed.append({"from": t.url, "to": new})
|
|
225
|
+
t.url = new
|
|
226
|
+
return {"changed": changed, "count": len(changed)}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@tool(
|
|
230
|
+
"sort",
|
|
231
|
+
("session", "window", "group"),
|
|
232
|
+
transform=True,
|
|
233
|
+
options={"--by": {"choices": ["domain", "title", "url"], "default": "domain"}},
|
|
234
|
+
)
|
|
235
|
+
def sort(node: Node, by: str = "domain", **_) -> Report:
|
|
236
|
+
"""Sort tabs within each container by domain, title or URL; groups keep their position."""
|
|
237
|
+
key = {
|
|
238
|
+
"domain": lambda t: (domain(t.url), t.url),
|
|
239
|
+
"title": lambda t: t.title.lower(),
|
|
240
|
+
"url": lambda t: t.url,
|
|
241
|
+
}[by]
|
|
242
|
+
for c in containers(node):
|
|
243
|
+
tabs = [it for it in c if isinstance(it, Tab)]
|
|
244
|
+
tabs.sort(key=key)
|
|
245
|
+
it_tabs = iter(tabs)
|
|
246
|
+
c[:] = [next(it_tabs) if isinstance(it, Tab) else it for it in c]
|
|
247
|
+
return {"sorted_by": by}
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@tool(
|
|
251
|
+
"group-by-domain",
|
|
252
|
+
("session", "window"),
|
|
253
|
+
transform=True,
|
|
254
|
+
options={"--min": {"type": int, "default": 2, "help": "minimum tabs per domain to form a group"}},
|
|
255
|
+
)
|
|
256
|
+
def group_by_domain(node: Node, min: int = 2, **_) -> Report:
|
|
257
|
+
"""Collect ungrouped tabs sharing a domain into a new group per domain."""
|
|
258
|
+
made = []
|
|
259
|
+
for w in node.windows if isinstance(node, Session) else [node]:
|
|
260
|
+
loose = [it for it in w.items if isinstance(it, Tab)]
|
|
261
|
+
by = collections.defaultdict(list)
|
|
262
|
+
for t in loose:
|
|
263
|
+
by[domain(t.url)].append(t)
|
|
264
|
+
for d, ts in by.items():
|
|
265
|
+
if len(ts) < min:
|
|
266
|
+
continue
|
|
267
|
+
for t in ts:
|
|
268
|
+
w.items.remove(t)
|
|
269
|
+
w.items.append(Group(title=d, tabs=ts))
|
|
270
|
+
made.append({"domain": d, "tabs": len(ts)})
|
|
271
|
+
return {"groups": made, "count": len(made)}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def move(session: Session, src: str, dst: str, index: int | None = None, before: str | None = None) -> Report:
|
|
275
|
+
"""Move a tab or group (src path) into a window or group (dst path): appended, at ``index``,
|
|
276
|
+
or in front of the node at path ``before`` (which must live in dst)."""
|
|
277
|
+
node = model.find(session, src)
|
|
278
|
+
target = model.find(session, dst)
|
|
279
|
+
anchor = model.find(session, before) if before else None
|
|
280
|
+
if isinstance(node, Window) or isinstance(target, Tab):
|
|
281
|
+
raise SystemExit("move: source must be a tab or group, destination a window or group")
|
|
282
|
+
if isinstance(node, Group) and isinstance(target, Group):
|
|
283
|
+
raise SystemExit("move: a group cannot go inside a group")
|
|
284
|
+
for c in containers(session):
|
|
285
|
+
if node in c:
|
|
286
|
+
c.remove(node)
|
|
287
|
+
break
|
|
288
|
+
dest = target.items if isinstance(target, Window) else target.tabs
|
|
289
|
+
if anchor is not None:
|
|
290
|
+
if anchor not in dest:
|
|
291
|
+
raise SystemExit(f"move: {before} is not directly inside {dst}")
|
|
292
|
+
index = dest.index(anchor)
|
|
293
|
+
dest.insert(len(dest) if index is None else index, node)
|
|
294
|
+
return {"moved": src, "to": dst}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def color(session: Session, path: str, color: str) -> Report:
|
|
298
|
+
"""Colour a group, or a tab: browsers only colour groups, so a tab becomes a one-tab group
|
|
299
|
+
with no title, which shows as a coloured chip and is remembered like any group."""
|
|
300
|
+
if color not in model.GROUP_COLORS:
|
|
301
|
+
raise SystemExit(f"color: choose one of {', '.join(model.GROUP_COLORS)}")
|
|
302
|
+
node = model.find(session, path)
|
|
303
|
+
if isinstance(node, Group):
|
|
304
|
+
node.color = color
|
|
305
|
+
return {"colored": path, "color": color}
|
|
306
|
+
if not isinstance(node, Tab):
|
|
307
|
+
raise SystemExit("color: path must be a tab or a group")
|
|
308
|
+
for w in session.windows:
|
|
309
|
+
if node in w.items:
|
|
310
|
+
w.items[w.items.index(node)] = Group(color=color, tabs=[node])
|
|
311
|
+
return {"colored": path, "color": color, "wrapped": True}
|
|
312
|
+
for g in w.groups():
|
|
313
|
+
if node in g.tabs: # already grouped: the group is the coloured thing
|
|
314
|
+
g.color = color
|
|
315
|
+
return {"colored": path, "color": color, "group": g.title}
|
|
316
|
+
raise SystemExit(f"color: {path} not found")
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tabwright
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Browser session manager: windows, tab groups, tabs and extensions as a browser-neutral model
|
|
5
|
+
Project-URL: Homepage, https://github.com/mostlyharmless-ai/tabwright
|
|
6
|
+
Project-URL: Issues, https://github.com/mostlyharmless-ai/tabwright/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/mostlyharmless-ai/tabwright/blob/main/CHANGELOG.md
|
|
8
|
+
Author: MostlyHarmless-AI
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: brave,browser,chrome,firefox,mcp,pyside6,session,tab-groups,tabs
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Environment :: X11 Applications :: Qt
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Provides-Extra: agent
|
|
26
|
+
Requires-Dist: mcp>=1.2; extra == 'agent'
|
|
27
|
+
Provides-Extra: gui
|
|
28
|
+
Requires-Dist: pyside6>=6.7; extra == 'gui'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# tabwright
|
|
32
|
+
|
|
33
|
+
[](https://github.com/mostlyharmless-ai/tabwright/actions/workflows/ci.yml)
|
|
34
|
+
[](LICENSE)
|
|
35
|
+

|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
**Your browser's windows, tab groups and tabs as a plain, editable model.**
|
|
39
|
+
Inspect them, fix them, save pieces as named sets, recompose, and write back:
|
|
40
|
+
from a CLI, a desktop GUI, or an agent over MCP. Works on the session files of a
|
|
41
|
+
stopped browser, or live inside a running one through a small companion extension.
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
## Why
|
|
46
|
+
|
|
47
|
+
A browser with hundreds of tabs in thirty groups is a working environment, and browsers
|
|
48
|
+
give you almost no tools to manage it: no way to reorder groups in bulk, dedupe, save a
|
|
49
|
+
group for later, or recover an exact layout after a crash scrambles it. tabwright treats
|
|
50
|
+
the tab strip as data. Every write path honours the order you give it.
|
|
51
|
+
|
|
52
|
+
- **Browsers**: Brave, Chrome, Chromium, Edge, Vivaldi (Chromium session files) and
|
|
53
|
+
Firefox, Tor Browser (sessionstore), with a browser-neutral model in between.
|
|
54
|
+
- **Offline**: read the newest session, edit, write it back; the browser restores it on
|
|
55
|
+
the next start. A forced stop leaves a hung browser's files untouched.
|
|
56
|
+
- **Live**: a companion extension snapshots and reconciles the running browser, and lists
|
|
57
|
+
or toggles its extensions.
|
|
58
|
+
- **Tools**: dedupe, find duplicates, check URLs, strip tracking parameters, sort, group by
|
|
59
|
+
domain, export; colour; positional move. One decorated function adds a tool to the CLI,
|
|
60
|
+
the GUI menu and the agent surface at once.
|
|
61
|
+
- **Library**: save any session, window, group or tab as a named set; compose new sessions
|
|
62
|
+
from sets.
|
|
63
|
+
- **Agents**: non-interactive CLI with stable JSON, `tabwright schema`, and `tabwright mcp`.
|
|
64
|
+
|
|
65
|
+
Linux today. The model and the live bridge are platform-neutral; profile discovery and
|
|
66
|
+
process control are not yet ported elsewhere.
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
uv tool install git+https://github.com/mostlyharmless-ai/tabwright --with 'PySide6>=6.7' --with mcp
|
|
72
|
+
# or, in a checkout
|
|
73
|
+
uv sync --extra gui --extra agent && uv run tabwright --help
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The core has no dependencies. `PySide6` is only for `tabwright gui`, `mcp` only for
|
|
77
|
+
`tabwright mcp`.
|
|
78
|
+
|
|
79
|
+
## Quick start
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
tabwright list -b brave --tabs # tree of the profile's newest session
|
|
83
|
+
tabwright list --live --tabs # the running browser, via the companion
|
|
84
|
+
tabwright dedupe --live --dry-run # what would change; nothing written
|
|
85
|
+
tabwright dedupe --live --apply # do it, live
|
|
86
|
+
tabwright save work w0/g2 # save a group as a named set
|
|
87
|
+
tabwright compose work notes research --apply # new session from three named sets
|
|
88
|
+
tabwright gui # the desktop GUI
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Recovering from a hang:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
tabwright stop -b brave --force # SIGKILL: session files stay as on disk
|
|
95
|
+
tabwright drop w3 --rescue-to w0 --apply # remove a window, keep its unique tabs
|
|
96
|
+
tabwright start -b brave # browser offers to restore the edited session
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Node paths: `w0` window, `w0/g2` item 2 of window 0 (a group), `w0/g2/t1` tab in a
|
|
100
|
+
group, `w0/t5` fifth tab of the window counting through groups.
|
|
101
|
+
|
|
102
|
+
Every command that produces a session accepts `--json`, `--out FILE` (the browser's
|
|
103
|
+
native format), `--apply` (into the stopped browser's profile), `--live --apply` (into
|
|
104
|
+
the running browser) or `--dry-run`.
|
|
105
|
+
|
|
106
|
+
## Tools
|
|
107
|
+
|
|
108
|
+
Each tool is a subcommand that takes an optional scope path (default: the whole
|
|
109
|
+
session) and refuses scopes it does not apply to. `tabwright tools` lists them.
|
|
110
|
+
|
|
111
|
+
| Tool | Kind | Scopes |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| `find-duplicates` | report | session, window, group |
|
|
114
|
+
| `stats` | report | session, window, group |
|
|
115
|
+
| `export --format md\|urls` | report | session, window, group, tab |
|
|
116
|
+
| `check-urls --timeout --workers` | report | session, window, group, tab |
|
|
117
|
+
| `dedupe` | transform | session, window, group |
|
|
118
|
+
| `strip-tracking-params` | transform | session, window, group, tab |
|
|
119
|
+
| `sort --by domain\|title\|url` | transform | session, window, group |
|
|
120
|
+
| `group-by-domain --min N` | transform | session, window |
|
|
121
|
+
| `move SRC DST` | transform | tab or group into window or group |
|
|
122
|
+
| `drop PATH [--rescue-to W]` | transform | window, group, tab |
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
tabwright find-duplicates w2 --json
|
|
126
|
+
tabwright dedupe w2 --dry-run # shows what would change, writes nothing
|
|
127
|
+
tabwright check-urls w0/g3 # dead and redirected URLs in one group
|
|
128
|
+
tabwright export w1 > vercel-tabs.md
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Reports print as JSON with `--json`; transforms print their report to stderr and
|
|
132
|
+
the resulting session through the chosen sink. Adding a tool is one decorated
|
|
133
|
+
function in `tools.py`; the CLI, scope checks and help text follow from the registry.
|
|
134
|
+
|
|
135
|
+
Library: `save NAME [PATH]`, `library`, `show NAME`, `rename OLD NEW`, `delete NAME`,
|
|
136
|
+
`compose NAME... [--separate]`.
|
|
137
|
+
|
|
138
|
+
## GUI
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
uv sync --extra gui && uv run tabwright gui # or: pip install 'tabwright[gui]'
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
A tree of windows, groups and tabs over the same model. Drag and drop moves tabs
|
|
145
|
+
between windows and groups and groups between windows; illegal drops are refused.
|
|
146
|
+
Right-click shows the tools that apply to the selected node kind, plus rename,
|
|
147
|
+
group, ungroup, drop and new window. The top row selects browser and profile, shows
|
|
148
|
+
whether it is running, and offers stop, forced stop, start, and apply (enabled only
|
|
149
|
+
while the browser is stopped). The library pane saves the selection as a named set
|
|
150
|
+
and loads sets into the selection. Reports appear in the pane below the tree.
|
|
151
|
+
|
|
152
|
+
## Live: the companion extension
|
|
153
|
+
|
|
154
|
+
Every source flag set accepts `--live`: the session is read from the running browser
|
|
155
|
+
instead of its session file, and `--apply` writes back into the running browser.
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
tabwright live install -b brave # host manifest + wrapper; prints the extension dir
|
|
159
|
+
tabwright live install -b firefox # Firefox: then about:debugging > Load Temporary Add-on (unsigned)
|
|
160
|
+
# load that dir unpacked (brave://extensions, Developer mode) or pass --load-extension=DIR
|
|
161
|
+
tabwright live status -b brave
|
|
162
|
+
tabwright list --live --tabs
|
|
163
|
+
tabwright dedupe --live --apply # any transform, applied to the running browser
|
|
164
|
+
tabwright list --live --json > s.json # edit, then:
|
|
165
|
+
tabwright push -f s.json --live # reconcile the browser to the file
|
|
166
|
+
tabwright live extensions
|
|
167
|
+
tabwright live extension <id> --disable
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The extension (`src/tabwright/extension`, MV3, permissions `tabs tabGroups management
|
|
171
|
+
nativeMessaging`) connects to the native messaging host `tabwright.native_host`, which
|
|
172
|
+
the browser launches. The host listens on `$XDG_RUNTIME_DIR/tabwright/<browser>.sock`
|
|
173
|
+
and relays one JSON request per connection. Reconcile rules on apply: tabs, groups and
|
|
174
|
+
windows carrying ids in `extra` are moved and regrouped; nodes without ids are created;
|
|
175
|
+
live tabs absent from the session are closed. In the GUI, "Load (bridge)" and "Apply
|
|
176
|
+
(bridge)" use the same path, and the running indicator shows "+ bridge" when the socket
|
|
177
|
+
is up.
|
|
178
|
+
|
|
179
|
+
Chromium reads host manifests from the browser's default user data dir even when it
|
|
180
|
+
runs on `--user-data-dir`; the host finds the actual data dir from its parent process,
|
|
181
|
+
so one `live install` per browser covers every profile and data dir.
|
|
182
|
+
|
|
183
|
+
## Agents
|
|
184
|
+
|
|
185
|
+
`tabwright schema` prints the model's JSON Schema and the command contract. Every command
|
|
186
|
+
is non-interactive: stdout is data, stderr is commentary, exit 0 ok, 1 refused or failed
|
|
187
|
+
with the reason on stderr, 2 usage. With the `agent` extra, `tabwright mcp` serves the
|
|
188
|
+
same contract over the Model Context Protocol on stdio: tools `run` (any CLI argument
|
|
189
|
+
list, returns code/stdout/stderr), `snapshot` (model JSON, live or from file) and `push`
|
|
190
|
+
(model JSON into the running or stopped browser), plus the `tabwright://schema` resource.
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
{"mcpServers": {"tabwright": {"command": "tabwright", "args": ["mcp"]}}}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
uv tool install --editable . --with mcp # or: pip install 'tabwright[agent]'
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Geometry, colour, order
|
|
201
|
+
|
|
202
|
+
Every window carries `geometry` (`x`, `y`, `width`, `height`, `state`), read from and
|
|
203
|
+
written to Chromium session files, Firefox session stores and the live bridge, and kept in
|
|
204
|
+
library sets. Wayland compositors do not let applications place their own windows, so
|
|
205
|
+
there `x`/`y` are stored but ignored and the live snapshot reports them as 0; size and
|
|
206
|
+
state still apply, and under X11 or XWayland placement across screens works as stored.
|
|
207
|
+
|
|
208
|
+
Browsers colour groups, not tabs. `tabwright color PATH COLOR` colours a group, or wraps a
|
|
209
|
+
bare tab in a one-tab untitled group, which shows as a coloured chip and is remembered like
|
|
210
|
+
any group. In the GUI: right-click, Colour….
|
|
211
|
+
|
|
212
|
+
Order is the model. Every list is the tab-strip order and every write path honours it, so
|
|
213
|
+
an agent can reorder by editing the JSON and pushing it back. `move SRC DST` appends by
|
|
214
|
+
default; `--index N` or `--before PATH` places the node. `tabwright schema` prints the
|
|
215
|
+
model's JSON Schema and the command contract (sources, sinks, tools, exit codes).
|
|
216
|
+
|
|
217
|
+
## Firefox and Tor Browser
|
|
218
|
+
|
|
219
|
+
`-b firefox` reads the profile's session store (`sessionstore-backups/recovery.jsonlz4`
|
|
220
|
+
while running or after a crash, else `sessionstore.jsonlz4`). `--profile` is a name from
|
|
221
|
+
`profiles.ini` ("Default" picks the default-marked one); `--data-dir` is an explicit
|
|
222
|
+
profile directory. Both the deb and the snap profile roots are searched. Tab groups
|
|
223
|
+
(Firefox 138+) map onto the model with Firefox's `gray` spelled `grey`. The mozlz4 codec
|
|
224
|
+
is pure Python; files written by tabwright are stored as LZ4 literals, so they are a
|
|
225
|
+
little larger than Firefox's own.
|
|
226
|
+
|
|
227
|
+
Apply writes both session files and leaves `sessionCheckpoints.json` in the
|
|
228
|
+
unfinished-shutdown shape, so Firefox restores the session on launch whatever its
|
|
229
|
+
startup-page setting. `-b tor` resolves the Tor Browser Launcher profile; Tor keeps no
|
|
230
|
+
session on disk, so only the live path can read it.
|
|
231
|
+
|
|
232
|
+
## Extension policy
|
|
233
|
+
|
|
234
|
+
Durable extension state in both families comes from managed policy files, which live in
|
|
235
|
+
root-owned paths. tabwright prints the file and the path; you install it:
|
|
236
|
+
|
|
237
|
+
```sh
|
|
238
|
+
tabwright policy -b brave --block <id> --force <id> > tabwright.json
|
|
239
|
+
sudo install -D -m 644 tabwright.json /etc/brave/policies/managed/tabwright.json
|
|
240
|
+
tabwright policy -b firefox --force uBlock0@raymondhill.net
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## How the write path works
|
|
244
|
+
|
|
245
|
+
Chromium offers no CLI or DevTools route to tab groups, so tabwright edits the
|
|
246
|
+
`Session_*` SNSS file with the browser stopped, then marks the profile as crashed
|
|
247
|
+
so the browser offers to restore on next launch. A forced stop leaves the files
|
|
248
|
+
exactly as on disk; a graceful stop lets the browser rewrite them first.
|
|
249
|
+
|
|
250
|
+
## Model
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{"kind": "session", "browser": "brave", "windows": [
|
|
254
|
+
{"kind": "window", "items": [
|
|
255
|
+
{"kind": "tab", "url": "...", "title": "...", "pinned": false, "active": true, "extra": {}},
|
|
256
|
+
{"kind": "group", "title": "work", "color": "blue", "collapsed": true, "tabs": [...], "extra": {}}
|
|
257
|
+
], "extra": {}}
|
|
258
|
+
], "extra": {}}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`extra` carries browser-specific identifiers; the model ignores it.
|
|
262
|
+
|
|
263
|
+
## Status and roadmap
|
|
264
|
+
|
|
265
|
+
Everything above is implemented and exercised against real Brave and Firefox profiles;
|
|
266
|
+
`docs/PLAN.md` records the design, what has been verified and what has not. Not yet:
|
|
267
|
+
macOS and Windows profile paths, a signed Firefox build of the companion, Safari.
|
|
268
|
+
|
|
269
|
+
## Contributing
|
|
270
|
+
|
|
271
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Changes are listed in [CHANGELOG.md](CHANGELOG.md).
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
tabwright/__init__.py,sha256=9jWp_TdP6dr7npa2TqkcqYcSJZqL38uyEg7eGrg8wbI,65
|
|
2
|
+
tabwright/cli.py,sha256=btmjsTd6i46C2OaS5BlhrAjxNnKp5WHmBvX1sDGhvV0,17133
|
|
3
|
+
tabwright/gui.py,sha256=9WuFgDvyLeXwLtNgw56hLWOS-NkKSIrVwzt-Yw-Dmlg,26079
|
|
4
|
+
tabwright/library.py,sha256=dPZlMYKv8pxlKT8dIlcKiDGVfjNatb659s2mzA8EWuY,1435
|
|
5
|
+
tabwright/live.py,sha256=v6BkBU3aj7Vm7zRHD_KQnYw5s51SAVpLGxUN6YEeyH0,4920
|
|
6
|
+
tabwright/mcp_server.py,sha256=FgUa82n1rUSjZ68EO3Pzz2Px0k0Y1m-FGiRJ-xCzrlQ,3210
|
|
7
|
+
tabwright/model.py,sha256=6wGYX5aWWoyKKr9nYR9n5qfJ5A7oDmxohPDkr_GPAu8,6153
|
|
8
|
+
tabwright/native_host.py,sha256=HqGkHSrGVP9GQ15edGwAyIcpG4r4m1KEFLcdKGtgpCI,4934
|
|
9
|
+
tabwright/policy.py,sha256=Ww3_If826JL6ld48zxp5RRaeHYgSD7l8gRuKXcqYj-g,1537
|
|
10
|
+
tabwright/tools.py,sha256=qyh51YbfiZxG-yMtkKVWYKZuQxqLfb84Q2m1-YdBjBE,11456
|
|
11
|
+
tabwright/adapters/__init__.py,sha256=Kdthx-MoXe5NbDywVIFATyCfdZzRN_VVtcn55xTF9Uw,710
|
|
12
|
+
tabwright/adapters/chromium.py,sha256=DxOWgVh06tbw3R9xHEKR6tTZuRRhDcrKZoBSKiMtCvM,5276
|
|
13
|
+
tabwright/adapters/firefox.py,sha256=Eokd5H5V9bDMHeYhVtQHqyub9YxEnILt6ZomkqLcE2g,12448
|
|
14
|
+
tabwright/adapters/snss.py,sha256=68WQZRab77GCwrPkDFvIW9dVvm35wbLGGpkG99WlUQo,9978
|
|
15
|
+
tabwright/extension/background.js,sha256=laLybM_7siZ89iVFscfFvAwEjLfSn92iHWhjgxw3D2k,6621
|
|
16
|
+
tabwright/extension/manifest.json,sha256=HRyq8oSa41w7WabZRwAig8fV9QxyLi7MJ2_ViujD-po,970
|
|
17
|
+
tabwright-0.1.0.dist-info/METADATA,sha256=tAJErl0yVV0ixhn7tNyMEFkCL6R03vdINQ-DC3W6N4o,12991
|
|
18
|
+
tabwright-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
19
|
+
tabwright-0.1.0.dist-info/entry_points.txt,sha256=JworxvxVRt9YugDjQ0RmhFNDeb7ytLkDUjubnhvQjPU,49
|
|
20
|
+
tabwright-0.1.0.dist-info/licenses/LICENSE,sha256=xB3BlugPsCRvIQExsaGwi_rar4I_vc6OyhCpGZ7lFA8,1074
|
|
21
|
+
tabwright-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MostlyHarmless-AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|