Skip to content

fix(memory): reject unknown CLI flags in memory save #45

@frits-v

Description

@frits-v

Summary

memory save silently accepts unknown flags (e.g. --kind, --body) and misroutes their values into positional arguments, causing data corruption in the database.

Reproduction

memory save --project muzzle --kind learning --topic "My Topic" --body "actual content"

Expected: error like unknown flag: --kind
Actual: silently saves with title=muzzle, content=learning (garbage)

Root cause

find_positional() in memory/src/main.rs:305 only recognizes flags in VALUE_FLAGS (-p, --type, --topic, --source). Unknown --flags are treated as boolean flags — skipped themselves but their following value becomes a positional arg.

if arg.starts_with('-') {
    if VALUE_FLAGS.contains(&arg.as_str()) {
        skip_next = true; // skip this flag's value
    }
    continue; // ← unknown flags silently skipped, value becomes positional
}

Proposed fix

Reject unknown flags early in cmd_save (and other subcommands):

for arg in args {
    if arg.starts_with('-') && !VALUE_FLAGS.contains(&arg.as_str()) {
        return Err(format!("unknown flag: {arg}"));
    }
}

Alternatively, validate at the find_positional level so all subcommands benefit.

Impact

Observed in production: observation #161 was saved with title=muzzle, content=learning instead of the intended 40-line H-4 origin story. Had to manually delete and re-save.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions