Add Prompt Builder bang ignores and facing-aware character features.
Strip !...! at compile time, and omit character features the active framing facing cannot see while keeping them checked in the editor. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -24,22 +24,33 @@ const {
|
||||
emptyOutfit,
|
||||
emptySet,
|
||||
emptyFraming,
|
||||
emptyFeature,
|
||||
cloneSceneForNext,
|
||||
normalizePromptSequence,
|
||||
normalizeSectionOrder,
|
||||
DEFAULT_PROMPT_SEQUENCE_SECTION_ORDER,
|
||||
ensureSceneStatesForCharacters
|
||||
ensureSceneStatesForCharacters,
|
||||
stripBangs,
|
||||
extractBangPhrases,
|
||||
compileCharacterForFacing,
|
||||
defaultVisibilityForGroup
|
||||
} = await import(pathToFileURL(tmp).href)
|
||||
unlinkSync(tmp)
|
||||
|
||||
test('formatCharacterLine covers name/description and outfit', () => {
|
||||
assert.equal(formatCharacterLine({ name: 'Ada', description: 'tall' }), 'Ada: tall')
|
||||
test('formatCharacterLine copies base and outfit, never name', () => {
|
||||
assert.equal(formatCharacterLine({ name: 'Ada', description: 'tall' }), 'tall')
|
||||
assert.equal(
|
||||
formatCharacterLine({ name: 'Ada', description: 'tall' }, { name: 'Work', description: 'blue jacket' }),
|
||||
'Ada: tall. Outfit: blue jacket'
|
||||
'tall. Outfit: blue jacket'
|
||||
)
|
||||
})
|
||||
|
||||
test('stripBangs removes inline ignore spans and cleans commas', () => {
|
||||
assert.equal(stripBangs('young woman, !brown eyes!, linen robe'), 'young woman, linen robe')
|
||||
assert.equal(stripBangs('a, !x!, b'), 'a, b')
|
||||
assert.deepEqual(extractBangPhrases('young woman, !brown eyes!, linen robe'), ['brown eyes'])
|
||||
})
|
||||
|
||||
test('selecting a framing copies only that framing text; labels never appear', () => {
|
||||
const wide = { ...emptyFraming('wide'), id: 'f-wide', text: 'open courtyard at dawn' }
|
||||
const medium = { ...emptyFraming('medium'), id: 'f-med', text: 'courtyard from the arch' }
|
||||
@@ -137,6 +148,7 @@ test('legacy beat-only set still opens as one wide framing', () => {
|
||||
assert.equal(legacy.sets.length, 1)
|
||||
assert.equal(legacy.sets[0].framings.length, 1)
|
||||
assert.equal(legacy.sets[0].framings[0].label, 'wide')
|
||||
assert.equal(legacy.sets[0].framings[0].facing, 'toward')
|
||||
assert.ok(legacy.sets[0].framings[0].text.includes('stone walls'))
|
||||
assert.ok(legacy.sets[0].framings[0].text.includes('first beat'))
|
||||
assert.ok(legacy.sets[0].framings[0].text.includes('second beat'))
|
||||
@@ -166,7 +178,8 @@ test('legacy sequence without sets still assembles', () => {
|
||||
updatedAt: 1
|
||||
})
|
||||
assert.deepEqual(legacy.sets, [])
|
||||
assert.equal(assembleSequenceText(legacy), 'oil\n\nAda: tall\n\nwalk')
|
||||
assert.equal(assembleSequenceText(legacy), 'oil\n\ntall\n\nwalk')
|
||||
assert.ok(!assembleSequenceText(legacy).includes('Ada'))
|
||||
})
|
||||
|
||||
test('cloneSceneForNext copies setStates including framingId', () => {
|
||||
@@ -195,7 +208,8 @@ test('character outfit and off still work with sets', () => {
|
||||
characterStates: [{ characterId: 'c1', on: true, outfitId: 'o1' }],
|
||||
prompt: 'hi'
|
||||
}, [ada], [])
|
||||
assert.equal(text, 'Ada: tall. Outfit: red dress\n\nhi')
|
||||
assert.equal(text, 'tall. Outfit: red dress\n\nhi')
|
||||
assert.ok(!text.includes('Ada'))
|
||||
})
|
||||
|
||||
test('ensureSceneStatesForCharacters turns new character on only for current scene', () => {
|
||||
@@ -230,7 +244,7 @@ test('sectionOrder settings then prompt then characters; empty style and set omi
|
||||
}
|
||||
const order = ['settings', 'prompt', 'characters']
|
||||
const text = assembleSceneText(scene, [ada], [set], order)
|
||||
assert.equal(text, 'soft light\n\nlooks up\n\nAda: tall')
|
||||
assert.equal(text, 'soft light\n\nlooks up\n\ntall')
|
||||
assert.ok(!text.includes('open yard'))
|
||||
assert.ok(!text.includes('Courtyard'))
|
||||
assert.ok(!text.includes('wide'))
|
||||
@@ -281,8 +295,117 @@ test('legacy sequence without sectionOrder keeps default order and \\n\\n\\n joi
|
||||
const full = assembleSequenceText(legacy)
|
||||
assert.equal(
|
||||
full,
|
||||
'oil\n\nday\n\nstone hall\n\nAda: tall\n\nwalk\n\n\nink\n\nAda: tall\n\nstop'
|
||||
'oil\n\nday\n\nstone hall\n\ntall\n\nwalk\n\n\nink\n\ntall\n\nstop'
|
||||
)
|
||||
assert.ok(!full.includes('Hall'))
|
||||
assert.ok(!full.includes('wide'))
|
||||
assert.ok(!full.includes('Ada'))
|
||||
})
|
||||
|
||||
test('bang strip applies to set framing and character text before join', () => {
|
||||
const eyes = {
|
||||
...emptyFeature('eyes'),
|
||||
id: 'feat-eyes',
|
||||
text: '!brown eyes!',
|
||||
enabled: true,
|
||||
visibility: defaultVisibilityForGroup('eyes')
|
||||
}
|
||||
const ada = {
|
||||
...emptyCharacter(),
|
||||
id: 'c1',
|
||||
name: 'Ada',
|
||||
description: 'young woman, !scar!, linen robe',
|
||||
features: [eyes]
|
||||
}
|
||||
const set = {
|
||||
...emptySet(),
|
||||
id: 's1',
|
||||
name: 'Yard',
|
||||
framings: [{
|
||||
...emptyFraming('wide'),
|
||||
id: 'f1',
|
||||
text: 'courtyard, !prop note!, dusk',
|
||||
facing: 'toward'
|
||||
}]
|
||||
}
|
||||
const text = assembleSceneText({
|
||||
style: '',
|
||||
settings: '',
|
||||
setStates: [{ setId: 's1', on: true, framingId: 'f1' }],
|
||||
characterStates: [{ characterId: 'c1', on: true, outfitId: null }],
|
||||
prompt: ''
|
||||
}, [ada], [set])
|
||||
assert.equal(text, 'courtyard, dusk\n\nyoung woman, linen robe')
|
||||
assert.ok(!text.includes('brown eyes'))
|
||||
assert.ok(!text.includes('scar'))
|
||||
assert.ok(!text.includes('prop note'))
|
||||
assert.ok(!text.includes('!'))
|
||||
assert.ok(!text.includes('Ada'))
|
||||
assert.ok(!text.includes('Yard'))
|
||||
})
|
||||
|
||||
test('facing away drops eyes; feature stays omitted with camera reason; out emits no character', () => {
|
||||
const eyes = {
|
||||
...emptyFeature('eyes'),
|
||||
id: 'feat-eyes',
|
||||
text: 'brown eyes',
|
||||
enabled: true,
|
||||
visibility: defaultVisibilityForGroup('eyes')
|
||||
}
|
||||
const hairBack = {
|
||||
...emptyFeature('hair back'),
|
||||
id: 'feat-hair',
|
||||
text: 'long braid',
|
||||
enabled: true,
|
||||
visibility: defaultVisibilityForGroup('hair back')
|
||||
}
|
||||
const clothing = {
|
||||
...emptyFeature('clothing'),
|
||||
id: 'feat-clothes',
|
||||
text: 'linen robe',
|
||||
enabled: true,
|
||||
visibility: defaultVisibilityForGroup('clothing')
|
||||
}
|
||||
const ada = {
|
||||
...emptyCharacter(),
|
||||
id: 'c1',
|
||||
name: 'Ada',
|
||||
description: 'young woman',
|
||||
features: [eyes, hairBack, clothing]
|
||||
}
|
||||
|
||||
const away = compileCharacterForFacing(ada, 'away')
|
||||
assert.equal(away.text, 'young woman, long braid, linen robe')
|
||||
assert.equal(away.omittedFeatures.length, 1)
|
||||
assert.equal(away.omittedFeatures[0].text, 'brown eyes')
|
||||
assert.equal(away.omittedFeatures[0].reason, 'camera')
|
||||
|
||||
const toward = compileCharacterForFacing(ada, 'toward')
|
||||
assert.equal(toward.text, 'young woman, brown eyes, linen robe')
|
||||
assert.ok(toward.omittedFeatures.some(item => item.text === 'long braid'))
|
||||
|
||||
const hands = compileCharacterForFacing(ada, 'hands')
|
||||
assert.equal(hands.text, 'young woman, linen robe')
|
||||
assert.ok(hands.omittedFeatures.some(item => item.text === 'brown eyes'))
|
||||
|
||||
const out = compileCharacterForFacing(ada, 'out')
|
||||
assert.equal(out.text, '')
|
||||
assert.equal(out.omittedFeatures.length, 3)
|
||||
|
||||
const set = {
|
||||
...emptySet(),
|
||||
id: 's1',
|
||||
name: 'Hall',
|
||||
framings: [{ ...emptyFraming('away'), id: 'f-away', text: 'stone hall', facing: 'away' }]
|
||||
}
|
||||
const sceneText = assembleSceneText({
|
||||
style: '',
|
||||
settings: '',
|
||||
setStates: [{ setId: 's1', on: true, framingId: 'f-away' }],
|
||||
characterStates: [{ characterId: 'c1', on: true, outfitId: null }],
|
||||
prompt: 'walks'
|
||||
}, [ada], [set])
|
||||
assert.equal(sceneText, 'stone hall\n\nyoung woman, long braid, linen robe\n\nwalks')
|
||||
assert.ok(!sceneText.includes('brown eyes'))
|
||||
assert.ok(!sceneText.includes('Hall'))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user