Personal Telegram developer console for GitHub
docs: align plugin foundation plan with implementation
davoodmehraban89 committed
Oct 3, 2026 at 01:42 UTC
61b6b98f31ef3d63fab439bbbde096f81dcd7e80
1 file changed
+76
-240
docs/superpowers/plans/2026-10-03-nexa-plugin-foundation.md
+76
-240
@@ -1,12 +1,10 @@
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.
3
+> **Execution method:** superpowers `executing-plans` + TDD, on branch `feat/plugin-foundation-v1` and PR #14.
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.
7
+**Architecture:** Focused core modules provide registry, policy, audit, and routing. The existing `GitHubService` and `MenuManager` remain the provider/data/view implementation; the GitHub plugin is an adapter around those existing capabilities.
8
9
**Spec:** `docs/superpowers/specs/2026-10-03-nexa-plugin-foundation-design.md`
10
@@ -15,22 +13,25 @@
13
- Bot remains owner-only.
14
- No secret, token, authorization header, or private key may appear in audit output, repository files, or Telegram output.
15
- Existing callback navigation continues to edit the same Telegram message.
18
-- Callback payloads remain within Telegram's 64-byte limit.
16
- 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.
17
+- Every declared plugin action must pass central policy evaluation before provider/view execution.
18
+- `WRITE` and `DESTRUCTIVE` actions are never auto-executed in Foundation v1.
19
- Worker remains stateless.
23
-- No AI, Browser QA, Supabase, Sentry, Linear, Notion, Mini App, or full Cloudflare operator implementation in this phase.
20
+- AI, Browser QA, Supabase, Sentry, Linear, Notion, Mini App, and full Cloudflare operator integrations are out of scope.
21
+
22
+## Implemented Structure
23
+
24
+New core:
25
+- `src/core/plugin-registry.js`
26
+- `src/core/action-policy.js`
27
+- `src/core/audit.js`
28
+- `src/core/router.js`
29
25
-## File Structure
30
+GitHub plugin:
31
+- `src/plugins/github/manifest.js`
32
+- `src/plugins/github/plugin.js`
33
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
+New tests:
35
- `test/plugin-registry.test.js`
36
- `test/action-policy.test.js`
37
- `test/audit.test.js`
@@ -38,247 +39,82 @@ New:
39
- `test/github-plugin.test.js`
40
41
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**
42
+- `src/bot.js`
43
+- `test/bot.test.js`
44
+- `PROJECT_MEMORY.md`
45
242
-Commit message: `refactor: route github through plugin kernel`
46
+## Security-Critical Router Contract
47
244
-### Task 6: Documentation, PR, CI, Deploy, Runtime Verification
48
+The implemented contract is deliberately stricter than the initial draft:
49
246
-**Files:**
247
-- Modify: `PROJECT_MEMORY.md`
50
+```text
51
+resolve route -> identify declared action -> evaluate policy -> audit decision -> execute provider/view code
52
+```
53
249
-**Interfaces:**
250
-- Consumes: completed implementation and CI/deploy evidence
251
-- Produces: durable checkpoint with SHAs/run IDs and explicit NOT VERIFIED items
54
+A plugin resolver returns either `null` or:
55
253
-- [ ] **Step 1: Update `PROJECT_MEMORY.md`**
56
+```js
57
+{
58
+ actionId: 'github.repos.list',
59
+ execute: async () => view
60
+}
61
+```
62
255
-Record Foundation v1 architecture, files, test counts, PR/commit evidence, and deployment state. Do not mark owner-device smoke verified until observed.
63
+`resolveCommand()` and `resolveCallback()` must be side-effect-free. Network/provider/menu work belongs inside the deferred `execute()` function. This guarantees `WRITE`, `DESTRUCTIVE`, undeclared, and denied actions cannot run before policy evaluation.
64
257
-- [ ] **Step 2: Run full suite one final time on branch**
65
+## Task 1 — Plugin Registry
66
259
-Run: `npm test`
260
-Expected: PASS.
67
+- [x] RED test added: valid registration, duplicate plugin ID, duplicate action ID, invalid risk, lookup behavior.
68
+- [x] RED CI confirmed: commit `2460b0854f6dbd99a80cfb9561850fdd23f1ac0e`, run `37069219176` failed for the missing module.
69
+- [x] `PluginRegistry` implemented: commit `3f644caef41a9136cb5f0a78b0c66798238a257d`.
70
+- [x] GREEN CI: `37069339637`.
71
262
-- [ ] **Step 3: Open PR to `main` and verify CI**
72
+## Task 2 — Action Policy + Redacted Audit
73
264
-Expected: PR CI success; inspect logs for actual discovered test count and zero failures.
74
+- [x] Policy RED commit `77efe66f008fcb417b0b66f22b186885d3fecdd3`; run `37069430240` failed as expected.
75
+- [x] `ActionPolicy` implementation commit `cbdba6b1b70342d6325d229cec1725c05862a537`; GREEN run `37069629741`.
76
+- [x] Audit RED commit `a6f9735185f7a0ce45fe744b9a13b1fa3d885681`; run `37069736330` failed as expected.
77
+- [x] `AuditLogger` implementation commit `92dfcba318f5199e6c9e54da5fbba91a15122ca3`; GREEN run `37069824796`.
78
+- [x] Recursive redaction covers nested strings, arrays, and objects; sink failures cannot break user actions.
79
266
-- [ ] **Step 4: Review PR diff for secrets and scope drift**
80
+## Task 3 — Policy-Enforcing Plugin Router
81
268
-Expected: only Foundation v1 files; no tokens/secrets; no unrelated provider integrations.
82
+- [x] RED commit `4e3fca87139310c24c3c83a5181fc638f887882d`; run `37069955642` failed as expected.
83
+- [x] Router implementation commit `00fcd1041e2f8074dc34727635395896eace0cba`.
84
+- [x] GREEN CI `37070015843`.
85
+- [x] Tests prove undeclared actions never execute.
86
+- [x] Tests prove `WRITE` and `DESTRUCTIVE` actions return approval-required results and never invoke `execute()`.
87
+- [x] Audit attempt/result events are emitted around allowed READ execution.
88
270
-- [ ] **Step 5: Merge only after CI is green**
89
+## Task 4 — GitHub Plugin Adapter
90
272
-Expected: squash/merge commit on `main`.
91
+- [x] RED commit `ae6829729779c2f656e99958a379c805eb1bebc4`; run `37070181121` failed as expected.
92
+- [x] Manifest + adapter implementation completed; final adapter commit `c9aed93bc1a3bd8ac047a3639722633bcd9c624e`.
93
+- [x] GREEN CI `37070481981`.
94
+- [x] `/repos`, `menu:repos`, `repo:`, `files:`, `tree:`, `blob:`, `pr:`, `commits:`, `status:` map to declared GitHub READ actions.
95
+- [x] Non-GitHub commands/callbacks are not consumed by the plugin.
96
274
-- [ ] **Step 6: Verify post-merge `main` CI and deploy workflow**
97
+## Task 5 — NexaDevBot Integration Without UX Regression
98
276
-Expected: both success; Cloudflare latest deployment serves the exact merged revision at 100% traffic.
99
+- [x] Migration RED tests added in commit `f1ee926320dc918d0d0c8b21d60710077a9d119b`; run `37070633843` failed as expected before integration.
100
+- [x] `src/bot.js` integration commit `d628a4ed0b07dfa4c748b6161515565b1eef3073`.
101
+- [x] `/repos` and GitHub callbacks route through the plugin kernel.
102
+- [x] `/start`, `/status`, and non-GitHub menu routes keep compatibility behavior.
103
+- [x] Callback acknowledgement remains best-effort and cannot block rendering.
104
+- [x] Same-message callback editing remains covered.
105
+- [x] PR CI run `37070778956` passed the merge result with **12 test files, 52 tests, 52 pass, 0 fail, 0 skip**.
106
278
-- [ ] **Step 7: Verify production runtime telemetry**
107
+## Task 6 — Final Review, Merge, Deploy, Runtime Verification
108
280
-Expected: Telegram webhook events on current Worker version return HTTP 200 with outcome `ok`, with no new plugin-kernel-related runtime errors.
109
+- [x] Full PR diff reviewed for Foundation v1 scope; no provider expansion or secret value added.
110
+- [x] Fresh PR CI evidence inspected, including test discovery and full `npm test` output.
111
+- [ ] Final documentation commit PR CI green.
112
+- [ ] PR #14 marked ready and merged to `main`.
113
+- [ ] Post-merge `main` CI green.
114
+- [ ] Cloudflare deploy workflow green and latest Worker deployment verified at 100% traffic.
115
+- [ ] Production Telegram webhook telemetry on the new Worker version returns HTTP 200 / outcome `ok` with no new plugin-kernel error.
116
+- [ ] Owner-device post-Foundation smoke recorded as VERIFIED or NOT VERIFIED.
117
282
-- [ ] **Step 8: Record owner-device smoke as VERIFIED or NOT VERIFIED**
118
+## Definition of Done
119
284
-Minimum smoke: `/start -> Repositories -> project -> Files -> folder/file -> project -> PR/Commits/Status -> Back -> Main`, preserving one-message callback navigation.
120
+Foundation v1 is complete only when all Task 6 runtime/deploy gates above are satisfied. Until then, implementation may be code-complete but is not marked production-complete.