Skip to content

Client slot validation disagrees with server ({2} and stray "}" pass locally) #29

Open

Description

@sujal-maheshwari2004

Summary

src/lib/utils/slots.ts is supposed to apply "the same rules the server enforces". It doesn't, in two ways:

  1. 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, but detectSlots doesn't report them, so they aren't declared and the server rejects the publish.
  2. 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 } makes validateTemplate return an error.
  • The viewer highlights the same placeholders the server recognises.

Where to look

Suggested approach

  • Change SLOT_REGEX to /\{([A-Za-z0-9_]+)\}/g. Spell it out as ASCII rather than relying on \w.
  • Export the regex, or a isSlotChar helper, and reuse it in PromptViewer.svelte and 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, return Unmatched "}" near "…".

Getting started

  • pnpm install, then pnpm 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 in PromptViewer.svelte.

Acceptance criteria

  • detectSlots("Answer in {2} sentences.") returns ["2"], and detectSlots("Hello {name} {1st}") returns ["name", "1st"].
  • validateTemplate("Hello {name} }") and validateTemplate("a } b") return an error, and validateTemplate("Hi {name}") still returns null.
  • New tests in slots.test.ts mirror the braces() cases in validate.go. They fail on the current code and pass after the fix.
  • PromptViewer highlights {2}.

Activity

  1. sujal-maheshwari2004 commented on Nov 15, 2026

    @sujal-maheshwari2004
    MemberAuthor

    Update: since priompt/proto#19 (proto v0.7.3, now used by the server and promptctl), {{ and }} are literal braces, exactly as in Python's str.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, slot name, literal brace.
    • any other { or } is an error (unclosed, empty, or an unmatched })

    The reference implementation is scan in priompt/proto validate/validate.go, and the test cases to mirror are TestLiteralBraces and TestBraceTypos in validate/validate_test.go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions