Skip to content

Conversation

@premiumjibles
Copy link
Contributor

@premiumjibles premiumjibles commented Dec 9, 2025

Summary by CodeRabbit

  • New Features

    • Portfolio data now includes pre-calculated overall and per-network aggregate totals, improving performance and reducing client-side computation.
  • Updates

    • AI system strengthened with stricter math enforcement rules, requiring all arithmetic operations to use dedicated calculation tools for improved accuracy.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
shapeshift-agentic Ready Ready Preview Comment Dec 9, 2025 6:30am

@coderabbitai
Copy link

coderabbitai bot commented Dec 9, 2025

📝 Walkthrough

Walkthrough

The changes restructure portfolio data aggregation and refactor instruction rules. Portfolio output now includes precomputed totals (overall and per-network) calculated with BigNumber, replacing the prior flat array format. Concurrently, system instructions are reorganized to emphasize a CRITICAL Math & Calculations section that mandates using precomputed totals and the mathCalculator tool for all arithmetic operations.

Changes

Cohort / File(s) Summary
System Instruction Updates
apps/agentic-server/src/routes/chat.ts
Removed inline rules about precalculated amounts and manual arithmetic. Introduced a new CRITICAL Math & Calculations block that enforces reliance on precomputed totals (totals.overall, totals.byNetwork) and mandatory use of mathCalculator for all computed values.
Portfolio Data Aggregation
apps/agentic-server/src/tools/portfolio.ts
Refactored PortfolioOutput type from flat array to structured object with networks array and totals. Introduced PortfolioTotals type. Updated executeGetPortfolio to compute and return per-network and overall totals using BigNumber for precise calculations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Type signature changes to PortfolioOutput may cascade to all consumers of the portfolio tool; verify callers are updated to handle the new object structure with networks and totals fields
  • BigNumber aggregation logic in executeGetPortfolio should be validated for correctness across multiple networks
  • Alignment between instructions and implementation: ensure the new rule enforcement in chat.ts properly reflects how totals are now precomputed and available for the mathCalculator tool

Possibly related PRs

Poem

🐰 With totals tucked and math so neat,
No mental sums, just spreadsheets!
Per-network counts and overall sums,
The calculator's beating drums—
Precision hops where guesses shun! 🧮

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: precalculating portfolio totals to prevent the AI from performing arithmetic. It directly aligns with the primary changes across both modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch precalc-totals

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e575a03 and 4f60849.

📒 Files selected for processing (2)
  • apps/agentic-server/src/routes/chat.ts (1 hunks)
  • apps/agentic-server/src/tools/portfolio.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: premiumjibles
Repo: shapeshift/agentic-chat PR: 68
File: apps/agentic-server/package.json:26-26
Timestamp: 2025-09-16T20:28:23.547Z
Learning: In the ShapeShift agentic-chat codebase, mathjs optimization (lazy-loading or using modular sub-packages) has been noted for future implementation rather than immediate action.
📚 Learning: 2025-09-16T20:28:23.547Z
Learnt from: premiumjibles
Repo: shapeshift/agentic-chat PR: 68
File: apps/agentic-server/package.json:26-26
Timestamp: 2025-09-16T20:28:23.547Z
Learning: In the ShapeShift agentic-chat codebase, mathjs optimization (lazy-loading or using modular sub-packages) has been noted for future implementation rather than immediate action.

Applied to files:

  • apps/agentic-server/src/routes/chat.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: main
🔇 Additional comments (6)
apps/agentic-server/src/routes/chat.ts (1)

237-242: Excellent addition to prevent AI calculation errors.

The new CRITICAL Math & Calculations section is well-designed with clear, emphatic language. The instructions properly direct the AI to use precomputed totals from the portfolio response and the mathCalculator tool for all arithmetic operations, which aligns perfectly with the portfolio.ts changes.

apps/agentic-server/src/tools/portfolio.ts (5)

4-4: Good choice for financial precision.

Using BigNumber for portfolio total calculations is appropriate to avoid floating-point precision errors in USD value aggregation.


42-45: Clean type definition for portfolio totals.

The PortfolioTotals structure is well-designed with clear separation of overall and per-network totals. Using string type for USD amounts maintains consistency with existing balance representations.


47-61: Well-structured data format improvement.

Restructuring PortfolioOutput from a flat array to an object with separate networks and totals properties provides better organization and makes the precomputed totals easily accessible to consumers.


161-171: Correct implementation of total calculation with BigNumber.

The aggregation logic properly uses BigNumber for precise financial arithmetic:

  • Network totals are calculated by summing all balance USD amounts
  • Overall total is the sum of all network totals
  • Results are formatted to 2 decimal places for USD display

The immutable .plus() pattern is correct, and BigNumber handles edge cases like empty balances gracefully.


184-184: Description accurately reflects the implementation.

The updated tool description clearly communicates the availability of precomputed totals and instructs consumers to use them directly without recalculation, which aligns perfectly with the CRITICAL Math & Calculations rules in chat.ts.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@premiumjibles premiumjibles merged commit 30cbbb5 into main Dec 10, 2025
4 checks passed
@premiumjibles premiumjibles deleted the precalc-totals branch December 10, 2025 03:30
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.

2 participants