Personal Telegram developer console for GitHub

phase2-20261005-j
audit/commit-drilldown audit/finalize-workspace-menu-security audit/ops-actionability audit/pr-menu-consolidation audit/status-menu-consolidation audit/telegram-menu-e2e audit/telegram-menu-e2e-wave2 chore/actions-node24-runtime cleanup/remove-diag design/cloudflare-ops-read docs/control-plane-2-7-design docs/guide-v2-1-sync docs/menu-audit-final-sync docs/phase2-acceptance-closeout docs/phase2-multifile-design feat/bootstrap-worker feat/cloudflare-ops-read feat/cp2-multifile-final feat/cp2-multifile-workspace feat/cp3-github-write-final feat/cp4-cloudflare-ops-final feat/cp5-cicd-control-plane feat/cp6-incident-manager feat/cp7-automation-engine feat/deep-file-browser feat/final-delivery-16-20 feat/github-advanced-read feat/in-app-guide-v2 feat/navigation-recovery-ux-v2 feat/ops-console-v2-1 feat/persistent-menu-code-input feat/phase2-multifile-workspace feat/phase2-multifile-workspace-v2 feat/plugin-foundation-v1 feat/safe-github-ops feat/self-register-webhook feat/studio-g0-foundation feat/telegram-main-inline-menu feat/telegram-pr-merge feat/ux-platform-8-12 feat/v3a-readonly-copilot feat/workspace-file-upload feature/mobile-repo-browser feature/multi-file-change-set fix/approval-expiry-feedback fix/callback-resilience-and-docs fix/ci-actions-pagination fix/cloudflare-fetch-binding fix/editor-request-body-cap fix/editor-safe-file-options fix/issues-permission-release-empty-ux fix/main-menu-callback-fallback fix/phase2-file-editor-selection fix/phase2-final-ux fix/phase2-workspace-ref-persistence fix/production-auto-deploy fix/provider-write-error-feedback fix/repository-id-navigation-fallback fix/repository-pr-navigation fix/telegram-callback-updates fix/telegram-runtime-diagnostics fix/workspace-editor-flow-v2 fix/workspace-recovery-validation hardening/ci-zero-test-telegram-token hardening/pr1-destructive-totp hardening/pr2-kill-switch main multifile-workspace nexa/edit-BwJEIIY3PW nexa/edit-IPHT8irO7b nexa/edit-b4Od3BIMYd p2-multifile phase2-20261005 phase2-20261005-a phase2-20261005-b phase2-20261005-c phase2-20261005-d phase2-20261005-e phase2-20261005-f phase2-20261005-g phase2-20261005-h phase2-20261005-i phase2-20261005-j phase2-20261005-k phase2-20261005-l phase2-20261005-m phase2-20261005-n phase2-20261005-o phase2-20261005-p phase2-20261005-q phase2-20261005-r phase2-20261005-s phase2-20261005-t phase2-20261005-u phase2-20261005-v phase2-20261005-w phase2-20261005-x phase2-20261005-y phase2-20261005-z phase2-acceptance-closeout phase2-add-file-hotfix phase2-change-set phase2-design-20261005 phase2-design-final phase2-implementation phase2-multifile-implementation phase2-multifile-spec phase2-spec-final phase2-workspace phase2/multifile-workspace plan/nexa-studio-v2-reviewed security/remove-telegram-setup spec/repository-workspace-editor v3a/multifile work/multifile
js 321 lines 14.8 KB
Raw
1 import { GuideMenuManager } from './guide-menu.js';
2 import { DEFAULT_CONFIG } from './config.js';
3
4 const escapeHtml = value => String(value ?? '')
5 .replaceAll('&', '&')
6 .replaceAll('<', '&lt;')
7 .replaceAll('>', '&gt;')
8 .replaceAll('"', '&quot;');
9
10 const mark = ok => ok ? '✅' : '❌';
11 const configuredText = ok => ok ? '✅ پیکربندی شده' : '❌ پیکربندی نشده';
12
13 function backRow(text, callback) {
14 return [{ text, callback_data: callback }];
15 }
16
17 export class OpsMenuManager extends GuideMenuManager {
18 constructor(github, diagnostics) {
19 super(github);
20 this.diagnostics = diagnostics;
21 }
22
23 getMainMenuView() {
24 const view = super.getMainMenuView();
25 const inlineKeyboard = (view.reply_markup?.inline_keyboard || []).map(row => row.map(button => (
26 button.callback_data === 'menu:settings'
27 ? { ...button, text: '⚙️ پیکربندی' }
28 : button
29 )));
30 return { ...view, reply_markup: { ...view.reply_markup, inline_keyboard: inlineKeyboard } };
31 }
32
33 getToolsView() {
34 return {
35 text:
36 `🔧 <b>ابزارهای توسعه و عیب‌یابی</b>
37 <code>🏠 Nexa Dev &gt; 🔧 ابزارها</code>
38 ➖➖➖➖➖➖➖➖➖➖
39 این بخش Diagnostics واقعی و فقط‌خواندنی Nexa است. هیچ‌کدام از ابزارهای این صفحه GitHub WRITE انجام نمی‌دهند.
40
41 • <b>خودآزمایی سیستم:</b> پیش‌نیازهای Runtime، امنیت، Durable Objectها و GitHub را یکجا بررسی می‌کند.
42 • <b>تست اتصال GitHub:</b> یک READ زنده اجرا و تعداد Repositoryهای قابل مشاهده را گزارش می‌کند.
43 • <b>Runtime / Bindings:</b> وضعیت پیکربندی Worker و Durable Objectها را بدون نمایش Secretها نشان می‌دهد.
44 • <b>Plugin Registry:</b> Pluginهای ثبت‌شده و تعداد Actionها را از Registry واقعی می‌خواند.
45 • <b>Ping داخلی:</b> فقط مسیر Callback و Render داخلی Bot را بررسی می‌کند.`,
46 reply_markup: {
47 inline_keyboard: [
48 [{ text: '🩺 خودآزمایی سیستم', callback_data: 'ops:selfcheck' }],
49 [{ text: '🐙 تست اتصال GitHub', callback_data: 'ops:github' }],
50 [
51 { text: '🧱 Runtime / Bindings', callback_data: 'ops:runtime' },
52 { text: '🧩 Plugin Registry', callback_data: 'ops:plugins' }
53 ],
54 [{ text: '🏓 Ping داخلی', callback_data: 'tool:ping' }],
55 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
56 ]
57 }
58 };
59 }
60
61 async getServiceStatusView() {
62 const report = await this.diagnostics.runSelfCheck();
63 const snapshot = report.snapshot;
64 const github = report.github;
65 const githubDetail = github.ok
66 ? `✅ متصل؛ ${github.repositoryCount} Repository قابل مشاهده`
67 : `❌ ناموفق؛ ${escapeHtml(github.error || 'خطای نامشخص')}`;
68
69 return {
70 text:
71 `📊 <b>وضعیت زنده Nexa Dev</b>
72 <code>🏠 Nexa Dev &gt; 📊 وضعیت</code>
73 ➖➖➖➖➖➖➖➖➖➖
74 • <b>Cloudflare Worker:</b> ✅ این درخواست داخل Worker اجرا شد.
75 • <b>Telegram Bot:</b> ${configuredText(snapshot.telegramConfigured)}
76 • <b>Webhook owner lock:</b> ${mark(snapshot.webhookSecretConfigured && snapshot.ownerConfigured)} ${snapshot.webhookSecretConfigured && snapshot.ownerConfigured ? 'فعال' : 'ناقص'}
77 • <b>GitHub live READ:</b> ${githubDetail}
78 • <b>WORKSPACE_STORE Durable Object:</b> ${configuredText(snapshot.workspaceStoreConfigured)}
79 • <b>APPROVAL_REPLAY_GUARD Durable Object:</b> ${configuredText(snapshot.replayGuardConfigured)}
80 • <b>Approval signer:</b> ${configuredText(snapshot.approvalSignerConfigured)}
81 • <b>Plugin Registry:</b> ${snapshot.pluginCount} Plugin / ${snapshot.actionCount} Action
82
83 <b>جمع‌بندی:</b> ${report.ok ? '✅ همهٔ کنترل‌های الزامی این Self-check پاس شدند.' : '⚠️ حداقل یک کنترل الزامی نیاز به بررسی دارد.'}
84
85 این صفحه latency، uptime یا SLA سرویس خارجی را بدون اندازه‌گیری واقعی ادعا نمی‌کند.`,
86 reply_markup: {
87 inline_keyboard: [
88 [{ text: '🔄 بررسی مجدد', callback_data: 'menu:status' }],
89 [{ text: '🩺 جزئیات Self-check', callback_data: 'ops:selfcheck' }],
90 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
91 ]
92 }
93 };
94 }
95
96 getSecurityView() {
97 const snapshot = this.diagnostics.getSnapshot();
98 return {
99 text:
100 `🔐 <b>مرکز امنیت Nexa Dev</b>
101 <code>🏠 Nexa Dev &gt; 🔐 امنیت</code>
102 ➖➖➖➖➖➖➖➖➖➖
103 • <b>Owner-only boundary:</b> ${configuredText(snapshot.ownerConfigured)}
104 • <b>Webhook secret:</b> ${configuredText(snapshot.webhookSecretConfigured)}
105 • <b>Safe Approval signer:</b> ${configuredText(snapshot.approvalSignerConfigured)}
106 • <b>Replay protection:</b> ${configuredText(snapshot.replayGuardConfigured)}
107 • <b>Workspace isolation:</b> ${configuredText(snapshot.workspaceStoreConfigured)}
108 • <b>GitHub credential:</b> ${configuredText(snapshot.githubConfigured)}
109
110 فقط وضعیت پیکربندی نمایش داده می‌شود؛ مقدار Credential یا Secret هرگز در این صفحه نمایش داده نمی‌شود.`,
111 reply_markup: {
112 inline_keyboard: [
113 [{ text: '🛡 خودآزمایی امنیت', callback_data: 'security:selfcheck' }],
114 [
115 { text: '📜 سیاست عملیات', callback_data: 'security:policy' },
116 { text: '✅ Safe Approval', callback_data: 'security:approval' }
117 ],
118 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
119 ]
120 }
121 };
122 }
123
124 getSettingsView() {
125 const snapshot = this.diagnostics.getSnapshot();
126 return {
127 text:
128 `⚙️ <b>مرکز پیکربندی Nexa Dev</b>
129 <code>🏠 Nexa Dev &gt; ⚙️ پیکربندی</code>
130 ➖➖➖➖➖➖➖➖➖➖
131 این بخش در V2.1 عمداً <b>فقط‌خواندنی</b> است تا Secret یا تنظیم حساس از Telegram تغییر نکند.
132
133 • Runtime: <b>${escapeHtml(snapshot.runtime)}</b>
134 • مالک GitHub: <code>${escapeHtml(snapshot.githubOwner)}</code>
135 • Editor: <b>Telegram Mini App</b>
136 • Pluginها: <b>${snapshot.pluginCount}</b>
137
138 برای مشاهده جزئیات هر حوزه یکی از گزینه‌های زیر را باز کنید.`,
139 reply_markup: {
140 inline_keyboard: [
141 [
142 { text: '🧱 Runtime', callback_data: 'config:runtime' },
143 { text: '🔗 Providerها', callback_data: 'config:providers' }
144 ],
145 [
146 { text: '🧑‍💻 Editor', callback_data: 'config:editor' },
147 { text: '🧩 Pluginها', callback_data: 'config:plugins' }
148 ],
149 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
150 ]
151 }
152 };
153 }
154
155 async getSelfCheckView(backCallback = 'menu:tools') {
156 const report = await this.diagnostics.runSelfCheck();
157 const lines = report.checks.map(check => {
158 const detail = check.detail ? ` — ${escapeHtml(check.detail)}` : '';
159 return `• ${mark(check.ok)} <b>${escapeHtml(check.label)}</b>${detail}`;
160 }).join('\n');
161 return {
162 text:
163 `🩺 <b>Self-check Nexa Dev</b>
164 ➖➖➖➖➖➖➖➖➖➖
165 ${lines}
166
167 <b>نتیجه:</b> ${report.ok ? '✅ PASS' : '❌ ATTENTION REQUIRED'}
168 این بررسی READ-only است و هیچ Provider mutation اجرا نمی‌کند.`,
169 reply_markup: { inline_keyboard: [
170 [{ text: '🔄 اجرای مجدد', callback_data: backCallback === 'menu:security' ? 'security:selfcheck' : 'ops:selfcheck' }],
171 backRow(backCallback === 'menu:security' ? '🔙 مرکز امنیت' : '🔙 ابزارها', backCallback)
172 ] }
173 };
174 }
175
176 async getGitHubProbeView(backCallback = 'menu:tools', refreshCallback = 'ops:github') {
177 const probe = await this.diagnostics.probeGitHub();
178 return {
179 text: probe.ok
180 ? `🐙 <b>تست اتصال GitHub</b>\n➖➖➖➖➖➖➖➖➖➖\n✅ READ زنده موفق بود.\nمالک: <code>${escapeHtml(probe.owner)}</code>\nRepositoryهای قابل مشاهده: <b>${probe.repositoryCount}</b>\n\nهیچ WRITEای انجام نشد.`
181 : `🐙 <b>تست اتصال GitHub</b>\n➖➖➖➖➖➖➖➖➖➖\n❌ READ زنده ناموفق بود.\n${escapeHtml(probe.error || 'خطای نامشخص')}\n\nهیچ وضعیت موفق ساختگی نمایش داده نمی‌شود.`,
182 reply_markup: { inline_keyboard: [
183 [{ text: '🔄 تست دوباره', callback_data: refreshCallback }],
184 backRow(backCallback === 'menu:settings' ? '🔙 پیکربندی' : '🔙 ابزارها', backCallback)
185 ] }
186 };
187 }
188
189 getRuntimeView(backCallback = 'menu:tools') {
190 const snapshot = this.diagnostics.getSnapshot();
191 return {
192 text:
193 `🧱 <b>Runtime / Bindings</b>
194 ➖➖➖➖➖➖➖➖➖➖
195 • Runtime: <b>${escapeHtml(snapshot.runtime)}</b>
196 • Telegram Bot: ${configuredText(snapshot.telegramConfigured)}
197 • Webhook secret: ${configuredText(snapshot.webhookSecretConfigured)}
198 • Owner lock: ${configuredText(snapshot.ownerConfigured)}
199 • GitHub credential: ${configuredText(snapshot.githubConfigured)}
200 • WORKSPACE_STORE: ${configuredText(snapshot.workspaceStoreConfigured)}
201 • APPROVAL_REPLAY_GUARD: ${configuredText(snapshot.replayGuardConfigured)}
202 • Approval signer: ${configuredText(snapshot.approvalSignerConfigured)}
203
204 این صفحه فقط وجود پیکربندی را نشان می‌دهد و هیچ Secretی را چاپ نمی‌کند.`,
205 reply_markup: { inline_keyboard: [backRow(backCallback === 'menu:settings' ? '🔙 پیکربندی' : '🔙 ابزارها', backCallback)] }
206 };
207 }
208
209 getPluginsView(backCallback = 'menu:tools') {
210 const summary = this.diagnostics.getPluginSummary();
211 const items = summary.plugins.length
212 ? summary.plugins.map(plugin => `• <b>${escapeHtml(plugin.id)}</b>: ${plugin.actionCount} Action — READ ${plugin.risks.READ} / WRITE ${plugin.risks.WRITE} / DESTRUCTIVE ${plugin.risks.DESTRUCTIVE}`).join('\n')
213 : '<i>Plugin ثبت‌شده‌ای یافت نشد.</i>';
214 return {
215 text:
216 `🧩 <b>Plugin Registry</b>
217 ➖➖➖➖➖➖➖➖➖➖
218 Pluginها: <b>${summary.pluginCount}</b>
219 Actionها: <b>${summary.actionCount}</b>
220
221 ${items}`,
222 reply_markup: { inline_keyboard: [backRow(backCallback === 'menu:settings' ? '🔙 پیکربندی' : '🔙 ابزارها', backCallback)] }
223 };
224 }
225
226 getSecurityPolicyView() {
227 return {
228 text:
229 `📜 <b>سیاست عملیات Nexa Dev</b>
230 ➖➖➖➖➖➖➖➖➖➖
231 • <b>READ:</b> فقط برای Owner مجاز است و بدون Safe Approval قابل اجراست.
232 • <b>WRITE:</b> قبل از Provider mutation به Safe Approval معتبر و Owner-bound نیاز دارد.
233 • <b>DESTRUCTIVE:</b> باید پشت همان Policy مرکزی و تأیید صریح باقی بماند؛ این مرکز امنیت هیچ مسیر دورزدنی ایجاد نمی‌کند.
234 • Approval token به Owner / Action / Risk / Target / Expiry متصل و یک‌بارمصرف است.
235 • Source، Draft، Secret و Signed token نباید وارد Audit log شوند.`,
236 reply_markup: { inline_keyboard: [backRow('🔙 مرکز امنیت', 'menu:security')] }
237 };
238 }
239
240 getApprovalStatusView() {
241 const snapshot = this.diagnostics.getSnapshot();
242 return {
243 text:
244 `✅ <b>وضعیت Safe Approval</b>
245 ➖➖➖➖➖➖➖➖➖➖
246 • Signer: ${configuredText(snapshot.approvalSignerConfigured)}
247 • Durable replay guard: ${configuredText(snapshot.replayGuardConfigured)}
248 • Owner lock: ${configuredText(snapshot.ownerConfigured)}
249
250 WRITE فقط بعد از تأیید معتبر اجرا می‌شود و Approval مصرف‌شده دوباره قابل استفاده نیست.`,
251 reply_markup: { inline_keyboard: [backRow('🔙 مرکز امنیت', 'menu:security')] }
252 };
253 }
254
255 getProvidersView() {
256 const snapshot = this.diagnostics.getSnapshot();
257 return {
258 text:
259 `🔗 <b>Providerها و اتصال‌ها</b>
260 ➖➖➖➖➖➖➖➖➖➖
261 • GitHub owner: <code>${escapeHtml(snapshot.githubOwner)}</code>
262 • GitHub credential: ${configuredText(snapshot.githubConfigured)}
263 • Telegram Bot credential: ${configuredText(snapshot.telegramConfigured)}
264 • Telegram Webhook secret: ${configuredText(snapshot.webhookSecretConfigured)}
265
266 مقادیر Credential نمایش داده نمی‌شوند. برای اعتبارسنجی Provider، تست READ زنده GitHub را مستقیماً اجرا کنید.`,
267 reply_markup: { inline_keyboard: [
268 [{ text: '🐙 تست زنده GitHub', callback_data: 'config:github' }],
269 backRow('🔙 پیکربندی', 'menu:settings')
270 ] }
271 };
272 }
273
274 getEditorConfigView() {
275 return {
276 text:
277 `🧑‍💻 <b>پیکربندی Workspace Editor</b>
278 ➖➖➖➖➖➖➖➖➖➖
279 • نوع: <b>Telegram Mini App</b>
280 • URL: <code>${escapeHtml(DEFAULT_CONFIG.workspaceEditorUrl)}</code>
281 • ذخیره: <b>Durable Draft در WORKSPACE_STORE</b>
282 • GitHub WRITE مستقیم از Editor: <b>ندارد</b>
283 • Commit نهایی: <b>Branch-only + Safe Approval</b>`,
284 reply_markup: { inline_keyboard: [backRow('🔙 پیکربندی', 'menu:settings')] }
285 };
286 }
287
288 async renderByCallback(callbackData) {
289 const [action, target] = String(callbackData || '').split(':');
290
291 if (action === 'menu') {
292 if (target === 'status') return this.getServiceStatusView();
293 if (target === 'tools') return this.getToolsView();
294 if (target === 'security') return this.getSecurityView();
295 if (target === 'settings') return this.getSettingsView();
296 }
297
298 if (action === 'ops') {
299 if (target === 'selfcheck') return this.getSelfCheckView('menu:tools');
300 if (target === 'github') return this.getGitHubProbeView();
301 if (target === 'runtime') return this.getRuntimeView('menu:tools');
302 if (target === 'plugins') return this.getPluginsView('menu:tools');
303 }
304
305 if (action === 'security') {
306 if (target === 'selfcheck') return this.getSelfCheckView('menu:security');
307 if (target === 'policy') return this.getSecurityPolicyView();
308 if (target === 'approval') return this.getApprovalStatusView();
309 }
310
311 if (action === 'config') {
312 if (target === 'runtime') return this.getRuntimeView('menu:settings');
313 if (target === 'providers') return this.getProvidersView();
314 if (target === 'github') return this.getGitHubProbeView('menu:settings', 'config:github');
315 if (target === 'editor') return this.getEditorConfigView();
316 if (target === 'plugins') return this.getPluginsView('menu:settings');
317 }
318
319 return super.renderByCallback(callbackData);
320 }
321 }