Skip to content

refactor: logging helper + tool boilerplate extractor#55

Merged
MarvelNwachukwu merged 2 commits into
mainfrom
chore/logging-and-tool-helpers
May 15, 2026
Merged

refactor: logging helper + tool boilerplate extractor#55
MarvelNwachukwu merged 2 commits into
mainfrom
chore/logging-and-tool-helpers

Conversation

@MarvelNwachukwu

Copy link
Copy Markdown
Contributor

Stacked on top of #54 — review/merge that first.

Summary

Two small refactors that cut ~75 lines and remove a bug class:

  1. src/util/log.ts — centralises stderr writes behind one log() helper, so we stop having to remember to append \n (the bug from chore: quick-win cleanup batch (6 atomic fixes) #54 commit be9f75a) or use the awkward template + "\n" concatenation pattern.
  2. src/util/with-approval-guard.ts — every trading tool repeated the same try { ... ApprovalRequiredError ... } boilerplate. Now one helper covers that, and each tool's execute body focuses on schema + service call.

script.ts keeps console.* (standalone CLI, not the MCP server). index.ts's fatal-error path keeps console.error because it carries the Error object for stack output.

Test plan

  • Newly enabled push.yml CI passes (lint + build)
  • All trading tools still serialise their result and approval-error responses identically

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Centralize stderr writes behind src/util/log.ts so we stop having
to remember to add \n, drop the awkward template + "\\n"
concatenation pattern, and remove the bug class where missing
newlines made log lines run together.

script.ts is left on console.* since it's a standalone CLI, not
the MCP server. index.ts's fatal-error console.error is kept
since it carries the Error object for stack output.
Every trading tool repeated the same try/catch:
  - serialise the result as pretty JSON
  - if ApprovalRequiredError, serialise that as JSON instead
  - otherwise rethrow

Centralizing it in one helper drops ~48 lines and makes each
tool's execute body focus on its zod schema + service call.
@MarvelNwachukwu
MarvelNwachukwu force-pushed the chore/logging-and-tool-helpers branch from 6a67a52 to 92e0287 Compare May 15, 2026 11:06
@MarvelNwachukwu
MarvelNwachukwu changed the base branch from chore/quick-win-bugs to main May 15, 2026 11:07
@MarvelNwachukwu
MarvelNwachukwu merged commit cbc16be into main May 15, 2026
1 check passed
MarvelNwachukwu added a commit that referenced this pull request May 15, 2026
chore: add changeset for cleanup patch (#54, #55)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant