Personal Telegram developer console for GitHub

phase2-20261005-v
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 99 lines 6.07 KB
Raw
1 import { correlateDeliveryState } from '../../core/cicd-control-plane.js';
2 import { cloudflarePluginManifest } from './manifest.js';
3
4 const escapeHtml = value => String(value ?? '')
5 .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;');
6 const mark = value => value ? '✅' : '❌';
7 const VERSION_ID = /^[0-9a-f-]{36}$/i;
8
9 function unavailableView() {
10 return {
11 text: '☁️ <b>Cloudflare Worker</b>\n❌ Provider Cloudflare پیکربندی نشده است.\nهیچ وضعیت موفق ساختگی نمایش داده نمی‌شود.',
12 reply_markup: { inline_keyboard: [[{ text: '🔄 بررسی مجدد', callback_data: 'cf:status' }],[{ text: '🔙 ابزارها', callback_data: 'menu:tools' }]] }
13 };
14 }
15
16 function snapshotView(snapshot) {
17 const deployment=snapshot.deployment, version=snapshot.version, obs=snapshot.observability||{};
18 const traffic=deployment?.versions?.length ? deployment.versions.map(i=>`${escapeHtml(i.versionId||'-')} — ${Number(i.percentage||0)}%`).join('\n') : 'استقرار فعالی گزارش نشده است.';
19 const bindings=snapshot.bindings?.length ? snapshot.bindings.slice(0,20).map(i=>`• <code>${escapeHtml(i.name||'-')}</code> — ${escapeHtml(i.type||'-')}`).join('\n') : '<i>Bindingی گزارش نشده است.</i>';
20 return {
21 text:`☁️ <b>Cloudflare Worker — ${escapeHtml(snapshot.workerName||'-')}</b>
22 ➖➖➖➖➖➖➖➖➖➖
23 <b>Deployment</b>
24 ID: <code>${escapeHtml(deployment?.id||'-')}</code>
25 Created: <code>${escapeHtml(deployment?.createdOn||'-')}</code>
26 Traffic:
27 ${traffic}
28
29 <b>Version</b>
30 ID: <code>${escapeHtml(version?.id||'-')}</code>
31
32 <b>Bindings</b>
33 ${bindings}
34
35 <b>Observability</b>
36 • Observability: ${mark(obs.enabled)}
37 • Logs: ${mark(obs.logsEnabled)}
38 • Invocation logs: ${mark(obs.invocationLogs)}
39 • Traces: ${mark(obs.tracesEnabled)}
40
41 Secret values نمایش داده نمی‌شوند.`,
42 reply_markup:{inline_keyboard:[
43 [{text:'🚦 CI/CD Control Plane',callback_data:'cf:delivery'}],
44 [{text:'📚 نسخه‌ها / Rollback',callback_data:'cf:versions'}],
45 [{text:'🔄 بروزرسانی',callback_data:'cf:status'}],
46 [{text:'🔙 ابزارها',callback_data:'menu:tools'}]
47 ]}
48 };
49 }
50
51 function versionsView(versions=[]) {
52 const rows=versions.slice(0,10).filter(v=>VERSION_ID.test(v.id)).map(v=>[
53 {text:`🚀 ${v.id.slice(0,8)} · ${String(v.createdOn||'').slice(0,10)}`,callback_data:`cfdeploy:${v.id}`}
54 ]);
55 return {
56 text:`☁️ <b>Cloudflare Versions</b>
57 هر Deploy/Rollback یک عملیات DESTRUCTIVE با Safe Approval است.
58 ➖➖➖➖➖➖➖➖➖➖
59 ${versions.slice(0,10).map(v=>`• <code>${escapeHtml(v.id)}</code>\n ${escapeHtml(v.createdOn||'-')} · ${escapeHtml(v.triggeredBy||'-')}`).join('\n\n')||'<i>نسخه‌ای گزارش نشده است.</i>'}`,
60 reply_markup:{inline_keyboard:[...rows,[{text:'🔄 بروزرسانی',callback_data:'cf:versions'}],[{text:'🔙 Cloudflare',callback_data:'cf:status'}]]}
61 };
62 }
63
64 export function createCloudflarePlugin({ cloudflare, github } = {}) {
65 return {
66 manifest: cloudflarePluginManifest,
67 resolveCallback(data) {
68 const value=String(data||'');
69 if(value==='cf:status') return {actionId:'cloudflare.worker.status',kind:'worker-status',async execute(){if(!cloudflare?.isConfigured?.())return unavailableView();return snapshotView(await cloudflare.getWorkerSnapshot());}};
70 if(value==='cf:versions') return {actionId:'cloudflare.worker.versions',kind:'versions',async execute(){if(!cloudflare?.isConfigured?.())return unavailableView();return versionsView(await cloudflare.listVersions());}};
71 if(value==='cf:delivery') return {actionId:'cloudflare.delivery.status',kind:'delivery-status',async execute(){
72 if(!cloudflare?.isConfigured?.() || !github) return {text:'🚦 <b>Delivery Control Plane</b>\n❌ Provider evidence is not configured.',reply_markup:{inline_keyboard:[[{text:'🔙 Cloudflare',callback_data:'cf:status'}]]}};
73 const repos=await github.listRepositories();
74 const repo=repos.find(item=>item.name===cloudflare.workerName) || repos[0];
75 if(!repo) throw new Error('GitHub repository evidence is unavailable');
76 const [commits,runs,runtime]=await Promise.all([github.listCommits(repo.id),github.listWorkflowRuns(repo.id,{perPage:20,page:1}),cloudflare.getWorkerSnapshot()]);
77 const targetSha=String(commits[0]?.fullSha||'');
78 const ci=runs.find(run=>run.name==='CI' && run.branch===(repo.defaultBranch||'main') && run.fullSha===targetSha) || null;
79 const deploy=runs.find(run=>/Deploy Cloudflare Worker/i.test(run.name) && run.branch===(repo.defaultBranch||'main') && run.fullSha===targetSha) || null;
80 const state=correlateDeliveryState({targetSha,ci,deploy,runtime});
81 const label=state.state==='success'?'SUCCESS / موفق':state.state.toUpperCase();
82 return {text:`🚦 <b>CI/CD Control Plane</b>\nState: <b>${label}</b>\nSHA: <code>${escapeHtml(targetSha.slice(0,12)||'-')}</code>\nCI: <b>${escapeHtml(ci?.conclusion||ci?.status||'unknown')}</b>\nDeploy: <b>${escapeHtml(deploy?.conclusion||deploy?.status||'unknown')}</b>\nRuntime: <code>${escapeHtml(state.versionId||runtime?.deployment?.versions?.[0]?.versionId||'-')}</code>\n\n${escapeHtml(state.reason)}</b>`,reply_markup:{inline_keyboard:[[{text:'🔄 بروزرسانی',callback_data:'cf:delivery'}],[{text:'🔙 Cloudflare',callback_data:'cf:status'}]]}};
83 }};
84 const m=value.match(/^cfdeploy:([0-9a-f-]{36})$/i);
85 if(m) {
86 const versionId=m[1];
87 return {
88 actionId:'cloudflare.worker.deploy_version',
89 approval:{input:{versionId},label:`Deploy/Rollback Cloudflare ${versionId.slice(0,8)}`,cancelCallback:'cf:versions'},
90 async execute(){
91 const result=await cloudflare.deployVersion(versionId);
92 return {text:`✅ Cloudflare version <code>${escapeHtml(result.versionId)}</code> با 100% traffic تأیید شد.`,reply_markup:{inline_keyboard:[[{text:'☁️ وضعیت',callback_data:'cf:status'}]]}};
93 }
94 };
95 }
96 return null;
97 }
98 };
99 }