Skip to content

feat(studio): appendToLastMessage + decode replacement escapes - #385

Merged
danvitv merged 3 commits into
hydall:nightlyfrom
danvitv:fix/regex-unicode-replacement-escapes
Sep 3, 2026
Merged

feat(studio): appendToLastMessage + decode replacement escapes#385
danvitv merged 3 commits into
hydall:nightlyfrom
danvitv:fix/regex-unicode-replacement-escapes

Conversation

@danvitv

@danvitv danvitv commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Studio: append-to-last-user-message

The classic (non-Studio) PresetBlock.appendToLastMessage lets a block's macro-expanded content be merged into the last user turn instead of being emitted as its own message. This ports that to Studio presets:

  • Add appendToLastMessage to StudioPresetBlock.
  • Read/write it through the preset codec (_block in StudioPresetCodec).
  • In StudioMessageBuilder, collect instruction blocks flagged appendToLastMessage, skip them as standalone messages, and merge their expanded content into the last user-role history message in emitHistory (mirrors the classic applyAppendToLastMessage).
  • Expose a switch field ("Append to last user message") in the inline Studio block editor, shown for instruction blocks.

Regex: decode \u/\n escapes in Replace With

The Replace With replacement string was applied literally: \uXXXX and \n typed as text were not decoded (unlike SillyTavern). Add _decodeReplacementEscapes in RegexService._applySingleScript to decode \uXXXX, \u{XXXX}, \n, \t, \r, \\, while leaving \0-\9 intact so _resolveReplacement still treats them as capture-group backreferences.

Verification

  • dart run build_runner build after the freezed/json model change.
  • dart analyze clean.
  • flutter test green for studio_preset_codec_test.dart, append_to_last_message_test.dart, studio_typed_message_builder_test.dart (33 tests).
  • Not run: test/webview_js render suite (no Node/Playwright in this session) - left to CI.

Adds the classic PresetBlock.appendToLastMessage behaviour to StudioPresetBlock so dynamic context (memory, lorebooks, ledger) can be merged into the last user-role history message instead of emitted as a separate turn, keeping the volatile tail off the KV-cached prefix.
@danvitv
danvitv merged commit 95fb1c3 into hydall:nightly Sep 3, 2026
2 of 3 checks passed
@danvitv
danvitv deleted the fix/regex-unicode-replacement-escapes branch September 3, 2026 22:22
hydall added a commit that referenced this pull request Sep 4, 2026
#387)

`prompt_build_architecture_test.dart` forbids the literal string
`prompt_builder.dart` in the six Studio request-assembly files, so the
ordinary prompt path cannot creep back into them. Two comments in
`StudioMessageBuilder` named the file — no import, no `PromptPayload` /
`PromptResult` use, only the wording — and had been failing that test on
`nightly` since #385, reddening CI for every PR opened against it.

- reword the `appendToLastMessage` comments in
  `lib/core/llm/studio_message_builder.dart` to point at "the ordinary
  prompt builder" instead of naming the file

The test's contract is untouched and no behaviour changes.
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