pi-continuous-learning 0.7.0 → 0.9.0

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 (91) hide show
  1. package/dist/analysis-event-log.d.ts +50 -0
  2. package/dist/analysis-event-log.d.ts.map +1 -0
  3. package/dist/analysis-event-log.js +120 -0
  4. package/dist/analysis-event-log.js.map +1 -0
  5. package/dist/analysis-notification.d.ts +20 -0
  6. package/dist/analysis-notification.d.ts.map +1 -0
  7. package/dist/analysis-notification.js +63 -0
  8. package/dist/analysis-notification.js.map +1 -0
  9. package/dist/cli/analyze-single-shot.d.ts +12 -0
  10. package/dist/cli/analyze-single-shot.d.ts.map +1 -1
  11. package/dist/cli/analyze-single-shot.js +84 -2
  12. package/dist/cli/analyze-single-shot.js.map +1 -1
  13. package/dist/cli/analyze.js +349 -21
  14. package/dist/cli/analyze.js.map +1 -1
  15. package/dist/confidence.d.ts +12 -1
  16. package/dist/confidence.d.ts.map +1 -1
  17. package/dist/confidence.js +35 -8
  18. package/dist/confidence.js.map +1 -1
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +7 -0
  21. package/dist/config.js.map +1 -1
  22. package/dist/consolidation.d.ts +43 -0
  23. package/dist/consolidation.d.ts.map +1 -0
  24. package/dist/consolidation.js +104 -0
  25. package/dist/consolidation.js.map +1 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +7 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/instinct-cleanup.d.ts +14 -0
  30. package/dist/instinct-cleanup.d.ts.map +1 -1
  31. package/dist/instinct-cleanup.js +59 -3
  32. package/dist/instinct-cleanup.js.map +1 -1
  33. package/dist/instinct-contradiction.d.ts +42 -0
  34. package/dist/instinct-contradiction.d.ts.map +1 -0
  35. package/dist/instinct-contradiction.js +164 -0
  36. package/dist/instinct-contradiction.js.map +1 -0
  37. package/dist/instinct-dream.d.ts +12 -0
  38. package/dist/instinct-dream.d.ts.map +1 -0
  39. package/dist/instinct-dream.js +33 -0
  40. package/dist/instinct-dream.js.map +1 -0
  41. package/dist/instinct-parser.d.ts.map +1 -1
  42. package/dist/instinct-parser.js +6 -0
  43. package/dist/instinct-parser.js.map +1 -1
  44. package/dist/observation-signal.d.ts +34 -0
  45. package/dist/observation-signal.d.ts.map +1 -0
  46. package/dist/observation-signal.js +66 -0
  47. package/dist/observation-signal.js.map +1 -0
  48. package/dist/prompts/analyzer-system-single-shot.d.ts.map +1 -1
  49. package/dist/prompts/analyzer-system-single-shot.js +57 -2
  50. package/dist/prompts/analyzer-system-single-shot.js.map +1 -1
  51. package/dist/prompts/analyzer-user-single-shot.d.ts.map +1 -1
  52. package/dist/prompts/analyzer-user-single-shot.js +5 -3
  53. package/dist/prompts/analyzer-user-single-shot.js.map +1 -1
  54. package/dist/prompts/consolidate-system.d.ts +6 -0
  55. package/dist/prompts/consolidate-system.d.ts.map +1 -0
  56. package/dist/prompts/consolidate-system.js +102 -0
  57. package/dist/prompts/consolidate-system.js.map +1 -0
  58. package/dist/prompts/consolidate-user.d.ts +19 -0
  59. package/dist/prompts/consolidate-user.d.ts.map +1 -0
  60. package/dist/prompts/consolidate-user.js +45 -0
  61. package/dist/prompts/consolidate-user.js.map +1 -0
  62. package/dist/prompts/dream-prompt.d.ts +7 -0
  63. package/dist/prompts/dream-prompt.d.ts.map +1 -0
  64. package/dist/prompts/dream-prompt.js +64 -0
  65. package/dist/prompts/dream-prompt.js.map +1 -0
  66. package/dist/prompts/evolve-prompt.d.ts.map +1 -1
  67. package/dist/prompts/evolve-prompt.js +6 -5
  68. package/dist/prompts/evolve-prompt.js.map +1 -1
  69. package/dist/types.d.ts +4 -0
  70. package/dist/types.d.ts.map +1 -1
  71. package/package.json +1 -1
  72. package/src/analysis-event-log.ts +171 -0
  73. package/src/analysis-notification.ts +79 -0
  74. package/src/cli/analyze-single-shot.ts +98 -2
  75. package/src/cli/analyze.ts +406 -20
  76. package/src/confidence.ts +33 -7
  77. package/src/config.ts +10 -0
  78. package/src/consolidation.ts +162 -0
  79. package/src/index.ts +17 -0
  80. package/src/instinct-cleanup.ts +62 -3
  81. package/src/instinct-contradiction.ts +202 -0
  82. package/src/instinct-dream.ts +62 -0
  83. package/src/instinct-parser.ts +6 -0
  84. package/src/observation-signal.ts +80 -0
  85. package/src/prompts/analyzer-system-single-shot.ts +57 -2
  86. package/src/prompts/analyzer-user-single-shot.ts +7 -2
  87. package/src/prompts/consolidate-system.ts +101 -0
  88. package/src/prompts/consolidate-user.ts +88 -0
  89. package/src/prompts/dream-prompt.ts +88 -0
  90. package/src/prompts/evolve-prompt.ts +6 -5
  91. package/src/types.ts +5 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Contradiction detection for instincts with opposing actions.
