Skip to content

Generalize semantic ambiguity gates - #56

Merged
simongonzalezdc merged 1 commit into
mainfrom
semantic-ambiguity-matrix
Apr 22, 2026
Merged

simongonzalezdc merged 1 commit into
mainfrom
semantic-ambiguity-matrix

Conversation

@simongonzalezdc

Copy link
Copy Markdown
Member

Summary

  • generalizes lexical ambiguity gates so matching eval/certification samples inherit rule expectations across dialects
  • adds dialect-aware required output groups and forbidden terms for pickup, transit, photo/screenshot, medicine, physical grab, and room-tidying senses
  • models Puerto Rican recoger el cuarto as tidying the room, not package/file pickup
  • adds PR eval/adversarial fixtures and broad category tests across all dialects
  • keeps certification from accepting one-token lucky matches by applying output groups from the ambiguity rule engine

Why

The previous fix was still too close to a one-off. The real failure mode is object/sense/dialect ambiguity: coger, tomar, agarrar, recoger, retirar, etc. cannot be handled as simple replacements. This patch makes ambiguity an executable category with prompt guidance and scoring gates.

Verification

  • pnpm build
  • pnpm test
  • pnpm audit --audit-level low
  • pnpm dialect:eval -- --out=/tmp/dialectos-ambiguity-matrix-eval
  • pnpm dialect:eval -- --fixtures=packages/cli/src/__tests__/fixtures/dialect-adversarial --out=/tmp/dialectos-ambiguity-matrix-adversarial
  • qwen3.5-9b live PR ambiguity eval: LLM_API_URL=http://127.0.0.1:1234/v1/chat/completions LLM_API_FORMAT=openai LLM_MODEL=qwen3.5-9b LLM_ALLOW_LOCAL=1 LLM_TIMEOUT_MS=180000 pnpm dialect:eval -- --live --provider=llm --fixtures=packages/cli/src/__tests__/fixtures/dialect-adversarial --dialects=es-PR --out=/tmp/dialectos-pr-ambiguity-live-qwen35-final
  • git diff --check
  • npm pack dry-run guard for all publishable packages

The coger/tomar/agarrar issue was a category failure, not a single Mexican term bug. This extends lexical ambiguity handling into reusable rule expectations that attach to any matching fixture across dialects, including Puerto Rican recoger el cuarto as a room-tidying sense.

Constraint: Ambiguity fixes must be executable across eval/certification scripts, not one-off prompt prose.

Rejected: Add only a Puerto Rico fixture | would repeat the one-off remediation pattern

Rejected: Treat recoger as a universal safe replacement | Puerto Rican room cleanup shows object/sense/dialect matters

Confidence: high

Scope-risk: moderate

Directive: For new overloaded verbs, add guidance plus expectations in lexical-ambiguity.ts so every matching eval/certification sample gets gated.

