Skip to content

feat(#349): memory type formalization + pattern-based auto-inference - #386

Merged
ajianaz merged 9 commits into
developfrom
feat/349-memory-types
Jun 19, 2026
Merged

ajianaz merged 9 commits into
developfrom
feat/349-memory-types

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Closes #349. See CHANGELOG entry for full details.

Summary

Tests

cargo test --workspace (221 passed, 0 failed), clippy clean, fmt clean.

Expand MemoryType enum from 5 to 9 variants (add Note, Insight, Reference,
Event) and add zero-LLM pattern-based inference on every remember().

Core (uteke-core):
  - MemoryType enum: +Note, +Insight, +Reference, +Event variants
  - MemoryType::infer_from_content(): URL prefix → Reference;
    decided/chose/will use → Decision; realized/learned/discovered → Insight;
    how-to/numbered list → Procedure; always/never/prefer/hate → Preference;
    ISO date + time word → Event; fallback → Note
  - MemoryType::recall_boost(): per-type additive score boost
    (Decision/Preference +0.05, Insight +0.03, Event +0.02, Note -0.02)
  - remember_typed() now runs inference when caller passes the default
    'fact'. If inference yields Note (ambiguous), keeps Fact for backward
    compatibility. Explicit types are honored as-is.
  - Helper functions: contains_any, is_numbered_list, has_iso_date

CLI (uteke-cli):
  - --type help text documents the full taxonomy + auto-inference

Tests (+13 new, 208 → 221 core tests):
  - enum roundtrip + case-insensitive parsing
  - per-pattern inference tests (reference, decision, insight, procedure,
    preference, event, fallback note)
  - recall_boost sign checks
  - has_temporal_validity for new variants
  - has_iso_date + is_numbered_list helpers

Closes #349
@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/uteke-core/src/memory/types.rs:357 — has_iso_date scans every 10-byte window and returns true for any YYYY-MM-DD substring without checking token boundaries. The added tests already show this with assert!(!has_iso_date("abc2026-00-00xyz")), but a valid embedded date like foo2026-12-31bar would still be accepted. Because infer_from_content uses this helper to classify content as Event, arbitrary identifiers or concatenated text containing a date-shaped substring can be misclassified.

Review powered by cora-cli · BYOK · MIT

CodeCora #386 flagged two issues:

1. infer_from_content() used lower.starts_with() on the original content
   for 'ref:' / 'see:' / 'docs:' detection, while the comment said these
   are line-start signals. Leading whitespace (e.g. '  ref: ...') would
   miss the Reference classification. Fixed: use first_line.to_lowercase()
   for line-start signals.

2. Test hardcoded http://example.com — replaced with https:// and added
   a regression test for the whitespace case.
CodeCora #386: remember_typed reclassified explicit 'fact' values via
auto-inference, breaking the API contract — callers passing 'fact'
explicitly could get 'Preference' back.

Fix:
  - remember_typed() now honors the caller-chosen type as-is, no override
  - remember_auto_infer() is the new inference path; explicit_type=None
    triggers pattern-based inference, Some(t) bypasses it
  - remember() default path uses remember_auto_infer(None) so content
    signals drive the type
  - Shared embed-then-store logic extracted into private remember_embed()

Backward compat preserved: ambiguous content still falls back to 'fact'.
CodeCora #386 round 2 found two bugs in infer_from_content:

1. URL detection used first_line.starts_with("http://") on the original
   (case-sensitive) string. 'HTTPS://example.com' was NOT detected as
   Reference. Fix: use first_lower for all prefix checks.

2. is_numbered_list used strip_prefix(single_digit) which only stripped
   ONE leading digit. '10. item' → strip '1' → rest='0. item' → no
   separator match. Fix: take_while(all_digits) then check separator.

Added regression tests for both cases.
CodeCora #386 r2: remember_auto_infer(Some(t)) forwarded the type string
directly to remember_embed without validation, bypassing the unknown-type
check that remember_typed performs. An invalid type like 'bogus' would
silently be stored.

Fix: run the same MemoryType::from_str_opt validation before using the
explicit type string.
CodeCora #386 r3: when num_str.parse::<u32>() failed (e.g. overflow from
'9999999999999999999999999. x'), the code fell through via 'continue'
without resetting consecutive/expected. A large-number line between
valid numbered lines would not break the sequence.

Fix: on parse failure or out-of-order number, reset consecutive=0 and
expected=1.
CodeCora #386 r4: is_iso_date_bytes only checked the digit/dash pattern,
accepting impossible dates like 2026-99-99 or 2026-13-40 as valid Event
triggers.

Fix: parse month and day from the digit bytes and validate month is
1-12 and day is 1-31. Added regression tests for invalid dates.
Clippy CI failed: month/day range checks used manual >= && <= instead
of RangeInclusive::contains.
CodeCora #386 r5: is_iso_date_bytes validated month 1-12 and day 1-31
globally, accepting impossible dates like 2026-02-31 or 2026-04-31.

Fix: lookup max_day per month (31 for Jan/Mar/May/Jul/Aug/Oct/Dec,
30 for Apr/Jun/Sep/Nov, 29 for Feb to accept leap day). Not a full
calendar implementation but eliminates the most obvious false positives.

