@yuaone/core 0.1.3 → 0.3.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/agent-loop.d.ts +152 -0
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +893 -9
- package/dist/agent-loop.js.map +1 -1
- package/dist/benchmark-runner.d.ts +141 -0
- package/dist/benchmark-runner.d.ts.map +1 -0
- package/dist/benchmark-runner.js +526 -0
- package/dist/benchmark-runner.js.map +1 -0
- package/dist/codebase-context.d.ts +49 -0
- package/dist/codebase-context.d.ts.map +1 -1
- package/dist/codebase-context.js +146 -0
- package/dist/codebase-context.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -1
- package/dist/context-budget.d.ts +1 -1
- package/dist/context-budget.d.ts.map +1 -1
- package/dist/context-budget.js +4 -2
- package/dist/context-budget.js.map +1 -1
- package/dist/context-compressor.d.ts +1 -1
- package/dist/context-compressor.d.ts.map +1 -1
- package/dist/context-compressor.js +5 -3
- package/dist/context-compressor.js.map +1 -1
- package/dist/context-manager.d.ts +7 -1
- package/dist/context-manager.d.ts.map +1 -1
- package/dist/context-manager.js +34 -2
- package/dist/context-manager.js.map +1 -1
- package/dist/continuation-engine.d.ts +168 -0
- package/dist/continuation-engine.d.ts.map +1 -0
- package/dist/continuation-engine.js +421 -0
- package/dist/continuation-engine.js.map +1 -0
- package/dist/cost-optimizer.d.ts +159 -0
- package/dist/cost-optimizer.d.ts.map +1 -0
- package/dist/cost-optimizer.js +406 -0
- package/dist/cost-optimizer.js.map +1 -0
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/execution-engine.js +9 -4
- package/dist/execution-engine.js.map +1 -1
- package/dist/execution-policy-engine.d.ts +133 -0
- package/dist/execution-policy-engine.d.ts.map +1 -0
- package/dist/execution-policy-engine.js +367 -0
- package/dist/execution-policy-engine.js.map +1 -0
- package/dist/failure-recovery.d.ts +228 -0
- package/dist/failure-recovery.d.ts.map +1 -0
- package/dist/failure-recovery.js +664 -0
- package/dist/failure-recovery.js.map +1 -0
- package/dist/hierarchical-planner.d.ts +69 -1
- package/dist/hierarchical-planner.d.ts.map +1 -1
- package/dist/hierarchical-planner.js +117 -0
- package/dist/hierarchical-planner.js.map +1 -1
- package/dist/impact-analyzer.d.ts +92 -0
- package/dist/impact-analyzer.d.ts.map +1 -0
- package/dist/impact-analyzer.js +615 -0
- package/dist/impact-analyzer.js.map +1 -0
- package/dist/index.d.ts +28 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -1
- package/dist/llm-client.d.ts +1 -1
- package/dist/llm-client.d.ts.map +1 -1
- package/dist/llm-client.js +74 -7
- package/dist/llm-client.js.map +1 -1
- package/dist/memory-updater.d.ts +189 -0
- package/dist/memory-updater.d.ts.map +1 -0
- package/dist/memory-updater.js +481 -0
- package/dist/memory-updater.js.map +1 -0
- package/dist/prompt-defense.d.ts +59 -0
- package/dist/prompt-defense.d.ts.map +1 -0
- package/dist/prompt-defense.js +311 -0
- package/dist/prompt-defense.js.map +1 -0
- package/dist/reflexion.d.ts +211 -0
- package/dist/reflexion.d.ts.map +1 -0
- package/dist/reflexion.js +559 -0
- package/dist/reflexion.js.map +1 -0
- package/dist/system-prompt.d.ts +19 -3
- package/dist/system-prompt.d.ts.map +1 -1
- package/dist/system-prompt.js +203 -38
- package/dist/system-prompt.js.map +1 -1
- package/dist/task-classifier.d.ts +92 -0
- package/dist/task-classifier.d.ts.map +1 -0
- package/dist/task-classifier.js +566 -0
- package/dist/task-classifier.js.map +1 -0
- package/dist/token-budget.d.ts +131 -0
- package/dist/token-budget.d.ts.map +1 -0
- package/dist/token-budget.js +321 -0
- package/dist/token-budget.js.map +1 -0
- package/dist/types.d.ts +20 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +18 -1
- package/dist/types.js.map +1 -1
- package/dist/world-state.d.ts +87 -0
- package/dist/world-state.d.ts.map +1 -0
- package/dist/world-state.js +435 -0
- package/dist/world-state.js.map +1 -0
- package/package.json +11 -21
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Injection Defense Module
|
|
3
|
+
*
|
|
4
|
+
* Sanitizes tool outputs and user inputs to prevent prompt injection attacks.
|
|
5
|
+
* Standalone module — no internal imports.
|
|
6
|
+
*/
|
|
7
|
+
const INJECTION_PATTERNS = [
|
|
8
|
+
{
|
|
9
|
+
name: "ignore_previous_instructions",
|
|
10
|
+
regex: /ignore\s+previous\s+instructions/gi,
|
|
11
|
+
severity: "critical",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "ignore_all_instructions",
|
|
15
|
+
regex: /ignore\s+all\s+instructions/gi,
|
|
16
|
+
severity: "critical",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "disregard_directive",
|
|
20
|
+
regex: /disregard\s+(previous|all|above|system)/gi,
|
|
21
|
+
severity: "critical",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "identity_override",
|
|
25
|
+
regex: /you\s+are\s+now/gi,
|
|
26
|
+
severity: "high",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "new_instructions",
|
|
30
|
+
regex: /new\s+instructions\s*:/gi,
|
|
31
|
+
severity: "high",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "system_prompt_extraction",
|
|
35
|
+
regex: /system\s+prompt\s*:/gi,
|
|
36
|
+
severity: "critical",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "reveal_instructions",
|
|
40
|
+
regex: /reveal\s+your\s+(instructions|prompt|system)/gi,
|
|
41
|
+
severity: "critical",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "override_safety",
|
|
45
|
+
regex: /override\s+(safety|security|rules)/gi,
|
|
46
|
+
severity: "critical",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "jailbreak",
|
|
50
|
+
regex: /\bjailbreak\b/gi,
|
|
51
|
+
severity: "high",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "dan_mode",
|
|
55
|
+
regex: /\bDAN\s+mode\b/gi,
|
|
56
|
+
severity: "high",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "pretend_override",
|
|
60
|
+
regex: /pretend\s+you\s+are/gi,
|
|
61
|
+
severity: "medium",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "act_as_override",
|
|
65
|
+
regex: /act\s+as\s+if\s+you/gi,
|
|
66
|
+
severity: "medium",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "forget_everything",
|
|
70
|
+
regex: /forget\s+everything/gi,
|
|
71
|
+
severity: "high",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "prompt_format_system",
|
|
75
|
+
regex: /\[SYSTEM\]/gi,
|
|
76
|
+
severity: "high",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "prompt_format_inst",
|
|
80
|
+
regex: /\[INST\]/gi,
|
|
81
|
+
severity: "high",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "prompt_format_sys_tag",
|
|
85
|
+
regex: /<<SYS>>/gi,
|
|
86
|
+
severity: "high",
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
// ── Size limits per tool ────────────────────────────────────────────────────
|
|
90
|
+
const TOOL_OUTPUT_LIMITS = {
|
|
91
|
+
file_read: 50_000,
|
|
92
|
+
grep: 20_000,
|
|
93
|
+
glob: 10_000,
|
|
94
|
+
shell_exec: 30_000,
|
|
95
|
+
git_ops: 20_000,
|
|
96
|
+
test_run: 30_000,
|
|
97
|
+
code_search: 20_000,
|
|
98
|
+
};
|
|
99
|
+
const DEFAULT_OUTPUT_LIMIT = 10_000;
|
|
100
|
+
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
101
|
+
function getOutputLimit(toolName) {
|
|
102
|
+
return TOOL_OUTPUT_LIMITS[toolName] ?? DEFAULT_OUTPUT_LIMIT;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Attempt to decode base64 segments in a string and check for injections.
|
|
106
|
+
* Returns any injection matches found in decoded segments.
|
|
107
|
+
*/
|
|
108
|
+
function detectBase64Injections(text) {
|
|
109
|
+
const matches = [];
|
|
110
|
+
// Match potential base64 strings (at least 16 chars, valid base64 alphabet)
|
|
111
|
+
const b64Regex = /[A-Za-z0-9+/]{16,}={0,2}/g;
|
|
112
|
+
let b64Match;
|
|
113
|
+
while ((b64Match = b64Regex.exec(text)) !== null) {
|
|
114
|
+
let decoded;
|
|
115
|
+
try {
|
|
116
|
+
decoded = Buffer.from(b64Match[0], "base64").toString("utf-8");
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// Check if the decoded string is mostly printable ASCII (sanity check)
|
|
122
|
+
const printable = decoded.replace(/[^\x20-\x7E]/g, "");
|
|
123
|
+
if (printable.length < decoded.length * 0.7) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
for (const pat of INJECTION_PATTERNS) {
|
|
127
|
+
const patRegex = new RegExp(pat.regex.source, pat.regex.flags);
|
|
128
|
+
const innerMatch = patRegex.exec(decoded);
|
|
129
|
+
if (innerMatch) {
|
|
130
|
+
matches.push({
|
|
131
|
+
pattern: `base64:${pat.name}`,
|
|
132
|
+
match: b64Match[0].substring(0, 40),
|
|
133
|
+
position: b64Match.index,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return matches;
|
|
139
|
+
}
|
|
140
|
+
function severityRank(s) {
|
|
141
|
+
const ranks = {
|
|
142
|
+
none: 0,
|
|
143
|
+
low: 1,
|
|
144
|
+
medium: 2,
|
|
145
|
+
high: 3,
|
|
146
|
+
critical: 4,
|
|
147
|
+
};
|
|
148
|
+
return ranks[s];
|
|
149
|
+
}
|
|
150
|
+
function maxSeverity(a, b) {
|
|
151
|
+
return severityRank(a) >= severityRank(b) ? a : b;
|
|
152
|
+
}
|
|
153
|
+
function severityToRecommendation(severity) {
|
|
154
|
+
switch (severity) {
|
|
155
|
+
case "none":
|
|
156
|
+
return "allow";
|
|
157
|
+
case "low":
|
|
158
|
+
case "medium":
|
|
159
|
+
return "sanitize";
|
|
160
|
+
case "high":
|
|
161
|
+
case "critical":
|
|
162
|
+
return "block";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Filter characters for high-strictness mode.
|
|
167
|
+
* Removes non-printable control characters (except newline, tab, carriage return).
|
|
168
|
+
*/
|
|
169
|
+
function filterChars(text) {
|
|
170
|
+
// Keep printable ASCII, newline, tab, CR, and common unicode
|
|
171
|
+
// Strip control chars 0x00-0x08, 0x0B, 0x0C, 0x0E-0x1F, 0x7F
|
|
172
|
+
return text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
173
|
+
}
|
|
174
|
+
// ── PromptDefense Class ─────────────────────────────────────────────────────
|
|
175
|
+
export class PromptDefense {
|
|
176
|
+
defaultLevel;
|
|
177
|
+
constructor(defaultLevel = "medium") {
|
|
178
|
+
this.defaultLevel = defaultLevel;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Detect injection patterns in text, including base64-encoded variants.
|
|
182
|
+
*/
|
|
183
|
+
detectInjection(text) {
|
|
184
|
+
const patterns = [];
|
|
185
|
+
let overallSeverity = "none";
|
|
186
|
+
// Direct pattern matching
|
|
187
|
+
for (const pat of INJECTION_PATTERNS) {
|
|
188
|
+
const regex = new RegExp(pat.regex.source, pat.regex.flags);
|
|
189
|
+
let m;
|
|
190
|
+
while ((m = regex.exec(text)) !== null) {
|
|
191
|
+
patterns.push({
|
|
192
|
+
pattern: pat.name,
|
|
193
|
+
match: m[0],
|
|
194
|
+
position: m.index,
|
|
195
|
+
});
|
|
196
|
+
overallSeverity = maxSeverity(overallSeverity, pat.severity);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Base64-encoded pattern matching
|
|
200
|
+
const b64Matches = detectBase64Injections(text);
|
|
201
|
+
for (const bm of b64Matches) {
|
|
202
|
+
patterns.push(bm);
|
|
203
|
+
// Base64-encoded injections are at least high severity (they imply intent)
|
|
204
|
+
overallSeverity = maxSeverity(overallSeverity, "high");
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
detected: patterns.length > 0,
|
|
208
|
+
severity: overallSeverity,
|
|
209
|
+
patterns,
|
|
210
|
+
recommendation: severityToRecommendation(overallSeverity),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Sanitize a string: strip injection patterns, optionally truncate and filter.
|
|
215
|
+
*/
|
|
216
|
+
sanitize(text, level) {
|
|
217
|
+
const effectiveLevel = level ?? this.defaultLevel;
|
|
218
|
+
let result = text;
|
|
219
|
+
// All levels: strip injection patterns
|
|
220
|
+
for (const pat of INJECTION_PATTERNS) {
|
|
221
|
+
result = result.replace(new RegExp(pat.regex.source, pat.regex.flags), "[REDACTED]");
|
|
222
|
+
}
|
|
223
|
+
// Medium+: also strip base64-encoded injections
|
|
224
|
+
if (effectiveLevel === "medium" || effectiveLevel === "high") {
|
|
225
|
+
const b64Regex = /[A-Za-z0-9+/]{16,}={0,2}/g;
|
|
226
|
+
const b64Segments = [];
|
|
227
|
+
let b64Match;
|
|
228
|
+
while ((b64Match = b64Regex.exec(result)) !== null) {
|
|
229
|
+
let decoded;
|
|
230
|
+
try {
|
|
231
|
+
decoded = Buffer.from(b64Match[0], "base64").toString("utf-8");
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const printable = decoded.replace(/[^\x20-\x7E]/g, "");
|
|
237
|
+
if (printable.length < decoded.length * 0.7)
|
|
238
|
+
continue;
|
|
239
|
+
for (const pat of INJECTION_PATTERNS) {
|
|
240
|
+
if (new RegExp(pat.regex.source, pat.regex.flags).test(decoded)) {
|
|
241
|
+
b64Segments.push({
|
|
242
|
+
start: b64Match.index,
|
|
243
|
+
end: b64Match.index + b64Match[0].length,
|
|
244
|
+
});
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// Replace b64 segments in reverse order to preserve indices
|
|
250
|
+
for (let i = b64Segments.length - 1; i >= 0; i--) {
|
|
251
|
+
const seg = b64Segments[i];
|
|
252
|
+
result =
|
|
253
|
+
result.substring(0, seg.start) +
|
|
254
|
+
"[REDACTED:BASE64]" +
|
|
255
|
+
result.substring(seg.end);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// High: aggressive character filtering
|
|
259
|
+
if (effectiveLevel === "high") {
|
|
260
|
+
result = filterChars(result);
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Sanitize tool output: detect injections, strip patterns, truncate to limit.
|
|
266
|
+
*/
|
|
267
|
+
sanitizeToolOutput(toolName, output) {
|
|
268
|
+
const originalLength = output.length;
|
|
269
|
+
const limit = getOutputLimit(toolName);
|
|
270
|
+
// Detect before sanitizing (for reporting)
|
|
271
|
+
const detection = this.detectInjection(output);
|
|
272
|
+
// Sanitize
|
|
273
|
+
let sanitized = this.sanitize(output, this.defaultLevel);
|
|
274
|
+
// Truncate
|
|
275
|
+
let truncated = false;
|
|
276
|
+
if (sanitized.length > limit) {
|
|
277
|
+
sanitized = sanitized.substring(0, limit) + "\n... [truncated]";
|
|
278
|
+
truncated = true;
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
output: sanitized,
|
|
282
|
+
injectionDetected: detection.detected,
|
|
283
|
+
patternsFound: detection.patterns.map((p) => p.pattern),
|
|
284
|
+
truncated,
|
|
285
|
+
originalLength,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Validate user input for injection attempts.
|
|
290
|
+
*/
|
|
291
|
+
validateUserInput(input) {
|
|
292
|
+
const detection = this.detectInjection(input);
|
|
293
|
+
const sanitizedInput = this.sanitize(input, this.defaultLevel);
|
|
294
|
+
return {
|
|
295
|
+
valid: !detection.detected || detection.severity === "low",
|
|
296
|
+
injectionDetected: detection.detected,
|
|
297
|
+
severity: detection.severity,
|
|
298
|
+
patternsFound: detection.patterns.map((p) => p.pattern),
|
|
299
|
+
sanitizedInput,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Wrap tool output with safety markers to prevent the LLM from confusing
|
|
304
|
+
* tool output with its own instructions.
|
|
305
|
+
*/
|
|
306
|
+
wrapToolOutput(toolName, output) {
|
|
307
|
+
const result = this.sanitizeToolOutput(toolName, output);
|
|
308
|
+
return `[Tool Output: ${toolName}]\n${result.output}\n[End Tool Output]`;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=prompt-defense.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-defense.js","sourceRoot":"","sources":["../src/prompt-defense.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6CH,MAAM,kBAAkB,GAAiB;IACvC;QACE,IAAI,EAAE,8BAA8B;QACpC,KAAK,EAAE,oCAAoC;QAC3C,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE,+BAA+B;QACtC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,2CAA2C;QAClD,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE,mBAAmB;QAC1B,QAAQ,EAAE,MAAM;KACjB;IACD;QACE,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,0BAA0B;QACjC,QAAQ,EAAE,MAAM;K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,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YACvD,SAAS;YACT,cAAc;SACf,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAE/D,OAAO;YACL,KAAK,EAAE,CAAC,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,QAAQ,KAAK,KAAK;YAC1D,iBAAiB,EAAE,SAAS,CAAC,QAAQ;YACrC,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,aAAa,EAAE,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YACvD,cAAc;SACf,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,QAAgB,EAAE,MAAc;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzD,OAAO,iBAAiB,QAAQ,MAAM,MAAM,CAAC,MAAM,qBAAqB,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module reflexion
|
|
3
|
+
* @description Reflexion Layer — structured self-reflection after each agent run.
|
|
4
|
+
*
|
|
5
|
+
* Based on the Reflexion paper (Shinn et al., 2023):
|
|
6
|
+
* dynamic memory + self-reflection loop for continuous improvement.
|
|
7
|
+
*
|
|
8
|
+
* Key design decisions:
|
|
9
|
+
* - `reflect()` is purely heuristic (no LLM calls) — analyzes tool results, counts failures, detects patterns
|
|
10
|
+
* - `getGuidance()` uses keyword matching to find relevant past reflections
|
|
11
|
+
* - Strategy confidence decays over time (0.95 per week)
|
|
12
|
+
* - File-based persistence in `.yuan/memory/`
|
|
13
|
+
* - Max 100 reflections (FIFO), max 50 strategies
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const engine = new ReflexionEngine({ projectPath: "/my/project" });
|
|
18
|
+
*
|
|
19
|
+
* // After a run
|
|
20
|
+
* const entry = engine.reflect({ goal, runId, termination, toolResults, ... });
|
|
21
|
+
* await engine.store.saveReflection(entry);
|
|
22
|
+
*
|
|
23
|
+
* // Before a run
|
|
24
|
+
* const guidance = await engine.getGuidance("fix the auth middleware");
|
|
25
|
+
* const prompt = engine.formatForSystemPrompt(guidance);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import type { Message, ToolResult, AgentTermination } from "./types.js";
|
|
29
|
+
/** A single reflection entry from an agent run */
|
|
30
|
+
export interface ReflexionEntry {
|
|
31
|
+
/** UUID */
|
|
32
|
+
id: string;
|
|
33
|
+
/** Agent run identifier */
|
|
34
|
+
runId: string;
|
|
35
|
+
/** Epoch ms */
|
|
36
|
+
timestamp: number;
|
|
37
|
+
/** Original user goal */
|
|
38
|
+
goal: string;
|
|
39
|
+
/** Run outcome */
|
|
40
|
+
outcome: "success" | "partial" | "failure";
|
|
41
|
+
/** From AgentTermination.reason */
|
|
42
|
+
terminationReason: string;
|
|
43
|
+
/** Self-reflection analysis */
|
|
44
|
+
reflection: {
|
|
45
|
+
/** Successful strategies */
|
|
46
|
+
whatWorked: string[];
|
|
47
|
+
/** Failed strategies */
|
|
48
|
+
whatFailed: string[];
|
|
49
|
+
/** Root cause of failure (if applicable) */
|
|
50
|
+
rootCause: string | null;
|
|
51
|
+
/** What to try next time */
|
|
52
|
+
alternativeApproach: string | null;
|
|
53
|
+
};
|
|
54
|
+
/** Tool usage analysis */
|
|
55
|
+
toolAnalysis: {
|
|
56
|
+
/** Which tools were called */
|
|
57
|
+
toolsUsed: string[];
|
|
58
|
+
/** Tools that failed */
|
|
59
|
+
failedTools: Array<{
|
|
60
|
+
tool: string;
|
|
61
|
+
error: string;
|
|
62
|
+
count: number;
|
|
63
|
+
}>;
|
|
64
|
+
/** Success rate 0–1 */
|
|
65
|
+
successRate: number;
|
|
66
|
+
/** Total tool calls */
|
|
67
|
+
totalCalls: number;
|
|
68
|
+
/** Average tool execution duration in ms */
|
|
69
|
+
avgDurationMs: number;
|
|
70
|
+
};
|
|
71
|
+
/** Run metrics */
|
|
72
|
+
metrics: {
|
|
73
|
+
iterations: number;
|
|
74
|
+
tokensUsed: number;
|
|
75
|
+
durationMs: number;
|
|
76
|
+
filesChanged: string[];
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** A learned strategy from successful runs */
|
|
80
|
+
export interface StrategyRecord {
|
|
81
|
+
/** UUID */
|
|
82
|
+
id: string;
|
|
83
|
+
/** Regex or keyword pattern that matches similar tasks */
|
|
84
|
+
taskPattern: string;
|
|
85
|
+
/** Description of what works */
|
|
86
|
+
strategy: string;
|
|
87
|
+
/** Proven tool ordering */
|
|
88
|
+
toolSequence: string[];
|
|
89
|
+
/** Number of times this strategy succeeded */
|
|
90
|
+
successCount: number;
|
|
91
|
+
/** Number of times this strategy failed */
|
|
92
|
+
failureCount: number;
|
|
93
|
+
/** success / (success + failure) */
|
|
94
|
+
confidence: number;
|
|
95
|
+
/** Last used timestamp */
|
|
96
|
+
lastUsed: number;
|
|
97
|
+
/** Example goals that used this strategy */
|
|
98
|
+
examples: string[];
|
|
99
|
+
}
|
|
100
|
+
/** Guidance produced before an agent run */
|
|
101
|
+
export interface ReflexionGuidance {
|
|
102
|
+
/** Relevant proven strategies */
|
|
103
|
+
relevantStrategies: StrategyRecord[];
|
|
104
|
+
/** Recent failures on similar tasks */
|
|
105
|
+
recentFailures: ReflexionEntry[];
|
|
106
|
+
/** Patterns that have failed before — things to avoid */
|
|
107
|
+
avoidPatterns: string[];
|
|
108
|
+
/** Suggested approach based on past success */
|
|
109
|
+
suggestedApproach: string | null;
|
|
110
|
+
}
|
|
111
|
+
/** Configuration for the ReflexionEngine */
|
|
112
|
+
export interface ReflexionConfig {
|
|
113
|
+
/** Project root path — stores data in `.yuan/memory/` */
|
|
114
|
+
projectPath: string;
|
|
115
|
+
/** Maximum stored reflections (FIFO). Default 100 */
|
|
116
|
+
maxReflections?: number;
|
|
117
|
+
/** Maximum stored strategies. Default 50 */
|
|
118
|
+
maxStrategies?: number;
|
|
119
|
+
/** Confidence decay multiplier per week. Default 0.95 */
|
|
120
|
+
confidenceDecayPerWeek?: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* File-based persistence for reflections and strategies.
|
|
124
|
+
*
|
|
125
|
+
* Storage location: `<projectPath>/.yuan/memory/`
|
|
126
|
+
*/
|
|
127
|
+
export declare class ReflexionStore {
|
|
128
|
+
private readonly memoryDir;
|
|
129
|
+
constructor(projectPath: string);
|
|
130
|
+
/** Save a reflection entry. Appends to the list. */
|
|
131
|
+
saveReflection(entry: ReflexionEntry): Promise<void>;
|
|
132
|
+
/** Get most recent reflections, optionally limited. */
|
|
133
|
+
getReflections(limit?: number): Promise<ReflexionEntry[]>;
|
|
134
|
+
/** Get reflections filtered by outcome. */
|
|
135
|
+
getReflectionsByOutcome(outcome: string): Promise<ReflexionEntry[]>;
|
|
136
|
+
/** Save or update a strategy record. */
|
|
137
|
+
saveStrategy(strategy: StrategyRecord): Promise<void>;
|
|
138
|
+
/** Find strategies relevant to a goal using keyword matching. */
|
|
139
|
+
findRelevantStrategies(goal: string, limit?: number): Promise<StrategyRecord[]>;
|
|
140
|
+
/** Update success/failure stats for a strategy. */
|
|
141
|
+
updateStrategyStats(strategyId: string, success: boolean): Promise<void>;
|
|
142
|
+
/** Remove reflections older than maxAge (ms). Returns count removed. */
|
|
143
|
+
pruneOldReflections(maxAge: number): Promise<number>;
|
|
144
|
+
private ensureDir;
|
|
145
|
+
private readJsonFile;
|
|
146
|
+
private writeJsonFile;
|
|
147
|
+
private loadReflectionsFile;
|
|
148
|
+
private loadStrategiesFile;
|
|
149
|
+
}
|
|
150
|
+
/** Parameters for the `reflect()` method */
|
|
151
|
+
export interface ReflectParams {
|
|
152
|
+
goal: string;
|
|
153
|
+
runId: string;
|
|
154
|
+
termination: AgentTermination;
|
|
155
|
+
toolResults: ToolResult[];
|
|
156
|
+
messages: Message[];
|
|
157
|
+
tokensUsed: number;
|
|
158
|
+
durationMs: number;
|
|
159
|
+
changedFiles: string[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* ReflexionEngine — heuristic-based self-reflection after agent runs.
|
|
163
|
+
*
|
|
164
|
+
* No LLM calls. Analyzes tool results, detects failure patterns,
|
|
165
|
+
* extracts strategies from successful runs, and provides guidance
|
|
166
|
+
* for future runs.
|
|
167
|
+
*/
|
|
168
|
+
export declare class ReflexionEngine {
|
|
169
|
+
readonly store: ReflexionStore;
|
|
170
|
+
private readonly maxReflections;
|
|
171
|
+
private readonly maxStrategies;
|
|
172
|
+
private readonly confidenceDecayPerWeek;
|
|
173
|
+
constructor(config: ReflexionConfig);
|
|
174
|
+
/**
|
|
175
|
+
* After an agent run: analyze what happened and produce a ReflexionEntry.
|
|
176
|
+
*
|
|
177
|
+
* Purely heuristic — no LLM call. Analyzes:
|
|
178
|
+
* - Tool success/failure rates
|
|
179
|
+
* - Error patterns
|
|
180
|
+
* - Termination reason
|
|
181
|
+
* - Duration and resource usage
|
|
182
|
+
*/
|
|
183
|
+
reflect(params: ReflectParams): ReflexionEntry;
|
|
184
|
+
/**
|
|
185
|
+
* Before an agent run: retrieve relevant past reflections for context injection.
|
|
186
|
+
*
|
|
187
|
+
* Searches reflections and strategies by keyword matching against the goal.
|
|
188
|
+
*/
|
|
189
|
+
getGuidance(goal: string): Promise<ReflexionGuidance>;
|
|
190
|
+
/**
|
|
191
|
+
* Extract a StrategyRecord from a successful run.
|
|
192
|
+
*
|
|
193
|
+
* Only creates a strategy if the run used 3+ tool calls (nontrivial).
|
|
194
|
+
*/
|
|
195
|
+
extractStrategy(entry: ReflexionEntry, goal: string): StrategyRecord | null;
|
|
196
|
+
/**
|
|
197
|
+
* Format guidance for injection into a system prompt.
|
|
198
|
+
*
|
|
199
|
+
* Returns empty string if no relevant guidance found.
|
|
200
|
+
*/
|
|
201
|
+
formatForSystemPrompt(guidance: ReflexionGuidance): string;
|
|
202
|
+
/** Determine outcome from termination reason and tool results */
|
|
203
|
+
private determineOutcome;
|
|
204
|
+
/** Analyze tool usage from results */
|
|
205
|
+
private analyzeTools;
|
|
206
|
+
/** Build reflection heuristically from run data */
|
|
207
|
+
private buildReflection;
|
|
208
|
+
/** Apply time-based confidence decay to a strategy */
|
|
209
|
+
private applyConfidenceDecay;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=reflexion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflexion.d.ts","sourceRoot":"","sources":["../src/reflexion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAIxE,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,WAAW;IACX,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IAC3C,mCAAmC;IACnC,iBAAiB,EAAE,MAAM,CAAC;IAE1B,+BAA+B;IAC/B,UAAU,EAAE;QACV,4BAA4B;QAC5B,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,wBAAwB;QACxB,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,4CAA4C;QAC5C,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,4BAA4B;QAC5B,mBAAmB,EAAE,MAAM,GAA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