Sfoglia il codice sorgente

fix(v13): word-boundary + column-scoped regex for advanced_count [hotfix 3]

deriveAdvancedCountsFromSummaries now uses \b word boundaries (H01 no
longer matches H010) and only searches the hookActivity column instead
of the full table row. Extract escapeRegex() as a named export and
detectHookActivityColumnIndex() to find the correct column dynamically.
Ma 6 mesi fa
parent
commit
284698463d
1 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 9 1
      packages/core/src/utils/hook-promotion.ts

+ 9 - 1
packages/core/src/utils/hook-promotion.ts

@@ -194,6 +194,14 @@ export function resolveHalfLifeChapters(hook: StoredHook): number {
 // Shared advanced_count promotion pass (used by both consolidator and runner)
 // Shared advanced_count promotion pass (used by both consolidator and runner)
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
 
 
+/**
+ * Escape special regex characters in a string so it can be used as a
+ * literal pattern inside `new RegExp(...)`.
+ */
+export function escapeRegex(s: string): string {
+  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+}
+
 export interface PromotionPassResult {
 export interface PromotionPassResult {
   /** Whether any hook flipped to promoted=true. */
   /** Whether any hook flipped to promoted=true. */
   readonly updated: boolean;
   readonly updated: boolean;
@@ -221,7 +229,7 @@ export function deriveAdvancedCountsFromSummaries(
   const hookActivityIndex = detectHookActivityColumnIndex(lines);
   const hookActivityIndex = detectHookActivityColumnIndex(lines);
 
 
   for (const hookId of hookIds) {
   for (const hookId of hookIds) {
-    const escaped = hookId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+    const escaped = escapeRegex(hookId);
     const pattern = new RegExp(`\\b${escaped}\\b`, "i");
     const pattern = new RegExp(`\\b${escaped}\\b`, "i");
     let count = 0;
     let count = 0;
     for (const line of lines) {
     for (const line of lines) {