Skip to content

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Feb 9, 2026

Summary

  • Enhanced pattern-tracker-helper.sh with recommend, export, and report commands for data-driven model routing decisions
  • Updated supervisor store_success_pattern/store_failure_pattern to use dedicated SUCCESS_PATTERN/FAILURE_PATTERN memory types with model tier, duration, and retry metadata
  • Integrated /route command with pattern history so model recommendations factor in historical success rates

Changes

pattern-tracker-helper.sh (major enhancement)

  • recommend command: Queries pattern history per model tier, calculates success rates, recommends the best-performing model
  • export command: Exports all patterns as JSON (sqlite3 -json) or CSV for external analysis
  • report command: Generates comprehensive report with date range, success rates, top failure patterns, model performance table, and recent patterns
  • suggest now includes model routing hints based on pattern data
  • All analysis queries both dedicated types (SUCCESS_PATTERN, FAILURE_PATTERN) and supervisor-generated types (WORKING_SOLUTION, FAILED_APPROACH, ERROR_FIX) for complete coverage
  • Added --task-id, --duration, --retries flags to record command

supervisor-helper.sh (pattern type alignment)

  • store_success_pattern() now stores as SUCCESS_PATTERN (was WORKING_SOLUTION)
  • store_failure_pattern() now stores as FAILURE_PATTERN (was FAILED_APPROACH/ERROR_FIX)
  • Both functions now look up model tier from task record and include it in tags/content
  • store_success_pattern() calculates task duration from started_at/completed_at timestamps
  • Structured content format: [task:type] description [model:tier] [duration:Ns] [retries:N]

/route command (pattern-aware routing)

  • Now runs pattern-tracker-helper.sh recommend before applying static routing rules
  • Combines pattern history with routing rules, weighting pattern data when sufficient samples exist

/patterns command (expanded)

  • Supports report, recommend, and standard suggest subcommands

memory/README.md

  • Updated pattern tracking section with all new commands and automatic capture documentation

Testing

  • ShellCheck: zero warnings on pattern-tracker-helper.sh
  • Syntax check: both scripts pass bash -n
  • Integration: all commands tested against live memory database (66 patterns)
  • Backward compatible: queries both old and new pattern types

Summary by CodeRabbit

Release Notes

  • New Features

    • Generate comprehensive reports on recorded patterns, including success/failure breakdowns and model tier performance.
    • Export pattern data in JSON or CSV formats.
    • Receive model tier recommendations based on pattern history and task types.
    • Enhanced pattern tracking now captures task duration and retry metadata for improved analysis.
  • Documentation

    • Updated routing guidance to incorporate pattern history analysis.
    • Expanded patterns documentation with detailed command pathways and available commands.

- Enhanced pattern-tracker-helper.sh with recommend, export, and report commands
- Supervisor now stores SUCCESS_PATTERN/FAILURE_PATTERN types (was WORKING_SOLUTION/FAILED_APPROACH)
  enabling pattern-tracker to find and analyze supervisor-generated patterns
- Supervisor patterns now include model tier, duration, and retry count metadata
- /route command now consults pattern history for data-driven model recommendations
- /patterns command supports report, recommend, and export subcommands
- Export supports JSON (via sqlite3 -json) and CSV formats
- Pattern analysis queries both dedicated and supervisor-generated pattern types
- Updated memory README with comprehensive pattern tracking documentation

Decision: kept backward compatibility by querying both old types (WORKING_SOLUTION,
FAILED_APPROACH, ERROR_FIX) and new types (SUCCESS_PATTERN, FAILURE_PATTERN) so
existing pattern data remains accessible.
@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant upgrade to the system's pattern tracking and model routing capabilities. By enhancing the pattern-tracker-helper.sh script with new analytical and reporting commands, and integrating the historical success and failure data directly into the model routing logic, the system can now make more informed and data-driven decisions about which models to use for specific tasks. The supervisor's automatic pattern capture has also been improved to store richer metadata, further empowering this data-driven approach.

