Skip to content

feat: track as-always-active-pattern#10

Merged
0xbrayo merged 1 commit intomasterfrom
always-active-pattern
Aug 23, 2025
Merged

feat: track as-always-active-pattern#10
0xbrayo merged 1 commit intomasterfrom
always-active-pattern

Conversation

@0xbrayo
Copy link
Copy Markdown
Member

@0xbrayo 0xbrayo commented Aug 23, 2025

Summary by CodeRabbit

  • New Features

    • The app now respects an optional “Always active” pattern setting when querying ActivityWatch data, improving accuracy of activity durations by preventing unintended idle gaps for specified apps/processes.
  • Chores

    • Updated a dependency branch to align with the new “Always active” support (no change to user-facing behavior).

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 23, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between ee09313 and 3e07089.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • src/main.rs (4 hunks)
 _______________________________________________
< Don't count your bugs before they're patched. >
 -----------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Walkthrough

The dependency branch for aw-client-rust changed in Cargo.toml. In src/main.rs, a setting named always_active_pattern is retrieved and passed into DesktopQueryParams. An import alias for Ordering was added, and a comparison reference was updated to use the alias.

Changes

Cohort / File(s) Summary of changes
Dependency update
Cargo.toml
Changed aw-client-rust dependency branch from queries-fix to always-active-pattern.
Query parameter integration
src/main.rs
Added cmpOrdering alias for std::cmp::Ordering. Fetched always_active_pattern via client.get_setting(...) and included it in DesktopQueryParams. Updated sort comparison to use cmpOrdering::Equal.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Main as main.rs
  participant Client as ActivityWatch Client
  participant Server as ActivityWatch Server

  User->>Main: Run application
  Main->>Client: get_setting("always_active_pattern")
  Client-->>Main: Option<String> value
  Note over Main: Build DesktopQueryParams<br/>including always_active_pattern (if present)

  Main->>Server: query(desktop, DesktopQueryParams{...})
  Server-->>Main: Results
  Note over Main: Sort results using Ordering alias

  Main-->>User: Display processed results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A thump of paws, I tweak the tune,
A pattern set to always bloom.
I fetch, I pass, I hop along,
Queries hum a steadier song.
With ordered whiskers, I compare—
Carrots sorted, clean and fair. 🥕🐇

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting in your project's settings in CodeRabbit to disable sequence diagrams in the walkthrough.

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch always-active-pattern

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@0xbrayo
Copy link
Copy Markdown
Member Author

0xbrayo commented Aug 23, 2025

#6

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Cargo.toml (1)

19-19: Pin the git dependency and verify crate resolution from forked repo

Depending on a moving branch increases build non-determinism and can break consumers unexpectedly. Also, since aw-client-rust is sourced from a forked aw-server-rust repo, please verify that the workspace actually contains a package named aw-client-rust on branch always-active-pattern.

  • Pin to a specific commit via rev = "<commit-sha>" for reproducibility.
  • Consider adding a comment explaining why the fork/branch is required and when it can be reverted.
  • If the repo hosts multiple crates in a workspace (likely), ensure Cargo resolves the aw-client-rust package correctly (no path override needed).

Example (illustrative only—use the actual commit SHA you depend on):

-aw-client-rust = {git = "https://github.com/0xbrayo/aw-server-rust", branch="always-active-pattern"}
+aw-client-rust = { git = "https://github.com/0xbrayo/aw-server-rust", branch = "always-active-pattern", rev = "<locked-commit-sha>" }

You can verify resolution locally with:

  • cargo update -p aw-client-rust
  • cargo tree -i aw-client-rust
src/main.rs (1)

17-17: Drop the type alias and use total_cmp for deterministic float sorting

The alias cmpOrdering is non-idiomatic (type aliases are usually UpperCamelCase) and exists solely to reference Ordering::Equal. Using f64::total_cmp yields a total ordering (robust in presence of NaN) and removes the need for the alias entirely.

Apply this diff to simplify:

-use std::cmp::Ordering as cmpOrdering;
-    categories.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(cmpOrdering::Equal));
+    categories.sort_by(|a, b| b.1.total_cmp(&a.1));

If you prefer to keep the current approach, at least rename the alias to CmpOrdering for style consistency and adjust the usage accordingly.

Also applies to: 1038-1038

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fb7353d and ee09313.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • src/main.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Lint and Format Check
  • GitHub Check: Build (Windows)
  • GitHub Check: Build (Linux ARM64)
  • GitHub Check: Build (macOS)
  • GitHub Check: Build (Linux x64)
  • GitHub Check: Build (Windows)
  • GitHub Check: Build (Linux ARM64)
