agentboss 0.1.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/README.md +34 -0
- package/bin/aboss.js +288 -0
- package/client/dist/assets/index-C1wFD_Vo.css +1 -0
- package/client/dist/assets/index-DBj1Ujlx.js +137 -0
- package/client/dist/index.html +34 -0
- package/package.json +64 -0
- package/server/analysis/daily-aggregator.js +258 -0
- package/server/analysis/difficulty.js +129 -0
- package/server/analysis/dimensions/ai-knowledge.js +172 -0
- package/server/analysis/dimensions/ai-tools.js +161 -0
- package/server/analysis/dimensions/judgement.js +107 -0
- package/server/analysis/dimensions/llm-merge.js +57 -0
- package/server/analysis/dimensions/output-quality.js +167 -0
- package/server/analysis/dimensions/problem-definition.js +104 -0
- package/server/analysis/dimensions/system-thinking.js +225 -0
- package/server/analysis/evidence-builder.js +104 -0
- package/server/analysis/job.js +273 -0
- package/server/analysis/report-builder.js +581 -0
- package/server/analysis/scoring-v2.js +72 -0
- package/server/analysis/text-signals.js +179 -0
- package/server/analysis/thresholds-v2.js +358 -0
- package/server/api/advice.js +124 -0
- package/server/api/analysis.js +141 -0
- package/server/api/execution.js +330 -0
- package/server/api/metrics.js +277 -0
- package/server/api/overview.js +308 -0
- package/server/api/project.js +255 -0
- package/server/api/reports.js +125 -0
- package/server/api/sessions.js +118 -0
- package/server/api/settings.js +119 -0
- package/server/db/connection.js +175 -0
- package/server/db/queries.js +1051 -0
- package/server/db/schema.js +487 -0
- package/server/etl/active-time.js +150 -0
- package/server/etl/backfill-subagents.js +178 -0
- package/server/etl/claude-code.js +826 -0
- package/server/etl/detect.js +341 -0
- package/server/etl/judge-filter.js +117 -0
- package/server/etl/opencode.js +606 -0
- package/server/execution/job.js +662 -0
- package/server/execution/prompt.js +227 -0
- package/server/execution/runner.js +218 -0
- package/server/index.js +94 -0
- package/server/llm/advice-prompt.js +339 -0
- package/server/llm/advice.js +384 -0
- package/server/llm/analysis-prompt.js +162 -0
- package/server/llm/cli-runner.js +249 -0
- package/server/llm/judge-prompts.js +179 -0
- package/server/llm/judge.js +118 -0
- package/server/llm/project-advice-prompt.js +332 -0
- package/server/llm/project-advice.js +491 -0
- package/server/llm/session-analyzer.js +122 -0
- package/server/utils/project.js +80 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection manager for Agent Boss.
|
|
3
|
+
*
|
|
4
|
+
* Opens (or creates) the boss.db SQLite database via sql.js and exposes a
|
|
5
|
+
* singleton Promise-based accessor. The in-memory database is periodically
|
|
6
|
+
* flushed to disk and saved on close.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const { getDb, saveDb, closeDb } = require('./connection');
|
|
10
|
+
* const db = await getDb();
|
|
11
|
+
* db.run('SELECT 1');
|
|
12
|
+
*
|
|
13
|
+
* @author Felix
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const initSqlJs = require('sql.js');
|
|
19
|
+
const { initDatabase, getDbPath } = require('./schema');
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Internal state
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/** @type {Promise<import('sql.js').Database> | null} */
|
|
26
|
+
let _dbPromise = null;
|
|
27
|
+
|
|
28
|
+
/** @type {import('sql.js').Database | null} */
|
|
29
|
+
let _dbInstance = null;
|
|
30
|
+
|
|
31
|
+
/** @type {NodeJS.Timeout | null} */
|
|
32
|
+
let _autoSaveTimer = null;
|
|
33
|
+
|
|
34
|
+
/** Auto-save interval in milliseconds (default: 30 s). */
|
|
35
|
+
const AUTO_SAVE_INTERVAL_MS = 30_000;
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Helpers
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Ensure the directory for the database file exists.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} dbPath Absolute path to the database file.
|
|
45
|
+
*/
|
|
46
|
+
function ensureDir(dbPath) {
|
|
47
|
+
const dir = path.dirname(dbPath);
|
|
48
|
+
if (!fs.existsSync(dir)) {
|
|
49
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Write the current in-memory database to disk.
|
|
55
|
+
*
|
|
56
|
+
* Safe to call at any time — if there is no active database instance the
|
|
57
|
+
* call is a no-op.
|
|
58
|
+
*/
|
|
59
|
+
function saveDb() {
|
|
60
|
+
if (!_dbInstance) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const dbPath = getDbPath();
|
|
64
|
+
ensureDir(dbPath);
|
|
65
|
+
const data = _dbInstance.export();
|
|
66
|
+
fs.writeFileSync(dbPath, Buffer.from(data));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Start the periodic auto-save timer. If a timer is already running it is
|
|
71
|
+
* left untouched.
|
|
72
|
+
*/
|
|
73
|
+
function startAutoSave() {
|
|
74
|
+
if (_autoSaveTimer) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
_autoSaveTimer = setInterval(() => {
|
|
78
|
+
try {
|
|
79
|
+
saveDb();
|
|
80
|
+
} catch (_err) {
|
|
81
|
+
// Swallow — auto-save is best-effort. The caller can always invoke
|
|
82
|
+
// saveDb() explicitly for error handling.
|
|
83
|
+
}
|
|
84
|
+
}, AUTO_SAVE_INTERVAL_MS);
|
|
85
|
+
|
|
86
|
+
// Allow the Node process to exit even if the timer is still active.
|
|
87
|
+
if (_autoSaveTimer.unref) {
|
|
88
|
+
_autoSaveTimer.unref();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Public API
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Return the singleton sql.js Database instance, initialising it on the
|
|
98
|
+
* first call.
|
|
99
|
+
*
|
|
100
|
+
* - If `~/.agent-boss/boss.db` exists the file is loaded into memory.
|
|
101
|
+
* - Otherwise a fresh in-memory database is created.
|
|
102
|
+
* - The full schema from `schema.js` is applied (CREATE IF NOT EXISTS).
|
|
103
|
+
* - An auto-save timer is started to periodically flush to disk.
|
|
104
|
+
*
|
|
105
|
+
* @returns {Promise<import('sql.js').Database>} Resolves to the database.
|
|
106
|
+
*/
|
|
107
|
+
function getDb() {
|
|
108
|
+
if (_dbPromise) {
|
|
109
|
+
return _dbPromise;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_dbPromise = (async () => {
|
|
113
|
+
const SQL = await initSqlJs();
|
|
114
|
+
const dbPath = getDbPath();
|
|
115
|
+
|
|
116
|
+
let db;
|
|
117
|
+
if (fs.existsSync(dbPath)) {
|
|
118
|
+
const fileBuffer = fs.readFileSync(dbPath);
|
|
119
|
+
db = new SQL.Database(fileBuffer);
|
|
120
|
+
} else {
|
|
121
|
+
ensureDir(dbPath);
|
|
122
|
+
db = new SQL.Database();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Apply / migrate schema (all statements are IF NOT EXISTS).
|
|
126
|
+
initDatabase(db);
|
|
127
|
+
|
|
128
|
+
_dbInstance = db;
|
|
129
|
+
|
|
130
|
+
// Persist the freshly-created / migrated database immediately so the
|
|
131
|
+
// file on disk is always up-to-date with the latest schema.
|
|
132
|
+
saveDb();
|
|
133
|
+
|
|
134
|
+
startAutoSave();
|
|
135
|
+
|
|
136
|
+
return db;
|
|
137
|
+
})();
|
|
138
|
+
|
|
139
|
+
// If initialisation fails, reset so the next call retries.
|
|
140
|
+
_dbPromise.catch(() => {
|
|
141
|
+
_dbPromise = null;
|
|
142
|
+
_dbInstance = null;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return _dbPromise;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Flush the database to disk and release all resources.
|
|
150
|
+
*
|
|
151
|
+
* After calling this the next `getDb()` call will re-open the database from
|
|
152
|
+
* the saved file.
|
|
153
|
+
*/
|
|
154
|
+
async function closeDb() {
|
|
155
|
+
if (_autoSaveTimer) {
|
|
156
|
+
clearInterval(_autoSaveTimer);
|
|
157
|
+
_autoSaveTimer = null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (_dbPromise) {
|
|
161
|
+
try {
|
|
162
|
+
const db = await _dbPromise;
|
|
163
|
+
// Final save before close.
|
|
164
|
+
saveDb();
|
|
165
|
+
db.close();
|
|
166
|
+
} catch (_err) {
|
|
167
|
+
// If getDb() itself had failed there is nothing to close.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_dbPromise = null;
|
|
172
|
+
_dbInstance = null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
module.exports = { getDb, saveDb, closeDb };
|