Skip to content

memory write: --update can't find notes; --category ignored and type dir mis-pluralized #1

Description

@JaySmith

Summary

cortex memory write computes the note file path from --type alone (naive type + "s"), so:

  1. It ignores --category entirely when building the target directory.
  2. Naive pluralization produces wrong dir names (entity -> entitys, knowledge -> knowledges).
  3. --update therefore cannot find existing notes created by the encoder/import, which live under <type-plural>/<category>/<id>.md (e.g. entities/systems/, knowledge/api/).

Net effect: --update fails with "Note does not exist" for notes that clearly exist (cortex memory get <id> returns them), and fresh writes land in a flat, wrong directory (I found a stranded knowledges/cortex-lint-fix-...md from an earlier write).

Repro

# Note exists and is readable:
cortex memory get jira            # works -> entities/systems/jira.md

# But update fails:
cortex memory write --update --title "jira" --type entity --category systems \
  --tier skill:jira --body-file ./x.md --no-encode
# -> "Note does not exist at <vault>/entitys/jira.md"
#    (wrong: naive plural 'entitys', and category 'systems' dropped)

Same for --type knowledge --category api -> looks in knowledges/ instead of knowledge/api/.

Root cause

cortex/cli/main.py:1133-1137:

type_dir_name = note_type + ("s" if not note_type.endswith("s") else "")
target_dir = vault_path / type_dir_name          # <-- --category never used
target_dir.mkdir(parents=True, exist_ok=True)
note_path = target_dir / f"{note_id}.md"
  • entity + "s" -> entitys (should be entities).
  • --category is accepted as an option but never contributes to the path.

Suggested fix

The encoder already solves this correctly for the update case — cortex/encoder/core.py:897-901 does a recursive lookup by id before falling back to a type dir:

for md in vault_root.rglob("*.md"):
    meta, _ = parse_frontmatter(md.read_text(...))
    if meta.get("id") == note_id:
        local_path = md
        break

memory write should do the same:

  1. On --update: locate the existing note by id via rglob (matching the encoder), regardless of directory, instead of reconstructing the path from --type.
  2. On create: build the path as <type-plural>/<category>/<id>.md using --category, and use a correct pluralization map (entity -> entities, knowledge -> knowledge/knowledges per convention) rather than blind + "s".

Workaround

Edit the note files directly in the vault (preserve frontmatter, bump updated), then run cortex encode.

Environment

  • cortex-ai 2.0.0 (uv tool install from ~/Projects/Cortex-AI)
  • macOS (darwin), Python 3.12

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