Personal Telegram developer console for GitHub

docs: design repository workspace editor

davoodmehraban89 committed Oct 3, 2026 at 11:44 UTC 0d6028450cf0847fc366c330951b42bb17197cd1
2 files changed +394 -41
PROJECT_MEMORY.md
+51 -41
@@ -79,7 +79,6 @@ Conclusion:
79 - Post-merge CI #172 / run `37102293956` succeeded on that exact SHA with 22 test files and 97/97 tests passing, 0 fail/skip/cancelled.
80 - Deploy #108 / run `37102308006` succeeded from that exact SHA.
81 - Active Cloudflare production version after deploy: `bc23d9e5-1490-429c-9369-4e751f173df5` at 100% traffic.
82 -- Cloudflare Observability issue summary after deploy showed 0 active issues and 0 active occurrences.
82
83 ### TDD evidence
84 - Provider RED CI #156 / run `37100585034`: 87 tests total, 82 pass / 5 expected failures for missing Advanced provider readers.
@@ -103,51 +102,62 @@ Conclusion:
102 - New READ callbacks resolve without provider calls before central policy evaluation; callback lengths are regression-tested against Telegram limits.
103 - READ provider failures visibly update Telegram instead of appearing silent.
104
106 -### Owner-device production smoke findings
107 -- Owner exercised the new Advanced READ menu on Telegram after production deploy; most tested paths rendered and navigated as expected.
108 -- `Issues` failed live with GitHub `403 Resource not accessible by personal access token`.
109 -- Cloudflare production audit confirmed `github.issues.list` passed central READ policy and then failed only at the GitHub provider boundary with that 403.
110 -- Root cause: the existing fine-grained PAT does not currently grant Repository permissions -> Issues -> Read. Existing visible permissions include Metadata Read plus Actions/Code/Pull requests Read and Write.
111 -- `Releases` did not fail: a direct GitHub releases read returned an empty list `[]`, proving this repository currently has no GitHub Releases. The old Telegram empty-state wording was merely ambiguous.
105 +## GitHub Advanced READ Production Acceptance — PR #20
106 +- Live owner-device smoke found two gaps: Issues returned GitHub 403 due missing `Issues: Read`, while Releases successfully returned an empty source-backed list.
107 +- PR #20 `fix: clarify Issues permission and empty Releases state` merged to `main` at `7c0df4c8616c6859a2dfc4c35b0e22d6e47215bc`.
108 +- Post-merge CI #177 / run `37106715317` completed successfully on that exact SHA with 23 test files and 99/99 tests passing, 0 fail/skip/cancelled.
109 +- Deploy #113 / run `37106727515` completed successfully after checking out that exact SHA.
110 +- Active Cloudflare production version after deploy: `5741faa0-720f-48d5-9e76-64726a5f5167` at 100% traffic.
111 +- Owner updated the existing fine-grained PAT to add only Repository permissions -> Issues -> Read-only; token value was not rotated/stored/logged.
112 +- Owner-device Telegram smoke after that permission change showed Issues no longer returns 403 and Releases renders the explicit no-published-release state.
113 +- Cloudflare production telemetry on version `5741faa0-720f-48d5-9e76-64726a5f5167` recorded `github.issues.list` with `outcome=success` and `github.releases.list` with `outcome=success` for the owner-device interactions.
114
113 -## Current Work — PR #20 Live-Smoke Findings Hardening
114 -- Branch: `fix/issues-permission-release-empty-ux`.
115 -- Draft PR #20: `fix: clarify Issues permission and empty Releases state`.
116 -- Scope is UI/error-guidance only; no new provider mutation is added.
117 -- Issues 403 feedback now tells the owner the exact least-privilege setting required: Fine-grained token -> Repository permissions -> Issues -> Read.
118 -- Empty Releases view now explicitly says that no GitHub Release is published for the repository instead of presenting an ambiguous not-found message.
119 -
120 -### TDD evidence
121 -- RED CI #173 / run `37106220231`: 23 test files, 99 tests total, 97 pass / exactly 2 expected failures for the live Issues-permission guidance and empty Releases wording.
122 -- GREEN CI #175 / run `37106470008` at implementation head `d779c746dd4c0dadb652f9d2375ba7765ff5803b`: 23 test files, 99/99 pass, 0 fail/skip/cancelled.
123 -- A fresh final CI is still required after this memory checkpoint because this documentation commit moves the PR head.
124 -
125 -### Not yet production-accepted
126 -- PR #20 is not merged/deployed at this checkpoint.
127 -- Exact post-merge `main` CI and Cloudflare deployment for PR #20 are NOT VERIFIED.
128 -- Issues live success remains NOT VERIFIED until the owner adds only `Issues: Read` to the existing fine-grained token and repeats the Telegram Issues read.
129 -- Releases source-backed empty state is verified at the GitHub API boundary, but the revised Telegram wording is NOT VERIFIED on the owner device until PR #20 is deployed.
115 +Conclusion:
116 +- GitHub Advanced READ production acceptance: VERIFIED.
117 +- Issues least-privilege provider authorization: VERIFIED.
118 +- Releases source-backed empty state: VERIFIED.
119 +- Telegram owner-device/runtime evidence: VERIFIED.
120 +
121 +## Current Design Work — Repository Workspace / Code Editor
122 +- Owner explicitly requires the future ability to open a file in any accessible repository, edit it from the Nexa mobile control plane, review the change, commit it, and send it back to GitHub.
123 +- Owner approved the architectural direction: branch-first, diff-first, no provider commit without Safe Approval, single-file first with a multi-file-capable architecture.
124 +- Design spec path: `docs/superpowers/specs/2026-10-03-repository-workspace-editor-design.md`.
125 +- Design branch: `spec/repository-workspace-editor`.
126 +- This is an architectural subsystem and is not yet implementation-approved until the owner reviews the written spec.
127 +
128 +### Approved design direction captured in the spec
129 +- Phase 1: durable owner-scoped single-file text workspace, exact diff, conflict/staleness checks, branch-first GitHub commit, Safe Approval, commit SHA + CI handoff.
130 +- Commit engine is based on Git Data blobs/trees/commits/refs so Phase 2 can atomically commit multiple files without redesign.
131 +- Draft content is stored outside Telegram callback data/process memory, preferably in a dedicated `WORKSPACE_STORE` Durable Object; existing `APPROVAL_REPLAY_GUARD` remains dedicated to approval replay protection.
132 +- Direct writes to `main` are out of scope for Phase 1 and may be added later only as an explicitly enabled high-risk path that respects GitHub protection rules.
133 +- Binary/LFS, automatic conflict resolution, secret/private-key-like files and arbitrary shell execution are out of scope for Phase 1.
134 +- Production acceptance requires owner-device evidence proving draft-only behavior before approval, exact diff, one approved commit, replay rejection, and GitHub/Cloudflare evidence agreement.
135 +
136 +### Not yet implementation-complete
137 +- Written spec requires owner review/approval before implementation planning.
138 +- No workspace storage binding/class has been added yet.
139 +- No editor WRITE action has been added yet.
140 +- No new GitHub commit mutation has been added yet.
141 +- No production editor smoke has been run yet.
142
143 ## Next Executable Actions
132 -1. Run fresh final PR #20 CI after this checkpoint; review the exact diff and secret patterns.
133 -2. Mark PR #20 ready and squash-merge only the exact reviewed green head.
134 -3. Verify exact post-merge `main` CI, deploy, active Cloudflare version and production runtime/telemetry.
135 -4. Owner adds only `Repository permissions -> Issues -> Read` to the existing fine-grained GitHub token; do not regenerate or rotate the token unnecessarily.
136 -5. Owner repeats Telegram `Issues` and `Releases`; verify production audit records provider success for both reads.
137 -6. Close GitHub Advanced READ production acceptance only after that owner-device/runtime verification.
138 -7. Then implement remaining GitHub Advanced WRITE items only where operationally useful and always through Safe Approval, followed by Cloudflare Ops.
144 +1. Owner reviews `docs/superpowers/specs/2026-10-03-repository-workspace-editor-design.md` and approves or requests changes.
145 +2. After written-spec approval, create the implementation plan via the required planning workflow.
146 +3. Implement with TDD in vertical slices: workspace storage -> edit/diff UX -> Git Data commit engine -> Safe Approval integration -> CI handoff -> production smoke.
147 +4. Only after Repository Workspace Phase 1 production acceptance, continue remaining useful GitHub Advanced WRITE operations and then Cloudflare Ops.
148
149 ## Remaining Roadmap
141 -1. Finish GitHub Advanced production acceptance; add workflow dispatch/specific-job rerun only if operationally useful and always via Safe Approval.
142 -2. Cloudflare Ops plugin: deployments, versions, bindings, health, telemetry/runtime errors and approval-gated rollback/deploy operations.
143 -3. CI/CD Control Plane and release acceptance orchestration.
144 -4. Monitoring + Incident Manager.
145 -5. Automation Engine with resumable/idempotent approval-aware workflows.
146 -6. AI Copilot with no direct production mutation.
147 -7. Browser QA real production smoke.
148 -8. Telegram Mini App backed by real APIs.
149 -9. Plugin ecosystem and multi-project control plane.
150 -10. Final hardening, recovery drills, docs and versioning.
150 +1. Repository Workspace / Code Editor Phase 1, then multi-file expansion.
151 +2. Remaining useful GitHub Advanced WRITE actions (for example workflow dispatch/specific-job rerun), always through Safe Approval.
152 +3. Cloudflare Ops plugin: deployments, versions, bindings, health, telemetry/runtime errors and approval-gated rollback/deploy operations.
153 +4. CI/CD Control Plane and release acceptance orchestration.
154 +5. Monitoring + Incident Manager.
155 +6. Automation Engine with resumable/idempotent approval-aware workflows.
156 +7. AI Copilot with no direct production mutation.
157 +8. Browser QA real production smoke.
158 +9. Telegram Mini App backed by the same workspace/control-plane APIs.
159 +10. Plugin ecosystem and multi-project control plane.
160 +11. Final hardening, recovery drills, docs and versioning.
161
162 ## Project Boundaries
163 - Nexa Dev Bot is independent from Finora / Factor-easy unless an explicit adapter is added.
docs/superpowers/specs/2026-10-03-repository-workspace-editor-design.md new
+343
@@ -0,0 +1,343 @@
1 +# Repository Workspace / Code Editor Design
2 +
3 +Date: 2026-10-03
4 +Status: Proposed for implementation after owner review
5 +Owner intent: let the repository owner browse a repository from Telegram, open a text file, edit it safely, inspect the exact diff, and commit the change back to GitHub. The architecture must support multi-file workspaces later without weakening approval, audit, branch, or conflict-safety rules.
6 +
7 +## 1. Goals
8 +
9 +The feature must let the owner:
10 +
11 +1. Select any repository already visible through Nexa.
12 +2. Browse to a text file and open a bounded preview.
13 +3. Start an edit workspace without writing anything to GitHub.
14 +4. Change file content or a bounded line range.
15 +5. Review a source-backed before/after diff.
16 +6. Provide a commit message.
17 +7. Commit only after Safe Approval.
18 +8. Receive the resulting commit SHA and continue into CI / Actions monitoring.
19 +9. Later edit multiple files in one workspace and commit them atomically.
20 +
21 +The central product goal is to make Nexa a real mobile developer control plane, not only a repository viewer.
22 +
23 +## 2. Delivery Strategy
24 +
25 +### Phase 1 — Safe single-file workspace
26 +
27 +Ship one-file editing first, but build the data model and commit engine so multi-file workspaces do not require a redesign.
28 +
29 +Phase 1 supports:
30 +- owner-only text-file editing;
31 +- branch-first commits;
32 +- bounded file preview and editing payloads;
33 +- exact diff before approval;
34 +- conflict detection against the original base HEAD;
35 +- Safe Approval before the GitHub mutation;
36 +- commit SHA feedback and CI handoff.
37 +
38 +Phase 1 does not support:
39 +- binary files;
40 +- Git LFS objects;
41 +- automatic merge/conflict resolution;
42 +- arbitrary shell execution;
43 +- direct commits to `main`;
44 +- editing likely-secret/private-key files;
45 +- multi-user collaboration.
46 +
47 +### Phase 2 — Multi-file workspace
48 +
49 +Reuse the same workspace and commit engine to stage several changed files and create one atomic tree/commit.
50 +
51 +### Phase 3 — Rich editor surface
52 +
53 +A Telegram Mini App can later use the same workspace API for larger files, syntax-aware editing, multi-file tabs, search and richer diff presentation. The Telegram chat UI remains the safe control and approval surface.
54 +
55 +## 3. User Flow
56 +
57 +### Open and edit
58 +
59 +`/start -> Repositories -> <repo> -> Files -> <file> -> Edit`
60 +
61 +The file view shows:
62 +- path;
63 +- branch/ref;
64 +- blob SHA;
65 +- file size;
66 +- bounded text preview;
67 +- `Edit` only when the file passes editable-file policy.
68 +
69 +Pressing `Edit` creates a local Nexa workspace. This is not a GitHub WRITE.
70 +
71 +### Draft
72 +
73 +The workspace records:
74 +- owner id;
75 +- repository id/full name;
76 +- base branch;
77 +- base HEAD SHA;
78 +- source path;
79 +- source blob SHA;
80 +- original content digest;
81 +- draft content/digest;
82 +- created/updated timestamps;
83 +- expiration time;
84 +- workspace state.
85 +
86 +The owner submits replacement text or a bounded line-range edit. Nexa validates size, encoding, path and workspace ownership before accepting it.
87 +
88 +### Review
89 +
90 +Nexa renders a bounded unified diff and summary:
91 +- repository;
92 +- base branch;
93 +- planned target branch;
94 +- file path;
95 +- additions/deletions;
96 +- original blob/base HEAD;
97 +- proposed content digest;
98 +- commit message.
99 +
100 +No provider mutation happens during preview.
101 +
102 +### Commit
103 +
104 +The default path is:
105 +
106 +`draft -> review diff -> Safe Approval -> create/update feature branch -> create commit -> return SHA -> monitor CI`
107 +
108 +The approval target binds at least:
109 +- repository;
110 +- base HEAD SHA;
111 +- target branch;
112 +- changed path(s);
113 +- proposed content/tree digest;
114 +- commit message digest;
115 +- action id;
116 +- owner;
117 +- expiry.
118 +
119 +If anything material changes after approval is issued, Nexa must require a new approval.
120 +
121 +## 4. Branch Policy
122 +
123 +### Default: branch-first
124 +
125 +Phase 1 never commits directly to `main`.
126 +
127 +Nexa generates or accepts a safe branch name such as:
128 +
129 +`nexa/edit-<short-workspace-id>`
130 +
131 +The final mutation may create the branch and commit as one approved composite action. This keeps drafts local while avoiding an unnecessary provider write before final confirmation.
132 +
133 +### Direct-main future mode
134 +
135 +Direct commits to the default branch are deferred. If added later they must be explicitly enabled, clearly marked high-risk, respect branch protection/rulesets, and use a stronger confirmation UX. Nexa must never bypass GitHub protection rules.
136 +
137 +## 5. Commit Engine
138 +
139 +The implementation should use GitHub Git Data primitives rather than designing around one-file Contents API behavior:
140 +
141 +1. Read and pin the base HEAD commit/tree.
142 +2. Create blob(s) for staged content.
143 +3. Create a new tree from the pinned base tree.
144 +4. Create one commit pointing to that tree.
145 +5. Create or fast-forward the approved target branch ref.
146 +
147 +This is slightly more work for the first single-file version, but it gives the correct atomic foundation for Phase 2 multi-file commits.
148 +
149 +No branch ref may be moved if the repository state no longer matches the conflict checks described below.
150 +
151 +## 6. Conflict and Staleness Safety
152 +
153 +A workspace is optimistic-concurrency controlled.
154 +
155 +Before final mutation Nexa re-reads the relevant branch state.
156 +
157 +Rules:
158 +- If the base branch HEAD no longer matches the workspace base HEAD, the commit is blocked as stale.
159 +- Nexa does not silently rebase, merge or overwrite.
160 +- The owner is shown the conflict/staleness reason and can refresh the workspace from the new base.
161 +- If a target branch already exists unexpectedly or moved since approval, the action fails closed.
162 +- A provider 409/422 or protection error is surfaced to Telegram and audited; success is never fabricated.
163 +
164 +## 7. Workspace Storage
165 +
166 +Draft content must not be stored in Telegram callback data or process memory.
167 +
168 +Use a dedicated owner-scoped durable workspace store, preferably a separate Durable Object namespace/class such as `WORKSPACE_STORE` / `WorkspaceStore`.
169 +
170 +Properties:
171 +- workspace id is random and non-secret;
172 +- every operation checks owner identity;
173 +- data is scoped by owner + workspace id;
174 +- TTL cleanup removes abandoned drafts;
175 +- no GitHub token, Telegram token or signing secret is stored in the workspace;
176 +- audit logs store metadata/digests, not full sensitive file contents;
177 +- draft state is never treated as a provider commit.
178 +
179 +The existing `APPROVAL_REPLAY_GUARD` remains dedicated to one-time approval consumption.
180 +
181 +## 8. Editable File Policy
182 +
183 +Phase 1 accepts UTF-8 text only.
184 +
185 +Reject or disable edit for:
186 +- binary/non-UTF-8 content;
187 +- files above the configured edit-size ceiling;
188 +- Git LFS pointers when unsafe to edit as normal text;
189 +- probable private-key/credential files such as common `.pem`, `id_rsa`, and committed environment-secret patterns;
190 +- generated files identified by explicit project policy when available.
191 +
192 +Reads may remain available where already allowed, but the editor should fail closed for risky write targets.
193 +
194 +All rendered file content and diff text must be HTML-escaped and bounded for Telegram.
195 +
196 +## 9. Telegram UX
197 +
198 +New controls should fit naturally into the existing GitHub plugin:
199 +
200 +File view:
201 +- `✏️ Edit`
202 +- existing navigation/back controls
203 +
204 +Workspace view:
205 +- path + base ref
206 +- draft status
207 +- `📝 تغییر متن`
208 +- `🔍 مشاهده Diff`
209 +- `💬 پیام Commit`
210 +- `✅ آماده Commit`
211 +- `🗑 لغو Draft`
212 +
213 +Ready-to-commit view:
214 +- exact change summary;
215 +- bounded diff;
216 +- target branch;
217 +- commit message;
218 +- `✅ تأیید و Commit` through Safe Approval;
219 +- cancel/back.
220 +
221 +After commit:
222 +- resulting SHA;
223 +- branch;
224 +- `🧪 CI / Actions`;
225 +- optional later `Create PR` action, separately approval-gated.
226 +
227 +For content too large to edit comfortably in chat, Phase 1 should explain the limit rather than truncate editable input silently. The richer Mini App editor is the planned expansion path.
228 +
229 +## 10. Action Model and Risk
230 +
231 +New actions should be explicit in the GitHub plugin manifest.
232 +
233 +READ examples:
234 +- `github.workspace.view`
235 +- `github.workspace.diff`
236 +
237 +Local/draft actions do not call GitHub and remain owner-only.
238 +
239 +Provider WRITE examples:
240 +- `github.workspace.commit_branch`
241 +- later `github.pr.create_from_workspace`
242 +
243 +Every provider WRITE must pass through the existing Action Policy, HMAC approval, durable replay guard and audit lifecycle.
244 +
245 +The commit provider call must not occur until approval is successfully consumed.
246 +
247 +## 11. Audit Requirements
248 +
249 +Audit events must let us reconstruct the control-plane decision without leaking source contents.
250 +
251 +Record metadata such as:
252 +- workspace id;
253 +- repo id;
254 +- base SHA;
255 +- target branch;
256 +- paths changed;
257 +- count of files;
258 +- additions/deletions when available;
259 +- proposed tree/content digest;
260 +- action/policy/approval outcome;
261 +- resulting commit SHA on success;
262 +- provider error category on failure.
263 +
264 +Do not log:
265 +- full file contents;
266 +- tokens/secrets;
267 +- signed approval callback tokens.
268 +
269 +## 12. Testing Strategy
270 +
271 +Implementation must be TDD and include:
272 +
273 +### Unit / provider
274 +- editable-file validation;
275 +- workspace owner isolation;
276 +- TTL/stale workspace behavior;
277 +- text/diff bounds and escaping;
278 +- blob/tree/commit/ref request construction;
279 +- multi-file-capable tree construction even if UI initially stages one file;
280 +- GitHub error propagation.
281 +
282 +### Policy / security
283 +- no GitHub WRITE before approval;
284 +- approval target binds repo/base/branch/path/content digest;
285 +- replay rejected;
286 +- expired approval rejected;
287 +- stale base HEAD blocks mutation;
288 +- unexpected target-branch movement blocks mutation;
289 +- non-owner cannot read or mutate workspace;
290 +- sensitive-file policy fails closed.
291 +
292 +### Integration
293 +- create draft -> edit -> diff -> approve -> branch commit;
294 +- provider failure visibly updates Telegram;
295 +- successful commit returns exact SHA and CI navigation.
296 +
297 +### Production acceptance
298 +CI alone is insufficient. Acceptance requires an owner-device smoke on a safe test file/branch proving:
299 +1. draft creation does not change GitHub;
300 +2. diff matches the proposed edit;
301 +3. no GitHub write occurs before approval;
302 +4. confirmation creates exactly one commit on the intended branch;
303 +5. replay does not create a second commit;
304 +6. GitHub and Cloudflare audit/runtime evidence agree on the same operation.
305 +
306 +## 13. Acceptance Criteria
307 +
308 +Phase 1 is complete only when all are true:
309 +
310 +- owner can open an eligible text file from Telegram;
311 +- owner can create/edit a durable draft;
312 +- exact bounded diff is visible before commit;
313 +- `main` is not directly mutated;
314 +- stale-base conflicts fail closed;
315 +- final GitHub mutation is Safe-Approval gated and one-time;
316 +- resulting commit SHA/branch are shown from provider evidence;
317 +- CI handoff is available;
318 +- audit does not expose full draft/source contents or secrets;
319 +- automated tests pass;
320 +- exact production deployment is verified;
321 +- owner-device production smoke passes.
322 +
323 +## 14. Roadmap Placement
324 +
325 +Updated order:
326 +
327 +1. GitHub Advanced READ production acceptance — completed.
328 +2. Repository Workspace / Code Editor — this design.
329 +3. Remaining useful GitHub Advanced WRITE operations (for example workflow dispatch or specific-job rerun) through Safe Approval.
330 +4. Cloudflare Ops plugin.
331 +5. CI/CD Control Plane and release acceptance orchestration.
332 +6. Monitoring + Incident Manager.
333 +7. Automation Engine.
334 +8. AI Copilot with no direct production mutation.
335 +9. Browser QA.
336 +10. Telegram Mini App using the same workspace/control-plane APIs.
337 +11. Plugin ecosystem, multi-project control plane and final hardening.
338 +
339 +## 15. Key Architecture Decision
340 +
341 +The editor is not a special bypass around GitHub controls. It is a first-class GitHub WRITE workflow built on the same policy, approval, replay-protection and audit boundary already proven in production.
342 +
343 +The initial UI is deliberately small, but the underlying workspace + Git Data commit model is designed for later multi-file atomic commits and a richer editor without changing the security contract.