Skip to content

Conversation

@chhoumann
Copy link
Owner

@chhoumann chhoumann commented Jan 4, 2026

Summary

This PR reduces QuickAdd’s bundled main.js size to fit within Obsidian Sync Standard’s per-file limit, which prevents the plugin from syncing and enabling on mobile when the bundle is too large.

Motivation / Context

QuickAdd’s production bundle exceeded the Sync Standard cap, causing main.js to be skipped during sync and the plugin to fail loading on mobile. The largest contributor was js-tiktoken. We need to keep a single-file bundle (Obsidian plugins require this), so the solution focuses on slimming the token-counting dependency.

What changed

  • Switched token counting to js-tiktoken/lite and included only the required OpenAI ranks (cl100k_base, o200k_base).
  • Removed text-davinci-003 from default OpenAI models (deprecated; requires additional ranks).
  • Added a small UI note near token counts: “Exact for OpenAI models; estimates for others.”
  • Updated tsconfig.json to moduleResolution: "bundler" so TypeScript can resolve js-tiktoken subpath exports.

Result

  • main.js size drops from ~6.11 MB to ~4.23 MB (under the Sync Standard limit).
  • Exact token counts are preserved for modern OpenAI models.
  • Non-OpenAI and legacy models use a fallback estimate, which matches existing behavior for non-OpenAI providers.

Testing

  • bun run build
  • bun run test

Screenshots

N/A (text-only UI note)

Closes #1071

@vercel
Copy link

vercel bot commented Jan 4, 2026

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

Project Deployment Review Updated (UTC)
quickadd Ready Ready Preview Jan 4, 2026 9:57am

@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

The changes modernize the tokenization approach in AIAssistant using Tiktoken with local caching, remove a deprecated OpenAI model, add clarifying UI notes about token count accuracy, introduce extensive responsive CSS styling rules, and update the TypeScript module resolution strategy.

Changes

Cohort / File(s) Summary
Tokenization Architecture
src/ai/AIAssistant.ts
Replaced legacy encoding API with Tiktoken-based tokenization including local encoding registry, caching mechanism, and helper utilities. Added input validation to repeatUntilResolved. Encoding fallback normalized to cl100k_base with graceful error handling.
Model Provider Updates
src/ai/Provider.ts
Removed text-davinci-003 model entry from OpenAIProvider.models array.
UI/UX Enhancements
src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts, src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
Added muted UI note beneath System Prompt token count: "Exact for OpenAI models; estimates for others." rendered as additional DOM element with reduced font size.
Styling & Layout
styles.css
Comprehensive additions-only CSS block introducing responsive layouts for modals, inputs, flex/grid containers, date picker components, suggestion pills with color theming, file suggestion items, accessibility features (focus outlines, reduced-motion), and dark theme overrides.
Build Configuration
tsconfig.json
Changed compilerOptions.moduleResolution from "node" to "bundler" to alter TypeScript module resolution strategy.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Tokens now counted with Tiktoken's grace,
Old models fade, new models take their place,
CSS blooms with colors anew,
And notes guide users through and through,
The bundler hops with nimbler feet! 🌟

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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Reduce bundle size below Obsidian Sync limit' directly and clearly summarizes the main objective of the PR, which involves optimizing the bundle size to stay within sync constraints.
Linked Issues check ✅ Passed The PR addresses issue #1071 by reducing bundle size to prevent sync failures on mobile; removes legacy models; adds token accuracy notes; and updates module resolution for js-tiktoken compatibility.
Out of Scope Changes check ✅ Passed All changes are directly related to bundle size reduction and fixing the mobile sync issue: token counting optimization, legacy model removal, UI clarification notes, and TypeScript configuration. CSS additions support the UI notes mentioned in objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link

@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: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 786b53c and 146f4dc.

📒 Files selected for processing (7)
  • main.js
  • src/ai/AIAssistant.ts
  • src/ai/Provider.ts
  • src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts
  • src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
  • styles.css
  • tsconfig.json
💤 Files with no reviewable changes (1)
  • src/ai/Provider.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,mts,mjs,js,json}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,mts,mjs,js,json}: Use tab indentation with width 2 in TypeScript and configuration files (enforced by Biome).
Follow an 80-character line guide (enforced by Biome).

