Personal Telegram developer console for GitHub
feat/persistent-menu-code-input
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 | # Safe GitHub Operator Design |
| 2 | |
| 3 | ## Purpose |
| 4 | Turn the production-accepted read-only plugin foundation into a safe write-capable GitHub operator without weakening the existing owner-only, fail-closed security model. |
| 5 | |
| 6 | ## Scope |
| 7 | This phase delivers two tightly coupled capabilities: |
| 8 | 1. A reusable Telegram approval flow for `WRITE` and `DESTRUCTIVE` plugin actions with durable one-time consumption. |
| 9 | 2. GitHub Advanced operations for workflow visibility/control and repository operational views. |
| 10 | |
| 11 | Out of scope for this phase: AI model execution, browser automation, Supabase, Cloudflare rollback and Mini App UI. A Cloudflare Durable Object namespace with SQLite storage is in scope because it is required for cross-isolate approval replay protection. |
| 12 | |
| 13 | ## Success criteria |
| 14 | - `READ` actions continue to execute immediately for the authorized owner. |
| 15 | - `WRITE` and `DESTRUCTIVE` actions never execute on the first request. |
| 16 | - Approval tokens are single-use, owner-bound, action-bound, short-lived, and tamper-evident. |
| 17 | - Approval UI exposes explicit Confirm and Cancel choices. |
| 18 | - Replayed, expired, malformed, wrong-owner, or mismatched approvals fail closed and do not execute provider code. |
| 19 | - One-time consumption remains enforced across Worker isolates through a Durable Object replay guard. |
| 20 | - GitHub workflow actions can list runs, inspect jobs/steps, re-run failed jobs, and cancel an in-progress workflow when the configured GitHub token has sufficient scope. |
| 21 | - Missing GitHub permissions produce an explicit operational error; they are not reported as success. |
| 22 | - Every attempted and completed action emits redacted audit events. |
| 23 | - Existing repository/file navigation remains unchanged. |
| 24 | - All existing tests stay green, new tests cover approval, durable replay and GitHub operator behavior, CI passes, production deploy succeeds, and live Telegram READ smoke remains healthy. |
| 25 | |
| 26 | ## Approval architecture |
| 27 | |
| 28 | ### Signed approval token |
| 29 | Approval state needed for verification is carried in a signed callback token; no server-side session is required to reconstruct the requested action. |
| 30 | |
| 31 | The token payload contains: |
| 32 | - `v`: schema version `1` |
| 33 | - `pluginId` |
| 34 | - `actionId` |
| 35 | - `input`: compact action parameters |
| 36 | - `risk`: `WRITE` or `DESTRUCTIVE` |
| 37 | - `ownerId` |
| 38 | - `issuedAt` |
| 39 | - `expiresAt` |
| 40 | - `nonce` |
| 41 | |
| 42 | The token is authenticated with HMAC-SHA-256 using `APPROVAL_SIGNING_SECRET` when configured, otherwise `TELEGRAM_WEBHOOK_SECRET` as the fail-closed fallback signing secret. Raw secrets are never logged or returned. |
| 43 | |
| 44 | Telegram callback data has a strict size budget, so approval tokens must not embed verbose objects. GitHub operations use compact numeric identifiers (repository ID and workflow run ID) and the token encoder rejects oversized payloads instead of truncating security-relevant data. |
| 45 | |
| 46 | ### ApprovalService |
| 47 | `ApprovalService.issue()` creates a signed token. `ApprovalService.verify()` validates signature, schema, owner, expiry, risk, and expected action before returning the decoded payload. |
| 48 | |
| 49 | A verified token does not by itself execute an action. `ApprovalService.consume()` must first persist one-time consumption through the replay store. Only then does the router receive explicit `approved: true` context. The action policy then allows the matching `WRITE`/`DESTRUCTIVE` action. |
| 50 | |
| 51 | ### Durable replay protection |
| 52 | `DurableApprovalReplayStore` maps the `(ownerId, nonce)` pair to a Cloudflare Durable Object identity. `ApprovalReplayGuard` performs an atomic check-and-write in Durable Object storage and schedules cleanup at token expiry. |
| 53 | |
| 54 | Security behavior: |
| 55 | - first valid consume before expiry: accepted and persisted; |
| 56 | - repeated consume for the same `(ownerId, nonce)`: rejected; |
| 57 | - expired consume: rejected; |
| 58 | - missing `APPROVAL_REPLAY_GUARD` binding: consume fails closed; |
| 59 | - cleanup occurs after expiry via the Durable Object alarm. |
| 60 | |
| 61 | `wrangler.jsonc` declares `APPROVAL_REPLAY_GUARD` bound to exported class `ApprovalReplayGuard` with SQLite storage. |
| 62 | |
| 63 | ## Policy changes |
| 64 | `ActionPolicy.evaluate()` accepts `approved` in addition to `action` and `isOwner`. |
| 65 | - non-owner: denied |
| 66 | - unknown action/risk: denied |
| 67 | - READ: allowed |
| 68 | - WRITE/DESTRUCTIVE without approval: `requiresApproval` |
| 69 | - WRITE/DESTRUCTIVE with verified and consumed approval: allowed with distinct audit reason |
| 70 | |
| 71 | The router remains `resolve -> policy -> execute`; approval verification and durable consume occur before the second dispatch that carries `approved: true`. |
| 72 | |
| 73 | ## Telegram UX |
| 74 | When a plugin route returns `requiresApproval`, the bot edits the same message to a confirmation view: |
| 75 | |
| 76 | - operation label |
| 77 | - repository/workflow target |
| 78 | - risk badge |
| 79 | - `✅ تأیید` callback |
| 80 | - `❌ لغو` callback |
| 81 | |
| 82 | Cancel returns to a safe operational view without provider execution. |
| 83 | |
| 84 | Confirmation callbacks use reserved prefixes: |
| 85 | - `approve:<token>` |
| 86 | - `cancel:<token>` |
| 87 | |
| 88 | Malformed/expired/replayed callbacks return a concise Persian error and never reach provider mutation. |
| 89 | |
| 90 | ## GitHub Advanced plugin |
| 91 | The existing GitHub plugin is extended instead of creating a second overlapping GitHub plugin. |
| 92 | |
| 93 | ### New READ actions |
| 94 | - `github.workflow.runs.list` |
| 95 | - `github.workflow.run.detail` |
| 96 | - `github.workflow.jobs.list` |
| 97 | |
| 98 | ### New WRITE actions |
| 99 | - `github.workflow.run.rerun_failed` |
| 100 | - `github.workflow.run.cancel` |
| 101 | |
| 102 | No branch deletion, merge, release publication, secret mutation, or repository settings mutation is added in this phase. |
| 103 | |
| 104 | ## GitHub service interfaces |
| 105 | Add focused methods to `GitHubService`: |
| 106 | - `listWorkflowRuns(repoId, { perPage = 10 } = {})` |
| 107 | - `getWorkflowRun(repoId, runId)` |
| 108 | - `listWorkflowJobs(repoId, runId)` |
| 109 | - `rerunFailedWorkflowRun(repoId, runId)` |
| 110 | - `cancelWorkflowRun(repoId, runId)` |
| 111 | |
| 112 | All methods resolve numeric repository IDs through the existing trusted repository resolver and use the configured bearer token. Non-2xx responses throw errors containing status and a bounded provider message. |
| 113 | |
| 114 | ## Menu changes |
| 115 | Repository detail adds an `🧪 CI / Actions` entry. Workflow views remain bounded for Telegram: |
| 116 | - maximum 10 runs in the current view |
| 117 | - concise status/conclusion/branch/SHA summary |
| 118 | - job details show step status/conclusion without full raw logs |
| 119 | |
| 120 | Raw job logs and AI analysis belong to later phases. |
| 121 | |
| 122 | ## Audit |
| 123 | Approval lifecycle emits: |
| 124 | - `approval_issued` |
| 125 | - `approval_verified` |
| 126 | - `approval_rejected` |
| 127 | - existing `action_attempt` |
| 128 | - existing `action_result` |
| 129 | |
| 130 | Audit payloads may include IDs and status but never secrets or signed approval tokens. |
| 131 | |
| 132 | ## Error handling |
| 133 | - Missing signing secret: fail closed for write approval; READ remains available. |
| 134 | - Missing Durable Object replay binding: approval consume fails closed before provider call. |
| 135 | - Signature mismatch/expiry/owner mismatch/action mismatch/replay: reject before provider call. |
| 136 | - GitHub 401/403: explicit permission/authentication error. |
| 137 | - GitHub 404: explicit not-found error. |
| 138 | - GitHub 409/422: explicit current-state conflict; do not fabricate success. |
| 139 | - Telegram edit failure follows existing error propagation behavior. |
| 140 | |
| 141 | ## Testing |
| 142 | Add unit coverage for: |
| 143 | - policy approved/unapproved semantics |
| 144 | - approval issue/verify/tamper/expiry/owner mismatch/oversize behavior |
| 145 | - durable replay consume, expiry, missing binding and Wrangler export/binding contract |
| 146 | - router execute gating with approved context |
| 147 | - GitHub REST method/path/body behavior and non-2xx failures |
| 148 | - plugin route ownership and risk mapping |
| 149 | - bot confirmation/cancel/approved callback flows |
| 150 | - no secret/token leakage in audit events |
| 151 | |
| 152 | Regression suite must retain all existing Foundation tests. |
| 153 | |
| 154 | ## Deployment acceptance |
| 155 | 1. PR CI green with non-zero test discovery. |
| 156 | 2. Merge to `main` and post-merge CI green. |
| 157 | 3. Cloudflare deployment succeeds for exact verified commit. |
| 158 | 4. Active deployment exposes `APPROVAL_REPLAY_GUARD` and exported SQLite `ApprovalReplayGuard`. |
| 159 | 5. Owner-device smoke: `/start -> Repositories -> project -> CI / Actions`. |
| 160 | 6. Live write-action smoke is only attempted after the owner confirms the action in Telegram; if the configured GitHub token lacks Actions write permission, provider-permission smoke is recorded as `NOT VERIFIED` and no secret/token rotation is performed automatically. |
| 161 | 7. Cloudflare telemetry shows current-version webhook HTTP 200 and redacted audit events with no new webhook error. |