@praveencs/agent 0.1.1 → 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/src/cli/commands/daemon.d.ts.map +1 -1
- package/dist/src/cli/commands/daemon.js +147 -7
- package/dist/src/cli/commands/daemon.js.map +1 -1
- package/dist/src/cli/commands/goal.d.ts +7 -0
- package/dist/src/cli/commands/goal.d.ts.map +1 -0
- package/dist/src/cli/commands/goal.js +246 -0
- package/dist/src/cli/commands/goal.js.map +1 -0
- package/dist/src/cli/commands/memory.d.ts +3 -0
- package/dist/src/cli/commands/memory.d.ts.map +1 -0
- package/dist/src/cli/commands/memory.js +108 -0
- package/dist/src/cli/commands/memory.js.map +1 -0
- package/dist/src/cli/index.d.ts.map +1 -1
- package/dist/src/cli/index.js +7 -2
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/daemon/manager.d.ts +9 -3
- package/dist/src/daemon/manager.d.ts.map +1 -1
- package/dist/src/daemon/manager.js +31 -10
- package/dist/src/daemon/manager.js.map +1 -1
- package/dist/src/daemon/service.d.ts +76 -0
- package/dist/src/daemon/service.d.ts.map +1 -0
- package/dist/src/daemon/service.js +284 -0
- package/dist/src/daemon/service.js.map +1 -0
- package/dist/src/daemon/triggers.d.ts +34 -0
- package/dist/src/daemon/triggers.d.ts.map +1 -0
- package/dist/src/daemon/triggers.js +76 -0
- package/dist/src/daemon/triggers.js.map +1 -0
- package/dist/src/goals/store.d.ts +128 -0
- package/dist/src/goals/store.d.ts.map +1 -0
- package/dist/src/goals/store.js +234 -0
- package/dist/src/goals/store.js.map +1 -0
- package/dist/src/memory/store.d.ts +69 -0
- package/dist/src/memory/store.d.ts.map +1 -0
- package/dist/src/memory/store.js +255 -0
- package/dist/src/memory/store.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse as parseYaml } from 'yaml';
|
|
4
|
+
/**
|
|
5
|
+
* Load triggers from .agent/triggers.yaml
|
|
6
|
+
*/
|
|
7
|
+
export async function loadTriggers(workDir) {
|
|
8
|
+
const dir = workDir ?? process.cwd();
|
|
9
|
+
const triggersPath = path.join(dir, '.agent', 'triggers.yaml');
|
|
10
|
+
try {
|
|
11
|
+
const content = await readFile(triggersPath, 'utf-8');
|
|
12
|
+
const parsed = parseYaml(content);
|
|
13
|
+
if (!parsed?.triggers || !Array.isArray(parsed.triggers)) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return parsed.triggers
|
|
17
|
+
.filter(t => t.enabled !== false)
|
|
18
|
+
.map(t => ({
|
|
19
|
+
...t,
|
|
20
|
+
enabled: t.enabled !== false,
|
|
21
|
+
debounce: t.debounce ?? 2000,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the default triggers template
|
|
30
|
+
*/
|
|
31
|
+
export function getDefaultTriggersYaml() {
|
|
32
|
+
return `# Agent Daemon Triggers
|
|
33
|
+
# These define what the daemon watches and automates.
|
|
34
|
+
# Event types: file.changed, cron, webhook, git.push, goal.check
|
|
35
|
+
|
|
36
|
+
triggers:
|
|
37
|
+
# Process the goal/task queue every 2 minutes
|
|
38
|
+
- name: goal-processor
|
|
39
|
+
event: goal.check
|
|
40
|
+
schedule: "*/2 * * * *"
|
|
41
|
+
enabled: true
|
|
42
|
+
action:
|
|
43
|
+
type: goal-progress
|
|
44
|
+
|
|
45
|
+
# Daily standup report from git log
|
|
46
|
+
# - name: morning-standup
|
|
47
|
+
# event: cron
|
|
48
|
+
# schedule: "0 9 * * 1-5"
|
|
49
|
+
# enabled: false
|
|
50
|
+
# action:
|
|
51
|
+
# skill: git-commit
|
|
52
|
+
# input:
|
|
53
|
+
# type: standup-report
|
|
54
|
+
|
|
55
|
+
# Auto code-review on file changes
|
|
56
|
+
# - name: auto-review
|
|
57
|
+
# event: file.changed
|
|
58
|
+
# watch: "src/**/*.ts"
|
|
59
|
+
# debounce: 5000
|
|
60
|
+
# enabled: false
|
|
61
|
+
# action:
|
|
62
|
+
# skill: code-review
|
|
63
|
+
# input:
|
|
64
|
+
# scope: changed-files
|
|
65
|
+
|
|
66
|
+
# System health check every hour
|
|
67
|
+
# - name: health-check
|
|
68
|
+
# event: cron
|
|
69
|
+
# schedule: "0 * * * *"
|
|
70
|
+
# enabled: false
|
|
71
|
+
# action:
|
|
72
|
+
# skill: system-monitor
|
|
73
|
+
# report: true
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=triggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggers.js","sourceRoot":"","sources":["../../../src/daemon/triggers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAmC1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAgB;IAC/C,MAAM,GAAG,GAAG,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACrC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;IAE/D,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAiB,CAAC;QAElD,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvD,OAAO,EAAE,CAAC;QACd,CAAC;QAED,OAAO,MAAM,CAAC,QAAQ;aACjB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC;aAChC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACP,GAAG,CAAC;YACJ,OAAO,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK;YAC5B,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;SAC/B,CAAC,CAAC,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IAClC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CV,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { MemoryStore } from '../memory/store.js';
|
|
2
|
+
/**
|
|
3
|
+
* Goal & Task management for autonomous execution
|
|
4
|
+
*/
|
|
5
|
+
export interface Goal {
|
|
6
|
+
id: number;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string | null;
|
|
9
|
+
status: 'active' | 'paused' | 'completed' | 'failed' | 'cancelled';
|
|
10
|
+
priority: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
updated_at: string;
|
|
13
|
+
deadline: string | null;
|
|
14
|
+
parent_goal_id: number | null;
|
|
15
|
+
progress: number;
|
|
16
|
+
metadata: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export interface Task {
|
|
19
|
+
id: number;
|
|
20
|
+
goal_id: number;
|
|
21
|
+
title: string;
|
|
22
|
+
description: string | null;
|
|
23
|
+
status: 'pending' | 'queued' | 'running' | 'completed' | 'failed' | 'blocked' | 'cancelled';
|
|
24
|
+
skill: string | null;
|
|
25
|
+
input: Record<string, any>;
|
|
26
|
+
output: string | null;
|
|
27
|
+
depends_on: number[];
|
|
28
|
+
scheduled_at: string | null;
|
|
29
|
+
started_at: string | null;
|
|
30
|
+
completed_at: string | null;
|
|
31
|
+
retry_count: number;
|
|
32
|
+
max_retries: number;
|
|
33
|
+
error: string | null;
|
|
34
|
+
requires_approval: boolean;
|
|
35
|
+
approved_at: string | null;
|
|
36
|
+
created_at: string;
|
|
37
|
+
}
|
|
38
|
+
export declare class GoalStore {
|
|
39
|
+
private db;
|
|
40
|
+
constructor(memoryStore: MemoryStore);
|
|
41
|
+
/**
|
|
42
|
+
* Create a new goal
|
|
43
|
+
*/
|
|
44
|
+
addGoal(title: string, options?: {
|
|
45
|
+
description?: string;
|
|
46
|
+
priority?: number;
|
|
47
|
+
deadline?: string;
|
|
48
|
+
parentGoalId?: number;
|
|
49
|
+
}): Goal;
|
|
50
|
+
/**
|
|
51
|
+
* Get a goal by ID
|
|
52
|
+
*/
|
|
53
|
+
getGoal(id: number): Goal | null;
|
|
54
|
+
/**
|
|
55
|
+
* List goals by status
|
|
56
|
+
*/
|
|
57
|
+
listGoals(status?: Goal['status']): Goal[];
|
|
58
|
+
/**
|
|
59
|
+
* Update goal status
|
|
60
|
+
*/
|
|
61
|
+
updateGoalStatus(id: number, status: Goal['status']): void;
|
|
62
|
+
/**
|
|
63
|
+
* Update goal progress (0.0 to 1.0)
|
|
64
|
+
*/
|
|
65
|
+
updateGoalProgress(id: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Delete a goal and its tasks
|
|
68
|
+
*/
|
|
69
|
+
removeGoal(id: number): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Add a task to a goal
|
|
72
|
+
*/
|
|
73
|
+
addTask(goalId: number, title: string, options?: {
|
|
74
|
+
description?: string;
|
|
75
|
+
skill?: string;
|
|
76
|
+
input?: Record<string, any>;
|
|
77
|
+
dependsOn?: number[];
|
|
78
|
+
requiresApproval?: boolean;
|
|
79
|
+
scheduledAt?: string;
|
|
80
|
+
}): Task;
|
|
81
|
+
/**
|
|
82
|
+
* Get a task by ID
|
|
83
|
+
*/
|
|
84
|
+
getTask(id: number): Task | null;
|
|
85
|
+
/**
|
|
86
|
+
* List tasks for a goal
|
|
87
|
+
*/
|
|
88
|
+
listTasks(goalId: number): Task[];
|
|
89
|
+
/**
|
|
90
|
+
* Get the next executable task (respects dependencies)
|
|
91
|
+
*/
|
|
92
|
+
getNextTask(): Task | null;
|
|
93
|
+
/**
|
|
94
|
+
* Mark task as running
|
|
95
|
+
*/
|
|
96
|
+
startTask(id: number): void;
|
|
97
|
+
/**
|
|
98
|
+
* Mark task as completed
|
|
99
|
+
*/
|
|
100
|
+
completeTask(id: number, output: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Mark task as failed
|
|
103
|
+
*/
|
|
104
|
+
failTask(id: number, error: string): void;
|
|
105
|
+
/**
|
|
106
|
+
* Approve a task that requires human approval
|
|
107
|
+
*/
|
|
108
|
+
approveTask(id: number): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get tasks waiting for approval
|
|
111
|
+
*/
|
|
112
|
+
getPendingApprovals(): Task[];
|
|
113
|
+
/**
|
|
114
|
+
* Get summary stats
|
|
115
|
+
*/
|
|
116
|
+
stats(): {
|
|
117
|
+
activeGoals: number;
|
|
118
|
+
completedGoals: number;
|
|
119
|
+
pendingTasks: number;
|
|
120
|
+
runningTasks: number;
|
|
121
|
+
completedTasks: number;
|
|
122
|
+
failedTasks: number;
|
|
123
|
+
awaitingApproval: number;
|
|
124
|
+
};
|
|
125
|
+
private parseTask;
|
|
126
|
+
private logAudit;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/goals/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AAEH,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAA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IACH,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAY9C;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAqBzC;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAWhC;;OAEG;IACH,mBAAmB,IAAI,IAAI,EAAE;IAU7B;;OAEG;IACH,KAAK,IAAI;QACL,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,MAAM,CAAC;QACrB,YAAY,EAAE,MAAM,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;KAC5B;IAeD,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,QAAQ;CAMnB"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
export class GoalStore {
|
|
2
|
+
db;
|
|
3
|
+
constructor(memoryStore) {
|
|
4
|
+
// Reuse the same database from MemoryStore
|
|
5
|
+
this.db = memoryStore.db;
|
|
6
|
+
}
|
|
7
|
+
// ─── Goal Operations ──────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Create a new goal
|
|
10
|
+
*/
|
|
11
|
+
addGoal(title, options = {}) {
|
|
12
|
+
const stmt = this.db.prepare(`
|
|
13
|
+
INSERT INTO goals (title, description, priority, deadline, parent_goal_id)
|
|
14
|
+
VALUES (?, ?, ?, ?, ?)
|
|
15
|
+
`);
|
|
16
|
+
const result = stmt.run(title, options.description ?? null, options.priority ?? 5, options.deadline ?? null, options.parentGoalId ?? null);
|
|
17
|
+
this.logAudit('goal.created', 'goal', result.lastInsertRowid, title);
|
|
18
|
+
return this.getGoal(result.lastInsertRowid);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get a goal by ID
|
|
22
|
+
*/
|
|
23
|
+
getGoal(id) {
|
|
24
|
+
const row = this.db.prepare('SELECT * FROM goals WHERE id = ?').get(id);
|
|
25
|
+
if (!row)
|
|
26
|
+
return null;
|
|
27
|
+
return { ...row, metadata: JSON.parse(row.metadata || '{}') };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* List goals by status
|
|
31
|
+
*/
|
|
32
|
+
listGoals(status) {
|
|
33
|
+
let rows;
|
|
34
|
+
if (status) {
|
|
35
|
+
rows = this.db.prepare('SELECT * FROM goals WHERE status = ? ORDER BY priority ASC, created_at DESC').all(status);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
rows = this.db.prepare('SELECT * FROM goals ORDER BY status ASC, priority ASC, created_at DESC').all();
|
|
39
|
+
}
|
|
40
|
+
return rows.map(r => ({ ...r, metadata: JSON.parse(r.metadata || '{}') }));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Update goal status
|
|
44
|
+
*/
|
|
45
|
+
updateGoalStatus(id, status) {
|
|
46
|
+
this.db.prepare(`
|
|
47
|
+
UPDATE goals SET status = ?, updated_at = datetime('now') WHERE id = ?
|
|
48
|
+
`).run(status, id);
|
|
49
|
+
this.logAudit(`goal.${status}`, 'goal', id, `Goal #${id} → ${status}`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Update goal progress (0.0 to 1.0)
|
|
53
|
+
*/
|
|
54
|
+
updateGoalProgress(id) {
|
|
55
|
+
const tasks = this.listTasks(id);
|
|
56
|
+
if (tasks.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
const completed = tasks.filter(t => t.status === 'completed').length;
|
|
59
|
+
const progress = completed / tasks.length;
|
|
60
|
+
this.db.prepare(`
|
|
61
|
+
UPDATE goals SET progress = ?, updated_at = datetime('now') WHERE id = ?
|
|
62
|
+
`).run(progress, id);
|
|
63
|
+
// Auto-complete goal if all tasks done
|
|
64
|
+
if (progress >= 1.0) {
|
|
65
|
+
this.updateGoalStatus(id, 'completed');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete a goal and its tasks
|
|
70
|
+
*/
|
|
71
|
+
removeGoal(id) {
|
|
72
|
+
const result = this.db.prepare('DELETE FROM goals WHERE id = ?').run(id);
|
|
73
|
+
return result.changes > 0;
|
|
74
|
+
}
|
|
75
|
+
// ─── Task Operations ──────────────────────────────────────
|
|
76
|
+
/**
|
|
77
|
+
* Add a task to a goal
|
|
78
|
+
*/
|
|
79
|
+
addTask(goalId, title, options = {}) {
|
|
80
|
+
const stmt = this.db.prepare(`
|
|
81
|
+
INSERT INTO tasks (goal_id, title, description, skill, input, depends_on, requires_approval, scheduled_at)
|
|
82
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
83
|
+
`);
|
|
84
|
+
const result = stmt.run(goalId, title, options.description ?? null, options.skill ?? null, JSON.stringify(options.input ?? {}), JSON.stringify(options.dependsOn ?? []), options.requiresApproval ? 1 : 0, options.scheduledAt ?? null);
|
|
85
|
+
this.logAudit('task.created', 'task', result.lastInsertRowid, title);
|
|
86
|
+
return this.getTask(result.lastInsertRowid);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get a task by ID
|
|
90
|
+
*/
|
|
91
|
+
getTask(id) {
|
|
92
|
+
const row = this.db.prepare('SELECT * FROM tasks WHERE id = ?').get(id);
|
|
93
|
+
if (!row)
|
|
94
|
+
return null;
|
|
95
|
+
return this.parseTask(row);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* List tasks for a goal
|
|
99
|
+
*/
|
|
100
|
+
listTasks(goalId) {
|
|
101
|
+
const rows = this.db.prepare('SELECT * FROM tasks WHERE goal_id = ? ORDER BY id ASC').all(goalId);
|
|
102
|
+
return rows.map(r => this.parseTask(r));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the next executable task (respects dependencies)
|
|
106
|
+
*/
|
|
107
|
+
getNextTask() {
|
|
108
|
+
// Get all pending/queued tasks ordered by goal priority
|
|
109
|
+
const candidates = this.db.prepare(`
|
|
110
|
+
SELECT t.* FROM tasks t
|
|
111
|
+
JOIN goals g ON t.goal_id = g.id
|
|
112
|
+
WHERE t.status IN ('pending', 'queued')
|
|
113
|
+
AND g.status = 'active'
|
|
114
|
+
ORDER BY g.priority ASC, t.id ASC
|
|
115
|
+
`).all();
|
|
116
|
+
for (const row of candidates) {
|
|
117
|
+
const task = this.parseTask(row);
|
|
118
|
+
// Check dependencies
|
|
119
|
+
if (task.depends_on.length > 0) {
|
|
120
|
+
const deps = task.depends_on.map(id => this.getTask(id));
|
|
121
|
+
const allMet = deps.every(d => d?.status === 'completed');
|
|
122
|
+
if (!allMet)
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
// Check if approval is needed and granted
|
|
126
|
+
if (task.requires_approval && !task.approved_at)
|
|
127
|
+
continue;
|
|
128
|
+
return task;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Mark task as running
|
|
134
|
+
*/
|
|
135
|
+
startTask(id) {
|
|
136
|
+
this.db.prepare(`
|
|
137
|
+
UPDATE tasks SET status = 'running', started_at = datetime('now') WHERE id = ?
|
|
138
|
+
`).run(id);
|
|
139
|
+
this.logAudit('task.started', 'task', id, `Task #${id} started`);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Mark task as completed
|
|
143
|
+
*/
|
|
144
|
+
completeTask(id, output) {
|
|
145
|
+
this.db.prepare(`
|
|
146
|
+
UPDATE tasks SET status = 'completed', output = ?, completed_at = datetime('now')
|
|
147
|
+
WHERE id = ?
|
|
148
|
+
`).run(output, id);
|
|
149
|
+
this.logAudit('task.completed', 'task', id, `Task #${id} completed`);
|
|
150
|
+
// Update goal progress
|
|
151
|
+
const task = this.getTask(id);
|
|
152
|
+
if (task)
|
|
153
|
+
this.updateGoalProgress(task.goal_id);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Mark task as failed
|
|
157
|
+
*/
|
|
158
|
+
failTask(id, error) {
|
|
159
|
+
const task = this.getTask(id);
|
|
160
|
+
if (!task)
|
|
161
|
+
return;
|
|
162
|
+
if (task.retry_count < task.max_retries) {
|
|
163
|
+
// Retry
|
|
164
|
+
this.db.prepare(`
|
|
165
|
+
UPDATE tasks SET status = 'pending', retry_count = retry_count + 1, error = ?
|
|
166
|
+
WHERE id = ?
|
|
167
|
+
`).run(error, id);
|
|
168
|
+
this.logAudit('task.retry', 'task', id, `Task #${id} retry ${task.retry_count + 1}/${task.max_retries}: ${error}`);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// Final failure
|
|
172
|
+
this.db.prepare(`
|
|
173
|
+
UPDATE tasks SET status = 'failed', error = ?, completed_at = datetime('now')
|
|
174
|
+
WHERE id = ?
|
|
175
|
+
`).run(error, id);
|
|
176
|
+
this.logAudit('task.failed', 'task', id, `Task #${id} failed: ${error}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Approve a task that requires human approval
|
|
181
|
+
*/
|
|
182
|
+
approveTask(id) {
|
|
183
|
+
const result = this.db.prepare(`
|
|
184
|
+
UPDATE tasks SET approved_at = datetime('now'), status = 'queued'
|
|
185
|
+
WHERE id = ? AND requires_approval = 1
|
|
186
|
+
`).run(id);
|
|
187
|
+
if (result.changes > 0) {
|
|
188
|
+
this.logAudit('task.approved', 'task', id, `Task #${id} approved`);
|
|
189
|
+
}
|
|
190
|
+
return result.changes > 0;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get tasks waiting for approval
|
|
194
|
+
*/
|
|
195
|
+
getPendingApprovals() {
|
|
196
|
+
const rows = this.db.prepare(`
|
|
197
|
+
SELECT * FROM tasks
|
|
198
|
+
WHERE requires_approval = 1 AND approved_at IS NULL
|
|
199
|
+
AND status NOT IN ('cancelled', 'completed', 'failed')
|
|
200
|
+
ORDER BY id ASC
|
|
201
|
+
`).all();
|
|
202
|
+
return rows.map(r => this.parseTask(r));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get summary stats
|
|
206
|
+
*/
|
|
207
|
+
stats() {
|
|
208
|
+
return {
|
|
209
|
+
activeGoals: this.db.prepare("SELECT COUNT(*) as c FROM goals WHERE status = 'active'").get().c,
|
|
210
|
+
completedGoals: this.db.prepare("SELECT COUNT(*) as c FROM goals WHERE status = 'completed'").get().c,
|
|
211
|
+
pendingTasks: this.db.prepare("SELECT COUNT(*) as c FROM tasks WHERE status IN ('pending','queued')").get().c,
|
|
212
|
+
runningTasks: this.db.prepare("SELECT COUNT(*) as c FROM tasks WHERE status = 'running'").get().c,
|
|
213
|
+
completedTasks: this.db.prepare("SELECT COUNT(*) as c FROM tasks WHERE status = 'completed'").get().c,
|
|
214
|
+
failedTasks: this.db.prepare("SELECT COUNT(*) as c FROM tasks WHERE status = 'failed'").get().c,
|
|
215
|
+
awaitingApproval: this.db.prepare("SELECT COUNT(*) as c FROM tasks WHERE requires_approval = 1 AND approved_at IS NULL AND status NOT IN ('cancelled','completed','failed')").get().c,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
// ─── Helpers ──────────────────────────────────────────────
|
|
219
|
+
parseTask(row) {
|
|
220
|
+
return {
|
|
221
|
+
...row,
|
|
222
|
+
input: JSON.parse(row.input || '{}'),
|
|
223
|
+
depends_on: JSON.parse(row.depends_on || '[]'),
|
|
224
|
+
requires_approval: !!row.requires_approval,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
logAudit(eventType, entityType, entityId, details) {
|
|
228
|
+
this.db.prepare(`
|
|
229
|
+
INSERT INTO audit_events (event_type, entity_type, entity_id, action, details)
|
|
230
|
+
VALUES (?, ?, ?, ?, ?)
|
|
231
|
+
`).run(eventType, entityType, entityId, eventType, details);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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OAAO,CAAC,yDAAyD,CAAC,CAAC,GAAG,EAAU,CAAC,CAAC;YACxG,gBAAgB,EAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,0IAA0I,CAAC,CAAC,GAAG,EAAU,CAAC,CAAC;SACjM,CAAC;IACN,CAAC;IAED,6DAA6D;IAErD,SAAS,CAAC,GAAQ;QACtB,OAAO;YACH,GAAG,GAAG;YACN,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC;YACpC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,CAAC;YAC9C,iBAAiB,EAAE,CAAC,CAAC,GAAG,CAAC,iBAAiB;SAC7C,CAAC;IACN,CAAC;IAEO,QAAQ,CAAC,SAAiB,EAAE,UAAkB,EAAE,QAAgB,EAAE,OAAe;QACrF,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC;;;SAGf,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;CACJ"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Store — Persistent agent memory backed by SQLite + FTS5
|
|
3
|
+
*
|
|
4
|
+
* Stores facts, project context, and learned information
|
|
5
|
+
* that persists across sessions.
|
|
6
|
+
*/
|
|
7
|
+
export interface Memory {
|
|
8
|
+
id: number;
|
|
9
|
+
content: string;
|
|
10
|
+
category: 'project' | 'preference' | 'fact' | 'learned' | 'general';
|
|
11
|
+
source: 'user' | 'agent' | 'auto';
|
|
12
|
+
tags: string[];
|
|
13
|
+
created_at: string;
|
|
14
|
+
accessed_at: string | null;
|
|
15
|
+
relevance_score: number;
|
|
16
|
+
}
|
|
17
|
+
export interface MemorySearchResult extends Memory {
|
|
18
|
+
rank: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class MemoryStore {
|
|
21
|
+
private db;
|
|
22
|
+
private static instance;
|
|
23
|
+
constructor(dbPath: string);
|
|
24
|
+
/**
|
|
25
|
+
* Get singleton instance scoped to a working directory
|
|
26
|
+
*/
|
|
27
|
+
static open(workDir: string): MemoryStore;
|
|
28
|
+
/**
|
|
29
|
+
* Run database migrations
|
|
30
|
+
*/
|
|
31
|
+
private migrate;
|
|
32
|
+
/**
|
|
33
|
+
* Save a new memory
|
|
34
|
+
*/
|
|
35
|
+
save(content: string, category?: Memory['category'], source?: Memory['source'], tags?: string[]): Memory;
|
|
36
|
+
/**
|
|
37
|
+
* Search memories using full-text search
|
|
38
|
+
*/
|
|
39
|
+
search(query: string, limit?: number): MemorySearchResult[];
|
|
40
|
+
/**
|
|
41
|
+
* Get all memories, optionally filtered by category
|
|
42
|
+
*/
|
|
43
|
+
list(category?: Memory['category'], limit?: number): Memory[];
|
|
44
|
+
/**
|
|
45
|
+
* Get a specific memory by ID
|
|
46
|
+
*/
|
|
47
|
+
getMemory(id: number): Memory | null;
|
|
48
|
+
/**
|
|
49
|
+
* Delete a memory
|
|
50
|
+
*/
|
|
51
|
+
forget(id: number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get relevant context for an LLM prompt
|
|
54
|
+
* Searches memories and returns formatted context
|
|
55
|
+
*/
|
|
56
|
+
getContext(query: string, maxTokens?: number): string;
|
|
57
|
+
/**
|
|
58
|
+
* Get memory count and stats
|
|
59
|
+
*/
|
|
60
|
+
stats(): {
|
|
61
|
+
total: number;
|
|
62
|
+
byCategory: Record<string, number>;
|
|
63
|
+
bySource: Record<string, number>;
|
|
64
|
+
};
|
|
65
|
+
private logAudit;
|
|
66
|
+
getAuditLog(limit?: number): any[];
|
|
67
|
+
close(): void;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/memory/store.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;A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