3
+ *
4
+ * Detects instincts that have similar triggers but semantically opposed actions
5
+ * using pattern-based heuristics (negation words, antonym verb pairs).
6
+ * No LLM cost - purely deterministic.
7
+ */
8
+ import { tokenize, jaccardSimilarity } from "./instinct-validator.js";
9
+ // ---------------------------------------------------------------------------
10
+ // Constants
11
+ // ---------------------------------------------------------------------------
12
+ /** Default Jaccard similarity threshold for trigger comparison. */
13
+ const DEFAULT_TRIGGER_THRESHOLD = 0.4;
14
+ /**
15
+ * Pairs of verbs/keywords that indicate opposing intent when one appears
16
+ * in each action. Order within each pair does not matter.
17
+ */
18
+ export const OPPOSING_VERB_PAIRS = [
19
+ ["avoid", "prefer"],
20
+ ["avoid", "use"],
21
+ ["avoid", "always"],
22
+ ["avoid", "ensure"],
23
+ ["never", "always"],
24
+ ["never", "prefer"],
25
+ ["never", "use"],
26
+ ["never", "ensure"],
27
+ ["skip", "always"],
28
+ ["skip", "ensure"],
29
+ ["skip", "require"],
30
+ ["reject", "prefer"],
31
+ ["reject", "use"],
32
+ ["reject", "accept"],
33
+ ];
34
+ /**
35
+ * Negation prefixes that invert the meaning of a following verb.
36
+ * Matched as word boundaries in lowercase text.
37
+ */
38
+ const NEGATION_PATTERNS = [
39
+ "do not ",
40
+ "don't ",
41
+ "do not",
42
+ "don't",
43
+ ];
44
+ // ---------------------------------------------------------------------------
45
+ // Helpers
46
+ // ---------------------------------------------------------------------------
47
+ /**
48
+ * Extracts the set of action-relevant keywords from an action string.
49
+ * Lowercases and splits on word boundaries.
50
+ */
51
+ function extractActionWords(action) {
52
+ return new Set(action
53
+ .toLowerCase()
54
+ .split(/[^a-z']+/)
55
+ .filter((w) => w.length > 0));
56
+ }
57
+ /**
58
+ * Checks whether a negation prefix appears in the action text,
59
+ * followed by a verb that appears in the other action.
60
+ */
61
+ function hasNegationConflict(actionA, actionB) {
62
+ const lowerA = actionA.toLowerCase();
63
+ const lowerB = actionB.toLowerCase();
64
+ const wordsA = extractActionWords(actionA);
65
+ const wordsB = extractActionWords(actionB);
66
+ for (const neg of NEGATION_PATTERNS) {
67
+ // Check if A has negation + verb that B uses affirmatively
68
+ const idxA = lowerA.indexOf(neg);
69
+ if (idxA !== -1) {
70
+ const afterNeg = lowerA.slice(idxA + neg.length).trim();
71
+ const negatedVerb = afterNeg.split(/[^a-z]+/)[0];
72
+ if (negatedVerb && negatedVerb.length > 1 && wordsB.has(negatedVerb)) {
73
+ return `"${neg}${negatedVerb}" vs "${negatedVerb}"`;
74
+ }
75
+ }
76
+ // Check if B has negation + verb that A uses affirmatively
77
+ const idxB = lowerB.indexOf(neg);
78
+ if (idxB !== -1) {
79
+ const afterNeg = lowerB.slice(idxB + neg.length).trim();
80
+ const negatedVerb = afterNeg.split(/[^a-z]+/)[0];
81
+ if (negatedVerb && negatedVerb.length > 1 && wordsA.has(negatedVerb)) {
82
+ return `"${neg}${negatedVerb}" vs "${negatedVerb}"`;
83
+ }
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+ /**
89
+ * Checks whether two actions are semantically opposing using verb pair matching
90
+ * and negation pattern detection.
91
+ *
92
+ * @returns A reason string if opposing, null otherwise.
93
+ */
94
+ export function hasOpposingAction(actionA, actionB) {
95
+ if (!actionA || !actionB)
96
+ return null;
97
+ if (actionA === actionB)
98
+ return null;
99
+ const wordsA = extractActionWords(actionA);
100
+ const wordsB = extractActionWords(actionB);
101
+ // Check opposing verb pairs
102
+ for (const [verbX, verbY] of OPPOSING_VERB_PAIRS) {
103
+ if ((wordsA.has(verbX) && wordsB.has(verbY)) ||
104
+ (wordsA.has(verbY) && wordsB.has(verbX))) {
105
+ return `opposing verbs: "${verbX}" vs "${verbY}"`;
106
+ }
107
+ }
108
+ // Check negation patterns (e.g., "do not use" vs "use")
109
+ const negationResult = hasNegationConflict(actionA, actionB);
110
+ if (negationResult) {
111
+ return `negation conflict: ${negationResult}`;
112
+ }
113
+ return null;
114
+ }
115
+ /**
116
+ * Finds all contradictory pairs in a set of instincts.
117
+ *
118
+ * A contradiction is defined as:
119
+ * 1. Similar triggers (Jaccard similarity >= threshold on trigger tokens)
120
+ * 2. Opposing actions (detected via verb pairs or negation patterns)
121
+ *
122
+ * Instincts with `flagged_for_removal` are excluded.
123
+ * Each pair is reported once (no duplicates).
124
+ *
125
+ * @param instincts - All instincts to check
126
+ * @param triggerThreshold - Jaccard similarity threshold for triggers (default 0.4)
127
+ * @returns Array of contradiction matches
128
+ */
129
+ export function findContradictions(instincts, triggerThreshold = DEFAULT_TRIGGER_THRESHOLD) {
130
+ const active = instincts.filter((i) => !i.flagged_for_removal);
131
+ if (active.length < 2)
132
+ return [];
133
+ const matches = [];
134
+ // Pre-compute trigger tokens
135
+ const triggerTokens = new Map();
136
+ for (const inst of active) {
137
+ triggerTokens.set(inst.id, tokenize(inst.trigger));
138
+ }
139
+ // Compare all unique pairs
140
+ for (let i = 0; i < active.length; i++) {
141
+ for (let j = i + 1; j < active.length; j++) {
142
+ const a = active[i];
143
+ const b = active[j];
144
+ // Step 1: Check trigger similarity
145
+ const tokensA = triggerTokens.get(a.id);
146
+ const tokensB = triggerTokens.get(b.id);
147
+ const similarity = jaccardSimilarity(tokensA, tokensB);
148
+ if (similarity < triggerThreshold)
149
+ continue;
150
+ // Step 2: Check action opposition
151
+ const reason = hasOpposingAction(a.action, b.action);
152
+ if (reason) {
153
+ matches.push({
154
+ instinctA: a,
155
+ instinctB: b,
156
+ triggerSimilarity: similarity,
157
+ reason,
158
+ });
159
+ }
160
+ }
161
+ }
162
+ return matches;
163
+ }
164
+ //# sourceMappingURL=instinct-contradiction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instinct-contradiction.js","sourceRoot":"","sources":["../src/instinct-contradiction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEtE,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,mEAAmE;AACnE,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA6C;IAC3E,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnB,CAAC,MAAM,EAAE,QAAQ,CAAC;IAClB,CAAC,MAAM,EAAE,QAAQ,CAAC;IAClB,CAAC,MAAM,EAAE,SAAS,CAAC;IACnB,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,QAAQ,EAAE,KAAK,CAAC;IACjB,CAAC,QAAQ,EAAE,QAAQ,CAAC;CACZ,CAAC;AAEX;;;GAGG;AACH,MAAM,iBAAiB,GAA0B;IAC/C,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,OAAO;CACR,CAAC;AAEF,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;GAGG;AACH,SAAS,kBAAkB,CAAC,M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AiB,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;YACrD,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC;oBACX,SAAS,EAAE,CAAC;oBACZ,SAAS,EAAE,CAAC;oBACZ,iBAAiB,EAAE,UAAU;oBAC7B,MAAM;iBACP,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * /instinct-dream slash command handler.
3
+ *
4
+ * Interactive version of consolidation that runs inside a Pi session.
5
+ * Loads all instincts, builds a consolidation prompt, and sends it as
6
+ * a followUp message for the LLM to review with the user.
7
+ */
8
+ import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
9
+ import type { InstalledSkill } from "./types.js";
10
+ export declare const COMMAND_NAME = "instinct-dream";
11
+ export declare function handleInstinctDream(_args: string, ctx: ExtensionCommandContext, pi: ExtensionAPI, projectId?: string | null, baseDir?: string, projectRoot?: string | null, installedSkills?: InstalledSkill[]): Promise<void>;
12
+ //# sourceMappingURL=instinct-dream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instinct-dream.d.ts","sourceRoot":"","sources":["../src/instinct-dream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAWjD,eAAO,MAAM,YAAY,mBAAmB,CAAC;AAE7C,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,uBAAuB,EAC5B,EAAE,EAAE,YAAY,EAChB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,EAC3B,eAAe,CAAC,EAAE,cAAc,EAAE,GACjC,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * /instinct-dream slash command handler.
3
+ *
4
+ * Interactive version of consolidation that runs inside a Pi session.
5
+ * Loads all instincts, builds a consolidation prompt, and sends it as
6
+ * a followUp message for the LLM to review with the user.
7
+ */
8
+ import { homedir } from "node:os";
9
+ import { join } from "node:path";
10
+ import { getBaseDir } from "./storage.js";
11
+ import { readAgentsMd } from "./agents-md.js";
12
+ import { loadProjectInstincts, loadGlobalInstincts } from "./instinct-store.js";
13
+ import { filterInstincts } from "./instinct-loader.js";
14
+ import { buildDreamPrompt } from "./prompts/dream-prompt.js";
15
+ const MAX_DREAM_INSTINCTS = 100;
16
+ export const COMMAND_NAME = "instinct-dream";
17
+ export async function handleInstinctDream(_args, ctx, pi, projectId, baseDir, projectRoot, installedSkills) {
18
+ const effectiveBase = baseDir ?? getBaseDir();
19
+ const projectInstincts = projectId
20
+ ? loadProjectInstincts(projectId, effectiveBase)
21
+ : [];
22
+ const globalInstincts = loadGlobalInstincts(effectiveBase);
23
+ const allInstincts = filterInstincts([...projectInstincts, ...globalInstincts], 0.1, MAX_DREAM_INSTINCTS);
24
+ if (allInstincts.length === 0) {
25
+ ctx.ui.notify("No instincts to consolidate. Keep using pi to accumulate instincts first.", "info");
26
+ return;
27
+ }
28
+ const agentsMdProject = projectRoot != null ? readAgentsMd(join(projectRoot, "AGENTS.md")) : null;
29
+ const agentsMdGlobal = readAgentsMd(join(homedir(), ".pi", "agent", "AGENTS.md"));
30
+ const prompt = buildDreamPrompt(allInstincts, agentsMdProject, agentsMdGlobal, installedSkills);
31
+ pi.sendUserMessage(prompt, { deliverAs: "followUp" });
32
+ }
33
+ //# sourceMappingURL=instinct-dream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instinct-dream.js","sourceRoot":"","sources":["../src/instinct-dream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;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C;IAC5E,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAElF,MAAM,MAAM,GAAG,gBAAgB,CAC7B,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,CAChB,CAAC;IACF,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AACxD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"instinct-parser.d.ts","sourceRoot":"","sources":["../src/instinct-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAyD3C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAyDvD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAwC5D"}
1
+ {"version":3,"file":"instinct-parser.d.ts","sourceRoot":"","sources":["../src/instinct-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAyD3C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CA4DvD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CA2C5D"}
@@ -108,6 +108,9 @@ export function parseInstinct(content) {
108
108
  if (fm["graduated_at"] !== undefined && fm["graduated_at"] !== null) {
109
109
  instinct.graduated_at = String(fm["graduated_at"]);
110
110
  }
111
+ if (fm["last_confirmed_session"] !== undefined && fm["last_confirmed_session"] !== null) {
112
+ instinct.last_confirmed_session = String(fm["last_confirmed_session"]);
113
+ }
111
114
  return instinct;
112
115
  }
113
116
  /**
@@ -149,6 +152,9 @@ export function serializeInstinct(instinct) {
149
152
  if (instinct.graduated_at !== undefined) {
150
153
  frontmatter["graduated_at"] = instinct.graduated_at;
151
154
  }
155
+ if (instinct.last_confirmed_session !== undefined) {
156
+ frontmatter["last_confirmed_session"] = instinct.last_confirmed_session;
157
+ }
152
158
  const yamlStr = stringifyYaml(frontmatter);
153
159
  return `---\n${yamlStr}---\n\n${instinct.action}\n`;
154
160
  }
@@ -1 +1 @@
1
- {"version":3,"file":"instinct-parser.js","sourceRoot":"","sources":["../src/instinct-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AAGtE,YAAY;AACZ,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAC5C,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B,MAAM,eAAe,GAAG;IACtB,IAAI;IACJ,OAAO;IACP,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,YAAY;IACZ,YAAY;IACZ,mBAAmB;IACnB,iBAAiB;IACjB,oBAAoB;IACpB,gBAAgB;CACR,CAAC;AAEX,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,eAAe,CAAC,EAAU;IACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,wBAAwB,EAAE,mEAAmE,CAC9F,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAe;IAIvC,gDAAgD;IAChD,MAA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EAAE,CAAC;QAC/C,WAAW,CAAC,qBAAqB,CAAC,GAAG,QAAQ,CAAC,mBAAmB,CAAC;IACpE,CAAC;IACD,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACxC,WAAW,CAAC,cAAc,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;IACtD,CAAC;IACD,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACxC,WAAW,CAAC,cAAc,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;IACtD,CAAC;IACD,IAAI,QAAQ,CAAC,sBAAsB,KAAK,SAAS,EAAE,CAAC;QAClD,WAAW,CAAC,wBAAwB,CAAC,GAAG,QAAQ,CAAC,sBAAsB,CAAC;IAC1E,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,QAAQ,OAAO,UAAU,QAAQ,CAAC,MAAM,IAAI,CAAC;AACtD,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Observation batch signal scoring.
3
+ * Determines whether a batch of observations contains enough signal
4
+ * to warrant running the analyzer (and spending tokens).
5
+ */
6
+ /**
7
+ * Score threshold below which a batch is considered low-signal.
8
+ * Batches scoring below this are skipped with a log entry.
9
+ */
10
+ export declare const LOW_SIGNAL_THRESHOLD = 3;
11
+ interface ScoreResult {
12
+ readonly score: number;
13
+ readonly errors: number;
14
+ readonly corrections: number;
15
+ readonly userPrompts: number;
16
+ }
17
+ /**
18
+ * Scores an observation batch for signal richness.
19
+ *
20
+ * Scoring rules:
21
+ * - Error observation (is_error: true): +2 points
22
+ * - user_prompt after an error (user correction): +3 points
23
+ * - Other user_prompt events (potential corrections/redirections): +1 point
24
+ *
25
+ * @param lines - Raw JSONL observation lines (preprocessed or raw)
26
+ * @returns Score result with breakdown
27
+ */
28
+ export declare function scoreObservationBatch(lines: string[]): ScoreResult;
29
+ /**
30
+ * Returns true if the batch is low-signal and analysis should be skipped.
31
+ */
32
+ export declare function isLowSignalBatch(lines: string[]): boolean;
33
+ export {};
34
+ //# sourceMappingURL=observation-signal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observation-signal.d.ts","sourceRoot":"","sources":["../src/observation-signal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC,UAAU,WAAW;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,CAuClE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAGzD"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Observation batch signal scoring.
3
+ * Determines whether a batch of observations contains enough signal
4
+ * to warrant running the analyzer (and spending tokens).
5
+ */
6
+ /**
7
+ * Score threshold below which a batch is considered low-signal.
8
+ * Batches scoring below this are skipped with a log entry.
9
+ */
10
+ export const LOW_SIGNAL_THRESHOLD = 3;
11
+ /**
12
+ * Scores an observation batch for signal richness.
13
+ *
14
+ * Scoring rules:
15
+ * - Error observation (is_error: true): +2 points
16
+ * - user_prompt after an error (user correction): +3 points
17
+ * - Other user_prompt events (potential corrections/redirections): +1 point
18
+ *
19
+ * @param lines - Raw JSONL observation lines (preprocessed or raw)
20
+ * @returns Score result with breakdown
21
+ */
22
+ export function scoreObservationBatch(lines) {
23
+ let score = 0;
24
+ let errors = 0;
25
+ let corrections = 0;
26
+ let userPrompts = 0;
27
+ let lastWasError = false;
28
+ for (const line of lines) {
29
+ const trimmed = line.trim();
30
+ if (!trimmed)
31
+ continue;
32
+ let obs;
33
+ try {
34
+ obs = JSON.parse(trimmed);
35
+ }
36
+ catch {
37
+ continue; // Skip malformed lines
38
+ }
39
+ if (obs.is_error) {
40
+ score += 2;
41
+ errors++;
42
+ lastWasError = true;
43
+ continue;
44
+ }
45
+ if (obs.event === "user_prompt") {
46
+ userPrompts++;
47
+ if (lastWasError) {
48
+ score += 3;
49
+ corrections++;
50
+ }
51
+ else {
52
+ score += 1;
53
+ }
54
+ }
55
+ lastWasError = false;
56
+ }
57
+ return { score, errors, corrections, userPrompts };
58
+ }
59
+ /**
60
+ * Returns true if the batch is low-signal and analysis should be skipped.
61
+ */
62
+ export function isLowSignalBatch(lines) {
63
+ const { score } = scoreObservationBatch(lines);
64
+ return score < LOW_SIGNAL_THRESHOLD;
65
+ }
66
+ //# sourceMappingURL=observation-signal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observation-signal.js","sourceRoot":"","sources":["../src/observation-signal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAStC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAe;IACnD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,YAAY,GAAG,KAAK,CAAC;IAEzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO;YAAE,SAAS;QAEvB,IAAI,GAAyB,CAAC;QAC9B,IAAI,CAAC;YACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAyB,CAAC;QACpD,CAAC;QAAC,MAAM,CAAC;YACP,SAAS,CAAC,uBAAuB;QACnC,CAAC;QAED,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,KAAK,IAAI,CAAC,CAAC;YACX,MAAM,EAAE,CAAC;YACT,YAAY,GAAG,IAAI,CAAC;YACpB,SAAS;QACX,CAAC;QAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,EAAE,CAAC;YAChC,WAAW,EAAE,CAAC;YACd,IAAI,YAAY,EAAE,CAAC;gBACjB,KAAK,IAAI,CAAC,CAAC;gBACX,WAAW,EAAE,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,KAAK,IAAI,CAAC,CAAC;YACb,CAAC;QACH,CAAC;QAED,YAAY,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAe;IAC9C,MAAM,EAAE,KAAK,EAAE,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,KAAK,GAAG,oBAAoB,CAAC;AACtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"analyzer-system-single-shot.d.ts","sourceRoot":"","sources":["../../src/prompts/analyzer-system-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CA8JpD"}
1
+ {"version":3,"file":"analyzer-system-single-shot.d.ts","sourceRoot":"","sources":["../../src/prompts/analyzer-system-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAqNpD"}
@@ -88,11 +88,50 @@ Each observation may include an active_instincts field listing instinct IDs
88
88
  that were injected into the agent's system prompt before that turn.
89
89
 
90
90
  Use this to update existing instinct confidence scores:
91
- - Confirmed (+0.05): instinct was active and agent followed guidance without correction
91
+ - Confirmed: instinct was active, agent followed guidance, user did NOT correct
92
92
  - Contradicted (-0.15): instinct was active but user corrected the agent
93
93
  - Inactive (no change): instinct was injected but trigger never arose
94
94
 
95
- When updating, increment the corresponding count field and recalculate confidence.
95
+ When updating, increment the corresponding count field.
96
+
97
+ ### Confirmation confidence deltas (diminishing returns)
98
+ Do NOT apply a flat +0.05 for every confirmation. Use these tiers based on the
99
+ instinct's current confirmed_count BEFORE this update:
100
+ - 1st-3rd confirmation (confirmed_count 0-2): +0.05
101
+ - 4th-6th confirmation (confirmed_count 3-5): +0.03
102
+ - 7th+ confirmation (confirmed_count 6+): +0.01
103
+
104
+ Note: the client applies these deltas automatically from confirmed_count.
105
+ You should still set the correct confirmed_count so the client can compute it.
106
+
107
+ ### Per-session confirmation deduplication
108
+ An instinct may only be confirmed ONCE per unique session_id. Each existing
109
+ instinct includes a last_confirmed_session field (if it has been confirmed before).
110
+
111
+ Rules:
112
+ - If all observations showing this instinct active belong to the same session as
113
+ last_confirmed_session, do NOT increment confirmed_count. The instinct already
114
+ received credit for that session.
115
+ - If a NEW session_id (different from last_confirmed_session) shows the instinct
116
+ active and followed, increment confirmed_count by 1 and set last_confirmed_session
117
+ to that new session_id.
118
+ - When creating a new instinct with initial confirmed_count > 0, set
119
+ last_confirmed_session to the session_id that provided the confirmation.
120
+
121
+ ### Baseline behavior filtering
122
+ Do NOT mark an instinct as "confirmed" if the agent's behavior would be expected
123
+ baseline practice regardless of whether the instinct was injected.
124
+
125
+ Examples of baseline behavior that should NOT count as confirmation:
126
+ - Reading a file before editing it
127
+ - Running a linter or type-checker after code changes
128
+ - Using conventional commit message format
129
+ - Checking for errors after tool calls
130
+ - Clarifying ambiguous requirements before starting
131
+
132
+ Only count a confirmation when the instinct guided behavior that would plausibly
133
+ NOT have occurred without it (e.g., a project-specific workflow, a non-obvious
134
+ convention, or a recovery pattern the agent had to learn).
96
135
 
97
136
  ## Confidence Scoring Rules
98
137
 
@@ -111,6 +150,21 @@ Use project scope when the pattern is specific to this project's tech stack or c
111
150
  Use global scope when the pattern applies universally to any coding session.
112
151
  When in doubt, prefer project scope.
113
152
 
153
+ ## Contradiction Detection
154
+
155
+ Before creating or updating instincts, check existing instincts for contradictions:
156
+ two instincts with similar triggers but semantically opposing actions.
157
+
158
+ Examples of contradictory pairs:
159
+ - "When designing APIs" -> "prefer interfaces" vs "avoid interfaces, use concrete types"
160
+ - "When writing tests" -> "always mock dependencies" vs "never mock, use real implementations"
161
+ - "When handling errors" -> "throw exceptions" vs "avoid exceptions, use Result types"
162
+
163
+ When you detect a contradiction:
164
+ 1. **If observations clearly support one side**: Delete the contradicted instinct (emit a "delete" change) and optionally boost the confirmed instinct's confidence.
165
+ 2. **If evidence is ambiguous**: Delete BOTH and create a single nuanced instinct that captures the context-dependent guidance (e.g., "prefer interfaces for public APIs, concrete types for internal helpers").
166
+ 3. **Do not create a new instinct that contradicts an existing one** without resolving the conflict first.
167
+
114
168
  ## Conservativeness Rules
115
169
 
116
170
  1. Only create a new instinct with 3+ clear independent observations supporting the pattern.
@@ -120,6 +174,7 @@ When in doubt, prefer project scope.
120
174
  5. Check existing instincts (provided in the user message) for duplicates before creating. Update instead.
121
175
  6. Write actions as clear instructions starting with a verb.
122
176
  7. Be skeptical of outliers - patterns seen only in unusual circumstances should not become instincts.
177
+ 8. Before creating, verify the new instinct does not contradict any existing instinct (see Contradiction Detection above).
123
178
 
124
179
  ## Quality Tiers
125
180
 
@@ -1 +1 @@
1
- {"version":3,"file":"analyzer-system-single-shot.js","sourceRoot":"","sources":["../../src/prompts/analyzer-system-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6EA4JoE,CAAC;AAC9E,CAAC"}
1
+ {"version":3,"file":"analyzer-system-single-shot.js","sourceRoot":"","sources":["../../src/prompts/analyzer-system-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,2BAA2B;IACzC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6EAmNoE,CAAC;AAC9E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"analyzer-user-single-shot.d.ts","sourceRoot":"","sources":["../../src/prompts/analyzer-user-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG1E,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,YAAY,EACrB,iBAAiB,EAAE,QAAQ,EAAE,EAC7B,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE,uBAA4B,GACpC,MAAM,CAiER"}
1
+ {"version":3,"file":"analyzer-user-single-shot.d.ts","sourceRoot":"","sources":["../../src/prompts/analyzer-user-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG1E,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,YAAY,EACrB,iBAAiB,EAAE,QAAQ,EAAE,EAC7B,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,GAAE,uBAA4B,GACpC,MAAM,CAsER"}
@@ -1,4 +1,4 @@
1
- import { formatInstinctsForPrompt } from "../cli/analyze-single-shot.js";
1
+ import { formatInstinctsCompact } from "../cli/analyze-single-shot.js";
2
2
  /**
3
3
  * Builds the user prompt for the single-shot analyzer.
4
4
  * Embeds all current instincts inline so the model has full context
@@ -14,7 +14,9 @@ export function buildSingleShotUserPrompt(project, existingInstincts, observatio
14
14
  const observationBlock = observationLines.length > 0
15
15
  ? observationLines.join("\n")
16
16
  : "(no observations recorded yet)";
17
- const instinctBlock = formatInstinctsForPrompt(existingInstincts);
17
+ const instinctBlock = existingInstincts.length > 0
18
+ ? formatInstinctsCompact(existingInstincts)
19
+ : "(no existing instincts)";
18
20
  const parts = [
19
21
  "## Project Context",
20
22
  "",
@@ -47,7 +49,7 @@ export function buildSingleShotUserPrompt(project, existingInstincts, observatio
47
49
  }
48
50
  parts.push("");
49
51
  }
50
- parts.push("", "## Instructions", "", "1. Review the existing instincts above.", "2. Analyze the new observations for patterns per the system prompt rules.", "3. Return a JSON change-set: create new instincts, update existing ones, or delete obsolete ones.", "4. Apply feedback analysis using the active_instincts field in each observation.", "5. Passive confidence decay has already been applied before this analysis.", "6. Before creating any instinct, check the Existing Guidelines section above.", " If the pattern is already covered by AGENTS.md, do NOT create an instinct for it.", "7. Apply the Quality Tier rules from the system prompt:", " - Generic agent behaviors (read-before-edit, clarify-before-implement) -> skip entirely", " - Project-specific patterns -> project-scoped instinct", " - Universal workflow patterns -> global-scoped instinct", "", "Return ONLY the JSON object. No prose, no markdown fences.");
52
+ parts.push("", "## Instructions", "", "1. Review the existing instincts above.", "2. Analyze the new observations for patterns per the system prompt rules.", "3. Return a JSON change-set: create new instincts, update existing ones, or delete obsolete ones.", "4. Apply feedback analysis using the active_instincts field in each observation.", "5. Passive confidence decay has already been applied before this analysis.", "6. Before creating any instinct, check the Existing Guidelines section above.", " If the pattern is already covered by AGENTS.md, do NOT create an instinct for it.", "7. Apply the Quality Tier rules from the system prompt:", " - Generic agent behaviors (read-before-edit, clarify-before-implement) -> skip entirely", " - Project-specific patterns -> project-scoped instinct", " - Universal workflow patterns -> global-scoped instinct", "8. Check existing instincts for contradictions (similar triggers, opposing actions).", " Resolve by deleting the weaker instinct or merging into a nuanced one.", "", "Return ONLY the JSON object. No prose, no markdown fences.");
51
53
  return parts.join("\n");
52
54
  }
53
55
  //# sourceMappingURL=analyzer-user-single-shot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"analyzer-user-single-shot.js","sourceRoot":"","sources":["../../src/prompts/analyzer-user-single-shot.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAQzE;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAqB,EACrB,iBAA6B,EAC7B,gBAA0B,EAC1B,UAAmC,EAAE;IAErC,MAAM,EAAE,eAAe,GAAG,IAAI,EAAE,cAAc,GAAG,IAAI,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAExF,MAAM,gBAAgB,GACpB,gBAAgB,CAAC,MAAM,GAAG,CAAC;QACzB,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7B,CAAC,CAAC,gCAAgC,CAAC;IAEvC,MAAM,aAAa,GAAG,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;IAElE,MAAM,KAAK,GAAa;QACtB,oBAAoB;QACpB,EAAE;QACF,eAAe,OAAO,CAAC,EAAE,EAAE;QAC3B,iBAAiB,OAAO,CAAC,IAAI,EAAE;QAC/B,EAAE;QACF,uBAAuB;QACvB,EAAE;QACF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AAI,CAAC,sBAAsB,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,EAAE,EACF,iBAAiB,EACjB,EAAE,EACF,yCAAyC,EACzC,2EAA2E,EAC3E,mGAAmG,EACnG,kFAAkF,EAClF,4EAA4E,EAC5E,+EAA+E,EAC/E,sFAAsF,EACtF,yDAAyD,EACzD,4FAA4F,EAC5F,2DAA2D,EAC3D,4DAA4D,EAC5D,sFAAsF,EACtF,2EAA2E,EAC3E,EAAE,EACF,4DAA4D,CAC7D,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * System prompt for the consolidation (dream) pass.
3
+ * Reviews the entire instinct corpus holistically - no observations needed.
4
+ */
5
+ export declare function buildConsolidateSystemPrompt(): string;
6
+ //# sourceMappingURL=consolidate-system.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consolidate-system.d.ts","sourceRoot":"","sources":["../../src/prompts/consolidate-system.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAgGrD"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * System prompt for the consolidation (dream) pass.
3
+ * Reviews the entire instinct corpus holistically - no observations needed.
4
+ */
5
+ export function buildConsolidateSystemPrompt() {
6
+ return `You are a coding behavior analyst performing a periodic consolidation review.
7
+ Your job is to review the entire instinct corpus holistically and produce a JSON change-set
8
+ that merges duplicates, removes stale entries, resolves contradictions, and promotes mature instincts.
9
+
10
+ ## Output Format
11
+
12
+ Return ONLY a valid JSON object (no prose, no markdown fences) with this structure:
13
+
14
+ {
15
+ "changes": [
16
+ {
17
+ "action": "create",
18
+ "instinct": {
19
+ "id": "kebab-case-id",
20
+ "title": "Short title",
21
+ "trigger": "When this should activate",
22
+ "action": "What the agent should do (verb phrase)",
23
+ "confidence": 0.5,
24
+ "domain": "typescript",
25
+ "scope": "project",
26
+ "observation_count": 3,
27
+ "confirmed_count": 0,
28
+ "contradicted_count": 0,
29
+ "inactive_count": 0,
30
+ "evidence": ["brief note 1", "brief note 2"]
31
+ }
32
+ },
33
+ {
34
+ "action": "update",
35
+ "instinct": { "...same fields as create..." }
36
+ },
37
+ {
38
+ "action": "delete",
39
+ "id": "instinct-id-to-delete",
40
+ "scope": "project"
41
+ }
42
+ ]
43
+ }
44
+
45
+ Return { "changes": [] } if no changes are needed.
46
+
47
+ ## Consolidation Tasks
48
+
49
+ Perform these analyses on the full instinct corpus:
50
+
51
+ ### 1. Merge Candidates
52
+ Find instincts with semantically similar triggers or actions, even if worded differently.
53
+ Merge them into a single stronger instinct:
54
+ - Delete both originals
55
+ - Create one merged instinct with combined evidence
56
+ - Set confidence to the higher of the two (capped at 0.9)
57
+ - Sum observation_count and confirmed_count from both
58
+
59
+ ### 2. Contradiction Resolution
60
+ Find instincts with similar triggers but opposing actions:
61
+ - "prefer X" vs "avoid X"
62
+ - "always do Y" vs "never do Y"
63
+ - "use A" vs "don't use A"
64
+
65
+ Resolution strategy:
66
+ - If one has clearly higher confidence (>0.1 difference): delete the weaker one
67
+ - If confidence is similar but one has more confirmations: keep the more confirmed one
68
+ - If evidence is truly ambiguous: delete both, create a nuanced context-dependent instinct
69
+
70
+ ### 3. Stale Instinct Detection
71
+ Flag instincts that reference patterns unlikely to still be relevant:
72
+ - Evidence references specific files or tools that may no longer exist
73
+ - Very old instincts (28+ days) with zero confirmations
74
+ - Instincts with high inactive_count relative to confirmed_count
75
+
76
+ ### 4. Promotion Candidates
77
+ Identify project-scoped instincts that should become global:
78
+ - Confidence >= 0.7
79
+ - confirmed_count >= 3
80
+ - Pattern is not project-specific (no project-specific file paths, tools, or conventions)
81
+
82
+ To promote: delete the project-scoped version and create a global-scoped version with the same data.
83
+
84
+ ### 5. AGENTS.md Deduplication
85
+ Check if any instincts are already covered by AGENTS.md guidelines.
86
+ Delete instincts that duplicate existing written guidelines.
87
+
88
+ ### 6. Quality Cleanup
89
+ - Delete instincts with confidence < 0.2
90
+ - Delete instincts flagged_for_removal
91
+ - Rewrite vague triggers or actions to be more specific (update action)
92
+
93
+ ## Conservativeness Rules
94
+
95
+ 1. Prefer fewer changes over many - only act when the improvement is clear
96
+ 2. When merging, preserve the essence of both instincts in the merged version
97
+ 3. Do not create new instincts from scratch - only merge or modify existing ones
98
+ 4. Clamping: always keep confidence in [0.1, 0.9]
99
+ 5. Write actions as clear instructions starting with a verb
100
+ 6. If unsure about a change, skip it - the next consolidation will catch it`;
101
+ }
102
+ //# sourceMappingURL=consolidate-system.js.map