From 91301e3534892a5436229e1d849c856fd076e863 Mon Sep 17 00:00:00 2001 From: Tirth Kanani Date: Sun, 14 Jun 2026 18:17:47 +0100 Subject: [PATCH] fix(language-lesson): drop over-broad "is" keyword that mislabels nodes with the type-guards concept The "type guards" concept pattern included the bare keyword "is", and detectLanguageConcepts matches via unbounded substring includes(). The 2-char substring "is" appears inside common English words (this, list, exists, analysis), so nearly every node was tagged with "type guards", polluting the concepts passed to the LLM lesson prompt. Remove the "is" token and rely on the more specific existing keywords ("type guard", "narrowing", "discriminated union"). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../core/src/__tests__/language-lesson.test.ts | 14 ++++++++++++++ .../packages/core/src/analyzer/language-lesson.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/understand-anything-plugin/packages/core/src/__tests__/language-lesson.test.ts b/understand-anything-plugin/packages/core/src/__tests__/language-lesson.test.ts index 19ebb0bc..5c1b5c46 100644 --- a/understand-anything-plugin/packages/core/src/__tests__/language-lesson.test.ts +++ b/understand-anything-plugin/packages/core/src/__tests__/language-lesson.test.ts @@ -140,6 +140,20 @@ describe("language-lesson", () => { expect(concepts).toContain("middleware pattern"); }); + it("does not flag type guards from the 'is' substring in common words", () => { + const plainNode: GraphNode = { + id: "function:math:add", + type: "function", + name: "add", + filePath: "src/math/add.ts", + summary: "This function adds two numbers", + tags: ["utility"], + complexity: "simple", + }; + const concepts = detectLanguageConcepts(plainNode, "typescript"); + expect(concepts).not.toContain("type guards"); + }); + it("returns empty for nodes with no detectable concepts", () => { const plainNode: GraphNode = { id: "file:src/config.ts", diff --git a/understand-anything-plugin/packages/core/src/analyzer/language-lesson.ts b/understand-anything-plugin/packages/core/src/analyzer/language-lesson.ts index 53fcc01a..cab4d4df 100644 --- a/understand-anything-plugin/packages/core/src/analyzer/language-lesson.ts +++ b/understand-anything-plugin/packages/core/src/analyzer/language-lesson.ts @@ -24,7 +24,7 @@ const BASE_CONCEPT_PATTERNS: Record = { "listener", ], "singleton": ["singleton", "instance", "shared client"], - "type guards": ["type guard", "is", "narrowing", "discriminated union"], + "type guards": ["type guard", "narrowing", "discriminated union"], "higher-order functions": [ "callback", "factory",