Files:

  • src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts
  • src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
  • src/ai/AIAssistant.ts
  • tsconfig.json
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use camelCase for variables and functions in TypeScript.
Prefer type-only imports in TypeScript.

Files:

  • src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts
  • src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
  • src/ai/AIAssistant.ts
**/*.{ts,tsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

Use PascalCase for classes and Svelte components.

Files:

  • src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts
  • src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
  • src/ai/AIAssistant.ts
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Route logging through the logger utilities for consistent output.

Files:

  • src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts
  • src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts
  • src/ai/AIAssistant.ts
{main.js,styles.css}

📄 CodeRabbit inference engine (AGENTS.md)

Bundled artifacts main.js and styles.css at the repo root should be generated, not hand-edited.

Files:

  • styles.css
🧠 Learnings (5)
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to **/*.{ts,tsx} : Prefer type-only imports in TypeScript.

Applied to files:

  • tsconfig.json
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to src/main.ts : Preserve the hand-ordered imports in `src/main.ts`; disable auto-sorting there.

Applied to files:

  • tsconfig.json
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Use `bun run build`: run `tsc --noEmit` then produce the production bundle.

Applied to files:

  • tsconfig.json
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Use `bun run dev`: watch-mode bundle via `esbuild.config.mjs`, regenerating `main.js` as you edit.

Applied to files:

  • tsconfig.json
📚 Learning: 2025-12-21T07:54:34.875Z
Learnt from: CR
Repo: chhoumann/quickadd PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-21T07:54:34.875Z
Learning: Applies to {main.js,styles.css} : Bundled artifacts `main.js` and `styles.css` at the repo root should be generated, not hand-edited.

Applied to files:

  • styles.css
🧬 Code graph analysis (1)
src/ai/AIAssistant.ts (1)
src/ai/Provider.ts (1)
  • Model (14-17)
🔇 Additional comments (7)
src/gui/MacroGUIs/AIAssistantCommandSettingsModal.ts (1)

182-189: LGTM - Clear user-facing note about token count accuracy.

The note accurately informs users that token counts are exact for OpenAI models and estimated for others, aligning with the cl100k_base fallback logic in AIAssistant.ts. The styling is consistent with existing UI patterns.

src/gui/MacroGUIs/AIAssistantInfiniteCommandSettingsModal.ts (1)

146-153: LGTM - Consistent with AIAssistantCommandSettingsModal.ts.

The UI note mirrors the implementation in the sibling modal, maintaining consistency across the plugin's AI assistant interfaces.

src/ai/AIAssistant.ts (4)

1-4: Good choice using js-tiktoken/lite for bundle size reduction.

The selective imports of only cl100k_base and o200k_base ranks minimizes bundle size while supporting modern OpenAI models. o200k_base covers GPT-4o and newer models; cl100k_base covers GPT-4, GPT-3.5-turbo, and serves as a reasonable fallback.


21-35: Solid caching pattern for Tiktoken instances.

The module-level cache prevents repeated instantiation of Tiktoken encoders. Since only two encodings are bundled, memory footprint is minimal. The defensive fallback on line 28 provides an extra safety net.


37-53: Token counting logic correctly handles model encoding fallbacks.

The normalization of legacy encodings (p50k_*, r50k_base, gpt2) to cl100k_base is appropriate since those ranks aren't bundled. Combined with the UI note about estimates for non-OpenAI models, users are informed when counts may be approximate.

One minor observation: The try-catch on lines 40-44 already sets encodingName = "cl100k_base" on error, and line 39 initializes it to "cl100k_base". The initialization could be removed since the catch block handles the fallback, but the current approach is more explicit.


55-69: Good defensive validation for repeatUntilResolved.

The input validation helps catch programming errors early with clear error messages.

styles.css (1)

1-1: Generated artifact - no manual review required.

Per coding guidelines, styles.css is a bundled artifact that should be generated via the build process, not hand-edited. The minified output includes appropriate responsive styles, accessibility media queries (prefers-reduced-motion, prefers-contrast), and theme support.

@chhoumann chhoumann merged commit 1e1a632 into master Jan 4, 2026
4 checks passed
@chhoumann chhoumann deleted the 1071 branch January 4, 2026 09:59
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.

[BUG] Failed to load plugin when using Obsidian Sync

2 participants