@koda-sl/baker-bridge 0.122.0-dev.fb98ea199 → 0.123.0-dev.e59c50e4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +28 -13
  2. package/dist/hono/avatar-accent.d.ts +17 -5
  3. package/dist/hono/avatar-accent.d.ts.map +1 -1
  4. package/dist/hono/avatar-accent.js +31 -64
  5. package/dist/hono/avatar-accent.js.map +1 -1
  6. package/dist/hono/avatar-accent.test.js +46 -35
  7. package/dist/hono/avatar-accent.test.js.map +1 -1
  8. package/dist/hono/avatar-face-question.d.ts +23 -6
  9. package/dist/hono/avatar-face-question.d.ts.map +1 -1
  10. package/dist/hono/avatar-face-question.js +48 -59
  11. package/dist/hono/avatar-face-question.js.map +1 -1
  12. package/dist/hono/avatar-face-question.test.js +46 -101
  13. package/dist/hono/avatar-face-question.test.js.map +1 -1
  14. package/dist/hono/bridge-job.d.ts +4 -0
  15. package/dist/hono/bridge-job.d.ts.map +1 -1
  16. package/dist/hono/bridge-job.js +9 -6
  17. package/dist/hono/bridge-job.js.map +1 -1
  18. package/dist/hono/bridge-job.test.js +7 -1
  19. package/dist/hono/bridge-job.test.js.map +1 -1
  20. package/dist/hono/jev.d.ts +16 -0
  21. package/dist/hono/jev.d.ts.map +1 -0
  22. package/dist/hono/jev.js +60 -0
  23. package/dist/hono/jev.js.map +1 -0
  24. package/dist/hono/jev.test.d.ts +2 -0
  25. package/dist/hono/jev.test.d.ts.map +1 -0
  26. package/dist/hono/jev.test.js +15 -0
  27. package/dist/hono/jev.test.js.map +1 -0
  28. package/dist/hono/openrouter-session.d.ts.map +1 -1
  29. package/dist/hono/openrouter-session.js +12 -1
  30. package/dist/hono/openrouter-session.js.map +1 -1
  31. package/dist/hono/openrouter-session.test.js +9 -3
  32. package/dist/hono/openrouter-session.test.js.map +1 -1
  33. package/dist/review/digest.d.ts +8 -1
  34. package/dist/review/digest.d.ts.map +1 -1
  35. package/dist/review/digest.js +10 -43
  36. package/dist/review/digest.js.map +1 -1
  37. package/dist/review/digest.test.js +11 -6
  38. package/dist/review/digest.test.js.map +1 -1
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -43,6 +43,7 @@ await server.start();
43
43
  | `INTERNAL_SECRET_KEY` | AES key for encrypting flow `_data.json` config at rest |
44
44
  | `ANTHROPIC_API_KEY` | Anthropic API key (required by the Agent SDK) |
45
45
  | `ANTHROPIC_BASE_URL` / `ANTHROPIC_AUTH_TOKEN` | OpenRouter routing (base URL + per-org key) injected into the sandbox. Forwarded to the Agent SDK subprocess so the agent can reach its model |
46
+ | `OPENROUTER_API_KEY` | The same per-org key under its own name. The bridge reads the user's and the agent's words with it before letting two kinds of call through: a question asking the user to pick an avatar's face (the casting picker shows real portraits), and an avatar accent in a language nobody asked for. Unset or unreachable, both calls go through unchecked |
46
47
  | `CLAUDE_CODE_EXTRA_BODY` | Optional JSON merged by the CLI into every model request body. The bridge sets/extends it per turn with a per-thread `session_id` so OpenRouter sticky-routes the whole conversation to one provider instance and its instance-scoped prompt cache is re-read across the turn's many tool-call requests (see [Prompt-cache pinning](#prompt-cache-pinning)). It also defaults `provider` to Bedrock first (see [Bedrock is the preferred provider](#bedrock-is-the-preferred-provider)). Any inherited value is merged; our `session_id` and the `web`-plugin opt-out win (see [OpenRouter web plugin is forced off](#openrouter-web-plugin-is-forced-off)). An inherited `provider` replaces the Bedrock default |
