Skip to content

Conversation

@himattm
Copy link
Collaborator

@himattm himattm commented Jan 30, 2026

Summary

  • Add --json flag to tq list, tq logs, and tq clear commands for structured JSON output
  • Add command column to queue schema so consumers can see what's running (e.g., ./gradlew build)
  • Add TestJsonSchemaContracts test class to enforce JSON structure stability for programmatic consumers

Motivation

Enable agents and status lines to programmatically read task queue state. For example, a Claude Code status line can now show "Queue: 1 running (./gradlew build), 2 waiting" by parsing tq list --json.

JSON Schemas

tq list --json

{
  "tasks": [{"id": 1, "queue_name": "global", "status": "running", "command": "./gradlew build", ...}],
  "summary": {"total": 1, "running": 1, "waiting": 0}
}

tq logs --json

{"entries": [{"event": "task_completed", "timestamp": "...", "task_id": 1, ...}]}

tq clear --json

{"cleared": 5, "success": true}

Test plan

  • tq list --json | jq . produces valid JSON
  • tq logs --json | jq . produces valid JSON
  • tq clear --json skips confirmation and outputs JSON
  • Schema contract tests verify exact field names and types
  • All 40 tests pass

🤖 Generated with Claude Code

Enable agents and status lines to read task queue state by adding
structured JSON output to list, logs, and clear commands. The command
field is now stored in the queue table and included in JSON output,
allowing consumers to see what's actually running (e.g., "./gradlew build").

Changes:
- Add --json flag to tq list, logs, and clear subcommands
- Add command column to queue schema with migration for existing DBs
- Add TestJsonSchemaContracts test class to enforce JSON structure stability
- JSON mode for clear skips interactive confirmation (implies --force)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds structured JSON output options to the tq CLI to support programmatic inspection of queue state, and extends the queue DB schema to store the task command.

Changes:

  • Add --json output mode to tq list, tq logs, and tq clear.
  • Persist the task command in the queue table and add a migration for existing DBs.
  • Add JSON schema contract tests to enforce stable output shape for consumers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tq.py Adds --json flags for list/logs/clear, emits JSON payloads, and stores the command string when registering tasks.
queue_core.py Extends the queue table schema with a command column and adds a migration to retrofit existing DBs.
tests/test_tq_cli.py Adds functional + contract tests asserting exact JSON schemas for list, logs, and clear.
Comments suppressed due to low confidence (8)

tests/test_tq_cli.py:505

  • This import of module os is redundant, as it was previously imported on line 7.
        import os

tests/test_tq_cli.py:506

  • This import of module signal is redundant, as it was previously imported on line 8.
        import signal

tests/test_tq_cli.py:574

  • This import of module os is redundant, as it was previously imported on line 7.
        import os

tests/test_tq_cli.py:575

  • This import of module signal is redundant, as it was previously imported on line 8.
        import signal

tests/test_tq_cli.py:632

  • This import of module os is redundant, as it was previously imported on line 7.
        import os

tests/test_tq_cli.py:633

  • This import of module signal is redundant, as it was previously imported on line 8.
        import signal

tests/test_tq_cli.py:703

  • This import of module signal is redundant, as it was previously imported on line 8.
        import signal

tests/test_tq_cli.py:740

  • This import of module signal is redundant, as it was previously imported on line 8.
        import signal

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

tq.py Outdated
# clear
subparsers.add_parser("clear", help="Clear all tasks from queue")
clear_parser = subparsers.add_parser("clear", help="Clear all tasks from queue")
clear_parser.add_argument("--json", action="store_true", help="Output in JSON format (implies --force)")
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The --json help text says it "implies --force", but there is no --force/--yes option implemented for tq clear. This is confusing for users and makes the help output inaccurate. Either add a real --force flag (and keep --json implying it), or update the help text to say that --json skips confirmation.

Suggested change
clear_parser.add_argument("--json", action="store_true", help="Output in JSON format (implies --force)")
clear_parser.add_argument(
"--json",
action="store_true",
help="Output in JSON format and skip confirmation",
)

Copilot uses AI. Check for mistakes.
Comment on lines 159 to 177
def test_list_json_empty_queue(self, temp_data_dir):
"""Test list --json command with empty queue."""
result = run_tq("list", "--json", data_dir=temp_data_dir)

assert result.returncode == 0
output = json.loads(result.stdout)
assert output == {
"tasks": [],
"summary": {"total": 0, "running": 0, "waiting": 0}
}

def test_list_json_no_database(self, temp_data_dir):
"""Test list --json command when database doesn't exist."""
result = run_tq("list", "--json", data_dir=temp_data_dir)

assert result.returncode == 0
output = json.loads(result.stdout)
assert output["tasks"] == []
assert output["summary"]["total"] == 0
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

test_list_json_empty_queue and test_list_json_no_database currently exercise the same code path (both run against a fresh temp dir with no DB file). This duplicates coverage and the "empty_queue" name/docstring is misleading. Consider removing one test, or change one to first initialize the DB (e.g., run a no-op task to create the DB, then clear it) so it actually tests the "DB exists but queue is empty" case.

Copilot uses AI. Check for mistakes.
- Fix --json help text: say "skip confirmation" instead of "implies --force"
- Fix test_list_json_empty_queue to actually test DB-exists-but-empty case

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@himattm himattm merged commit 22cfe41 into main Jan 30, 2026
6 of 7 checks passed
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.

2 participants