feat(modules): port util + misc; expose Registry to handlers

Phase 5a of go-port-cloud-run plan: port first 2 of 4 modules (wordle/loldle
deferred to later phase). Port util.go, info.go, help.go, stickerid.go and
misc.go with tests. /help renders registry view; /info exposes chat/thread/
sender ids; /stickerid (private) returns bot-scoped file_ids; /ping writes
last_ping KV ms-epoch JSON for byte-parity, /mstats reads it, /fortytwo is
easter egg.

Registry-pointer-in-Deps required for /help to access module registry—pointer
captured at factory time, stable post-Build. Static factory catalog moved from
modules pkg to cmd/server to break import cycle. Code-review fixes applied in
same session: /info nil-deref guard, KV wire-format parity.
This commit is contained in:
tiennm99 committed 2026-05-09 08:24:52 +07:00
1 parent c7a631bffd
commit 45a57e1573
11 files changed
+597 -14

No files matched your search

+10 -4
View File
@@ -59,14 +59,20 @@ type Module struct {
}
// Deps is the dependency bundle a Factory receives. Each field is added in the
// phase that introduces it; today only KV + Env exist (Firestore: Phase 04,
// Gemini: Phase 07).
// phase that introduces it; today KV, Env, and Registry exist (Gemini: Phase 07).
//
// Deps.Env is the process environment with sensitive keys stripped. Modules
// must not assume Env contains every variable — see cmd/server.envForModules.
//
// Deps.Registry is a pointer to the Registry being built. At factory call
// time the Registry is partially populated (only modules earlier in the
// MODULES env order); by the time any handler runs, it is fully populated.
// Modules that need to introspect commands (e.g. /help) capture this pointer
// in their handler closures.
type Deps struct {
KV storage.KVStore // already prefixed with the module name when passed to a Factory
Env map[string]string // process env minus known-sensitive keys
KV storage.KVStore // already prefixed with the module name when passed to a Factory
Env map[string]string // process env minus known-sensitive keys
Registry *Registry // populated by Build; safe to capture but read-only at module use
}
// Factory constructs a Module from its Deps. Spec deviation: Phase 03 plan