agentfit 0.1.2 → 0.1.3

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/bin/agentfit.mjs CHANGED
@@ -36,11 +36,10 @@ if (!existsSync(generatedClient)) {
36
36
  run('npx prisma generate')
37
37
  }
38
38
 
39
- const dbPath = path.join(ROOT, 'agentfit.db')
40
- if (!existsSync(dbPath)) {
41
- info('Creating database...')
42
- run('npx prisma migrate deploy')
43
- }
39
+ // Run migrations — creates DB if new, applies pending migrations if existing.
40
+ // migrate deploy is a no-op when already up to date.
41
+ info('Applying database migrations...')
42
+ run('npx prisma migrate deploy')
44
43
 
45
44
  // ─── Build if .next doesn't exist ───────────────────────────────────
46
45
  const nextDir = path.join(ROOT, '.next')
package/electron/main.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { app, BrowserWindow, shell, dialog } from 'electron'
2
- import { execSync, spawn } from 'child_process'
3
- import { existsSync } from 'fs'
1
+ import { app, BrowserWindow, shell, dialog, utilityProcess } from 'electron'
2
+ import { existsSync, readFileSync } from 'fs'
3
+ import { createRequire } from 'module'
4
4
  import path from 'path'
5
5
  import http from 'http'
6
6
 
@@ -36,11 +36,8 @@ process.on('uncaughtException', (err) => {
36
36
  throw err
37
37
  })
38
38
 
39
- function ensureDatabase() {
39
+ async function ensureDatabase() {
40
40
  const schemaSQL = path.join(PRISMA_DIR, 'schema.sql')
41
- const initScript = isPacked
42
- ? path.join(process.resourcesPath, 'app.asar.unpacked', 'electron', 'init-db.mjs')
43
- : path.join(import.meta.dirname, 'init-db.mjs')
44
41
 
45
42
  if (!existsSync(schemaSQL)) {
46
43
  throw new Error(`schema.sql not found at ${schemaSQL}. Run "npm run prisma:schema-sql" first.`)
@@ -48,22 +45,24 @@ function ensureDatabase() {
48
45
 
49
46
  log(existsSync(DB_PATH) ? 'Checking database schema...' : 'Creating database...')
50
47
 
51
- // Run init-db.mjs using Electron's bundled Node.js runtime.
48
+ // Run DB init inline to avoid spawning a child Electron process,
49
+ // which causes a second dock icon on macOS.
52
50
  // Uses @libsql/client (already bundled) — works on macOS, Linux, and Windows.
53
51
  // schema.sql uses IF NOT EXISTS — safe to run on existing DBs.
54
52
  try {
55
- execSync(
56
- `"${process.execPath}" "${initScript}" "${DB_PATH}" "${schemaSQL}"`,
57
- {
58
- stdio: 'pipe',
59
- timeout: 15000,
60
- env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
61
- }
62
- )
53
+ const serverDir = isPacked
54
+ ? path.join(process.resourcesPath, 'app.asar.unpacked', 'electron', 'server')
55
+ : path.join(import.meta.dirname, 'server')
56
+ const require = createRequire(path.join(serverDir, 'package.json'))
57
+ const { createClient } = require('@libsql/client')
58
+
59
+ const client = createClient({ url: `file:${DB_PATH}` })
60
+ const sql = readFileSync(schemaSQL, 'utf-8')
61
+ await client.executeMultiple(sql)
62
+ client.close()
63
63
  log('Database ready.')
64
64
  } catch (err) {
65
- const stderr = err.stderr?.toString() || err.message
66
- log(`Database setup warning: ${stderr}`)
65
+ log(`Database setup warning: ${err.message}`)
67
66
  }
68
67
  }
69
68
 
@@ -78,14 +77,14 @@ function startServer() {
78
77
 
79
78
  log(`Starting server from ${serverJs}`)
80
79
 
81
- // In packaged Electron, process.execPath is the Electron binary.
82
- // We need to set ELECTRON_RUN_AS_NODE=1 so it acts as plain Node.js.
83
- serverProcess = spawn(process.execPath, [serverJs], {
80
+ // Use utilityProcess.fork() instead of child_process.spawn() to avoid
81
+ // a second dock icon on macOS. It runs as a background Node.js process.
82
+ serverProcess = utilityProcess.fork(serverJs, [], {
84
83
  cwd: SERVER_DIR,
85
- stdio: ['ignore', 'pipe', 'pipe'],
84
+ stdio: 'pipe',
85
+ serviceName: 'agentfit-server',
86
86
  env: {
87
87
  ...process.env,
88
- ELECTRON_RUN_AS_NODE: '1',
89
88
  PORT: String(PORT),
90
89
  HOSTNAME: '127.0.0.1',
91
90
  DATABASE_URL: `file:${DB_PATH}`,
@@ -95,10 +94,6 @@ function startServer() {
95
94
 
96
95
  serverProcess.stdout?.on('data', (d) => log(d.toString().trim()))
97
96
  serverProcess.stderr?.on('data', (d) => log(d.toString().trim()))
98
- serverProcess.on('error', (err) => {
99
- log(`Server process error: ${err.message}`)
100
- reject(err)
101
- })
102
97
  serverProcess.on('exit', (code) => {
103
98
  if (code !== null && code !== 0) {
104
99
  log(`Server exited with code ${code}`)
@@ -171,7 +166,7 @@ app.whenReady().then(async () => {
171
166
  const splash = showSplash()
172
167
 
173
168
  try {
174
- ensureDatabase()
169
+ await ensureDatabase()
175
170
  await startServer()
176
171
  splash.close()
177
172
  createWindow()
@@ -185,7 +180,7 @@ app.whenReady().then(async () => {
185
180
 
186
181
  app.on('window-all-closed', () => {
187
182
  if (serverProcess) {
188
- serverProcess.kill('SIGTERM')
183
+ serverProcess.kill()
189
184
  serverProcess = null
190
185
  }
191
186
  app.quit()
@@ -193,7 +188,7 @@ app.on('window-all-closed', () => {
193
188
 
194
189
  app.on('before-quit', () => {
195
190
  if (serverProcess) {
196
- serverProcess.kill('SIGTERM')
191
+ serverProcess.kill()
197
192
  serverProcess = null
198
193
  }
199
194
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentfit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Fitness tracker dashboard for AI coding agents (Claude Code, Codex). Visualize usage, cost, tokens, and productivity from local conversation logs.",
5
5
  "type": "module",
6
6
  "bin": {