github-stars-organizer 0.2.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.
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: github-stars-organizer
3
+ Version: 0.2.0
4
+ Summary: Organize GitHub starred repos into Star Lists — free heuristic categorization, optional LLM
5
+ Project-URL: Homepage, https://github.com/nishal21/github-stars-organizer
6
+ Project-URL: Repository, https://github.com/nishal21/github-stars-organizer
7
+ Project-URL: Issues, https://github.com/nishal21/github-stars-organizer/issues
8
+ Author-email: Nishal K <nishal21@users.noreply.github.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: cli,developer-tools,github,organize,productivity,stars
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Version Control :: Git
20
+ Classifier: Topic :: Utilities
21
+ Requires-Python: >=3.12
22
+ Requires-Dist: beautifulsoup4>=4.12
23
+ Requires-Dist: httpx>=0.27
24
+ Requires-Dist: rich>=13.0
25
+ Provides-Extra: llm
26
+ Requires-Dist: openai>=1.0; extra == 'llm'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # GitHub Stars Organizer
30
+
31
+ [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
32
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
33
+ [![CI](https://github.com/nishal21/github-stars-organizer/actions/workflows/ci.yml/badge.svg)](https://github.com/nishal21/github-stars-organizer/actions/workflows/ci.yml)
34
+
35
+ **Organize 300+ GitHub stars into lists in minutes — free, no AI required.**
36
+
37
+ GitHub's official API can star/unstar repos, but **cannot create or manage Star Lists**. This CLI:
38
+
39
+ 1. Fetches your starred repos (public GitHub API)
40
+ 2. Categorizes them by name, description, language, and topics
41
+ 3. Creates lists and assigns repos via your browser session
42
+
43
+ ### Why this tool?
44
+
45
+ | Tool | Drawback | This project |
46
+ |------|----------|--------------|
47
+ | [github-star-organizer](https://github.com/luoling8192/github-star-organizer) | Requires paid LLM API | **Free heuristic by default** |
48
+ | [ghstars](https://github.com/snowfluke/github-manage-stars-unofficial) | Manual category files only | **Auto-plan + custom rules + optional LLM** |
49
+ | [starred](https://github.com/amirhmoradi/starred) | AI-first, complex | **Simple: plan → review → apply** |
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ # From source
55
+ git clone https://github.com/nishal21/github-stars-organizer.git
56
+ cd github-stars-organizer
57
+ uv sync
58
+
59
+ # Or from PyPI (after v0.2.0 release)
60
+ pip install github-stars-organizer
61
+ ```
62
+
63
+ Requires Python 3.12+ and [uv](https://docs.astral.sh/uv/) (recommended).
64
+
65
+ ## Quick start
66
+
67
+ ### 1. Build a plan (no credentials needed)
68
+
69
+ ```bash
70
+ organize-stars plan --username YOUR_USERNAME
71
+ ```
72
+
73
+ Review `categorization-plan.json`. Edit assignments or add custom rules:
74
+
75
+ ```bash
76
+ cp categories.example.toml categories.toml
77
+ # edit categories.toml
78
+ organize-stars plan --username YOUR_USERNAME --categories categories.toml
79
+ ```
80
+
81
+ ### 2. Configure credentials
82
+
83
+ ```bash
84
+ organize-stars init
85
+ ```
86
+
87
+ Or copy and edit manually:
88
+
89
+ ```bash
90
+ cp config.example.toml config.toml
91
+ ```
92
+
93
+ | Field | How to get it |
94
+ |-------|----------------|
95
+ | `username` | Your GitHub username |
96
+ | `token` | [GitHub token settings](https://github.com/settings/tokens) (classic; `public_repo` if you star private repos) |
97
+ | `cookies` | See [Getting your cookie](#getting-your-browser-cookie) below |
98
+
99
+ ### 3. Preview and apply
100
+
101
+ ```bash
102
+ organize-stars apply --dry-run
103
+ organize-stars apply
104
+ ```
105
+
106
+ View result: `https://github.com/YOUR_USERNAME?tab=stars`
107
+
108
+ If interrupted, resume with:
109
+
110
+ ```bash
111
+ organize-stars apply --resume
112
+ ```
113
+
114
+ ## Getting your browser cookie
115
+
116
+ GitHub Star Lists have no public API — applying lists uses your browser session.
117
+
118
+ 1. Log into [github.com](https://github.com) in Chrome or Edge
119
+ 2. Press **F12** to open DevTools
120
+ 3. Open the **Network** tab
121
+ 4. Refresh the page
122
+ 5. Click any request to `github.com`
123
+ 6. Under **Headers**, find **Cookie**
124
+ 7. Copy the **entire** cookie string into `config.toml` → `[github.session]` → `cookies`
125
+
126
+ Cookies expire every few weeks. Refresh from DevTools if you get CSRF or 403 errors.
127
+
128
+ ## CLI reference
129
+
130
+ ```bash
131
+ organize-stars init [--config config.toml] [--force]
132
+ organize-stars status [--config config.toml]
133
+ organize-stars lists [--config config.toml]
134
+
135
+ organize-stars plan --username USER [--categories categories.toml] [--output plan.json]
136
+ organize-stars plan --config config.toml [--categories categories.toml]
137
+ organize-stars plan --config config.toml --llm # optional AI mode
138
+
139
+ organize-stars apply [--config config.toml] [--plan plan.json] [--dry-run] [--yes] [--resume]
140
+ ```
141
+
142
+ ## Optional LLM mode
143
+
144
+ For smarter categorization, add a `[llm]` section to `config.toml` and install the extra:
145
+
146
+ ```bash
147
+ uv sync --extra llm
148
+ organize-stars plan --config config.toml --llm
149
+ ```
150
+
151
+ Heuristic mode remains the default — no API key required.
152
+
153
+ ## Default categories
154
+
155
+ - AI & LLM
156
+ - Web Dev & Frontend
157
+ - Mobile & Android
158
+ - Backend & APIs
159
+ - Dev Tools & CLI
160
+ - Self-hosting & DevOps
161
+ - Security & Privacy
162
+ - Media & Creative
163
+ - Gaming & Entertainment
164
+ - Go & Systems
165
+ - Learning & Inspiration
166
+ - Misc & Tools
167
+
168
+ Customize via `categories.toml` or edit the plan JSON before applying.
169
+
170
+ ## Troubleshooting
171
+
172
+ | Problem | Fix |
173
+ |---------|-----|
174
+ | CSRF / 403 error | Refresh browser cookie in `config.toml` |
175
+ | Rate limited | Wait a few minutes; reduce `concurrency` in config |
176
+ | More than 32 lists | GitHub hard limit — merge categories in plan or `categories.toml` |
177
+ | Apply interrupted | Run `organize-stars apply --resume` |
178
+ | `config.toml not found` | Run `organize-stars init` |
179
+
180
+ Check setup anytime:
181
+
182
+ ```bash
183
+ organize-stars status
184
+ ```
185
+
186
+ ## Privacy and security
187
+
188
+ - Token and cookies stay in local `config.toml` (gitignored) — never commit them
189
+ - Plan mode reads only **public** repo metadata
190
+ - LLM mode (optional) sends metadata to your configured provider
191
+ - See [SECURITY.md](SECURITY.md)
192
+
193
+ ## Development
194
+
195
+ ```bash
196
+ uv sync --dev
197
+ uv run pytest
198
+ uv run ruff check .
199
+ ```
200
+
201
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
202
+
203
+ ## Attribution
204
+
205
+ Web client adapted from [luoling8192/github-star-organizer](https://github.com/luoling8192/github-star-organizer) (MIT). See [ATTRIBUTION.md](ATTRIBUTION.md).
206
+
207
+ ## License
208
+
209
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,16 @@
1
+ stars_organizer/__init__.py,sha256=Mrp2_JPrfHQk8JfYLYSYPIS2M_Eo732pz1T7uwhsho8,83
2
+ stars_organizer/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
3
+ stars_organizer/apply.py,sha256=6VMLRzMvV1gK5iizXSn8sk1H2OUlXm8dU3bSrbTOQAc,5547
4
+ stars_organizer/categorize.py,sha256=vyLIf7I5Bv6gSu24FH3_2dQWrQhk2Gl10OQprgtBC3k,6472
5
+ stars_organizer/cli.py,sha256=cLq3hbxlb5SYeDo-h23vUhhpWNTv1zeTncskB7kSev0,7835
6
+ stars_organizer/config.py,sha256=k3WWFz1W8fM3fLb8hAxiik0-Z-NbUt57jRgYNzeqtUs,1992
7
+ stars_organizer/github_api.py,sha256=sifiqceMThG71hTcEPYki9oG6XcKKpY-qx7NZJsgWfk,2292
8
+ stars_organizer/github_web.py,sha256=PRSsjbCau9C9pYMQsj-xXlP_ZzoRgL7jYKVTHUny7j8,11469
9
+ stars_organizer/llm_categorize.py,sha256=0pV1xWiOIhpMUs7yNukJNvrh4blPYRrK54qjVtQUKXI,4588
10
+ stars_organizer/models.py,sha256=r6rBucH1UCcZaGnkblaRHv4gTxsT3EE3PGHJI5x8T1Y,988
11
+ stars_organizer/state.py,sha256=ELUWY_rM9DCYrLxodpTfdnYnhCtTooykx-NbyyJNzoc,972
12
+ github_stars_organizer-0.2.0.dist-info/METADATA,sha256=z4FC4WOj---MsFsbKLkAFux6419BQeIDw9AtNSnnEZo,6374
13
+ github_stars_organizer-0.2.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
14
+ github_stars_organizer-0.2.0.dist-info/entry_points.txt,sha256=mPiRXiwLnXQsW-SKLfgXu1xDNG4x4iR-qzoHmKln-Iw,60
15
+ github_stars_organizer-0.2.0.dist-info/licenses/LICENSE,sha256=gIc-_Nua6iVpPBPg8sjkcLzk0suICMIpdA0OzdfmViA,1065
16
+ github_stars_organizer-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ organize-stars = stars_organizer.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nishal21
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.
@@ -0,0 +1,3 @@
1
+ """Organize GitHub starred repositories into Star Lists."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,155 @@
1
+ """Apply a categorization plan to GitHub Star Lists."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections import defaultdict
6
+ from pathlib import Path
7
+
8
+ from rich.console import Console
9
+ from rich.progress import BarColumn, Progress, SpinnerColumn, TaskProgressColumn, TextColumn
10
+
11
+ from .categorize import MAX_LISTS, load_plan
12
+ from .config import load_config
13
+ from .github_api import fetch_starred_repos
14
+ from .github_web import GitHubWebClient
15
+ from .models import Assignment, CategorizationResult
16
+ from .state import DEFAULT_STATE_PATH, ApplyState
17
+
18
+ console = Console()
19
+
20
+
21
+ async def apply_plan(
22
+ *,
23
+ dry_run: bool,
24
+ config_path: Path,
25
+ plan_path: Path,
26
+ yes: bool = False,
27
+ resume: bool = False,
28
+ state_path: Path = DEFAULT_STATE_PATH,
29
+ ) -> None:
30
+ cfg = load_config(config_path)
31
+ assignments_map = load_plan(plan_path)
32
+
33
+ console.print(f"Loaded plan: {len(assignments_map)} repos")
34
+ repos = await fetch_starred_repos(cfg.github)
35
+ if not repos:
36
+ console.print("[red]No starred repos found. Check your GitHub token in config.toml.[/red]")
37
+ return
38
+
39
+ repo_by_name = {r.full_name: r for r in repos}
40
+ missing = [name for name in assignments_map if name not in repo_by_name]
41
+ if missing:
42
+ console.print(
43
+ f"[yellow]Warning: {len(missing)} repos no longer starred (skipped).[/yellow]"
44
+ )
45
+
46
+ assignments = [
47
+ Assignment(repo=name, list_name=list_name)
48
+ for name, list_name in assignments_map.items()
49
+ if name in repo_by_name
50
+ ]
51
+
52
+ by_list: dict[str, list[str]] = defaultdict(list)
53
+ for assignment in assignments:
54
+ by_list[assignment.list_name].append(assignment.repo)
55
+
56
+ console.print("\nPlanned lists:")
57
+ for list_name in sorted(by_list, key=lambda key: (-len(by_list[key]), key)):
58
+ console.print(f" {list_name}: {len(by_list[list_name])} repos")
59
+
60
+ if len(by_list) > MAX_LISTS:
61
+ console.print(
62
+ f"\n[red]Error: plan has {len(by_list)} lists; GitHub max is {MAX_LISTS}.[/red]"
63
+ " Merge categories before applying."
64
+ )
65
+ return
66
+
67
+ if dry_run:
68
+ console.print("\n[yellow]Dry run — no changes applied.[/yellow]")
69
+ return
70
+
71
+ if not yes:
72
+ confirm = console.input(
73
+ "\n[bold]Apply these lists to GitHub? (y/N): [/bold]"
74
+ ).strip().lower()
75
+ if confirm != "y":
76
+ console.print("Aborted.")
77
+ return
78
+
79
+ state = ApplyState.load(state_path) if resume else None
80
+ if state and state.plan_path != str(plan_path.resolve()):
81
+ console.print("[yellow]Resume state is for a different plan; starting fresh.[/yellow]")
82
+ state = None
83
+
84
+ if state is None:
85
+ state = ApplyState(plan_path=str(plan_path.resolve()))
86
+
87
+ already_assigned = set(state.assigned_repos)
88
+ pending = [a for a in assignments if a.repo not in already_assigned]
89
+
90
+ result = CategorizationResult(
91
+ assignments=pending,
92
+ new_lists=sorted(name for name in by_list if name not in state.lists_created),
93
+ )
94
+
95
+ web = GitHubWebClient(cfg.github)
96
+ try:
97
+ existing_lists = await web.get_lists(repos[0])
98
+ list_name_to_id = {item.name: item.id for item in existing_lists}
99
+ for name in state.lists_created:
100
+ for item in existing_lists:
101
+ if item.name == name:
102
+ list_name_to_id[item.name] = item.id
103
+
104
+ if result.new_lists:
105
+ console.print(f"\nCreating {len(result.new_lists)} lists...")
106
+ for name in result.new_lists:
107
+ if name in list_name_to_id:
108
+ continue
109
+ created = await web.create_list(name, repos[0])
110
+ if created:
111
+ list_name_to_id[created.name] = created.id
112
+ state.lists_created.append(created.name)
113
+ state.save(state_path)
114
+ console.print(f" [green]+[/green] {name}")
115
+ else:
116
+ console.print(f" [red]![/red] Failed: {name}")
117
+
118
+ console.print(f"\nAssigning {len(pending)} repos...")
119
+ ok = len(already_assigned)
120
+
121
+ with Progress(
122
+ SpinnerColumn(),
123
+ TextColumn("[progress.description]{task.description}"),
124
+ BarColumn(),
125
+ TaskProgressColumn(),
126
+ console=console,
127
+ ) as progress:
128
+ task = progress.add_task("Assigning repos...", total=len(pending))
129
+ for assignment in pending:
130
+ repo = repo_by_name.get(assignment.repo)
131
+ target_id = list_name_to_id.get(assignment.list_name)
132
+ if not repo or not target_id:
133
+ progress.advance(task)
134
+ continue
135
+ if await web.assign_repo(repo, [target_id]):
136
+ ok += 1
137
+ state.assigned_repos.append(assignment.repo)
138
+ else:
139
+ state.failed_repos.append(assignment.repo)
140
+ state.save(state_path)
141
+ progress.advance(task)
142
+
143
+ if state.failed_repos:
144
+ console.print(
145
+ f"\n[yellow]Done with {len(state.failed_repos)} failures. "
146
+ f"Re-run with --resume to retry.[/yellow]"
147
+ )
148
+ else:
149
+ ApplyState.clear(state_path)
150
+ console.print(
151
+ f"\n[bold green]Done![/bold green] Assigned {ok}/{len(assignments)} repos."
152
+ )
153
+ console.print(f"View: https://github.com/{cfg.github.username}?tab=stars")
154
+ finally:
155
+ await web.close()
@@ -0,0 +1,177 @@
1
+ """Heuristic categorization of starred repositories into broad lists."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import re
7
+ import tomllib
8
+ from collections import defaultdict
9
+ from pathlib import Path
10
+
11
+ from .models import StarredRepo
12
+
13
+ CATEGORIES: dict[str, list[tuple[str, int]]] = {
14
+ "AI & LLM": [
15
+ (r"\b(llm|gpt|claude|openai|gemini|mistral|ollama|whisper|transformer|langchain|copilot|codex|inference|embedding|rag\b|fine-?tun|huggingface|pytorch|tensorflow|neural|speech|tts|text-to-speech|voice|skill\b|agent\b|mcp\b|synthid|deepseek|llama|anthropic)", 3),
16
+ (r"\b(ai\b|machine-learning|ml\b|computer-vision|nlp\b|generative)", 2),
17
+ ],
18
+ "Web Dev & Frontend": [
19
+ (r"\b(react|nextjs|next\.js|vue|svelte|tailwind|frontend|responsive|portfolio|css|html|ui\b|component|design-system|landing|website|web-app|browser|electron|vite|webpack|angular)", 3),
20
+ (r"\b(javascript|typescript|web\b|frontend|css-framework)", 1),
21
+ ],
22
+ "Mobile & Android": [
23
+ (r"\b(android|ios|flutter|dart|kotlin|swift|scrcpy|mobile|apk|iphone|ipad|react-native|expo)", 3),
24
+ ],
25
+ "Dev Tools & CLI": [
26
+ (r"\b(cli\b|terminal|vscode|cursor|git\b|github|developer-tool|devtools|automation|workflow|productivity|dotfiles|neovim|vim|shell|bash|zsh|toolkit|utility|script)", 2),
27
+ (r"\b(debug|lint|format|test|benchmark|monitor|log\b|trace)", 1),
28
+ ],
29
+ "Backend & APIs": [
30
+ (r"\b(api\b|backend|server|fastapi|express|graphql|rest\b|microservice|database|postgres|redis|mongodb|mysql|orm\b|grpc|websocket|auth\b|oauth|jwt)", 3),
31
+ (r"\b(node\b|django|flask|rails|laravel|spring)", 2),
32
+ ],
33
+ "Security & Privacy": [
34
+ (r"\b(security|privacy|vpn|proxy|encrypt|pentest|malware|reverse-engineer|exploit|vulnerability|firewall|tor\b|anonymous|hack\b|ctf\b|red-team|blue-team|atomic-red)", 3),
35
+ ],
36
+ "Media & Creative": [
37
+ (r"\b(video|audio|image|ffmpeg|media|edit|creative|photo|music|podcast|stream|youtube|animation|render|graphics|canvas|figma|design\b|art\b|tts|speech)", 2),
38
+ ],
39
+ "Self-hosting & DevOps": [
40
+ (r"\b(self-host|docker|kubernetes|k8s|homelab|raspberry|router|linux|infra|deploy|cloud|aws|azure|gcp|terraform|ansible|ci/cd|github-actions|nginx|proxy-server|serverless)", 3),
41
+ (r"\b(devops|infrastructure|container|helm|monitoring|grafana|prometheus)", 2),
42
+ ],
43
+ "Gaming & Entertainment": [
44
+ (r"\b(game|gaming|minecraft|steam|emulator|retro|unity|unreal|godot|anime|manga|otaku|dating-app)", 3),
45
+ ],
46
+ "Learning & Inspiration": [
47
+ (r"\b(tutorial|learn|course|awesome-|education|docs\b|guide|example|sample|template|starter|boilerplate|thesis|defense|portfolio|inspiration|list-of|curated|collection)", 2),
48
+ ],
49
+ "Go & Systems": [
50
+ (r"\b(go\b|golang|rust|systems|kernel|embedded|firmware|hardware|c\b|c\+\+|assembly|low-level|performance|memory|compiler)", 2),
51
+ ],
52
+ }
53
+
54
+ # Tie-breakers only when multiple categories score equally (not fallback defaults).
55
+ LANG_HINTS = {
56
+ "typescript": "Web Dev & Frontend",
57
+ "javascript": "Web Dev & Frontend",
58
+ "go": "Go & Systems",
59
+ "rust": "Go & Systems",
60
+ "kotlin": "Mobile & Android",
61
+ "swift": "Mobile & Android",
62
+ "dart": "Mobile & Android",
63
+ "php": "Backend & APIs",
64
+ "ruby": "Backend & APIs",
65
+ "java": "Backend & APIs",
66
+ }
67
+
68
+ MAX_LISTS = 32
69
+
70
+ DEFAULT_CATEGORY = "Misc & Tools"
71
+
72
+
73
+ def load_categories(path: Path) -> dict[str, list[tuple[str, int]]]:
74
+ """Load custom category rules from a TOML file."""
75
+ with open(path, "rb") as f:
76
+ raw = tomllib.load(f)
77
+
78
+ categories: dict[str, list[tuple[str, int]]] = {}
79
+ for entry in raw.get("category", []):
80
+ name = entry["name"]
81
+ weight = int(entry.get("weight", 2))
82
+ patterns = entry.get("patterns", [])
83
+ # User patterns use substring match (e.g. "anime" matches "anime-api").
84
+ categories[name] = [(re.escape(pattern), weight) for pattern in patterns]
85
+ return categories
86
+
87
+
88
+ def merge_categories(
89
+ custom: dict[str, list[tuple[str, int]]] | None = None,
90
+ *,
91
+ override: bool = False,
92
+ ) -> dict[str, list[tuple[str, int]]]:
93
+ """Merge custom categories with defaults. Custom rules are checked first."""
94
+ if not custom:
95
+ return dict(CATEGORIES)
96
+ if override:
97
+ return dict(custom)
98
+ merged = dict(CATEGORIES)
99
+ for name, patterns in custom.items():
100
+ merged[name] = patterns
101
+ return merged
102
+
103
+
104
+ def _repo_text(repo: StarredRepo) -> str:
105
+ return " ".join(
106
+ filter(
107
+ None,
108
+ [
109
+ repo.full_name,
110
+ repo.description,
111
+ repo.language,
112
+ " ".join(repo.topics),
113
+ ],
114
+ )
115
+ ).lower()
116
+
117
+
118
+ def categorize_repo(
119
+ repo: StarredRepo,
120
+ *,
121
+ categories: dict[str, list[tuple[str, int]]] | None = None,
122
+ ) -> str:
123
+ rules = categories or CATEGORIES
124
+ text = _repo_text(repo)
125
+ scores: dict[str, int] = defaultdict(int)
126
+
127
+ for category, patterns in rules.items():
128
+ for pattern, weight in patterns:
129
+ if re.search(pattern, text):
130
+ scores[category] += weight
131
+
132
+ if not scores:
133
+ return DEFAULT_CATEGORY
134
+
135
+ max_score = max(scores.values())
136
+ top = [cat for cat, score in scores.items() if score == max_score]
137
+
138
+ if len(top) == 1:
139
+ return top[0]
140
+
141
+ lang = repo.language.lower() if repo.language else ""
142
+ if lang in LANG_HINTS and LANG_HINTS[lang] in top:
143
+ return LANG_HINTS[lang]
144
+
145
+ return top[0]
146
+
147
+
148
+ def build_plan(
149
+ username: str,
150
+ repos: list[StarredRepo],
151
+ *,
152
+ categories: dict[str, list[tuple[str, int]]] | None = None,
153
+ ) -> dict:
154
+ assignments: dict[str, str] = {}
155
+ by_list: dict[str, list[str]] = defaultdict(list)
156
+
157
+ for repo in repos:
158
+ category = categorize_repo(repo, categories=categories)
159
+ assignments[repo.full_name] = category
160
+ by_list[category].append(repo.full_name)
161
+
162
+ return {
163
+ "username": username,
164
+ "total": len(repos),
165
+ "lists": {name: len(items) for name, items in sorted(by_list.items(), key=lambda x: -len(x[1]))},
166
+ "assignments": assignments,
167
+ }
168
+
169
+
170
+ def save_plan(plan: dict, path: Path) -> None:
171
+ path.parent.mkdir(parents=True, exist_ok=True)
172
+ path.write_text(json.dumps(plan, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
173
+
174
+
175
+ def load_plan(path: Path) -> dict[str, str]:
176
+ data = json.loads(path.read_text(encoding="utf-8"))
177
+ return data["assignments"]