How macOS Summarize Works (Reverse-Engineered with Kimi K3) A developer reverse-engineered macOS's Summarize feature, revealing that the extractive summarization algorithm uses TF-IDF cosine similarity via the SearchKit framework. The Python reimplementation, built from dynamic analysis of SKSummary, produces byte-identical output on 9 of 12 test files, with minor floating-point noise on 2 and a CJK tokenization gap on 1. The project, hosted on GitHub, documents the algorithm's tokenization quirks, sentence segmentation rules, and summary length formulas for macOS 26.5.2. Please note: the code and content in this repository were generated by an LLM Kimi K3 . English | 中文 /fenxer/macos-summarize-internals/blob/main/README.zh-CN.md Ever wondered what happens when you right-click text in macOS and choose Services → Summarize ? This repository contains a complete answer: a dynamic-analysis reverse engineering of SKSummary the SearchKit engine behind Summary Service.app , plus a Python reimplementation that is byte-verified against the system output on a 12-file corpus — 9 files byte-identical, 2 differing only in exact-tie floating-point noise, and 1 covering the CJK tokenization gap scoring formula itself verified . - Summary Service.app is a thin shell. The real algorithm lives in SearchKit SKSummary — a public API family dating back to the Carbon era . - It is extractive summarization as self-retrieval : build an in-memory inverted index over the sentences, then run the whole document as a ranked query against it, and pick the top sentences by TF-IDF cosine similarity:score s = Σ q t ·w t / √Σ w t ², where w t = idf·ln 1+tf , q t = idf·ln 1+qtf /|Q|, idf t = 1 + ln N/df - Default summary length: k = max 1, ⌊3.0·ln n⌋ ; the UI slider switches to k = max 1, ⌊n·pct⌋ . - No stopword removal, no stemming. Digits are terms even single digits , case is folded, single-character words are indexed. - Tokenization quirks pinned by probes: decimals split at the dot 3.5 → 3 , 5 ; e-mail splits at @ but the domain stays whole admin@example.com → admin + example.com ; hyphens split; apostrophes are kept. - Sentence segmentation: no break when a period is followed by a lowercase letter; 。!? break unconditionally. - Ties: the later sentence ranks first; zero-term sentences sink to the bottom in document order. - Summary assembly keeps raw trailing whitespace: adjacent sentences are joined with 2 extra spaces, skipped ranges get an ellipsis ... , paragraph crossings use \n\n / \n\n... . - Test environment: macOS 26.5.2 arm64 . These are private behaviors; re-verify on other versions. | Path | What it is | |---|---| tools/pysummary.py | The Python reimplementation segmentation, tokenization, scoring, ranking, assembly | tools/sk dump.c | Ground-truth dumper: calls system SKSummary and prints sentence count, per-sentence ranks, sentence texts, and summaries for k=1..8 | tools/tok dump.c | Dumper for real CFStringTokenizer sentence/word tokenization | tools/compare.py | Regression harness: diffs sk dump vs pysummary.py over corpus/ .txt | corpus/ | 12 regression texts prose, repeats, ties, paragraphs, numbers, news, abbreviations, punctuation, long text, Chinese, hyphen/e-mail, full-tie | probes/ | All probes & experiments from the reverse-engineering process C probes, lldb scripts, hypothesis tests | dumps/ | Raw SearchKit segment dumps captured during analysis | docs/article.md | The full write-up Chinese | docs/article.en.md | The full write-up English , also appended at the bottom of this README | - macOS with Xcode Command Line Tools clang — the dumpers link against system frameworks python3 standard library only; probes/exp3.py additionally needs numpy build the ground-truth dumpers clang -O1 -framework CoreServices tools/sk dump.c -o tools/sk dump clang -O1 -framework CoreFoundation tools/tok dump.c -o tools/tok dump run the full regression expect: PASS 9 / PASS△ 2 / known-deviation 1 python3 tools/compare.py summarize any text file with the reimplementation python3 tools/pysummary.py your text.txt python3 tools/pysummary.py