Skip to content

feat(web): optional loop-phrase prompt prefix (loop-focused workflow)#264

Draft
leszko wants to merge 1 commit into
mainfrom
rafal/feat/loop-phrase-prompt
Draft

feat(web): optional loop-phrase prompt prefix (loop-focused workflow)#264
leszko wants to merge 1 commit into
mainfrom
rafal/feat/loop-phrase-prompt

Conversation

@leszko

@leszko leszko commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

What

Acts on the loop-prompting experiment finding: prepending a short perfect loop of <prompt> lowers the loop-seam discontinuity ~12–14% on average (techno −22%, deep house −18%; neutral on smooth pads) with no measured downside.

This adds an opt-in, client-side, WYSIWYG-respecting loop-phrase prefix that mirrors the existing auto_prepend_lora_triggers pattern exactly.

How (and why it's low-risk)

  • No server / protocol / wire-type change. It rides the existing prompt WS command (tags/tags_b). The phrase is injected onto the wire at send-time in wirePromptTransform and stripped from the incoming text first, so there's no double-prepend and toggling it takes effect on the next send.
  • WYSIWYG preserved. The Tags A/B textareas stay the operator's clean text — exactly like LoRA triggers, which the engine comment calls out: "the server intentionally does NOT inject anything behind the user's back." Injection is client-side and reversible.
  • Composition: wire order is <lora triggers><loop phrase><clean tags> — triggers stay at the head as activation tokens, the phrase wraps the prompt.

Surface

  • lib/config.ts: engine.auto_prepend_loop_phrase (default false — opt-in, pending ear confirmation) and engine.loop_phrase (default "a short perfect loop of", the study's best performer; edged "seamless repeating loop of").
  • lib/loopPhrase.ts: loopPhrasePrefix() + stripLeadingLoopPhrase().
  • lib/loraTriggers.ts: wirePromptTransform composes the two prefixes.
  • tests/unit/loopPhrase.test.ts: 14 tests — gating, custom phrase, idempotency, blank-phrase guard, trigger composition.

How to test

Edit demos/realtime_motion_graph_web/web/public/config.json and set:

{ "engine": { "auto_prepend_loop_phrase": true } }

then refresh (same live-config workflow as the LoRA flag — no rebuild). A/B against false. Try "loop_phrase": "seamless repeating loop of" too. The win is biggest on rhythmic material where the loop wrap is audible.

Checks

npm run typecheck clean · npm run build clean · vitest run tests/unit/loopPhrase.test.ts → 14 passed.

Caveats

The effect is distributional (per-seed variance is large) and was measured with objective proxies — it's defaulted off until confirmed by ear in the live app, which is exactly what this PR enables. The companion latent-size finding (20–30 s window) is not in this PR — it needs a sub-60 s TRT engine profile build, tracked separately.

🤖 Generated with Claude Code

Acts on the loop-prompting experiment finding: prepending "a short
perfect loop of <prompt>" lowers the loop-seam discontinuity ~12-14% on
average (techno -22%, deep house -18%; neutral on smooth pads) with no
measured downside.

Mirrors the auto_prepend_lora_triggers pattern exactly: a client-side,
WYSIWYG-respecting wire transform. The Tags A/B textareas stay the
operator's clean text; the phrase is injected onto the wire at send-time
in wirePromptTransform and stripped on the next send, so there is no
double-prepend. Rides the existing `prompt` WS command (tags/tags_b) --
no server, protocol, or wire-type change.

- engine.auto_prepend_loop_phrase (default false, opt-in pending ear
  confirmation) + engine.loop_phrase (default "a short perfect loop of").
  Toggle live via web/public/config.json + refresh, same as the LoRA flag.
- lib/loopPhrase.ts: loopPhrasePrefix() + stripLeadingLoopPhrase().
- wirePromptTransform composes <lora triggers><loop phrase><clean tags>.
- 14 unit tests: gating, custom phrase, idempotency, trigger composition.

typecheck + next build clean; vitest green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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