pi-continuous-learning 0.8.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.
- package/dist/cli/analyze.js +237 -13
- package/dist/cli/analyze.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -1
- package/dist/consolidation.d.ts +43 -0
- package/dist/consolidation.d.ts.map +1 -0
- package/dist/consolidation.js +104 -0
- package/dist/consolidation.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/instinct-cleanup.d.ts +14 -0
- package/dist/instinct-cleanup.d.ts.map +1 -1
- package/dist/instinct-cleanup.js +59 -3
- package/dist/instinct-cleanup.js.map +1 -1
- package/dist/instinct-contradiction.d.ts +42 -0
- package/dist/instinct-contradiction.d.ts.map +1 -0
- package/dist/instinct-contradiction.js +164 -0
- package/dist/instinct-contradiction.js.map +1 -0
- package/dist/instinct-dream.d.ts +12 -0
- package/dist/instinct-dream.d.ts.map +1 -0
- package/dist/instinct-dream.js +33 -0
- package/dist/instinct-dream.js.map +1 -0
- package/dist/prompts/analyzer-system-single-shot.d.ts.map +1 -1
- package/dist/prompts/analyzer-system-single-shot.js +16 -0
- package/dist/prompts/analyzer-system-single-shot.js.map +1 -1
- package/dist/prompts/analyzer-user-single-shot.d.ts.map +1 -1
- package/dist/prompts/analyzer-user-single-shot.js +1 -1
- package/dist/prompts/analyzer-user-single-shot.js.map +1 -1
- package/dist/prompts/consolidate-system.d.ts +6 -0
- package/dist/prompts/consolidate-system.d.ts.map +1 -0
- package/dist/prompts/consolidate-system.js +102 -0
- package/dist/prompts/consolidate-system.js.map +1 -0
- package/dist/prompts/consolidate-user.d.ts +19 -0
- package/dist/prompts/consolidate-user.d.ts.map +1 -0
- package/dist/prompts/consolidate-user.js +45 -0
- package/dist/prompts/consolidate-user.js.map +1 -0
- package/dist/prompts/dream-prompt.d.ts +7 -0
- package/dist/prompts/dream-prompt.d.ts.map +1 -0
- package/dist/prompts/dream-prompt.js +64 -0
- package/dist/prompts/dream-prompt.js.map +1 -0
- package/dist/prompts/evolve-prompt.d.ts.map +1 -1
- package/dist/prompts/evolve-prompt.js +6 -5
- package/dist/prompts/evolve-prompt.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/analyze.ts +268 -13
- package/src/config.ts +10 -0
- package/src/consolidation.ts +162 -0
- package/src/index.ts +15 -0
- package/src/instinct-cleanup.ts +62 -3
- package/src/instinct-contradiction.ts +202 -0
- package/src/instinct-dream.ts +62 -0
- package/src/prompts/analyzer-system-single-shot.ts +16 -0
- package/src/prompts/analyzer-user-single-shot.ts +2 -0
- package/src/prompts/consolidate-system.ts +101 -0
- package/src/prompts/consolidate-user.ts +88 -0
- package/src/prompts/dream-prompt.ts +88 -0
- package/src/prompts/evolve-prompt.ts +6 -5
- package/src/types.ts +4 -0
|
@@ -32,9 +32,18 @@ export declare function cleanupZeroConfirmedInstincts(dir: string, ttlDays: numb
|
|
|
32
32
|
* @returns Number of instincts deleted.
|
|
33
33
|
*/
|
|
34
34
|
export declare function enforceInstinctCap(dir: string, maxCount: number): number;
|
|
35
|
+
/**
|
|
36
|
+
* Flags the lower-confidence instinct in each contradictory pair.
|
|
37
|
+
* When confidence is equal, both are flagged.
|
|
38
|
+
* Already-flagged instincts are excluded from contradiction detection.
|
|
39
|
+
*
|
|
40
|
+
* @returns Number of instincts newly flagged.
|
|
41
|
+
*/
|
|
42
|
+
export declare function cleanupContradictions(dir: string): number;
|
|
35
43
|
export interface CleanupResult {
|
|
36
44
|
flaggedDeleted: number;
|
|
37
45
|
zeroConfirmedDeleted: number;
|
|
46
|
+
contradictionsFlagged: number;
|
|
38
47
|
capDeleted: number;
|
|
39
48
|
total: number;
|
|
40
49
|
}
|
|
@@ -43,6 +52,11 @@ export interface CleanupResult {
|
|
|
43
52
|
* Order: flagged → zero-confirmed → cap enforcement (cap runs last so it
|
|
44
53
|
* accounts for deletions made by the earlier rules).
|
|
45
54
|
*/
|
|
55
|
+
/**
|
|
56
|
+
* Runs all cleanup rules against a single directory.
|
|
57
|
+
* Order: flagged → zero-confirmed → contradictions → cap enforcement
|
|
58
|
+
* (cap runs last so it accounts for deletions/flags from earlier rules).
|
|
59
|
+
*/
|
|
46
60
|
export declare function cleanupDir(dir: string, config: Config, maxCount: number): CleanupResult;
|
|
47
61
|
/**
|
|
48
62
|
* Runs a full cleanup pass over project and global instinct directories.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instinct-cleanup.d.ts","sourceRoot":"","sources":["../src/instinct-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"instinct-cleanup.d.ts","sourceRoot":"","sources":["../src/instinct-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,YAAY,CAAC;AAgCnD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,EACX,kBAAkB,EAAE,MAAM,GACzB,MAAM,CAeR;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,MAAM,CAeR;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgBxE;AAMD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAmCzD;AAMD,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;;GAIG;AACH;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,aAAa,CAUf;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,MAAM,EAAE,MAAM,EACd,OAAO,SAAe,GACrB,aAAa,CAoCf"}
|
package/dist/instinct-cleanup.js
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { unlinkSync, existsSync } from "node:fs";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
-
import { listInstincts, invalidateCache } from "./instinct-store.js";
|
|
12
|
+
import { listInstincts, saveInstinct, invalidateCache } from "./instinct-store.js";
|
|
13
13
|
import { getBaseDir, getProjectInstinctsDir, getGlobalInstinctsDir, } from "./storage.js";
|
|
14
|
+
import { findContradictions } from "./instinct-contradiction.js";
|
|
14
15
|
// ---------------------------------------------------------------------------
|
|
15
16
|
// Helpers
|
|
16
17
|
// ---------------------------------------------------------------------------
|
|
@@ -101,6 +102,52 @@ export function enforceInstinctCap(dir, maxCount) {
|
|
|
101
102
|
return deleted;
|
|
102
103
|
}
|
|
103
104
|
// ---------------------------------------------------------------------------
|
|
105
|
+
// Result type
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
/**
|
|
108
|
+
* Flags the lower-confidence instinct in each contradictory pair.
|
|
109
|
+
* When confidence is equal, both are flagged.
|
|
110
|
+
* Already-flagged instincts are excluded from contradiction detection.
|
|
111
|
+
*
|
|
112
|
+
* @returns Number of instincts newly flagged.
|
|
113
|
+
*/
|
|
114
|
+
export function cleanupContradictions(dir) {
|
|
115
|
+
const instincts = listInstincts(dir);
|
|
116
|
+
const matches = findContradictions(instincts);
|
|
117
|
+
if (matches.length === 0)
|
|
118
|
+
return 0;
|
|
119
|
+
const toFlag = new Set();
|
|
120
|
+
for (const match of matches) {
|
|
121
|
+
const { instinctA, instinctB } = match;
|
|
122
|
+
if (instinctA.confidence > instinctB.confidence) {
|
|
123
|
+
toFlag.add(instinctB.id);
|
|
124
|
+
}
|
|
125
|
+
else if (instinctB.confidence > instinctA.confidence) {
|
|
126
|
+
toFlag.add(instinctA.id);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// Equal confidence - flag both for user review
|
|
130
|
+
toFlag.add(instinctA.id);
|
|
131
|
+
toFlag.add(instinctB.id);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
let flagged = 0;
|
|
135
|
+
for (const instinct of instincts) {
|
|
136
|
+
if (toFlag.has(instinct.id)) {
|
|
137
|
+
const updated = {
|
|
138
|
+
...instinct,
|
|
139
|
+
flagged_for_removal: true,
|
|
140
|
+
updated_at: new Date().toISOString(),
|
|
141
|
+
};
|
|
142
|
+
saveInstinct(updated, dir);
|
|
143
|
+
flagged++;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (flagged > 0)
|
|
147
|
+
invalidateCache(dir);
|
|
148
|
+
return flagged;
|
|
149
|
+
}
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
104
151
|
// Orchestrator
|
|
105
152
|
// ---------------------------------------------------------------------------
|
|
106
153
|
/**
|
|
@@ -108,12 +155,18 @@ export function enforceInstinctCap(dir, maxCount) {
|
|
|
108
155
|
* Order: flagged → zero-confirmed → cap enforcement (cap runs last so it
|
|
109
156
|
* accounts for deletions made by the earlier rules).
|
|
110
157
|
*/
|
|
158
|
+
/**
|
|
159
|
+
* Runs all cleanup rules against a single directory.
|
|
160
|
+
* Order: flagged → zero-confirmed → contradictions → cap enforcement
|
|
161
|
+
* (cap runs last so it accounts for deletions/flags from earlier rules).
|
|
162
|
+
*/
|
|
111
163
|
export function cleanupDir(dir, config, maxCount) {
|
|
112
164
|
const flaggedDeleted = cleanupFlaggedInstincts(dir, config.flagged_cleanup_days);
|
|
113
165
|
const zeroConfirmedDeleted = cleanupZeroConfirmedInstincts(dir, config.instinct_ttl_days);
|
|
166
|
+
const contradictionsFlagged = cleanupContradictions(dir);
|
|
114
167
|
const capDeleted = enforceInstinctCap(dir, maxCount);
|
|
115
|
-
const total = flaggedDeleted + zeroConfirmedDeleted + capDeleted;
|
|
116
|
-
return { flaggedDeleted, zeroConfirmedDeleted, capDeleted, total };
|
|
168
|
+
const total = flaggedDeleted + zeroConfirmedDeleted + contradictionsFlagged + capDeleted;
|
|
169
|
+
return { flaggedDeleted, zeroConfirmedDeleted, contradictionsFlagged, capDeleted, total };
|
|
117
170
|
}
|
|
118
171
|
/**
|
|
119
172
|
* Runs a full cleanup pass over project and global instinct directories.
|
|
@@ -128,6 +181,7 @@ export function runCleanupPass(projectId, config, baseDir = getBaseDir()) {
|
|
|
128
181
|
const result = {
|
|
129
182
|
flaggedDeleted: 0,
|
|
130
183
|
zeroConfirmedDeleted: 0,
|
|
184
|
+
contradictionsFlagged: 0,
|
|
131
185
|
capDeleted: 0,
|
|
132
186
|
total: 0,
|
|
133
187
|
};
|
|
@@ -136,6 +190,7 @@ export function runCleanupPass(projectId, config, baseDir = getBaseDir()) {
|
|
|
136
190
|
const projectResult = cleanupDir(projectDir, config, config.max_total_instincts_per_project);
|
|
137
191
|
result.flaggedDeleted += projectResult.flaggedDeleted;
|
|
138
192
|
result.zeroConfirmedDeleted += projectResult.zeroConfirmedDeleted;
|
|
193
|
+
result.contradictionsFlagged += projectResult.contradictionsFlagged;
|
|
139
194
|
result.capDeleted += projectResult.capDeleted;
|
|
140
195
|
result.total += projectResult.total;
|
|
141
196
|
}
|
|
@@ -143,6 +198,7 @@ export function runCleanupPass(projectId, config, baseDir = getBaseDir()) {
|
|
|
143
198
|
const globalResult = cleanupDir(globalDir, config, config.max_total_instincts_global);
|
|
144
199
|
result.flaggedDeleted += globalResult.flaggedDeleted;
|
|
145
200
|
result.zeroConfirmedDeleted += globalResult.zeroConfirmedDeleted;
|
|
201
|
+
result.contradictionsFlagged += globalResult.contradictionsFlagged;
|
|
146
202
|
result.capDeleted += globalResult.capDeleted;
|
|
147
203
|
result.total += globalResult.total;
|
|
148
204
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instinct-cleanup.js","sourceRoot":"","sources":["../src/instinct-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"instinct-cleanup.js","sourceRoot":"","sources":["../src/instinct-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,SAAS,CAAC,OAAe;IAChC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAkB,EAAE,GAAW;IACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAA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AAU,EAAE,OAAO,CAAC,CAAC;IAC7D,MAAM,YAAY,GAAG,UAAU,CAC7B,SAAS,EACT,MAAM,EACN,MAAM,CAAC,0BAA0B,CAClC,CAAC;IACF,MAAM,CAAC,cAAc,IAAI,YAAY,CAAC,cAAc,CAAC;IACrD,MAAM,CAAC,oBAAoB,IAAI,YAAY,CAAC,oBAAoB,CAAC;IACjE,MAAM,CAAC,qBAAqB,IAAI,YAAY,CAAC,qBAAqB,CAAC;IACnE,MAAM,CAAC,UAAU,IAAI,YAAY,CAAC,UAAU,CAAC;IAC7C,MAAM,CAAC,KAAK,IAAI,YAAY,CAAC,KAAK,CAAC;IAEnC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 type { Instinct } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Pairs of verbs/keywords that indicate opposing intent when one appears
|
|
11
|
+
* in each action. Order within each pair does not matter.
|
|
12
|
+
*/
|
|
13
|
+
export declare const OPPOSING_VERB_PAIRS: ReadonlyArray<readonly [string, string]>;
|
|
14
|
+
export interface ContradictionMatch {
|
|
15
|
+
instinctA: Instinct;
|
|
16
|
+
instinctB: Instinct;
|
|
17
|
+
triggerSimilarity: number;
|
|
18
|
+
reason: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks whether two actions are semantically opposing using verb pair matching
|
|
22
|
+
* and negation pattern detection.
|
|
23
|
+
*
|
|
24
|
+
* @returns A reason string if opposing, null otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasOpposingAction(actionA: string, actionB: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Finds all contradictory pairs in a set of instincts.
|
|
29
|
+
*
|
|
30
|
+
* A contradiction is defined as:
|
|
31
|
+
* 1. Similar triggers (Jaccard similarity >= threshold on trigger tokens)
|
|
32
|
+
* 2. Opposing actions (detected via verb pairs or negation patterns)
|
|
33
|
+
*
|
|
34
|
+
* Instincts with `flagged_for_removal` are excluded.
|
|
35
|
+
* Each pair is reported once (no duplicates).
|
|
36
|
+
*
|
|
37
|
+
* @param instincts - All instincts to check
|
|
38
|
+
* @param triggerThreshold - Jaccard similarity threshold for triggers (default 0.4)
|
|
39
|
+
* @returns Array of contradiction matches
|
|
40
|
+
*/
|
|
41
|
+
export declare function findContradictions(instincts: readonly Instinct[], triggerThreshold?: number): ContradictionMatch[];
|
|
42
|
+
//# sourceMappingURL=instinct-contradiction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instinct-contradiction.d.ts","sourceRoot":"","sources":["../src/instinct-contradiction.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAU3C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAe/D,CAAC;AAqEX,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,QAAQ,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwBjF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,gBAAgB,SAA4B,GAC3C,kBAAkB,EAAE,CAuCtB"}
|
|
@@ -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;;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,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,2BAA2B;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC;YACrB,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC;YAErB,mCAAmC;YACnC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAC;YACzC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,CAAC;YACzC,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAEvD,IAAI,UAAU,GAAG,gBAAgB;gBAAE,SAAS;YAE5C,kCAAkC;YAClC,MAAM,MAAM,GAAG,iBAAiB,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;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACj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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":"analyzer-system-single-shot.d.ts","sourceRoot":"","sources":["../../src/prompts/analyzer-system-single-shot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,
|
|
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"}
|
|
@@ -150,6 +150,21 @@ Use project scope when the pattern is specific to this project's tech stack or c
|
|
|
150
150
|
Use global scope when the pattern applies universally to any coding session.
|
|
151
151
|
When in doubt, prefer project scope.
|
|
152
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
|
+
|
|
153
168
|
## Conservativeness Rules
|
|
154
169
|
|
|
155
170
|
1. Only create a new instinct with 3+ clear independent observations supporting the pattern.
|
|
@@ -159,6 +174,7 @@ When in doubt, prefer project scope.
|
|
|
159
174
|
5. Check existing instincts (provided in the user message) for duplicates before creating. Update instead.
|
|
160
175
|
6. Write actions as clear instructions starting with a verb.
|
|
161
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).
|
|
162
178
|
|
|
163
179
|
## Quality Tiers
|
|
164
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
|
|
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,
|
|
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"}
|
|
@@ -49,7 +49,7 @@ export function buildSingleShotUserPrompt(project, existingInstincts, observatio
|
|
|
49
49
|
}
|
|
50
50
|
parts.push("");
|
|
51
51
|
}
|
|
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", "", "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.");
|
|
53
53
|
return parts.join("\n");
|
|
54
54
|
}
|
|
55
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,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAQvE;;;;;;;;;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,IAA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AAC;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,EAAE,EACF,4DAA4D,CAC7D,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
1
|
+
{"version":3,"file":"analyzer-user-single-shot.js","sourceRoot":"","sources":["../../src/prompts/analyzer-user-single-shot.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAQvE;;;;;;;;;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,GACjB,iBAAiB,CAAC,MAAM,GAAG,CAAC;QAC1B,CAAC,CAAC,sBAAsB,CAAC,iBAAiB,CAAC;QAC3C,CAAC,CAAC,yBAAyB,CAAC;IAEhC,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,aAAa;QACb,EAAE;QACF,oCAAoC;QACpC,EAAE;QACF,KAAK;QACL,gBAAgB;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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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consolidate-system.js","sourceRoot":"","sources":["../../src/prompts/consolidate-system.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EA8FmE,CAAC;AAC7E,CAAC"}
|