File size: 1,667 Bytes
cc11e77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// S526 — estratto da agentLoop.ts: Step4/7/8/S127 context hints group
// Raccoglie in un solo posto i 4 hint sincroni che popolano il system prompt.

import { suggestRecipe } from "../skillRecipes";

export interface ContextHints {
  strategyHint:   string;
  knowledgeRules: string;
  userModelCtx:   string;
  skillHint:      string;
  recipeHint:     string; // S-RECIPE: ricetta confermata per il task corrente
}

export interface ContextHintsDeps {
  selfLearning: {
    getStrategyFor: (q: string) => string | null | undefined;
  };
  getKnowledgeRules:   () => string;
  getUserModelContext: () => string;
  suggestPattern:      (q: string) => string | null | undefined;
}

/**
 * S526/Step4+7+8+S127: carica i 4 context hints sincroni (strategy, knowledge,
 * user model, skill pattern). Tutti non-bloccanti: fallback "" su errore.
 */
export function loadContextHints(
  lastUserMsg: string,
  deps: ContextHintsDeps,
): ContextHints {
  const strategyHint = (() => {
    try   { return deps.selfLearning.getStrategyFor(lastUserMsg) ?? ""; }
    catch { return ""; }
  })();
  const knowledgeRules = (() => {
    try { return deps.getKnowledgeRules(); } catch { return ""; }
  })();
  const userModelCtx = (() => {
    try { return deps.getUserModelContext(); } catch { return ""; }
  })();
  const skillHint = (() => {
    try { return deps.suggestPattern(lastUserMsg) ?? ""; } catch { return ""; }
  })();
  // S-RECIPE: ricetta confermata ad alta confidenza
  const recipeHint = (() => {
    try { return suggestRecipe(lastUserMsg) ?? ""; } catch { return ""; }
  })();
  return { strategyHint, knowledgeRules, userModelCtx, skillHint, recipeHint };
}