-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.mjs
More file actions
91 lines (79 loc) · 3.07 KB
/
Copy pathdemo.mjs
File metadata and controls
91 lines (79 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { globalACEPlugin, globalSkillbook } from "./dist/index.js";
const mockProvider = {
async generateText(prompt, system) {
console.log("[Mock LLM] generateText called");
return "Mock response";
},
async generateStructured(prompt, system, schema) {
console.log("[Mock LLM] generateStructured called with schema");
// If this is the SkillManager call (has operations in schema), return updates
if (schema._def?.typeName === "ZodObject" && schema._def?.shape()?.operations) {
return {
reasoning: "Added strategy based on reflection",
operations: [
{
type: "ADD",
section: "tool-use",
content: "Always check file existence before writing to prevent data loss",
justification: "Based on the task where user created a config file without checking existing files"
}
]
};
}
// Reflector output
return {
reasoning: "Task completed successfully - good tool usage",
errorIdentification: "none",
rootCauseAnalysis: "N/A",
correctApproach: "Used appropriate tools",
keyInsight: "Good problem-solving approach",
extractedLearnings: [
{
section: "tool-use",
content: "Always verify file existence before writing",
justification: "Prevents overwriting important files"
}
],
skillTags: []
};
}
};
async function main() {
console.log("=== ACE Plugin Demo ===\n");
// Initialize
globalACEPlugin.initialize(mockProvider);
console.log("1. Initialized ACE plugin\n");
// Show initial stats
const initialStats = globalACEPlugin.getStats();
console.log("2. Initial stats:", initialStats, "\n");
// Learn from a task
console.log("3. Learning from task...\n");
await globalACEPlugin.learnFromTask(
"Create a TypeScript config file for a new project",
"I need to create a tsconfig.json with proper settings for a modern TypeScript project. I'll use strict mode, ES2022 target, and enable common options.",
"Created tsconfig.json with target: ES2022, strict: true, module: NodeNext",
[
{ name: "write", arguments: { path: "tsconfig.json", content: "..." }, result: "File written" },
{ name: "read", arguments: { path: "package.json" }, result: "{ type: 'module' }" }
],
true
);
// Show updated stats
const updatedStats = globalACEPlugin.getStats();
console.log("\n4. Updated stats:", updatedStats);
// Show learned skills
console.log("\n5. Learned skills:");
const skills = globalSkillbook.getSkills();
for (const skill of skills) {
console.log(` - ${skill.id}: ${skill.content.substring(0, 60)}...`);
}
// Test prompt enhancement
console.log("\n6. Prompt enhancement test:");
const basePrompt = "Write a function to parse JSON";
const enhanced = globalACEPlugin.enhancePrompt(basePrompt);
console.log(` Base: ${basePrompt}`);
console.log(` Enhanced length: ${enhanced.length} chars`);
console.log(enhanced.substring(0, 300) + "...");
console.log("\n=== Demo Complete ===");
}
main().catch(console.error);