Feature/cli status - #1811
Feature/cli status#1811jeregon1 wants to merge 8 commits into
Conversation
- Extract pure snapshot logic to app/utils/cliStatus.js - Add --json/-j option to status command - Wire --json flag through both instance paths in main.js - Detect paused state in status output - Delete snapshot file on app quit - Add 24 unit tests for all three exported functions - Update CHANGELOG
…n fields to JSON output - Replace app.quit() with app.exit(0) in status handlers to bypass before-quit handler (globalShortcut not ready) - Add time_to_*_human and long_break_enabled fields to JSON output - Rename time_to_* fields to time_to_*_ms for clarity - Update printJsonSnapshotAsText to use new field names - Update tests to match new JSON shape
There was a problem hiding this comment.
Pull request overview
This PR adds a stretchly status CLI command intended to expose the current break state without opening the GUI, with optional --json / -j output for status bar/script integration. It implements a snapshot-based approach by having the running instance write a JSON snapshot to the user data directory, which subsequent invocations can read.
Changes:
- Added CLI parsing/support for a new
statuscommand (including--json/-j). - Added snapshot generation utilities (
app/utils/cliStatus.js) and a new test suite covering status formatting/snapshot building. - Updated documentation (README/CHANGELOG) to mention the new CLI behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/commands.js | Adds coverage ensuring --status is recognized and not forwarded to the main instance. |
| test/cliStatus.js | Adds tests for duration formatting and status snapshot construction in text and JSON modes. |
| README.md | Documents the new status CLI usage. |
| CHANGELOG.md | Notes the new CLI status command and JSON flag. |
| app/utils/commands.js | Registers the status command and --json option; adds examples; tweaks parsing for --status. |
| app/utils/cliStatus.js | Introduces snapshot building + long-break time computation helpers. |
| app/main.js | Writes status snapshot periodically (via tray update path) and adds logic to print status from snapshot / headless run. |
| ======= | ||
| - `stretchly status` command to show current break state from CLI | ||
| - `stretchly status --json` flag for machine-readable JSON output | ||
| >>>>>>> f254297a (feat: implement stretchly status command with --json flag) | ||
| - advanced option for Break Health Mode |
| When a Stretchly instance is running, the `stretchly` command can be use to interact with it from the command line. | ||
|
|
||
| Type `stretchly help` to get a list of all commands and options available as well as some examples. | ||
| Type `stretchly --status` to see either active break details (type + time remaining) or, when no break is active, time to next break and next long break. |
| writeCliStatusSnapshot() | ||
|
|
||
| if (!appIcon && !settings.get('showTrayIcon')) { | ||
| return | ||
| } |
| const startupCommand = new Command(commandLineArguments, app.getVersion(), false) | ||
| if (startupCommand.command === 'status') { | ||
| printCliStatusAndQuit(startupCommand.options && startupCommand.options.json) | ||
| return | ||
| } |
| if (json) { | ||
| return { | ||
| status: 'active_break', | ||
| break_type: reference === 'finishMicrobreak' ? 'mini' : 'long', | ||
| time_to_break_end_ms: breakPlanner.scheduler.timeLeft, | ||
| time_to_break_end_human: formatCliDuration(breakPlanner.scheduler.timeLeft) | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1811 +/- ##
==========================================
+ Coverage 67.39% 71.04% +3.65%
==========================================
Files 16 18 +2
Lines 506 563 +57
==========================================
+ Hits 341 400 +59
+ Misses 165 163 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi and thanks for the PR :) Can you explain what complexities do you mean here?
|
|
Thank you for reviewing, It's my first contribution to the project, so probably I don't understand it well enough so that I'm right on what I'm going to say. I'll really appreciate any feedback <3 |
|
Ah, gotcha, you mean sending message from 1st to 2nd instance. That's right, we don't have that yet, but writing file every 10 seconds seems excessive. I think we should use We need to decide: how are we going to map it? Do we want to use localized message or english? What do you think? |
|
I believe this command's main purpose is to be used with the --json flag, i.e. people using this will be mainly for scripting purposes, as the person who created the #1628 stated. In that case, I think it's not necessary to add localization. And yes, I didn't notice the |
|
So plan should be:
Then we can nitpick about specific wording in messages |
Issue: #1628
Requirements
nodeversion specified inpackage.jsonwas used (v22+).npm run lintreports no offenses.npm run testis error-free (24 new tests pass).Description of the Change
Adds a
stretchly statusCLI command that shows the current break state without opening the GUI. Supports both human-readable text output and--json/-jfor machine parsing (integration with polybar, i3status, etc.).States detected:
no_active_break— shows time remaining until the next mini and long breakactive_break— shows break type (mini/long) and time until it endspaused— shows that breaks are pausedSnapshot-based architecture: The running instance periodically writes a JSON snapshot file. Any second instance reads this file to display status, avoiding IPC complexity and keeping the first instance unmodified.
Verification Process
npm run lint— cleannpm run test— 24 new tests + 32 existing = 56 passednpm run pack— builds successfully on Windows