Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,21 @@ search.search("kubectl", current_repo="infra")
├── read other repo files
│
▼
Filter: substring match "kubectl" in command text
Prefilter: needle test on the raw line's command span (skips json.loads)
│
▼
Score each match:
score = (frequency × 0.4) + (recency × 0.4) + (context × 0.2)
Filter: every query term must appear in the command text
│ (if nothing matches, expand through the concept map and retry)
▼
Score each match (mem/ranking.py — stdlib only, shared with the finder):
score = (picks × 0.40) + (frequency × 0.21) + (recency × 0.21)
+ (prefix × 0.09) + (context × 0.09)
│
├── frequency: count of identical commands
├── recency: exp(-days × ln2/7), half-life 7 days
└── context: 1.0 same repo, 0.5 same prefix, 0.0 other
├── picks: 1 - 2^-w over the finder's decayed selections, 21d half-life
├── frequency: log1p(n)/log1p(50), capped at 1
├── recency: exp(-days × ln2/7), half-life 7 days
├── prefix: 1.0 if the command starts with the query
└── context: 1.0 same repo, 0.5 sibling, 0.0 other
│
▼
Deduplicate by command string (keep highest score)
Expand Down Expand Up @@ -423,3 +429,10 @@ See `docs/decisions/` for detailed ADRs:
- [002: Apple FM SDK for Patterns](docs/decisions/002-apple-fm-sdk-for-patterns.md)
- [003: No Daemon, Background Subprocess Instead](docs/decisions/003-no-daemon.md)
- [004: Per-Repository JSONL Files](docs/decisions/004-per-repo-jsonl.md)
- [005: A Derived Index, With the JSONL as the Source of Truth](docs/decisions/005-derived-index-jsonl-source-of-truth.md)
- [006: App Intents, Shortcuts and Spotlight — Evaluated and Deferred](docs/decisions/006-app-intents-shortcuts-spotlight-deferred.md)
- [007: MCP Over Stdio, Never HTTP](docs/decisions/007-mcp-over-stdio-never-http.md)
- [008: The Interactive TUI Is Built on the Standard Library](docs/decisions/008-stdlib-tui.md)
- [009: Ranking Learns From What You Select](docs/decisions/009-ranking-learns-from-selections.md)
- [010: The Keychain for Variable Values](docs/decisions/010-keychain-for-variable-values.md)
- [011: A Concept Map, Not Embeddings](docs/decisions/011-concept-map-over-embeddings.md)
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,24 @@ You type a command
**Search scoring:**

```
score = (frequency × 0.4) + (recency × 0.4) + (context × 0.2)
score = (picks × 0.40) + (frequency × 0.21) + (recency × 0.21)
+ (prefix × 0.09) + (context × 0.09)
```

- **Frequency** — how often you've run this command
- **Picks** — how often you chose this command in the finder, halving every
21 days. Weighted highest because it is the only signal that is not an
inference: it is you having already answered the question. Zero until you
use `Ctrl+R`, and with none recorded the ordering is exactly what the other
four produce on their own.
- **Frequency** — how often you ran it: `log1p(n)/log1p(50)`, capped, so the
jump from 1 to 5 counts and one repeated command cannot own every result
- **Recency** — exponential decay, 7-day half-life
- **Context** — 1.0 same repo, 0.5 same directory prefix, 0.0 otherwise
- **Prefix** — the command *starts with* your query, not merely contains it
- **Context** — 1.0 same repo, 0.5 sibling directory, 0.0 otherwise

Every feature is normalised to [0, 1] and the weights sum to 1, so a score
reads as a fraction. If nothing matches literally, the
[concept map](#search) expands the query — and only then.

**AI features** use [Apple Foundation Models](https://developer.apple.com/machine-learning/api/) running entirely on your Mac's neural engine. No API keys, no cloud, no data leaves the machine. If Apple Intelligence isn't available, everything still works — you just don't get pattern extraction or credential detection.

Expand All @@ -591,7 +603,7 @@ beside them, is rebuilt from them, and is safe to delete:
myapp.json # repo-scoped groups and saved commands
_global.json # global groups and saved commands
concepts.json # your concept map, layered over the shipped one
vars.json # persistent variable store (0600 permissions)
vars.json # which variables exist (values are in the Keychain)
agent.json # AI agent access flag (off unless you enabled it)
agent-audit.jsonl # append-only record of every agent request
```
Expand Down Expand Up @@ -627,7 +639,10 @@ Data rotation happens automatically in the background:
- Zero telemetry — no analytics, no crash reports
- Zero cloud dependencies — fully offline, always
- On-device AI only — runs on your Mac's neural engine
- Plain text storage — no proprietary formats, you own your data
- Plain text storage — no proprietary formats, you own your data. The one
deliberate exception is variable *values*, which live in the macOS
Keychain: "readable with `cat`" is the wrong property for a password
([ADR-010](docs/decisions/010-keychain-for-variable-values.md))
- Agent access off by default — opt-in, redacted and audited ([MCP](#ai-agents-mcp))

Read more in [PHILOSOPHY.md](PHILOSOPHY.md).
Expand Down
76 changes: 76 additions & 0 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,79 @@ def test_version_returns_quickly(self, home: Path, workdir: Path) -> None:
assert "mem" in result.stdout

assert min(durations) < 0.5, f"mem --version took {min(durations):.3f}s"


class TestDocumentationDoesNotDrift:
"""Docs that state a formula the code no longer uses are worse than none.

Both `README.md` and `ARCHITECTURE.md` published
`score = frequency*0.4 + recency*0.4 + context*0.2` for two releases after
that formula stopped existing — through the fix that normalised it and the
feature that added two more terms. Nothing detects prose going stale, so
the checks that can be mechanical are made mechanical.
"""

DOCS = ["README.md", "ARCHITECTURE.md", "PHILOSOPHY.md", "CHANGELOG.md"]

def test_every_adr_is_listed(self) -> None:
"""A decision nobody can find from the index may as well not exist."""
index = (REPO_ROOT / "ARCHITECTURE.md").read_text(encoding="utf-8")
missing = [
path.name
for path in sorted((REPO_ROOT / "docs" / "decisions").glob("*.md"))
if path.name not in index
Comment on lines +621 to +623

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict the ADR check to decision-index links

Checking whether the filename occurs anywhere in ARCHITECTURE.md does not prove that it is linked from the decision index. This already produces a false negative for ADR-010: its filename also appears in the variable-store section, so removing its new index entry would still leave this test green. Parse the decision-index links, or at least require the filename in that section's Markdown link targets.

Useful? React with 👍 / 👎.

]

assert not missing, f"ADRs not linked from ARCHITECTURE.md: {missing}"

def test_no_link_to_a_decision_record_is_broken(self) -> None:
import re

broken: list[tuple[str, str]] = []
for name in self.DOCS:
text = (REPO_ROOT / name).read_text(encoding="utf-8")
for match in re.finditer(r"\]\((docs/decisions/[^)]+)\)", text):
if not (REPO_ROOT / match.group(1)).exists():
broken.append((name, match.group(1)))

assert not broken, f"broken ADR links: {broken}"

def test_the_published_scoring_formula_names_every_feature(self) -> None:
"""The docs must not describe a ranking that stopped existing.

Checked against `mem.ranking`'s own weight constants rather than a
hard-coded list, so adding a sixth feature fails here until it is
written down.
"""
from mem import ranking

features = [
name[2:].lower()
for name in dir(ranking)
if name.startswith("W_") and isinstance(getattr(ranking, name), float)
]
assert features, "no weight constants found — did they get renamed?"

for name in ("README.md", "ARCHITECTURE.md"):
formula = self._formula_in(REPO_ROOT / name)
unmentioned = [f for f in features if f not in formula]
Comment on lines +657 to +658

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify formula coefficients, not only feature names

When a later ranking change alters a weight without renaming its W_* constant, this check still passes as long as the feature name remains in the formula; for example, changing W_PICKS from 0.40 to 0.30 would leave both documents publishing the obsolete coefficient. Since this test is intended to prevent the published formula from diverging from the code, it also needs to compare the documented numeric weights with the constants.

Useful? React with 👍 / 👎.

assert not unmentioned, (
f"{name} publishes a formula missing {unmentioned}; "
f"it is describing a ranking the code does not use:\n{formula}"
)

@staticmethod
def _formula_in(path: Path) -> str:
"""The formula itself, not the prose around it.

Bounded at the first blank line after `score =`. An earlier version
took a fixed 400-character window, which reached far enough to include
the bullet list underneath — so the check passed against a formula
with a term deleted, because the term was still named in the prose.
Verified by deleting one.
"""
text = path.read_text(encoding="utf-8").lower()
start = text.find("score =")
assert start != -1, f"{path.name} no longer shows the scoring formula"
end = text.find("\n\n", start)
return text[start : end if end != -1 else len(text)]