Personal Telegram developer console for GitHub
hardening/ci-zero-test-telegram-token
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
| 1 | import { DEFAULT_CONFIG } from './config.js'; |
| 2 | |
| 3 | function escapeHtml(value = '') { |
| 4 | return String(value) |
| 5 | .replaceAll('&', '&') |
| 6 | .replaceAll('<', '<') |
| 7 | .replaceAll('>', '>') |
| 8 | .replaceAll('"', '"'); |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Menu Router and UI Generator for Nexa Dev Bot. |
| 13 | * Views never claim external service health unless that view was built from a live API response. |
| 14 | */ |
| 15 | export class MenuManager { |
| 16 | constructor(githubService) { |
| 17 | this.github = githubService; |
| 18 | } |
| 19 | |
| 20 | getMainMenuView() { |
| 21 | const text = |
| 22 | `⚡ <b>Nexa Dev Bot | پنل مدیریت توسعه</b> |
| 23 | ➖➖➖➖➖➖➖➖➖➖ |
| 24 | یکی از بخشهای زیر را انتخاب کنید. |
| 25 | اتصال GitHub هنگام باز کردن مخزنها بهصورت زنده بررسی میشود.`; |
| 26 | |
| 27 | return { |
| 28 | text, |
| 29 | reply_markup: { |
| 30 | inline_keyboard: [ |
| 31 | [ |
| 32 | { text: '📁 مخزنها (پروژهها)', callback_data: 'menu:repos' }, |
| 33 | { text: '📊 وضعیت سرویس', callback_data: 'menu:status' } |
| 34 | ], |
| 35 | [ |
| 36 | { text: '🔧 ابزارهای توسعه', callback_data: 'menu:tools' }, |
| 37 | { text: '⚙️ تنظیمات', callback_data: 'menu:settings' } |
| 38 | ], |
| 39 | [ |
| 40 | { text: '🔐 امنیت', callback_data: 'menu:security' } |
| 41 | ] |
| 42 | ] |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | async getReposListView() { |
| 48 | const repos = await this.github.listRepositories(); |
| 49 | const text = |
| 50 | `📁 <b>فهرست مخزنها و پروژهها</b> |
| 51 | <code>🏠 Nexa Dev > 📁 مخزنها</code> |
| 52 | ➖➖➖➖➖➖➖➖➖➖ |
| 53 | این فهرست از GitHub API دریافت شده است. پروژه مورد نظر را انتخاب کنید:`; |
| 54 | |
| 55 | const inlineKeyboard = []; |
| 56 | for (let i = 0; i < repos.length; i += 2) { |
| 57 | const row = []; |
| 58 | row.push({ |
| 59 | text: `${repos[i].private ? '🔒' : '🌐'} ${repos[i].name}`, |
| 60 | callback_data: `repo:${repos[i].id}` |
| 61 | }); |
| 62 | if (repos[i + 1]) { |
| 63 | row.push({ |
| 64 | text: `${repos[i + 1].private ? '🔒' : '🌐'} ${repos[i + 1].name}`, |
| 65 | callback_data: `repo:${repos[i + 1].id}` |
| 66 | }); |
| 67 | } |
| 68 | inlineKeyboard.push(row); |
| 69 | } |
| 70 | |
| 71 | if (!repos.length) { |
| 72 | inlineKeyboard.push([{ text: '🔄 بررسی مجدد', callback_data: 'menu:repos' }]); |
| 73 | } |
| 74 | inlineKeyboard.push([{ text: '🔙 بازگشت به منوی اصلی', callback_data: 'menu:main' }]); |
| 75 | |
| 76 | return { text, reply_markup: { inline_keyboard: inlineKeyboard } }; |
| 77 | } |
| 78 | |
| 79 | async getRepoDetailView(repoId) { |
| 80 | const repo = await this.github.getRepository(repoId); |
| 81 | const visibility = repo.private ? '🔒 خصوصی' : '🌐 عمومی'; |
| 82 | const archived = repo.archived ? '\n⚠️ وضعیت: آرشیوشده' : ''; |
| 83 | const description = repo.description ? `\n📝 ${escapeHtml(repo.description)}` : ''; |
| 84 | const text = |
| 85 | `📦 <b>پروژه: ${escapeHtml(repo.name)}</b> |
| 86 | <code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repo.name)}</code> |
| 87 | ➖➖➖➖➖➖➖➖➖➖ |
| 88 | 👤 مخزن: <code>${escapeHtml(repo.fullName)}</code> |
| 89 | 👁 دسترسی: ${visibility} |
| 90 | 🌿 شاخه پیشفرض: <code>${escapeHtml(repo.defaultBranch)}</code>${archived}${description} |
| 91 | |
| 92 | اطلاعات بالا از GitHub API دریافت شد. یک عملیات را انتخاب کنید:`; |
| 93 | |
| 94 | return { |
| 95 | text, |
| 96 | reply_markup: { |
| 97 | inline_keyboard: [ |
| 98 | [ |
| 99 | { text: '📂 فایلها', callback_data: `files:${repoId}` }, |
| 100 | { text: '🔀 Pull Requestها', callback_data: `pr:${repoId}` } |
| 101 | ], |
| 102 | [ |
| 103 | { text: '📝 Commitها', callback_data: `commits:${repoId}` }, |
| 104 | { text: '📊 وضعیت / تستها', callback_data: `status:${repoId}` } |
| 105 | ], |
| 106 | [{ text: '🔙 بازگشت به لیست پروژهها', callback_data: 'menu:repos' }] |
| 107 | ] |
| 108 | } |
| 109 | }; |
| 110 | } |
| 111 | |
| 112 | async getPullRequestsView(repoId) { |
| 113 | const prs = await this.github.listPullRequests(repoId); |
| 114 | const prListText = prs.length |
| 115 | ? prs.map(pr => { |
| 116 | const state = pr.merged ? '🟣 Merged' : (pr.state === 'open' ? '🟢 Open' : '🔴 Closed'); |
| 117 | return `• <b>#${pr.number}</b> ${escapeHtml(pr.title)}\n └ <i>${escapeHtml(pr.author)} | ${state}</i>`; |
| 118 | }).join('\n\n') |
| 119 | : '<i>Pull Requestی در پاسخ GitHub یافت نشد.</i>'; |
| 120 | |
| 121 | const text = |
| 122 | `🔀 <b>Pull Requestهای پروژه ${escapeHtml(repoId)}</b> |
| 123 | <code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 🔀 Pull Request</code> |
| 124 | ➖➖➖➖➖➖➖➖➖➖ |
| 125 | ${prListText}`; |
| 126 | |
| 127 | return { |
| 128 | text, |
| 129 | reply_markup: { |
| 130 | inline_keyboard: [[ |
| 131 | { text: '🔄 بروزرسانی', callback_data: `pr:${repoId}` }, |
| 132 | { text: '🔙 بازگشت به پروژه', callback_data: `repo:${repoId}` } |
| 133 | ]] |
| 134 | } |
| 135 | }; |
| 136 | } |
| 137 | |
| 138 | async getCommitsView(repoId) { |
| 139 | const commits = await this.github.listCommits(repoId); |
| 140 | const commitListText = commits.length |
| 141 | ? commits.map(c => `• <code>${escapeHtml(c.sha)}</code> - ${escapeHtml(c.message)}\n └ <i>${escapeHtml(c.author)}${c.date ? ` | ${escapeHtml(c.date)}` : ''}</i>`).join('\n\n') |
| 142 | : '<i>کامیتی در پاسخ GitHub یافت نشد.</i>'; |
| 143 | |
| 144 | const text = |
| 145 | `📝 <b>آخرین Commitهای پروژه ${escapeHtml(repoId)}</b> |
| 146 | <code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 📝 Commitها</code> |
| 147 | ➖➖➖➖➖➖➖➖➖➖ |
| 148 | ${commitListText}`; |
| 149 | |
| 150 | return { |
| 151 | text, |
| 152 | reply_markup: { |
| 153 | inline_keyboard: [[ |
| 154 | { text: '🔄 بروزرسانی', callback_data: `commits:${repoId}` }, |
| 155 | { text: '🔙 بازگشت به پروژه', callback_data: `repo:${repoId}` } |
| 156 | ]] |
| 157 | } |
| 158 | }; |
| 159 | } |
| 160 | |
| 161 | async getFilesView(repoId, subpath = '') { |
| 162 | const files = await this.github.listFiles(repoId, subpath); |
| 163 | const itemsText = files.length |
| 164 | ? files.map(f => { |
| 165 | const icon = f.type === 'dir' ? '📁' : '📄'; |
| 166 | const size = f.type === 'file' && f.size ? ` (${f.size} B)` : ''; |
| 167 | return `${icon} <code>${escapeHtml(f.name)}</code>${size}`; |
| 168 | }).join('\n') |
| 169 | : '<i>پوشه خالی است.</i>'; |
| 170 | |
| 171 | const text = |
| 172 | `📂 <b>ساختار فایلهای پروژه ${escapeHtml(repoId)}</b> |
| 173 | <code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 📂 فایلها${subpath ? ` > ${escapeHtml(subpath)}` : ''}</code> |
| 174 | ➖➖➖➖➖➖➖➖➖➖ |
| 175 | ${itemsText}`; |
| 176 | |
| 177 | return { |
| 178 | text, |
| 179 | reply_markup: { |
| 180 | inline_keyboard: [[ |
| 181 | { text: '🔄 بروزرسانی', callback_data: `files:${repoId}${subpath ? `:${subpath}` : ''}` }, |
| 182 | { text: '🔙 بازگشت به پروژه', callback_data: `repo:${repoId}` } |
| 183 | ]] |
| 184 | } |
| 185 | }; |
| 186 | } |
| 187 | |
| 188 | async getRepoStatusView(repoId) { |
| 189 | const status = await this.github.getRepoStatus(repoId); |
| 190 | const runsText = status.lastRuns.length |
| 191 | ? status.lastRuns.map(r => { |
| 192 | const icon = r.conclusion === 'success' ? '✅' : (r.conclusion === 'failure' ? '❌' : '⏳'); |
| 193 | return `• ${icon} <b>${escapeHtml(r.name)}</b>: ${escapeHtml(r.conclusion || r.status || 'unknown')}\n └ <i>${escapeHtml(r.commit || '')}</i>`; |
| 194 | }).join('\n') |
| 195 | : '<i>Workflow runی در پاسخ GitHub یافت نشد.</i>'; |
| 196 | |
| 197 | const text = |
| 198 | `📊 <b>وضعیت پایپلاین ${escapeHtml(repoId)}</b> |
| 199 | <code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 📊 وضعیت</code> |
| 200 | ➖➖➖➖➖➖➖➖➖➖ |
| 201 | شاخه پیشفرض: <code>${escapeHtml(status.defaultBranch)}</code> |
| 202 | آخرین نتایج GitHub Actions: |
| 203 | |
| 204 | ${runsText}`; |
| 205 | |
| 206 | return { |
| 207 | text, |
| 208 | reply_markup: { |
| 209 | inline_keyboard: [[ |
| 210 | { text: '🔄 بروزرسانی', callback_data: `status:${repoId}` }, |
| 211 | { text: '🔙 بازگشت به پروژه', callback_data: `repo:${repoId}` } |
| 212 | ]] |
| 213 | } |
| 214 | }; |
| 215 | } |
| 216 | |
| 217 | getServiceStatusView() { |
| 218 | const text = |
| 219 | `📊 <b>وضعیت سیستم و سرویسها</b> |
| 220 | <code>🏠 Nexa Dev > 📊 وضعیت سرویس</code> |
| 221 | ➖➖➖➖➖➖➖➖➖➖ |
| 222 | • <b>Cloudflare Worker:</b> این درخواست توسط Worker پاسخ داده شد. |
| 223 | • <b>Telegram Webhook:</b> secret و owner در مرز ورودی Worker enforce میشوند؛ مقادیر محرمانه نمایش داده نمیشوند. |
| 224 | • <b>GitHub API:</b> هنگام باز کردن مخزنها و وضعیت پروژه بهصورت زنده فراخوانی میشود. |
| 225 | • <b>CI/CD:</b> نتیجه هر مخزن از GitHub Actions خوانده میشود. |
| 226 | |
| 227 | این صفحه SLA، latency یا سلامت سرویس خارجی را بدون اندازهگیری واقعی اعلام نمیکند.`; |
| 228 | |
| 229 | return { |
| 230 | text, |
| 231 | reply_markup: { |
| 232 | inline_keyboard: [[ |
| 233 | { text: '🔄 بررسی مجدد', callback_data: 'menu:status' }, |
| 234 | { text: '🔙 بازگشت به منوی اصلی', callback_data: 'menu:main' } |
| 235 | ]] |
| 236 | } |
| 237 | }; |
| 238 | } |
| 239 | |
| 240 | getToolsView() { |
| 241 | const tools = DEFAULT_CONFIG.devTools.map(t => `• <b>${t.title}</b>\n └ <i>${t.desc}</i>`).join('\n\n'); |
| 242 | const text = |
| 243 | `🔧 <b>ابزارهای توسعه</b> |
| 244 | <code>🏠 Nexa Dev > 🔧 ابزارهای توسعه</code> |
| 245 | ➖➖➖➖➖➖➖➖➖➖ |
| 246 | ${tools}`; |
| 247 | |
| 248 | return { |
| 249 | text, |
| 250 | reply_markup: { |
| 251 | inline_keyboard: [ |
| 252 | [{ text: '🏓 بررسی مسیر داخلی', callback_data: 'tool:ping' }], |
| 253 | [{ text: '🔙 بازگشت به منوی اصلی', callback_data: 'menu:main' }] |
| 254 | ] |
| 255 | } |
| 256 | }; |
| 257 | } |
| 258 | |
| 259 | getSettingsView() { |
| 260 | const text = |
| 261 | `⚙️ <b>تنظیمات Nexa Dev</b> |
| 262 | <code>🏠 Nexa Dev > ⚙️ تنظیمات</code> |
| 263 | ➖➖➖➖➖➖➖➖➖➖ |
| 264 | • مالک GitHub پیشفرض: <code>${escapeHtml(DEFAULT_CONFIG.defaultOwner)}</code> |
| 265 | • Runtime: <b>Cloudflare Worker</b> |
| 266 | • ناوبری: <b>Single-message / editMessageText</b> |
| 267 | • زبان رابط: <b>فارسی</b> |
| 268 | |
| 269 | مقادیر Secret از این رابط نمایش داده نمیشوند.`; |
| 270 | |
| 271 | return { |
| 272 | text, |
| 273 | reply_markup: { inline_keyboard: [[{ text: '🔙 بازگشت به منوی اصلی', callback_data: 'menu:main' }]] } |
| 274 | }; |
| 275 | } |
| 276 | |
| 277 | getSecurityView() { |
| 278 | const text = |
| 279 | `🔐 <b>امنیت و دسترسیها</b> |
| 280 | <code>🏠 Nexa Dev > 🔐 امنیت</code> |
| 281 | ➖➖➖➖➖➖➖➖➖➖ |
| 282 | • Webhook secret: <b>اجباری در Worker</b> |
| 283 | • Owner-only access: <b>اجباری با OWNER_TELEGRAM_ID</b> |
| 284 | • Credentials: <b>خارج از مخزن و خارج از پیامهای ربات</b> |
| 285 | • Diagnostic ID endpoint: <b>غیرفعال</b> |
| 286 | |
| 287 | این صفحه وجود یا مقدار Secretهای runtime را افشا نمیکند.`; |
| 288 | |
| 289 | return { |
| 290 | text, |
| 291 | reply_markup: { inline_keyboard: [[{ text: '🔙 بازگشت به منوی اصلی', callback_data: 'menu:main' }]] } |
| 292 | }; |
| 293 | } |
| 294 | |
| 295 | async renderByCallback(callbackData) { |
| 296 | const [action, target, ...extra] = String(callbackData || '').split(':'); |
| 297 | |
| 298 | switch (action) { |
| 299 | case 'menu': |
| 300 | if (target === 'repos') return this.getReposListView(); |
| 301 | if (target === 'status') return this.getServiceStatusView(); |
| 302 | if (target === 'tools') return this.getToolsView(); |
| 303 | if (target === 'settings') return this.getSettingsView(); |
| 304 | if (target === 'security') return this.getSecurityView(); |
| 305 | return this.getMainMenuView(); |
| 306 | case 'repo': |
| 307 | return this.getRepoDetailView(target); |
| 308 | case 'pr': |
| 309 | return this.getPullRequestsView(target); |
| 310 | case 'commits': |
| 311 | return this.getCommitsView(target); |
| 312 | case 'files': |
| 313 | return this.getFilesView(target, extra.join(':')); |
| 314 | case 'status': |
| 315 | return this.getRepoStatusView(target); |
| 316 | case 'tool': |
| 317 | if (target === 'ping') { |
| 318 | return { |
| 319 | text: '🏓 <b>Pong</b>\nمسیر داخلی ربات پاسخ داد. latency شبکه یا سلامت سرویس خارجی در این عملیات اندازهگیری نشده است.', |
| 320 | reply_markup: { inline_keyboard: [[{ text: '🔙 بازگشت به ابزارها', callback_data: 'menu:tools' }]] } |
| 321 | }; |
| 322 | } |
| 323 | return this.getToolsView(); |
| 324 | default: |
| 325 | return this.getMainMenuView(); |
| 326 | } |
| 327 | } |
| 328 | } |