@hasna/todos 0.5.1 → 0.6.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/cli/index.js +319 -39
- package/dist/index.d.ts +2 -0
- package/dist/index.js +126 -1
- package/dist/mcp/index.js +34 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2332,6 +2332,36 @@ var init_database = __esm(() => {
|
|
|
2332
2332
|
);
|
|
2333
2333
|
CREATE INDEX IF NOT EXISTS idx_api_keys_hash ON api_keys(key_hash);
|
|
2334
2334
|
INSERT OR IGNORE INTO _migrations (id) VALUES (5);
|
|
2335
|
+
`,
|
|
2336
|
+
`
|
|
2337
|
+
CREATE TABLE IF NOT EXISTS audit_log (
|
|
2338
|
+
id TEXT PRIMARY KEY,
|
|
2339
|
+
entity_type TEXT NOT NULL CHECK(entity_type IN ('task', 'plan', 'project', 'api_key', 'comment')),
|
|
2340
|
+
entity_id TEXT NOT NULL,
|
|
2341
|
+
action TEXT NOT NULL CHECK(action IN ('create', 'update', 'delete', 'start', 'complete', 'lock', 'unlock')),
|
|
2342
|
+
actor TEXT,
|
|
2343
|
+
changes TEXT,
|
|
2344
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
2345
|
+
);
|
|
2346
|
+
CREATE INDEX IF NOT EXISTS idx_audit_entity ON audit_log(entity_type, entity_id);
|
|
2347
|
+
CREATE INDEX IF NOT EXISTS idx_audit_created ON audit_log(created_at);
|
|
2348
|
+
|
|
2349
|
+
CREATE TABLE IF NOT EXISTS webhooks (
|
|
2350
|
+
id TEXT PRIMARY KEY,
|
|
2351
|
+
url TEXT NOT NULL,
|
|
2352
|
+
events TEXT NOT NULL DEFAULT '[]',
|
|
2353
|
+
secret TEXT,
|
|
2354
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
2355
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
2356
|
+
);
|
|
2357
|
+
|
|
2358
|
+
CREATE TABLE IF NOT EXISTS rate_limits (
|
|
2359
|
+
key TEXT PRIMARY KEY,
|
|
2360
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
2361
|
+
window_start TEXT NOT NULL DEFAULT (datetime('now'))
|
|
2362
|
+
);
|
|
2363
|
+
|
|
2364
|
+
INSERT OR IGNORE INTO _migrations (id) VALUES (6);
|
|
2335
2365
|
`
|
|
2336
2366
|
];
|
|
2337
2367
|
});
|
|
@@ -2539,9 +2569,12 @@ function listTasks(filter = {}, db) {
|
|
|
2539
2569
|
params.push(filter.plan_id);
|
|
2540
2570
|
}
|
|
2541
2571
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
2572
|
+
const limitVal = filter.limit || 100;
|
|
2573
|
+
const offsetVal = filter.offset || 0;
|
|
2574
|
+
params.push(limitVal, offsetVal);
|
|
2542
2575
|
const rows = d.query(`SELECT * FROM tasks ${where} ORDER BY
|
|
2543
2576
|
CASE priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END,
|
|
2544
|
-
created_at DESC
|
|
2577
|
+
created_at DESC LIMIT ? OFFSET ?`).all(...params);
|
|
2545
2578
|
return rows.map(rowToTask);
|
|
2546
2579
|
}
|
|
2547
2580
|
function updateTask(id, input, db) {
|
|
@@ -8082,6 +8115,163 @@ var init_api_keys = __esm(() => {
|
|
|
8082
8115
|
init_database();
|
|
8083
8116
|
});
|
|
8084
8117
|
|
|
8118
|
+
// src/db/audit.ts
|
|
8119
|
+
function rowToEntry(row) {
|
|
8120
|
+
return {
|
|
8121
|
+
...row,
|
|
8122
|
+
changes: row.changes ? JSON.parse(row.changes) : null
|
|
8123
|
+
};
|
|
8124
|
+
}
|
|
8125
|
+
function logAudit(entityType, entityId, action, actor, changes, db) {
|
|
8126
|
+
const d = db || getDatabase();
|
|
8127
|
+
d.run(`INSERT INTO audit_log (id, entity_type, entity_id, action, actor, changes, created_at)
|
|
8128
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`, [uuid(), entityType, entityId, action, actor || null, changes ? JSON.stringify(changes) : null, now()]);
|
|
8129
|
+
}
|
|
8130
|
+
function getAuditLog(entityType, entityId, limit = 50, offset = 0, db) {
|
|
8131
|
+
const d = db || getDatabase();
|
|
8132
|
+
const conditions = [];
|
|
8133
|
+
const params = [];
|
|
8134
|
+
if (entityType) {
|
|
8135
|
+
conditions.push("entity_type = ?");
|
|
8136
|
+
params.push(entityType);
|
|
8137
|
+
}
|
|
8138
|
+
if (entityId) {
|
|
8139
|
+
conditions.push("entity_id = ?");
|
|
8140
|
+
params.push(entityId);
|
|
8141
|
+
}
|
|
8142
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
8143
|
+
params.push(limit, offset);
|
|
8144
|
+
const rows = d.query(`SELECT * FROM audit_log ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`).all(...params);
|
|
8145
|
+
return rows.map(rowToEntry);
|
|
8146
|
+
}
|
|
8147
|
+
var init_audit = __esm(() => {
|
|
8148
|
+
init_database();
|
|
8149
|
+
});
|
|
8150
|
+
|
|
8151
|
+
// src/db/webhooks.ts
|
|
8152
|
+
function rowToWebhook(row) {
|
|
8153
|
+
return {
|
|
8154
|
+
...row,
|
|
8155
|
+
events: JSON.parse(row.events),
|
|
8156
|
+
active: row.active === 1
|
|
8157
|
+
};
|
|
8158
|
+
}
|
|
8159
|
+
function createWebhook(input, db) {
|
|
8160
|
+
const d = db || getDatabase();
|
|
8161
|
+
const id = uuid();
|
|
8162
|
+
d.run(`INSERT INTO webhooks (id, url, events, secret, created_at)
|
|
8163
|
+
VALUES (?, ?, ?, ?, ?)`, [id, input.url, JSON.stringify(input.events || []), input.secret || null, now()]);
|
|
8164
|
+
return getWebhook(id, d);
|
|
8165
|
+
}
|
|
8166
|
+
function getWebhook(id, db) {
|
|
8167
|
+
const d = db || getDatabase();
|
|
8168
|
+
const row = d.query("SELECT * FROM webhooks WHERE id = ?").get(id);
|
|
8169
|
+
return row ? rowToWebhook(row) : null;
|
|
8170
|
+
}
|
|
8171
|
+
function listWebhooks(db) {
|
|
8172
|
+
const d = db || getDatabase();
|
|
8173
|
+
return d.query("SELECT * FROM webhooks ORDER BY created_at DESC").all().map(rowToWebhook);
|
|
8174
|
+
}
|
|
8175
|
+
function deleteWebhook(id, db) {
|
|
8176
|
+
const d = db || getDatabase();
|
|
8177
|
+
return d.run("DELETE FROM webhooks WHERE id = ?", [id]).changes > 0;
|
|
8178
|
+
}
|
|
8179
|
+
async function dispatchWebhooks(event, payload, db) {
|
|
8180
|
+
const d = db || getDatabase();
|
|
8181
|
+
const rows = d.query("SELECT * FROM webhooks WHERE active = 1").all();
|
|
8182
|
+
const webhooks = rows.map(rowToWebhook).filter((w) => w.events.length === 0 || w.events.includes(event));
|
|
8183
|
+
for (const webhook of webhooks) {
|
|
8184
|
+
try {
|
|
8185
|
+
const headers = { "Content-Type": "application/json" };
|
|
8186
|
+
if (webhook.secret) {
|
|
8187
|
+
const encoder = new TextEncoder;
|
|
8188
|
+
const key = await crypto.subtle.importKey("raw", encoder.encode(webhook.secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
8189
|
+
const body = JSON.stringify({ event, data: payload, timestamp: now() });
|
|
8190
|
+
const sig = await crypto.subtle.sign("HMAC", key, encoder.encode(body));
|
|
8191
|
+
headers["X-Webhook-Signature"] = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8192
|
+
fetch(webhook.url, {
|
|
8193
|
+
method: "POST",
|
|
8194
|
+
headers,
|
|
8195
|
+
body
|
|
8196
|
+
}).catch(() => {});
|
|
8197
|
+
} else {
|
|
8198
|
+
fetch(webhook.url, {
|
|
8199
|
+
method: "POST",
|
|
8200
|
+
headers,
|
|
8201
|
+
body: JSON.stringify({ event, data: payload, timestamp: now() })
|
|
8202
|
+
}).catch(() => {});
|
|
8203
|
+
}
|
|
8204
|
+
} catch {}
|
|
8205
|
+
}
|
|
8206
|
+
}
|
|
8207
|
+
var init_webhooks = __esm(() => {
|
|
8208
|
+
init_database();
|
|
8209
|
+
});
|
|
8210
|
+
|
|
8211
|
+
// src/lib/rate-limit.ts
|
|
8212
|
+
function cleanup() {
|
|
8213
|
+
const now2 = Date.now();
|
|
8214
|
+
if (now2 - lastCleanup < CLEANUP_INTERVAL)
|
|
8215
|
+
return;
|
|
8216
|
+
lastCleanup = now2;
|
|
8217
|
+
for (const [key, entry] of windows) {
|
|
8218
|
+
if (entry.resetAt < now2)
|
|
8219
|
+
windows.delete(key);
|
|
8220
|
+
}
|
|
8221
|
+
}
|
|
8222
|
+
function checkRateLimit(key, maxRequests, windowMs) {
|
|
8223
|
+
cleanup();
|
|
8224
|
+
const now2 = Date.now();
|
|
8225
|
+
const entry = windows.get(key);
|
|
8226
|
+
if (!entry || entry.resetAt < now2) {
|
|
8227
|
+
windows.set(key, { count: 1, resetAt: now2 + windowMs });
|
|
8228
|
+
return { allowed: true, remaining: maxRequests - 1, resetAt: now2 + windowMs };
|
|
8229
|
+
}
|
|
8230
|
+
entry.count++;
|
|
8231
|
+
if (entry.count > maxRequests) {
|
|
8232
|
+
return { allowed: false, remaining: 0, resetAt: entry.resetAt };
|
|
8233
|
+
}
|
|
8234
|
+
return { allowed: true, remaining: maxRequests - entry.count, resetAt: entry.resetAt };
|
|
8235
|
+
}
|
|
8236
|
+
var windows, CLEANUP_INTERVAL = 60000, lastCleanup;
|
|
8237
|
+
var init_rate_limit = __esm(() => {
|
|
8238
|
+
windows = new Map;
|
|
8239
|
+
lastCleanup = Date.now();
|
|
8240
|
+
});
|
|
8241
|
+
|
|
8242
|
+
// src/lib/env.ts
|
|
8243
|
+
import { existsSync as existsSync6, readFileSync as readFileSync2 } from "fs";
|
|
8244
|
+
import { join as join6 } from "path";
|
|
8245
|
+
function loadEnv() {
|
|
8246
|
+
const paths = [
|
|
8247
|
+
join6(process.cwd(), ".env"),
|
|
8248
|
+
join6(process.cwd(), ".env.local")
|
|
8249
|
+
];
|
|
8250
|
+
for (const path of paths) {
|
|
8251
|
+
if (!existsSync6(path))
|
|
8252
|
+
continue;
|
|
8253
|
+
const content = readFileSync2(path, "utf-8");
|
|
8254
|
+
for (const line of content.split(`
|
|
8255
|
+
`)) {
|
|
8256
|
+
const trimmed = line.trim();
|
|
8257
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
8258
|
+
continue;
|
|
8259
|
+
const eqIdx = trimmed.indexOf("=");
|
|
8260
|
+
if (eqIdx === -1)
|
|
8261
|
+
continue;
|
|
8262
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
8263
|
+
let value = trimmed.slice(eqIdx + 1).trim();
|
|
8264
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
8265
|
+
value = value.slice(1, -1);
|
|
8266
|
+
}
|
|
8267
|
+
if (!process.env[key]) {
|
|
8268
|
+
process.env[key] = value;
|
|
8269
|
+
}
|
|
8270
|
+
}
|
|
8271
|
+
}
|
|
8272
|
+
}
|
|
8273
|
+
var init_env = () => {};
|
|
8274
|
+
|
|
8085
8275
|
// src/server/serve.ts
|
|
8086
8276
|
var exports_serve = {};
|
|
8087
8277
|
__export(exports_serve, {
|
|
@@ -8089,27 +8279,27 @@ __export(exports_serve, {
|
|
|
8089
8279
|
createFetchHandler: () => createFetchHandler
|
|
8090
8280
|
});
|
|
8091
8281
|
import { execSync } from "child_process";
|
|
8092
|
-
import { existsSync as
|
|
8093
|
-
import { join as
|
|
8282
|
+
import { existsSync as existsSync7, readFileSync as readFileSync3 } from "fs";
|
|
8283
|
+
import { join as join7, dirname as dirname2, extname } from "path";
|
|
8094
8284
|
import { fileURLToPath } from "url";
|
|
8095
8285
|
function resolveDashboardDir() {
|
|
8096
8286
|
const candidates = [];
|
|
8097
8287
|
try {
|
|
8098
8288
|
const scriptDir = dirname2(fileURLToPath(import.meta.url));
|
|
8099
|
-
candidates.push(
|
|
8100
|
-
candidates.push(
|
|
8289
|
+
candidates.push(join7(scriptDir, "..", "dashboard", "dist"));
|
|
8290
|
+
candidates.push(join7(scriptDir, "..", "..", "dashboard", "dist"));
|
|
8101
8291
|
} catch {}
|
|
8102
8292
|
if (process.argv[1]) {
|
|
8103
8293
|
const mainDir = dirname2(process.argv[1]);
|
|
8104
|
-
candidates.push(
|
|
8105
|
-
candidates.push(
|
|
8294
|
+
candidates.push(join7(mainDir, "..", "dashboard", "dist"));
|
|
8295
|
+
candidates.push(join7(mainDir, "..", "..", "dashboard", "dist"));
|
|
8106
8296
|
}
|
|
8107
|
-
candidates.push(
|
|
8297
|
+
candidates.push(join7(process.cwd(), "dashboard", "dist"));
|
|
8108
8298
|
for (const candidate of candidates) {
|
|
8109
|
-
if (
|
|
8299
|
+
if (existsSync7(candidate))
|
|
8110
8300
|
return candidate;
|
|
8111
8301
|
}
|
|
8112
|
-
return
|
|
8302
|
+
return join7(process.cwd(), "dashboard", "dist");
|
|
8113
8303
|
}
|
|
8114
8304
|
function randomPort() {
|
|
8115
8305
|
return 20000 + Math.floor(Math.random() * 20000);
|
|
@@ -8126,8 +8316,8 @@ function json(data, status = 200, port) {
|
|
|
8126
8316
|
}
|
|
8127
8317
|
function getPackageVersion() {
|
|
8128
8318
|
try {
|
|
8129
|
-
const pkgPath =
|
|
8130
|
-
return JSON.parse(
|
|
8319
|
+
const pkgPath = join7(dirname2(fileURLToPath(import.meta.url)), "..", "..", "package.json");
|
|
8320
|
+
return JSON.parse(readFileSync3(pkgPath, "utf-8")).version || "0.0.0";
|
|
8131
8321
|
} catch {
|
|
8132
8322
|
return "0.0.0";
|
|
8133
8323
|
}
|
|
@@ -8140,7 +8330,7 @@ async function parseJsonBody(req) {
|
|
|
8140
8330
|
}
|
|
8141
8331
|
}
|
|
8142
8332
|
function serveStaticFile(filePath) {
|
|
8143
|
-
if (!
|
|
8333
|
+
if (!existsSync7(filePath))
|
|
8144
8334
|
return null;
|
|
8145
8335
|
const ext = extname(filePath);
|
|
8146
8336
|
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
@@ -8149,8 +8339,9 @@ function serveStaticFile(filePath) {
|
|
|
8149
8339
|
});
|
|
8150
8340
|
}
|
|
8151
8341
|
function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
8342
|
+
loadEnv();
|
|
8152
8343
|
const dir = dashboardDir || resolveDashboardDir();
|
|
8153
|
-
const hasDashboard = dashboardExists ??
|
|
8344
|
+
const hasDashboard = dashboardExists ?? existsSync7(dir);
|
|
8154
8345
|
return async (req) => {
|
|
8155
8346
|
const url = new URL(req.url);
|
|
8156
8347
|
let path = url.pathname;
|
|
@@ -8173,6 +8364,21 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8173
8364
|
}
|
|
8174
8365
|
}
|
|
8175
8366
|
}
|
|
8367
|
+
if (path.startsWith("/api/")) {
|
|
8368
|
+
const rateLimitKey = req.headers.get("authorization") || req.headers.get("x-forwarded-for") || "anonymous";
|
|
8369
|
+
const rateResult = checkRateLimit(rateLimitKey, 100, 60000);
|
|
8370
|
+
if (!rateResult.allowed) {
|
|
8371
|
+
return new Response(JSON.stringify({ error: "Rate limit exceeded. Try again later." }), {
|
|
8372
|
+
status: 429,
|
|
8373
|
+
headers: {
|
|
8374
|
+
"Content-Type": "application/json",
|
|
8375
|
+
"Retry-After": String(Math.ceil((rateResult.resetAt - Date.now()) / 1000)),
|
|
8376
|
+
"X-RateLimit-Remaining": "0",
|
|
8377
|
+
...SECURITY_HEADERS
|
|
8378
|
+
}
|
|
8379
|
+
});
|
|
8380
|
+
}
|
|
8381
|
+
}
|
|
8176
8382
|
if (path === "/api/tasks" && method === "GET") {
|
|
8177
8383
|
try {
|
|
8178
8384
|
const filter = {};
|
|
@@ -8188,6 +8394,12 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8188
8394
|
filter.project_id = projectId;
|
|
8189
8395
|
if (planId)
|
|
8190
8396
|
filter.plan_id = planId;
|
|
8397
|
+
const limit = parseInt(url.searchParams.get("limit") || "100", 10);
|
|
8398
|
+
const offset = parseInt(url.searchParams.get("offset") || "0", 10);
|
|
8399
|
+
if (limit)
|
|
8400
|
+
filter.limit = Math.min(limit, 500);
|
|
8401
|
+
if (offset)
|
|
8402
|
+
filter.offset = offset;
|
|
8191
8403
|
const tasks = listTasks(filter);
|
|
8192
8404
|
const projectCache = new Map;
|
|
8193
8405
|
const planCache = new Map;
|
|
@@ -8265,6 +8477,8 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8265
8477
|
agent_id: parsed.data.agent_id,
|
|
8266
8478
|
status: parsed.data.status
|
|
8267
8479
|
});
|
|
8480
|
+
logAudit("task", task.id, "create", parsed.data.agent_id);
|
|
8481
|
+
dispatchWebhooks("task.created", task);
|
|
8268
8482
|
return json(task, 201, port);
|
|
8269
8483
|
} catch (e) {
|
|
8270
8484
|
return json({ error: e instanceof Error ? e.message : "Failed to create task" }, 500, port);
|
|
@@ -8298,6 +8512,8 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8298
8512
|
tags: parsed.data.tags,
|
|
8299
8513
|
metadata: parsed.data.metadata
|
|
8300
8514
|
});
|
|
8515
|
+
logAudit("task", id, "update", undefined, parsed.data);
|
|
8516
|
+
dispatchWebhooks("task.updated", task);
|
|
8301
8517
|
return json(task, 200, port);
|
|
8302
8518
|
} catch (e) {
|
|
8303
8519
|
const status = e instanceof Error && e.name === "VersionConflictError" ? 409 : 500;
|
|
@@ -8311,6 +8527,8 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8311
8527
|
const deleted = deleteTask(id);
|
|
8312
8528
|
if (!deleted)
|
|
8313
8529
|
return json({ error: "Task not found" }, 404, port);
|
|
8530
|
+
logAudit("task", id, "delete");
|
|
8531
|
+
dispatchWebhooks("task.deleted", { id });
|
|
8314
8532
|
return json({ deleted: true }, 200, port);
|
|
8315
8533
|
} catch (e) {
|
|
8316
8534
|
return json({ error: e instanceof Error ? e.message : "Failed to delete task" }, 500, port);
|
|
@@ -8328,6 +8546,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8328
8546
|
return json({ error: "Invalid request body" }, 400, port);
|
|
8329
8547
|
const agentId = parsed.data.agent_id || "dashboard";
|
|
8330
8548
|
const task = startTask(id, agentId);
|
|
8549
|
+
logAudit("task", id, "start", agentId);
|
|
8331
8550
|
return json(task, 200, port);
|
|
8332
8551
|
} catch (e) {
|
|
8333
8552
|
const status = e instanceof Error && e.name === "TaskNotFoundError" ? 404 : e instanceof Error && e.name === "LockError" ? 409 : 500;
|
|
@@ -8346,6 +8565,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8346
8565
|
return json({ error: "Invalid request body" }, 400, port);
|
|
8347
8566
|
const agentId = parsed.data.agent_id;
|
|
8348
8567
|
const task = completeTask(id, agentId);
|
|
8568
|
+
logAudit("task", id, "complete", agentId);
|
|
8349
8569
|
return json(task, 200, port);
|
|
8350
8570
|
} catch (e) {
|
|
8351
8571
|
const status = e instanceof Error && e.name === "TaskNotFoundError" ? 404 : e instanceof Error && e.name === "LockError" ? 409 : 500;
|
|
@@ -8419,6 +8639,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8419
8639
|
description: parsed.data.description,
|
|
8420
8640
|
task_list_id: parsed.data.task_list_id
|
|
8421
8641
|
});
|
|
8642
|
+
logAudit("project", project.id, "create");
|
|
8422
8643
|
return json(project, 201, port);
|
|
8423
8644
|
} catch (e) {
|
|
8424
8645
|
return json({ error: e instanceof Error ? e.message : "Failed to create project" }, 500, port);
|
|
@@ -8500,6 +8721,8 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8500
8721
|
return json({ error: "Invalid request body" }, 400, port);
|
|
8501
8722
|
}
|
|
8502
8723
|
const plan = createPlan(parsed.data);
|
|
8724
|
+
logAudit("plan", plan.id, "create");
|
|
8725
|
+
dispatchWebhooks("plan.created", plan);
|
|
8503
8726
|
return json(plan, 201, port);
|
|
8504
8727
|
} catch (e) {
|
|
8505
8728
|
return json({ error: e instanceof Error ? e.message : "Failed to create plan" }, 500, port);
|
|
@@ -8532,6 +8755,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8532
8755
|
return json({ error: "Invalid request body" }, 400, port);
|
|
8533
8756
|
}
|
|
8534
8757
|
const plan = updatePlan(id, parsed.data);
|
|
8758
|
+
logAudit("plan", id, "update", undefined, parsed.data);
|
|
8535
8759
|
return json(plan, 200, port);
|
|
8536
8760
|
} catch (e) {
|
|
8537
8761
|
const status = e instanceof Error && e.name === "PlanNotFoundError" ? 404 : 500;
|
|
@@ -8545,6 +8769,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8545
8769
|
const deleted = deletePlan(id);
|
|
8546
8770
|
if (!deleted)
|
|
8547
8771
|
return json({ error: "Plan not found" }, 404, port);
|
|
8772
|
+
logAudit("plan", id, "delete");
|
|
8548
8773
|
return json({ deleted: true }, 200, port);
|
|
8549
8774
|
} catch (e) {
|
|
8550
8775
|
return json({ error: e instanceof Error ? e.message : "Failed to delete plan" }, 500, port);
|
|
@@ -8619,6 +8844,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8619
8844
|
return json({ error: "Invalid request body" }, 400, port);
|
|
8620
8845
|
}
|
|
8621
8846
|
const apiKey = await createApiKey(parsed.data);
|
|
8847
|
+
logAudit("api_key", apiKey.id, "create");
|
|
8622
8848
|
return json(apiKey, 201, port);
|
|
8623
8849
|
} catch (e) {
|
|
8624
8850
|
return json({ error: e instanceof Error ? e.message : "Failed to create API key" }, 500, port);
|
|
@@ -8644,6 +8870,56 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8644
8870
|
return json({ error: e instanceof Error ? e.message : "Failed to check auth status" }, 500, port);
|
|
8645
8871
|
}
|
|
8646
8872
|
}
|
|
8873
|
+
if (path === "/api/audit" && method === "GET") {
|
|
8874
|
+
try {
|
|
8875
|
+
const entityType = url.searchParams.get("entity_type") || undefined;
|
|
8876
|
+
const entityId = url.searchParams.get("entity_id") || undefined;
|
|
8877
|
+
const limit = parseInt(url.searchParams.get("limit") || "50", 10);
|
|
8878
|
+
const offset = parseInt(url.searchParams.get("offset") || "0", 10);
|
|
8879
|
+
const entries = getAuditLog(entityType, entityId, Math.min(limit, 200), offset);
|
|
8880
|
+
return json(entries, 200, port);
|
|
8881
|
+
} catch (e) {
|
|
8882
|
+
return json({ error: e instanceof Error ? e.message : "Failed to get audit log" }, 500, port);
|
|
8883
|
+
}
|
|
8884
|
+
}
|
|
8885
|
+
if (path === "/api/webhooks" && method === "GET") {
|
|
8886
|
+
try {
|
|
8887
|
+
const webhooks = listWebhooks();
|
|
8888
|
+
return json(webhooks, 200, port);
|
|
8889
|
+
} catch (e) {
|
|
8890
|
+
return json({ error: e instanceof Error ? e.message : "Failed to list webhooks" }, 500, port);
|
|
8891
|
+
}
|
|
8892
|
+
}
|
|
8893
|
+
if (path === "/api/webhooks" && method === "POST") {
|
|
8894
|
+
try {
|
|
8895
|
+
const body = await parseJsonBody(req);
|
|
8896
|
+
if (!body)
|
|
8897
|
+
return json({ error: "Invalid JSON" }, 400, port);
|
|
8898
|
+
if (!body.url || typeof body.url !== "string") {
|
|
8899
|
+
return json({ error: "Missing required field: url" }, 400, port);
|
|
8900
|
+
}
|
|
8901
|
+
const webhook = createWebhook({
|
|
8902
|
+
url: body.url,
|
|
8903
|
+
events: Array.isArray(body.events) ? body.events : undefined,
|
|
8904
|
+
secret: typeof body.secret === "string" ? body.secret : undefined
|
|
8905
|
+
});
|
|
8906
|
+
return json(webhook, 201, port);
|
|
8907
|
+
} catch (e) {
|
|
8908
|
+
return json({ error: e instanceof Error ? e.message : "Failed to create webhook" }, 500, port);
|
|
8909
|
+
}
|
|
8910
|
+
}
|
|
8911
|
+
const webhookDeleteMatch = path.match(/^\/api\/webhooks\/([^/]+)$/);
|
|
8912
|
+
if (webhookDeleteMatch && method === "DELETE") {
|
|
8913
|
+
try {
|
|
8914
|
+
const id = webhookDeleteMatch[1];
|
|
8915
|
+
const deleted = deleteWebhook(id);
|
|
8916
|
+
if (!deleted)
|
|
8917
|
+
return json({ error: "Webhook not found" }, 404, port);
|
|
8918
|
+
return json({ deleted: true }, 200, port);
|
|
8919
|
+
} catch (e) {
|
|
8920
|
+
return json({ error: e instanceof Error ? e.message : "Failed to delete webhook" }, 500, port);
|
|
8921
|
+
}
|
|
8922
|
+
}
|
|
8647
8923
|
if (method === "OPTIONS") {
|
|
8648
8924
|
return new Response(null, {
|
|
8649
8925
|
headers: {
|
|
@@ -8655,12 +8931,12 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8655
8931
|
}
|
|
8656
8932
|
if (hasDashboard && (method === "GET" || method === "HEAD")) {
|
|
8657
8933
|
if (path !== "/") {
|
|
8658
|
-
const filePath =
|
|
8934
|
+
const filePath = join7(dir, path);
|
|
8659
8935
|
const res2 = serveStaticFile(filePath);
|
|
8660
8936
|
if (res2)
|
|
8661
8937
|
return res2;
|
|
8662
8938
|
}
|
|
8663
|
-
const indexPath =
|
|
8939
|
+
const indexPath = join7(dir, "index.html");
|
|
8664
8940
|
const res = serveStaticFile(indexPath);
|
|
8665
8941
|
if (res)
|
|
8666
8942
|
return res;
|
|
@@ -8671,7 +8947,7 @@ function createFetchHandler(getPort, dashboardDir, dashboardExists) {
|
|
|
8671
8947
|
async function startServer(port, options) {
|
|
8672
8948
|
const shouldOpen = options?.open ?? true;
|
|
8673
8949
|
const dashboardDir = resolveDashboardDir();
|
|
8674
|
-
const dashboardExists =
|
|
8950
|
+
const dashboardExists = existsSync7(dashboardDir);
|
|
8675
8951
|
if (!dashboardExists) {
|
|
8676
8952
|
console.error(`
|
|
8677
8953
|
Dashboard not found at: ${dashboardDir}`);
|
|
@@ -8735,6 +9011,10 @@ var init_serve = __esm(() => {
|
|
|
8735
9011
|
init_comments();
|
|
8736
9012
|
init_api_keys();
|
|
8737
9013
|
init_search();
|
|
9014
|
+
init_audit();
|
|
9015
|
+
init_webhooks();
|
|
9016
|
+
init_rate_limit();
|
|
9017
|
+
init_env();
|
|
8738
9018
|
MIME_TYPES = {
|
|
8739
9019
|
".html": "text/html; charset=utf-8",
|
|
8740
9020
|
".js": "application/javascript",
|
|
@@ -9890,13 +10170,13 @@ init_sync();
|
|
|
9890
10170
|
init_config();
|
|
9891
10171
|
import chalk from "chalk";
|
|
9892
10172
|
import { execSync as execSync2 } from "child_process";
|
|
9893
|
-
import { existsSync as
|
|
9894
|
-
import { basename, dirname as dirname3, join as
|
|
10173
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
10174
|
+
import { basename, dirname as dirname3, join as join8, resolve as resolve2 } from "path";
|
|
9895
10175
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
9896
10176
|
function getPackageVersion2() {
|
|
9897
10177
|
try {
|
|
9898
|
-
const pkgPath =
|
|
9899
|
-
return JSON.parse(
|
|
10178
|
+
const pkgPath = join8(dirname3(fileURLToPath2(import.meta.url)), "..", "..", "package.json");
|
|
10179
|
+
return JSON.parse(readFileSync4(pkgPath, "utf-8")).version || "0.0.0";
|
|
9900
10180
|
} catch {
|
|
9901
10181
|
return "0.0.0";
|
|
9902
10182
|
}
|
|
@@ -10512,8 +10792,8 @@ hooks.command("install").description("Install Claude Code hooks for auto-sync").
|
|
|
10512
10792
|
if (p)
|
|
10513
10793
|
todosBin = p;
|
|
10514
10794
|
} catch {}
|
|
10515
|
-
const hooksDir =
|
|
10516
|
-
if (!
|
|
10795
|
+
const hooksDir = join8(process.cwd(), ".claude", "hooks");
|
|
10796
|
+
if (!existsSync8(hooksDir))
|
|
10517
10797
|
mkdirSync3(hooksDir, { recursive: true });
|
|
10518
10798
|
const hookScript = `#!/usr/bin/env bash
|
|
10519
10799
|
# Auto-generated by: todos hooks install
|
|
@@ -10538,11 +10818,11 @@ esac
|
|
|
10538
10818
|
|
|
10539
10819
|
exit 0
|
|
10540
10820
|
`;
|
|
10541
|
-
const hookPath =
|
|
10821
|
+
const hookPath = join8(hooksDir, "todos-sync.sh");
|
|
10542
10822
|
writeFileSync2(hookPath, hookScript);
|
|
10543
10823
|
execSync2(`chmod +x "${hookPath}"`);
|
|
10544
10824
|
console.log(chalk.green(`Hook script created: ${hookPath}`));
|
|
10545
|
-
const settingsPath =
|
|
10825
|
+
const settingsPath = join8(process.cwd(), ".claude", "settings.json");
|
|
10546
10826
|
const settings = readJsonFile2(settingsPath);
|
|
10547
10827
|
if (!settings["hooks"]) {
|
|
10548
10828
|
settings["hooks"] = {};
|
|
@@ -10589,40 +10869,40 @@ function getMcpBinaryPath() {
|
|
|
10589
10869
|
if (p)
|
|
10590
10870
|
return p;
|
|
10591
10871
|
} catch {}
|
|
10592
|
-
const bunBin =
|
|
10593
|
-
if (
|
|
10872
|
+
const bunBin = join8(HOME2, ".bun", "bin", "todos-mcp");
|
|
10873
|
+
if (existsSync8(bunBin))
|
|
10594
10874
|
return bunBin;
|
|
10595
10875
|
return "todos-mcp";
|
|
10596
10876
|
}
|
|
10597
10877
|
function readJsonFile2(path) {
|
|
10598
|
-
if (!
|
|
10878
|
+
if (!existsSync8(path))
|
|
10599
10879
|
return {};
|
|
10600
10880
|
try {
|
|
10601
|
-
return JSON.parse(
|
|
10881
|
+
return JSON.parse(readFileSync4(path, "utf-8"));
|
|
10602
10882
|
} catch {
|
|
10603
10883
|
return {};
|
|
10604
10884
|
}
|
|
10605
10885
|
}
|
|
10606
10886
|
function writeJsonFile2(path, data) {
|
|
10607
10887
|
const dir = dirname3(path);
|
|
10608
|
-
if (!
|
|
10888
|
+
if (!existsSync8(dir))
|
|
10609
10889
|
mkdirSync3(dir, { recursive: true });
|
|
10610
10890
|
writeFileSync2(path, JSON.stringify(data, null, 2) + `
|
|
10611
10891
|
`);
|
|
10612
10892
|
}
|
|
10613
10893
|
function readTomlFile(path) {
|
|
10614
|
-
if (!
|
|
10894
|
+
if (!existsSync8(path))
|
|
10615
10895
|
return "";
|
|
10616
|
-
return
|
|
10896
|
+
return readFileSync4(path, "utf-8");
|
|
10617
10897
|
}
|
|
10618
10898
|
function writeTomlFile(path, content) {
|
|
10619
10899
|
const dir = dirname3(path);
|
|
10620
|
-
if (!
|
|
10900
|
+
if (!existsSync8(dir))
|
|
10621
10901
|
mkdirSync3(dir, { recursive: true });
|
|
10622
10902
|
writeFileSync2(path, content);
|
|
10623
10903
|
}
|
|
10624
10904
|
function registerClaude(binPath, global) {
|
|
10625
|
-
const configPath = global ?
|
|
10905
|
+
const configPath = global ? join8(HOME2, ".claude", ".mcp.json") : join8(process.cwd(), ".mcp.json");
|
|
10626
10906
|
const config = readJsonFile2(configPath);
|
|
10627
10907
|
if (!config["mcpServers"]) {
|
|
10628
10908
|
config["mcpServers"] = {};
|
|
@@ -10637,7 +10917,7 @@ function registerClaude(binPath, global) {
|
|
|
10637
10917
|
console.log(chalk.green(`Claude Code (${scope}): registered in ${configPath}`));
|
|
10638
10918
|
}
|
|
10639
10919
|
function unregisterClaude(global) {
|
|
10640
|
-
const configPath = global ?
|
|
10920
|
+
const configPath = global ? join8(HOME2, ".claude", ".mcp.json") : join8(process.cwd(), ".mcp.json");
|
|
10641
10921
|
const config = readJsonFile2(configPath);
|
|
10642
10922
|
const servers = config["mcpServers"];
|
|
10643
10923
|
if (!servers || !("todos" in servers)) {
|
|
@@ -10650,7 +10930,7 @@ function unregisterClaude(global) {
|
|
|
10650
10930
|
console.log(chalk.green(`Claude Code (${scope}): unregistered from ${configPath}`));
|
|
10651
10931
|
}
|
|
10652
10932
|
function registerCodex(binPath) {
|
|
10653
|
-
const configPath =
|
|
10933
|
+
const configPath = join8(HOME2, ".codex", "config.toml");
|
|
10654
10934
|
let content = readTomlFile(configPath);
|
|
10655
10935
|
content = removeTomlBlock(content, "mcp_servers.todos");
|
|
10656
10936
|
const block = `
|
|
@@ -10664,7 +10944,7 @@ args = []
|
|
|
10664
10944
|
console.log(chalk.green(`Codex CLI: registered in ${configPath}`));
|
|
10665
10945
|
}
|
|
10666
10946
|
function unregisterCodex() {
|
|
10667
|
-
const configPath =
|
|
10947
|
+
const configPath = join8(HOME2, ".codex", "config.toml");
|
|
10668
10948
|
let content = readTomlFile(configPath);
|
|
10669
10949
|
if (!content.includes("[mcp_servers.todos]")) {
|
|
10670
10950
|
console.log(chalk.dim(`Codex CLI: todos not found in ${configPath}`));
|
|
@@ -10697,7 +10977,7 @@ function removeTomlBlock(content, blockName) {
|
|
|
10697
10977
|
`);
|
|
10698
10978
|
}
|
|
10699
10979
|
function registerGemini(binPath) {
|
|
10700
|
-
const configPath =
|
|
10980
|
+
const configPath = join8(HOME2, ".gemini", "settings.json");
|
|
10701
10981
|
const config = readJsonFile2(configPath);
|
|
10702
10982
|
if (!config["mcpServers"]) {
|
|
10703
10983
|
config["mcpServers"] = {};
|
|
@@ -10711,7 +10991,7 @@ function registerGemini(binPath) {
|
|
|
10711
10991
|
console.log(chalk.green(`Gemini CLI: registered in ${configPath}`));
|
|
10712
10992
|
}
|
|
10713
10993
|
function unregisterGemini() {
|
|
10714
|
-
const configPath =
|
|
10994
|
+
const configPath = join8(HOME2, ".gemini", "settings.json");
|
|
10715
10995
|
const config = readJsonFile2(configPath);
|
|
10716
10996
|
const servers = config["mcpServers"];
|
|
10717
10997
|
if (!servers || !("todos" in servers)) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -177,6 +177,36 @@ var MIGRATIONS = [
|
|
|
177
177
|
);
|
|
178
178
|
CREATE INDEX IF NOT EXISTS idx_api_keys_hash ON api_keys(key_hash);
|
|
179
179
|
INSERT OR IGNORE INTO _migrations (id) VALUES (5);
|
|
180
|
+
`,
|
|
181
|
+
`
|
|
182
|
+
CREATE TABLE IF NOT EXISTS audit_log (
|
|
183
|
+
id TEXT PRIMARY KEY,
|
|
184
|
+
entity_type TEXT NOT NULL CHECK(entity_type IN ('task', 'plan', 'project', 'api_key', 'comment')),
|
|
185
|
+
entity_id TEXT NOT NULL,
|
|
186
|
+
action TEXT NOT NULL CHECK(action IN ('create', 'update', 'delete', 'start', 'complete', 'lock', 'unlock')),
|
|
187
|
+
actor TEXT,
|
|
188
|
+
changes TEXT,
|
|
189
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
190
|
+
);
|
|
191
|
+
CREATE INDEX IF NOT EXISTS idx_audit_entity ON audit_log(entity_type, entity_id);
|
|
192
|
+
CREATE INDEX IF NOT EXISTS idx_audit_created ON audit_log(created_at);
|
|
193
|
+
|
|
194
|
+
CREATE TABLE IF NOT EXISTS webhooks (
|
|
195
|
+
id TEXT PRIMARY KEY,
|
|
196
|
+
url TEXT NOT NULL,
|
|
197
|
+
events TEXT NOT NULL DEFAULT '[]',
|
|
198
|
+
secret TEXT,
|
|
199
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
200
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
CREATE TABLE IF NOT EXISTS rate_limits (
|
|
204
|
+
key TEXT PRIMARY KEY,
|
|
205
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
206
|
+
window_start TEXT NOT NULL DEFAULT (datetime('now'))
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
INSERT OR IGNORE INTO _migrations (id) VALUES (6);
|
|
180
210
|
`
|
|
181
211
|
];
|
|
182
212
|
var _db = null;
|
|
@@ -499,9 +529,12 @@ function listTasks(filter = {}, db) {
|
|
|
499
529
|
params.push(filter.plan_id);
|
|
500
530
|
}
|
|
501
531
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
532
|
+
const limitVal = filter.limit || 100;
|
|
533
|
+
const offsetVal = filter.offset || 0;
|
|
534
|
+
params.push(limitVal, offsetVal);
|
|
502
535
|
const rows = d.query(`SELECT * FROM tasks ${where} ORDER BY
|
|
503
536
|
CASE priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END,
|
|
504
|
-
created_at DESC
|
|
537
|
+
created_at DESC LIMIT ? OFFSET ?`).all(...params);
|
|
505
538
|
return rows.map(rowToTask);
|
|
506
539
|
}
|
|
507
540
|
function updateTask(id, input, db) {
|
|
@@ -1530,6 +1563,91 @@ function syncWithAgents(agents, taskListIdByAgent, projectId, direction = "both"
|
|
|
1530
1563
|
}
|
|
1531
1564
|
return { pushed, pulled, errors };
|
|
1532
1565
|
}
|
|
1566
|
+
// src/db/audit.ts
|
|
1567
|
+
function rowToEntry(row) {
|
|
1568
|
+
return {
|
|
1569
|
+
...row,
|
|
1570
|
+
changes: row.changes ? JSON.parse(row.changes) : null
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
function logAudit(entityType, entityId, action, actor, changes, db) {
|
|
1574
|
+
const d = db || getDatabase();
|
|
1575
|
+
d.run(`INSERT INTO audit_log (id, entity_type, entity_id, action, actor, changes, created_at)
|
|
1576
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`, [uuid(), entityType, entityId, action, actor || null, changes ? JSON.stringify(changes) : null, now()]);
|
|
1577
|
+
}
|
|
1578
|
+
function getAuditLog(entityType, entityId, limit = 50, offset = 0, db) {
|
|
1579
|
+
const d = db || getDatabase();
|
|
1580
|
+
const conditions = [];
|
|
1581
|
+
const params = [];
|
|
1582
|
+
if (entityType) {
|
|
1583
|
+
conditions.push("entity_type = ?");
|
|
1584
|
+
params.push(entityType);
|
|
1585
|
+
}
|
|
1586
|
+
if (entityId) {
|
|
1587
|
+
conditions.push("entity_id = ?");
|
|
1588
|
+
params.push(entityId);
|
|
1589
|
+
}
|
|
1590
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1591
|
+
params.push(limit, offset);
|
|
1592
|
+
const rows = d.query(`SELECT * FROM audit_log ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`).all(...params);
|
|
1593
|
+
return rows.map(rowToEntry);
|
|
1594
|
+
}
|
|
1595
|
+
// src/db/webhooks.ts
|
|
1596
|
+
function rowToWebhook(row) {
|
|
1597
|
+
return {
|
|
1598
|
+
...row,
|
|
1599
|
+
events: JSON.parse(row.events),
|
|
1600
|
+
active: row.active === 1
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
function createWebhook(input, db) {
|
|
1604
|
+
const d = db || getDatabase();
|
|
1605
|
+
const id = uuid();
|
|
1606
|
+
d.run(`INSERT INTO webhooks (id, url, events, secret, created_at)
|
|
1607
|
+
VALUES (?, ?, ?, ?, ?)`, [id, input.url, JSON.stringify(input.events || []), input.secret || null, now()]);
|
|
1608
|
+
return getWebhook(id, d);
|
|
1609
|
+
}
|
|
1610
|
+
function getWebhook(id, db) {
|
|
1611
|
+
const d = db || getDatabase();
|
|
1612
|
+
const row = d.query("SELECT * FROM webhooks WHERE id = ?").get(id);
|
|
1613
|
+
return row ? rowToWebhook(row) : null;
|
|
1614
|
+
}
|
|
1615
|
+
function listWebhooks(db) {
|
|
1616
|
+
const d = db || getDatabase();
|
|
1617
|
+
return d.query("SELECT * FROM webhooks ORDER BY created_at DESC").all().map(rowToWebhook);
|
|
1618
|
+
}
|
|
1619
|
+
function deleteWebhook(id, db) {
|
|
1620
|
+
const d = db || getDatabase();
|
|
1621
|
+
return d.run("DELETE FROM webhooks WHERE id = ?", [id]).changes > 0;
|
|
1622
|
+
}
|
|
1623
|
+
async function dispatchWebhooks(event, payload, db) {
|
|
1624
|
+
const d = db || getDatabase();
|
|
1625
|
+
const rows = d.query("SELECT * FROM webhooks WHERE active = 1").all();
|
|
1626
|
+
const webhooks = rows.map(rowToWebhook).filter((w) => w.events.length === 0 || w.events.includes(event));
|
|
1627
|
+
for (const webhook of webhooks) {
|
|
1628
|
+
try {
|
|
1629
|
+
const headers = { "Content-Type": "application/json" };
|
|
1630
|
+
if (webhook.secret) {
|
|
1631
|
+
const encoder = new TextEncoder;
|
|
1632
|
+
const key = await crypto.subtle.importKey("raw", encoder.encode(webhook.secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
1633
|
+
const body = JSON.stringify({ event, data: payload, timestamp: now() });
|
|
1634
|
+
const sig = await crypto.subtle.sign("HMAC", key, encoder.encode(body));
|
|
1635
|
+
headers["X-Webhook-Signature"] = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1636
|
+
fetch(webhook.url, {
|
|
1637
|
+
method: "POST",
|
|
1638
|
+
headers,
|
|
1639
|
+
body
|
|
1640
|
+
}).catch(() => {});
|
|
1641
|
+
} else {
|
|
1642
|
+
fetch(webhook.url, {
|
|
1643
|
+
method: "POST",
|
|
1644
|
+
headers,
|
|
1645
|
+
body: JSON.stringify({ event, data: payload, timestamp: now() })
|
|
1646
|
+
}).catch(() => {});
|
|
1647
|
+
}
|
|
1648
|
+
} catch {}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1533
1651
|
export {
|
|
1534
1652
|
validateApiKey,
|
|
1535
1653
|
updateTask,
|
|
@@ -1545,8 +1663,10 @@ export {
|
|
|
1545
1663
|
resolvePartialId,
|
|
1546
1664
|
resetDatabase,
|
|
1547
1665
|
removeDependency,
|
|
1666
|
+
logAudit,
|
|
1548
1667
|
lockTask,
|
|
1549
1668
|
loadConfig,
|
|
1669
|
+
listWebhooks,
|
|
1550
1670
|
listTasks,
|
|
1551
1671
|
listSessions,
|
|
1552
1672
|
listProjects,
|
|
@@ -1554,6 +1674,7 @@ export {
|
|
|
1554
1674
|
listComments,
|
|
1555
1675
|
listApiKeys,
|
|
1556
1676
|
hasAnyApiKeys,
|
|
1677
|
+
getWebhook,
|
|
1557
1678
|
getTaskWithRelations,
|
|
1558
1679
|
getTaskDependents,
|
|
1559
1680
|
getTaskDependencies,
|
|
@@ -1564,7 +1685,10 @@ export {
|
|
|
1564
1685
|
getPlan,
|
|
1565
1686
|
getDatabase,
|
|
1566
1687
|
getComment,
|
|
1688
|
+
getAuditLog,
|
|
1567
1689
|
ensureProject,
|
|
1690
|
+
dispatchWebhooks,
|
|
1691
|
+
deleteWebhook,
|
|
1568
1692
|
deleteTask,
|
|
1569
1693
|
deleteSession,
|
|
1570
1694
|
deleteProject,
|
|
@@ -1572,6 +1696,7 @@ export {
|
|
|
1572
1696
|
deleteComment,
|
|
1573
1697
|
deleteApiKey,
|
|
1574
1698
|
defaultSyncAgents,
|
|
1699
|
+
createWebhook,
|
|
1575
1700
|
createTask,
|
|
1576
1701
|
createSession,
|
|
1577
1702
|
createProject,
|
package/dist/mcp/index.js
CHANGED
|
@@ -4219,6 +4219,36 @@ var MIGRATIONS = [
|
|
|
4219
4219
|
);
|
|
4220
4220
|
CREATE INDEX IF NOT EXISTS idx_api_keys_hash ON api_keys(key_hash);
|
|
4221
4221
|
INSERT OR IGNORE INTO _migrations (id) VALUES (5);
|
|
4222
|
+
`,
|
|
4223
|
+
`
|
|
4224
|
+
CREATE TABLE IF NOT EXISTS audit_log (
|
|
4225
|
+
id TEXT PRIMARY KEY,
|
|
4226
|
+
entity_type TEXT NOT NULL CHECK(entity_type IN ('task', 'plan', 'project', 'api_key', 'comment')),
|
|
4227
|
+
entity_id TEXT NOT NULL,
|
|
4228
|
+
action TEXT NOT NULL CHECK(action IN ('create', 'update', 'delete', 'start', 'complete', 'lock', 'unlock')),
|
|
4229
|
+
actor TEXT,
|
|
4230
|
+
changes TEXT,
|
|
4231
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
4232
|
+
);
|
|
4233
|
+
CREATE INDEX IF NOT EXISTS idx_audit_entity ON audit_log(entity_type, entity_id);
|
|
4234
|
+
CREATE INDEX IF NOT EXISTS idx_audit_created ON audit_log(created_at);
|
|
4235
|
+
|
|
4236
|
+
CREATE TABLE IF NOT EXISTS webhooks (
|
|
4237
|
+
id TEXT PRIMARY KEY,
|
|
4238
|
+
url TEXT NOT NULL,
|
|
4239
|
+
events TEXT NOT NULL DEFAULT '[]',
|
|
4240
|
+
secret TEXT,
|
|
4241
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
4242
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
4243
|
+
);
|
|
4244
|
+
|
|
4245
|
+
CREATE TABLE IF NOT EXISTS rate_limits (
|
|
4246
|
+
key TEXT PRIMARY KEY,
|
|
4247
|
+
count INTEGER NOT NULL DEFAULT 0,
|
|
4248
|
+
window_start TEXT NOT NULL DEFAULT (datetime('now'))
|
|
4249
|
+
);
|
|
4250
|
+
|
|
4251
|
+
INSERT OR IGNORE INTO _migrations (id) VALUES (6);
|
|
4222
4252
|
`
|
|
4223
4253
|
];
|
|
4224
4254
|
var _db = null;
|
|
@@ -4455,9 +4485,12 @@ function listTasks(filter = {}, db) {
|
|
|
4455
4485
|
params.push(filter.plan_id);
|
|
4456
4486
|
}
|
|
4457
4487
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
4488
|
+
const limitVal = filter.limit || 100;
|
|
4489
|
+
const offsetVal = filter.offset || 0;
|
|
4490
|
+
params.push(limitVal, offsetVal);
|
|
4458
4491
|
const rows = d.query(`SELECT * FROM tasks ${where} ORDER BY
|
|
4459
4492
|
CASE priority WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 END,
|
|
4460
|
-
created_at DESC
|
|
4493
|
+
created_at DESC LIMIT ? OFFSET ?`).all(...params);
|
|
4461
4494
|
return rows.map(rowToTask);
|
|
4462
4495
|
}
|
|
4463
4496
|
function updateTask(id, input, db) {
|