@hasna/logs 0.3.12 → 0.3.14

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.
@@ -6,10 +6,10 @@ import {
6
6
  setPageAuth,
7
7
  setRetentionPolicy,
8
8
  startScheduler
9
- } from "../index-2sbhn1ye.js";
9
+ } from "../index-5qwba140.js";
10
10
  import {
11
11
  getHealth
12
- } from "../index-xjn8gam3.js";
12
+ } from "../index-cpvq9np9.js";
13
13
  import {
14
14
  createAlertRule,
15
15
  createPage,
@@ -31,7 +31,7 @@ import {
31
31
  updateAlertRule,
32
32
  updateIssueStatus,
33
33
  updateProject
34
- } from "../index-t97ttm0a.js";
34
+ } from "../index-6zrkek5y.js";
35
35
  import {
36
36
  createJob,
37
37
  deleteJob,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/logs",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "description": "Log aggregation + browser script + headless page scanner + performance monitoring for AI agents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/hasna/logs.git"
25
25
  },
26
26
  "publishConfig": {
27
- "access": "restricted",
28
- "registry": "https://registry.npmjs.org/"
27
+ "registry": "https://registry.npmjs.org",
28
+ "access": "public"
29
29
  },
30
30
  "keywords": [
31
31
  "logs",
@@ -37,8 +37,9 @@
37
37
  "lighthouse"
38
38
  ],
39
39
  "author": "Andrei Hasna <andrei@hasna.com>",
