[PR #7674] [MERGED] refactor(generate): move the reply text cleanup into reply-text-cleanup.ts (#7573, slice 4) #7876

Closed
opened 2026-10-24 04:08:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7674
Author: @Gunterlie
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @Gunterlie

Base: staging ← Head: chore/7573-reply-text-cleanup


📝 Commits (3)

  • 382517a refactor(generate): move the reply text cleanup into reply-text-cleanup.ts
  • 1902a2b test(generate): pin the prefix strip without the envelope strip hiding it
  • 60dc0e5 Merge remote-tracking branch 'origin/staging' into chore/7573-reply-text-cleanup

📊 Changes

4 files changed (+318 additions, -144 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+19 -143)
➕ packages/server/src/routes/generate/reply-text-cleanup.ts (+175 -0)
➕ scripts/regressions/generate-reply-text-cleanup.regression.ts (+123 -0)
📝 scripts/regressions/open-issues.regression.ts (+1 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Part of #7573 (fourth slice). Stacked on #7673 (which is stacked on #7672): merge those first; GitHub retargets this PR to staging when its base branch is deleted.

Why this change

After the reply command parse (#7673), the post-generation step cleans the reply text: it moves <ooc> notes to the connected conversation, strips a group member's name or speaker wrapper, drops a reply written as the wrong speaker, strips the conversation envelope, trims an incomplete ending, and tidies roleplay whitespace. These were about 145 lines of string rules inside generateForCharacter, mixed with route state. As one pure function with a table of cases, each rule is testable without a model and readable in one pass.

No behaviour change.

What changed

  • New packages/server/src/routes/generate/reply-text-cleanup.ts: cleanGeneratedReply(text, options) returns { text, changed, oocMessages } or { dropped: "wrong_speaker" }. The steps keep their order and their log lines.
  • generate.routes.ts (now about 15,000 lines) keeps its own state writes. On a wrong-speaker drop it still sends the empty content_replace and returns null, as before.
  • New scripts/regressions/generate-reply-text-cleanup.regression.ts: 14 table rows for the OOC extraction (and when it is skipped), the individual-group prefix and wrapper strip, the prune passes, the trailing-turn cut, the wrong-speaker drop, the merged group that keeps its prefixes, the envelope strip, the incomplete-ending trim on and off, and roleplay whitespace. Each row also checks changed.
  • The open-issues extra-turn pin now reads the new module.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Agent-run results (not a substitute for the boxes above):

  • pnpm check: passed.
  • Regressions: generate-reply-text-cleanup passed. In a sweep of 70 regressions (every one that reads generate.routes.ts or covers OOC, envelope, trim or speaker prefixes), 69 passed. multiplayer-peer-server-security fails with ERR_TLS_CERT_ALTNAME_INVALID for ::1; it fails the same way on current staging without this change, so it is a local host issue, not this PR.
  • Local CodeRabbit: 0 findings. A separate line-by-line review found no behaviour change and one weak test row (the envelope strip also removed the prefix, so the row could not catch a broken prefix strip); fixed.

Manual verification notes

  • Manually verify an individual-generation group conversation: a reply that starts with the character's own name shows without the name.
  • Manually verify a roleplay chat with a connected conversation: an <ooc>…</ooc> note in the reply moves to the conversation and leaves the roleplay text clean.
  • Manually verify "Trim incomplete model output" on and off: a reply cut mid-sentence is trimmed only when it is on.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Summary by CodeRabbit

  • Bug Fixes
    • Generated roleplay replies now handle out-of-character messages separately from the reply.
    • Group replies are cleaned up to remove mismatched speaker turns and stop at the next speaker’s turn.
    • Conversation replies have extra formatting and envelope text removed, while preserving speaker labels where needed.
    • When applicable, incomplete endings and excess whitespace are cleaned up. Replies containing only another speaker’s text are discarded.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7674 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `chore/7573-reply-text-cleanup` --- ### 📝 Commits (3) - [`382517a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/382517a843242bec27a80c7ff8ce7625dbad484d) refactor(generate): move the reply text cleanup into reply-text-cleanup.ts - [`1902a2b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1902a2b6c70b810640199eafd2ee7822c421afa7) test(generate): pin the prefix strip without the envelope strip hiding it - [`60dc0e5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/60dc0e5f4b02b1d6c059a679115f4f2cd94103a3) Merge remote-tracking branch 'origin/staging' into chore/7573-reply-text-cleanup ### 📊 Changes **4 files changed** (+318 additions, -144 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+19 -143) ➕ `packages/server/src/routes/generate/reply-text-cleanup.ts` (+175 -0) ➕ `scripts/regressions/generate-reply-text-cleanup.regression.ts` (+123 -0) 📝 `scripts/regressions/open-issues.regression.ts` (+1 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Part of #7573 (fourth slice). Stacked on #7673 (which is stacked on #7672): merge those first; GitHub retargets this PR to `staging` when its base branch is deleted. ## Why this change After the reply command parse (#7673), the post-generation step cleans the reply text: it moves `<ooc>` notes to the connected conversation, strips a group member's name or speaker wrapper, drops a reply written as the wrong speaker, strips the conversation envelope, trims an incomplete ending, and tidies roleplay whitespace. These were about 145 lines of string rules inside `generateForCharacter`, mixed with route state. As one pure function with a table of cases, each rule is testable without a model and readable in one pass. No behaviour change. ## What changed - New `packages/server/src/routes/generate/reply-text-cleanup.ts`: `cleanGeneratedReply(text, options)` returns `{ text, changed, oocMessages }` or `{ dropped: "wrong_speaker" }`. The steps keep their order and their log lines. - `generate.routes.ts` (now about 15,000 lines) keeps its own state writes. On a wrong-speaker drop it still sends the empty `content_replace` and returns `null`, as before. - New `scripts/regressions/generate-reply-text-cleanup.regression.ts`: 14 table rows for the OOC extraction (and when it is skipped), the individual-group prefix and wrapper strip, the prune passes, the trailing-turn cut, the wrong-speaker drop, the merged group that keeps its prefixes, the envelope strip, the incomplete-ending trim on and off, and roleplay whitespace. Each row also checks `changed`. - The `open-issues` extra-turn pin now reads the new module. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Agent-run results (not a substitute for the boxes above): - `pnpm check`: passed. - Regressions: `generate-reply-text-cleanup` passed. In a sweep of 70 regressions (every one that reads `generate.routes.ts` or covers OOC, envelope, trim or speaker prefixes), 69 passed. `multiplayer-peer-server-security` fails with `ERR_TLS_CERT_ALTNAME_INVALID` for `::1`; it fails the same way on current `staging` without this change, so it is a local host issue, not this PR. - Local CodeRabbit: 0 findings. A separate line-by-line review found no behaviour change and one weak test row (the envelope strip also removed the prefix, so the row could not catch a broken prefix strip); fixed. ### Manual verification notes - Manually verify an individual-generation group conversation: a reply that starts with the character's own name shows without the name. - Manually verify a roleplay chat with a connected conversation: an `<ooc>…</ooc>` note in the reply moves to the conversation and leaves the roleplay text clean. - Manually verify "Trim incomplete model output" on and off: a reply cut mid-sentence is trimmed only when it is on. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Generated roleplay replies now handle out-of-character messages separately from the reply. * Group replies are cleaned up to remove mismatched speaker turns and stop at the next speaker’s turn. * Conversation replies have extra formatting and envelope text removed, while preserving speaker labels where needed. * When applicable, incomplete endings and excess whitespace are cleaned up. Replies containing only another speaker’s text are discarded. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:08:24 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7876
No description provided.