Personal Telegram developer console for GitHub

docs: plan safe GitHub operator phase

davoodmehraban89 committed Oct 3, 2026 at 05:21 UTC 412ab269e2b88630d465c961f0e01eecca2cb68e
1 file changed +134
docs/superpowers/plans/2026-10-03-safe-github-ops.md new
+134
@@ -0,0 +1,134 @@
1 +# Safe GitHub Operator Implementation Plan
2 +
3 +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4 +
5 +**Goal:** Add reusable Telegram approvals and safe GitHub workflow operations on top of the production-accepted plugin foundation.
6 +
7 +**Architecture:** Keep the existing `resolve -> policy -> execute` boundary. Add an HMAC-backed approval service between the first approval-required dispatch and a second approved dispatch, then extend the existing GitHub plugin/service/menu with workflow read/write actions. No new external dependency is required.
8 +
9 +**Tech Stack:** JavaScript ES modules, Node test runner, Cloudflare Workers Web Crypto, Telegram Bot API, GitHub REST API.
10 +
11 +**Spec:** `docs/superpowers/specs/2026-10-03-safe-github-ops-design.md`
12 +
13 +## Global Constraints
14 +- Owner-only authorization remains enforced at the Worker boundary.
15 +- `READ` executes immediately; `WRITE` and `DESTRUCTIVE` require verified approval.
16 +- Approval tokens use HMAC-SHA-256 and never appear in audit logs.
17 +- No new paid service/resource is enabled.
18 +- Existing GitHub repository/file UX remains backward compatible.
19 +- Provider failures remain explicit; no fabricated success.
20 +
21 +## Review Focus
22 +- Tampered/expired/wrong-owner approval callback must never reach provider execution.
23 +- Telegram callback-data size overflow must fail closed before rendering an unusable button.
24 +- GitHub token 401/403/409/422 responses must surface as failures, not success.
25 +- Duplicate approval callback must not intentionally execute provider code twice in the same Worker isolate.
26 +- Existing READ navigation and Cloudflare fetch regression must remain green.
27 +
28 +---
29 +
30 +### Task 1: Approval service and policy semantics
31 +
32 +**Files:**
33 +- Create: `src/core/approval.js`
34 +- Modify: `src/core/action-policy.js`
35 +- Test: `test/approval.test.js`
36 +- Test: `test/action-policy.test.js`
37 +
38 +**Interfaces:**
39 +- Produces: `ApprovalService.issue(payload) -> token`, `ApprovalService.verify(token, expectations) -> payload`, `ApprovalService.consume(token, expectations) -> payload`.
40 +- Produces: `ActionPolicy.evaluate({ action, isOwner, approved })`.
41 +
42 +- [ ] Write failing tests for valid issue/verify, tamper, expiry, wrong owner, wrong action, oversize and replay.
43 +- [ ] Run targeted tests and verify RED.
44 +- [ ] Implement minimal approval service using Web Crypto HMAC-SHA-256 and bounded base64url payloads.
45 +- [ ] Extend policy to allow approved owner WRITE/DESTRUCTIVE actions.
46 +- [ ] Run targeted tests and verify GREEN.
47 +
48 +### Task 2: Router approved dispatch and audit lifecycle
49 +
50 +**Files:**
51 +- Modify: `src/core/router.js`
52 +- Test: `test/plugin-router.test.js`
53 +- Test: `test/audit.test.js`
54 +
55 +**Interfaces:**
56 +- Consumes: `context.approved === true` after approval verification.
57 +- Produces: policy-enforced execution and approval lifecycle audit records without signed tokens.
58 +
59 +- [ ] Add failing tests proving unapproved write does not execute and approved write does.
60 +- [ ] Verify RED.
61 +- [ ] Pass `approved` into policy and add safe audit fields.
62 +- [ ] Verify GREEN and full router/audit tests.
63 +
64 +### Task 3: GitHub workflow REST service
65 +
66 +**Files:**
67 +- Modify: `src/github.js`
68 +- Test: `test/github.test.js`
69 +
70 +**Interfaces:**
71 +- Produces: `listWorkflowRuns`, `getWorkflowRun`, `listWorkflowJobs`, `rerunFailedWorkflowRun`, `cancelWorkflowRun`.
72 +
73 +- [ ] Add failing path/method/body/error tests.
74 +- [ ] Verify RED.
75 +- [ ] Implement minimal authenticated REST methods through existing request helper/repository resolver.
76 +- [ ] Verify GREEN including 401/403/404/409/422 failure handling.
77 +
78 +### Task 4: GitHub plugin actions and workflow views
79 +
80 +**Files:**
81 +- Modify: `src/plugins/github/manifest.js`
82 +- Modify: `src/plugins/github/plugin.js`
83 +- Modify: `src/menu.js`
84 +- Test: `test/github-plugin.test.js`
85 +- Test: `test/navigation.test.js`
86 +
87 +**Interfaces:**
88 +- Produces READ actions for workflow runs/jobs and WRITE actions for rerun/cancel.
89 +- Produces compact Telegram views and callback IDs using repository/run/job IDs.
90 +
91 +- [ ] Add failing route/view/risk tests.
92 +- [ ] Verify RED.
93 +- [ ] Add manifest actions, callback resolvers and bounded workflow views.
94 +- [ ] Verify GREEN and existing navigation regression suite.
95 +
96 +### Task 5: Telegram confirmation flow
97 +
98 +**Files:**
99 +- Modify: `src/bot.js`
100 +- Test: `test/bot.test.js`
101 +
102 +**Interfaces:**
103 +- Consumes router `requiresApproval` response.
104 +- Produces `approve:<token>` and `cancel:<token>` callbacks and a second approved dispatch.
105 +
106 +- [ ] Add failing tests for confirmation rendering, cancel, verified approval, malformed/expired token and duplicate consume.
107 +- [ ] Verify RED.
108 +- [ ] Integrate `ApprovalService` with bot callback flow; never log token.
109 +- [ ] Verify GREEN and existing `/start`, `/repos`, stale callback tests.
110 +
111 +### Task 6: Local runtime command and documentation
112 +
113 +**Files:**
114 +- Modify: `package.json`
115 +- Modify: `README.md`
116 +- Modify: `PROJECT_MEMORY.md`
117 +
118 +**Interfaces:**
119 +- Produces `npm start` -> `wrangler dev` for local Worker development.
120 +
121 +- [ ] Change local start command without altering production deploy workflow.
122 +- [ ] Document safe operations and provider permission requirement.
123 +- [ ] Update project checkpoint with exact test/PR/deploy evidence after verification.
124 +
125 +### Task 7: PR, CI, deployment and runtime verification
126 +
127 +**Files:** none unless fixes are required.
128 +
129 +- [ ] Run full CI through PR and inspect logs for discovered test count/pass/fail/skip.
130 +- [ ] Review complete PR diff for scope and secret leakage.
131 +- [ ] Merge only after green CI.
132 +- [ ] Verify post-merge main CI and exact-commit Cloudflare deployment.
133 +- [ ] Verify owner-device READ navigation telemetry on current version.
134 +- [ ] Attempt a write smoke only if the existing runtime GitHub token already permits the chosen operation; otherwise record provider-permission smoke as `NOT VERIFIED` without rotating secrets automatically.