5.9 KiB
summary, read_when, title
| summary | read_when | title | ||
|---|---|---|---|---|
| Refactor clusters with highest LOC reduction potential |
|
Refactor Cluster Backlog |
Refactor Cluster Backlog
Ranked by likely LOC reduction, safety, and breadth.
1. Channel plugin config and security scaffolding
Highest-value cluster.
Repeated shapes across many channel plugins:
config.listAccountIdsconfig.resolveAccountconfig.defaultAccountIdconfig.setAccountEnabledconfig.deleteAccountconfig.describeAccountsecurity.resolveDmPolicy
Strong examples:
extensions/telegram/src/channel.tsextensions/googlechat/src/channel.tsextensions/slack/src/channel.tsextensions/discord/src/channel.tsextensions/matrix/src/channel.tsextensions/irc/src/channel.tsextensions/signal/src/channel.tsextensions/mattermost/src/channel.ts
Likely extraction shape:
buildChannelConfigAdapter(...)buildMultiAccountConfigAdapter(...)buildDmSecurityAdapter(...)
Expected savings:
- ~250-450 LOC
Risk:
- Medium. Each channel has slightly different
isConfigured, warnings, and normalization.
2. Extension runtime singleton boilerplate
Very safe.
Nearly every extension has the same runtime holder:
let runtime: PluginRuntime | null = nullsetXRuntimegetXRuntime
Strong examples:
extensions/telegram/src/runtime.tsextensions/matrix/src/runtime.tsextensions/slack/src/runtime.tsextensions/discord/src/runtime.tsextensions/whatsapp/src/runtime.tsextensions/imessage/src/runtime.tsextensions/twitch/src/runtime.ts
Special-case variants:
extensions/bluebubbles/src/runtime.tsextensions/line/src/runtime.tsextensions/synology-chat/src/runtime.ts
Likely extraction shape:
createPluginRuntimeStore<T>(errorMessage)
Expected savings:
- ~180-260 LOC
Risk:
- Low
3. Onboarding prompt and config-patch steps
Large surface area.
Many onboarding files repeat:
- resolve account id
- prompt allowlist entries
- merge allowFrom
- set DM policy
- prompt secrets
- patch top-level vs account-scoped config
Strong examples:
extensions/bluebubbles/src/onboarding.tsextensions/googlechat/src/onboarding.tsextensions/msteams/src/onboarding.tsextensions/zalo/src/onboarding.tsextensions/zalouser/src/onboarding.tsextensions/nextcloud-talk/src/onboarding.tsextensions/matrix/src/onboarding.tsextensions/irc/src/onboarding.ts
Existing helper seam:
src/channels/plugins/onboarding/helpers.ts
Likely extraction shape:
promptAllowFromList(...)buildDmPolicyAdapter(...)applyScopedAccountPatch(...)promptSecretFields(...)
Expected savings:
- ~300-600 LOC
Risk:
- Medium. Easy to over-generalize; keep helpers narrow and composable.
4. Multi-account config-schema fragments
Repeated schema fragments across extensions.
Common patterns:
const allowFromEntry = z.union([z.string(), z.number()])- account schema plus:
accounts: z.object({}).catchall(accountSchema).optional()defaultAccount: z.string().optional()
- repeated DM/group fields
- repeated markdown/tool policy fields
Strong examples:
extensions/bluebubbles/src/config-schema.tsextensions/zalo/src/config-schema.tsextensions/zalouser/src/config-schema.tsextensions/matrix/src/config-schema.tsextensions/nostr/src/config-schema.ts
Likely extraction shape:
AllowFromEntrySchemabuildMultiAccountChannelSchema(accountSchema)buildCommonDmGroupFields(...)
Expected savings:
- ~120-220 LOC
Risk:
- Low to medium. Some schemas are simple, some are special.
5. Webhook and monitor lifecycle startup
Good medium-value cluster.
Repeated startAccount / monitor setup patterns:
- resolve account
- compute webhook path
- log startup
- start monitor
- wait for abort
- cleanup
- status sink updates
Strong examples:
extensions/googlechat/src/channel.tsextensions/bluebubbles/src/channel.tsextensions/zalo/src/channel.tsextensions/telegram/src/channel.tsextensions/nextcloud-talk/src/channel.ts
Existing helper seam:
src/plugin-sdk/channel-lifecycle.ts
Likely extraction shape:
- helper for account monitor lifecycle
- helper for webhook-backed account startup
Expected savings:
- ~150-300 LOC
Risk:
- Medium to high. Transport details diverge quickly.
6. Small exact-clone cleanup
Low-risk cleanup bucket.
Examples:
- duplicated gateway argv detection:
src/infra/gateway-lock.tssrc/cli/daemon-cli/lifecycle.ts
- duplicated port diagnostics rendering:
src/cli/daemon-cli/restart-health.ts
- duplicated session-key construction:
src/web/auto-reply/monitor/broadcast.ts
Expected savings:
- ~30-60 LOC
Risk:
- Low
Test clusters
LINE webhook event fixtures
Strong examples:
src/line/bot-handlers.test.ts
Likely extraction:
makeLineEvent(...)runLineEvent(...)makeLineAccount(...)
Expected savings:
- ~120-180 LOC
Telegram native command auth matrix
Strong examples:
src/telegram/bot-native-commands.group-auth.test.tssrc/telegram/bot-native-commands.plugin-auth.test.ts
Likely extraction:
- forum context builder
- denied-message assertion helper
- table-driven auth cases
Expected savings:
- ~80-140 LOC
Zalo lifecycle setup
Strong examples:
extensions/zalo/src/monitor.lifecycle.test.ts
Likely extraction:
- shared monitor setup harness
Expected savings:
- ~50-90 LOC
Brave llm-context unsupported-option tests
Strong examples:
src/agents/tools/web-tools.enabled-defaults.test.ts
Likely extraction:
it.each(...)matrix
Expected savings:
- ~30-50 LOC
Suggested order
- Runtime singleton boilerplate
- Small exact-clone cleanup
- Config and security builder extraction
- Test-helper extraction
- Onboarding step extraction
- Monitor lifecycle helper extraction