Highlights

  • Enhanced Pattern Tracking Commands: The pattern-tracker-helper.sh script now includes new commands: recommend for data-driven model suggestions, export for outputting patterns in JSON or CSV, and report for generating comprehensive pattern summaries.
  • Richer Supervisor Pattern Storage: The supervisor's store_success_pattern and store_failure_pattern functions now use dedicated SUCCESS_PATTERN and FAILURE_PATTERN memory types, and automatically capture model tier, task duration, and retry count metadata from task records.
  • Data-Driven Model Routing Integration: The /route command has been integrated with the pattern history, allowing model recommendations to factor in historical success rates before applying static routing rules, leading to more intelligent model selection.
  • Expanded /patterns Command: The /patterns slash command now supports report and recommend subcommands, providing direct access to the new pattern analysis capabilities.
Changelog
  • .agents/memory/README.md
    • Updated documentation to reflect the new recommend, export, and report commands for pattern-tracker-helper.sh.
    • Added details about automatic pattern capture by the supervisor, including model tier, duration, and retry count metadata.
    • Updated examples for /patterns and /route commands to showcase new functionalities.
  • .agents/scripts/commands/patterns.md
    • Modified the description to include model routing as a function of the command.
    • Updated instructions to support report and recommend subcommands for /patterns.
    • Enhanced the 'no patterns recorded' message with a list of available commands.
  • .agents/scripts/commands/route.md
    • Updated the description to indicate that model routing now uses both rules and pattern history.
    • Modified instructions to first check pattern history for data-driven insights using pattern-tracker-helper.sh recommend.
    • Added a step to combine pattern history with routing rules, giving weight to pattern data when sufficient samples exist.
    • Updated the output format for recommendations to include 'Pattern data' details.
  • .agents/scripts/pattern-tracker-helper.sh
    • Added a new recommend command to suggest optimal model tiers based on historical success rates.
    • Implemented export command to allow exporting patterns in JSON or CSV format.
    • Introduced report command to generate a comprehensive summary report of pattern data.
    • Enhanced the record command with new options: --task-id, --duration, and --retries for capturing more detailed metadata.
    • Modified analyze and suggest commands to query across all relevant pattern types (SUCCESS_PATTERN, FAILURE_PATTERN, WORKING_SOLUTION, FAILED_APPROACH, ERROR_FIX) for complete coverage.
    • Updated the stats command to provide a more detailed breakdown, including counts for supervisor-generated patterns and statistics per model tier.
    • Added ensure_db and sql_escape helper functions for improved database interaction robustness.
    • Integrated _show_model_hint into the suggest command to provide model routing context.
  • .agents/scripts/supervisor-helper.sh
    • Updated store_failure_pattern to store patterns as FAILURE_PATTERN (previously FAILED_APPROACH/ERROR_FIX).
    • Enhanced store_failure_pattern to extract model tier from the task record and include it in the pattern's content and tags.
    • Updated store_success_pattern to store patterns as SUCCESS_PATTERN (previously WORKING_SOLUTION).
    • Enhanced store_success_pattern to extract model tier, calculate task duration, and retrieve retry count from the task record, including this metadata in the pattern's content and tags.
Activity
  • The pull request was created by marcusquinn.
  • No additional comments or reviews have been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Note

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

 ___________________________________________________________________________________________________________________________
< If programmers were electricians, parallel programmers would be bomb disposal experts. Both cut wires. - Bartosz Milewski >
 ---------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/t102.3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

1 similar comment
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Note

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

 ___________________________________________________________________________________________________________________________
< If programmers were electricians, parallel programmers would be bomb disposal experts. Both cut wires. - Bartosz Milewski >
 ---------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/t102.3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Walkthrough

This PR expands the pattern tracking system with SQL-backed analysis, new querying capabilities, and model-tier metadata enrichment. The pattern-tracker-helper script gains three new commands (recommend, export, report) and dynamic SQL filtering logic. Documentation updates reflect new pattern-aware routing flows. Pattern storage is enhanced with model tier, duration, and retry metadata across both supervisor and tracking helpers.

