Skip to content

feat(word-count): scene budget check with expand/compress rewrite (#15)#41

Merged
DankerMu merged 3 commits into
mainfrom
feat/word-count-control
Feb 21, 2026
Merged

feat(word-count): scene budget check with expand/compress rewrite (#15)#41
DankerMu merged 3 commits into
mainfrom
feat/word-count-control

Conversation

@DankerMu
Copy link
Copy Markdown
Owner

Summary

  • Add scene target_chars budget check with ±15% tolerance
  • POST /api/generate/word-count-check: returns budget status (within/over/under)
  • POST /api/generate/rewrite: SSE streaming expand/compress via LLM
  • Rejects rewrite if text already within budget (400)
  • Input validation: target_chars 100-50000, mode expand|compress

Changes

  • backend/app/services/word_count.py: Budget check + rewrite prompt builder
  • backend/app/api/generation.py: 2 new endpoints (word-count-check, rewrite)
  • backend/app/api/ai_schemas.py: RewriteRequest + WordCountCheck schemas
  • backend/tests/test_word_count.py: 16 tests (8 unit + 2 prompt + 6 API)
  • frontend/src/lib/types.ts: WordCountCheck, RewriteMode types

Test Plan

  • 16 backend tests passing (120 total suite)
  • Ruff lint clean
  • Frontend UI integration (pending)

Closes #15

🤖 Generated with Claude Code

DankerMu and others added 3 commits February 21, 2026 12:41
- Add word_count service: check_word_budget() + build_rewrite_prompt()
- POST /api/generate/word-count-check: budget status endpoint
- POST /api/generate/rewrite: SSE streaming expand/compress via LLM
- Tolerance ±15%, rejects rewrite if already within budget
- Input validation: target_chars 100-50000, mode expand|compress
- 16 tests: 8 unit (budget logic) + 2 prompt + 6 API endpoint
- Frontend TypeScript types: WordCountCheck, RewriteMode

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- H1: validate mode matches budget direction (reject mismatch with 400)
- M1: create dedicated WordCountCheckRequest schema (no scene_id/mode)
- M2: add max_length=100000 to text field
- L1: move word_count imports to module top level
- L3: add mode/direction mismatch test

All 17 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DankerMu
Copy link
Copy Markdown
Owner Author

Review Result: PASS (92/100)

  • Pure functions with clean separation of concerns
  • 17 tests covering unit + API edge cases
  • Proper input validation (Literal type, Field constraints)
  • SSE streaming with mode/direction mismatch guard
  • Consistent with existing codebase patterns

@DankerMu DankerMu merged commit 760a276 into main Feb 21, 2026
7 checks passed
@DankerMu DankerMu deleted the feat/word-count-control branch February 21, 2026 05:04
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.

Word Count Control: 场景字数中约束

1 participant