Repository navigation
Add llmmend/prompt: safePrompt, trusted, escapeTags - #89
Merged
Merged
Conversation
A template tag that escapes each substitution for the tags the template itself uses, so untrusted text can't close or forge the prompt's own sections. Widens the glossary's purpose to both directions (#22). Closes #88 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F61ff7dDPwJn5kuD25LtiS
This was referenced Oct 27, 2026
Merged
nightlightmare
added a commit
that referenced
this pull request
Oct 27, 2026
Releases 0.6.0. ## What ships From `CHANGELOG.md`, three new modules, all **minor**: - `llmmend/prompt`: `safePrompt`, `trusted`, `escapeTags`: untrusted text can't close or forge a prompt's own tags (#89). - `llmmend/cost`: `estimateCost`, `toUsage`: the cost of a call by part from its usage and prices per million tokens (#91). - `llmmend/retry`: `classifyError`: eleven provider-neutral error kinds, `retryable` and the Provider's `retryAfter` (#94). One **patch**: stream `usage` events leave out a count the Provider sent as `null`; the four adapters now share one usage conversion with `toUsage` (#91). Added to the changelog by hand, since #91's changeset described only the new module. The playground's Prompt, Cost and Errors tabs (#92, #94) are already live on Pages. ## Before release - **Provider adapters** changed in #91 (the shared usage conversion), so the providers were re-recorded and compared with the fixtures, then restored: - **Anthropic** (via Bedrock), all seven cases: same payload fields, LLM event types, usage fields, stop reasons; `responseId` set in all. - **Gemini**: `text`, `thinking`, `max-tokens` the same on every count. `tool-calls-parallel` got HTTP 503 `UNAVAILABLE` (high demand), which `classifyError` reads as `overloaded`, retryable. - **Drift:** the Ollama drift check passes on main at f3af34c, after the adapter change ([run](https://github.com/nightlightmare/llmmend/actions/runs/40589829344)). - **Size:** within limits. `prompt` 582 B, `cost` 689 B, `retry` 1.39 of 1.5 kB; the existing bundles did not grow (`collectText` 6.78 kB, `streamToolCalls` 6.92 kB). - **Local checks:** tests (911), docs, size, smoke on all seven subpaths, and `check:publish` pass. CI on main is green at f3af34c. ## After merge `release.yml` stages 0.6.0 with `npm stage publish` and creates the tag and GitHub release; approve the staged version on npmjs.com with 2FA. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01F61ff7dDPwJn5kuD25LtiS Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
llmmend/prompt, re-exported from the root; smoke checks (Node, Bun, Deno, Workers) and the WebKit suite cover it.GLOSSARY.md: the purpose widens to text at the LLM boundary in both directions (Stage 3: new modules (prompt, messages, cost, retry) #22), with Prompt, Own tag and Escaping.docs/api.mdsection; all in three languages.llms.txtregenerated.One deliberate widening of the issue's "recognition =
extractTag's": a tag cut off before its>(</documentat the end of a substitution) is escaped too.extractTagwouldn't read it as a tag, but a model might, and escaping it costs nothing. So everythingextractTagrecognises is escaped, plus that. The regex isn't shared withsrc/json/tags.tsfor the same reason: matching a name prefix is simpler than matching a whole tag.Evidence
Property test: for any text built from
<,>,/,document,DOCUMENT,notes, whitespace and quotes,extractAllTagsonsafePrompt`<document>${a}</document><notes>${b}</notes>`finds exactlydocumentthennotes: no substitution can close or open either.Before: no way in llmmend to build a prompt from untrusted text.
After: 15 new tests (Node and WebKit); 863 tests, docs, smoke, publint and attw pass;
llmmend/promptis 582 B of its 1 kB limit.Merge Danger
Door: two-way
Blast Radius: new subpath
Additive: a new export path and three root exports with names unused so far. Once released, the escaping rules are public behaviour; widening them later (e.g.
escape: 'all', deferred) would be an option, not a change.Closes #88
🤖 Generated with Claude Code
https://claude.ai/code/session_01F61ff7dDPwJn5kuD25LtiS