crewly 1.4.41 → 1.4.42
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/config/roles/orchestrator/fragments/communication.md +117 -0
- package/config/roles/orchestrator/fragments/lifecycle.md +112 -0
- package/config/roles/orchestrator/fragments/recovery.md +47 -0
- package/dist/backend/backend/src/services/agent/agent-registration.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/agent/agent-registration.service.js +6 -0
- package/dist/backend/backend/src/services/agent/agent-registration.service.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-builder.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-builder.service.js +5 -0
- package/dist/backend/backend/src/services/ai/prompt-builder.service.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.js +6 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/communication.module.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.d.ts +16 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.js +30 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/context-assembly.service.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/index.d.ts +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/index.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/index.js +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/index.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.js +8 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.d.ts +29 -12
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.js +159 -66
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-assembly.service.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.d.ts +35 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.js +23 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/prompt-module.interface.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.js +8 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/recovery.module.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.d.ts +10 -0
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.js +55 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/soul.module.js.map +1 -1
- package/dist/backend/backend/src/services/ai/self-improvement/attention.service.d.ts +74 -0
- package/dist/backend/backend/src/services/ai/self-improvement/attention.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/attention.service.js +132 -0
- package/dist/backend/backend/src/services/ai/self-improvement/attention.service.js.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/growth-areas.service.d.ts +81 -0
- package/dist/backend/backend/src/services/ai/self-improvement/growth-areas.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/growth-areas.service.js +135 -0
- package/dist/backend/backend/src/services/ai/self-improvement/growth-areas.service.js.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/index.d.ts +13 -0
- package/dist/backend/backend/src/services/ai/self-improvement/index.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/index.js +13 -0
- package/dist/backend/backend/src/services/ai/self-improvement/index.js.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/memory-consolidation.service.d.ts +107 -0
- package/dist/backend/backend/src/services/ai/self-improvement/memory-consolidation.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/memory-consolidation.service.js +183 -0
- package/dist/backend/backend/src/services/ai/self-improvement/memory-consolidation.service.js.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/prediction-calibration.service.d.ts +97 -0
- package/dist/backend/backend/src/services/ai/self-improvement/prediction-calibration.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/prediction-calibration.service.js +128 -0
- package/dist/backend/backend/src/services/ai/self-improvement/prediction-calibration.service.js.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/self-model.service.d.ts +95 -0
- package/dist/backend/backend/src/services/ai/self-improvement/self-model.service.d.ts.map +1 -0
- package/dist/backend/backend/src/services/ai/self-improvement/self-model.service.js +116 -0
- package/dist/backend/backend/src/services/ai/self-improvement/self-model.service.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Service for cross-layer memory consolidation.
|
|
5
|
+
*
|
|
6
|
+
* Reads all agent memories (learnings, failures, successes), identifies
|
|
7
|
+
* recurring patterns, and generates a consolidation report. Can be run
|
|
8
|
+
* periodically (e.g., weekly) to keep insights fresh.
|
|
9
|
+
*
|
|
10
|
+
* Storage: ~/.crewly/agents/{sessionName}/consolidation.json
|
|
11
|
+
*/
|
|
12
|
+
export class MemoryConsolidationService {
|
|
13
|
+
memoryProvider;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new MemoryConsolidationService.
|
|
16
|
+
*
|
|
17
|
+
* @param memoryProvider - Function that retrieves agent memories
|
|
18
|
+
*/
|
|
19
|
+
constructor(memoryProvider) {
|
|
20
|
+
this.memoryProvider = memoryProvider;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the file path for an agent's consolidation report.
|
|
24
|
+
*
|
|
25
|
+
* @param sessionName - Agent session name
|
|
26
|
+
* @returns Absolute path to consolidation.json
|
|
27
|
+
*/
|
|
28
|
+
getFilePath(sessionName) {
|
|
29
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '/tmp';
|
|
30
|
+
return path.join(homeDir, '.crewly', 'agents', sessionName, 'consolidation.json');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Read the most recent consolidation report from disk.
|
|
34
|
+
*
|
|
35
|
+
* @param sessionName - Agent session name
|
|
36
|
+
* @returns Consolidation report, or empty default if none exists
|
|
37
|
+
*/
|
|
38
|
+
async getReport(sessionName) {
|
|
39
|
+
try {
|
|
40
|
+
const filePath = this.getFilePath(sessionName);
|
|
41
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
42
|
+
return JSON.parse(raw);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return {
|
|
46
|
+
patterns: [],
|
|
47
|
+
insights: [],
|
|
48
|
+
consolidatedAt: '',
|
|
49
|
+
memoriesAnalyzed: 0,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run consolidation analysis on all agent memories.
|
|
55
|
+
*
|
|
56
|
+
* Identifies recurring patterns by counting word/phrase frequency
|
|
57
|
+
* across memories and extracting common themes.
|
|
58
|
+
*
|
|
59
|
+
* @param sessionName - Agent session name
|
|
60
|
+
* @returns The generated consolidation report
|
|
61
|
+
*/
|
|
62
|
+
async consolidate(sessionName) {
|
|
63
|
+
const memories = await this.memoryProvider(sessionName);
|
|
64
|
+
if (memories.length === 0) {
|
|
65
|
+
const emptyReport = {
|
|
66
|
+
patterns: [],
|
|
67
|
+
insights: [],
|
|
68
|
+
consolidatedAt: new Date().toISOString(),
|
|
69
|
+
memoriesAnalyzed: 0,
|
|
70
|
+
};
|
|
71
|
+
await this.save(sessionName, emptyReport);
|
|
72
|
+
return emptyReport;
|
|
73
|
+
}
|
|
74
|
+
const patterns = this.extractPatterns(memories);
|
|
75
|
+
const insights = this.deriveInsights(memories, patterns);
|
|
76
|
+
const report = {
|
|
77
|
+
patterns,
|
|
78
|
+
insights,
|
|
79
|
+
consolidatedAt: new Date().toISOString(),
|
|
80
|
+
memoriesAnalyzed: memories.length,
|
|
81
|
+
};
|
|
82
|
+
await this.save(sessionName, report);
|
|
83
|
+
return report;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extract recurring patterns from memories by analyzing keyword frequency.
|
|
87
|
+
*
|
|
88
|
+
* @param memories - Array of memory text strings
|
|
89
|
+
* @returns Identified patterns sorted by occurrence count
|
|
90
|
+
*/
|
|
91
|
+
extractPatterns(memories) {
|
|
92
|
+
const keyPhrases = {};
|
|
93
|
+
const now = new Date().toISOString().split('T')[0];
|
|
94
|
+
// Track keyword groups
|
|
95
|
+
const topicKeywords = {
|
|
96
|
+
'error handling': ['error', 'exception', 'catch', 'throw', 'failure'],
|
|
97
|
+
'testing': ['test', 'coverage', 'jest', 'assert', 'mock'],
|
|
98
|
+
'performance': ['performance', 'slow', 'optimize', 'cache', 'latency'],
|
|
99
|
+
'async patterns': ['async', 'await', 'promise', 'concurrent', 'race'],
|
|
100
|
+
'type safety': ['type', 'typescript', 'interface', 'generic', 'cast'],
|
|
101
|
+
'code quality': ['refactor', 'clean', 'duplicate', 'pattern', 'convention'],
|
|
102
|
+
'deployment': ['deploy', 'docker', 'build', 'release', 'production'],
|
|
103
|
+
'security': ['security', 'auth', 'token', 'credential', 'vulnerability'],
|
|
104
|
+
};
|
|
105
|
+
for (const memory of memories) {
|
|
106
|
+
const lower = memory.toLowerCase();
|
|
107
|
+
for (const [topic, keywords] of Object.entries(topicKeywords)) {
|
|
108
|
+
const hits = keywords.filter((kw) => lower.includes(kw));
|
|
109
|
+
if (hits.length >= 2) {
|
|
110
|
+
if (!keyPhrases[topic]) {
|
|
111
|
+
keyPhrases[topic] = { count: 0, sources: new Set() };
|
|
112
|
+
}
|
|
113
|
+
keyPhrases[topic].count++;
|
|
114
|
+
// Categorize source by content hints
|
|
115
|
+
if (lower.includes('fail') || lower.includes('error') || lower.includes('bug')) {
|
|
116
|
+
keyPhrases[topic].sources.add('failure');
|
|
117
|
+
}
|
|
118
|
+
else if (lower.includes('complet') || lower.includes('success') || lower.includes('fixed')) {
|
|
119
|
+
keyPhrases[topic].sources.add('success');
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
keyPhrases[topic].sources.add('learning');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return Object.entries(keyPhrases)
|
|
128
|
+
.filter(([, v]) => v.count >= 2)
|
|
129
|
+
.sort((a, b) => b[1].count - a[1].count)
|
|
130
|
+
.map(([topic, v]) => ({
|
|
131
|
+
pattern: topic,
|
|
132
|
+
occurrences: v.count,
|
|
133
|
+
sources: Array.from(v.sources),
|
|
134
|
+
identifiedAt: now,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Derive insights from memories and patterns.
|
|
139
|
+
*
|
|
140
|
+
* @param memories - Array of memory text strings
|
|
141
|
+
* @param patterns - Previously extracted patterns
|
|
142
|
+
* @returns Array of derived insights
|
|
143
|
+
*/
|
|
144
|
+
deriveInsights(memories, patterns) {
|
|
145
|
+
const insights = [];
|
|
146
|
+
// Insight: if a pattern appears in both failures and successes, it's a learning area
|
|
147
|
+
for (const pattern of patterns) {
|
|
148
|
+
if (pattern.sources.includes('failure') && pattern.sources.includes('success')) {
|
|
149
|
+
insights.push({
|
|
150
|
+
insight: `${pattern.pattern}: appears in both failures and successes — active learning area`,
|
|
151
|
+
confidence: pattern.occurrences >= 4 ? 'high' : 'medium',
|
|
152
|
+
relatedMemories: memories
|
|
153
|
+
.filter((m) => m.toLowerCase().includes(pattern.pattern.split(' ')[0]))
|
|
154
|
+
.slice(0, 3),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Insight: high-frequency pattern suggests systematic behavior
|
|
159
|
+
for (const pattern of patterns) {
|
|
160
|
+
if (pattern.occurrences >= 4) {
|
|
161
|
+
insights.push({
|
|
162
|
+
insight: `${pattern.pattern}: recurring theme across ${pattern.occurrences} memories — may indicate systematic tendency`,
|
|
163
|
+
confidence: 'high',
|
|
164
|
+
relatedMemories: [],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return insights;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Persist consolidation report to disk.
|
|
172
|
+
*
|
|
173
|
+
* @param sessionName - Agent session name
|
|
174
|
+
* @param report - Consolidation report to save
|
|
175
|
+
*/
|
|
176
|
+
async save(sessionName, report) {
|
|
177
|
+
const filePath = this.getFilePath(sessionName);
|
|
178
|
+
const dir = path.dirname(filePath);
|
|
179
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
180
|
+
fs.writeFileSync(filePath, JSON.stringify(report, null, 2), 'utf-8');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=memory-consolidation.service.js.map
|
package/dist/backend/backend/src/services/ai/self-improvement/memory-consolidation.service.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-consolidation.service.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/self-improvement/memory-consolidation.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAgD7B;;;;;;;;GAQG;AACH,MAAM,OAAO,0BAA0B;IAC9B,cAAc,CAAiB;IAEvC;;;;OAIG;IACH,YAAY,cAA8B;QACzC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACK,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,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;yBACtE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;iBACb,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,+DAA+D;QAC/D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAChC,IAAI,OAAO,CAAC,WAAW,IAAI,CAAC,EAAE,CAAC;gBAC9B,QAAQ,CAAC,IAAI,CAAC;oBACb,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,4BAA4B,OAAO,CAAC,WAAW,8CAA8C;oBACxH,UAAU,EAAE,MAAM;oBAClB,eAAe,EAAE,EAAE;iBACnB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,IAAI,CAAC,WAAmB,EAAE,MAA2B;QAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;CACD"}
|
package/dist/backend/backend/src/services/ai/self-improvement/prediction-calibration.service.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single prediction made by an agent.
|
|
3
|
+
*/
|
|
4
|
+
export interface Prediction {
|
|
5
|
+
/** Unique prediction ID */
|
|
6
|
+
id: string;
|
|
7
|
+
/** What the agent predicted */
|
|
8
|
+
prediction: string;
|
|
9
|
+
/** Confidence level (0-1) */
|
|
10
|
+
confidence: number;
|
|
11
|
+
/** When the prediction was made (ISO date string) */
|
|
12
|
+
madeAt: string;
|
|
13
|
+
/** Actual outcome (set when resolved) */
|
|
14
|
+
outcome?: string;
|
|
15
|
+
/** Whether the prediction was accurate (set when resolved) */
|
|
16
|
+
accurate?: boolean;
|
|
17
|
+
/** When the prediction was resolved (ISO date string) */
|
|
18
|
+
resolvedAt?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Persisted predictions data structure.
|
|
22
|
+
*/
|
|
23
|
+
export interface PredictionsData {
|
|
24
|
+
/** All predictions (resolved and unresolved) */
|
|
25
|
+
predictions: Prediction[];
|
|
26
|
+
/** Overall calibration score (0-1, higher = better calibrated) */
|
|
27
|
+
calibrationScore: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Service for tracking agent prediction accuracy and calibration.
|
|
31
|
+
*
|
|
32
|
+
* Agents make predictions with confidence levels, then resolve them
|
|
33
|
+
* with actual outcomes. The calibration score measures how well
|
|
34
|
+
* an agent's confidence maps to actual accuracy.
|
|
35
|
+
*
|
|
36
|
+
* Storage: ~/.crewly/agents/{sessionName}/predictions.json
|
|
37
|
+
*/
|
|
38
|
+
export declare class PredictionCalibrationService {
|
|
39
|
+
/**
|
|
40
|
+
* Get the file path for an agent's predictions.
|
|
41
|
+
*
|
|
42
|
+
* @param sessionName - Agent session name
|
|
43
|
+
* @returns Absolute path to predictions.json
|
|
44
|
+
*/
|
|
45
|
+
private getFilePath;
|
|
46
|
+
/**
|
|
47
|
+
* Read predictions data from disk.
|
|
48
|
+
*
|
|
49
|
+
* @param sessionName - Agent session name
|
|
50
|
+
* @returns Predictions data, or empty default if file doesn't exist
|
|
51
|
+
*/
|
|
52
|
+
getPredictions(sessionName: string): Promise<PredictionsData>;
|
|
53
|
+
/**
|
|
54
|
+
* Record a new prediction.
|
|
55
|
+
*
|
|
56
|
+
* @param sessionName - Agent session name
|
|
57
|
+
* @param prediction - What is being predicted
|
|
58
|
+
* @param confidence - Confidence level (0-1)
|
|
59
|
+
* @returns The created prediction
|
|
60
|
+
*/
|
|
61
|
+
makePrediction(sessionName: string, prediction: string, confidence: number): Promise<Prediction>;
|
|
62
|
+
/**
|
|
63
|
+
* Resolve a prediction with its actual outcome.
|
|
64
|
+
*
|
|
65
|
+
* @param sessionName - Agent session name
|
|
66
|
+
* @param id - Prediction ID to resolve
|
|
67
|
+
* @param outcome - What actually happened
|
|
68
|
+
* @param accurate - Whether the prediction was accurate
|
|
69
|
+
* @returns The resolved prediction, or null if not found
|
|
70
|
+
*/
|
|
71
|
+
resolvePrediction(sessionName: string, id: string, outcome: string, accurate: boolean): Promise<Prediction | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Get the agent's current calibration score.
|
|
74
|
+
*
|
|
75
|
+
* @param sessionName - Agent session name
|
|
76
|
+
* @returns Calibration score (0-1), or 0 if no resolved predictions
|
|
77
|
+
*/
|
|
78
|
+
getCalibrationScore(sessionName: string): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Calculate calibration score from resolved predictions.
|
|
81
|
+
*
|
|
82
|
+
* Uses a simplified Brier-like score: for each resolved prediction,
|
|
83
|
+
* compares confidence to actual accuracy. Perfect calibration = 1.0.
|
|
84
|
+
*
|
|
85
|
+
* @param predictions - All predictions
|
|
86
|
+
* @returns Calibration score (0-1)
|
|
87
|
+
*/
|
|
88
|
+
private calculateCalibrationScore;
|
|
89
|
+
/**
|
|
90
|
+
* Persist predictions data to disk.
|
|
91
|
+
*
|
|
92
|
+
* @param sessionName - Agent session name
|
|
93
|
+
* @param data - Predictions data to save
|
|
94
|
+
*/
|
|
95
|
+
private save;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=prediction-calibration.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prediction-calibration.service.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/self-improvement/prediction-calibration.service.ts"],"names":[],"mappings":"AAGA;;GAE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
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Service for tracking agent prediction accuracy and calibration.
|
|
5
|
+
*
|
|
6
|
+
* Agents make predictions with confidence levels, then resolve them
|
|
7
|
+
* with actual outcomes. The calibration score measures how well
|
|
8
|
+
* an agent's confidence maps to actual accuracy.
|
|
9
|
+
*
|
|
10
|
+
* Storage: ~/.crewly/agents/{sessionName}/predictions.json
|
|
11
|
+
*/
|
|
12
|
+
export class PredictionCalibrationService {
|
|
13
|
+
/**
|
|
14
|
+
* Get the file path for an agent's predictions.
|
|
15
|
+
*
|
|
16
|
+
* @param sessionName - Agent session name
|
|
17
|
+
* @returns Absolute path to predictions.json
|
|
18
|
+
*/
|
|
19
|
+
getFilePath(sessionName) {
|
|
20
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '/tmp';
|
|
21
|
+
return path.join(homeDir, '.crewly', 'agents', sessionName, 'predictions.json');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Read predictions data from disk.
|
|
25
|
+
*
|
|
26
|
+
* @param sessionName - Agent session name
|
|
27
|
+
* @returns Predictions data, or empty default if file doesn't exist
|
|
28
|
+
*/
|
|
29
|
+
async getPredictions(sessionName) {
|
|
30
|
+
try {
|
|
31
|
+
const filePath = this.getFilePath(sessionName);
|
|
32
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
33
|
+
return JSON.parse(raw);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return { predictions: [], calibrationScore: 0 };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Record a new prediction.
|
|
41
|
+
*
|
|
42
|
+
* @param sessionName - Agent session name
|
|
43
|
+
* @param prediction - What is being predicted
|
|
44
|
+
* @param confidence - Confidence level (0-1)
|
|
45
|
+
* @returns The created prediction
|
|
46
|
+
*/
|
|
47
|
+
async makePrediction(sessionName, prediction, confidence) {
|
|
48
|
+
const data = await this.getPredictions(sessionName);
|
|
49
|
+
const clampedConfidence = Math.max(0, Math.min(1, confidence));
|
|
50
|
+
const newPrediction = {
|
|
51
|
+
id: `pred-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`,
|
|
52
|
+
prediction,
|
|
53
|
+
confidence: clampedConfidence,
|
|
54
|
+
madeAt: new Date().toISOString().split('T')[0],
|
|
55
|
+
};
|
|
56
|
+
data.predictions.push(newPrediction);
|
|
57
|
+
await this.save(sessionName, data);
|
|
58
|
+
return newPrediction;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolve a prediction with its actual outcome.
|
|
62
|
+
*
|
|
63
|
+
* @param sessionName - Agent session name
|
|
64
|
+
* @param id - Prediction ID to resolve
|
|
65
|
+
* @param outcome - What actually happened
|
|
66
|
+
* @param accurate - Whether the prediction was accurate
|
|
67
|
+
* @returns The resolved prediction, or null if not found
|
|
68
|
+
*/
|
|
69
|
+
async resolvePrediction(sessionName, id, outcome, accurate) {
|
|
70
|
+
const data = await this.getPredictions(sessionName);
|
|
71
|
+
const found = data.predictions.find((p) => p.id === id);
|
|
72
|
+
if (!found) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
found.outcome = outcome;
|
|
76
|
+
found.accurate = accurate;
|
|
77
|
+
found.resolvedAt = new Date().toISOString().split('T')[0];
|
|
78
|
+
// Recalculate calibration score
|
|
79
|
+
data.calibrationScore = this.calculateCalibrationScore(data.predictions);
|
|
80
|
+
await this.save(sessionName, data);
|
|
81
|
+
return found;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the agent's current calibration score.
|
|
85
|
+
*
|
|
86
|
+
* @param sessionName - Agent session name
|
|
87
|
+
* @returns Calibration score (0-1), or 0 if no resolved predictions
|
|
88
|
+
*/
|
|
89
|
+
async getCalibrationScore(sessionName) {
|
|
90
|
+
const data = await this.getPredictions(sessionName);
|
|
91
|
+
return data.calibrationScore;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Calculate calibration score from resolved predictions.
|
|
95
|
+
*
|
|
96
|
+
* Uses a simplified Brier-like score: for each resolved prediction,
|
|
97
|
+
* compares confidence to actual accuracy. Perfect calibration = 1.0.
|
|
98
|
+
*
|
|
99
|
+
* @param predictions - All predictions
|
|
100
|
+
* @returns Calibration score (0-1)
|
|
101
|
+
*/
|
|
102
|
+
calculateCalibrationScore(predictions) {
|
|
103
|
+
const resolved = predictions.filter((p) => p.resolvedAt !== undefined);
|
|
104
|
+
if (resolved.length === 0)
|
|
105
|
+
return 0;
|
|
106
|
+
let totalError = 0;
|
|
107
|
+
for (const p of resolved) {
|
|
108
|
+
const actual = p.accurate ? 1 : 0;
|
|
109
|
+
totalError += Math.pow(p.confidence - actual, 2);
|
|
110
|
+
}
|
|
111
|
+
// Brier score is mean squared error; invert so 1 = perfect
|
|
112
|
+
const brierScore = totalError / resolved.length;
|
|
113
|
+
return Math.round((1 - brierScore) * 100) / 100;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Persist predictions data to disk.
|
|
117
|
+
*
|
|
118
|
+
* @param sessionName - Agent session name
|
|
119
|
+
* @param data - Predictions data to save
|
|
120
|
+
*/
|
|
121
|
+
async save(sessionName, data) {
|
|
122
|
+
const filePath = this.getFilePath(sessionName);
|
|
123
|
+
const dir = path.dirname(filePath);
|
|
124
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
125
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=prediction-calibration.service.js.map
|
package/dist/backend/backend/src/services/ai/self-improvement/prediction-calibration.service.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prediction-calibration.service.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/self-improvement/prediction-calibration.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,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+
* A recognized decision pattern for an agent.
|
|
3
|
+
*/
|
|
4
|
+
export interface DecisionPattern {
|
|
5
|
+
/** Description of the pattern */
|
|
6
|
+
pattern: string;
|
|
7
|
+
/** How many times this pattern has been observed */
|
|
8
|
+
frequency: number;
|
|
9
|
+
/** Last time this pattern was observed (ISO date string) */
|
|
10
|
+
lastSeen: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A recognized cognitive bias for an agent.
|
|
14
|
+
*/
|
|
15
|
+
export interface CognitiveBias {
|
|
16
|
+
/** Description of the bias */
|
|
17
|
+
bias: string;
|
|
18
|
+
/** How impactful this bias is */
|
|
19
|
+
severity: 'low' | 'medium' | 'high';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A recognized blind spot for an agent.
|
|
23
|
+
*/
|
|
24
|
+
export interface BlindSpot {
|
|
25
|
+
/** Description of the blind spot */
|
|
26
|
+
description: string;
|
|
27
|
+
/** When this blind spot was identified (ISO date string) */
|
|
28
|
+
identifiedAt: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Persisted self-model data structure.
|
|
32
|
+
*/
|
|
33
|
+
export interface SelfModelData {
|
|
34
|
+
/** Recurring decision patterns */
|
|
35
|
+
decisionPatterns: DecisionPattern[];
|
|
36
|
+
/** Identified cognitive biases */
|
|
37
|
+
biases: CognitiveBias[];
|
|
38
|
+
/** Known blind spots */
|
|
39
|
+
blindSpots: BlindSpot[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Service for managing an agent's self-model — their understanding
|
|
43
|
+
* of their own decision patterns, biases, and blind spots.
|
|
44
|
+
*
|
|
45
|
+
* Storage: ~/.crewly/agents/{sessionName}/self-model.json
|
|
46
|
+
*/
|
|
47
|
+
export declare class SelfModelService {
|
|
48
|
+
/**
|
|
49
|
+
* Get the file path for an agent's self-model.
|
|
50
|
+
*
|
|
51
|
+
* @param sessionName - Agent session name
|
|
52
|
+
* @returns Absolute path to self-model.json
|
|
53
|
+
*/
|
|
54
|
+
private getFilePath;
|
|
55
|
+
/**
|
|
56
|
+
* Read the self-model data from disk.
|
|
57
|
+
*
|
|
58
|
+
* @param sessionName - Agent session name
|
|
59
|
+
* @returns Self-model data, or empty default if file doesn't exist
|
|
60
|
+
*/
|
|
61
|
+
getSelfModel(sessionName: string): Promise<SelfModelData>;
|
|
62
|
+
/**
|
|
63
|
+
* Add or increment a decision pattern.
|
|
64
|
+
*
|
|
65
|
+
* @param sessionName - Agent session name
|
|
66
|
+
* @param pattern - Description of the decision pattern
|
|
67
|
+
* @returns The added or updated pattern
|
|
68
|
+
*/
|
|
69
|
+
addPattern(sessionName: string, pattern: string): Promise<DecisionPattern>;
|
|
70
|
+
/**
|
|
71
|
+
* Add a cognitive bias.
|
|
72
|
+
*
|
|
73
|
+
* @param sessionName - Agent session name
|
|
74
|
+
* @param bias - Description of the bias
|
|
75
|
+
* @param severity - How impactful the bias is
|
|
76
|
+
* @returns The added bias
|
|
77
|
+
*/
|
|
78
|
+
addBias(sessionName: string, bias: string, severity?: 'low' | 'medium' | 'high'): Promise<CognitiveBias>;
|
|
79
|
+
/**
|
|
80
|
+
* Add a blind spot.
|
|
81
|
+
*
|
|
82
|
+
* @param sessionName - Agent session name
|
|
83
|
+
* @param description - Description of the blind spot
|
|
84
|
+
* @returns The added blind spot
|
|
85
|
+
*/
|
|
86
|
+
addBlindSpot(sessionName: string, description: string): Promise<BlindSpot>;
|
|
87
|
+
/**
|
|
88
|
+
* Persist self-model data to disk.
|
|
89
|
+
*
|
|
90
|
+
* @param sessionName - Agent session name
|
|
91
|
+
* @param data - Self-model data to save
|
|
92
|
+
*/
|
|
93
|
+
private save;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=self-model.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-model.service.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/self-improvement/self-model.service.ts"],"names":[],"mappings":"AAGA;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B"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing an agent's self-model — their understanding
|
|
5
|
+
* of their own decision patterns, biases, and blind spots.
|
|
6
|
+
*
|
|
7
|
+
* Storage: ~/.crewly/agents/{sessionName}/self-model.json
|
|
8
|
+
*/
|
|
9
|
+
export class SelfModelService {
|
|
10
|
+
/**
|
|
11
|
+
* Get the file path for an agent's self-model.
|
|
12
|
+
*
|
|
13
|
+
* @param sessionName - Agent session name
|
|
14
|
+
* @returns Absolute path to self-model.json
|
|
15
|
+
*/
|
|
16
|
+
getFilePath(sessionName) {
|
|
17
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '/tmp';
|
|
18
|
+
return path.join(homeDir, '.crewly', 'agents', sessionName, 'self-model.json');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read the self-model data from disk.
|
|
22
|
+
*
|
|
23
|
+
* @param sessionName - Agent session name
|
|
24
|
+
* @returns Self-model data, or empty default if file doesn't exist
|
|
25
|
+
*/
|
|
26
|
+
async getSelfModel(sessionName) {
|
|
27
|
+
try {
|
|
28
|
+
const filePath = this.getFilePath(sessionName);
|
|
29
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
30
|
+
return JSON.parse(raw);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return { decisionPatterns: [], biases: [], blindSpots: [] };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Add or increment a decision pattern.
|
|
38
|
+
*
|
|
39
|
+
* @param sessionName - Agent session name
|
|
40
|
+
* @param pattern - Description of the decision pattern
|
|
41
|
+
* @returns The added or updated pattern
|
|
42
|
+
*/
|
|
43
|
+
async addPattern(sessionName, pattern) {
|
|
44
|
+
const data = await this.getSelfModel(sessionName);
|
|
45
|
+
const existing = data.decisionPatterns.find((p) => p.pattern.toLowerCase() === pattern.toLowerCase());
|
|
46
|
+
if (existing) {
|
|
47
|
+
existing.frequency++;
|
|
48
|
+
existing.lastSeen = new Date().toISOString().split('T')[0];
|
|
49
|
+
await this.save(sessionName, data);
|
|
50
|
+
return existing;
|
|
51
|
+
}
|
|
52
|
+
const newPattern = {
|
|
53
|
+
pattern,
|
|
54
|
+
frequency: 1,
|
|
55
|
+
lastSeen: new Date().toISOString().split('T')[0],
|
|
56
|
+
};
|
|
57
|
+
data.decisionPatterns.push(newPattern);
|
|
58
|
+
await this.save(sessionName, data);
|
|
59
|
+
return newPattern;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Add a cognitive bias.
|
|
63
|
+
*
|
|
64
|
+
* @param sessionName - Agent session name
|
|
65
|
+
* @param bias - Description of the bias
|
|
66
|
+
* @param severity - How impactful the bias is
|
|
67
|
+
* @returns The added bias
|
|
68
|
+
*/
|
|
69
|
+
async addBias(sessionName, bias, severity = 'low') {
|
|
70
|
+
const data = await this.getSelfModel(sessionName);
|
|
71
|
+
const existing = data.biases.find((b) => b.bias.toLowerCase() === bias.toLowerCase());
|
|
72
|
+
if (existing) {
|
|
73
|
+
existing.severity = severity;
|
|
74
|
+
await this.save(sessionName, data);
|
|
75
|
+
return existing;
|
|
76
|
+
}
|
|
77
|
+
const newBias = { bias, severity };
|
|
78
|
+
data.biases.push(newBias);
|
|
79
|
+
await this.save(sessionName, data);
|
|
80
|
+
return newBias;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Add a blind spot.
|
|
84
|
+
*
|
|
85
|
+
* @param sessionName - Agent session name
|
|
86
|
+
* @param description - Description of the blind spot
|
|
87
|
+
* @returns The added blind spot
|
|
88
|
+
*/
|
|
89
|
+
async addBlindSpot(sessionName, description) {
|
|
90
|
+
const data = await this.getSelfModel(sessionName);
|
|
91
|
+
const existing = data.blindSpots.find((b) => b.description.toLowerCase() === description.toLowerCase());
|
|
92
|
+
if (existing) {
|
|
93
|
+
return existing;
|
|
94
|
+
}
|
|
95
|
+
const newSpot = {
|
|
96
|
+
description,
|
|
97
|
+
identifiedAt: new Date().toISOString().split('T')[0],
|
|
98
|
+
};
|
|
99
|
+
data.blindSpots.push(newSpot);
|
|
100
|
+
await this.save(sessionName, data);
|
|
101
|
+
return newSpot;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Persist self-model data to disk.
|
|
105
|
+
*
|
|
106
|
+
* @param sessionName - Agent session name
|
|
107
|
+
* @param data - Self-model data to save
|
|
108
|
+
*/
|
|
109
|
+
async save(sessionName, data) {
|
|
110
|
+
const filePath = this.getFilePath(sessionName);
|
|
111
|
+
const dir = path.dirname(filePath);
|
|
112
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
113
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=self-model.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-model.service.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/ai/self-improvement/self-model.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AA8C7B;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;;;;OAKG;IACK,WAAW,CAAC,WAAmB;QACtC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,MAAM,CAAC;QACtE,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,WAAmB;QACrC,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,C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C,CAAC,CAAC,CAAC;SACpD,CAAC;QACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9B,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACnC,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,IAAI,CAAC,WAAmB,EAAE,IAAmB;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crewly",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Multi-agent orchestration platform for AI coding teams — coordinates Claude Code, Gemini CLI, and Codex agents with a real-time web dashboard",
|
|
6
6
|
"main": "dist/cli/cli/src/index.js",
|