Skip to content

fix(tasks): honor category argument in add_task (#46)#63

Open
sheikharfaz wants to merge 3 commits into
TruFoundation:mainfrom
sheikharfaz:fix/task-category-gh46
Open

fix(tasks): honor category argument in add_task (#46)#63
sheikharfaz wants to merge 3 commits into
TruFoundation:mainfrom
sheikharfaz:fix/task-category-gh46

Conversation

@sheikharfaz

@sheikharfaz sheikharfaz commented Jun 8, 2026

Copy link
Copy Markdown

Summary

Fixes #46. add_task() hard-coded category="General" and treated the entire argument (quotes included) as the task text, so a user-supplied category was silently discarded — even though the Todo model and the SQLite persistence layer fully support categories and the README documents addtask "<task>" "<category>".

Fix

add_task now parses an optional quoted category, mirroring the existing update_task syntax and the documented form. Fully backward-compatible:

Input task category
task add "Buy milk" "Shopping" Buy milk Shopping
task add "Pay rent" Pay rent General (default)
task add buy groceries buy groceries General (unchanged)

A one-line companion change in cli.py makes its addtask handler pass the quoted form instead of concatenating the two captured groups into a single string.

Tests

Added 3 regression tests in tests/test_tasks.py covering a supplied category, the default fallback, and unquoted back-compat. Full suite passes locally — 31 passed, 5 skipped on Python 3.10.

Summary by CodeRabbit

  • New Features

    • Enhanced task command to support quoted syntax with optional category parameter, defaulting to "General" when omitted
    • Maintains backwards compatibility with existing unquoted task format
  • Tests

    • Added tests validating quoted syntax parsing, default category behavior, and backwards compatibility

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds category argument support to the add_task command by implementing regex-based parsing for quoted "task" and optional "category" arguments, updating the CLI to pass arguments in the new quoted format, and validating the behavior with three new test cases including backwards compatibility.

Changes

Task Category Support

Layer / File(s) Summary
Task parsing with category support
trushell/commands/tasks.py
add_task now parses args via regex to extract quoted "task" and optional quoted "category", defaulting category to "General" when omitted. Supports unquoted task text for backwards compatibility. Module imports re for pattern matching.
CLI argument forwarding
trushell/cli.py
The addtask command handler now constructs and passes task and category arguments to add_task using explicit quoted format "{task}" "{category}".
Parsing validation tests
tests/test_tasks.py
Three tests verify that add_task parses quoted task and category correctly, defaults category to "General" when only task is provided, and remains backwards compatible by treating unquoted input as full task text with category defaulting to "General". Each test monkeypatches insert_todo to capture and assert on constructed todo fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Tasks now remember their homes so true,
With categories quoted, defaults when none are due,
Backwards we journey, yet forward we leap,
Three tests confirm these promises we keep! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(tasks): honor category argument in add_task (#46)' clearly summarizes the main change: fixing the add_task function to respect category arguments instead of hardcoding them.
Linked Issues check ✅ Passed The PR fully addresses issue #46 by implementing quoted category parsing in add_task, updating cli.py to pass quoted arguments, and adding comprehensive regression tests validating the fix.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #46: tests validate category parsing, cli.py passes properly formatted arguments, and add_task implements the required parsing logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
trushell/commands/tasks.py (1)

28-34: ⚡ Quick win

Edge case: Empty quoted task is not rejected.

If a user provides an empty quoted task (e.g., task add ""), the regex won't match because [^"]+ requires at least one character. The else branch on line 33 will treat the input "" (including literal quote characters) as the task text, creating a Todo with task='""' and category='General'. The validation on line 24 doesn't catch this because '""'.strip() evaluates to '""' (non-empty).

Consider adding validation after parsing to reject empty task text:

🛡️ Proposed validation for empty task
     else:
         task_text = text
         category = "General"
+
+    if not task_text:
+        print('Usage: task add "<task>" ["<category>"]')
+        return

     todo = Todo(task=task_text, category=category)

Note: The pattern [^"]+ also doesn't handle embedded quotes (e.g., "Buy \"milk\""). This is a known limitation of the simple regex approach. For more robust parsing, consider shlex.split() in a future enhancement, though that would require careful handling of backwards compatibility for unquoted input.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@trushell/commands/tasks.py` around lines 28 - 34, The parsing allows an empty
quoted task like '""' to slip through as task_text, so after the existing
parsing (the match / else block that sets match, task_text and category) add a
validation that rejects empty quoted tasks: detect if the original text starts
and ends with a quote (e.g., text.startswith('"') and text.endswith('"')) and
then check the inner content (text[1:-1].strip()) is not empty; if it is empty,
raise the same validation/return error used on line 24. Apply this check after
the match/else logic (referencing variables match, task_text, category and the
surrounding parsing block) so inputs like '""' are rejected while preserving
existing behavior for unquoted inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@trushell/commands/tasks.py`:
- Around line 28-34: The parsing allows an empty quoted task like '""' to slip
through as task_text, so after the existing parsing (the match / else block that
sets match, task_text and category) add a validation that rejects empty quoted
tasks: detect if the original text starts and ends with a quote (e.g.,
text.startswith('"') and text.endswith('"')) and then check the inner content
(text[1:-1].strip()) is not empty; if it is empty, raise the same
validation/return error used on line 24. Apply this check after the match/else
logic (referencing variables match, task_text, category and the surrounding
parsing block) so inputs like '""' are rejected while preserving existing
behavior for unquoted inputs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cf716379-26e4-4de6-b720-b834903c1c2e

📥 Commits

Reviewing files that changed from the base of the PR and between 7ab2e53 and bdc22d3.

📒 Files selected for processing (3)
  • tests/test_tasks.py
  • trushell/cli.py
  • trushell/commands/tasks.py

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.

Task commands bypass category argument

1 participant