Skip to content

fix: runtime PACKAGE_ROOT, frontmatter ordering, llms.txt support#19

Merged
rsbh merged 3 commits intomainfrom
fix_order_and_llms
Mar 12, 2026
Merged

fix: runtime PACKAGE_ROOT, frontmatter ordering, llms.txt support#19
rsbh merged 3 commits intomainfrom
fix_order_and_llms

Conversation

@rsbh
Copy link
Copy Markdown
Member

@rsbh rsbh commented Mar 11, 2026

Summary

  • Runtime PACKAGE_ROOT: Replace build-time PACKAGE_ROOT injection with runtime resolution via import.meta.url, fixing broken next binary path in published npm package
  • Frontmatter ordering: Add order field to fumadocs schema so sidebar ordering works; folders sort by index page order with fallback to lowest child order
  • Docker type fixes: Add unified and @types/unist deps, fix DirectiveNode types for strict TS in Docker production builds
  • llms.txt support: Add /llms.txt and /llms-full.txt routes, controlled via llms.enabled in chronicle.yaml (default: false). Upgrades fumadocs-core to 16.6.15 for native llms() support

Test plan

  • npx @raystack/chronicle dev works from outside the monorepo (PACKAGE_ROOT fix)
  • Docker build and run succeeds with docs content
  • Sidebar pages respect order frontmatter values
  • Folders sort by their index page's order
  • /llms.txt returns page index when llms.enabled: true
  • /llms-full.txt returns full content when llms.enabled: true
  • Both llms routes return 404 when llms.enabled: false

🤖 Generated with Claude Code

rsbh and others added 3 commits March 11, 2026 16:10
- 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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added LLM support with endpoints to serve documentation content for language models in text format.
    • Enhanced documentation configuration with optional frontmatter ordering.
  • Dependencies

    • Added unified and @types/unist packages.
    • Updated fumadocs-core to version 16.6.15.

Walkthrough

This 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

Cohort / File(s) Summary
Build System & PACKAGE_ROOT Resolution
build-cli.ts, src/cli/commands/build.ts, src/cli/commands/dev.ts, src/cli/commands/serve.ts, src/cli/commands/start.ts
Removed compile-time PACKAGE_ROOT injection from Bun.build and replaced it with runtime computation using fileURLToPath(import.meta.url) across all CLI commands to derive the package root path.
Dependencies
package.json
Added @types/unist (^3.0.3) and unified (^11.0.5); updated fumadocs-core from ^16.4.9 to 16.6.15.
Documentation Configuration
source.config.ts
Added frontmatter schema with optional order field and postprocess configuration (includeProcessedMarkdown: true) to the docs definition.
LLM Feature Implementation
src/app/llms.txt/route.ts, src/app/llms-full.txt/route.ts, src/lib/get-llm-text.ts, src/types/config.ts, src/lib/config.ts
Added new GET routes for serving LLM index and full LLM text; introduced getLLMText utility to format pages for LLM consumption; created LlmsConfig interface with enabled flag and integrated it into ChronicleConfig.
Plugin & Source Updates
src/lib/remark-unused-directives.ts, src/lib/source.ts
Refactored remark-unused-directives to use local type casting for node operations; updated source.ts to determine folder ordering based on matching URL paths instead of first sorted item.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rohilsurana
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the three main changes: runtime PACKAGE_ROOT resolution, frontmatter ordering, and llms.txt support, matching the key modifications in the changeset.
Description check ✅ Passed The description is directly related to the changeset, providing detailed context for each major change including runtime PACKAGE_ROOT fixes, frontmatter ordering, Docker type fixes, and llms.txt support with a comprehensive test plan.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_order_and_llms

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.

@rsbh rsbh requested a review from rohilsurana March 11, 2026 11:22
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getLLMText throws for any page (e.g., missing processed text), Promise.all will reject and the entire request returns a 500 error. Consider using Promise.allSettled or wrapping getLLMText to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b6c947 and c5e3bec.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • packages/chronicle/build-cli.ts
  • packages/chronicle/package.json
  • packages/chronicle/source.config.ts
  • packages/chronicle/src/app/llms-full.txt/route.ts
  • packages/chronicle/src/app/llms.txt/route.ts
  • packages/chronicle/src/cli/commands/build.ts
  • packages/chronicle/src/cli/commands/dev.ts
  • packages/chronicle/src/cli/commands/serve.ts
  • packages/chronicle/src/cli/commands/start.ts
  • packages/chronicle/src/lib/config.ts
  • packages/chronicle/src/lib/get-llm-text.ts
  • packages/chronicle/src/lib/remark-unused-directives.ts
  • packages/chronicle/src/lib/source.ts
  • packages/chronicle/src/types/config.ts
💤 Files with no reviewable changes (1)
  • packages/chronicle/build-cli.ts

@rsbh rsbh merged commit 8265e8e into main Mar 12, 2026
1 check passed
@rsbh rsbh deleted the fix_order_and_llms branch March 16, 2026 04:47
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