🔇 Additional comments (1)
src/main.rs (1)

478-479: Threading the new parameter through DesktopQueryParams looks good

The new always_active_pattern field is correctly plumbed into DesktopQueryParams. Once the safe extraction above is applied, this will gracefully handle absent settings.

Comment thread src/main.rs
Comment on lines +459 to +466
let always_active_pattern = Some(
client
.get_setting("always_active_pattern")
.unwrap()
.to_string(),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid panic and incorrect JSON stringification when reading always_active_pattern

unwrap() will panic if the setting is missing or the server is unavailable. Additionally, to_string() on a serde_json::Value yields JSON (e.g., quoted strings) rather than the plain string content. Prefer a safe extraction to Option<String>.

Apply this diff to make it robust and correct:

-    let always_active_pattern = Some(
-        client
-            .get_setting("always_active_pattern")
-            .unwrap()
-            .to_string(),
-    );
+    let always_active_pattern = match client.get_setting("always_active_pattern") {
+        Ok(v) => v.as_str().map(|s| s.to_owned()),
+        Err(e) => {
+            log::debug!("always_active_pattern not set or unavailable: {}", e);
+            None
+        }
+    };
🤖 Prompt for AI Agents
In src/main.rs around lines 459 to 465, replace the current unwrap()+to_string()
usage with a non-panicking conversion that yields an Option<String>; call
client.get_setting("always_active_pattern"), convert any Err to None with .ok()
(or if it already returns Option, use it directly), then .and_then(|v|
v.as_str().map(|s| s.to_owned())), assigning the result to let
always_active_pattern: Option<String> so missing settings or errors produce None
and the JSON Value is unwrapped to the raw string content.

@0xbrayo 0xbrayo force-pushed the always-active-pattern branch from ee09313 to 3e07089 Compare August 23, 2025 04:45
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/main.rs (1)

459-466: Avoid panic and incorrect JSON stringification when reading always_active_pattern

Using expect(...) will terminate the process if the setting is absent or the server is unavailable, and Value::to_string() returns JSON (quoted) rather than the raw string. Convert to Option via as_str() and handle errors gracefully.

Apply this diff to Lines 459-466:

-    // Should never fail
-    let always_active_pattern = Some(
-        client
-            .get_setting("always_active_pattern")
-            .expect("failed to fetch always_active_pattern")
-            .to_string(),
-    );
+    // Best-effort fetch; treat missing/unavailable as None and unwrap JSON string to a plain String
+    let always_active_pattern = match client.get_setting("always_active_pattern") {
+        Ok(v) => v.as_str().map(|s| s.to_owned()),
+        Err(e) => {
+            log::debug!("always_active_pattern not set or unavailable: {}", e);
+            None
+        }
+    };
🧹 Nitpick comments (2)
src/main.rs (2)

1039-1040: Prefer f64::total_cmp to avoid NaN pitfalls and drop the Ordering alias

partial_cmp returns None for NaN; defaulting to Equal can yield unstable ordering. total_cmp provides a total order for f64 and is available on stable. It also lets you remove the cmpOrdering alias entirely.

Apply this diff to Line 1039:

-    categories.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(cmpOrdering::Equal));
+    categories.sort_by(|a, b| b.1.total_cmp(&a.1));

17-17: Remove the non-idiomatic cmpOrdering alias

The alias adds noise and CamelCase spelling is unconventional for a type alias. With the sort change to total_cmp, this import is no longer needed.

Apply this diff to Line 17:

-use std::cmp::Ordering as cmpOrdering;
+// (removed) no longer needed
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ee09313 and 3e07089.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • src/main.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build (Windows)
  • GitHub Check: Build (Linux ARM64)
  • GitHub Check: Build (Linux x64)
  • GitHub Check: Lint and Format Check
  • GitHub Check: Build (Linux ARM64)
  • GitHub Check: Lint and Format Check
  • GitHub Check: Build (Windows)
  • GitHub Check: Build (Linux x64)
🔇 Additional comments (1)
src/main.rs (1)

479-480: Confirm DesktopQueryParams expects Option for always_active_pattern

Given the upstream change, verify the field type matches Option (or whatever the new API expects). If it expects a regex or serde_json::Value, adapt the conversion accordingly. Also decide whether empty strings should be treated as None.

@0xbrayo 0xbrayo merged commit 6d09ab0 into master Aug 23, 2025
11 checks passed
coderabbitai bot added a commit that referenced this pull request Aug 23, 2025
Docstrings generation was requested by @0xbrayo.

* #10 (comment)

The following files were modified:

* `src/main.rs`
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 23, 2025

Note

Generated docstrings for this pull request at #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant