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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- Phrases with "jump to" (like "go to") and filler words such as
"including" and "ones" now find their command: "jump to my home
directory" gives `cd ~`, and "i want to see the files including hidden
ones" gives `ls -la` instead of a `du` example.
ones" gives `ls -la`. Neither had an answer before. "show all files
including hidden ones" now gives `ls -la` instead of a `du` example.
- The match evaluation has 20 more real-world phrasings. Thanks to
@cisheengai.

Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ fish tests/test_fish_bind.fish # the fish Ctrl+G binding
`python tests/match_eval.py` scores matching on ~420 real phrasings (right,
wrong, missed); `tests/test_match_eval.py` fails if it gets worse. Add
phrasings to `tests/match_eval.json` when you add phrases or synonyms.
`--held-out` scores `tests/match_heldout.json`, which is never tuned against.
- **Plain mode:** never print symbols directly; use `$ICON_TIP`,
`$ICON_WARN`, `$ICON_OK`, `$ICON_NOTE`, `$ICON_FAIL`, `$ICON_BULLET`,
`$ICON_CHEER` (set in `set_symbols`).
Expand Down
13 changes: 10 additions & 3 deletions tests/match_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
have said nothing). The number that matters most.
- missed: nothing, when there was a right answer. Annoying, not harmful.

tests/match_heldout.json is a second set that is never tuned against, for an
honest score: run `python tests/match_eval.py --held-out`, and don't add
synonyms or phrases to fix what it shows. Once it has been tuned against,
move its phrases to match_eval.json and write a new set before scoring.

