Personal Telegram developer console for GitHub

nexa/edit-BwJEIIY3PW
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 143 lines 7.2 KB
Raw
1 const WORKSPACE_CALLBACK = /^(?:ws|wfile|wtext|wmsg|wdiff|wready|wcancel):([A-Za-z0-9_-]{10})$/;
2 const WORKSPACE_ID = /^[A-Za-z0-9_-]{10}$/;
3 const INTENT_ID = /^[A-Za-z0-9_-]{8}$/;
4
5 const escapeHtml = value => String(value ?? '')
6 .replaceAll('&', '&')
7 .replaceAll('<', '&lt;')
8 .replaceAll('>', '&gt;')
9 .replaceAll('"', '&quot;');
10
11 function legacyFailureView(data, error) {
12 const reason = String(error?.message || 'Provider read failed');
13 const permissionDenied = /403|resource not accessible by personal access token/i.test(reason);
14 const repoMatch = String(data || '').match(/^[^:]+:(\d+)/);
15 const fallback = repoMatch ? `repo:${repoMatch[1]}` : 'menu:main';
16 const isIssues = String(data || '').startsWith('issues:');
17 const detail = permissionDenied
18 ? isIssues
19 ? 'GitHub درخواست Issues را با خطای 403 رد کرد. در Fine-grained token، مجوز Repository permissions → Issues را روی Read قرار دهید.'
20 : 'GitHub این درخواست خواندنی را با خطای 403 رد کرد. مجوز Read مربوط به این بخش در توکن فعلی کافی نیست.'
21 : 'دریافت اطلاعات از سرویس با خطا مواجه شد. هیچ تغییری انجام نشد.';
22
23 return {
24 text:
25 `⚠️ <b>دریافت اطلاعات با خطا مواجه شد</b>
26 ➖➖➖➖➖➖➖➖➖➖
27 ${detail}
28
29 این خطا هیچ عملیات تغییردهنده‌ای اجرا نکرد.`,
30 reply_markup: { inline_keyboard: [[{ text: repoMatch ? '↩️ بازگشت به پروژه' : '↩️ منوی اصلی', callback_data: fallback }]] },
31 validationError: false
32 };
33 }
34
35 export async function buildCallbackFailureView({ data, error, ownerId, workspaces } = {}) {
36 const callback = String(data || '');
37 const reason = String(error?.message || 'Provider read failed');
38 const match = callback.match(WORKSPACE_CALLBACK);
39 if (!match) return legacyFailureView(callback, error);
40
41 const workspaceId = match[1];
42 let workspace = null;
43 if (ownerId !== undefined && ownerId !== null && typeof workspaces?.getWorkspace === 'function') {
44 try {
45 workspace = await workspaces.getWorkspace({ ownerId: String(ownerId), workspaceId });
46 } catch {
47 // Recovery remains available even when durable context lookup itself fails.
48 }
49 }
50
51 const repoId = Number(workspace?.repoId);
52 const hasRepo = Number.isSafeInteger(repoId);
53 const missingCommitMessage = /^Commit message is required$/i.test(reason);
54 const longCommitMessage = /^Commit message must be 120 characters or fewer$/i.test(reason);
55 const noDraftChange = /^No draft change to commit$/i.test(reason);
56 const validationError = missingCommitMessage || longCommitMessage || noDraftChange;
57
58 let title = '⚠️ <b>عملیات Workspace متوقف شد</b>';
59 let detail = workspace
60 ? 'Workspace و Draft فعلی محفوظ هستند. می‌توانید دوباره تلاش کنید یا به Draft برگردید.'
61 : 'عملیات متوقف شد. برای بازیابی وضعیت، دوباره تلاش کنید یا به منوی اصلی برگردید.';
62 if (missingCommitMessage) {
63 title = '✍️ <b>پیام Commit لازم است</b>';
64 detail = 'قبل از «آماده Commit»، یک پیام Commit ثبت کنید. هیچ تغییری در GitHub انجام نشده است.';
65 } else if (longCommitMessage) {
66 title = '✍️ <b>پیام Commit بیش از حد طولانی است</b>';
67 detail = 'پیام Commit باید حداکثر 120 کاراکتر باشد. هیچ تغییری در GitHub انجام نشده است.';
68 } else if (noDraftChange) {
69 title = '📝 <b>تغییری برای Commit وجود ندارد</b>';
70 detail = 'محتوای Draft با نسخهٔ اصلی یکسان است. ابتدا Draft را تغییر دهید؛ هیچ تغییری در GitHub انجام نشده است.';
71 }
72
73 const rows = [];
74 if (missingCommitMessage || longCommitMessage) {
75 rows.push([{ text: '✍️ ثبت پیام Commit', callback_data: `wmsg:${workspaceId}` }]);
76 }
77 rows.push([{ text: '🔄 تلاش مجدد', callback_data: callback }]);
78 rows.push([{ text: '📝 ادامه Draft', callback_data: `ws:${workspaceId}` }]);
79 if (hasRepo) rows.push([{ text: '📦 بازگشت به پروژه', callback_data: `repo:${repoId}` }]);
80 rows.push([{ text: '🏠 منوی اصلی', callback_data: 'menu:main' }]);
81
82 return {
83 text: `${title}\n➖➖➖➖➖➖➖➖➖➖\n${detail}`,
84 reply_markup: { inline_keyboard: rows },
85 validationError
86 };
87 }
88
89 export async function buildApprovedActionFailedView({ payload, error, ownerId, workspaces } = {}) {
90 const reason = String(error?.message || 'GitHub operation failed');
91 const permissionDenied = /403|resource not accessible by personal access token/i.test(reason);
92 const repoId = Number(payload?.input?.repoId);
93 const runId = Number(payload?.input?.runId);
94 const workspaceAction = payload?.actionId === 'github.workspace.commit_branch';
95 const intentId = String(payload?.input?.intentId || '');
96
97 let workspaceId = '';
98 if (
99 workspaceAction &&
100 INTENT_ID.test(intentId) &&
101 ownerId !== undefined &&
102 ownerId !== null &&
103 typeof workspaces?.getIntent === 'function'
104 ) {
105 try {
106 const intent = await workspaces.getIntent({ ownerId: String(ownerId), intentId });
107 const candidate = String(intent?.workspaceId || '');
108 if (WORKSPACE_ID.test(candidate)) workspaceId = candidate;
109 } catch {
110 // Provider failure feedback must still render even if durable recovery lookup fails.
111 }
112 }
113
114 const detail = workspaceAction
115 ? permissionDenied
116 ? 'تأیید شما معتبر بود، اما GitHub درخواست Commit شاخه را با خطای 403 رد کرد. دسترسی Contents WRITE توکن فعلی را بررسی کنید.'
117 : `تأیید شما معتبر بود، اما Commit شاخه انجام نشد: ${escapeHtml(reason)}`
118 : permissionDenied
119 ? 'تأیید شما معتبر بود، اما GitHub درخواست را با خطای 403 رد کرد. دسترسی توکن فعلی برای GitHub Actions WRITE کافی نیست.'
120 : `تأیید شما معتبر بود، اما GitHub عملیات را موفق اعلام نکرد: ${escapeHtml(reason)}`;
121
122 const rows = [];
123 if (workspaceAction && workspaceId) {
124 rows.push([{ text: '🔄 درخواست تأیید تازه', callback_data: `wready:${workspaceId}` }]);
125 rows.push([{ text: '📝 ادامه Draft', callback_data: `ws:${workspaceId}` }]);
126 } else if (!workspaceAction && Number.isSafeInteger(repoId) && Number.isSafeInteger(runId)) {
127 rows.push([{ text: '↩️ بازگشت به Run', callback_data: `run:${repoId}:${runId}` }]);
128 }
129 if (Number.isSafeInteger(repoId)) {
130 rows.push([{ text: '📦 بازگشت به پروژه', callback_data: `repo:${repoId}` }]);
131 }
132 rows.push([{ text: '🏠 منوی اصلی', callback_data: 'menu:main' }]);
133
134 return {
135 text:
136 `⚠️ <b>اجرای عملیات در GitHub ناموفق بود</b>
137 ➖➖➖➖➖➖➖➖➖➖
138 ${detail}
139
140 این تأیید یک‌بار مصرف شده است؛ برای تلاش مجدد باید تأیید تازه ایجاد شود.`,
141 reply_markup: { inline_keyboard: rows }
142 };
143 }