Added tests for per-month invalid dates.
// non-empty line. Use first_line (not lower) so leading whitespace
// doesn't matter.
let first_lower = first_line.to_ascii_lowercase();
if first_lower.starts_with("http://")
@ajianaz
ajianaz merged commit d0cb534 into develop Jun 19, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the feat/349-memory-types branch July 9, 2026 14:28
ajianaz added a commit that referenced this pull request Aug 13, 2026
…386)

* feat(#349): memory type formalization + pattern-based auto-inference

Expand MemoryType enum from 5 to 9 variants (add Note, Insight, Reference,
Event) and add zero-LLM pattern-based inference on every remember().

Core (uteke-core):
  - MemoryType enum: +Note, +Insight, +Reference, +Event variants
  - MemoryType::infer_from_content(): URL prefix → Reference;
    decided/chose/will use → Decision; realized/learned/discovered → Insight;
    how-to/numbered list → Procedure; always/never/prefer/hate → Preference;
    ISO date + time word → Event; fallback → Note
  - MemoryType::recall_boost(): per-type additive score boost
    (Decision/Preference +0.05, Insight +0.03, Event +0.02, Note -0.02)
  - remember_typed() now runs inference when caller passes the default
    'fact'. If inference yields Note (ambiguous), keeps Fact for backward
    compatibility. Explicit types are honored as-is.
  - Helper functions: contains_any, is_numbered_list, has_iso_date

CLI (uteke-cli):
  - --type help text documents the full taxonomy + auto-inference

Tests (+13 new, 208 → 221 core tests):
  - enum roundtrip + case-insensitive parsing
  - per-pattern inference tests (reference, decision, insight, procedure,
    preference, event, fallback note)
  - recall_boost sign checks
  - has_temporal_validity for new variants
  - has_iso_date + is_numbered_list helpers

Closes #349

* fix(#349): reference detection with whitespace + drop http:// URL

CodeCora #386 flagged two issues:

1. infer_from_content() used lower.starts_with() on the original content
   for 'ref:' / 'see:' / 'docs:' detection, while the comment said these
   are line-start signals. Leading whitespace (e.g. '  ref: ...') would
   miss the Reference classification. Fixed: use first_line.to_lowercase()
   for line-start signals.

2. Test hardcoded http://example.com — replaced with https:// and added
   a regression test for the whitespace case.

* fix(#349): split remember_typed (explicit) and remember_auto_infer

CodeCora #386: remember_typed reclassified explicit 'fact' values via
auto-inference, breaking the API contract — callers passing 'fact'
explicitly could get 'Preference' back.

Fix:
  - remember_typed() now honors the caller-chosen type as-is, no override
  - remember_auto_infer() is the new inference path; explicit_type=None
    triggers pattern-based inference, Some(t) bypasses it
  - remember() default path uses remember_auto_infer(None) so content
    signals drive the type
  - Shared embed-then-store logic extracted into private remember_embed()

Backward compat preserved: ambiguous content still falls back to 'fact'.

* fix(#349): uppercase URL schemes + multi-digit numbered lists

CodeCora #386 round 2 found two bugs in infer_from_content:

1. URL detection used first_line.starts_with("http://") on the original
   (case-sensitive) string. 'HTTPS://example.com' was NOT detected as
   Reference. Fix: use first_lower for all prefix checks.

2. is_numbered_list used strip_prefix(single_digit) which only stripped
   ONE leading digit. '10. item' → strip '1' → rest='0. item' → no
   separator match. Fix: take_while(all_digits) then check separator.

Added regression tests for both cases.

* fix(#349): validate explicit_type in remember_auto_infer

CodeCora #386 r2: remember_auto_infer(Some(t)) forwarded the type string
directly to remember_embed without validation, bypassing the unknown-type
check that remember_typed performs. An invalid type like 'bogus' would
silently be stored.

Fix: run the same MemoryType::from_str_opt validation before using the
explicit type string.

* fix(#349): reset counter on parse failure in is_numbered_list

CodeCora #386 r3: when num_str.parse::<u32>() failed (e.g. overflow from
'9999999999999999999999999. x'), the code fell through via 'continue'
without resetting consecutive/expected. A large-number line between
valid numbered lines would not break the sequence.

Fix: on parse failure or out-of-order number, reset consecutive=0 and
expected=1.

* fix(#349): validate month/day ranges in ISO date detection

CodeCora #386 r4: is_iso_date_bytes only checked the digit/dash pattern,
accepting impossible dates like 2026-99-99 or 2026-13-40 as valid Event
triggers.

Fix: parse month and day from the digit bytes and validate month is
1-12 and day is 1-31. Added regression tests for invalid dates.

* fix(#349): clippy manual_range_contains in is_iso_date_bytes

Clippy CI failed: month/day range checks used manual >= && <= instead
of RangeInclusive::contains.

* fix(#349): per-month day validation in ISO date detection

CodeCora #386 r5: is_iso_date_bytes validated month 1-12 and day 1-31
globally, accepting impossible dates like 2026-02-31 or 2026-04-31.

Fix: lookup max_day per month (31 for Jan/Mar/May/Jul/Aug/Oct/Dec,
30 for Apr/Jun/Sep/Nov, 29 for Feb to accept leap day). Not a full
calendar implementation but eliminates the most obvious false positives.

Added tests for per-month invalid dates.
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.

feat: memory type formalization — typed memory categories with auto-inference

2 participants