Personal Telegram developer console for GitHub
docs: add plugin foundation v1 implementation plan
davoodmehraban89 committed
Oct 3, 2026 at 01:17 UTC
5f9a1991dbc3a1e79f5c04dfbe591c4d35e74a97
1 file changed
+284
docs/superpowers/plans/2026-10-03-nexa-plugin-foundation.md
new
+284
@@ -0,0 +1,284 @@
1
+# Nexa Dev Bot Plugin Foundation v1 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:** Introduce a small plugin kernel with explicit action risk policy and redacted auditing, then route existing GitHub behavior through a GitHub plugin without changing Telegram UX.
6
+
7
+**Architecture:** Add focused core modules for registry, policy, audit, and routing. Wrap the existing `GitHubService`/`MenuManager` behavior in a GitHub plugin adapter so existing UI and transport remain stable while future integrations gain a common extension contract.
8
+
9
+**Tech Stack:** JavaScript ES modules, Node.js 22 test runner, Cloudflare Workers, Telegram Bot API, GitHub REST API.
10
+
11
+**Spec:** `docs/superpowers/specs/2026-10-03-nexa-plugin-foundation-design.md`
12
+
13
+## Global Constraints
14
+
15
+- Bot remains owner-only.
16
+- No secret, token, authorization header, or private key may appear in audit output, repository files, or Telegram output.
17
+- Existing callback navigation continues to edit the same Telegram message.
18
+- Callback payloads remain within Telegram's 64-byte limit.
19
+- Missing credentials fail closed.
20
+- Every declared plugin action must pass central policy evaluation before execution.
21
+- `WRITE` and `DESTRUCTIVE` actions are not automatically executed in Foundation v1.
22
+- Worker remains stateless.
23
+- No AI, Browser QA, Supabase, Sentry, Linear, Notion, Mini App, or full Cloudflare operator implementation in this phase.
24
+
25
+## File Structure
26
+
27
+New:
28
+- `src/core/plugin-registry.js` — validates and indexes plugin manifests/actions.
29
+- `src/core/action-policy.js` — evaluates `READ` / `WRITE` / `DESTRUCTIVE` actions.
30
+- `src/core/audit.js` — best-effort structured audit with secret redaction.
31
+- `src/core/router.js` — resolves commands/callbacks to one plugin and enforces policy before execution.
32
+- `src/plugins/github/manifest.js` — GitHub plugin manifest/action declarations.
33
+- `src/plugins/github/plugin.js` — adapter over current `GitHubService` and `MenuManager` GitHub routes.
34
+- `test/plugin-registry.test.js`
35
+- `test/action-policy.test.js`
36
+- `test/audit.test.js`
37
+- `test/plugin-router.test.js`
38
+- `test/github-plugin.test.js`
39
+
40
+Modified:
41
+- `src/bot.js` — construct registry/router, route GitHub command/callbacks through plugin kernel, retain compatibility paths for non-GitHub menus.
42
+- `PROJECT_MEMORY.md` — record request, implementation evidence, CI/deploy/runtime status.
43
+
44
+## Review Focus
45
+
46
+1. Duplicate plugin/action identifiers must fail fast instead of silently shadowing an existing route.
47
+2. Unknown risk values or undeclared actions must be denied and must never invoke plugin code.
48
+3. Audit serialization must redact secrets even when they occur inside nested error/message values.
49
+4. A plugin returning `null` must not consume a route; the router must continue/fall back deterministically without dispatching two plugins.
50
+5. Callback acknowledgement failure must still not block GitHub plugin rendering/editing after migration.
51
+
52
+---
53
+
54
+### Task 1: Plugin Registry
55
+
56
+**Files:**
57
+- Create: `src/core/plugin-registry.js`
58
+- Create: `test/plugin-registry.test.js`
59
+
60
+**Interfaces:**
61
+- Produces: `PluginRegistry`, constructor `new PluginRegistry(plugins = [])`
62
+- Produces: `registry.getPlugins()`, `registry.getAction(actionId)`, `registry.getPlugin(pluginId)`
63
+- Manifest actions use `{ [actionId]: { risk: 'READ'|'WRITE'|'DESTRUCTIVE' } }`
64
+
65
+- [ ] **Step 1: Write failing registry tests**
66
+
67
+Cover valid registration, duplicate plugin ID, duplicate action ID, invalid risk, and lookup behavior.
68
+
69
+- [ ] **Step 2: Run registry test and confirm RED**
70
+
71
+Run: `node --test test/plugin-registry.test.js`
72
+Expected: FAIL because `src/core/plugin-registry.js` does not exist.
73
+
74
+- [ ] **Step 3: Implement `PluginRegistry` minimally**
75
+
76
+Validate plugin `manifest.id`, `manifest.actions`, and allowed risk values. Store immutable lookup maps sufficient for later router/policy tasks.
77
+
78
+- [ ] **Step 4: Run registry test and confirm GREEN**
79
+
80
+Run: `node --test test/plugin-registry.test.js`
81
+Expected: PASS.
82
+
83
+- [ ] **Step 5: Commit**
84
+
85
+Commit message: `feat: add plugin registry`
86
+
87
+### Task 2: Action Policy and Redacted Audit
88
+
89
+**Files:**
90
+- Create: `src/core/action-policy.js`
91
+- Create: `src/core/audit.js`
92
+- Create: `test/action-policy.test.js`
93
+- Create: `test/audit.test.js`
94
+
95
+**Interfaces:**
96
+- Consumes: action descriptors returned by `PluginRegistry.getAction(actionId)`
97
+- Produces: `ActionPolicy.evaluate({ action, isOwner }) -> { allowed, requiresApproval, risk, reason }`
98
+- Produces: `AuditLogger` with `log(event)` and shared redaction over configured secret values
99
+
100
+- [ ] **Step 1: Write failing policy tests**
101
+
102
+Assert owner `READ` is allowed without approval; `WRITE` and `DESTRUCTIVE` require approval and are not auto-executed; non-owner and missing/unknown action are denied.
103
+
104
+- [ ] **Step 2: Run policy test and confirm RED**
105
+
106
+Run: `node --test test/action-policy.test.js`
107
+Expected: FAIL because module is missing.
108
+
109
+- [ ] **Step 3: Implement `ActionPolicy` minimally**
110
+
111
+Use exact risks `READ`, `WRITE`, `DESTRUCTIVE`; return deterministic reason strings and deny unknown/missing actions.
112
+
113
+- [ ] **Step 4: Write failing audit tests**
114
+
115
+Assert nested strings containing bot/webhook/GitHub secrets are emitted redacted and that logging exceptions do not escape to the caller.
116
+
117
+- [ ] **Step 5: Run audit test and confirm RED**
118
+
119
+Run: `node --test test/audit.test.js`
120
+Expected: FAIL because module is missing.
121
+
122
+- [ ] **Step 6: Implement `AuditLogger` minimally**
123
+
124
+Accept secret values at construction, recursively sanitize string values, then emit structured events through an injectable sink defaulting to `console.log`; sink failure is swallowed after best-effort safe error logging.
125
+
126
+- [ ] **Step 7: Run policy + audit tests and confirm GREEN**
127
+
128
+Run: `node --test test/action-policy.test.js test/audit.test.js`
129
+Expected: PASS.
130
+
131
+- [ ] **Step 8: Commit**
132
+
133
+Commit message: `feat: add action policy and redacted audit`
134
+
135
+### Task 3: Policy-Enforcing Plugin Router
136
+
137
+**Files:**
138
+- Create: `src/core/router.js`
139
+- Create: `test/plugin-router.test.js`
140
+
141
+**Interfaces:**
142
+- Consumes: `PluginRegistry`, `ActionPolicy`, `AuditLogger`
143
+- Produces: `PluginRouter.dispatchCommand(command, context)` and `PluginRouter.dispatchCallback(data, context)`
144
+- Plugin handler result shape: `null` for no ownership, otherwise `{ actionId, view }` or `{ actionId, result }`
145
+
146
+- [ ] **Step 1: Write failing router tests**
147
+
148
+Assert exactly one matching plugin handles a route; `null` continues; unknown route returns `null`; declared `READ` runs; undeclared/denied action never reaches execution; WRITE/DESTRUCTIVE produce an approval-required normalized result without executing provider code; audit attempt/result events are emitted.
149
+
150
+- [ ] **Step 2: Run router test and confirm RED**
151
+
152
+Run: `node --test test/plugin-router.test.js`
153
+Expected: FAIL because router module is missing.
154
+
155
+- [ ] **Step 3: Implement `PluginRouter` minimally**
156
+
157
+Resolve handlers in registry order, require the returned `actionId` to be declared by that plugin, evaluate policy, audit the decision, and only return/execute an already-produced read view when policy allows. For approval-required actions, return a normalized non-executed result.
158
+
159
+- [ ] **Step 4: Run router test and confirm GREEN**
160
+
161
+Run: `node --test test/plugin-router.test.js`
162
+Expected: PASS.
163
+
164
+- [ ] **Step 5: Commit**
165
+
166
+Commit message: `feat: add policy enforcing plugin router`
167
+
168
+### Task 4: GitHub Plugin Adapter
169
+
170
+**Files:**
171
+- Create: `src/plugins/github/manifest.js`
172
+- Create: `src/plugins/github/plugin.js`
173
+- Create: `test/github-plugin.test.js`
174
+
175
+**Interfaces:**
176
+- Consumes: existing `GitHubService` and `MenuManager`
177
+- Produces: `createGitHubPlugin({ github, menu })`
178
+- Manifest id: `github`
179
+- Commands: `/repos`
180
+- Callback ownership prefixes: `menu:repos`, `repo:`, `files:`, `tree:`, `blob:`, `pr:`, `commits:`, `status:`
181
+- All Foundation v1 GitHub actions are `READ`
182
+
183
+- [ ] **Step 1: Write failing GitHub plugin tests**
184
+
185
+Assert `/repos` and each GitHub callback family map to a declared READ action and preserve the exact existing view objects returned by `MenuManager`; unrelated commands/callbacks return `null`.
186
+
187
+- [ ] **Step 2: Run GitHub plugin test and confirm RED**
188
+
189
+Run: `node --test test/github-plugin.test.js`
190
+Expected: FAIL because plugin modules are missing.
191
+
192
+- [ ] **Step 3: Implement GitHub manifest and adapter minimally**
193
+
194
+Delegate rendering to current menu methods. Do not move GitHub API logic or rewrite menu copy.
195
+
196
+- [ ] **Step 4: Run GitHub plugin test and confirm GREEN**
197
+
198
+Run: `node --test test/github-plugin.test.js`
199
+Expected: PASS.
200
+
201
+- [ ] **Step 5: Commit**
202
+
203
+Commit message: `feat: add github plugin adapter`
204
+
205
+### Task 5: Integrate Kernel into NexaDevBot Without UX Regression
206
+
207
+**Files:**
208
+- Modify: `src/bot.js`
209
+- Modify: `test/bot.test.js`
210
+- Modify: `test/navigation.test.js`
211
+- Modify: `test/security.test.js` only if a new explicit policy assertion belongs there
212
+
213
+**Interfaces:**
214
+- Consumes: `PluginRegistry`, `ActionPolicy`, `AuditLogger`, `PluginRouter`, `createGitHubPlugin`
215
+- Preserves: public behavior of `NexaDevBot.handleUpdate`, `handleMessage`, `handleCallbackQuery`
216
+
217
+- [ ] **Step 1: Add failing migration regression tests**
218
+
219
+Assert `/repos` and GitHub callback paths are dispatched through the plugin router, existing `/start`, `/status`, tools/settings/security compatibility paths remain unchanged, callback edits remain in-place, and callback acknowledgement failure still cannot block render/edit.
220
+
221
+- [ ] **Step 2: Run focused migration tests and confirm RED**
222
+
223
+Run: `node --test test/bot.test.js test/navigation.test.js`
224
+Expected: at least the new plugin-routing assertions FAIL before integration.
225
+
226
+- [ ] **Step 3: Integrate kernel into `NexaDevBot`**
227
+
228
+Construct the GitHub plugin from the existing `github` and `menu` instances. Route `/repos` and GitHub callbacks through `PluginRouter`; keep `/start`, `/status`, and non-GitHub menu callbacks on existing compatibility paths for Foundation v1.
229
+
230
+- [ ] **Step 4: Run focused migration tests and confirm GREEN**
231
+
232
+Run: `node --test test/bot.test.js test/navigation.test.js`
233
+Expected: PASS.
234
+
235
+- [ ] **Step 5: Run complete suite**
236
+
237
+Run: `npm test`
238
+Expected: all existing and new tests PASS with zero failures/skips.
239
+
240
+- [ ] **Step 6: Commit**
241
+
242
+Commit message: `refactor: route github through plugin kernel`
243
+
244
+### Task 6: Documentation, PR, CI, Deploy, Runtime Verification
245
+
246
+**Files:**
247
+- Modify: `PROJECT_MEMORY.md`
248
+
249
+**Interfaces:**
250
+- Consumes: completed implementation and CI/deploy evidence
251
+- Produces: durable checkpoint with SHAs/run IDs and explicit NOT VERIFIED items
252
+
253
+- [ ] **Step 1: Update `PROJECT_MEMORY.md`**
254
+
255
+Record Foundation v1 architecture, files, test counts, PR/commit evidence, and deployment state. Do not mark owner-device smoke verified until observed.
256
+
257
+- [ ] **Step 2: Run full suite one final time on branch**
258
+
259
+Run: `npm test`
260
+Expected: PASS.
261
+
262
+- [ ] **Step 3: Open PR to `main` and verify CI**
263
+
264
+Expected: PR CI success; inspect logs for actual discovered test count and zero failures.
265
+
266
+- [ ] **Step 4: Review PR diff for secrets and scope drift**
267
+
268
+Expected: only Foundation v1 files; no tokens/secrets; no unrelated provider integrations.
269
+
270
+- [ ] **Step 5: Merge only after CI is green**
271
+
272
+Expected: squash/merge commit on `main`.
273
+
274
+- [ ] **Step 6: Verify post-merge `main` CI and deploy workflow**
275
+
276
+Expected: both success; Cloudflare latest deployment serves the exact merged revision at 100% traffic.
277
+
278
+- [ ] **Step 7: Verify production runtime telemetry**
279
+
280
+Expected: Telegram webhook events on current Worker version return HTTP 200 with outcome `ok`, with no new plugin-kernel-related runtime errors.
281
+
282
+- [ ] **Step 8: Record owner-device smoke as VERIFIED or NOT VERIFIED**
283
+
284
+Minimum smoke: `/start -> Repositories -> project -> Files -> folder/file -> project -> PR/Commits/Status -> Back -> Main`, preserving one-message callback navigation.