{"id":26396,"library":"sleep-compiler","title":"sleep-compiler","description":"A command-line sleep tracker that logs, analyzes, and reports sleep patterns. Version 1.4.0 is the latest stable release. Data is stored locally in SQLite at ~/.sleep-compiler/sleep.db with no cloud dependencies. Key differentiators: it operates entirely offline, supports active sleep sessions (sleep now / wake now), generates reports with quality thresholds and consistency scores, and exports CSV. Alternatives like Sleep as Android require a mobile app; sleep-compiler runs in the terminal for developers and privacy-conscious users.","status":"active","version":"1.4.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install sleep-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add sleep-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add sleep-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Local SQLite database storage","package":"better-sqlite3","optional":false},{"reason":"Command-line interface parsing","package":"commander","optional":false}],"imports":[{"note":"Package is ESM-only as of v1.4.0","wrong":"const sleepCompiler = require('sleep-compiler')","symbol":"default","correct":"import sleepCompiler from 'sleep-compiler'"},{"note":"Named export, not default","wrong":"import logSleep from 'sleep-compiler'","symbol":"logSleep","correct":"import { logSleep } from 'sleep-compiler'"},{"note":"ESM named import; CommonJS require will fail","wrong":"const getReport = require('sleep-compiler').getReport","symbol":"getReport","correct":"import { getReport } from 'sleep-compiler'"}],"quickstart":{"code":"// Log sleep entry and generate a 7-day report\nimport { logSleep, getReport } from 'sleep-compiler';\n\nasync function main() {\n  // Log sleep for last night\n  await logSleep({\n    sleepTime: '23:30',\n    wakeTime: '07:15',\n    date: '2024-03-15'\n  });\n\n  // Get report for last 7 days\n  const report = await getReport({ days: 7 });\n  console.log(report);\n}\n\nmain().catch(err => console.error(err));","lang":"typescript","description":"Demonstrates logging a sleep entry and retrieving a report programmatically using named imports."},"warnings":[{"fix":"Use import statements instead of require(). Update your package.json to include \"type\": \"module\" or use .mjs extension.","message":"In v1.4.0, the API changed from CommonJS to ESM-only. require() will throw an error.","severity":"breaking","affected_versions":">=1.4.0"},{"fix":"Do not manually modify or delete files in ~/.sleep-compiler/. Use the status command to check active sessions.","message":"The `sleep now` command saves a pending session to ~/.sleep-compiler/pending-sleep.json. If this file is deleted before running `wake now`, the session is lost.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide times in 24-hour format, e.g., '23:30' for 11:30 PM or '07:15' for 7:15 AM.","message":"Times must be in 24-hour format (HH:MM). Using 12-hour format with AM/PM will cause parsing errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `sleep-compiler export --format csv` instead of `sleep-compiler export`.","message":"The `--format csv` option for export was added in v1.3.0 and is stable. The old export command without format is deprecated.","severity":"deprecated","affected_versions":">=1.3.0 <1.4.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Start a sleep session with `sleep-compiler sleep now` before calling `wake now`.","cause":"Attempted to run `wake now` without an active sleep session.","error":"Error: No pending sleep found. Run `sleep-compiler sleep now` first."},{"fix":"Add \"type\": \"module\" to package.json or rename file to .mjs.","cause":"Trying to use ESM imports in a CommonJS context without proper configuration.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use 24-hour format: hours 00-23, minutes 00-59. Example: '23:30'.","cause":"Provided sleep or wake time in wrong format, e.g., using 12-hour with AM/PM.","error":"Error: Invalid sleep time format. Use HH:MM in 24h format."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}