github-ai-mcp 1.0.2__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.
- github_ai_mcp/__init__.py +1 -0
- github_ai_mcp/__main__.py +3 -0
- github_ai_mcp/cli/__init__.py +1 -0
- github_ai_mcp/cli/app.py +128 -0
- github_ai_mcp/config.py +112 -0
- github_ai_mcp/core/__init__.py +1 -0
- github_ai_mcp/core/git_engine.py +76 -0
- github_ai_mcp/core/github_api.py +86 -0
- github_ai_mcp/core/job_engine.py +889 -0
- github_ai_mcp/core/locking.py +41 -0
- github_ai_mcp/desktop/__init__.py +1 -0
- github_ai_mcp/desktop/control.py +26 -0
- github_ai_mcp/desktop/entry.py +77 -0
- github_ai_mcp/desktop/legal.py +9 -0
- github_ai_mcp/desktop/prerequisites.py +31 -0
- github_ai_mcp/desktop/processes.py +116 -0
- github_ai_mcp/desktop/runtime.py +34 -0
- github_ai_mcp/desktop/setup.py +408 -0
- github_ai_mcp/desktop/startup.py +64 -0
- github_ai_mcp/desktop/streams.py +50 -0
- github_ai_mcp/desktop/supervisor.py +358 -0
- github_ai_mcp/desktop/tunnel.py +242 -0
- github_ai_mcp/exceptions.py +6 -0
- github_ai_mcp/gui/__init__.py +1 -0
- github_ai_mcp/gui/app.py +969 -0
- github_ai_mcp/gui/workers.py +26 -0
- github_ai_mcp/security/__init__.py +1 -0
- github_ai_mcp/security/auth_github.py +67 -0
- github_ai_mcp/security/auth_mcp.py +38 -0
- github_ai_mcp/security/paths.py +34 -0
- github_ai_mcp/security/policy.py +40 -0
- github_ai_mcp/security/secret_scan.py +24 -0
- github_ai_mcp/server.py +97 -0
- github_ai_mcp/storage/__init__.py +1 -0
- github_ai_mcp/storage/database.py +88 -0
- github_ai_mcp/tool_definitions.py +185 -0
- github_ai_mcp-1.0.2.dist-info/METADATA +33 -0
- github_ai_mcp-1.0.2.dist-info/RECORD +42 -0
- github_ai_mcp-1.0.2.dist-info/WHEEL +5 -0
- github_ai_mcp-1.0.2.dist-info/entry_points.txt +2 -0
- github_ai_mcp-1.0.2.dist-info/licenses/LICENSE +21 -0
- github_ai_mcp-1.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"""Graphical first-run configuration; credentials never enter JSON or logs."""
|
|
2
|
+
import secrets
|
|
3
|
+
import sys
|
|
4
|
+
import shutil
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from PySide6.QtCore import QTimer
|
|
8
|
+
from PySide6.QtWidgets import (QApplication, QCheckBox, QDialog, QDialogButtonBox, QFileDialog,
|
|
9
|
+
QFormLayout, QLabel, QLineEdit, QPushButton, QMessageBox, QPlainTextEdit, QVBoxLayout, QScrollArea, QWidget)
|
|
10
|
+
|
|
11
|
+
from github_ai_mcp.desktop import startup
|
|
12
|
+
from github_ai_mcp.desktop.tunnel import (SECRET, profile_path, preflight, repair_profile,
|
|
13
|
+
command_text, local_profile, expected_command)
|
|
14
|
+
from github_ai_mcp.config import save_config
|
|
15
|
+
from github_ai_mcp.desktop.prerequisites import check_prerequisites
|
|
16
|
+
from github_ai_mcp.desktop.runtime import bundled_tool
|
|
17
|
+
from github_ai_mcp.core.github_api import GitHub
|
|
18
|
+
from github_ai_mcp.exceptions import AppError
|
|
19
|
+
from github_ai_mcp.gui.workers import Task
|
|
20
|
+
from github_ai_mcp.security.auth_github import get_secret, store_secret, store_token, remove_secret
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Setup(QDialog):
|
|
24
|
+
def __init__(self, config, path, pool, parent=None):
|
|
25
|
+
super().__init__(parent)
|
|
26
|
+
self.config, self.path, self.pool = config, path, pool
|
|
27
|
+
self.task = None
|
|
28
|
+
self.edit_task = None
|
|
29
|
+
self.diagnostic_task = None
|
|
30
|
+
self.setWindowTitle("GitHub-AI-MCP")
|
|
31
|
+
self.resize(780, 750)
|
|
32
|
+
ru = config.locale == "ru"
|
|
33
|
+
outer = QVBoxLayout(self)
|
|
34
|
+
scroll = QScrollArea()
|
|
35
|
+
scroll.setWidgetResizable(True)
|
|
36
|
+
content = QWidget()
|
|
37
|
+
self.content = content
|
|
38
|
+
scroll.setWidget(content)
|
|
39
|
+
outer.addWidget(scroll)
|
|
40
|
+
form = QFormLayout(content)
|
|
41
|
+
self.info = QLabel("Первый запуск: Git, защищённое хранилище, MCP и официальный туннель." if ru else
|
|
42
|
+
"First run: Git, OS credential vault, MCP and official tunnel.")
|
|
43
|
+
self.info.setWordWrap(True)
|
|
44
|
+
outer.addWidget(self.info)
|
|
45
|
+
self.dependencies = QLabel("Проверка компонентов…" if ru else "Checking components…")
|
|
46
|
+
self.dependencies.setWordWrap(True)
|
|
47
|
+
self.dependencies.setOpenExternalLinks(True)
|
|
48
|
+
form.addRow(self.dependencies)
|
|
49
|
+
self.explore = QPushButton("Продолжить без настройки интеграций" if ru else "Explore without configuring integrations")
|
|
50
|
+
self.explore.clicked.connect(self.reject)
|
|
51
|
+
form.addRow(self.explore)
|
|
52
|
+
self.client = QLineEdit(config.tunnel_client or bundled_tool("tunnel-client") or shutil.which("tunnel-client.exe") or shutil.which("tunnel-client") or "")
|
|
53
|
+
form.addRow("Клиент туннеля" if ru else "Tunnel client", self.client)
|
|
54
|
+
browse = QPushButton("Выбрать…" if ru else "Browse…")
|
|
55
|
+
browse.clicked.connect(self.browse)
|
|
56
|
+
form.addRow(browse)
|
|
57
|
+
self.profile = QLineEdit(config.tunnel_profile)
|
|
58
|
+
form.addRow("Профиль" if ru else "Profile", self.profile)
|
|
59
|
+
self.profile_file = QLineEdit(config.tunnel_profile_file)
|
|
60
|
+
form.addRow("YAML профиля" if ru else "Profile YAML", self.profile_file)
|
|
61
|
+
select_profile = QPushButton("Выбрать YAML…" if ru else "Select YAML…")
|
|
62
|
+
select_profile.clicked.connect(self.browse_profile)
|
|
63
|
+
form.addRow(select_profile)
|
|
64
|
+
self.tunnel_key = QLineEdit()
|
|
65
|
+
self.tunnel_key.setEchoMode(QLineEdit.EchoMode.Password)
|
|
66
|
+
form.addRow("Ключ control-plane туннеля" if ru else "Tunnel control-plane runtime key", self.tunnel_key)
|
|
67
|
+
key_note = QLabel("Сохраняется в хранилище ОС. Это не GitHub PAT и не ключ модели OpenAI." if ru else
|
|
68
|
+
"Saved in the OS vault. Separate from GitHub PAT and OpenAI model keys.")
|
|
69
|
+
key_note.setWordWrap(True)
|
|
70
|
+
form.addRow(key_note)
|
|
71
|
+
remove_key = QPushButton("Удалить ключ туннеля" if ru else "Remove tunnel key")
|
|
72
|
+
remove_key.clicked.connect(self.remove_tunnel_key)
|
|
73
|
+
form.addRow(remove_key)
|
|
74
|
+
diagnostics = QPushButton("Проверить профиль и ключ" if ru else "Validate profile and key")
|
|
75
|
+
diagnostics.clicked.connect(self.diagnose_tunnel)
|
|
76
|
+
form.addRow(diagnostics)
|
|
77
|
+
repair = QPushButton("Исправить команду MCP (с резервной копией)" if ru else "Repair MCP command (with backup)")
|
|
78
|
+
repair.clicked.connect(self.repair_tunnel)
|
|
79
|
+
form.addRow(repair)
|
|
80
|
+
edit = QPushButton("Редактор YAML" if ru else "YAML editor")
|
|
81
|
+
edit.clicked.connect(self.edit_profile)
|
|
82
|
+
form.addRow(edit)
|
|
83
|
+
self.token = QLineEdit()
|
|
84
|
+
self.token.setEchoMode(QLineEdit.EchoMode.Password)
|
|
85
|
+
form.addRow("GitHub PAT (необязательно)" if ru else "GitHub PAT (optional)", self.token)
|
|
86
|
+
note = QLabel("PAT проверяется до сохранения. Для приватного Git требуется встроенный GitHub CLI.\n"
|
|
87
|
+
"Используется существующий профиль официального клиента; его вход остаётся у поставщика." if ru else
|
|
88
|
+
"PAT is validated before saving. Private Git also requires the bundled GitHub CLI.\n"
|
|
89
|
+
"Uses an existing official client profile; its sign-in is managed by the provider.")
|
|
90
|
+
note.setWordWrap(True)
|
|
91
|
+
form.addRow(note)
|
|
92
|
+
self.stdio = QLineEdit(expected_command(config, Path(path)))
|
|
93
|
+
self.stdio.setCursorPosition(0)
|
|
94
|
+
self.stdio.setToolTip("Команда канала main в YAML. Сохраните настройки после изменения." if ru else
|
|
95
|
+
"YAML main-channel command. Save settings after editing.")
|
|
96
|
+
form.addRow("Локальная команда stdio" if ru else "Local stdio command", self.stdio)
|
|
97
|
+
reset_stdio = QPushButton("Подставить команду текущей программы" if ru else "Use current application command")
|
|
98
|
+
reset_stdio.clicked.connect(lambda: self.stdio.setText(command_text(self.path)))
|
|
99
|
+
form.addRow(reset_stdio)
|
|
100
|
+
copy_stdio = QPushButton("Скопировать команду stdio" if ru else "Copy stdio command")
|
|
101
|
+
copy_stdio.clicked.connect(lambda: QApplication.clipboard().setText(self.stdio.text()))
|
|
102
|
+
form.addRow(copy_stdio)
|
|
103
|
+
self.copy_button = QPushButton("Скопировать токен MCP" if ru else "Copy MCP token")
|
|
104
|
+
self.copy_button.clicked.connect(self.copy_mcp)
|
|
105
|
+
form.addRow(self.copy_button)
|
|
106
|
+
self.start = QCheckBox("Запускать службы при открытии" if ru else "Start services on launch")
|
|
107
|
+
self.start.setChecked(config.autostart_services)
|
|
108
|
+
form.addRow(self.start)
|
|
109
|
+
self.start_mcp = QCheckBox("Автоматически запускать MCP" if ru else "Start MCP automatically")
|
|
110
|
+
self.start_mcp.setChecked(config.start_mcp)
|
|
111
|
+
form.addRow(self.start_mcp)
|
|
112
|
+
self.start_tunnel = QCheckBox("Автоматически запускать туннель" if ru else "Start optional tunnel automatically")
|
|
113
|
+
self.start_tunnel.setChecked(config.start_tunnel)
|
|
114
|
+
form.addRow(self.start_tunnel)
|
|
115
|
+
self.minimize = QCheckBox("Сворачивать в трей при запуске" if ru else "Minimize to tray on startup")
|
|
116
|
+
self.minimize.setChecked(config.minimize_on_startup)
|
|
117
|
+
form.addRow(self.minimize)
|
|
118
|
+
self.recovery = QCheckBox("Перезапускать службы после сбоя" if ru else "Restart services after failure")
|
|
119
|
+
self.recovery.setChecked(config.restart_services)
|
|
120
|
+
form.addRow(self.recovery)
|
|
121
|
+
self.notifications = QCheckBox("Уведомлять о критических ошибках" if ru else "Notify about critical failures")
|
|
122
|
+
self.notifications.setChecked(config.critical_notifications)
|
|
123
|
+
form.addRow(self.notifications)
|
|
124
|
+
self.windows_start = QCheckBox("Запускать при входе в Windows (текущий пользователь)" if ru else "Launch at Windows sign-in (current user)")
|
|
125
|
+
registration = startup.status(path)
|
|
126
|
+
self.windows_start.setChecked(registration["registered"])
|
|
127
|
+
self.windows_start.setEnabled(sys.platform == "win32")
|
|
128
|
+
form.addRow(self.windows_start)
|
|
129
|
+
self.registration = QLabel()
|
|
130
|
+
self.update_registration()
|
|
131
|
+
self.registration.setWordWrap(True)
|
|
132
|
+
form.addRow(self.registration)
|
|
133
|
+
validate_start = QPushButton("Проверить автозапуск" if ru else "Validate startup")
|
|
134
|
+
validate_start.clicked.connect(self.update_registration)
|
|
135
|
+
form.addRow(validate_start)
|
|
136
|
+
repair_start = QPushButton("Включить / исправить автозапуск" if ru else "Enable / repair startup")
|
|
137
|
+
repair_start.setEnabled(sys.platform == "win32")
|
|
138
|
+
repair_start.clicked.connect(self.repair_startup)
|
|
139
|
+
form.addRow(repair_start)
|
|
140
|
+
details = QPushButton("Открыть автозагрузку Windows" if ru else "Open Windows startup settings")
|
|
141
|
+
details.setEnabled(sys.platform == "win32")
|
|
142
|
+
details.clicked.connect(lambda: __import__("os").startfile("ms-settings:startupapps"))
|
|
143
|
+
form.addRow(details)
|
|
144
|
+
self.background = QCheckBox("Закрытие окна сворачивает в трей" if ru else "Close window to tray")
|
|
145
|
+
self.background.setChecked(config.background_on_close)
|
|
146
|
+
form.addRow(self.background)
|
|
147
|
+
self.buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
|
148
|
+
self.buttons.accepted.connect(self.save)
|
|
149
|
+
self.buttons.rejected.connect(self.reject)
|
|
150
|
+
self.buttons.button(QDialogButtonBox.StandardButton.Save).setText("Сохранить" if ru else "Save")
|
|
151
|
+
self.buttons.button(QDialogButtonBox.StandardButton.Cancel).setText("Отмена" if ru else "Cancel")
|
|
152
|
+
outer.addWidget(self.buttons)
|
|
153
|
+
QTimer.singleShot(0, self.check_components)
|
|
154
|
+
|
|
155
|
+
def update_registration(self):
|
|
156
|
+
registration = startup.status(self.path)
|
|
157
|
+
ru = self.config.locale == "ru"
|
|
158
|
+
if sys.platform != "win32":
|
|
159
|
+
text = "Автозапуск доступен только в Windows" if ru else "Logon startup is available on Windows"
|
|
160
|
+
elif registration["valid"]:
|
|
161
|
+
text = "Автозапуск Windows включён, команда корректна" if ru else "Windows startup enabled; command valid"
|
|
162
|
+
elif registration["registered"]:
|
|
163
|
+
text = "Автозапуск зарегистрирован; требуется исправление" if ru else "Startup registered; repair required"
|
|
164
|
+
else:
|
|
165
|
+
text = "Автозапуск Windows выключен" if ru else "Windows startup disabled"
|
|
166
|
+
self.registration.setText(text)
|
|
167
|
+
|
|
168
|
+
def selected_config(self):
|
|
169
|
+
command = self.stdio.text().strip()
|
|
170
|
+
return self.config.model_copy(update={"tunnel_client": self.selected_client(),
|
|
171
|
+
"tunnel_profile": self.profile.text().strip(), "tunnel_profile_file": self.profile_file.text().strip(),
|
|
172
|
+
"tunnel_stdio_command": "" if command == command_text(self.path) else command})
|
|
173
|
+
|
|
174
|
+
def operation(self, fn):
|
|
175
|
+
if not self.buttons.isEnabled():
|
|
176
|
+
return
|
|
177
|
+
self.buttons.setEnabled(False)
|
|
178
|
+
self.content.setEnabled(False)
|
|
179
|
+
self.task = Task(fn)
|
|
180
|
+
def done(result):
|
|
181
|
+
self.buttons.setEnabled(True)
|
|
182
|
+
self.content.setEnabled(True)
|
|
183
|
+
self.info.setText(str(result))
|
|
184
|
+
self.task.signals.done.connect(done)
|
|
185
|
+
self.task.signals.failed.connect(self.failed)
|
|
186
|
+
self.pool.start(self.task)
|
|
187
|
+
|
|
188
|
+
def browse_profile(self):
|
|
189
|
+
path, _ = QFileDialog.getOpenFileName(self, "YAML", "", "YAML (*.yaml *.yml)")
|
|
190
|
+
if path:
|
|
191
|
+
self.profile_file.setText(path)
|
|
192
|
+
|
|
193
|
+
def remove_tunnel_key(self):
|
|
194
|
+
if QMessageBox.question(self, "GitHub-AI-MCP", "Удалить ключ туннеля из хранилища ОС? / Remove tunnel key from OS vault?") == QMessageBox.StandardButton.Yes:
|
|
195
|
+
def remove():
|
|
196
|
+
remove_secret(SECRET)
|
|
197
|
+
return "Ключ удалён / Key removed"
|
|
198
|
+
self.operation(remove)
|
|
199
|
+
|
|
200
|
+
def diagnose_tunnel(self):
|
|
201
|
+
config = self.selected_config()
|
|
202
|
+
key = self.tunnel_key.text().strip() or None
|
|
203
|
+
self.operation(lambda: (preflight(config, self.path, runtime_key=key), "Профиль и ключ приняты doctor; удалённое подключение не проверено / Doctor accepted profile and key; remote connection unverified")[1])
|
|
204
|
+
|
|
205
|
+
def repair_tunnel(self):
|
|
206
|
+
if QMessageBox.question(self, "GitHub-AI-MCP", "Изменить только команду MCP в профиле? Будет создана копия. / Change only the MCP command with backup?") == QMessageBox.StandardButton.Yes:
|
|
207
|
+
config = self.selected_config()
|
|
208
|
+
self.operation(lambda: "Команда записана в YAML. Сохраните настройки. Ключ и сеть ещё не проверены. Копия: / Command saved; save settings. Key/network not checked. Backup: " + repair_profile(config, self.path))
|
|
209
|
+
|
|
210
|
+
def repair_startup(self):
|
|
211
|
+
if self.windows_start.isChecked():
|
|
212
|
+
try:
|
|
213
|
+
startup.enable(self.path)
|
|
214
|
+
self.update_registration()
|
|
215
|
+
except (OSError, AppError) as error:
|
|
216
|
+
self.info.setText(str(error))
|
|
217
|
+
else:
|
|
218
|
+
self.info.setText("Сначала включите запуск при входе / Select launch at sign-in first")
|
|
219
|
+
|
|
220
|
+
def edit_profile(self):
|
|
221
|
+
if not self.buttons.isEnabled():
|
|
222
|
+
return
|
|
223
|
+
# Explicit local editor. Raw secrets are never put in the editor or diagnostic output.
|
|
224
|
+
try:
|
|
225
|
+
config = self.selected_config()
|
|
226
|
+
path = profile_path(config)
|
|
227
|
+
except AppError as error:
|
|
228
|
+
self.info.setText(str(error))
|
|
229
|
+
return
|
|
230
|
+
class EditorDialog(QDialog):
|
|
231
|
+
def reject(inner):
|
|
232
|
+
if not self.edit_task:
|
|
233
|
+
super(EditorDialog, inner).reject()
|
|
234
|
+
dialog = EditorDialog(self)
|
|
235
|
+
dialog.resize(700, 500)
|
|
236
|
+
layout = QVBoxLayout(dialog)
|
|
237
|
+
from github_ai_mcp.desktop.tunnel import safe_editor_text
|
|
238
|
+
original = path.read_bytes()
|
|
239
|
+
editor = QPlainTextEdit(safe_editor_text(original.decode("utf-8")))
|
|
240
|
+
layout.addWidget(editor)
|
|
241
|
+
note = QLabel("Сохранение: резервная копия и локальная проверка; без сети / Save: backup and local validation; offline")
|
|
242
|
+
layout.addWidget(note)
|
|
243
|
+
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
|
244
|
+
layout.addWidget(buttons)
|
|
245
|
+
def save():
|
|
246
|
+
if self.edit_task:
|
|
247
|
+
return
|
|
248
|
+
text = editor.toPlainText()
|
|
249
|
+
editor.setEnabled(False)
|
|
250
|
+
buttons.setEnabled(False)
|
|
251
|
+
def write():
|
|
252
|
+
import os
|
|
253
|
+
import tempfile
|
|
254
|
+
fd, name = tempfile.mkstemp(suffix=".yaml", dir=path.parent)
|
|
255
|
+
temp = Path(name)
|
|
256
|
+
try:
|
|
257
|
+
with os.fdopen(fd, "w", encoding="utf-8") as stream:
|
|
258
|
+
stream.write(text)
|
|
259
|
+
stream.flush()
|
|
260
|
+
os.fsync(stream.fileno())
|
|
261
|
+
local_profile(config, self.path, path=temp)
|
|
262
|
+
if path.read_bytes() != original:
|
|
263
|
+
raise AppError("PROFILE_CHANGED", "Profile changed; retry / Профиль изменился: повторите")
|
|
264
|
+
# Backups are sanitized if original malformed text contained secrets.
|
|
265
|
+
backup = path.with_name(path.name + ".backup-" + secrets.token_hex(6))
|
|
266
|
+
backup.write_text(safe_editor_text(original.decode("utf-8")), encoding="utf-8")
|
|
267
|
+
os.chmod(backup, 0o600)
|
|
268
|
+
temp.replace(path)
|
|
269
|
+
return True
|
|
270
|
+
finally:
|
|
271
|
+
temp.unlink(missing_ok=True)
|
|
272
|
+
self.edit_task = Task(write)
|
|
273
|
+
def done(_):
|
|
274
|
+
self.edit_task = None
|
|
275
|
+
dialog.accept()
|
|
276
|
+
def failed(error):
|
|
277
|
+
self.edit_task = None
|
|
278
|
+
editor.setEnabled(True)
|
|
279
|
+
buttons.setEnabled(True)
|
|
280
|
+
note.setText(error)
|
|
281
|
+
self.edit_task.signals.done.connect(done)
|
|
282
|
+
self.edit_task.signals.failed.connect(failed)
|
|
283
|
+
self.pool.start(self.edit_task)
|
|
284
|
+
buttons.accepted.connect(save)
|
|
285
|
+
buttons.rejected.connect(dialog.reject)
|
|
286
|
+
dialog.exec()
|
|
287
|
+
|
|
288
|
+
def check_components(self):
|
|
289
|
+
self.diagnostic_task = Task(check_prerequisites)
|
|
290
|
+
def display(result):
|
|
291
|
+
translations = {"Installed": "Установлен", "Missing": "Не найден", "Unusable": "Не работает",
|
|
292
|
+
"Available": "Доступно", "Unavailable": "Недоступно"}
|
|
293
|
+
ru = self.config.locale == "ru"
|
|
294
|
+
labels = {"git": "Git", "gh": "GitHub CLI", "vault": "Хранилище ОС" if ru else "OS vault"}
|
|
295
|
+
self.dependencies.setText("<br>".join(
|
|
296
|
+
f"{labels[name]}: {translations[item['status']] if ru else item['status']} · "
|
|
297
|
+
f"<a href='{item['url']}'>{'Официальная справка' if ru else 'Official help'}</a>"
|
|
298
|
+
for name, item in result.items()))
|
|
299
|
+
self.diagnostic_task.signals.done.connect(display)
|
|
300
|
+
self.diagnostic_task.signals.failed.connect(self.dependencies.setText)
|
|
301
|
+
self.pool.start(self.diagnostic_task)
|
|
302
|
+
|
|
303
|
+
def copy_mcp(self):
|
|
304
|
+
if self.task and not self.buttons.isEnabled():
|
|
305
|
+
return
|
|
306
|
+
self.buttons.setEnabled(False)
|
|
307
|
+
self.copy_button.setEnabled(False)
|
|
308
|
+
self.task = Task(lambda: get_secret("mcp-http"))
|
|
309
|
+
def copy(value):
|
|
310
|
+
self.buttons.setEnabled(True)
|
|
311
|
+
self.copy_button.setEnabled(True)
|
|
312
|
+
clipboard = QApplication.clipboard()
|
|
313
|
+
clipboard.setText(value)
|
|
314
|
+
self.info.setText("Токен скопирован; буфер очистится через 60 секунд" if self.config.locale == "ru" else
|
|
315
|
+
"Token copied; clipboard clears after 60 seconds")
|
|
316
|
+
QTimer.singleShot(60000, lambda: clipboard.clear() if clipboard.text() == value else None)
|
|
317
|
+
self.task.signals.done.connect(copy)
|
|
318
|
+
self.task.signals.failed.connect(self.failed)
|
|
319
|
+
self.pool.start(self.task)
|
|
320
|
+
|
|
321
|
+
def browse(self):
|
|
322
|
+
path, _ = QFileDialog.getOpenFileName(self, "Официальный клиент туннеля" if self.config.locale == "ru" else "Official tunnel client")
|
|
323
|
+
if path:
|
|
324
|
+
self.client.setText(path)
|
|
325
|
+
|
|
326
|
+
def save(self):
|
|
327
|
+
if not self.buttons.isEnabled():
|
|
328
|
+
return
|
|
329
|
+
selected = self.selected_config()
|
|
330
|
+
command_changed = selected.tunnel_stdio_command != self.config.tunnel_stdio_command
|
|
331
|
+
tunnel_key = self.tunnel_key.text().strip()
|
|
332
|
+
client, profile, token = self.selected_client(), self.profile.text().strip(), self.token.text().strip()
|
|
333
|
+
ru = self.config.locale == "ru"
|
|
334
|
+
if client and not Path(client).is_file():
|
|
335
|
+
self.info.setText("Файл клиента не найден" if ru else "Client file not found")
|
|
336
|
+
return
|
|
337
|
+
if not profile or any(ord(c) < 32 for c in profile) or profile.startswith("-"):
|
|
338
|
+
self.info.setText("Неверный профиль" if ru else "Invalid profile")
|
|
339
|
+
return
|
|
340
|
+
if token and QMessageBox.question(self, "GitHub", "Новый PAT заменит существующий локальный токен GitHub. Сохранить?" if ru else
|
|
341
|
+
"The new PAT replaces any existing local GitHub token. Save it?") != QMessageBox.StandardButton.Yes:
|
|
342
|
+
return
|
|
343
|
+
self.buttons.setEnabled(False)
|
|
344
|
+
self.content.setEnabled(False)
|
|
345
|
+
self.copy_button.setEnabled(False)
|
|
346
|
+
self.token.clear()
|
|
347
|
+
self.info.setText("Проверка…" if ru else "Validating…")
|
|
348
|
+
def validate():
|
|
349
|
+
if not shutil.which("git"):
|
|
350
|
+
raise AppError("GIT_UNAVAILABLE", "Установите Git for Windows и повторите настройку" if ru else "Install Git for Windows, then retry Setup")
|
|
351
|
+
expected_command(selected, self.path)
|
|
352
|
+
if command_changed:
|
|
353
|
+
repair_profile(selected, self.path)
|
|
354
|
+
if tunnel_key:
|
|
355
|
+
store_secret(SECRET, tunnel_key)
|
|
356
|
+
if token:
|
|
357
|
+
GitHub(token).request("GET", "/user")
|
|
358
|
+
store_token(token)
|
|
359
|
+
try:
|
|
360
|
+
get_secret("mcp-http")
|
|
361
|
+
except AppError:
|
|
362
|
+
store_secret("mcp-http", secrets.token_urlsafe(32))
|
|
363
|
+
return True
|
|
364
|
+
self.task = Task(validate)
|
|
365
|
+
def done(_):
|
|
366
|
+
self.config.tunnel_client = client
|
|
367
|
+
self.config.tunnel_profile = profile
|
|
368
|
+
self.config.autostart_services = self.start.isChecked()
|
|
369
|
+
self.config.start_mcp = self.start_mcp.isChecked()
|
|
370
|
+
self.config.start_tunnel = self.start_tunnel.isChecked()
|
|
371
|
+
self.config.minimize_on_startup = self.minimize.isChecked()
|
|
372
|
+
self.config.restart_services = self.recovery.isChecked()
|
|
373
|
+
self.config.critical_notifications = self.notifications.isChecked()
|
|
374
|
+
self.config.tunnel_profile_file = self.profile_file.text().strip()
|
|
375
|
+
self.config.tunnel_stdio_command = selected.tunnel_stdio_command
|
|
376
|
+
self.config.background_on_close = self.background.isChecked()
|
|
377
|
+
self.config.setup_complete = True
|
|
378
|
+
try:
|
|
379
|
+
save_config(self.path, self.config)
|
|
380
|
+
if self.windows_start.isEnabled():
|
|
381
|
+
if self.windows_start.isChecked():
|
|
382
|
+
startup.enable(self.path)
|
|
383
|
+
else:
|
|
384
|
+
startup.disable()
|
|
385
|
+
except (OSError, AppError) as error:
|
|
386
|
+
self.failed(str(error))
|
|
387
|
+
return
|
|
388
|
+
self.accept()
|
|
389
|
+
self.tunnel_key.clear()
|
|
390
|
+
self.task.signals.done.connect(done)
|
|
391
|
+
self.task.signals.failed.connect(self.failed)
|
|
392
|
+
self.pool.start(self.task)
|
|
393
|
+
|
|
394
|
+
def selected_client(self):
|
|
395
|
+
value = self.client.text().strip()
|
|
396
|
+
# Never persist _MEIPASS: a new launch has a different temporary path.
|
|
397
|
+
return "" if value == bundled_tool("tunnel-client") else value
|
|
398
|
+
|
|
399
|
+
def failed(self, message):
|
|
400
|
+
self.info.setText(message)
|
|
401
|
+
self.buttons.setEnabled(True)
|
|
402
|
+
self.content.setEnabled(True)
|
|
403
|
+
self.copy_button.setEnabled(True)
|
|
404
|
+
|
|
405
|
+
def reject(self):
|
|
406
|
+
if self.task and not self.buttons.isEnabled():
|
|
407
|
+
return
|
|
408
|
+
super().reject()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""One opt-in HKCU Run value; no elevation, credentials, or shell commands."""
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from github_ai_mcp.exceptions import AppError
|
|
7
|
+
|
|
8
|
+
RUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
|
|
9
|
+
VALUE = "GitHub-AI-MCP"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def command(config_path):
|
|
13
|
+
executable = Path(sys.executable).resolve()
|
|
14
|
+
if getattr(sys, "frozen", False):
|
|
15
|
+
args = [str(executable)]
|
|
16
|
+
else:
|
|
17
|
+
windowed = executable.with_name("pythonw.exe")
|
|
18
|
+
if windowed.is_file():
|
|
19
|
+
executable = windowed
|
|
20
|
+
args = [str(executable), "-m", "github_ai_mcp.desktop.entry"]
|
|
21
|
+
if not executable.is_file() or not Path(config_path).is_file():
|
|
22
|
+
raise AppError("STARTUP_INVALID", "Restore executable/configuration before enabling startup / Восстановите программу и конфигурацию")
|
|
23
|
+
return subprocess.list2cmdline([*args, "--config", str(Path(config_path).resolve()), "--logon"])
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def registry():
|
|
27
|
+
if os.name != "nt":
|
|
28
|
+
raise AppError("WINDOWS_ONLY", "Windows startup is available on Windows / Автозапуск доступен в Windows")
|
|
29
|
+
import winreg
|
|
30
|
+
return winreg
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def status(config_path):
|
|
34
|
+
try:
|
|
35
|
+
reg = registry()
|
|
36
|
+
with reg.OpenKey(reg.HKEY_CURRENT_USER, RUN_KEY) as key:
|
|
37
|
+
actual, kind = reg.QueryValueEx(key, VALUE)
|
|
38
|
+
return {"registered": True, "valid": kind == reg.REG_SZ and actual == command(config_path),
|
|
39
|
+
"mechanism": "HKCU Run", "error": ""}
|
|
40
|
+
except FileNotFoundError:
|
|
41
|
+
return {"registered": False, "valid": False, "mechanism": "HKCU Run", "error": ""}
|
|
42
|
+
except (AppError, OSError) as error:
|
|
43
|
+
return {"registered": False, "valid": False, "mechanism": "HKCU Run", "error": str(error)}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def enable(config_path):
|
|
47
|
+
reg = registry()
|
|
48
|
+
# Legacy installer shortcuts must be disabled first to avoid competing launches.
|
|
49
|
+
legacy = Path(os.environ.get("APPDATA", "")) / "Microsoft/Windows/Start Menu/Programs/Startup/GitHub-AI-MCP.lnk"
|
|
50
|
+
if legacy.is_file():
|
|
51
|
+
raise AppError("STARTUP_CONFLICT", "Remove the old GitHub-AI-MCP startup shortcut first / Удалите старый ярлык GitHub-AI-MCP из автозагрузки")
|
|
52
|
+
value = command(config_path)
|
|
53
|
+
with reg.CreateKeyEx(reg.HKEY_CURRENT_USER, RUN_KEY, 0, reg.KEY_SET_VALUE) as key:
|
|
54
|
+
reg.SetValueEx(key, VALUE, 0, reg.REG_SZ, value)
|
|
55
|
+
return status(config_path)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def disable():
|
|
59
|
+
reg = registry()
|
|
60
|
+
try:
|
|
61
|
+
with reg.OpenKey(reg.HKEY_CURRENT_USER, RUN_KEY, 0, reg.KEY_SET_VALUE) as key:
|
|
62
|
+
reg.DeleteValue(key, VALUE)
|
|
63
|
+
except FileNotFoundError:
|
|
64
|
+
pass
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Recover inherited Windows pipes in PyInstaller's windowed executable.
|
|
2
|
+
|
|
3
|
+
Never allocate a console. Stdout is reserved for JSON-RPC in stdio mode.
|
|
4
|
+
"""
|
|
5
|
+
import ctypes
|
|
6
|
+
import io
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Any, cast
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def inherited_stream(index, mode):
|
|
13
|
+
if os.name != "nt":
|
|
14
|
+
return None
|
|
15
|
+
import msvcrt
|
|
16
|
+
kernel = cast(Any, ctypes).WinDLL("kernel32", use_last_error=True)
|
|
17
|
+
kernel.GetStdHandle.argtypes = [ctypes.c_uint32]
|
|
18
|
+
kernel.GetStdHandle.restype = ctypes.c_void_p
|
|
19
|
+
kernel.GetCurrentProcess.restype = ctypes.c_void_p
|
|
20
|
+
kernel.DuplicateHandle.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
|
|
21
|
+
ctypes.POINTER(ctypes.c_void_p), ctypes.c_uint32,
|
|
22
|
+
ctypes.c_int, ctypes.c_uint32]
|
|
23
|
+
handle = kernel.GetStdHandle(index & 0xffffffff)
|
|
24
|
+
if not handle or handle == ctypes.c_void_p(-1).value:
|
|
25
|
+
return None
|
|
26
|
+
duplicate = ctypes.c_void_p()
|
|
27
|
+
owner = kernel.GetCurrentProcess()
|
|
28
|
+
if not kernel.DuplicateHandle(owner, handle, owner, ctypes.byref(duplicate), 0, False, 2):
|
|
29
|
+
return None
|
|
30
|
+
flags = (os.O_RDONLY if mode == "r" else os.O_WRONLY) | cast(Any, os).O_BINARY
|
|
31
|
+
try:
|
|
32
|
+
fd = cast(Any, msvcrt).open_osfhandle(duplicate.value, flags)
|
|
33
|
+
except OSError:
|
|
34
|
+
kernel.CloseHandle.argtypes = [ctypes.c_void_p]
|
|
35
|
+
kernel.CloseHandle(duplicate)
|
|
36
|
+
return None
|
|
37
|
+
return io.TextIOWrapper(os.fdopen(fd, mode + "b", buffering=0),
|
|
38
|
+
encoding="utf-8", errors="replace", write_through=True)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def prepare_streams(require_input=False):
|
|
42
|
+
for name, index, mode in (("stdin", -10, "r"), ("stdout", -11, "w"), ("stderr", -12, "w")):
|
|
43
|
+
if getattr(sys, name) is None:
|
|
44
|
+
stream = inherited_stream(index, mode)
|
|
45
|
+
if stream is None:
|
|
46
|
+
if require_input and name in {"stdin", "stdout"}:
|
|
47
|
+
raise SystemExit("MCP stdio requires inherited input/output pipes")
|
|
48
|
+
stream = open(os.devnull, mode, encoding="utf-8")
|
|
49
|
+
setattr(sys, name, stream)
|
|
50
|
+
setattr(sys, "__" + name + "__", stream)
|