Personal Telegram developer console for GitHub
feat: add operational menu surfaces
davoodmehraban89 committed
Oct 4, 2026 at 14:03 UTC
256e0b3feb10f0ff3a1e7bcbca78547865472fa0
1 file changed
+317
src/ops-menu.js
new
+317
@@ -0,0 +1,317 @@
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('<', '<')
7
+ .replaceAll('>', '>')
8
+ .replaceAll('"', '"');
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 > 🔧 ابزارها</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 > 📊 وضعیت</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 > 🔐 امنیت</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 > ⚙️ پیکربندی</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() {
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: 'ops:github' }],
184
+ backRow('🔙 ابزارها', 'menu:tools')
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 نمایش داده نمیشوند. اتصال زنده GitHub را از «ابزارها → تست اتصال GitHub» بررسی کنید.`,
267
+ reply_markup: { inline_keyboard: [backRow('🔙 پیکربندی', 'menu:settings')] }
268
+ };
269
+ }
270
+
271
+ getEditorConfigView() {
272
+ return {
273
+ text:
274
+`🧑💻 <b>پیکربندی Workspace Editor</b>
275
+➖➖➖➖➖➖➖➖➖➖
276
+• نوع: <b>Telegram Mini App</b>
277
+• URL: <code>${escapeHtml(DEFAULT_CONFIG.workspaceEditorUrl)}</code>
278
+• ذخیره: <b>Durable Draft در WORKSPACE_STORE</b>
279
+• GitHub WRITE مستقیم از Editor: <b>ندارد</b>
280
+• Commit نهایی: <b>Branch-only + Safe Approval</b>`,
281
+ reply_markup: { inline_keyboard: [backRow('🔙 پیکربندی', 'menu:settings')] }
282
+ };
283
+ }
284
+
285
+ async renderByCallback(callbackData) {
286
+ const [action, target] = String(callbackData || '').split(':');
287
+
288
+ if (action === 'menu') {
289
+ if (target === 'status') return this.getServiceStatusView();
290
+ if (target === 'tools') return this.getToolsView();
291
+ if (target === 'security') return this.getSecurityView();
292
+ if (target === 'settings') return this.getSettingsView();
293
+ }
294
+
295
+ if (action === 'ops') {
296
+ if (target === 'selfcheck') return this.getSelfCheckView('menu:tools');
297
+ if (target === 'github') return this.getGitHubProbeView();
298
+ if (target === 'runtime') return this.getRuntimeView('menu:tools');
299
+ if (target === 'plugins') return this.getPluginsView('menu:tools');
300
+ }
301
+
302
+ if (action === 'security') {
303
+ if (target === 'selfcheck') return this.getSelfCheckView('menu:security');
304
+ if (target === 'policy') return this.getSecurityPolicyView();
305
+ if (target === 'approval') return this.getApprovalStatusView();
306
+ }
307
+
308
+ if (action === 'config') {
309
+ if (target === 'runtime') return this.getRuntimeView('menu:settings');
310
+ if (target === 'providers') return this.getProvidersView();
311
+ if (target === 'editor') return this.getEditorConfigView();
312
+ if (target === 'plugins') return this.getPluginsView('menu:settings');
313
+ }
314
+
315
+ return super.renderByCallback(callbackData);
316
+ }
317
+}