47
48
  | `BAKER_CHAT_ID` | Present only when running inside a chat sandbox. When set, the bridge relocates Claude Code auto-memory into the cloned repo (`.claude/memory`) — see [Session journal](#session-journal-agent-memory) |
48
49
  | `BAKER_ACTING_USER_ID` | Injected into the Agent SDK subprocess env per turn (when the turn's sender is known) so in-sandbox `baker` CLI calls can scope work to the acting user — e.g. `baker mcp add --scope user` |
@@ -205,23 +206,37 @@ cache stays warm while the Bedrock default is set.
205
206
 
206
207
  ## Bedrock is the preferred provider
207
208
 
208
- The same `CLAUDE_CODE_EXTRA_BODY` value carries
209
- `provider: { order: ["amazon-bedrock"], allow_fallbacks: true }`. Without it,
210
- OpenRouter load-balances Claude across Anthropic, Vertex, Azure and Bedrock by
211
- price and uptime, and the `session_id` pin then holds the conversation on whichever
212
- it picked first. With it, every request goes to Bedrock first and only moves to
213
- another provider when Bedrock is down or rate-limited. An inherited `provider`
214
- (set in the sandbox's `CLAUDE_CODE_EXTRA_BODY`) replaces this default as an
215
- operator override.
209
+ The same `CLAUDE_CODE_EXTRA_BODY` value carries a `provider` with
210
+ `allow_fallbacks: true` and this `order`:
211
+
212
+ ```json
213
+ ["amazon-bedrock", "amazon-bedrock/eu-west-1", "amazon-bedrock/us-east-1"]
214
+ ```
215
+
216
+ Without it, OpenRouter load-balances Claude across Anthropic, Vertex, Azure and
217
+ Bedrock by price and uptime, and the `session_id` pin then holds the conversation
218
+ on whichever it picked first. With it, every request goes to Bedrock first, then
219
+ to the two regional Bedrock endpoints, and only moves to another provider when all
220
+ three fail. The regions are there because Bedrock's failure mode is AWS capacity,
221
+ not our quota: on weekday mornings the default endpoint answers `503` to most Opus
222
+ 5.5 requests for hours, and AWS's advice for a `503` is another region. All three
223
+ run on our own Bedrock key; the providers after them bill OpenRouter credits. An
224
+ inherited `provider` (set in the sandbox's `CLAUDE_CODE_EXTRA_BODY`) replaces this
225
+ default as an operator override.
216
226
 
217
227
  A manual `order` bypasses OpenRouter's sticky routing, so while it is set the
218
228
  `session_id` pin above is inert and the `order` is what keeps the cache warm. The
219
229
  bare `amazon-bedrock` slug is a single endpoint (regional endpoints are separate
220
- slugs), so every request lands on the same one; measured, consecutive requests
221
- read the whole cached prefix back. The cost is on fallback: each request retries
222
- Bedrock first, so a cache warmed on the fallback provider is not reused while
223
- Bedrock is flapping. The `session_id` pin still applies whenever an inherited
224
- `provider` drops the `order`.
230
+ slugs), so while it is healthy every request lands on the same one; measured,
231
+ consecutive requests read the whole cached prefix back. The cost is on fallback.
232
+ Each endpoint keeps its own cache, the regional Bedrock ones included, so a
233
+ request that moves to the next endpoint starts cold and pays its whole prefix;
234
+ and each request retries the default endpoint first, so a cache warmed further
235
+ down the `order` is not reused while Bedrock is flapping. During a capacity
236
+ window every request also waits for the default endpoint's `503` (about 7 s)
237
+ before moving on.
238
+ The `session_id` pin still applies whenever an inherited `provider` drops the
239
+ `order`.
225
240
 
226
241
  The preference only holds for a request Bedrock can serve, and OpenRouter drops
227
242
  Bedrock from the route without an error when it can't. From Opus 5.5 the CLI
@@ -13,11 +13,23 @@
13
13
  * own description, in the creation hint and in the family doc by now, so this is the
14
14
  * layer left.
15
15
  *
16
- * Narrow by construction — it only fires when the user is clearly writing Spanish AND
17
- * the accent clearly names another language AND nothing the user said asks for that
18
- * language or market. An ad a Spaniard genuinely wants in English says so, and then
19
- * this stays out of the way.
16
+ * Whether the accent fits is read by Jev from what the user said, in whatever language
17
+ * they write: their own language, a regional accent of it, or a language or market they
18
+ * asked for all fit. A wrong refusal leaves the user nothing to type, so a judge that
19
+ * cannot answer lets the command through.
20
20
  */
21
+ import type { Judge } from "./jev.ts";
22
+ /**
23
+ * Three judgments, each its own Noul in one request: an accent fits when the user writes in
24
+ * its language, or asked for it, or it names no language at all. Asked as one question, a
25
+ * face ("eher südländischer Typ") read as a request for Italian (0.79). Re-run
26
+ * `scripts/avatar-guard-evals` after changing any of them.
27
+ */
28
+ export declare const ACCENT_WRITTEN_IN_QUESTION: string;
29
+ export declare const ACCENT_ASKED_FOR_QUESTION: string;
30
+ export declare const ACCENT_NAMES_LANGUAGE_QUESTION = "Does `accent` name a language, a country or a regional accent?";
31
+ /** Each answer is a yes at or above this. Measured in `scripts/avatar-guard-evals`. */
32
+ export declare const ACCENT_HELD = 0.5;
21
33
  /** The `--accent` value in a `baker avatars create|update` command, if it has one. */
22
34
  export declare function accentFrom(command: string): string | null;
23
35
  /** The refusal, or null when the accent is consistent with what the user asked for. */
@@ -30,5 +42,5 @@ export declare function accentContradictsUser(command: string | undefined, userT
30
42
  * the UK, in English" — and writes the next in Spanish had their own decision refused,
31
43
  * with nothing they could type to get past it short of repeating themselves every time.
32
44
  */
33
- priorUserText?: string): string | null;
45
+ priorUserText: string | undefined, judge: Judge): Promise<string | null>;
34
46
  //# sourceMappingURL=avatar-accent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatar-accent.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAmCH,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIzD;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS;AAC5B;;;;;;;GAOG;AACH,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,GAAG,IAAI,CAkBf"}
1
+ {"version":3,"file":"avatar-accent.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAES,CAAC;AACjD,eAAO,MAAM,yBAAyB,QAG6E,CAAC;AACpH,eAAO,MAAM,8BAA8B,mEAAmE,CAAC;AAC/G,uFAAuF;AACvF,eAAO,MAAM,WAAW,MAAM,CAAC;AAI/B,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIzD;AAED,uFAAuF;AACvF,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS;AAC5B;;;;;;;GAOG;AACH,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB"}
@@ -1,51 +1,19 @@
1
1
  /**
2
- * Refuses an avatar cast to speak a language the user never asked for.
3
- *
4
- * `--accent` decides the LANGUAGE of every clip that avatar appears in, and the agent
5
- * keeps reading it off the person's looks instead of off the conversation. Three runs in
6
- * a row, each from the same Spanish sentence asking for "aspecto europeo" — a face:
7
- *
8
- * --accent "Dutch, neutral European accent"
9
- * --accent "German, clear and authoritative"
10
- * --accent "English from UK, Southern England accent"
11
- *
12
- * The first shipped: a Spanish client's ad, spoken in German. The rule is in the flag's
13
- * own description, in the creation hint and in the family doc by now, so this is the
14
- * layer left.
15
- *
16
- * Narrow by construction — it only fires when the user is clearly writing Spanish AND
17
- * the accent clearly names another language AND nothing the user said asks for that
18
- * language or market. An ad a Spaniard genuinely wants in English says so, and then
19
- * this stays out of the way.
2
+ * Three judgments, each its own Noul in one request: an accent fits when the user writes in
3
+ * its language, or asked for it, or it names no language at all. Asked as one question, a
4
+ * face ("eher südländischer Typ") read as a request for Italian (0.79). Re-run
5
+ * `scripts/avatar-guard-evals` after changing any of them.
20
6
  */
21
- /** Words that are common in Spanish and rare-to-absent in English/German/Dutch. */
22
- const SPANISH_MARKERS = /\b(que|para|con|una?|los|las|del|por|pero|como|cuando|donde|porque|nuestro|nuestra|quiero|hacer|tiene|está|más|también|anuncio|vídeo|video|cliente|empresa)\b/gi;
23
- /** Languages an accent can name, with the words that would justify asking for one. */
24
- const FOREIGN_LANGUAGES = [
25
- {
26
- name: "English",
27
- accent: /\b(english|british|american|uk|usa|australian|irish|scottish)\b/i,
28
- justification: /\b(ingl[ée]s|inglesa|uk|reino unido|brit[áa]nic|estados unidos|usa|americano|irlanda|australia)\b/i,
29
- },
30
- {
31
- name: "German",
32
- accent: /\b(german|austrian|deutsch)\b/i,
33
- justification: /\b(alem[áa]n|alemana|alemania|austria)\b/i,
34
- },
35
- { name: "French", accent: /\b(french|parisian)\b/i, justification: /\b(franc[ée]s|francesa|francia)\b/i },
36
- {
37
- name: "Dutch",
38
- accent: /\b(dutch|netherlands|flemish)\b/i,
39
- justification: /\b(holand[ée]s|neerland[ée]s|pa[íi]ses bajos|holanda|b[ée]lgica)\b/i,
40
- },
41
- { name: "Italian", accent: /\b(italian)\b/i, justification: /\b(italiano|italiana|italia)\b/i },
42
- { name: "Portuguese", accent: /\b(portuguese|brazilian)\b/i, justification: /\b(portugu[ée]s|portugal|brasil)\b/i },
43
- ];
44
- /** Enough Spanish function words that the user is plainly writing Spanish. */
45
- const SPANISH_CONFIDENCE = 3;
46
- function writesSpanish(text) {
47
- return (text.match(SPANISH_MARKERS) ?? []).length >= SPANISH_CONFIDENCE;
48
- }
7
+ export const ACCENT_WRITTEN_IN_QUESTION = "`accent` is how an ad's presenter will speak. Is `conversation` written in the language `accent` names? " +
8
+ "Any regional accent of that language counts.";
9
+ export const ACCENT_ASKED_FOR_QUESTION = "`accent` is how an ad's presenter will speak. Does `conversation` ask for the ad or presenter in the language " +
10
+ "`accent` names, or for a country, region or market where that language is spoken? Asking for how the " +
11
+ "presenter should look (a European, Nordic, Asian, Mediterranean or American look) is not asking for a language.";
12
+ export const ACCENT_NAMES_LANGUAGE_QUESTION = "Does `accent` name a language, a country or a regional accent?";
13
+ /** Each answer is a yes at or above this. Measured in `scripts/avatar-guard-evals`. */
14
+ export const ACCENT_HELD = 0.5;
15
+ /** The most of the conversation read, from its end: the latest turns carry the decision. */
16
+ const CONVERSATION_CHARS = 12_000;
49
17
  /** The `--accent` value in a `baker avatars create|update` command, if it has one. */
50
18
  export function accentFrom(command) {
51
19
  if (!/\bbaker\s+avatars\s+(create|update)\b/.test(command))
@@ -54,7 +22,7 @@ export function accentFrom(command) {
54
22
  return match ? (match[2] ?? match[3] ?? match[4] ?? null) : null;
55
23
  }
56
24
  /** The refusal, or null when the accent is consistent with what the user asked for. */
57
- export function accentContradictsUser(command, userText,
25
+ export async function accentContradictsUser(command, userText,
58
26
  /**
59
27
  * What the user said EARLIER in the same conversation.
60
28
  *
@@ -63,24 +31,23 @@ export function accentContradictsUser(command, userText,
63
31
  * the UK, in English" — and writes the next in Spanish had their own decision refused,
64
32
  * with nothing they could type to get past it short of repeating themselves every time.
65
33
  */
66
- priorUserText) {
67
- const said = [priorUserText ?? "", userText ?? ""].join(" ").trim();
68
- if (!command || !said || !writesSpanish(said))
34
+ priorUserText, judge) {
35
+ const said = [priorUserText ?? "", userText ?? ""].join("\n").trim().slice(-CONVERSATION_CHARS);
36
+ const accent = command ? accentFrom(command) : null;
37
+ if (!accent || !said)
38
+ return null;
39
+ const answers = await judge([ACCENT_WRITTEN_IN_QUESTION, ACCENT_ASKED_FOR_QUESTION, ACCENT_NAMES_LANGUAGE_QUESTION].map((question) => ({
40
+ instructions: { accent, conversation: said, question },
41
+ })));
42
+ const [writtenIn, askedFor, namesLanguage] = answers ?? [];
43
+ if (writtenIn === undefined || askedFor === undefined || namesLanguage === undefined)
69
44
  return null;
70
- const accent = accentFrom(command);
71
- if (!accent)
45
+ if (writtenIn >= ACCENT_HELD || askedFor >= ACCENT_HELD || namesLanguage < ACCENT_HELD)
72
46
  return null;
73
- for (const language of FOREIGN_LANGUAGES) {
74
- if (!language.accent.test(accent))
75
- continue;
76
- if (language.justification.test(said))
77
- return null;
78
- return (`Blocked: --accent "${accent}" makes this avatar speak ${language.name}, and the user is writing to you in ` +
79
- `Spanish without asking for ${language.name} anywhere. --accent sets the LANGUAGE of every clip, not the ` +
80
- `person's looks — "aspecto europeo", "Nordic" and "Mediterranean" describe a FACE and belong in --subject. ` +
81
- `Use the user's own language (e.g. --accent "Spanish from Spain, Madrid accent"). If the ad really is for a ` +
82
- `${language.name}-speaking market, ask them first and say so in the same turn.`);
83
- }
84
- return null;
47
+ return (`Blocked: --accent "${accent}" sets the language this avatar speaks, and nothing the user said asks for it: ` +
48
+ `it is not the language they write to you in, nor one they asked for. --accent sets the LANGUAGE of every ` +
49
+ `clip, not the person's looks — "aspecto europeo", "Nordic" and "Mediterranean" describe a FACE and belong ` +
50
+ `in --subject. Use the user's own language and accent. If the ad really is for a market that speaks another ` +
51
+ `language, ask them first and say so in the same turn.`);
85
52
  }
86
53
  //# sourceMappingURL=avatar-accent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatar-accent.js","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mFAAmF;AACnF,MAAM,eAAe,GACnB,iKAAiK,CAAC;AAEpK,sFAAsF;AACtF,MAAM,iBAAiB,GAA8D;IACnF;QACE,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,kEAAkE;QAC1E,aAAa,EAAE,oGAAoG;KACpH;IACD;QACE,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,gCAAgC;QACxC,aAAa,EAAE,2CAA2C;KAC3D;IACD,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,wBAAwB,EAAE,aAAa,EAAE,oCAAoC,EAAE;IACzG;QACE,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,kCAAkC;QAC1C,aAAa,EAAE,qEAAqE;KACrF;IACD,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,iCAAiC,EAAE;IAC/F,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,6BAA6B,EAAE,aAAa,EAAE,qCAAqC,EAAE;CACpH,CAAC;AAEF,8EAA8E;AAC9E,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,IAAI,kBAAkB,CAAC;AAC1E,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,IAAI,CAAC,uCAAuC,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACxE,MAAM,KAAK,GAAG,8CAA8C,CAAC,IAA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8BAA8B,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACzG,YAAY,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE;KACvD,CAAC,CAAC,CACJ,CAAC;IACF,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,GAAG,OAAO,IAAI,EAAE,CAAC;IAC3D,IAAI,SAAS,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAClG,IAAI,SAAS,IAAI,WAAW,IAAI,QAAQ,IAAI,WAAW,IAAI,aAAa,GAAG,WAAW;QAAE,OAAO,IAAI,CAAC;IACpG,OAAO,CACL,sBAAsB,MAAM,iFAAiF;QAC7G,2GAA2G;QAC3G,4GAA4G;QAC5G,6GAA6G;QAC7G,uDAAuD,CACxD,CAAC;AACJ,CAAC"}
@@ -1,48 +1,59 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { accentContradictsUser, accentFrom } from "./avatar-accent.js";
3
- const ASK = "Crea un avatar para un anuncio de TikTok en el que vendamos la instalación de placas solares para ahorrar dinero, con aspecto europeo.";
4
- describe("accentContradictsUser", () => {
5
- it("refuses each of the three accents that shipped from this exact sentence", () => {
6
- for (const accent of [
7
- "Dutch, neutral European accent",
8
- "German, clear and authoritative",
9
- "English from UK, Southern England accent",
10
- ]) {
11
- const refusal = accentContradictsUser(`baker avatars create --name "X" --accent "${accent}"`, ASK);
12
- expect(refusal).toContain("--accent sets the LANGUAGE");
2
+ import { ACCENT_ASKED_FOR_QUESTION, ACCENT_NAMES_LANGUAGE_QUESTION, accentContradictsUser, accentFrom, } from "./avatar-accent.js";
3
+ const CREATE = (accent) => `baker avatars create --name "X" --accent "${accent}"`;
4
+ /**
5
+ * A judge that reads every accent as naming a language unless it mentions `noLanguage`, and
6
+ * holds it asked for only when the conversation mentions `marker`. The user never writes in it.
7
+ */
8
+ function fitsWhen(marker, noLanguage = "warm") {
9
+ return async (questions) => questions.map(({ instructions }) => {
10
+ if (instructions.question === ACCENT_NAMES_LANGUAGE_QUESTION) {
11
+ return instructions.accent?.includes(noLanguage) ? 0.02 : 0.9;
12
+ }
13
+ if (instructions.question === ACCENT_ASKED_FOR_QUESTION) {
14
+ return instructions.conversation?.includes(marker) ? 0.9 : 0.1;
13
15
  }
16
+ return 0.05;
14
17
  });
15
- it("allows the user's own language", () => {
16
- expect(accentContradictsUser('baker avatars create --name "X" --accent "Spanish from Spain, Madrid accent"', ASK)).toBeNull();
18
+ }
19
+ describe("accentContradictsUser", () => {
20
+ it("refuses an accent the judge reads as a language nobody asked for, in any language the user writes", async () => {
21
+ const refusal = await accentContradictsUser(CREATE("Swedish, neutral"), "Zrób awatara do reklamy na TikToka o panelach słonecznych, ma wyglądać skandynawsko.", undefined, fitsWhen("po szwedzku"));
22
+ expect(refusal).toContain("--accent sets the LANGUAGE");
17
23
  });
18
- it("allows a foreign language the user actually asked for", () => {
19
- // A Spanish speaker selling into the UK is a real case and must not be blocked.
20
- expect(accentContradictsUser('baker avatars create --name "X" --accent "English from UK"', "Quiero un anuncio para el mercado de UK, en inglés, sobre placas solares")).toBeNull();
24
+ it("allows an accent the judge reads as asked for", async () => {
25
+ const refusal = await accentContradictsUser(CREATE("German, standard"), "Reklama jest na rynek niemiecki, awatar ma mówić po niemiecku.", undefined, fitsWhen("po niemiecku"));
26
+ expect(refusal).toBeNull();
21
27
  });
22
- it("stays out of the way when the user is not writing Spanish", () => {
23
- expect(accentContradictsUser('baker avatars create --name "X" --accent "German"', "Create an avatar for a TikTok ad about solar panels")).toBeNull();
28
+ it("reads what the user said in an earlier turn on the same footing as this one", async () => {
29
+ // A user who settles the market in one turn and writes the next in Spanish had their
30
+ // own decision refused, with nothing they could type short of repeating it every time.
31
+ const refusal = await accentContradictsUser(CREATE("English from UK, Southern England accent"), "Crea el avatar y empieza con el primer clip.", "La campaña es para UK y el anuncio va en inglés.", fitsWhen("para UK"));
32
+ expect(refusal).toBeNull();
33
+ });
34
+ it("allows the language the user writes in, which nobody has to ask for", async () => {
35
+ const writesIt = async (questions) => questions.map(({ instructions }) => (instructions.question === ACCENT_ASKED_FOR_QUESTION ? 0.1 : 0.95));
36
+ const refusal = await accentContradictsUser(CREATE("Polish, Warsaw"), "Zrób awatara do reklamy.", undefined, writesIt);
37
+ expect(refusal).toBeNull();
24
38
  });
25
- it("ignores commands that are not creating an avatar", () => {
26
- expect(accentContradictsUser("grep -rn -- --accent docs/", ASK)).toBeNull();
27
- expect(accentContradictsUser(undefined, ASK)).toBeNull();
39
+ it("lets an accent that names no language through: it cannot contradict anything", async () => {
40
+ const refusal = await accentContradictsUser(CREATE("warm and friendly"), "Crea un avatar para la clínica dental.", undefined, fitsWhen("nothing asked"));
41
+ expect(refusal).toBeNull();
28
42
  });
43
+ it("lets the command through when the judge cannot answer, rather than refuse on a guess", async () => {
44
+ expect(await accentContradictsUser(CREATE("German"), "Hazme un avatar", undefined, async () => null)).toBeNull();
45
+ });
46
+ it("ignores commands that set no accent, without asking the judge", async () => {
47
+ const unreachable = () => Promise.reject(new Error("the judge should not be asked"));
48
+ expect(await accentContradictsUser("grep -rn -- --accent docs/", "Hazme un avatar", undefined, unreachable)).toBeNull();
49
+ expect(await accentContradictsUser('baker avatars create --name "X"', "Hazme un avatar", undefined, unreachable)).toBeNull();
50
+ expect(await accentContradictsUser(undefined, "Hazme un avatar", undefined, unreachable)).toBeNull();
51
+ });
52
+ });
53
+ describe("accentFrom", () => {
29
54
  it("reads the accent however it was quoted", () => {
30
55
  expect(accentFrom('baker avatars create --accent "German, firm"')).toBe("German, firm");
31
56
  expect(accentFrom("baker avatars update marta --accent='British English'")).toBe("British English");
32
57
  });
33
58
  });
34
- describe("what the user said in an earlier turn", () => {
35
- it("accepts a foreign accent the conversation already established", () => {
36
- // The gate reads the turn in front of it. A user who settles the market in one turn —
37
- // "the campaign is for the UK, in English" — and then writes the next one in Spanish
38
- // got their own decision refused, with nothing they could type to get past it short of
39
- // repeating themselves in every message.
40
- const refusal = accentContradictsUser('baker avatars create --name "X" --accent "English from UK, Southern England accent"', "Crea el avatar y empieza con el primer clip.", "La campaña es para UK y el anuncio va en inglés.");
41
- expect(refusal).toBeNull();
42
- });
43
- it("still refuses when nothing in the conversation asked for it", () => {
44
- const refusal = accentContradictsUser('baker avatars create --name "X" --accent "English from UK, Southern England accent"', "Crea el avatar y empieza con el primer clip.", "Quiero un anuncio de placas solares para el mercado local.");
45
- expect(refusal).toContain("--accent sets the LANGUAGE");
46
- });
47
- });
48
59
  //# sourceMappingURL=avatar-accent.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatar-accent.test.js","sourceRoot":"","sources":["../../src/hono/avatar-accent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,GAAG,GACP,wIAAwI,CAAC;AAE3I,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,yEAAyE,EAAE,GAAG,EAAE;QACjF,KAAK,MAAM,MAAM,IAAI;YACnB,gCAAgC;YAChC,iCAAiC;YACjC,0CAA0C;SAC3C,EAAE,CAAC;YACF,MAAM,OAAO,GAAG,qBAAqB,CAAC,6CAA6C,MAAM,GAAG,EAAE,GAAG,CAAC,CAAC;YACnG,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CACJ,qBAAqB,CAAC,8EAA8E,EAAE,GAAG,CAAC,CAC3G,CAAC,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EA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AC,8CAA8C,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACxF,MAAM,CAAC,UAAU,CAAC,uDAAuD,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACtG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -11,15 +11,32 @@
11
11
  * before asking anyway — three times, in both casting modes. A rule that survives being
12
12
  * read needs a gate, and `routeToolUse` is the one path every question travels.
13
13
  *
14
- * Its own module so it can be tested as the pure function it is, without the bridge's
15
- * environment having to exist.
14
+ * Read by Jev, so a face asked for in any language or wording is caught, with no list of
15
+ * face words to fall out of date. Its own module, with the judge as a parameter, so it can be
16
+ * tested without the network or the bridge's environment.
16
17
  */
18
+ import type { Judge } from "./jev.ts";
19
+ /**
20
+ * The two questions Jev answers about each question the agent asks, as the user would read
21
+ * it: is it a face pick, and is it about a page. A presenter section on a landing is a photo
22
+ * the user already has, which the casting picker cannot offer, and asked in one question it
23
+ * read as a face pick (0.81). Kept word for word in step with the scaffold's
24
+ * guard-avatar-face-question hook, the same rule one layer in. Re-run
25
+ * `scripts/avatar-guard-evals` after changing either.
26
+ */
27
+ export declare const FACE_PICK_QUESTION: string;
28
+ export declare const ON_A_PAGE_QUESTION = "Does `asked` mention a website, a landing page or a section of a web page?";
29
+ /** At or above, a face pick; below, not about a page. Measured in `scripts/avatar-guard-evals`. */
30
+ export declare const FACE_PICK_HELD = 0.5;
31
+ export declare const ON_A_PAGE_HELD = 0.5;
17
32
  /** What the agent is told when this is refused — names both ways out. */
18
33
  export declare const FACE_QUESTION_MESSAGE: string;
34
+ /** One question as the user would read it: header, question, then each option. Pure. */
35
+ export declare function questionText(question: unknown): string;
19
36
  /**
20
- * Deliberately narrow, because a wrong refusal costs the user a real question: it fires
21
- * only when the text is about a face AND about an avatar or a casting. An avatar's
22
- * accent, its wardrobe, whether to use one at all — all still askable.
37
+ * Whether any question asks the user to pick a face. Each question is put to the judge as
38
+ * two Nouls, all in one request. A wrong refusal costs the user a real question, so a judge that
39
+ * cannot answer lets every question through.
23
40
  */
24
- export declare function asksForAvatarFace(input: Record<string, unknown> | undefined): boolean;
41
+ export declare function asksForAvatarFace(input: Record<string, unknown> | undefined, judge: Judge): Promise<boolean>;
25
42
  //# sourceMappingURL=avatar-face-question.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatar-face-question.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAwCH,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,QAK4B,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,OAAO,CAqBrF"}
1
+ {"version":3,"file":"avatar-face-question.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAKpB,CAAC;AACZ,eAAO,MAAM,kBAAkB,+EAA+E,CAAC;AAC/G,mGAAmG;AACnG,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,QAK4B,CAAC;AAE/D,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAWtD;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAalH"}
@@ -11,78 +11,67 @@
11
11
  * before asking anyway — three times, in both casting modes. A rule that survives being
12
12
  * read needs a gate, and `routeToolUse` is the one path every question travels.
13
13
  *
14
- * Its own module so it can be tested as the pure function it is, without the bridge's
15
- * environment having to exist.
14
+ * Read by Jev, so a face asked for in any language or wording is caught, with no list of
15
+ * face words to fall out of date. Its own module, with the judge as a parameter, so it can be
16
+ * tested without the network or the bridge's environment.
16
17
  */
17
- /** A face, in the languages the product is used in. `typeface` must not match. */
18
- const FACE_WORD = /(?<!type)\b(faces?|rostros?|caras?|retratos?|portraits?)\b/i;
19
18
  /**
20
- * `face` the VERB, which describes what the avatar does rather than whose it is.
21
- * "Should Marta face the camera or look away?" is a direction, not a casting call.
19
+ * The two questions Jev answers about each question the agent asks, as the user would read
20
+ * it: is it a face pick, and is it about a page. A presenter section on a landing is a photo
21
+ * the user already has, which the casting picker cannot offer, and asked in one question it
22
+ * read as a face pick (0.81). Kept word for word in step with the scaffold's
23
+ * guard-avatar-face-question hook, the same rule one layer in. Re-run
24
+ * `scripts/avatar-guard-evals` after changing either.
22
25
  */
23
- const FACE_VERB = /\bfaces?\s+(?:the\s+|el\s+|la\s+|a\s+la\s+)?(?:camera|c[áa]mara|lens|viewer|audience|forward|away|left|right|towards?|hacia)\b/gi;
24
- /**
25
- * What makes a face an avatar's face rather than anything else.
26
- *
27
- * Two tiers, because they are not equally certain. `avatar` and `casting` name the
28
- * thing the picker exists for and nothing else. `presenter`/`presentadora` names a
29
- * ROLE, and a client's landing page has one of those too — a real person, in a photo
30
- * they already own, that `request_avatar_casting` cannot offer and cannot replace.
31
- */
32
- const CASTING_WORD = /\b(avatars?|casting)\b/i;
33
- const ROLE_WORD = /\b(presentador[ao]s?|presenters?)\b/i;
34
- /**
35
- * An asset the user ALREADY has, which is never a face waiting to be cast. Only
36
- * consulted for the weak `ROLE_WORD` tier: under an explicit avatar or casting
37
- * header the picker is still the answer however the question is worded.
38
- */
39
- const EXISTING_ASSET_WORD = /\b(landings?|p[áa]ginas?|pages?|secci[óo]n|seccion|sections?|hero|fotos?|photos?|im[áa]genes|imagen|images?)\b/i;
40
- /**
41
- * "Portrait" the ORIENTATION, which is not a face at all.
42
- *
43
- * An aspect ratio beside it, or a sibling that names a frame shape, says the question
44
- * is about the shape of the frame. Under an "Avatar" header that question read as a
45
- * face picker and was refused — and a wrong refusal costs the user a real question
46
- * this tool is exactly right for. `vertical` is in the list because it is the
47
- * commonest phrasing of it and the only one Spanish uses; without it the exemption
48
- * only ever fired on a question that happened to offer landscape as the alternative.
49
- */
50
- const ORIENTATION_WORD = /\b(\d{1,2}:\d{1,2}|landscape|square|horizontal|vertical|apaisado|cuadrado|aspect ratio|relaci[óo]n de aspecto)\b/i;
26
+ export const FACE_PICK_QUESTION = "`asked` is a question an AI assistant puts to a marketer while making a video ad with a generated presenter " +
27
+ "(an avatar), shown as text with options. Does it ask the marketer to pick which person the presenter is, by " +
28
+ "their face, age, hair or general appearance? Not when it asks about the video format or orientation, where " +
29
+ "the presenter looks or how they move, their accent, language, voice or clothes, or whether to use a presenter " +
30
+ "at all.";
31
+ export const ON_A_PAGE_QUESTION = "Does `asked` mention a website, a landing page or a section of a web page?";
32
+ /** At or above, a face pick; below, not about a page. Measured in `scripts/avatar-guard-evals`. */
33
+ export const FACE_PICK_HELD = 0.5;
34
+ export const ON_A_PAGE_HELD = 0.5;
51
35
  /** What the agent is told when this is refused — names both ways out. */
52
36
  export const FACE_QUESTION_MESSAGE = "Blocked: this tool renders text, so it cannot show a face — the user would be choosing between descriptions of " +
53
37
  "people they cannot see. If they should choose, invoke the request_avatar_casting TOOL instead — as a tool call with " +
54
38
  "avatarHandle, never as a shell command — it renders " +
55
39
  "the real portraits and blocks until they pick. If nobody is there to ask, create the avatar with --face auto, ask " +
56
40
  "nothing, and do not describe the resulting face as chosen.";
41
+ /** One question as the user would read it: header, question, then each option. Pure. */
42
+ export function questionText(question) {
43
+ if (typeof question !== "object" || question === null)
44
+ return "";
45
+ const { header, question: asked, options } = question;
46
+ const lines = [[header, asked].filter((part) => typeof part === "string" && part.trim()).join(" — ")];
47
+ for (const option of Array.isArray(options) ? options : []) {
48
+ if (typeof option !== "object" || option === null)
49
+ continue;
50
+ const { label, description } = option;
51
+ const parts = [label, description].filter((part) => typeof part === "string" && part.trim());
52
+ if (parts.length > 0)
53
+ lines.push(`- ${parts.join(": ")}`);
54
+ }
55
+ return lines.join("\n").trim();
56
+ }
57
57
  /**
58
- * Deliberately narrow, because a wrong refusal costs the user a real question: it fires
59
- * only when the text is about a face AND about an avatar or a casting. An avatar's
60
- * accent, its wardrobe, whether to use one at all — all still askable.
58
+ * Whether any question asks the user to pick a face. Each question is put to the judge as
59
+ * two Nouls, all in one request. A wrong refusal costs the user a real question, so a judge that
60
+ * cannot answer lets every question through.
61
61
  */
62
- export function asksForAvatarFace(input) {
62
+ export async function asksForAvatarFace(input, judge) {
63
63
  const questions = input?.questions;
64
64
  if (!Array.isArray(questions))
65
65
  return false;
66
- return questions.some((question) => {
67
- const q = question;
68
- const options = Array.isArray(q.options)
69
- ? q.options
70
- .map((option) => {
71
- const o = option;
72
- return `${String(o?.label ?? "")} ${String(o?.description ?? "")}`;
73
- })
74
- .join(" ")
75
- : "";
76
- // The verb is dropped before anything else looks for a face, so a question that
77
- // only ever used `face` that way has no face in it at all.
78
- const text = `${String(q.header ?? "")} ${String(q.question ?? "")} ${options}`.replace(FACE_VERB, " ");
79
- if (ORIENTATION_WORD.test(text) && !/(faces?|rostros?|caras?)\b/i.test(text))
80
- return false;
81
- if (!FACE_WORD.test(text))
82
- return false;
83
- if (CASTING_WORD.test(text))
84
- return true;
85
- return ROLE_WORD.test(text) && !EXISTING_ASSET_WORD.test(text);
86
- });
66
+ const asked = questions.map(questionText).filter(Boolean);
67
+ if (asked.length === 0)
68
+ return false;
69
+ const answers = await judge(asked.flatMap((text) => [
70
+ { instructions: { asked: text, question: FACE_PICK_QUESTION } },
71
+ { instructions: { asked: text, question: ON_A_PAGE_QUESTION } },
72
+ ]));
73
+ if (!answers)
74
+ return false;
75
+ return asked.some((_, i) => (answers[2 * i] ?? 0) >= FACE_PICK_HELD && (answers[2 * i + 1] ?? 1) < ON_A_PAGE_HELD);
87
76
  }
88
77
  //# sourceMappingURL=avatar-face-question.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"avatar-face-question.js","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,kFAAkF;AAClF,MAAM,SAAS,GAAG,6DAA6D,CAAC;AAChF;;;GAGG;AACH,MAAM,SAAS,GACb,kIAAkI,CAAC;AACrI;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAC/C,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD;;;;GAIG;AACH,MAAM,mBAAmB,GACvB,iHAAiH,CAAC;AACpH;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GACpB,mHAAmH,CAAC;AAEtH,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAChC,iHAAiH;IACjH,sHAAsH;IACtH,sDAAsD;IACtD,oHAAoH;IACpH,4DAA4D,CAAC;AAE/D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA0C;IAC1E,MAAM,SAAS,GAAG,KAAK,EAAE,SAAS,CAAC;IACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QACjC,MAAM,CAAC,GAAG,QAAuE,CAAC;QAClF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;YACtC,CAAC,CAAC,CAAC,CAAC,OAAO;iBACN,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBACd,MAAM,CAAC,GAAG,MAAoD,CAAC;gBAC/D,OAAO,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,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