You're reading this. The skill predicted it. A workflow that turns every post into a calibrated experiment—score, blind-predict, retro, evolve. The future doesn't reward effort, it rewards those who see the pattern first. 1M followers in a month — not luck, system.
Python
Fix privacy-safe runtime paths for douyin-session (#16)
level5Ninja4d7c909a26e6
diff --git a/.gitignore b/.gitignoreindex 84801f2..d2fdcf9 100644--- a/.gitignore+++ b/.gitignore@@ -16,6 +16,7 @@ __pycache__/.venv/venv/.python-version+tests/# 用户项目数据(万一开发者在 cheat-on-content 源码目录里跑了 cheat-init)# 这些文件应该在用户自己的 content project 里,不该污染源码 repodiff --git a/adapters/perf-data/douyin-session/README.md b/adapters/perf-data/douyin-session/README.mdindex 2fbc8ca..a7f2b31 100644--- a/adapters/perf-data/douyin-session/README.md+++ b/adapters/perf-data/douyin-session/README.md@@ -11,12 +11,13 @@抖音视频页是**强 JS 渲染 + XHR 加载评论 + 反爬严重**——不带浏览器引擎和登录态的方案(比如 Claude 的 WebFetch、Python requests)拿不到任何数据。douyin-session 用 **Playwright + 持久化 Chromium context** 模拟真实浏览器:-- 你首次扫码登录抖音创作者中心,cookie 存在 `.auth/`+- 你首次扫码登录抖音创作者中心,cookie 存在**你的内容项目根目录** `.auth/`- 之后每次抓取直接复用 cookie,不用重新登录- 拦截抖音前端的 XHR responses 直接抓数据接口的 JSON(不解析 HTML)- 抓 3 类数据:视频列表 / 详细数据(完播 / 转粉率)/ 评论-输出写到 `<video_folder>/report.md`(cheat-retro 读这个文件 → 摘要写到 prediction 复盘段)。+输出写到**你的内容项目** `videos/<...>/report.md`(`cheat-retro` 读这个文件 → 摘要写到 prediction 复盘段)。+调试产物(URL dump / 截图)写到 `.cheat-cache/douyin-session-debug/`,避免散落在 skill 源码目录。## 安装(一次性)@@ -98,6 +99,7 @@ cheat-publish 会在登记发布时把 aweme_id 存到 prediction header(如- **冷启动用户慎装**:Playwright + Chromium 体积大(~500MB),新人容易劝退- **TOS 风险**:用自己的 cookie 抓自己后台数据是个人用途;别滥用- **不要把 .auth/ 提交到 git**:cookie 里有你的会话凭据,泄露 = 他人能登录你的抖音账号+- `.cheat-cache/douyin-session-debug/` 也不应提交到 git:里面可能含调试截图和接口 URL dump## 文件清单diff --git a/adapters/perf-data/douyin-session/crawler.py b/adapters/perf-data/douyin-session/crawler.pyindex fb3433a..4198e40 100644--- a/adapters/perf-data/douyin-session/crawler.py+++ b/adapters/perf-data/douyin-session/crawler.py@@ -11,9 +11,8 @@ from pathlib import Pathfrom typing import Anyfrom playwright.async_api import BrowserContext, Page, Response, async_playwright+from paths import auth_dir, debug_dir-AUTH_DIR = Path(__file__).parent / ".auth"-DEBUG_DIR = Path(__file__).parent / ".debug"CREATOR_HOME = "https://creator.douyin.com/creator-micro/home"CREATOR_CONTENT = "https://creator.douyin.com/creator-micro/content/manage"@@ -28,9 +27,10 @@ class Session:@classmethodasync def open(cls, headless: bool = False) -> Session:pw = await async_playwright().start()- AUTH_DIR.mkdir(exist_ok=True)+ auth_path = auth_dir()+ auth_path.mkdir(exist_ok=True)ctx = await pw.chromium.launch_persistent_context(- user_data_dir=str(AUTH_DIR),+ user_data_dir=str(auth_path),headless=headless,viewport={"width": 1440, "height": 900},args=["--disable-blink-features=AutomationControlled"],@@ -99,8 +99,9 @@ async def fetch_recent_videos(sess: Session, limit: int = 50) -> list[dict]:await asyncio.sleep(1.5)videos = _parse_video_list(captured, limit)if not videos:- DEBUG_DIR.mkdir(exist_ok=True)- (DEBUG_DIR / "creator_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")+ debug_path = debug_dir()+ debug_path.mkdir(parents=True, exist_ok=True)+ (debug_path / "creator_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")print(f"[诊断] 视频列表为空,{len(all_urls)} 个请求已 dump。")return videosfinally:@@ -178,8 +179,9 @@ async def fetch_video_detail(sess: Session, aweme_id: str) -> dict:await page.goto(url, wait_until="domcontentloaded", timeout=60000)await asyncio.sleep(6)if not captured:- DEBUG_DIR.mkdir(exist_ok=True)- (DEBUG_DIR / "detail_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")+ debug_path = debug_dir()+ debug_path.mkdir(parents=True, exist_ok=True)+ (debug_path / "detail_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")print("[诊断] 详细数据接口没拦到,已 dump URL 列表。")return {"captured": captured}finally:@@ -230,9 +232,10 @@ async def fetch_comments_creator(sess: Session, aweme_id: str, max_pages: int =await page.evaluate("window.scrollBy(0, 1500)")await asyncio.sleep(1.5)- DEBUG_DIR.mkdir(exist_ok=True)- await page.screenshot(path=str(DEBUG_DIR / "creator_comment_page.png"))- (DEBUG_DIR / "creator_comment_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")+ debug_path = debug_dir()+ debug_path.mkdir(parents=True, exist_ok=True)+ await page.screenshot(path=str(debug_path / "creator_comment_page.png"))+ (debug_path / "creator_comment_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")# 解析:抽取所有 data 里可能包含评论的结构comments: list[dict] = []@@ -311,8 +314,9 @@ async def fetch_comments(sess: Session, aweme_id: str, max_pages: int = 60) -> lpassawait asyncio.sleep(4)- DEBUG_DIR.mkdir(exist_ok=True)- await page.screenshot(path=str(DEBUG_DIR / "comment_page.png"))+ debug_path = debug_dir()+ debug_path.mkdir(parents=True, exist_ok=True)+ await page.screenshot(path=str(debug_path / "comment_page.png"))# 策略:把最后一条评论 scrollIntoView 触发 IntersectionObserver 懒加载last_count = 0@@ -353,7 +357,7 @@ async def fetch_comments(sess: Session, aweme_id: str, max_pages: int = 60) -> ldedup.append(c)dedup.sort(key=lambda x: x["digg_count"], reverse=True)- (DEBUG_DIR / "comment_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")+ (debug_path / "comment_urls.txt").write_text("\n".join(all_urls), encoding="utf-8")return dedupfinally:await page.close()diff --git a/adapters/perf-data/douyin-session/paths.py b/adapters/perf-data/douyin-session/paths.pynew file mode 100644index 0000000..c7ec16f--- /dev/null+++ b/adapters/perf-data/douyin-session/paths.py@@ -0,0 +1,40 @@+from __future__ import annotations++import os+from pathlib import Path+from typing import Mapping+++def runtime_project_root(+ env: Mapping[str, str] | None = None,+ cwd: Path | None = None,+) -> Path:+ active_env = env if env is not None else os.environ+ if active_env.get("CHEAT_PROJECT_ROOT"):+ return Path(active_env["CHEAT_PROJECT_ROOT"]).expanduser().resolve()+ base_cwd = cwd if cwd is not None else Path.cwd()+ return Path(base_cwd).expanduser().resolve()+++def auth_dir(+ env: Mapping[str, str] | None = None,+ cwd: Path | None = None,+) -> Path:+ return runtime_project_root(env=env, cwd=cwd) / ".auth"+++def debug_dir(+ env: Mapping[str, str] | None = None,+ cwd: Path | None = None,+) -> Path:+ return runtime_project_root(env=env, cwd=cwd) / ".cheat-cache" / "douyin-session-debug"+++def videos_dir(+ env: Mapping[str, str] | None = None,+ cwd: Path | None = None,+) -> Path:+ active_env = env if env is not None else os.environ+ if active_env.get("CHEAT_VIDEOS_DIR"):+ return Path(active_env["CHEAT_VIDEOS_DIR"]).expanduser().resolve()+ return runtime_project_root(env=env, cwd=cwd) / "videos"diff --git a/adapters/perf-data/douyin-session/review.py b/adapters/perf-data/douyin-session/review.pyindex 37e69cc..e1daab3 100644--- a/adapters/perf-data/douyin-session/review.py+++ b/adapters/perf-data/douyin-session/review.py@@ -8,15 +8,12 @@from __future__ import annotationsimport asyncio-import shutilimport sysfrom pathlib import Pathimport crawlerimport renderer--ROOT = Path(__file__).parent-VIDEOS_DIR = ROOT / "videos"+from paths import videos_dirdef _prompt(msg: str) -> str:@@ -61,7 +58,8 @@ async def run() -> None:注意:会打开两次 Chromium(一次选视频,一次抓全量)。"""- VIDEOS_DIR.mkdir(exist_ok=True)+ active_videos_dir = videos_dir()+ active_videos_dir.mkdir(parents=True, exist_ok=True)print("[选视频] 打开创作者中心拉列表……")sess = await crawler.Session.open()@@ -87,7 +85,8 @@ async def run() -> None:async def run_with_id(aweme_id: str, script_path: str | None) -> None:- VIDEOS_DIR.mkdir(exist_ok=True)+ active_videos_dir = videos_dir()+ active_videos_dir.mkdir(parents=True, exist_ok=True)script = ""if script_path:@@ -104,7 +103,7 @@ async def run_with_id(aweme_id: str, script_path: str | None) -> None:detail = result["detail"]comments = result["comments"]- out_dir = renderer.output_dir_for(video, VIDEOS_DIR)+ out_dir = renderer.output_dir_for(video, active_videos_dir)out_dir.mkdir(parents=True, exist_ok=True)if script:(out_dir / "script.txt").write_text(script, encoding="utf-8")diff --git a/adapters/perf-data/douyin-session/run.sh b/adapters/perf-data/douyin-session/run.shindex 26852f9..1bc23c6 100755--- a/adapters/perf-data/douyin-session/run.sh+++ b/adapters/perf-data/douyin-session/run.sh@@ -87,6 +87,7 @@ fi# Run from PROJECT_ROOT so .auth/ is found and outputs go to expected pathscd "$PROJECT_ROOT"+export CHEAT_PROJECT_ROOT="$PROJECT_ROOT"# Override VIDEOS_DIR via env var so review.py writes to user's videos/ not its own# (review.py uses ROOT/videos by default; we override to use user's project)diff --git a/hooks/log-event.sh b/hooks/log-event.shindex dd64354..b134b58 100755--- a/hooks/log-event.sh+++ b/hooks/log-event.sh@@ -39,9 +39,8 @@ if command -v jq >/dev/null 2>&1; thentool: (.tool_name // null),file: (.tool_input.file_path // null),success: (.tool_response.success // null),- prompt_excerpt: (- (.user_prompt // "" | tostring) | .[:120]- )+ prompt_present: ((.user_prompt // null) != null),+ prompt_chars: ((.user_prompt // "" | tostring) | length)}' 2>/dev/null || echo "")if [[ -z "$event_json" ]]; thendiff --git a/hooks/meta-logging.json b/hooks/meta-logging.jsonindex 2f7d59d..ddb6a2e 100644--- a/hooks/meta-logging.json+++ b/hooks/meta-logging.json@@ -1,5 +1,5 @@{- "_comment": "cheat-on-content meta-logging hook. Passively records every cheat-* skill invocation, tool call, and session lifecycle event to .cheat-cache/usage.jsonl. All hooks are async fire-and-forget — never blocks. Used by /cheat-status to compute things like 'distance since last bump'.",+ "_comment": "cheat-on-content meta-logging hook. Passively records local event metadata to .cheat-cache/usage.jsonl. It stores event type, tool/file metadata, and prompt presence/length only — not raw prompt excerpts. All hooks are async fire-and-forget — never blocks. Used by /cheat-status to compute things like 'distance since last bump'.","hooks": {"PostToolUse": [{diff --git a/shared-references/state-management.md b/shared-references/state-management.mdindex 37ce3b6..0e229ab 100644--- a/shared-references/state-management.md+++ b/shared-references/state-management.md@@ -279,6 +279,7 @@ def write_state(state):`.cheat-cache/` 目录**不应该**被纳入 git:- 含 `usage.jsonl`(meta-logging 钩子的本地日志)- 含 `trends-history.jsonl`(trend 抓取的去重缓存)+- 也可能含 adapter 调试文件(如 `douyin-session-debug/`)- 这些是设备本地状态,跨设备同步无意义`/cheat-init` 应自动在用户项目根追加(不覆盖)`.gitignore`: