Personal Telegram developer console for GitHub

feat/studio-g0-foundation
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 371 lines 15.5 KB
Raw
1 import { GuideMenuManager } from './guide-menu.js';
2 import { workspaceEditorUrl } from './config.js';
3
4 const escapeHtml = (value) =>
5 String(value ?? '')
6 .replaceAll('&', '&')
7 .replaceAll('<', '&lt;')
8 .replaceAll('>', '&gt;')
9 .replaceAll('"', '&quot;');
10
11 const mark = (ok) => (ok ? '✅' : '❌');
12 const configuredText = (ok) => (ok ? '✅ پیکربندی شده' : '❌ پیکربندی نشده');
13
14 function backRow(text, callback) {
15 return [{ text, callback_data: callback }];
16 }
17
18 export class OpsMenuManager extends GuideMenuManager {
19 constructor(github, diagnostics) {
20 super(github);
21 this.diagnostics = diagnostics;
22 }
23
24 getMainMenuView() {
25 const view = super.getMainMenuView();
26 const inlineKeyboard = (view.reply_markup?.inline_keyboard || []).map(
27 (row) =>
28 row.map((button) =>
29 button.callback_data === 'menu:settings'
30 ? { ...button, text: '⚙️ پیکربندی' }
31 : button
32 )
33 );
34 return {
35 ...view,
36 reply_markup: { ...view.reply_markup, inline_keyboard: inlineKeyboard }
37 };
38 }
39
40 getToolsView() {
41 return {
42 text: `🔧 <b>ابزارهای توسعه و عیب‌یابی</b>
43 <code>🏠 Nexa Dev &gt; 🔧 ابزارها</code>
44 ➖➖➖➖➖➖➖➖➖➖
45 این بخش Diagnostics واقعی و فقط‌خواندنی Nexa است. هیچ‌کدام از ابزارهای این صفحه GitHub WRITE انجام نمی‌دهند.
46
47 • <b>خودآزمایی سیستم:</b> پیش‌نیازهای Runtime، امنیت، Durable Objectها و GitHub را یکجا بررسی می‌کند.
48 • <b>تست اتصال GitHub:</b> یک READ زنده اجرا و تعداد Repositoryهای قابل مشاهده را گزارش می‌کند.
49 • <b>Runtime / Bindings:</b> وضعیت پیکربندی Worker و Durable Objectها را بدون نمایش Secretها نشان می‌دهد.
50 • <b>Plugin Registry:</b> Pluginهای ثبت‌شده و تعداد Actionها را از Registry واقعی می‌خواند.
51 • <b>Ping داخلی:</b> فقط مسیر Callback و Render داخلی Bot را بررسی می‌کند.`,
52 reply_markup: {
53 inline_keyboard: [
54 [{ text: '🩺 خودآزمایی سیستم', callback_data: 'ops:selfcheck' }],
55 [{ text: '🐙 تست اتصال GitHub', callback_data: 'ops:github' }],
56 [
57 { text: '🧱 Runtime / Bindings', callback_data: 'ops:runtime' },
58 { text: '🧩 Plugin Registry', callback_data: 'ops:plugins' }
59 ],
60 [{ text: '🏓 Ping داخلی', callback_data: 'tool:ping' }],
61 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
62 ]
63 }
64 };
65 }
66
67 async getServiceStatusView() {
68 const report = await this.diagnostics.runSelfCheck();
69 const snapshot = report.snapshot;
70 const github = report.github;
71 const githubDetail = github.ok
72 ? `✅ متصل؛ ${github.repositoryCount} Repository قابل مشاهده`
73 : `❌ ناموفق؛ ${escapeHtml(github.error || 'خطای نامشخص')}`;
74
75 return {
76 text: `📊 <b>وضعیت زنده Nexa Dev</b>
77 <code>🏠 Nexa Dev &gt; 📊 وضعیت</code>
78 ➖➖➖➖➖➖➖➖➖➖
79 • <b>Cloudflare Worker:</b> ✅ این درخواست داخل Worker اجرا شد.
80 • <b>Telegram Bot:</b> ${configuredText(snapshot.telegramConfigured)}
81 • <b>Webhook owner lock:</b> ${mark(snapshot.webhookSecretConfigured && snapshot.ownerConfigured)} ${snapshot.webhookSecretConfigured && snapshot.ownerConfigured ? 'فعال' : 'ناقص'}
82 • <b>GitHub live READ:</b> ${githubDetail}
83 • <b>WORKSPACE_STORE Durable Object:</b> ${configuredText(snapshot.workspaceStoreConfigured)}
84 • <b>APPROVAL_REPLAY_GUARD Durable Object:</b> ${configuredText(snapshot.replayGuardConfigured)}
85 • <b>Approval signer:</b> ${configuredText(snapshot.approvalSignerConfigured)}
86 • <b>Plugin Registry:</b> ${snapshot.pluginCount} Plugin / ${snapshot.actionCount} Action
87
88 <b>جمع‌بندی:</b> ${report.ok ? '✅ همهٔ کنترل‌های الزامی این Self-check پاس شدند.' : '⚠️ حداقل یک کنترل الزامی نیاز به بررسی دارد.'}
89
90 این صفحه latency، uptime یا SLA سرویس خارجی را بدون اندازه‌گیری واقعی ادعا نمی‌کند.`,
91 reply_markup: {
92 inline_keyboard: [
93 [{ text: '🔄 بررسی مجدد', callback_data: 'menu:status' }],
94 [{ text: '🩺 جزئیات Self-check', callback_data: 'ops:selfcheck' }],
95 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
96 ]
97 }
98 };
99 }
100
101 getSecurityView() {
102 const snapshot = this.diagnostics.getSnapshot();
103 return {
104 text: `🔐 <b>مرکز امنیت Nexa Dev</b>
105 <code>🏠 Nexa Dev &gt; 🔐 امنیت</code>
106 ➖➖➖➖➖➖➖➖➖➖
107 • <b>Owner-only boundary:</b> ${configuredText(snapshot.ownerConfigured)}
108 • <b>Webhook secret:</b> ${configuredText(snapshot.webhookSecretConfigured)}
109 • <b>Safe Approval signer:</b> ${configuredText(snapshot.approvalSignerConfigured)}
110 • <b>Replay protection:</b> ${configuredText(snapshot.replayGuardConfigured)}
111 • <b>Workspace isolation:</b> ${configuredText(snapshot.workspaceStoreConfigured)}
112 • <b>GitHub credential:</b> ${configuredText(snapshot.githubConfigured)}
113
114 فقط وضعیت پیکربندی نمایش داده می‌شود؛ مقدار Credential یا Secret هرگز در این صفحه نمایش داده نمی‌شود.`,
115 reply_markup: {
116 inline_keyboard: [
117 [{ text: '🛡 خودآزمایی امنیت', callback_data: 'security:selfcheck' }],
118 [
119 { text: '📜 سیاست عملیات', callback_data: 'security:policy' },
120 { text: '✅ Safe Approval', callback_data: 'security:approval' }
121 ],
122 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
123 ]
124 }
125 };
126 }
127
128 getSettingsView() {
129 const snapshot = this.diagnostics.getSnapshot();
130 return {
131 text: `⚙️ <b>مرکز پیکربندی Nexa Dev</b>
132 <code>🏠 Nexa Dev &gt; ⚙️ پیکربندی</code>
133 ➖➖➖➖➖➖➖➖➖➖
134 این بخش در V2.1 عمداً <b>فقط‌خواندنی</b> است تا Secret یا تنظیم حساس از Telegram تغییر نکند.
135
136 • Runtime: <b>${escapeHtml(snapshot.runtime)}</b>
137 • مالک GitHub: <code>${escapeHtml(snapshot.githubOwner)}</code>
138 • Editor: <b>Telegram Mini App</b>
139 • Pluginها: <b>${snapshot.pluginCount}</b>
140
141 برای مشاهده جزئیات هر حوزه یکی از گزینه‌های زیر را باز کنید.`,
142 reply_markup: {
143 inline_keyboard: [
144 [
145 { text: '🧱 Runtime', callback_data: 'config:runtime' },
146 { text: '🔗 Providerها', callback_data: 'config:providers' }
147 ],
148 [
149 { text: '🧑‍💻 Editor', callback_data: 'config:editor' },
150 { text: '🧩 Pluginها', callback_data: 'config:plugins' }
151 ],
152 backRow('🔙 بازگشت به منوی اصلی', 'menu:main')
153 ]
154 }
155 };
156 }
157
158 async getSelfCheckView(backCallback = 'menu:tools') {
159 const report = await this.diagnostics.runSelfCheck();
160 const lines = report.checks
161 .map((check) => {
162 const detail = check.detail ? ` — ${escapeHtml(check.detail)}` : '';
163 return `• ${mark(check.ok)} <b>${escapeHtml(check.label)}</b>${detail}`;
164 })
165 .join('\n');
166 return {
167 text: `🩺 <b>Self-check Nexa Dev</b>
168 ➖➖➖➖➖➖➖➖➖➖
169 ${lines}
170
171 <b>نتیجه:</b> ${report.ok ? '✅ PASS' : '❌ ATTENTION REQUIRED'}
172 این بررسی READ-only است و هیچ Provider mutation اجرا نمی‌کند.`,
173 reply_markup: {
174 inline_keyboard: [
175 [
176 {
177 text: '🔄 اجرای مجدد',
178 callback_data:
179 backCallback === 'menu:security'
180 ? 'security:selfcheck'
181 : 'ops:selfcheck'
182 }
183 ],
184 backRow(
185 backCallback === 'menu:security' ? '🔙 مرکز امنیت' : '🔙 ابزارها',
186 backCallback
187 )
188 ]
189 }
190 };
191 }
192
193 async getGitHubProbeView(
194 backCallback = 'menu:tools',
195 refreshCallback = 'ops:github'
196 ) {
197 const probe = await this.diagnostics.probeGitHub();
198 return {
199 text: probe.ok
200 ? `🐙 <b>تست اتصال GitHub</b>\n➖➖➖➖➖➖➖➖➖➖\n✅ READ زنده موفق بود.\nمالک: <code>${escapeHtml(probe.owner)}</code>\nRepositoryهای قابل مشاهده: <b>${probe.repositoryCount}</b>\n\nهیچ WRITEای انجام نشد.`
201 : `🐙 <b>تست اتصال GitHub</b>\n➖➖➖➖➖➖➖➖➖➖\n❌ READ زنده ناموفق بود.\n${escapeHtml(probe.error || 'خطای نامشخص')}\n\nهیچ وضعیت موفق ساختگی نمایش داده نمی‌شود.`,
202 reply_markup: {
203 inline_keyboard: [
204 [{ text: '🔄 تست دوباره', callback_data: refreshCallback }],
205 backRow(
206 backCallback === 'menu:settings' ? '🔙 پیکربندی' : '🔙 ابزارها',
207 backCallback
208 )
209 ]
210 }
211 };
212 }
213
214 getRuntimeView(backCallback = 'menu:tools') {
215 const snapshot = this.diagnostics.getSnapshot();
216 return {
217 text: `🧱 <b>Runtime / Bindings</b>
218 ➖➖➖➖➖➖➖➖➖➖
219 • Runtime: <b>${escapeHtml(snapshot.runtime)}</b>
220 • Telegram Bot: ${configuredText(snapshot.telegramConfigured)}
221 • Webhook secret: ${configuredText(snapshot.webhookSecretConfigured)}
222 • Owner lock: ${configuredText(snapshot.ownerConfigured)}
223 • GitHub credential: ${configuredText(snapshot.githubConfigured)}
224 • WORKSPACE_STORE: ${configuredText(snapshot.workspaceStoreConfigured)}
225 • APPROVAL_REPLAY_GUARD: ${configuredText(snapshot.replayGuardConfigured)}
226 • Approval signer: ${configuredText(snapshot.approvalSignerConfigured)}
227
228 این صفحه فقط وجود پیکربندی را نشان می‌دهد و هیچ Secretی را چاپ نمی‌کند.`,
229 reply_markup: {
230 inline_keyboard: [
231 backRow(
232 backCallback === 'menu:settings' ? '🔙 پیکربندی' : '🔙 ابزارها',
233 backCallback
234 )
235 ]
236 }
237 };
238 }
239
240 getPluginsView(backCallback = 'menu:tools') {
241 const summary = this.diagnostics.getPluginSummary();
242 const items = summary.plugins.length
243 ? summary.plugins
244 .map(
245 (plugin) =>
246 `• <b>${escapeHtml(plugin.id)}</b>: ${plugin.actionCount} Action — READ ${plugin.risks.READ} / WRITE ${plugin.risks.WRITE} / DESTRUCTIVE ${plugin.risks.DESTRUCTIVE}`
247 )
248 .join('\n')
249 : '<i>Plugin ثبت‌شده‌ای یافت نشد.</i>';
250 return {
251 text: `🧩 <b>Plugin Registry</b>
252 ➖➖➖➖➖➖➖➖➖➖
253 Pluginها: <b>${summary.pluginCount}</b>
254 Actionها: <b>${summary.actionCount}</b>
255
256 ${items}`,
257 reply_markup: {
258 inline_keyboard: [
259 backRow(
260 backCallback === 'menu:settings' ? '🔙 پیکربندی' : '🔙 ابزارها',
261 backCallback
262 )
263 ]
264 }
265 };
266 }
267
268 getSecurityPolicyView() {
269 return {
270 text: `📜 <b>سیاست عملیات Nexa Dev</b>
271 ➖➖➖➖➖➖➖➖➖➖
272 • <b>READ:</b> فقط برای Owner مجاز است و بدون Safe Approval قابل اجراست.
273 • <b>WRITE:</b> قبل از Provider mutation به Safe Approval معتبر و Owner-bound نیاز دارد.
274 • <b>DESTRUCTIVE:</b> باید پشت همان Policy مرکزی و تأیید صریح باقی بماند؛ این مرکز امنیت هیچ مسیر دورزدنی ایجاد نمی‌کند.
275 • Approval token به Owner / Action / Risk / Target / Expiry متصل و یک‌بارمصرف است.
276 • Source، Draft، Secret و Signed token نباید وارد Audit log شوند.`,
277 reply_markup: {
278 inline_keyboard: [backRow('🔙 مرکز امنیت', 'menu:security')]
279 }
280 };
281 }
282
283 getApprovalStatusView() {
284 const snapshot = this.diagnostics.getSnapshot();
285 return {
286 text: `✅ <b>وضعیت Safe Approval</b>
287 ➖➖➖➖➖➖➖➖➖➖
288 • Signer: ${configuredText(snapshot.approvalSignerConfigured)}
289 • Durable replay guard: ${configuredText(snapshot.replayGuardConfigured)}
290 • Owner lock: ${configuredText(snapshot.ownerConfigured)}
291
292 WRITE فقط بعد از تأیید معتبر اجرا می‌شود و Approval مصرف‌شده دوباره قابل استفاده نیست.`,
293 reply_markup: {
294 inline_keyboard: [backRow('🔙 مرکز امنیت', 'menu:security')]
295 }
296 };
297 }
298
299 getProvidersView() {
300 const snapshot = this.diagnostics.getSnapshot();
301 return {
302 text: `🔗 <b>Providerها و اتصال‌ها</b>
303 ➖➖➖➖➖➖➖➖➖➖
304 • GitHub owner: <code>${escapeHtml(snapshot.githubOwner)}</code>
305 • GitHub credential: ${configuredText(snapshot.githubConfigured)}
306 • Telegram Bot credential: ${configuredText(snapshot.telegramConfigured)}
307 • Telegram Webhook secret: ${configuredText(snapshot.webhookSecretConfigured)}
308
309 مقادیر Credential نمایش داده نمی‌شوند. برای اعتبارسنجی Provider، تست READ زنده GitHub را مستقیماً اجرا کنید.`,
310 reply_markup: {
311 inline_keyboard: [
312 [{ text: '🐙 تست زنده GitHub', callback_data: 'config:github' }],
313 backRow('🔙 پیکربندی', 'menu:settings')
314 ]
315 }
316 };
317 }
318
319 getEditorConfigView() {
320 const editorUrl = workspaceEditorUrl(
321 this.diagnostics?.env?.WORKSPACE_EDITOR_URL
322 );
323 return {
324 text: `🧑‍💻 <b>پیکربندی Workspace Editor</b>
325 ➖➖➖➖➖➖➖➖➖➖
326 • نوع: <b>Telegram Mini App</b>
327 • URL: <code>${editorUrl ? escapeHtml(editorUrl) : 'پیکربندی نشده'}</code>
328 • ذخیره: <b>Durable Draft در WORKSPACE_STORE</b>
329 • GitHub WRITE مستقیم از Editor: <b>ندارد</b>
330 • Commit نهایی: <b>Branch-only + Safe Approval</b>`,
331 reply_markup: {
332 inline_keyboard: [backRow('🔙 پیکربندی', 'menu:settings')]
333 }
334 };
335 }
336
337 async renderByCallback(callbackData) {
338 const [action, target] = String(callbackData || '').split(':');
339
340 if (action === 'menu') {
341 if (target === 'status') return this.getServiceStatusView();
342 if (target === 'tools') return this.getToolsView();
343 if (target === 'security') return this.getSecurityView();
344 if (target === 'settings') return this.getSettingsView();
345 }
346
347 if (action === 'ops') {
348 if (target === 'selfcheck') return this.getSelfCheckView('menu:tools');
349 if (target === 'github') return this.getGitHubProbeView();
350 if (target === 'runtime') return this.getRuntimeView('menu:tools');
351 if (target === 'plugins') return this.getPluginsView('menu:tools');
352 }
353
354 if (action === 'security') {
355 if (target === 'selfcheck') return this.getSelfCheckView('menu:security');
356 if (target === 'policy') return this.getSecurityPolicyView();
357 if (target === 'approval') return this.getApprovalStatusView();
358 }
359
360 if (action === 'config') {
361 if (target === 'runtime') return this.getRuntimeView('menu:settings');
362 if (target === 'providers') return this.getProvidersView();
363 if (target === 'github')
364 return this.getGitHubProbeView('menu:settings', 'config:github');
365 if (target === 'editor') return this.getEditorConfigView();
366 if (target === 'plugins') return this.getPluginsView('menu:settings');
367 }
368
369 return super.renderByCallback(callbackData);
370 }
371 }