Repository navigation
Open
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Description
Summary
src/lib/utils/slots.ts is supposed to apply "the same rules the server enforces". It doesn't, in two ways:
- Slot names. The UI accepts only
[a-zA-Z_][a-zA-Z0-9_]*. The server and promptctl use\{(\w+)\}, so{2}and{1st}are slots to the server. The UI considers such a template valid, butdetectSlotsdoesn't report them, so they aren't declared and the server rejects the publish. - Stray
}. The server rejects a closing brace that has no matching opener. The UI never checks for one.
Impact
The editor and new-prompt form show a template as valid, enable Save, and then fail on publish with a server error the author didn't expect. Combined with the stuck commit dialog bug, this leaves the editor unusable until a reload. The viewer's slot highlighting also disagrees with the server about what counts as a slot.
Steps to reproduce
From a fresh clone (Node 24):
git clone https://github.com/priompt/ui && cd ui && pnpm install
node -e '
import("./src/lib/utils/slots.ts").then(({ validateTemplate, detectSlots }) => {
console.log(validateTemplate("Answer in {2} sentences."), detectSlots("Answer in {2} sentences."));
console.log(validateTemplate("Hello {name} }"));
});'Actual:
null []
null
The server rejects both. The first fails with invalid prompt: template uses undeclared slots: 2. The second fails with invalid prompt: template has an unmatched "}" near " {name} }".
Expected behavior
validateTemplate and detectSlots agree with priompt/proto validate.Template:
{2}and{1st}are detected as slots, so they get declared on publish.- A stray
}makesvalidateTemplatereturn an error. - The viewer highlights the same placeholders the server recognises.
Where to look
src/lib/utils/slots.ts#L11:SLOT_REGEX = /\{([a-zA-Z_][a-zA-Z0-9_]*)\}/gsrc/lib/utils/slots.ts#L37-L59:validateTemplatescans for unclosed{but not unmatched}. The doubled-brace check also uses the narrower name pattern.src/lib/components/prompt/PromptViewer.svelte#L8: a third copy of the narrow pattern, used for highlighting.- priompt/proto
validate/validate.go#L17:placeholderRe = \{(\w+)\}, where Go's\wis ASCII[0-9A-Za-z_]. - priompt/proto
validate/validate.go#L137-L176:braces(), including the unmatched-}scan at L155-L167.
Suggested approach
- Change
SLOT_REGEXto/\{([A-Za-z0-9_]+)\}/g. Spell it out as ASCII rather than relying on\w. - Export the regex, or a
isSlotCharhelper, and reuse it inPromptViewer.svelteand in the doubled-brace check, so there is one definition. - Port the second loop of
braces(): for each}, walk back over slot characters. If the walk doesn't end on a{, or ends immediately, returnUnmatched "}" near "…".
Getting started
pnpm install, thenpnpm test(Node's built-in test runner with type stripping; use Node 24).- Existing tests live in
src/lib/utils/slots.test.ts. Add cases there. - The whole fix is in
src/lib/utils/slots.ts, plus a one-line change inPromptViewer.svelte.
Acceptance criteria
-
detectSlots("Answer in {2} sentences.")returns["2"], anddetectSlots("Hello {name} {1st}")returns["name", "1st"]. -
validateTemplate("Hello {name} }")andvalidateTemplate("a } b")return an error, andvalidateTemplate("Hi {name}")still returnsnull. - New tests in
slots.test.tsmirror thebraces()cases in validate.go. They fail on the current code and pass after the fix. -
PromptViewerhighlights{2}.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Activity
sujal-maheshwari2004 commentedon Nov 15, 2026
Update: since priompt/proto#19 (proto v0.7.3, now used by the server and promptctl),
{{and}}are literal braces, exactly as in Python'sstr.format. So the client rule to port is no longer the plain\{(\w+)\}regexp:{name}is a slot (ASCII letters, digits, underscore; may start with a digit){{and}}are a literal{and}, never part of a slot.{{name}}is the text{name}, and{{{name}}}is a literal brace, slotname, literal brace.{or}is an error (unclosed, empty, or an unmatched})The reference implementation is
scanin priompt/protovalidate/validate.go, and the test cases to mirror areTestLiteralBracesandTestBraceTyposinvalidate/validate_test.go.