Changes

Cohort / File(s) Summary
Documentation Updates
.agents/scripts/commands/patterns.md, .agents/scripts/commands/route.md
Expanded routing documentation to incorporate pattern history usage. patterns.md now includes report and recommend flows with helper invocations. route.md reordered steps to prioritize pattern history checks and expanded evaluation criteria with success rates and conflict handling guidance.
Pattern Tracker Core Expansion
.agents/scripts/pattern-tracker-helper.sh
Major enhancement introducing SQL-backed pattern analysis, database utilities (ensure_db, sql_escape), and three new commands: recommend (model tier suggestions), export (JSON/CSV output), and report (comprehensive analytics). Enhanced suggest flow surfaces both success and failure patterns with model routing hints.
Pattern Storage Enrichment
.agents/scripts/supervisor-helper.sh
Updated pattern storage functions to capture model tier, duration, and retry metadata. Patterns now include enriched content/tags with [model:] and [duration:s] markers enabling downstream model-aware routing decisions.

Sequence Diagram(s)

sequenceDiagram
    participant Supervisor as Supervisor Helper
    participant PatternDB as Pattern Tracker DB
    participant Router as Route Command
    participant Recommender as Recommend Command

    rect rgba(100, 200, 100, 0.5)
    Note over Supervisor,PatternDB: Pattern Recording Flow
    Supervisor->>PatternDB: store_failure_pattern(task, model_tier, duration, retries)
    Supervisor->>PatternDB: store_success_pattern(task, model_tier, duration, retries)
    PatternDB->>PatternDB: Enrich with metadata tags
    end

    rect rgba(100, 150, 200, 0.5)
    Note over Router,PatternDB: Pattern-Based Routing Flow
    Router->>PatternDB: Query pattern history (WHERE clauses by task_type, model)
    PatternDB-->>Router: Return success/failure pattern data
    Router->>Router: Evaluate patterns vs routing rules
    Router->>Router: Resolve conflicts & compute confidence
    Router-->>Router: Recommend model tier
    end

    rect rgba(200, 150, 100, 0.5)
    Note over Recommender,PatternDB: Pattern Recommendation Flow
    Recommender->>PatternDB: analyze() with task-type filtering
    PatternDB-->>Recommender: Pattern analysis with success rates
    Recommender->>Recommender: Compute model tier recommendations
    Recommender-->>Recommender: Present recommendation with context notes
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • marcusquinn/aidevops#341: Directly modifies the same files (pattern-tracker-helper.sh, patterns.md, route.md, supervisor-helper.sh) to establish pattern tracking infrastructure with model-tier tagging and new tracking commands.
  • marcusquinn/aidevops#380: Modifies supervisor-helper.sh pattern storage functions (store_failure_pattern, store_success_pattern) to integrate memory recall and metadata enrichment logic.

Poem

📊 Patterns emerge from the code's whispered tale,
SQL queries now trace each model's trail,
With metadata crowned and recommendations bright,
The router learns wisdom from history's light! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding success pattern tracking with model routing integration, directly reflected in supervisor-helper.sh, pattern-tracker-helper.sh, and route.md updates.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/t102.3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

Copy link
Contributor

@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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.agents/scripts/pattern-tracker-helper.sh (1)

81-98: ⚠️ Potential issue | 🟡 Minor

Missing shift 2 guard — if a flag like --outcome is the last argument with no value, $2 is unset and shift 2 will fail under set -u.

With set -euo pipefail (line 18), accessing $2 when only one argument remains triggers an unbound variable error, and shift 2 will also fail. This applies to all flag-parsing case branches across cmd_record, cmd_analyze, cmd_recommend, and cmd_export.

This is an edge case (user error), but under set -u it produces a confusing "unbound variable" traceback rather than a helpful error message.

🛡️ Example guard pattern
--outcome)
    if [[ $# -lt 2 ]]; then
        log_error "--outcome requires a value"
        return 1
    fi
    outcome="$2"; shift 2 ;;
🤖 Fix all issues with AI agents
In @.agents/scripts/commands/patterns.md:
- Line 54: The "Available commands: suggest, recommend, analyze, stats, report,
export" list omits the `record` command shown in the example; update that
command list to include `record` so it matches the example usage (i.e., add
`record` to the string "Available commands: ...") and verify any surrounding
documentation references to the same command list (the example block
demonstrating `record`) are consistent.

In @.agents/scripts/commands/route.md:
- Around line 14-18: The documentation invokes recommend with free-form
"$ARGUMENTS" but cmd_recommend in pattern-tracker-helper.sh only filters by
--task-type (positional task_desc is only displayed), so update the call or
docs: either modify the script to extract a task type from ARGUMENTS before
calling recommend (e.g., derive and pass --task-type from ARGUMENTS) or change
the example invocation to pass an explicit task type variable instead of raw
free text; reference cmd_recommend, pattern-tracker-helper.sh, recommend,
ARGUMENTS, and task_desc when making the change and add a short clarifying
comment explaining whether global stats are acceptable or a task-type must be
provided.

In @.agents/scripts/pattern-tracker-helper.sh:
- Around line 29-34: Remove the duplicated comment immediately above the
PATTERN_TYPES declaration: keep a single descriptive comment that references
PATTERN_TYPES_SQL and PATTERN_TYPES, delete the redundant repeated line so the
block has only one comment followed by the
PATTERN_TYPES="'SUCCESS_PATTERN','FAILURE_PATTERN','WORKING_SOLUTION','FAILED_APPROACH','ERROR_FIX'"
and readonly PATTERN_TYPES; no other code changes are needed.
- Around line 396-411: The tie-breaker currently uses an always-true check ([[
"$total" -gt 0 ]]) so equal rates always pick the last model; update the logic
to prefer the model with the larger sample count by comparing total to a tracked
best_total (e.g., change the tie condition to [[ "$rate" -eq "$best_rate" ]] &&
[[ "$total" -gt "$best_total" ]]) and when you set best_rate and best_model also
set best_total=$total; also add initialization for best_rate (e.g., -1) and
best_total (0) before the loop that iterates model_tier so the comparisons work
correctly.
- Around line 531-536: The sqlite3 -json usage in the case block (where local
query=... and sqlite3 -json "$MEMORY_DB" "$query") is not safe on older SQLite
versions; add a compatibility check at script start or before this branch that
detects whether sqlite3 supports -json (e.g., parse sqlite3 --version or try a
small test query) and if not, run sqlite3 without -json and pipe output through
jq (or a small shell-to-JSON formatter) to produce the same JSON shape, and log
a clear warning when falling back; update the case branch to call a helper
function (e.g., ensure_sqlite_json or format_query_json) that encapsulates the
detection and fallback so the SELECT query variable and MEMORY_DB usage remain
unchanged while guaranteeing consistent JSON output and visible logs on
fallback.

In @.agents/scripts/supervisor-helper.sh:
- Around line 7707-7710: Remove the unused local variable duration_info from the
declaration to satisfy ShellCheck SC2034; update the local line in
.agents/scripts/supervisor-helper.sh (where task_model, duration_info, retries
are declared) to only declare the used variables (task_model and retries) and
then re-run ShellCheck to ensure no remaining violations.
🧹 Nitpick comments (5)
.agents/scripts/supervisor-helper.sh (1)

7652-7677: Consider adding duration/retry metadata to failure patterns for parity with success records.

Success patterns now carry duration/retries; failures only add model tier. If reports/recommendations expect those fields across outcomes, the missing data can skew comparisons. Suggest mirroring the duration/retry enrichment (or explicitly documenting the asymmetry).

.agents/scripts/pattern-tracker-helper.sh (4)

21-27: readonly SCRIPT_DIR declared after SCRIPT_DIR is already used on line 22.

SCRIPT_DIR is assigned on line 21 and immediately used on line 22 to source shared-constants.sh. The readonly on line 25 comes after the value has already been consumed. While this works, if shared-constants.sh or init_log_file (line 23) were to reassign SCRIPT_DIR, the readonly wouldn't protect against it. Consider combining assignment and readonly, or moving the readonly immediately after assignment on line 21.


60-66: sql_escape() does not escape LIKE wildcards % and _.

This function is used to build LIKE '%${escaped_value}%' clauses in cmd_analyze, cmd_recommend, cmd_report, and _show_model_hint. If a user-supplied value (e.g., task_type) contains % or _, the LIKE pattern will match unintended rows. The task-type validation is a soft warning (line 120), so arbitrary values flow through unchecked.

Risk is low in practice (inputs are typically alphanumeric slugs), but for a zero-technical-debt posture, consider escaping LIKE metacharacters or using exact-match (=) where appropriate.

🛡️ Proposed enhancement
 sql_escape() {
     local val="$1"
-    echo "${val//\'/\'\'}"
+    # Escape single quotes for SQL strings
+    val="${val//\'/\'\'}"
+    # Escape LIKE wildcards when used in LIKE patterns
+    val="${val//%/\\%}"
+    val="${val//_/\\_}"
+    echo "$val"
 }

Note: If you add this, the LIKE clauses would need ESCAPE '\' appended, e.g., LIKE '%value%' ESCAPE '\'. Alternatively, keep sql_escape focused on quotes and add a separate sql_escape_like().


186-186: ensure_db || return 0 silently succeeds when the DB is missing.

In cmd_analyze (line 186), cmd_stats (line 442), and cmd_report (line 554), a missing database causes the command to return 0 (success). This is a deliberate design choice for a graceful no-op, but in cmd_export (line 526) it returns 1 — the inconsistency could surprise callers.

If the intent is that analyze, stats, and report are informational (no DB = nothing to show), while export is a data pipeline command (no DB = error), the inconsistency is fine but worth a brief inline comment explaining the rationale for discoverability.


673-716: _show_model_hint largely duplicates the core logic of cmd_recommend.

Both iterate VALID_MODELS, query success/failure counts per tier, and pick the best model by rate. The only difference is _show_model_hint requires m_total > 2 and cmd_recommend requires m_total > 0. Consider extracting the shared query-and-rank logic into a helper to keep them in sync and reduce the maintenance surface.

--task-type bugfix --model sonnet \
--description "Structured debugging approach found root cause quickly"

Available commands: suggest, recommend, analyze, stats, report, export
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Command list may be incomplete.

The available commands list mentions suggest, recommend, analyze, stats, report, export, but the example above (lines 50-52) demonstrates the record command. Should record be included in the available commands list for completeness?

📝 Suggested fix to include record command
-Available commands: suggest, recommend, analyze, stats, report, export
+Available commands: record, suggest, recommend, analyze, stats, report, export
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Available commands: suggest, recommend, analyze, stats, report, export
Available commands: record, suggest, recommend, analyze, stats, report, export
🤖 Prompt for AI Agents
In @.agents/scripts/commands/patterns.md at line 54, The "Available commands:
suggest, recommend, analyze, stats, report, export" list omits the `record`
command shown in the example; update that command list to include `record` so it
matches the example usage (i.e., add `record` to the string "Available commands:
...") and verify any surrounding documentation references to the same command
list (the example block demonstrating `record`) are consistent.

Comment on lines +14 to +18
1. First, check pattern history for data-driven insights:

2. Analyze the task description against the routing rules:
```bash
~/.aidevops/agents/scripts/pattern-tracker-helper.sh recommend "$ARGUMENTS"
```
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

recommend is invoked with the raw task description, but the command only filters by --task-type, not free text.

cmd_recommend in pattern-tracker-helper.sh uses --task-type for SQL filtering. Positional arguments are stored in task_desc but are only displayed — they don't influence the query. So invoking recommend "$ARGUMENTS" (where $ARGUMENTS is a free-form task description like "refactor the auth middleware") will show unfiltered global model stats, not task-specific recommendations.

If the intent is task-type-specific routing, the agent would need to extract a task type from $ARGUMENTS first. If global stats are acceptable here, consider adding a comment clarifying that.

🤖 Prompt for AI Agents
In @.agents/scripts/commands/route.md around lines 14 - 18, The documentation
invokes recommend with free-form "$ARGUMENTS" but cmd_recommend in
pattern-tracker-helper.sh only filters by --task-type (positional task_desc is
only displayed), so update the call or docs: either modify the script to extract
a task type from ARGUMENTS before calling recommend (e.g., derive and pass
--task-type from ARGUMENTS) or change the example invocation to pass an explicit
task type variable instead of raw free text; reference cmd_recommend,
pattern-tracker-helper.sh, recommend, ARGUMENTS, and task_desc when making the
change and add a short clarifying comment explaining whether global stats are
acceptable or a task-type must be provided.

Comment on lines +29 to +34
# All pattern-related memory types (dedicated + supervisor-generated)
# All pattern-related memory types (dedicated + supervisor-generated)
# Use via: local types_sql="$PATTERN_TYPES_SQL" then sqlite3 ... "$types_sql" ...
# Or inline in single-line sqlite3 calls where variable expansion works correctly
PATTERN_TYPES="'SUCCESS_PATTERN','FAILURE_PATTERN','WORKING_SOLUTION','FAILED_APPROACH','ERROR_FIX'"
readonly PATTERN_TYPES
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Duplicate comment on lines 29–30.

Lines 29 and 30 are identical comments. One should be removed.

✂️ Proposed fix
-# All pattern-related memory types (dedicated + supervisor-generated)
 # All pattern-related memory types (dedicated + supervisor-generated)
 # Use via: local types_sql="$PATTERN_TYPES_SQL" then sqlite3 ... "$types_sql" ...
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# All pattern-related memory types (dedicated + supervisor-generated)
# All pattern-related memory types (dedicated + supervisor-generated)
# Use via: local types_sql="$PATTERN_TYPES_SQL" then sqlite3 ... "$types_sql" ...
# Or inline in single-line sqlite3 calls where variable expansion works correctly
PATTERN_TYPES="'SUCCESS_PATTERN','FAILURE_PATTERN','WORKING_SOLUTION','FAILED_APPROACH','ERROR_FIX'"
readonly PATTERN_TYPES
# All pattern-related memory types (dedicated + supervisor-generated)
# Use via: local types_sql="$PATTERN_TYPES_SQL" then sqlite3 ... "$types_sql" ...
# Or inline in single-line sqlite3 calls where variable expansion works correctly
PATTERN_TYPES="'SUCCESS_PATTERN','FAILURE_PATTERN','WORKING_SOLUTION','FAILED_APPROACH','ERROR_FIX'"
readonly PATTERN_TYPES
🤖 Prompt for AI Agents
In @.agents/scripts/pattern-tracker-helper.sh around lines 29 - 34, Remove the
duplicated comment immediately above the PATTERN_TYPES declaration: keep a
single descriptive comment that references PATTERN_TYPES_SQL and PATTERN_TYPES,
delete the redundant repeated line so the block has only one comment followed by
the
PATTERN_TYPES="'SUCCESS_PATTERN','FAILURE_PATTERN','WORKING_SOLUTION','FAILED_APPROACH','ERROR_FIX'"
and readonly PATTERN_TYPES; no other code changes are needed.

Comment on lines +396 to +411
local total=$((successes + failures))
if [[ "$total" -gt 0 ]]; then
has_data=true
local rate
rate=$(( (successes * 100) / total ))
printf " %-10s %8d %8d %9d%%\n" "$model_tier" "$successes" "$failures" "$rate"

# Track best model (prefer higher success rate, break ties with more data)
if [[ "$rate" -gt "$best_rate" ]] || { [[ "$rate" -eq "$best_rate" ]] && [[ "$total" -gt 0 ]]; }; then
best_rate=$rate
best_model=$model_tier
fi
else
echo " (no matching failure patterns)"
printf " %-10s %8s %8s %10s\n" "$model_tier" "-" "-" "no data"
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Tie-breaking logic in cmd_recommend is a no-op — always picks the last model at a given rate.

On line 404, the tie-breaker condition is [[ "$total" -gt 0 ]], but we're already inside the if [[ "$total" -gt 0 ]] block (line 397), so this is always true. The result: when two models have the same success rate, the one iterated last wins regardless of sample count. The comment on line 403 says "prefer … more data," but that's not what the code does.

🐛 Proposed fix — break ties by sample count
-            # Track best model (prefer higher success rate, break ties with more data)
-            if [[ "$rate" -gt "$best_rate" ]] || { [[ "$rate" -eq "$best_rate" ]] && [[ "$total" -gt 0 ]]; }; then
-                best_rate=$rate
-                best_model=$model_tier
+            # Track best model (prefer higher success rate, break ties with more data)
+            if [[ "$rate" -gt "$best_rate" ]] || { [[ "$rate" -eq "$best_rate" ]] && [[ "$total" -gt "$best_total" ]]; }; then
+                best_rate=$rate
+                best_model=$model_tier
+                best_total=$total
             fi

And initialize on line 387:

-    local best_model="" best_rate=0 has_data=false
+    local best_model="" best_rate=0 best_total=0 has_data=false
🤖 Prompt for AI Agents
In @.agents/scripts/pattern-tracker-helper.sh around lines 396 - 411, The
tie-breaker currently uses an always-true check ([[ "$total" -gt 0 ]]) so equal
rates always pick the last model; update the logic to prefer the model with the
larger sample count by comparing total to a tracked best_total (e.g., change the
tie condition to [[ "$rate" -eq "$best_rate" ]] && [[ "$total" -gt "$best_total"
]]) and when you set best_rate and best_model also set best_total=$total; also
add initialization for best_rate (e.g., -1) and best_total (0) before the loop
that iterates model_tier so the comparisons work correctly.

Comment on lines +531 to +536
case "$format" in
json)
# Use sqlite3 -json for proper JSON output
local query="SELECT l.id, l.type, l.content, l.tags, l.confidence, l.created_at, COALESCE(a.access_count, 0) as access_count FROM learnings l LEFT JOIN learning_access a ON l.id = a.id WHERE l.type IN ($types_sql) ORDER BY l.created_at DESC;"
sqlite3 -json "$MEMORY_DB" "$query" 2>/dev/null || echo "[]"
;;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

SQLite 3.33.0 -json flag introduction minimum version requirement

💡 Result:

The sqlite3 command-line shell’s -json flag (sets output mode to JSON) was introduced in SQLite 3.33.0 (released 2020-08-14). So the minimum required version is SQLite/sqlite3 3.33.0. [1] [2]

Note: This is a CLI (shell) feature, not a SQLite library/API requirement. [1]

Sources:
[1] (sqlite.org)
[2] (sqlite.org)

Citations:


🏁 Script executed:

# Check the script around the mentioned lines and full context
head -550 .agents/scripts/pattern-tracker-helper.sh | tail -50

Repository: marcusquinn/aidevops

Length of output: 2000


🏁 Script executed:

# Also get broader context about the function
grep -n "case.*format" .agents/scripts/pattern-tracker-helper.sh -A 30 | head -100

Repository: marcusquinn/aidevops

Length of output: 1497


🏁 Script executed:

# Check if there's any version checking in the script
grep -n "sqlite3.*version\|version.*sqlite\|3\.33\|SQLITE" .agents/scripts/pattern-tracker-helper.sh

Repository: marcusquinn/aidevops

Length of output: 46


🏁 Script executed:

# Check for other sqlite3 usage patterns in the script
grep -n "sqlite3" .agents/scripts/pattern-tracker-helper.sh

Repository: marcusquinn/aidevops

Length of output: 4318


🏁 Script executed:

# Look for any version check or compatibility handling in the script
grep -n "version\|compatibility\|check" .agents/scripts/pattern-tracker-helper.sh | head -20

Repository: marcusquinn/aidevops

Length of output: 429


Add version compatibility check for sqlite3 -json or implement jq-based fallback.

The -json flag requires SQLite ≥ 3.33.0 (released 2020-08-14). Systems running older versions (e.g., Ubuntu 18.04/20.04 stock packages) will fail silently, with the 2>/dev/null || echo "[]" fallback masking the error and producing an empty array indistinguishable from actual empty results. This violates the DevOps requirements for clear logging and reliability.

Implement either:

  1. A version check at script initialization that validates SQLite version and falls back to jq-based JSON conversion if -json is unavailable
  2. Use jq to manually format standard query output as JSON, ensuring compatibility across SQLite versions

This aligns with the broader error recovery and logging requirements for automation scripts.

🤖 Prompt for AI Agents
In @.agents/scripts/pattern-tracker-helper.sh around lines 531 - 536, The
sqlite3 -json usage in the case block (where local query=... and sqlite3 -json
"$MEMORY_DB" "$query") is not safe on older SQLite versions; add a compatibility
check at script start or before this branch that detects whether sqlite3
supports -json (e.g., parse sqlite3 --version or try a small test query) and if
not, run sqlite3 without -json and pipe output through jq (or a small
shell-to-JSON formatter) to produce the same JSON shape, and log a clear warning
when falling back; update the case branch to call a helper function (e.g.,
ensure_sqlite_json or format_query_json) that encapsulates the detection and
fallback so the SELECT query variable and MEMORY_DB usage remain unchanged while
guaranteeing consistent JSON output and visible logs on fallback.

Comment on lines +7707 to +7710
local task_model duration_info retries
task_model=$(db "$SUPERVISOR_DB" "SELECT model FROM tasks WHERE id = '$escaped_id';" 2>/dev/null || echo "")
retries=$(db "$SUPERVISOR_DB" "SELECT retries FROM tasks WHERE id = '$escaped_id';" 2>/dev/null || echo "0")

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove unused duration_info to keep ShellCheck clean.

duration_info is declared but never used, which will trigger ShellCheck (SC2034) in this script.

🧹 Proposed fix
-    local task_model duration_info retries
+    local task_model retries

As per coding guidelines, "Run ShellCheck with zero violations on all scripts in .agents/scripts/".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
local task_model duration_info retries
task_model=$(db "$SUPERVISOR_DB" "SELECT model FROM tasks WHERE id = '$escaped_id';" 2>/dev/null || echo "")
retries=$(db "$SUPERVISOR_DB" "SELECT retries FROM tasks WHERE id = '$escaped_id';" 2>/dev/null || echo "0")
local task_model retries
task_model=$(db "$SUPERVISOR_DB" "SELECT model FROM tasks WHERE id = '$escaped_id';" 2>/dev/null || echo "")
retries=$(db "$SUPERVISOR_DB" "SELECT retries FROM tasks WHERE id = '$escaped_id';" 2>/dev/null || echo "0")
🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 7707 - 7710, Remove the
unused local variable duration_info from the declaration to satisfy ShellCheck
SC2034; update the local line in .agents/scripts/supervisor-helper.sh (where
task_model, duration_info, retries are declared) to only declare the used
variables (task_model and retries) and then re-run ShellCheck to ensure no
remaining violations.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 54 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Mon Feb 9 16:30:15 UTC 2026: Code review monitoring started
Mon Feb 9 16:30:16 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 54

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 54
  • VULNERABILITIES: 0

Generated on: Mon Feb 9 16:30:18 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@marcusquinn marcusquinn merged commit a1a4eb4 into main Feb 9, 2026
1 check was pending
@marcusquinn marcusquinn deleted the feature/t102.3 branch February 9, 2026 16:32
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