Repository navigation
Expand file tree
/
Copy pathexample.js
More file actions
57 lines (47 loc) · 2.07 KB
/
Copy pathexample.js
File metadata and controls
57 lines (47 loc) · 2.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
/**
* agent-tension — quick start example
* Run: node example.js
*/
import { DriveSystem } from './index.js';
const drive = new DriveSystem();
const goals = [
{ id: 1, title: 'Write unit tests', confidence: 0.4, createdAt: Date.now() - 90 * 60_000 },
{ id: 2, title: 'Refactor auth module', confidence: 0.25, createdAt: Date.now() - 20 * 60_000 },
{ id: 3, title: 'Update documentation', confidence: 0.6, createdAt: Date.now() - 5 * 60_000 },
];
console.log('=== Agent wakes up — no work done yet ===\n');
console.log('Status:', drive.getStatus());
console.log();
// Simulate 15 idle ticks (agent did nothing)
console.log('--- 15 idle ticks pass ---\n');
for (let i = 0; i < 15; i++) drive.onIdleTick();
const s1 = drive.getStatus();
console.log(`Tension: ${(s1.tension * 100).toFixed(0)}% threshold: ${(s1.actionThreshold * 100).toFixed(0)}% urgent: ${s1.isUrgent}`);
console.log();
// Which goals can we act on now?
console.log('--- Goal evaluation ---\n');
for (const goal of goals) {
const boost = drive.getUrgencyBoost(goal);
const canAct = drive.confidenceMet(goal.confidence);
const effectivePriority = goal.confidence * 100 + boost;
console.log(`"${goal.title}"`);
console.log(` confidence=${(goal.confidence*100).toFixed(0)}% urgency_boost=+${boost} effective_priority=${effectivePriority.toFixed(0)} act=${canAct}`);
}
console.log();
// Agent works on the highest priority goal
console.log('--- Agent executes "Write unit tests" ---\n');
drive.onTaskExecuted(goals[0]);
console.log('Status:', drive.getStatus());
console.log();
// Agent completes it
console.log('--- Goal completed ---\n');
drive.onGoalComplete(goals[0]);
console.log('Status:', drive.getStatus());
console.log();
// Serialize and restore
console.log('--- Serialize / restore ---\n');
const saved = JSON.stringify(drive.toJSON());
const { DriveSystem: DS } = await import('./index.js');
const restored = DS.fromJSON(JSON.parse(saved));
console.log('Restored tension:', (restored.tension * 100).toFixed(0) + '%');
console.log('Goals completed:', restored.goalsCompleted);