Skip to content

Library: more than 15 books opens the AI without the flag - #244

Closed
manager wants to merge 1 commit into
mainfrom
feat/library-ai-by-books
Closed

manager wants to merge 1 commit into
mainfrom
feat/library-ai-by-books

Conversation

@manager

@manager manager commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

The AI shelf and the magic books open to an owner who holds the library-ai flag, or whose library holds more than 15 books. Only objects of type book count, on every shelf. Authorized by Wolf on 2026-09-25.

  • One check, opensLibraryAi (src/lib/library/flags.ts), decides for the page and for /api/library/ai-shelf and /api/library/magic-book through ownerOfLibrary.
  • The count is read from the library on each check; nothing is stored. The AI appears with the sixteenth book and hides again at fifteen unless the flag is held.
  • The AI shelf keeps its own 30-book lock (AI_SHELF_MIN_BOOKS).
  • LIBRARY.md records the rule; scripts/release/library-batch-check.cjs covers 15 vs 16 books, non-book objects and the flag override.

Checks run: node scripts/release/library-batch-check.cjs PASS, tsc --noEmit clean, ESLint and Prettier clean.

🤖 Generated with Claude Code

The AI shelf and the magic books now open to an owner who holds the
library-ai flag or whose library holds more than 15 books (type book,
every shelf). One check, opensLibraryAi, decides for the page and both
routes; the count is read from the library on each check, nothing is
stored. The AI shelf keeps its own 30-book lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Claude finished @manager's task in 2m 13s —— View job


Review: Library AI opens with 15+ books (#244)

  • Gather context (diff, changed files)
  • Understand the request (code review)
  • Review correctness & React best practices
  • Review TypeScript quality
  • Review project conventions (AGENTS.md)
  • Review accessibility & security
  • Review styling
  • Post inline comments for issues found (none needed)
  • Post final summary

Assessment: clean, no blocking issues found.

Traced the full path for both correctness and security:

  • countBooks/opensLibraryAi (src/lib/library/flags.ts) — null-safe on library/singleShelves/objects, counts only attributes.type === 'book' across every singleShelves entry. Confirmed against src/local-types/library/library.ts and Shelf.tsx that a shelf's objects are always homogeneous with its own type, so not also filtering by shelf.attributes.type (unlike digestLibrary) is harmless in practice, and matches the PR's stated intent ("on every shelf").
  • Server-side enforcement is authoritative, not trusted from the client. ownerOfLibrary (src/lib/library/owner.ts:105) re-fetches the library from Strapi with the caller's own token and recomputes opensLibraryAi(me, library) there — a client can't spoof the book count to unlock /api/library/ai-shelf or /api/library/magic-book. The existing POPULATE query in owner.ts already pulls singleShelves.objects deep enough for countBooks, so no populate gap.
  • Favorites double-count check: confirmed via src/lib/library/favorites.ts that "Favorites" is a synthetic view over singleShelves objects, not a separate relation — no double-counting risk.
  • Client-side gating (Library.tsx:276) mirrors the old holdsFlag pattern 1:1 and stays behind viewAsOwner at the render site (Library.tsx:1476), so a visitor still never sees the AI shelf/magic books, consistent with LIBRARY.md's guarantee.
  • Migration completeness: grepped for any leftover { flag: LIBRARY_AI_FLAG } or holdsFlag call sites outside flags.ts itself — none found; both API routes and owner.ts are fully switched to { libraryAi: true } / opensLibraryAi.
  • Conventions: import order matches AGENTS.md ordering (@constants → @local-types → @lib), import type used correctly for StrapiLibraryEntry, no any, no App Router/Tailwind/state-library violations, no UI/styling touched.
  • Tests in scripts/release/library-batch-check.cjs cover the 15-vs-16 boundary, non-book objects mixed onto a shelf, the flag override, and both API routes/page wiring via source-text assertions — consistent with the file's existing style.

No inline comments filed — didn't find anything rising above nitpick level.

@manager

manager commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Shipped inside #246.

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.

1 participant