Personal Telegram developer console for GitHub
docs: add Nexa plugin foundation v1 design spec
davoodmehraban89 committed
Oct 3, 2026 at 01:14 UTC
adabadefd74de656b20d112c325be4defcbf2103
1 file changed
+317
docs/superpowers/specs/2026-10-03-nexa-plugin-foundation-design.md
new
+317
@@ -0,0 +1,317 @@
1
+# Nexa Dev Bot — Plugin Foundation v1 Design
2
+
3
+Date: 2026-10-03
4
+Status: Design approved in chat; implementation pending written-spec review
5
+Repository: `davoodmehraban89/nexa-dev-bot`
6
+Target branch: `main`
7
+
8
+## 1. Purpose
9
+
10
+Nexa Dev Bot is currently a stable owner-only Telegram interface over GitHub, deployed as a Cloudflare Worker. The next step is to turn it into an extensible DevOps control plane without coupling every new integration directly into `bot.js` and `menu.js`.
11
+
12
+Foundation v1 introduces a small plugin kernel that supports future GitHub, Cloudflare, CI/CD, AI, Browser QA, monitoring, automation and other adapters while preserving the current production behavior.
13
+
14
+Success means:
15
+
16
+1. Existing `/start`, repository browsing, file browsing, PR/commit/status views and owner-only behavior remain unchanged from the user perspective.
17
+2. Plugins can register commands, callback handlers, menu entries and actions through one registry.
18
+3. Every action has an explicit risk level and is checked by one policy engine before execution.
19
+4. Action attempts produce redacted audit events without storing secrets.
20
+5. GitHub becomes the first plugin using the new contract, proving the architecture against real existing functionality.
21
+6. CI and production deployment remain green, and Telegram runtime smoke remains the final acceptance gate.
22
+
23
+## 2. Scope
24
+
25
+### In scope
26
+
27
+- Plugin registry and manifest contract.
28
+- Action risk model: `READ`, `WRITE`, `DESTRUCTIVE`.
29
+- Central permission/policy evaluation.
30
+- Redacted audit events for action attempts and results.
31
+- Plugin routing for Telegram commands/callbacks.
32
+- Core menu entry registration.
33
+- GitHub plugin adapter around the existing `GitHubService` and menu flows.
34
+- Backward-compatible migration from the current direct `NexaDevBot -> MenuManager/GitHubService` wiring.
35
+- Unit/regression tests for the kernel and GitHub adapter.
36
+- Cloudflare-safe runtime behavior.
37
+
38
+### Explicitly out of scope for Foundation v1
39
+
40
+- AI provider integration.
41
+- Browser automation.
42
+- Supabase integration.
43
+- Sentry/Linear/Notion integrations.
44
+- Persistent user sessions or database storage.
45
+- Multi-user authorization.
46
+- Automatic destructive actions.
47
+- Telegram Mini App.
48
+- Full Cloudflare operator plugin.
49
+
50
+These are later plugins built on top of this foundation.
51
+
52
+## 3. Constraints and invariants
53
+
54
+- The bot stays owner-only.
55
+- No secret, token or private key may be persisted in repository files, audit entries or Telegram output.
56
+- Existing production navigation must continue to edit the same Telegram message for callbacks.
57
+- Telegram callback payloads must remain within the 64-byte limit.
58
+- Missing credentials fail closed.
59
+- A plugin must not bypass policy evaluation for declared actions.
60
+- `WRITE` and `DESTRUCTIVE` actions are not automatically executed in this phase; the kernel only establishes the policy contract for later approval workflows.
61
+- The Worker remains stateless in Foundation v1.
62
+
63
+## 4. Architecture
64
+
65
+### 4.1 Core modules
66
+
67
+Proposed structure:
68
+
69
+```text
70
+src/
71
+ core/
72
+ plugin-registry.js
73
+ action-policy.js
74
+ audit.js
75
+ router.js
76
+ plugins/
77
+ github/
78
+ plugin.js
79
+ manifest.js
80
+ views.js
81
+ bot.js
82
+ index.js
83
+ telegram.js
84
+ github.js
85
+ menu.js
86
+```
87
+
88
+Foundation v1 deliberately reuses `github.js` and existing view behavior instead of rewriting the GitHub API layer.
89
+
90
+### 4.2 Plugin manifest
91
+
92
+Each plugin exports a manifest with a stable identifier and declared capabilities.
93
+
94
+Conceptual contract:
95
+
96
+```js
97
+{
98
+ id: 'github',
99
+ name: 'GitHub',
100
+ version: 1,
101
+ commands: ['/repos'],
102
+ menuEntries: [...],
103
+ actions: {
104
+ 'github.repos.list': { risk: 'READ' },
105
+ 'github.repo.open': { risk: 'READ' }
106
+ }
107
+}
108
+```
109
+
110
+The registry rejects duplicate plugin IDs, duplicate action IDs and invalid risk levels at construction time.
111
+
112
+### 4.3 Plugin interface
113
+
114
+A plugin may expose:
115
+
116
+- `manifest`
117
+- `handleCommand(context)`
118
+- `handleCallback(context)`
119
+- `getMenuEntries(context)`
120
+- optional `health(context)`
121
+
122
+A plugin returns either `null` when it does not own the route or a normalized response/view object. Core routing decides which plugin receives a command/callback; transport remains centralized in `NexaDevBot`.
123
+
124
+### 4.4 Action policy
125
+
126
+Every action execution goes through `ActionPolicy.evaluate()`.
127
+
128
+Policy result:
129
+
130
+```js
131
+{
132
+ allowed: true,
133
+ requiresApproval: false,
134
+ risk: 'READ',
135
+ reason: 'owner_read_allowed'
136
+}
137
+```
138
+
139
+Initial rules:
140
+
141
+- `READ`: allowed for the authenticated owner.
142
+- `WRITE`: not auto-executed; returns `requiresApproval: true`.
143
+- `DESTRUCTIVE`: not auto-executed; returns `requiresApproval: true` and marks the operation as high risk.
144
+- Unknown action/risk: denied.
145
+
146
+No confirmation UX is implemented yet; Foundation v1 only makes the contract enforceable so later write-capable plugins cannot skip it.
147
+
148
+### 4.5 Audit trail
149
+
150
+`AuditLogger` receives structured events such as:
151
+
152
+```js
153
+{
154
+ event: 'action_attempt',
155
+ pluginId: 'github',
156
+ actionId: 'github.repos.list',
157
+ risk: 'READ',
158
+ outcome: 'allowed'
159
+}
160
+```
161
+
162
+Foundation v1 uses Cloudflare `console` output only. It does not add storage.
163
+
164
+Redaction rules:
165
+
166
+- Never include Telegram bot token.
167
+- Never include webhook secret.
168
+- Never include GitHub token.
169
+- Never include raw authorization headers.
170
+- Errors pass through the existing safe redaction helper or an equivalent shared sanitizer.
171
+
172
+## 5. Data and control flow
173
+
174
+### `/start`
175
+
176
+```text
177
+Telegram webhook
178
+ -> index security gates
179
+ -> NexaDevBot
180
+ -> core router
181
+ -> core/main menu + plugin menu entries
182
+ -> TelegramClient.sendMessage
183
+```
184
+
185
+### GitHub callback
186
+
187
+```text
188
+callback query
189
+ -> callback acknowledgement (best effort)
190
+ -> core router resolves github plugin
191
+ -> policy evaluates declared READ action
192
+ -> audit action attempt
193
+ -> github plugin delegates to existing GitHubService/view logic
194
+ -> TelegramClient.editMessageText
195
+ -> audit result
196
+```
197
+
198
+### Future write action
199
+
200
+```text
201
+callback/command
202
+ -> plugin declares WRITE action
203
+ -> policy returns requiresApproval
204
+ -> core does not execute action
205
+ -> later approval subsystem renders confirmation UX
206
+```
207
+
208
+This guarantees the safety boundary exists before write-capable plugins are added.
209
+
210
+## 6. Migration strategy
211
+
212
+Foundation v1 is incremental, not a rewrite.
213
+
214
+1. Add core modules with tests while production code still uses the current direct flow.
215
+2. Introduce GitHub plugin adapter around the existing `GitHubService` and current views.
216
+3. Route only GitHub-related commands/callbacks through the registry.
217
+4. Keep existing top-level status/tools/settings/security views working through compatibility paths during this phase.
218
+5. Remove direct GitHub routing from `bot.js` only after regression tests prove behavioral parity.
219
+
220
+No production behavior is intentionally changed in this migration.
221
+
222
+## 7. Error handling
223
+
224
+- Registry construction errors fail fast in tests/startup.
225
+- Unknown command/callback falls back to the current main-menu behavior.
226
+- Plugin exceptions are caught at the bot boundary, redacted and surfaced as safe operational failures.
227
+- Telegram transport failures keep existing explicit propagation behavior.
228
+- Policy denial never calls the plugin action implementation.
229
+- Audit logging failure must not break a read-only user action; audit logging is best-effort in Foundation v1, but failures are themselves safely logged when possible.
230
+
231
+## 8. Testing strategy
232
+
233
+### New unit tests
234
+
235
+- Registry accepts valid plugin.
236
+- Registry rejects duplicate plugin ID.
237
+- Registry rejects duplicate action IDs.
238
+- Registry rejects unknown risk level.
239
+- Router dispatches command to exactly one plugin.
240
+- Router dispatches callback to exactly one plugin.
241
+- Unknown route returns no plugin match.
242
+- Policy allows owner `READ`.
243
+- Policy requires approval for `WRITE`.
244
+- Policy requires approval for `DESTRUCTIVE`.
245
+- Policy denies undeclared/unknown action.
246
+- Audit logger redacts known secrets.
247
+
248
+### Migration regression tests
249
+
250
+- `/start` renders the same main menu behavior.
251
+- `/repos` still uses live GitHub data.
252
+- `menu:repos`, `repo:*`, `files:*`, `tree:*`, `blob:*`, `pr:*`, `commits:*`, `status:*` continue to work.
253
+- Callback navigation still edits the same Telegram message.
254
+- Callback acknowledgement failure still cannot block rendering.
255
+- Missing GitHub token still fails closed.
256
+- Non-owner update still produces no private response.
257
+- Cloudflare-specific default `fetch` receiver regression remains green.
258
+
259
+### Acceptance gates
260
+
261
+- All existing tests pass.
262
+- New kernel/plugin tests pass.
263
+- CI on the feature branch passes.
264
+- PR diff contains no secret material.
265
+- Post-merge `main` CI passes.
266
+- Cloudflare deploy workflow passes.
267
+- Production Telegram `/start` and GitHub navigation smoke pass before Foundation v1 is marked complete.
268
+
269
+## 9. Security model
270
+
271
+The kernel is designed so future integrations cannot treat Telegram button presses as implicit authorization for arbitrary writes.
272
+
273
+Security boundaries:
274
+
275
+1. `index.js`: webhook secret + owner identity.
276
+2. `router`: route ownership.
277
+3. `ActionPolicy`: action authorization/risk decision.
278
+4. plugin: implementation only after allowed policy result.
279
+5. `AuditLogger`: traceable, redacted action record.
280
+
281
+This does not replace provider-side least privilege. GitHub/Cloudflare/Supabase credentials should still be scoped to the minimum permissions required by each future plugin.
282
+
283
+## 10. Files expected to change in implementation
284
+
285
+New:
286
+
287
+- `src/core/plugin-registry.js`
288
+- `src/core/action-policy.js`
289
+- `src/core/audit.js`
290
+- `src/core/router.js`
291
+- `src/plugins/github/manifest.js`
292
+- `src/plugins/github/plugin.js`
293
+- kernel/plugin test files
294
+
295
+Likely modified:
296
+
297
+- `src/bot.js`
298
+- `src/menu.js` or a compatibility extraction used by the GitHub plugin
299
+- `test/bot.test.js`
300
+- `test/navigation.test.js`
301
+- `PROJECT_MEMORY.md`
302
+
303
+`src/github.js`, `src/telegram.js` and `src/index.js` should change only if required by an explicit integration boundary or shared redaction extraction; unrelated refactors are excluded.
304
+
305
+## 11. Definition of done
306
+
307
+Foundation v1 is complete only when all of the following are true:
308
+
309
+- Plugin registry exists and validates manifests.
310
+- GitHub functionality is routed through the plugin contract.
311
+- Action policy is enforced before plugin actions.
312
+- Read actions are audited with secrets redacted.
313
+- Existing Telegram UX is behaviorally compatible.
314
+- Automated tests and CI are green.
315
+- Exact verified commit is deployed by the Cloudflare workflow.
316
+- Real Telegram smoke confirms `/start` and GitHub navigation on the deployed Worker.
317
+- `PROJECT_MEMORY.md` records the final evidence and any remaining NOT VERIFIED items.