Skip to content

Reduce duplicated config/tracking boilerplate in tracking.ts and index.ts #103

Description

@sebastianbarrozo

Summary

opencode-plugin/src/tracking.ts repeats the same boilerplate across all four tracker methods (sessionStart, toolExecuted, sessionEnd, heartbeat) plus the internal send function. This creates maintenance risk: changes to config resolution, user identity, default model, or cost calculation must be applied in multiple places.

Additionally, opencode-plugin/src/index.ts duplicates the exact same multi-line config-not-found error message at lines 33-34 and 121-122.

Evidence

tracking.ts — repeated patterns across methods:

Pattern Occurrences Lines
readConfig() + if (!config) return 91-92, 112-113, 145-146, 188-189, 225-226
readTeamConfig(ctx.directory || process.cwd()) 114, 147, 190, 227
config.user_email || userInfo().username 126, 169, 199, 236
lastModel || "claude-opus-4-6" (hardcoded default) 128, 161, 191, 228
Math.round(calculateCost(...) * 1e6) / 1e6 cost block 208-218, 247-257

index.ts — duplicated string:
The config-not-found message ("No Fyso credentials found. Run the sync-team skill first...") is identical at lines 33-34 and 121-122.

Acceptance criteria

  • Extract a DEFAULT_MODEL constant in tracking.ts to replace the 4 hardcoded "claude-opus-4-6" strings.
  • Extract the config-not-found message to a shared constant in config.ts, used by both tools in index.ts.
  • Extract a helper (e.g. resolveContext) that performs readConfig + readTeamConfig + user resolution, reducing the repeated 3-line preamble in each tracker method.
  • Extract the cost calculation rounding into a small helper used by both sessionEnd and heartbeat.
  • Existing tests (tracking.test.ts, config.test.ts, create-team.test.ts) continue to pass.
  • No behavioral changes — only structural deduplication.

Suggested validation

cd opencode-plugin && npm test
# Verify all existing tests pass unchanged
# Grep for "claude-opus-4-6" — should appear only in the DEFAULT_MODEL constant
# Grep for "No Fyso credentials" — should appear only in the shared constant

Pipeline

  • Esta issue fue solicitada por un agente de mantenimiento programado.
  • Entra sin labels para publicarse en triage; segun configuracion puede requerir aceptacion manual o autoaceptarse.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions