Skip to content

History parsing: comments and flags incorrectly learned as commandsΒ #91

@noahgift

Description

@noahgift

Bug Description

The analyze command shows that comments (#) and flags (--context) are being parsed as top commands:

πŸ” Top 10 Base Commands:
   ─────────────────────────────────────────
   git           1411 (  6.7%) β–ˆβ–ˆβ–ˆ
   aws           1288 (  6.1%) β–ˆβ–ˆβ–ˆ
   #             1170 (  5.6%) β–ˆβ–ˆ        <-- Comments!
   --context     1144 (  5.4%) β–ˆβ–ˆ        <-- Flags!
   touch         1094 (  5.2%) β–ˆβ–ˆ

Impact

  1. Model wastes capacity learning comment lines
  2. Model learns flag patterns without their commands
  3. Suggestions may include fragments like --context alone

Root Cause

History parsing splits on whitespace and treats first token as command, but doesn't filter:

  • Lines starting with # (comments)
  • Multiline commands where continuation has flags first
  • Malformed history entries

Expected Behavior

πŸ” Top 10 Base Commands:
   ─────────────────────────────────────────
   git           1411 (  6.7%) β–ˆβ–ˆβ–ˆ
   aws           1288 (  6.1%) β–ˆβ–ˆβ–ˆ
   touch         1094 (  5.2%) β–ˆβ–ˆ
   cargo          709 (  3.4%) β–ˆ
   ...

Suggested Fixes

1. Filter comments during training

fn parse_command(line: &str) -> Option<&str> {
    let trimmed = line.trim();
    if trimmed.is_empty() || trimmed.starts_with('#') {
        return None;
    }
    // ...
}

2. Skip lines starting with flags

fn is_valid_command_start(first_token: &str) -> bool {
    !first_token.starts_with('-') && 
    !first_token.starts_with('#') &&
    !first_token.is_empty()
}

3. Handle multiline commands

ZSH history may contain multiline commands with \ continuations. These should be joined before parsing.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions