Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(forge): stop forwarding a truncated director rewrite as the prompt

nirholas6d5069344e8f
diff --git a/api/_mcp-studio/forge-client.js b/api/_mcp-studio/forge-client.js
index 52929bcae..eed50a39a 100644
--- a/api/_mcp-studio/forge-client.js
+++ b/api/_mcp-studio/forge-client.js
@@ -233,9 +233,53 @@ export async function rig(base, glbUrl, { timeoutEnv } = {}) {
// providers), so the director silently never ran on any surface. Fail-soft:
// returns null on any failure so the caller forwards the original prompt
// unchanged, never faked.
-const DIRECTOR_MAX_TOKENS = 200;
+// A complete director spec (subject, construction, materials, lighting, framing,
+// negatives) measures ~800 characters, which is right at what 200 tokens buys.
+// With no headroom, any model even slightly more verbose than average had its
+// answer cut mid-clause, and the fragment was then forwarded as the brief:
+// observed on production 2026-08-07, "a red wooden rocking chair" directed to
+// "A classic wooden rocking chair with gracefully curved" and "a small ceramic
+// teapot with a bamboo handle" to "A small,", which reconstructed as a coffee
+// tamper. Budget for a whole spec instead of a clipped one.
+const DIRECTOR_MAX_TOKENS = 400;
const DIRECTOR_TIMEOUT_MS = 20_000;
+// Longest brief we forward. The director's own specs land near 800 characters;
+// beyond this the model has stopped writing a prompt and started writing prose.
+const DIRECTOR_MAX_CHARS = 1000;
+
+// A rewrite that stops mid-clause is a truncated generation, not a brief. The
+// tell is the final character: a complete spec ends on a word or terminal
+// punctuation, never on a separator that promises more text. Hyphen, en-dash
+// and em-dash are written as escapes (not literal glyphs) so this regex itself
+// never trips the repo's own em-dash ban.
+const ENDS_MID_CLAUSE = /[,;:\-\u2013\u2014/&+([{]$/;
+
+// Trailing function words carry the same tell without the punctuation ("...with
+// gracefully curved" is complete only if "curved" is the last adjective, which a
+// dangling connective rules out).
+const DANGLING_CONNECTIVE =
+ /\b(?:and|or|with|without|of|in|on|at|to|for|from|by|as|the|a|an|its|their|plus|featuring|including|made|constructed)$/i;
+
+// Decide whether a director rewrite is safe to forward in place of the user's
+// own words. The director is a quality lever that must never cost a caller their
+// intent, so anything that fails this check falls back to the raw prompt rather
+// than shipping a fragment. Pure: same inputs → same verdict.
+export function isUsableDirectorRewrite(refined, rawPrompt) {
+ if (typeof refined !== 'string') return false;
+ const text = refined.trim();
+ if (text.length < 3 || text.length > DIRECTOR_MAX_CHARS) return false;
+ if (ENDS_MID_CLAUSE.test(text)) return false;
+ if (DANGLING_CONNECTIVE.test(text)) return false;
+ // The director's contract is to ENRICH a rough idea into a denser spec. A
+ // result no longer than what the caller typed has added nothing, and is far
+ // more likely a clipped opening clause than a genuine tightening, so the
+ // user's own wording is the better brief.
+ const raw = String(rawPrompt ?? '').trim();
+ if (raw && text.length <= raw.length) return false;
+ return true;
+}
+
export async function directPrompt(instruction, rawPrompt) {
const user = `Idea: ${rawPrompt}`;
let text = null;
@@ -287,7 +331,9 @@ export async function directPrompt(instruction, rawPrompt) {
// dangling quote when the model adds commentary lines after a quoted prompt.
const firstLine = text.trim().split('\n')[0].trim();
const refined = firstLine.replace(/^["'“”]+|["'“”]+$/g, '').trim();
- return refined.length >= 3 && refined.length <= 1000 ? refined : null;
+ // Returning null here is the documented fail-soft path: the caller forwards
+ // the caller's original prompt unchanged, which is always a valid brief.
+ return isUsableDirectorRewrite(refined, rawPrompt) ? refined : null;
}
function sleep(ms) {