mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2704] [Issue]: ST-compatible lorebook export omits useRegex/recursion/vectorized and mis-encodes at-depth position #1349
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1349
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2704
Originally assigned to: @SpicyMarinara on GitHub.
Summary
The "SillyTavern-compatible" lorebook export (
format=compatible) omits several per-entry fields and mis-encodes at-depth placement, so a Marinara lorebook exported for ST loses regex-key matching, recursion gating, and vectorization opt-out, and at-depth entries land in the wrong place. This is the export-side companion to the import mismaps in #2690 — even a Marinara→ST round-trip isn't lossless.Expected behavior
The compatible export should emit a faithful SillyTavern World Info file: at-depth entries encoded as ST's at-depth form (position 4 + role + depth), and per-entry
useRegex, recursion, and vectorization flags preserved so the entry behaves the same after re-import.Actual behavior
buildCompatibleLorebookExport(lorebooks.routes.ts:130-169) writes each entry's fields but:position: Number(entry.position ?? 0)directly. Marinara'sposition=2means at-depth, but ST'sposition=2means Author's-Note-Top (ST at-depth isposition=4+role+depth). So every Marinara at-depth entry exports as ST AN-Top — wrong placement, and itsdepth/roleare ignored by ST. The export can never produce ST's at-depth form.useRegex/regexomitted. Never emitted, so a regex-key entry re-imports asuseRegex=falseand matches its pattern literally.preventRecursion/excludeRecursionomitted. Never emitted, so a non-recursable entry re-imports as recursable, changing which lore fires.vectorized/excludeFromVectorizationomitted. Never emitted, so a vectorization opt-out is reset to default on re-import.How it breaks the pipeline
Code trace (staging @
b826f8f4) —packages/server/src/routes/lorebooks.routes.ts,buildCompatibleLorebookExport(:130-169, per-entry object:133-156):position: Number(entry.position ?? 0)(:144); Marinara enumshared/types/lorebook.ts:159-160; importerresolvePositionmapsat_depth→2(st-lorebook.importer.ts:214-222).useRegexomitted; importer readsBoolean(entry.useRegex ?? entry.regex ?? false)(st-lorebook.importer.ts:403).preventRecursionomitted; importer readsBoolean(entry.preventRecursion ?? entry.excludeRecursion ?? false)(:419).excludeFromVectorizationomitted; STvectorizedfield recognized (st-lorebook.importer.ts:49).Steps to reproduce
position=2(at-depth),depth=6,role=assistant,useRegex=true(regex key),preventRecursion=true,excludeFromVectorization=true.GET /lorebooks/:id/export?format=compatible, then re-import the file.useRegex=false(literal match),preventRecursion=false, vectorization re-enabled.Suggested fix
Make the compatible export the inverse of the importer: emit Marinara
position=2as STposition=4with numericrole+depth(and0→0,1→1); adduseRegex(+regexalias),excludeRecursion: entry.preventRecursion === true, andvectorized: entry.excludeFromVectorization !== trueto each entry object, so import/export round-trips losslessly.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of import/export round-trips. Export-side companion to the import mismaps in #2690 (and the at-depth placement in #2691/#2676). Part of a set of import/export fidelity issues filed together.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@kolacheee commented on GitHub (Jun 21, 2026):
Two clarifications to keep this actionable:
The "round-trips losslessly" goal requires importer changes too, not just the export. Marinara's own importer (packages/server/src/services/import/st-lorebook.importer.ts) cannot decode the corrected export for two of the four fields, so shipping only the export change leaves the documented "re-import the file" reproduce step still broken for at-depth and vectorization:
resolvePosition (st-lorebook.importer.ts:214-222) only accepts numeric 0-2; ST at-depth position=4 falls through to
return 0(before_char). So exporting at-depth as position=4 round-trips correctly into SillyTavern, but a Marinara->file->Marinara re-import still lands the entry at before_char. Fix: addif (typeof value === "number" && value === 4) return 2;(or broaden the numeric range and map 4->2) so ST at-depth decodes back to Marinara at_depth. (depth and role already survive: the importer readsdepthat :405 androleat :382/:407 unconditionally, so once position decodes to 2 the original depth/role are preserved.)The importer never reads
vectorized: thevectorized?: booleanat :49 is declared on the STWorldInfoEntry type but never consumed, and the import input (:388-421) omits excludeFromVectorization entirely. So exportingvectorizedwon't restore excludeFromVectorization on Marinara re-import. Fix: in the import input addexcludeFromVectorization: entry.vectorized === false ? true : Boolean(entry.excludeFromVectorization)(mind the inverted polarity — STvectorized=truemeans "is vectorized" = NOT excluded).useRegex (:403) and preventRecursion/excludeRecursion (:419) are already read by the importer, so those two fields round-trip with the export change alone.
Minor correction to the "How it breaks the pipeline" trace: the bullet "ST
vectorizedfield recognized (st-lorebook.importer.ts:49)" should read "declared in the STWorldInfoEntry type (:49) but not consumed by the importer." The importer does not currently read entry.vectorized anywhere, which is exactly why importer change (1) above is required for the vectorization opt-out to survive a Marinara re-import.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed the still-valid gaps on the issue sweep branch. At-depth compatible export/import and useRegex/preventRecursion handling were already present in the current branch, so I left those intact. This patch adds the ST regex alias and vectorized flag on compatible export, maps vectorized=false back to excludeFromVectorization on import, and corrects the importer so vectorized=true no longer strips keyword keys. Final pnpm validation is deferred until the full sweep is complete.