40
- "license": "MIT",
40
+ "license": "Apache-2.0",
41
41
  "dependencies": {
42
+ "@hasna/cloud": "^0.1.0",
42
43
  "@modelcontextprotocol/sdk": "^1.12.1",
43
44
  "commander": "^14.0.0",
44
45
  "hono": "^4.7.11",
package/src/db/index.ts CHANGED
@@ -1,13 +1,30 @@
1
- import { Database } from "bun:sqlite"
1
+ import { SqliteAdapter as Database } from "@hasna/cloud"
2
2
  import { join } from "node:path"
3
- import { existsSync, mkdirSync } from "node:fs"
3
+ import { existsSync, mkdirSync, cpSync } from "node:fs"
4
4
  import { migrateAlertRules } from "./migrations/001_alert_rules.ts"
5
5
  import { migrateIssues } from "./migrations/002_issues.ts"
6
6
  import { migrateRetention } from "./migrations/003_retention.ts"
7
7
  import { migratePageAuth } from "./migrations/004_page_auth.ts"
8
8
 
9
- const DATA_DIR = process.env.LOGS_DATA_DIR ?? join(process.env.HOME ?? "~", ".logs")
10
- const DB_PATH = process.env.LOGS_DB_PATH ?? join(DATA_DIR, "logs.db")
9
+ function resolveDataDir(): string {
10
+ const explicit = process.env.HASNA_LOGS_DATA_DIR ?? process.env.LOGS_DATA_DIR
11
+ if (explicit) return explicit
12
+
13
+ const home = process.env.HOME ?? "~"
14
+ const newDir = join(home, ".hasna", "logs")
15
+ const oldDir = join(home, ".logs")
16
+
17
+ // Auto-migrate: copy old data to new location if needed
18
+ if (!existsSync(newDir) && existsSync(oldDir)) {
19
+ mkdirSync(join(home, ".hasna"), { recursive: true })
20
+ cpSync(oldDir, newDir, { recursive: true })
21
+ }
22
+
23
+ return newDir
24
+ }
25
+
26
+ const DATA_DIR = resolveDataDir()
27
+ const DB_PATH = process.env.HASNA_LOGS_DB_PATH ?? process.env.LOGS_DB_PATH ?? join(DATA_DIR, "logs.db")
11
28
 
12
29
  let _db: Database | null = null
13
30
 
@@ -18,6 +35,15 @@ export function getDb(): Database {
18
35
  _db.run("PRAGMA journal_mode=WAL")
19
36
  _db.run("PRAGMA foreign_keys=ON")
20
37
  migrate(_db)
38
+ _db.run(`CREATE TABLE IF NOT EXISTS feedback (
39
+ id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
40
+ message TEXT NOT NULL,
41
+ email TEXT,
42
+ category TEXT DEFAULT 'general',
43
+ version TEXT,
44
+ machine_id TEXT,
45
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
46
+ )`)
21
47
  return _db
22
48
  }
23
49
 
package/src/lib/health.ts CHANGED
@@ -29,7 +29,7 @@ export function getHealth(db: Database): HealthResult {
29
29
 
30
30
  let db_size_bytes: number | null = null
31
31
  try {
32
- const dbPath = process.env.LOGS_DB_PATH
32
+ const dbPath = process.env.HASNA_LOGS_DB_PATH ?? process.env.LOGS_DB_PATH
33
33
  if (dbPath) {
34
34
  const { statSync } = require("node:fs")
35
35
  db_size_bytes = statSync(dbPath).size
@@ -0,0 +1,25 @@
1
+ import { test, expect } from "bun:test"
2
+ import { fileURLToPath } from "url"
3
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js"
4
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
5
+
6
+ test("logs MCP lists tools over stdio", async () => {
7
+ const entry = fileURLToPath(new URL("./index.ts", import.meta.url))
8
+ const transport = new StdioClientTransport({
9
+ command: "bun",
10
+ args: ["run", entry],
11
+ })
12
+ const client = new Client({ name: "logs-mcp-test", version: "0.0.0" }, { capabilities: {} })
13
+
14
+ try {
15
+ await client.connect(transport)
16
+ const result = await client.listTools()
17
+ const toolNames = result.tools.map((tool) => tool.name)
18
+
19
+ expect(toolNames.length).toBeGreaterThan(0)
20
+ expect(toolNames).toContain("get_health")
21
+ expect(toolNames).toContain("log_search")
22
+ } finally {
23
+ await client.close().catch(() => {})
24
+ }
25
+ })
package/src/mcp/index.ts CHANGED
@@ -75,53 +75,62 @@ const TOOLS: Record<string, { desc: string; params: string }> = {
75
75
  describe_tools: { desc: "List all tools with descriptions and param signatures", params: "()" },
76
76
  }
77
77
 
78
- server.tool("search_tools", { query: z.string() }, ({ query }) => {
78
+ // Fellow agents: keep MCP registrations behind this helper so descriptions and schemas stay aligned with the current SDK.
79
+ function registerTool(
80
+ name: keyof typeof TOOLS,
81
+ schema: Record<string, z.ZodTypeAny>,
82
+ handler: (...args: any[]) => any,
83
+ ) {
84
+ return server.tool(name, TOOLS[name].desc, schema, handler)
85
+ }
86
+
87
+ registerTool("search_tools", { query: z.string() }, ({ query }) => {
79
88
  const q = query.toLowerCase()
80
89
  const matches = Object.entries(TOOLS).filter(([k, v]) => k.includes(q) || v.desc.toLowerCase().includes(q))
81
90
  const text = matches.map(([k, v]) => `${k}${v.params} — ${v.desc}`).join("\n") || "No matches"
82
91
  return { content: [{ type: "text", text }] }
83
92
  })
84
93
 
85
- server.tool("describe_tools", {}, () => ({
94
+ registerTool("describe_tools", {}, () => ({
86
95
  content: [{ type: "text", text: Object.entries(TOOLS).map(([k, v]) => `${k}${v.params} — ${v.desc}`).join("\n") }]
87
96
  }))
88
97
 
89
- server.tool("resolve_project", { name: z.string() }, ({ name }) => {
98
+ registerTool("resolve_project", { name: z.string() }, ({ name }) => {
90
99
  const id = resolveProjectId(db, name)
91
100
  const project = id ? db.prepare("SELECT * FROM projects WHERE id = $id").get({ $id: id }) : null
92
101
  return { content: [{ type: "text", text: JSON.stringify(project ?? { error: `Project '${name}' not found` }) }] }
93
102
  })
94
103
 
95
- server.tool("register_project", {
104
+ registerTool("register_project", {
96
105
  name: z.string(), github_repo: z.string().optional(), base_url: z.string().optional(), description: z.string().optional(),
97
106
  }, (args) => ({ content: [{ type: "text", text: JSON.stringify(createProject(db, args)) }] }))
98
107
 
99
- server.tool("register_page", {
108
+ registerTool("register_page", {
100
109
  project_id: z.string(), url: z.string(), path: z.string().optional(), name: z.string().optional(),
101
110
  }, (args) => ({ content: [{ type: "text", text: JSON.stringify(createPage(db, { ...args, project_id: rp(args.project_id) ?? args.project_id })) }] }))
102
111
 
103
- server.tool("create_scan_job", {
112
+ registerTool("create_scan_job", {
104
113
  project_id: z.string(), schedule: z.string(), page_id: z.string().optional(),
105
114
  }, (args) => ({ content: [{ type: "text", text: JSON.stringify(createJob(db, { ...args, project_id: rp(args.project_id) ?? args.project_id })) }] }))
106
115
 
107
- server.tool("log_push", {
116
+ registerTool("log_push", {
108
117
  level: z.enum(["debug", "info", "warn", "error", "fatal"]),
109
118
  message: z.string(),
110
119
  project_id: z.string().optional(), service: z.string().optional(),
111
120
  trace_id: z.string().optional(), session_id: z.string().optional(),
112
121
  agent: z.string().optional(), url: z.string().optional(),
113
- metadata: z.record(z.unknown()).optional(),
122
+ metadata: z.record(z.string(), z.unknown()).optional(),
114
123
  }, (args) => {
115
124
  const row = ingestLog(db, { ...args, project_id: rp(args.project_id) })
116
125
  return { content: [{ type: "text", text: `Logged: ${row.id}` }] }
117
126
  })
118
127
 
119
- server.tool("log_push_batch", {
128
+ registerTool("log_push_batch", {
120
129
  entries: z.array(z.object({
121
130
  level: z.enum(["debug", "info", "warn", "error", "fatal"]),
122
131
  message: z.string(),
123
132
  project_id: z.string().optional(), service: z.string().optional(),
124
- trace_id: z.string().optional(), metadata: z.record(z.unknown()).optional(),
133
+ trace_id: z.string().optional(), metadata: z.record(z.string(), z.unknown()).optional(),
125
134
  })),
126
135
  trace_id: z.string().optional().describe("Shared trace_id applied to all entries that don't have their own trace_id"),
127
136
  project_id: z.string().optional().describe("Shared project_id applied to all entries (individual entry project_id takes precedence)"),
@@ -134,7 +143,7 @@ server.tool("log_push_batch", {
134
143
  return { content: [{ type: "text", text: `Logged ${rows.length} entries${trace_id ? ` (trace: ${trace_id})` : ''}` }] }
135
144
  })
136
145
 
137
- server.tool("log_search", {
146
+ registerTool("log_search", {
138
147
  project_id: z.string().optional(), page_id: z.string().optional(),
139
148
  level: z.string().optional(), service: z.string().optional(),
140
149
  since: z.string().optional(), until: z.string().optional(),
@@ -151,14 +160,14 @@ server.tool("log_search", {
151
160
  return { content: [{ type: "text", text: JSON.stringify(applyBrief(rows, args.brief !== false)) }] }
152
161
  })
153
162
 
154
- server.tool("log_tail", {
163
+ registerTool("log_tail", {
155
164
  project_id: z.string().optional(), n: z.number().optional(), brief: z.boolean().optional(),
156
165
  }, ({ project_id, n, brief }) => {
157
166
  const rows = tailLogs(db, rp(project_id), n ?? 50)
158
167
  return { content: [{ type: "text", text: JSON.stringify(applyBrief(rows, brief !== false)) }] }
159
168
  })
160
169
 
161
- server.tool("log_count", {
170
+ registerTool("log_count", {
162
171
  project_id: z.string().optional(), service: z.string().optional(),
163
172
  level: z.string().optional(), since: z.string().optional(), until: z.string().optional(),
164
173
  group_by: z.enum(["level", "service"]).optional().describe("Return breakdown by 'level' or 'service' in addition to totals"),
@@ -166,7 +175,7 @@ server.tool("log_count", {
166
175
  content: [{ type: "text", text: JSON.stringify(countLogs(db, { ...args, project_id: rp(args.project_id) })) }]
167
176
  }))
168
177
 
169
- server.tool("log_recent_errors", {
178
+ registerTool("log_recent_errors", {
170
179
  project_id: z.string().optional(), since: z.string().optional(), limit: z.number().optional(),
171
180
  }, ({ project_id, since, limit }) => {
172
181
  const rows = searchLogs(db, {
@@ -178,19 +187,19 @@ server.tool("log_recent_errors", {
178
187
  return { content: [{ type: "text", text: JSON.stringify(applyBrief(rows, true)) }] }
179
188
  })
180
189
 
181
- server.tool("log_summary", {
190
+ registerTool("log_summary", {
182
191
  project_id: z.string().optional(), since: z.string().optional(),
183
192
  }, ({ project_id, since }) => ({
184
193
  content: [{ type: "text", text: JSON.stringify(summarizeLogs(db, rp(project_id), parseTime(since) ?? since)) }]
185
194
  }))
186
195
 
187
- server.tool("log_context", {
196
+ registerTool("log_context", {
188
197
  trace_id: z.string(), brief: z.boolean().optional(),
189
198
  }, ({ trace_id, brief }) => ({
190
199
  content: [{ type: "text", text: JSON.stringify(applyBrief(getLogContext(db, trace_id), brief !== false)) }]
191
200
  }))
192
201
 
193
- server.tool("log_context_from_id", {
202
+ registerTool("log_context_from_id", {
194
203
  log_id: z.string(),
195
204
  brief: z.boolean().optional(),
196
205
  window: z.number().int().min(0).optional().describe("Return N logs before and after the target log's timestamp (in addition to trace context)"),
@@ -198,7 +207,7 @@ server.tool("log_context_from_id", {
198
207
  content: [{ type: "text", text: JSON.stringify(applyBrief(getLogContextFromId(db, log_id, window ?? 0), brief !== false)) }]
199
208
  }))
200
209
 
201
- server.tool("log_export", {
210
+ registerTool("log_export", {
202
211
  project_id: z.string().optional().describe("Project name or ID"),
203
212
  format: z.enum(["json", "csv"]).optional().default("json").describe("Output format"),
204
213
  since: z.string().optional().describe("Since time (1h, 24h, 7d, ISO)"),
@@ -222,7 +231,7 @@ server.tool("log_export", {
222
231
  return { content: [{ type: "text" as const, text: chunks.join("") }] }
223
232
  })
224
233
 
225
- server.tool("log_diagnose", {
234
+ registerTool("log_diagnose", {
226
235
  project_id: z.string(),
227
236
  since: z.string().optional(),
228
237
  include: z.array(z.enum(["top_errors", "error_rate", "failing_pages", "perf"])).optional(),
@@ -230,7 +239,7 @@ server.tool("log_diagnose", {
230
239
  content: [{ type: "text", text: JSON.stringify(diagnose(db, rp(project_id) ?? project_id, since, include)) }]
231
240
  }))
232
241
 
233
- server.tool("log_compare", {
242
+ registerTool("log_compare", {
234
243
  project_id: z.string(),
235
244
  a_since: z.string(), a_until: z.string(),
236
245
  b_since: z.string(), b_until: z.string(),
@@ -240,71 +249,71 @@ server.tool("log_compare", {
240
249
  parseTime(b_since) ?? b_since, parseTime(b_until) ?? b_until)) }]
241
250
  }))
242
251
 
243
- server.tool("log_session_context", {
252
+ registerTool("log_session_context", {
244
253
  session_id: z.string(), brief: z.boolean().optional(),
245
254
  }, async ({ session_id, brief }) => {
246
255
  const ctx = await getSessionContext(db, session_id)
247
256
  return { content: [{ type: "text", text: JSON.stringify({ ...ctx, logs: applyBrief(ctx.logs, brief !== false) }) }] }
248
257
  })
249
258
 
250
- server.tool("perf_snapshot", {
259
+ registerTool("perf_snapshot", {
251
260
  project_id: z.string(), page_id: z.string().optional(),
252
261
  }, ({ project_id, page_id }) => {
253
262
  const snap = getLatestSnapshot(db, rp(project_id) ?? project_id, page_id)
254
263
  return { content: [{ type: "text", text: JSON.stringify(snap ? { ...snap, label: scoreLabel(snap.score) } : null) }] }
255
264
  })
256
265
 
257
- server.tool("perf_trend", {
266
+ registerTool("perf_trend", {
258
267
  project_id: z.string(), page_id: z.string().optional(), since: z.string().optional(), limit: z.number().optional(),
259
268
  }, ({ project_id, page_id, since, limit }) => ({
260
269
  content: [{ type: "text", text: JSON.stringify(getPerfTrend(db, rp(project_id) ?? project_id, page_id, parseTime(since) ?? since, limit ?? 50)) }]
261
270
  }))
262
271
 
263
- server.tool("scan_status", {
272
+ registerTool("scan_status", {
264
273
  project_id: z.string().optional(),
265
274
  }, ({ project_id }) => ({
266
275
  content: [{ type: "text", text: JSON.stringify(listJobs(db, rp(project_id))) }]
267
276
  }))
268
277
 
269
- server.tool("list_projects", {}, () => ({
278
+ registerTool("list_projects", {}, () => ({
270
279
  content: [{ type: "text", text: JSON.stringify(listProjects(db)) }]
271
280
  }))
272
281
 
273
- server.tool("list_pages", { project_id: z.string() }, ({ project_id }) => ({
282
+ registerTool("list_pages", { project_id: z.string() }, ({ project_id }) => ({
274
283
  content: [{ type: "text", text: JSON.stringify(listPages(db, rp(project_id) ?? project_id)) }]
275
284
  }))
276
285
 
277
- server.tool("list_issues", {
286
+ registerTool("list_issues", {
278
287
  project_id: z.string().optional(), status: z.string().optional(), limit: z.number().optional(),
279
288
  }, ({ project_id, status, limit }) => ({
280
289
  content: [{ type: "text", text: JSON.stringify(listIssues(db, rp(project_id), status, limit ?? 50)) }]
281
290
  }))
282
291
 
283
- server.tool("resolve_issue", {
292
+ registerTool("resolve_issue", {
284
293
  id: z.string(), status: z.enum(["open", "resolved", "ignored"]),
285
294
  }, ({ id, status }) => ({
286
295
  content: [{ type: "text", text: JSON.stringify(updateIssueStatus(db, id, status)) }]
287
296
  }))
288
297
 
289
- server.tool("create_alert_rule", {
298
+ registerTool("create_alert_rule", {
290
299
  project_id: z.string(), name: z.string(),
291
300
  level: z.string().optional(), service: z.string().optional(),
292
301
  threshold_count: z.number().optional(), window_seconds: z.number().optional(),
293
302
  action: z.enum(["webhook", "log"]).optional(), webhook_url: z.string().optional(),
294
303
  }, (args) => ({ content: [{ type: "text", text: JSON.stringify(createAlertRule(db, { ...args, project_id: rp(args.project_id) ?? args.project_id })) }] }))
295
304
 
296
- server.tool("list_alert_rules", {
305
+ registerTool("list_alert_rules", {
297
306
  project_id: z.string().optional(),
298
307
  }, ({ project_id }) => ({
299
308
  content: [{ type: "text", text: JSON.stringify(listAlertRules(db, rp(project_id))) }]
300
309
  }))
301
310
 
302
- server.tool("delete_alert_rule", { id: z.string() }, ({ id }) => {
311
+ registerTool("delete_alert_rule", { id: z.string() }, ({ id }) => {
303
312
  deleteAlertRule(db, id)
304
313
  return { content: [{ type: "text", text: "deleted" }] }
305
314
  })
306
315
 
307
- server.tool("get_health", {}, () => ({
316
+ registerTool("get_health", {}, () => ({
308
317
  content: [{ type: "text", text: JSON.stringify(getHealth(db)) }]
309
318
  }))
310
319
 
@@ -329,5 +338,26 @@ server.tool("log_stats", {
329
338
  }
330
339
  })
331
340
 
341
+ server.tool(
342
+ "send_feedback",
343
+ "Send feedback about this service",
344
+ {
345
+ message: z.string(),
346
+ email: z.string().optional(),
347
+ category: z.enum(["bug", "feature", "general"]).optional(),
348
+ },
349
+ async (params) => {
350
+ try {
351
+ const pkg = require("../../package.json")
352
+ db.run("INSERT INTO feedback (message, email, category, version) VALUES (?, ?, ?, ?)", [
353
+ params.message, params.email || null, params.category || "general", pkg.version,
354
+ ])
355
+ return { content: [{ type: "text" as const, text: "Feedback saved. Thank you!" }] }
356
+ } catch (e) {
357
+ return { content: [{ type: "text" as const, text: String(e) }], isError: true }
358
+ }
359
+ },
360
+ )
361
+
332
362
  const transport = new StdioServerTransport()
333
363
  await server.connect(transport)