Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

feat(compression): add SHARED_BOUNDARIES to caveman output mode prompts

diegosouzapwaf80efe75a53
diff --git a/open-sse/services/compression/outputMode.ts b/open-sse/services/compression/outputMode.ts
index 10b4ae1d47..b90bf84d1a 100644
--- a/open-sse/services/compression/outputMode.ts
+++ b/open-sse/services/compression/outputMode.ts
@@ -19,42 +19,45 @@ export interface CavemanOutputModeResult {
skippedReason?: string;
}
+/**
+ * Shared boundary clause — appended to every intensity level.
+ * Tells the model which contexts warrant a temporary return to normal style,
+ * matching the caveman skill's SHARED_BOUNDARIES contract
+ * (https://github.com/JuliusBrussee/caveman).
+ */
+export const SHARED_BOUNDARIES =
+ "Code blocks, file paths, commands, errors, URLs: keep exact. Security warnings, irreversible action confirmations, multi-step ordered sequences: write normal. Resume terse style after. Active every response until user asks for normal mode.";
+
const CAVEMAN_INSTRUCTION_BY_LANGUAGE = {
en: {
- lite: "Respond concise. Drop filler, pleasantries, hedging. Keep full sentences, technical terms, code, errors, URLs, and identifiers exact.",
- full: "Respond terse like smart caveman. Drop articles, filler, pleasantries, hedging. Fragments OK. Keep all technical substance, code, errors, URLs, identifiers exact.",
- ultra:
- "Respond ultra terse. Use short technical prose, arrows for causality, common abbreviations like DB/auth/config/req/res/fn. Never abbreviate code symbols, API names, error strings, URLs, or identifiers.",
+ lite: `Respond concise. Drop filler, pleasantries, hedging. Keep full sentences, technical terms, code, errors, URLs, and identifiers exact. ${SHARED_BOUNDARIES}`,
+ full: `Respond terse like smart caveman. Drop articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries, hedging. Fragments OK. Short synonyms (big not extensive, fix not implement). Keep all technical substance, code, errors, URLs, identifiers exact. ${SHARED_BOUNDARIES}`,
+ ultra: `Respond ultra terse. Maximum compression. Telegraphic. Abbreviate (DB/auth/config/req/res/fn/impl), strip conjunctions, arrows for causality (X → Y). One word when one word enough. Never abbreviate code symbols, API names, error strings, URLs, or identifiers. ${SHARED_BOUNDARIES}`,
},
"pt-BR": {
- lite: "Responda conciso. Remova enrolacao, cortesias e incerteza. Preserve termos tecnicos, codigo, erros, URLs e identificadores exatamente.",
- full: "Responda seco e compacto. Frases curtas OK. Preserve todo conteudo tecnico, codigo, erros, URLs e identificadores exatamente.",
- ultra:
- "Responda ultra compacto. Use prosa tecnica curta e abreviacoes comuns como DB/auth/config/req/res/fn. Nunca abrevie simbolos de codigo, APIs, erros, URLs ou identificadores.",
+ lite: `Responda conciso. Remova enrolacao, cortesias e incerteza. Preserve termos tecnicos, codigo, erros, URLs e identificadores exatamente. ${SHARED_BOUNDARIES}`,
+ full: `Responda seco e compacto. Frases curtas OK. Preserve todo conteudo tecnico, codigo, erros, URLs e identificadores exatamente. ${SHARED_BOUNDARIES}`,
+ ultra: `Responda ultra compacto. Use prosa tecnica curta e abreviacoes comuns como DB/auth/config/req/res/fn. Nunca abrevie simbolos de codigo, APIs, erros, URLs ou identificadores. ${SHARED_BOUNDARIES}`,
},
es: {
- lite: "Responde conciso. Quita relleno, cortesias y dudas. Conserva terminos tecnicos, codigo, errores, URLs e identificadores exactos.",
- full: "Responde seco y compacto. Fragmentos OK. Conserva todo el contenido tecnico, codigo, errores, URLs e identificadores exactos.",
- ultra:
- "Responde ultra compacto. Usa prosa tecnica corta y abreviaturas comunes como DB/auth/config/req/res/fn. Nunca abrevies simbolos de codigo, APIs, errores, URLs o identificadores.",
+ lite: `Responde conciso. Quita relleno, cortesias y dudas. Conserva terminos tecnicos, codigo, errores, URLs e identificadores exactos. ${SHARED_BOUNDARIES}`,
+ full: `Responde seco y compacto. Fragmentos OK. Conserva todo el contenido tecnico, codigo, errores, URLs e identificadores exactos. ${SHARED_BOUNDARIES}`,
+ ultra: `Responde ultra compacto. Usa prosa tecnica corta y abreviaturas comunes como DB/auth/config/req/res/fn. Nunca abrevies simbolos de codigo, APIs, errores, URLs o identificadores. ${SHARED_BOUNDARIES}`,
},
de: {
- lite: "Antworte knapp. Entferne Fuellwoerter, Hoeflichkeit und Unsicherheit. Bewahre Fachbegriffe, Code, Fehler, URLs und Bezeichner exakt.",
- full: "Antworte sehr knapp. Fragmente OK. Bewahre alle technischen Inhalte, Code, Fehler, URLs und Bezeichner exakt.",
- ultra:
- "Antworte ultra knapp. Nutze kurze technische Prosa und uebliche Abkuerzungen wie DB/auth/config/req/res/fn. Code-Symbole, APIs, Fehler, URLs und Bezeichner nie abkuerzen.",
+ lite: `Antworte knapp. Entferne Fuellwoerter, Hoeflichkeit und Unsicherheit. Bewahre Fachbegriffe, Code, Fehler, URLs und Bezeichner exakt. ${SHARED_BOUNDARIES}`,
+ full: `Antworte sehr knapp. Fragmente OK. Bewahre alle technischen Inhalte, Code, Fehler, URLs und Bezeichner exakt. ${SHARED_BOUNDARIES}`,
+ ultra: `Antworte ultra knapp. Nutze kurze technische Prosa und uebliche Abkuerzungen wie DB/auth/config/req/res/fn. Code-Symbole, APIs, Fehler, URLs und Bezeichner nie abkuerzen. ${SHARED_BOUNDARIES}`,
},
fr: {
- lite: "Reponds concis. Retire remplissage, politesses et hesitations. Garde termes techniques, code, erreurs, URLs et identifiants exacts.",
- full: "Reponds tres compact. Fragments OK. Garde tout le contenu technique, code, erreurs, URLs et identifiants exacts.",
- ultra:
- "Reponds ultra compact. Utilise une prose technique courte et des abreviations communes comme DB/auth/config/req/res/fn. N'abrege jamais symboles de code, APIs, erreurs, URLs ou identifiants.",
+ lite: `Reponds concis. Retire remplissage, politesses et hesitations. Garde termes techniques, code, erreurs, URLs et identifiants exacts. ${SHARED_BOUNDARIES}`,
+ full: `Reponds tres compact. Fragments OK. Garde tout le contenu technique, code, erreurs, URLs et identifiants exacts. ${SHARED_BOUNDARIES}`,
+ ultra: `Reponds ultra compact. Utilise une prose technique courte et des abreviations communes comme DB/auth/config/req/res/fn. N'abrege jamais symboles de code, APIs, erreurs, URLs ou identifiants. ${SHARED_BOUNDARIES}`,
},
ja: {
- lite: "簡潔に回答。冗長表現、挨拶、曖昧表現を削る。技術用語、コード、エラー、URL、識別子は正確に保持。",
- full: "短く圧縮して回答。断片文可。技術内容、コード、エラー、URL、識別子は正確に保持。",
- ultra:
- "超短く回答。DB/auth/config/req/res/fn など一般的な略語は可。コード記号、API名、エラー文字列、URL、識別子は省略しない。",
+ lite: `簡潔に回答。冗長表現、挨拶、曖昧表現を削る。技術用語、コード、エラー、URL、識別子は正確に保持。${SHARED_BOUNDARIES}`,
+ full: `短く圧縮して回答。断片文可。技術内容、コード、エラー、URL、識別子は正確に保持。${SHARED_BOUNDARIES}`,
+ ultra: `超短く回答。DB/auth/config/req/res/fn など一般的な略語は可。コード記号、API名、エラー文字列、URL、識別子は省略しない。${SHARED_BOUNDARIES}`,
},
} as const;
@@ -135,11 +138,8 @@ export function applyCavemanOutputMode(
return { body, applied: false, skippedReason: "no_messages" };
}
- if (config.autoClarity !== false) {
- const bypass = shouldBypassCavemanOutputMode(messages);
- if (bypass) return { body, applied: false, skippedReason: bypass };
- }
-
+ // Check idempotency before bypass so the marker in an already-injected system
+ // message doesn't trigger a false-positive bypass (e.g. SHARED_BOUNDARIES keywords).
const alreadyApplied = messages.some(
(message) =>
message.role === "system" &&
@@ -148,6 +148,11 @@ export function applyCavemanOutputMode(
);
if (alreadyApplied) return { body, applied: false, skippedReason: "already_applied" };
+ if (config.autoClarity !== false) {
+ const bypass = shouldBypassCavemanOutputMode(messages);
+ if (bypass) return { body, applied: false, skippedReason: bypass };
+ }
+
const instruction = buildCavemanOutputInstruction(config, language);
const nextMessages = [...messages];
const first = nextMessages[0];
diff --git a/tests/unit/compression/cavemanSharedBoundaries.test.ts b/tests/unit/compression/cavemanSharedBoundaries.test.ts
new file mode 100644
index 0000000000..a794f6be28
--- /dev/null
+++ b/tests/unit/compression/cavemanSharedBoundaries.test.ts
@@ -0,0 +1,44 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import {
+ SHARED_BOUNDARIES,
+ buildCavemanOutputInstruction,
+} from "../../../open-sse/services/compression/outputMode.ts";
+
+test("SHARED_BOUNDARIES is exported and non-empty string", () => {
+ assert.equal(typeof SHARED_BOUNDARIES, "string");
+ assert.ok(SHARED_BOUNDARIES.length > 0);
+});
+
+test("SHARED_BOUNDARIES instructs model to write normal for security warnings", () => {
+ assert.match(SHARED_BOUNDARIES, /security/i);
+ assert.match(SHARED_BOUNDARIES, /normal/i);
+});
+
+test("SHARED_BOUNDARIES instructs model to resume terse style after", () => {
+ assert.match(SHARED_BOUNDARIES, /resume/i);
+});
+
+test("SHARED_BOUNDARIES covers irreversible actions", () => {
+ assert.match(SHARED_BOUNDARIES, /irreversible/i);
+});
+
+test("SHARED_BOUNDARIES covers multi-step ordered sequences", () => {
+ assert.match(SHARED_BOUNDARIES, /sequence|ordered/i);
+});
+
+test("buildCavemanOutputInstruction includes SHARED_BOUNDARIES text", () => {
+ const instruction = buildCavemanOutputInstruction({ enabled: true, intensity: "full" });
+ assert.ok(instruction.includes(SHARED_BOUNDARIES), "instruction must embed SHARED_BOUNDARIES");
+});
+
+test("buildCavemanOutputInstruction includes persistence clause for all intensities", () => {
+ for (const intensity of ["lite", "full", "ultra"] as const) {
+ const instr = buildCavemanOutputInstruction({ enabled: true, intensity });
+ assert.match(
+ instr,
+ /active every response|until user asks/i,
+ `${intensity} must have persistence clause`
+ );
+ }
+});