add LLM-optimized documentation package for router & start#6545
add LLM-optimized documentation package for router & start#6545LadyBluenotes wants to merge 1 commit intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughThis pull request introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
|
View your CI Pipeline Execution ↗ for commit e1c34ff
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@packages/llm-docs/scripts/generate.mjs`:
- Line 460: The reduction calculation can divide by zero when totalOriginal is
0; update the computation around the expression that assigns reduction (the line
using Math.round((1 - totalStripped / totalOriginal) * 100)) to guard against
totalOriginal === 0 and produce a sensible default (e.g., 0) instead of
performing the division — replace the direct expression with a conditional that
checks totalOriginal and only computes the percentage when nonzero, otherwise
sets reduction to 0.
- Around line 278-281: The reduction calculation can produce NaN/Infinity when
originalSize is 0; update the object building (where reduced value is set using
strippedSize, originalSize, reduction) to guard against division by zero by
computing reduction as 0 when originalSize is 0 (or when both originalSize and
strippedSize are 0) otherwise use Math.round((1 - strippedSize / originalSize) *
100); locate the code that returns the object with keys strippedSize,
estimatedTokens and reduction and apply this conditional check.
In `@packages/router-core/package.json`:
- Line 163: Remove "@tanstack/llm-docs" from the dependencies list in
package.json and add the same entry under devDependencies (preserve the
"workspace:*" specifier), ensuring package.json keys remain valid JSON; update
any lockfile if present (run install) and run the package tests/build to verify
nothing broke.
🧹 Nitpick comments (3)
packages/solid-router/package.json (1)
109-109: Consider moving@tanstack/llm-docstodevDependencies.Same concern as noted in
router-core/package.json— documentation tooling likely belongs indevDependenciesrather than productiondependenciesto avoid inflating consumer installations.packages/react-start/package.json (1)
96-96: Consider moving@tanstack/llm-docstodevDependencies.Consistent with the other packages in this PR, this documentation tooling package likely belongs in
devDependencies.packages/llm-docs/scripts/generate.mjs (1)
474-474: Consider propagating a non-zero exit code on failure.Currently, if
main()throws, the error is logged but the process may still exit with code 0, which could cause CI pipelines to incorrectly report success.Proposed fix
-main().catch(console.error) +main().catch((err) => { + console.error(err) + process.exit(1) +})
| strippedSize, | ||
| estimatedTokens, | ||
| reduction: Math.round((1 - strippedSize / originalSize) * 100), | ||
| } |
There was a problem hiding this comment.
Guard against division by zero for empty files.
If a markdown file is empty, originalSize will be 0, causing reduction to be NaN (or Infinity if strippedSize is also 0).
Proposed fix
- const reduction = Math.round((1 - strippedSize / originalSize) * 100)
+ const reduction = originalSize > 0
+ ? Math.round((1 - strippedSize / originalSize) * 100)
+ : 0🤖 Prompt for AI Agents
In `@packages/llm-docs/scripts/generate.mjs` around lines 278 - 281, The reduction
calculation can produce NaN/Infinity when originalSize is 0; update the object
building (where reduced value is set using strippedSize, originalSize,
reduction) to guard against division by zero by computing reduction as 0 when
originalSize is 0 (or when both originalSize and strippedSize are 0) otherwise
use Math.round((1 - strippedSize / originalSize) * 100); locate the code that
returns the object with keys strippedSize, estimatedTokens and reduction and
apply this conditional check.
| fs.writeFileSync(path.join(OUTPUT_DIR, 'AGENT.md'), agentMd, 'utf-8') | ||
|
|
||
| // Summary | ||
| const reduction = Math.round((1 - totalStripped / totalOriginal) * 100) |
There was a problem hiding this comment.
Same division-by-zero edge case in summary calculation.
If no files are processed (empty docs directories), totalOriginal would be 0.
Proposed fix
- const reduction = Math.round((1 - totalStripped / totalOriginal) * 100)
+ const reduction = totalOriginal > 0
+ ? Math.round((1 - totalStripped / totalOriginal) * 100)
+ : 0📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const reduction = Math.round((1 - totalStripped / totalOriginal) * 100) | |
| const reduction = totalOriginal > 0 | |
| ? Math.round((1 - totalStripped / totalOriginal) * 100) | |
| : 0 |
🤖 Prompt for AI Agents
In `@packages/llm-docs/scripts/generate.mjs` at line 460, The reduction
calculation can divide by zero when totalOriginal is 0; update the computation
around the expression that assigns reduction (the line using Math.round((1 -
totalStripped / totalOriginal) * 100)) to guard against totalOriginal === 0 and
produce a sensible default (e.g., 0) instead of performing the division —
replace the direct expression with a conditional that checks totalOriginal and
only computes the percentage when nonzero, otherwise sets reduction to 0.
| }, | ||
| "dependencies": { | ||
| "@tanstack/history": "workspace:*", | ||
| "@tanstack/llm-docs": "workspace:*", |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, let's see the context around line 163 in package.json
echo "=== package.json context around line 163 ==="
sed -n '155,175p' packages/router-core/package.json
echo -e "\n=== Checking for runtime imports of `@tanstack/llm-docs` in router-core/src ==="
rg "@tanstack/llm-docs" packages/router-core/src/ 2>/dev/null || echo "No imports found in src"
echo -e "\n=== Checking if llm-docs is imported anywhere in the router-core directory ==="
rg "@tanstack/llm-docs" packages/router-core/ --type ts --type js --type json 2>/dev/null | grep -v node_modules || echo "No imports found"
echo -e "\n=== Checking dependencies vs devDependencies structure ==="
grep -A 2 '"dependencies"' packages/router-core/package.json | head -5
grep -A 2 '"devDependencies"' packages/router-core/package.json | head -5Repository: TanStack/router
Length of output: 979
Move @tanstack/llm-docs to devDependencies.
The @tanstack/llm-docs package is not used in any runtime code and should not be a production dependency. This unnecessarily increases bundle size for all consumers of @tanstack/router-core.
🤖 Prompt for AI Agents
In `@packages/router-core/package.json` at line 163, Remove "@tanstack/llm-docs"
from the dependencies list in package.json and add the same entry under
devDependencies (preserve the "workspace:*" specifier), ensuring package.json
keys remain valid JSON; update any lockfile if present (run install) and run the
package tests/build to verify nothing broke.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.