Run `python tests/match_eval.py` for the full report;
tests/test_match_eval.py keeps the numbers from getting worse.
"""
Expand All @@ -26,10 +31,11 @@
from clishe_brain import ClisheBrain # noqa: E402

CASES_FILE = Path(__file__).resolve().parent / "match_eval.json"
HELDOUT_FILE = CASES_FILE.with_name("match_heldout.json")


def load_cases():
return json.loads(CASES_FILE.read_text(encoding="utf-8"))
def load_cases(path=CASES_FILE):
return json.loads(path.read_text(encoding="utf-8"))


def fake_linux_machine():
Expand Down Expand Up @@ -83,7 +89,8 @@ def evaluate(cases=None):


def main():
counts, rows = evaluate()
held_out = "--held-out" in sys.argv[1:]
counts, rows = evaluate(load_cases(HELDOUT_FILE) if held_out else None)
total = len(rows)
for verdict in ("wrong", "missed"):
picked = [r for r in rows if r[3] == verdict]
Expand Down
67 changes: 67 additions & 0 deletions tests/match_heldout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{"say": "am i running out of room on this laptop", "want": ["df -h"]},
{"say": "my hard disk is almost full how do i check", "want": ["df -h"]},
{"say": "which of these folders is the heaviest", "want": ["du -sh * | sort -h", "du -sh * | sort -rh | head -n 10"]},
{"say": "how many gigs is my downloads folder", "want": ["du -sh <folder>"]},
{"say": "track down huge files", "want": ["find . -type f -size +100M"]},
{"say": "what have i got in this directory", "want": ["ls -la", "ls"]},
{"say": "reveal dotfiles", "want": ["ls -la", "ls -a"]},
{"say": "where exactly am i right now", "want": ["pwd"]},
{"say": "move up one level", "want": ["cd .."]},
{"say": "return to the directory i was in before", "want": ["cd -"]},
{"say": "take me home", "want": ["cd ~", "cd"]},
{"say": "make me a directory called photos", "want": ["mkdir -p <folder name>"]},
{"say": "get rid of this file", "want": ["rm <file>"]},
{"say": "i want to trash a folder", "want": ["rm -r <folder>"]},
{"say": "duplicate this file somewhere else", "want": ["cp <file> <destination>"]},
{"say": "call this file something else", "want": ["mv <old name> <new name>"]},
{"say": "put this file in another folder", "want": ["mv <file> <destination>"]},
{"say": "let me look at what is written in notes.txt", "want": ["cat <file>", "less <file>"]},
{"say": "first few rows of a csv", "want": ["head -n 20 <file>"]},
{"say": "tail end of the log file", "want": ["tail -n 20 <file>", "tail -f <file>"]},
{"say": "keep an eye on a log as it grows", "want": ["tail -f <file>"]},
{"say": "number of lines in my script", "want": ["wc -l <file>"]},
{"say": "are these two files the same", "want": ["diff <first file> <second file>"]},
{"say": "hunt for a word across every file here", "want": ["grep -rn <text> ."]},
{"say": "i lost a file and dont know where it is", "want": ["find . -iname <file name>"]},
{"say": "put lines in alphabetical order", "want": ["sort <file>"]},
{"say": "drop the repeated rows from a file", "want": ["sort -u <file>"]},
{"say": "squash this folder into a tar.gz", "want": ["tar -czvf <archive name>.tar.gz <folder>"]},
{"say": "open up a .zip i downloaded", "want": ["unzip <file>"]},
{"say": "bundle a folder as a zip", "want": ["zip -r <archive name>.zip <folder>"]},
{"say": "whats hogging the processor", "want": ["top"]},
{"say": "why is everything lagging", "want": ["top"]},
{"say": "how much ram am i using", "want": ["free -h"]},
{"say": "everything running at the moment", "want": ["ps aux"]},
{"say": "force a frozen program to close", "want": ["kill <process id>", "pkill <program name>"]},
{"say": "how many cores does this machine have", "want": ["nproc"]},
{"say": "which graphics card is in here", "want": ["lspci | grep -iE 'vga|3d|display'"]},
{"say": "what usb gadgets are plugged in", "want": ["lsusb"]},
{"say": "which version of linux is this", "want": ["cat /etc/os-release"]},
{"say": "when did i last reboot", "want": ["uptime", "uptime -s", "last reboot"]},
{"say": "who else is on this machine", "want": ["who"]},
{"say": "whats todays date", "want": ["date"]},
{"say": "tidy up my screen", "want": ["clear"]},
{"say": "let me run this script", "want": ["chmod +x <file>"]},
{"say": "give the file to another user", "want": ["sudo chown <user> <file>"]},
{"say": "grab a file off the web", "want": ["wget <url>"]},
{"say": "is my wifi actually working", "want": ["ping -c 4 google.com"]},
{"say": "what address do websites see me as", "want": ["curl -s ifconfig.me"]},
{"say": "which ports are listening on my computer", "want": ["ss -tuln"]},
{"say": "is that site down", "want": ["curl -sI <url>"]},
{"say": "where does git live on my system", "want": ["command -v <program name>"]},
{"say": "what have i modified since the last commit", "want": ["git diff", "git status"]},
{"say": "start a fresh branch", "want": ["git switch -c <branch>"]},
{"say": "take back the commit i just made", "want": ["git reset --soft HEAD~1"]},
{"say": "park my changes for a bit", "want": ["git stash push -m <message>"]},
{"say": "bring my stash back", "want": ["git stash pop"]},
{"say": "which python do i have", "want": ["python3 --version", "which python3"]},
{"say": "set up a venv", "want": ["python3 -m venv .venv"]},
{"say": "sing me a song", "want": []},
{"say": "what should i cook tonight", "want": []},
{"say": "thanks that helped a lot", "want": []},
{"say": "write my essay for me", "want": []},
{"say": "who won the match yesterday", "want": []},
{"say": "destroy the whole computer", "want": []},
{"say": "is it going to rain", "want": []}
]
17 changes: 14 additions & 3 deletions tests/test_match_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
MIN_RIGHT / lower MAX_WRONG to the new numbers so they stay that way.
Run `python tests/match_eval.py` to see every wrong and missed phrase.
"""
import json
import sys
from pathlib import Path

import pytest

sys.path.insert(0, str(Path(__file__).resolve().parent))

from match_eval import evaluate, load_cases # noqa: E402
from match_eval import CASES_FILE, HELDOUT_FILE, ROOT, evaluate, load_cases # noqa: E402

MIN_RIGHT = 339
MAX_WRONG = 20


def test_cases_are_well_formed():
cases = load_cases()
@pytest.mark.parametrize("path", [CASES_FILE, HELDOUT_FILE], ids=lambda p: p.stem)
def test_cases_are_well_formed(path):
cases = load_cases(path)
says = [c["say"] for c in cases]
assert len(says) == len(set(says)), "a phrase is listed twice"
for case in cases:
Expand All @@ -27,6 +31,13 @@ def test_cases_are_well_formed():
assert all(isinstance(w, str) and w.strip() for w in case["want"]), case


def test_held_out_phrases_are_not_tuned_against():
"""Their score isn't a gate: gating on it would mean tuning to it."""
known = {c["say"] for c in load_cases()}
known |= set(json.loads((ROOT / "seed_kb.json").read_text(encoding="utf-8")))
assert not known & {c["say"] for c in load_cases(HELDOUT_FILE)}


def test_matching_does_not_get_worse():
counts, rows = evaluate()
wrong = [f"{case['say']!r} -> {command!r}" for case, _, command, verdict in rows
Expand Down
Loading