fix: runtime PACKAGE_ROOT, frontmatter ordering, llms.txt support#19
fix: runtime PACKAGE_ROOT, frontmatter ordering, llms.txt support#19
Conversation
- Replace build-time PACKAGE_ROOT injection with runtime resolution via import.meta.url, fixing broken next binary path in published npm package - Add `order` field to fumadocs frontmatter schema so sidebar ordering works - Use folder's index page order for group sorting, fallback to lowest child order Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…t TS Adds missing type dependencies that caused Docker production build failures. Fixes DirectiveNode type to be compatible with strict unist types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add /llms.txt (index) and /llms-full.txt (full content) routes - Controlled via llms.enabled in chronicle.yaml (default: false) - Upgrade fumadocs-core to 16.6.15 for native llms() support - Enable postprocess with includeProcessedMarkdown in source config Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR introduces LLM support features while refactoring PACKAGE_ROOT resolution from compile-time to runtime across CLI commands. It adds new routes for serving LLM content, introduces configuration types and utilities for LLM management, updates documentation configuration with frontmatter schema and postprocess options, and adjusts CLI commands to compute the package root dynamically. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant LLMRoute as /llms.txt Route
participant Config as Config Loader
participant Source as Page Source
participant LLMProcessor as LLM Processor
Client->>LLMRoute: GET /llms.txt
LLMRoute->>Config: loadConfig()
Config-->>LLMRoute: config
alt config.llms.enabled is false
LLMRoute-->>Client: 404 Not Found
else config.llms.enabled is true
LLMRoute->>Source: getPages()
Source-->>LLMRoute: pages[]
LLMRoute->>LLMProcessor: getLLMText(each page)
LLMProcessor-->>LLMRoute: formatted text for each page
LLMRoute->>LLMRoute: join results with blank lines
LLMRoute-->>Client: 200 OK + LLM text
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/chronicle/src/app/llms-full.txt/route.ts (1)
14-15: Consider handling individual page processing failures.If
getLLMTextthrows for any page (e.g., missing processed text),Promise.allwill reject and the entire request returns a 500 error. Consider usingPromise.allSettledor wrappinggetLLMTextto gracefully skip problematic pages.♻️ Suggested approach with error handling
- const scan = source.getPages().map(getLLMText) - const scanned = await Promise.all(scan) + const scan = source.getPages().map(async (page) => { + try { + return await getLLMText(page) + } catch { + console.error(`Failed to process page: ${page.url}`) + return null + } + }) + const scanned = (await Promise.all(scan)).filter(Boolean)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/chronicle/src/app/llms-full.txt/route.ts` around lines 14 - 15, The current mapping uses Promise.all over source.getPages().map(getLLMText) which will reject the entire request if any getLLMText call throws; change this to handle per-page failures by using Promise.allSettled or by wrapping getLLMText calls in a try/catch wrapper so you can filter out failed results. Specifically, update the code that creates scan and scanned (the getLLMText mapping) to await Promise.allSettled(scan) (or map to async p => { try { return { status: 'fulfilled', value: await getLLMText(p) } catch (e) { return { status: 'rejected', reason: e } } }), then filter for fulfilled entries, log or record rejected entries (using existing logger or console.error) and continue processing only the successful values so a single bad page won’t cause a 500.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/chronicle/package.json`:
- Line 41: The package.json currently lists "@types/unist" in dependencies but
it is only used as a type-only import (e.g., "type { Node } from 'unist'" in
remark-unused-directives.ts); move "@types/unist" from dependencies into
devDependencies in package.json so the type package is only installed for
development/compilation, and remove it from the dependencies section to avoid
shipping dev-only types.
In `@packages/chronicle/src/cli/commands/build.ts`:
- Line 8: PACKAGE_ROOT is computed too shallowly and resolves to dist/ when
bundled; update the path traversal in the PACKAGE_ROOT declaration (the
path.resolve call using path.dirname(fileURLToPath(import.meta.url))) to go up
three levels instead of two so it points to the package root; apply the same
change in the analogous declaration in serve.ts as well (look for the
PACKAGE_ROOT constant and the path.resolve(... fileURLToPath(import.meta.url))
expression).
In `@packages/chronicle/src/lib/get-llm-text.ts`:
- Around line 4-9: The getLLMText function must guard against missing content:
check the result of page.data.getText('processed') and page.data.title in
getLLMText and if either is null/undefined return null instead of embedding
"undefined" in the string; update getLLMText to explicitly return null for
missing processed text or title (referencing getLLMText,
page.data.getText('processed') and page.data.title) and ensure the caller in
llms-full.txt/route.ts filters out nulls before joining the returned texts.
---
Nitpick comments:
In `@packages/chronicle/src/app/llms-full.txt/route.ts`:
- Around line 14-15: The current mapping uses Promise.all over
source.getPages().map(getLLMText) which will reject the entire request if any
getLLMText call throws; change this to handle per-page failures by using
Promise.allSettled or by wrapping getLLMText calls in a try/catch wrapper so you
can filter out failed results. Specifically, update the code that creates scan
and scanned (the getLLMText mapping) to await Promise.allSettled(scan) (or map
to async p => { try { return { status: 'fulfilled', value: await getLLMText(p) }
catch (e) { return { status: 'rejected', reason: e } } }), then filter for
fulfilled entries, log or record rejected entries (using existing logger or
console.error) and continue processing only the successful values so a single
bad page won’t cause a 500.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 647b2dcc-2680-4b17-aa7f-6e64058de589
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (14)
packages/chronicle/build-cli.tspackages/chronicle/package.jsonpackages/chronicle/source.config.tspackages/chronicle/src/app/llms-full.txt/route.tspackages/chronicle/src/app/llms.txt/route.tspackages/chronicle/src/cli/commands/build.tspackages/chronicle/src/cli/commands/dev.tspackages/chronicle/src/cli/commands/serve.tspackages/chronicle/src/cli/commands/start.tspackages/chronicle/src/lib/config.tspackages/chronicle/src/lib/get-llm-text.tspackages/chronicle/src/lib/remark-unused-directives.tspackages/chronicle/src/lib/source.tspackages/chronicle/src/types/config.ts
💤 Files with no reviewable changes (1)
- packages/chronicle/build-cli.ts
Summary
PACKAGE_ROOTinjection with runtime resolution viaimport.meta.url, fixing brokennextbinary path in published npm packageorderfield to fumadocs schema so sidebar ordering works; folders sort by index page order with fallback to lowest child orderunifiedand@types/unistdeps, fixDirectiveNodetypes for strict TS in Docker production builds/llms.txtand/llms-full.txtroutes, controlled viallms.enabledinchronicle.yaml(default: false). Upgradesfumadocs-coreto 16.6.15 for nativellms()supportTest plan
npx @raystack/chronicle devworks from outside the monorepo (PACKAGE_ROOT fix)orderfrontmatter values/llms.txtreturns page index whenllms.enabled: true/llms-full.txtreturns full content whenllms.enabled: truellms.enabled: false🤖 Generated with Claude Code