Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/PsychQuant/che-apple-mail-mcpWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/commands/psychquant/che-apple-mail-mcp/archive-mail-rebuild-threads)<a href="https://agentmods.dev/commands/psychquant/che-apple-mail-mcp/archive-mail-rebuild-threads"><img src="https://agentmods.dev/badge/commands/psychquant/che-apple-mail-mcp/archive-mail-rebuild-threads/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/commands/psychquant/che-apple-mail-mcp/archive-mail-rebuild-threads"><img src="https://agentmods.dev/badge/commands/psychquant/che-apple-mail-mcp/archive-mail-rebuild-threads.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00012 | $0.01780 |
| Opus 5 | $0.00006 | $0.00890 |
| Sonnet 5 | $0.00002 | $0.00356 |
| Haiku 4.5 | $0.00001 | $0.00178 |
Grade A, and why
archive-mail-rebuild-threads scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 12d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 199 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Archive Mail — Rebuild Threads Index
掃描 archive 目錄下所有 md 檔的 YAML frontmatter,從 canonical storage 重建 .threads.json。
什麼時候用
.threads.json損壞或被刪除- 手動修改過 md frontmatter 的 thread_key(例如拆分長 thread)
- 從舊版 archive 升級到 v2.6.0+(舊 md 沒有 frontmatter,需先 backfill frontmatter 再 rebuild)
- 想確認
.threads.json和 md 檔一致(當作 sanity check)
使用方式
/archive-mail-rebuild-threads
/archive-mail-rebuild-threads communications/emails
- 第一個參數(可選):archive 目錄,預設
communication/emails
執行步驟
Step 1: 解析參數
archive_dir: 預設communication/emails
若目錄不存在,報錯退出。
Step 2: 解析 namespace 路徑 + 備份既有 threads.json(v2.8.0+)
NAMESPACE_DIR=".claude/.mail"
SLUG=$(echo "${archive_dir}" | tr '/' '-' | sed 's/^[-.]*//;s/[-.]*$//')
INDEX_DIR="${NAMESPACE_DIR}/state/archives/${SLUG}"
THREADS_FILE="${INDEX_DIR}/threads.json"
mkdir -p "${INDEX_DIR}"
# Auto-migrate legacy(silent)
if [ ! -f "${THREADS_FILE}" ] && [ -f "${archive_dir}/.threads.json" ]; then
mv "${archive_dir}/.threads.json" "${THREADS_FILE}"
echo "🔄 Migrated ${archive_dir}/.threads.json → ${THREADS_FILE}"
fi
# Backup existing threads.json before rebuild
if [ -f "${THREADS_FILE}" ]; then
cp "${THREADS_FILE}" "${THREADS_FILE}.bak.$(date +%Y%m%d_%H%M%S)"
echo "Backed up existing threads.json"
fi
備份不刪舊的,方便回滾。
Step 3: 掃描所有 md 檔
用 Glob "${archive_dir}/*.md" 列出所有歸檔 md。
對每一個 md:
Read檔案(只需要前 30 行,frontmatter 一定在這裡面)- 解析 YAML frontmatter(位於檔案最前面的
---之間) - 提取:
message_id(必需)thread_key(必需)in_reply_to(可選)date(必需)sender(必需)
- 若 frontmatter 缺失或必需欄位不全:
- 記錄到
missing_frontmatter清單 - 不中斷流程,繼續下一檔
- 記錄到
Step 4: 聚合成 threads 結構
建立新的 threads 物件:
new_threads = {}
for each valid md:
key = md.thread_key
if key not in new_threads:
new_threads[key] = {
"messages": [],
"participants_set": set(),
"first_message": null,
"last_message": null
}
entry = new_threads[key]
entry.messages.append({
"message_id": md.message_id,
"file": md.filename,
"date": md.date,
"sender": md.sender,
"in_reply_to": md.in_reply_to or null
})
entry.participants_set.add(md.sender)
if md.to/cc available in frontmatter → add to set
entry.first_message = min(entry.first_message, md.date)
entry.last_message = max(entry.last_message, md.date)
# 後處理
for key, entry in new_threads:
entry.messages.sort(key=lambda m: m.date) # 時序排序
entry.message_count = len(entry.messages)
entry.participants = sorted(list(entry.participants_set))
del entry.participants_set
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 12d ago First seen · 199 lines · 12 tokens per session scan A d75bfcbc104a
archive-mail-rebuild-threads is a command published in the GitHub repository PsychQuant/che-apple-mail-mcp (8 stars, last pushed today), licensed MIT. It adds 12 tokens to every session and 1,780 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other commands, from other repositories
analyze-attachments
Deep attachment analysis with extraction, importance classification, and content analysis.
remind
Create a reminder from natural language.
week
Show this week's calendar overview.
start-10-4.en
Lesson 10-4: GmailApp Email Search/Extraction → Sheet Organization!
notes-snapshot-preflight
Preflight Apple Notes Snapshot before you attach MCP, Local Web API, or AI Diagnose to a local coding host.
cabinet
Build a self-contained archive bundle for a single .eml — markdown, retained attachments, and source file in one directory.