Tested: pnpm build; pnpm test; pnpm audit --audit-level low; deterministic default/adversarial dialect eval; qwen3.5-9b live es-PR adversarial eval; npm pack dry-run guard

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7822dbe240

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/dialect-eval.mjs
Comment on lines +23 to +25
const { buildLexicalAmbiguityExpectations } = await import(
pathToFileURL(`${process.cwd()}/packages/cli/dist/lib/lexical-ambiguity.js`).href
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Lazy-load lexical expectations for mock eval runs

Importing packages/cli/dist/lib/lexical-ambiguity.js at module load time makes node scripts/dialect-eval.mjs crash with ERR_MODULE_NOT_FOUND on a clean checkout where dist/ has not been built yet, including the default mock path. Before this change, mock eval could run without compiled artifacts, so this introduces a startup regression for pnpm dialect:eval unless users remember to build first.

Useful? React with 👍 / 👎.

Comment on lines +26 to +28
const { buildLexicalAmbiguityExpectations } = await import(
pathToFileURL(`${process.cwd()}/packages/cli/dist/lib/lexical-ambiguity.js`).href
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid hard dependency on dist in certify startup

This top-level dynamic import forces scripts/dialect-certify.mjs to require packages/cli/dist before any sample execution, so pnpm dialect:certify now fails immediately with ERR_MODULE_NOT_FOUND on fresh clones that have not run pnpm build. Because certify's mock mode no longer starts without build artifacts, this is a functional regression in the default workflow.

Useful? React with 👍 / 👎.

@simongonzalezdc
simongonzalezdc merged commit e0d2749 into main Apr 22, 2026
6 checks passed
@simongonzalezdc
simongonzalezdc deleted the semantic-ambiguity-matrix branch April 22, 2026 19:35
Comment thread scripts/dialect-eval.mjs
for (const term of sample.forbiddenOutputTerms || []) {
const lexicalExpectations = buildLexicalAmbiguityExpectations(sample.source, dialect);

for (const term of [...(sample.forbiddenOutputTerms || []), ...lexicalExpectations.forbiddenOutputTerms]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: You're concatenating arrays of forbidden terms like a toddler stacking blocks — no regard for duplicates. When a term appears in both the sample's forbiddenOutputTerms and the rule's expectations (e.g., "coger"), the loop will process it twice and push identical failure messages. Two copies of the same error don't make it more convincing; they just make you look careless.

🩹 The Fix: Deduplicate before the loop:

const allForbiddenTerms = [...new Set([...(sample.forbiddenOutputTerms || []), ...lexicalExpectations.forbiddenOutputTerms])];
for (const term of allForbiddenTerms) {
  if (output && hasForbiddenTerm(output, term)) {
    failures.push(`Forbidden output term present: ${term}`);
  }
}

📏 Severity: warning

Comment thread scripts/dialect-eval.mjs

if (output && sample.requiredOutputGroups?.length) {
for (const group of sample.requiredOutputGroups) {
const requiredOutputGroups = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: You're merging requiredOutputGroups arrays with the enthusiasm of a hoarder — no deduplication, so identical groups (like ["recoge","recoger","retira","retirar"]) will be checked twice. If a sample is missing that group, you'll get two identical "missing group" errors. If it's present, you waste cycles needlessly. Either way, it's sloppy.

🩹 The Fix: Deduplicate based on group content:

const mergedGroups = [
  ...(sample.requiredOutputGroups || []),
  ...lexicalExpectations.requiredOutputGroups,
];
const uniqueGroups = Array.from(
  new Map(mergedGroups.map(g => [g.join('|'), g])).values()
);
// then loop over uniqueGroups

📏 Severity: warning

for (const term of sample.forbiddenOutputTerms || []) {
const lexicalExpectations = buildLexicalAmbiguityExpectations(sample.source, dialect);

for (const term of [...(sample.forbiddenOutputTerms || []), ...lexicalExpectations.forbiddenOutputTerms]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: Same duplication bug as in dialect-eval.mjs but in certify. Forbidden terms are concatenated without deduplication, guaranteeing duplicate failure messages when there's overlap.

🩹 The Fix: Apply the same Set-based deduplication here:

const allForbidden = [...new Set([...(sample.forbiddenOutputTerms || []), ...lexicalExpectations.forbiddenOutputTerms])];
for (const term of allForbidden) { ... }

📏 Severity: warning


if (output && sample.requiredOutputGroups?.length) {
for (const group of sample.requiredOutputGroups) {
const requiredOutputGroups = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: And the required groups merge here suffers the same duplication problem — identical groups from sample and lexical expectations will be checked twice, cluttering the failure output.

🩹 The Fix: Deduplicate groups as shown in dialect-eval:

const merged = [...(sample.requiredOutputGroups || []), ...lexicalExpectations.requiredOutputGroups];
const unique = Array.from(new Map(merged.map(g => [g.join('|'), g])).values());
// use unique

📏 Severity: warning

guidance: "For taking transportation, use tomar/toma or abordar/aborda by register and dialect. Do not use coger outside Spain/Andorra. Preserve dialect-specific vehicle terms such as guagua where the dialect contract requires them.",
expectations: (dialect) => ({
requiredOutputGroups: [
dialect === "es-CU" || dialect === "es-DO" || dialect === "es-PR"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 The Roast: Hardcoding the guagua dialect list ("es-CU","es-DO","es-PR") inline is a DRY violation that could drift from the same constant in scripts. Next time someone updates one list and forgets the other, you'll get inconsistent vehicle expectations.

🩹 The Fix: Extract these dialects into a shared constant (e.g., in @espanol/types or a utils module) and import it everywhere. At minimum, define a local constant and reuse it.

📏 Severity: suggestion

@kilo-code-bot

kilo-code-bot Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Code Review Roast 🔥

Verdict: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 4
💡 suggestion 1
🤏 nitpick 0
Issue Details (click to expand)
File Line Roast
scripts/dialect-eval.mjs 106 Duplicate forbidden terms when merging sample and lexical expectations
scripts/dialect-eval.mjs 119 Duplicate required groups when merging arrays
scripts/dialect-certify.mjs 133 Duplicate forbidden terms similar to eval
scripts/dialect-certify.mjs 146 Duplicate required groups similar to eval
packages/cli/src/lib/lexical-ambiguity.ts 74 Hardcoded guagua dialect list — should be shared constant

Fix Link

Fix these issues in Kilo Cloud

🏆 Best part: The new buildLexicalAmbiguityExpectations function is actually clean and elegantly composable. I'm genuinely impressed — I need to sit down.

💀 Worst part: The duplicate array merging in the eval/certify scripts. It's a basic oversight that turns error reporting into a broken record. Fix the deduplication before this code touches production.

📊 Overall: Like a machismo subjunctive — promising tense action but with a couple of unexpected conjugations that need cleaning up.

Files Reviewed (12 files)
  • README.md
  • docs/index.html
  • index.html
  • packages/cli/src/__tests__/dialect-eval-script.test.ts
  • packages/cli/src/__tests__/fixtures/dialect-adversarial/es-MX.json
  • packages/cli/src/__tests__/fixtures/dialect-adversarial/es-PR.json
  • packages/cli/src/__tests__/fixtures/dialect-eval/es-MX.json
  • packages/cli/src/__tests__/fixtures/dialect-eval/es-PR.json
  • packages/cli/src/__tests__/lexical-ambiguity.test.ts
  • packages/cli/src/lib/lexical-ambiguity.ts
  • scripts/dialect-certify.mjs
  • scripts/dialect-eval.mjs

Reviewed by step-3.5-flash · 2,422,427 tokens

simongonzalezdc added a commit that referenced this pull request Nov 11, 2026
Brings GitHub main level with Forgejo main (ef214e5), the canonical
repo, so GitHub carries what v0.3.2 is cut from.

- **Roast fixes:** dictionary accents and meaning-safe swaps (#50),
accented words in the register, voseo, gender and grammar checks (#51),
the file sandbox and patched dependencies (#52), honest claims and a
pinned toolchain (#53), and adjective agreement, MCP vosotros parity,
the real engine in the demo, and no more "first" claim (#55).
- **Branding:** the Hermes plugin icon (#54).
- **Release:** every version and install path moves to 0.3.2 (#56).
- **Security:** the voseo quote regex CodeQL flagged on this PR now runs
in linear time (#57).
- **Pages:** `docs/CNAME` is removed. The site already serves from
kyanitelabs.github.io/DialectOS/ without a redirect.

After this merges, both mains have the same files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01RXhEX6WJsRZUyGhsp5WgGe

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant