Personal Telegram developer console for GitHub

docs: record plugin foundation v1 implementation checkpoint

davoodmehraban89 committed Oct 3, 2026 at 01:43 UTC c44b557e64d2c3bb9a181f663833385abfb50ad3
1 file changed +105 -46
PROJECT_MEMORY.md
+105 -46
@@ -17,14 +17,19 @@
17
18 ## Architecture
19 - `src/index.js` — Cloudflare Worker HTTP boundary; webhook secret, owner authorization, required Telegram transport checks and redacted runtime diagnostics.
20 -- `src/bot.js` — Telegram update/callback router; callback acknowledgement is best-effort and cannot block menu rendering.
20 +- `src/bot.js` — Telegram update/callback coordinator; constructs the plugin kernel, keeps callback acknowledgement best-effort, routes GitHub operations through policy, and retains compatibility paths for non-GitHub menus.
21 +- `src/core/plugin-registry.js` — validates plugin/action manifests and rejects duplicate IDs or invalid risk values.
22 +- `src/core/action-policy.js` — central `READ` / `WRITE` / `DESTRUCTIVE` policy evaluation.
23 +- `src/core/audit.js` — best-effort structured action audit with recursive secret redaction.
24 +- `src/core/router.js` — policy-enforcing plugin router using the security-critical `resolve -> policy -> execute` flow.
25 +- `src/plugins/github/manifest.js` — GitHub plugin capability/action declarations.
26 +- `src/plugins/github/plugin.js` — GitHub plugin adapter around existing `GitHubService` and `MenuManager` behavior.
27 - `src/telegram.js` — Telegram Bot API client; explicit error propagation, fail-closed token handling and Cloudflare-safe default `fetch` invocation.
28 - `src/github.js` — authenticated GitHub REST reader; explicit errors, numeric repository-id resolution, tree/blob access.
29 - `src/menu.js` — hierarchical stateless inline menus, one-message editing, repository/file browser.
30 - `src/config.js` — non-secret static config.
31 - `.github/workflows/ci.yml` — Node 22 tests, official GitHub Actions v7 releases and non-zero test-discovery guard.
32 - `.github/workflows/deploy.yml` — production Cloudflare Worker deploy after successful CI on `main`; deploys the exact verified commit.
27 -- `test/` — security, Worker, navigation, menu, GitHub and Telegram regression coverage.
33 - `wrangler.jsonc` — Worker configuration; `keep_vars: true`, workers.dev enabled and observability enabled.
34
35 ## Runtime Configuration
@@ -49,6 +54,10 @@ GitHub Actions deployment secrets:
54 - Runtime diagnostic logs redact Telegram, webhook and GitHub secrets.
55 - Temporary setup/diagnostic exposure is disabled in source/tests.
56 - Operational UI does not invent SLA, latency or external health claims.
57 +- Plugin manifests must declare action risk as `READ`, `WRITE`, or `DESTRUCTIVE`.
58 +- Undeclared/unknown plugin actions are denied.
59 +- `WRITE` and `DESTRUCTIVE` plugin actions are not executed before an approval flow exists.
60 +- Plugin route resolvers must be side-effect-free; provider/view work is deferred to `execute()` after policy evaluation.
61
62 ## Telegram UX / GitHub Reader
63 - `/start` creates the initial menu message.
@@ -74,73 +83,115 @@ Audit scope covered the full recursive repository tree, including workflows, Wor
83
84 ### Root cause
85 - Telegram requests were reaching the production Worker, so webhook registration, secret header and owner gate were not the blocker.
77 -- Production observability showed `POST /telegram/webhook` returning HTTP 400 with:
78 - `Telegram API sendMessage network failure: Illegal invocation: function called with incorrect this reference`.
79 -- Root defect was in `src/telegram.js`: the platform-global `fetch` had been stored directly as an instance property and later called as `this.fetchFn(...)`, which supplied `TelegramClient` as the receiver. Cloudflare Workers rejects that receiver binding.
86 +- Production observability showed `POST /telegram/webhook` returning HTTP 400 with `Telegram API sendMessage network failure: Illegal invocation: function called with incorrect this reference`.
87 +- Root defect was in `src/telegram.js`: the platform-global `fetch` had been stored directly as an instance property and later called with the wrong receiver.
88 - Node unit tests had previously missed this platform-specific semantic difference.
89
90 ### PR #11 — redacted runtime diagnostics
83 -- Added regression-first diagnostics without exposing secrets.
84 -- RED commit: `079f9b7977e1120d1bcdbbcd75d91e6a322e5a49`.
85 -- Implementation commit: `2851c7045141aaeff501564d4a6bf8f22e333754`.
86 -- PR CI run `37064293599` = 30/30 pass.
87 -- Squash-merged to `main` at `cfd7a0b4803b13c76646b71666e7e0c66e023c99`.
91 +- RED commit `079f9b7977e1120d1bcdbbcd75d91e6a322e5a49`.
92 +- Implementation commit `2851c7045141aaeff501564d4a6bf8f22e333754`.
93 +- PR CI `37064293599` = 30/30 pass.
94 +- Squash merge `cfd7a0b4803b13c76646b71666e7e0c66e023c99`.
95 - Post-merge CI `37064405261` and deploy `37064436885` succeeded.
96
97 ### PR #12 — Cloudflare fetch receiver fix
91 -- Added a regression test that reproduces Cloudflare-style illegal receiver invocation.
92 -- RED commit: `99cf3468f820eb06390b7001c1d1eb5e5fb4ebbd`.
93 -- Fix commit: `c487727c968e4f00aecf0985a38b152f58e3b9b4`.
94 -- Fix: default transport now uses `(...args) => fetch(...args)` instead of storing bare platform `fetch`.
98 +- RED commit `99cf3468f820eb06390b7001c1d1eb5e5fb4ebbd`.
99 +- Fix commit `c487727c968e4f00aecf0985a38b152f58e3b9b4`.
100 +- Default transport now uses `(...args) => fetch(...args)` instead of storing bare platform `fetch`.
101 - PR CI `37064953868` = 31/31 pass.
96 -- Squash-merged to `main` at `bd01d8ede44331f50e1115d569095fb12246331d`.
102 +- Squash merge `bd01d8ede44331f50e1115d569095fb12246331d`.
103 - Post-merge CI `37065054623` and deploy `37065141745` succeeded.
98 -- Cloudflare telemetry after this deploy showed current-version Telegram webhook requests returning HTTP 200; the `Illegal invocation` errors existed only on the older Worker version.
104 +- Cloudflare telemetry showed current-version Telegram webhook requests returning HTTP 200; `Illegal invocation` existed only on the older Worker version.
105
106 ### PR #13 — callback resilience + documentation alignment
101 -- Added regression coverage requiring menu editing to continue even if `answerCallbackQuery` is stale/fails.
102 -- RED commit: `13daeb442d6a2e1189a5cec2148aab9c2ea7c338`.
103 -- Callback fix commit: `28e2e6b619c646796600048a34616138fbbc207c`.
104 -- README alignment commit: `67b04e04214e334a88aea0ecdc4598bc5fbd027c`.
107 +- RED commit `13daeb442d6a2e1189a5cec2148aab9c2ea7c338`.
108 +- Callback fix commit `28e2e6b619c646796600048a34616138fbbc207c`.
109 +- README alignment commit `67b04e04214e334a88aea0ecdc4598bc5fbd027c`.
110 - PR CI `37065725004` = 32/32 pass.
106 -- Squash-merged to `main` at `6c90cbb8384c9591ba89367b48e4ce7e785ce72f`.
107 -- Post-merge CI `37065832210` succeeded.
108 -- Post-merge deploy `37065860268` succeeded.
109 -- Cloudflare latest deployment after PR #13: `13a5abdc-92a0-415f-b30b-ab422ae8b8ce`, version `812c52f7-f0b3-48bf-917c-151f4618dabd`, 100% traffic.
110 -- Live Telegram webhook on this exact Worker version returned HTTP 200 with Worker outcome `ok`.
111 -- Observability query found no new `telegram_webhook_error` on fixed/current versions; retained error events were from the old pre-fix version only.
111 +- Squash merge `6c90cbb8384c9591ba89367b48e4ce7e785ce72f`.
112 +- Post-merge CI `37065832210` and deploy `37065860268` succeeded.
113 +- Cloudflare deployment `13a5abdc-92a0-415f-b30b-ab422ae8b8ce`, version `812c52f7-f0b3-48bf-917c-151f4618dabd`, served 100% traffic.
114 +- Live Telegram webhook on that Worker version returned HTTP 200 / outcome `ok`.
115 +
116 +## Plugin Foundation v1 — Implementation Checkpoint 2026-10-03
117 +
118 +### Approved design and plan
119 +- Design: `docs/superpowers/specs/2026-10-03-nexa-plugin-foundation-design.md`.
120 +- Design commit on `main`: `adabadefd74de656b20d112c325be4defcbf2103`.
121 +- Plan: `docs/superpowers/plans/2026-10-03-nexa-plugin-foundation.md`.
122 +- Initial plan commit on `main`: `5f9a1991dbc3a1e79f5c04dfbe591c4d35e74a97`.
123 +- Feature branch: `feat/plugin-foundation-v1`.
124 +- PR: `#14`.
125 +
126 +### Architecture implemented on PR #14
127 +- Plugin Registry with manifest/action validation.
128 +- Central Action Policy with owner READ allow and WRITE/DESTRUCTIVE approval-required decisions.
129 +- Recursive-redaction Audit Logger.
130 +- Plugin Router enforcing `resolve -> policy -> execute`.
131 +- GitHub manifest and plugin adapter.
132 +- `/repos` and GitHub callbacks migrated through the plugin kernel.
133 +- `/start`, `/status`, tools/settings/security and other non-GitHub menu flows remain compatibility routes in Foundation v1.
134 +
135 +### Security-critical design correction during implementation
136 +The initial plan described a handler returning an already-produced view/result. TDD review identified that this could allow provider/view work before policy. The implemented contract is safer: route resolution returns `{ actionId, execute }`; resolution must be side-effect-free, policy is evaluated next, and only then may `execute()` run. Tests prove denied, undeclared, WRITE and DESTRUCTIVE actions do not call `execute()`.
137 +
138 +### TDD evidence
139 +- Registry RED `2460b0854f6dbd99a80cfb9561850fdd23f1ac0e` / CI `37069219176`; GREEN `3f644caef41a9136cb5f0a78b0c66798238a257d` / CI `37069339637`.
140 +- Policy RED `77efe66f008fcb417b0b66f22b186885d3fecdd3` / CI `37069430240`; GREEN `cbdba6b1b70342d6325d229cec1725c05862a537` / CI `37069629741`.
141 +- Audit RED `a6f9735185f7a0ce45fe744b9a13b1fa3d885681` / CI `37069736330`; GREEN `92dfcba318f5199e6c9e54da5fbba91a15122ca3` / CI `37069824796`.
142 +- Router RED `4e3fca87139310c24c3c83a5181fc638f887882d` / CI `37069955642`; GREEN `00fcd1041e2f8074dc34727635395896eace0cba` / CI `37070015843`.
143 +- GitHub adapter RED `ae6829729779c2f656e99958a379c805eb1bebc4` / CI `37070181121`; GREEN adapter head `c9aed93bc1a3bd8ac047a3639722633bcd9c624e` / CI `37070481981`.
144 +- Bot migration RED `f1ee926320dc918d0d0c8b21d60710077a9d119b` / CI `37070633843`; GREEN integration `d628a4ed0b07dfa4c748b6161515565b1eef3073` / CI `37070778956`.
145 +- CI `37070778956` inspected in full: 12 test files discovered; 52 tests, 52 pass, 0 fail, 0 skipped/cancelled/todo.
146 +
147 +### Current verification state
148 +VERIFIED on PR merge result:
149 +- Plugin registry validation.
150 +- READ/WRITE/DESTRUCTIVE policy semantics.
151 +- Recursive audit redaction and non-breaking sink failure.
152 +- Undeclared and approval-required actions do not execute provider code.
153 +- GitHub callback/command ownership mapping.
154 +- Existing `/start`, same-message navigation, stale callback handling, security gates, GitHub fail-closed behavior and Cloudflare fetch-receiver regression remain green.
155 +
156 +NOT YET VERIFIED for Foundation v1:
157 +- Final documentation-head PR CI after this checkpoint commit.
158 +- Merge of PR #14 to `main`.
159 +- Post-merge `main` CI.
160 +- Cloudflare deployment of the merged Foundation revision.
161 +- Production Telegram webhook telemetry on that new Worker version.
162 +- Owner-device visual/interactive smoke after Foundation deploy.
163
164 ## Current Work / Last Checkpoint
165 WHERE WE ARE:
115 -- Full repository audit completed.
116 -- The production `/start` failure root cause was identified, reproduced with a regression test, fixed, merged and deployed.
117 -- Main CI and Cloudflare deploy are green.
118 -- Latest production Worker receives Telegram webhook traffic successfully with HTTP 200.
119 -- Callback navigation was additionally hardened against stale callback acknowledgements.
120 -- README now matches the deployed stateless Worker architecture.
166 +- Foundation v1 implementation is on PR #14 and has passed the full automated suite on the pre-documentation head.
167 +- Final documentation alignment is being committed before merge.
168 +- Production is still the previously verified pre-Foundation version until PR #14 is merged and deploy succeeds.
169
170 WHAT REMAINS:
123 -1. Owner-device visual smoke: confirm the new main menu is visible after `/start`.
124 -2. Exercise `Repositories → repository → Files → folder → file preview → root → project → Commits/PR/Status → Back → Main` and confirm the same Telegram message is edited throughout.
125 -3. Optional non-owner smoke to confirm no private bot response.
171 +1. Verify final PR #14 CI after documentation changes.
172 +2. Mark PR ready and merge after green CI/scope review.
173 +3. Verify post-merge main CI and Cloudflare deploy.
174 +4. Verify current-version Telegram webhook telemetry.
175 +5. Record owner-device smoke for the Foundation build.
176
177 ## Acceptance Rules
128 -A checkpoint is complete only after:
129 -`IMPLEMENTED → VERIFIED → FIXED IF NEEDED → RE-VERIFIED`
178 +A checkpoint is complete only after `IMPLEMENTED -> VERIFIED -> FIXED IF NEEDED -> RE-VERIFIED`.
179 Minimum automated/runtime gates:
180 - Non-zero discovered test files.
181 - Security tests green.
182 - Navigation/bot/menu/index tests green.
134 -- GitHub fail-closed/data-trust tests green.
183 +- Plugin registry/policy/audit/router tests green.
184 +- GitHub plugin/fail-closed/data-trust tests green.
185 - Telegram missing-token/API-error and Cloudflare fetch-receiver regression tests green.
186 - Production deploy workflow green.
187 - Cloudflare telemetry must show successful production webhook behavior before runtime is called verified.
188
189 ## Known Gaps / Low-Priority Technical Debt
140 -- Owner-device visual/interactive smoke remains the final UI acceptance gate.
190 +- Post-Foundation owner-device visual/interactive smoke remains a final UI acceptance gate.
191 - `package.json` still has `"start": "node src/index.js"`, which is not a useful local Cloudflare Worker development command; it does not affect production deployment.
142 -- Extremely long path-based refresh callback data could theoretically approach Telegram's 64-byte callback-data limit; normal deep navigation uses SHA-based callbacks and is not affected by the incident fixed here.
192 +- Extremely long path-based refresh callback data could theoretically approach Telegram's 64-byte callback-data limit; normal deep navigation uses SHA-based callbacks.
193 - Persistent navigation/session storage is intentionally not required for the current stateless callback flow.
194 +- Foundation v1 establishes approval-required policy results but intentionally does not implement the Telegram confirmation UX; that belongs to the first write-capable plugin phase.
195
196 ## Project Boundaries
197 - Nexa Dev Bot is independent from Finora / Factor-easy and has no Supabase requirement in this project.
@@ -150,22 +201,30 @@ Minimum automated/runtime gates:
201 ## Important Paths
202 - `PROJECT_MEMORY.md`
203 - `README.md`
204 +- `docs/superpowers/specs/2026-10-03-nexa-plugin-foundation-design.md`
205 +- `docs/superpowers/plans/2026-10-03-nexa-plugin-foundation.md`
206 - `src/index.js`
207 - `src/bot.js`
208 +- `src/core/plugin-registry.js`
209 +- `src/core/action-policy.js`
210 +- `src/core/audit.js`
211 +- `src/core/router.js`
212 +- `src/plugins/github/manifest.js`
213 +- `src/plugins/github/plugin.js`
214 - `src/menu.js`
215 - `src/telegram.js`
216 - `src/github.js`
158 -- `src/config.js`
217 +- `test/plugin-registry.test.js`
218 +- `test/action-policy.test.js`
219 +- `test/audit.test.js`
220 +- `test/plugin-router.test.js`
221 +- `test/github-plugin.test.js`
222 - `test/security.test.js`
223 - `test/navigation.test.js`
224 - `test/bot.test.js`
162 -- `test/menu.test.js`
163 -- `test/index.test.js`
164 -- `test/github.test.js`
165 -- `test/telegram.test.js`
225 - `.github/workflows/ci.yml`
226 - `.github/workflows/deploy.yml`
227 - `wrangler.jsonc`
228
229 ## Next Executable Action
171 -Run `/start` on the owner Telegram account. If the main menu renders, complete the one-message navigation smoke and record the result here.
\ No newline at end of file
230 +Verify final PR #14 CI after documentation commits; if green, perform final scope/secret review, mark ready, merge, verify main CI/deploy, then verify production telemetry and owner-device smoke.