| name | overleaf |
| description | LaTeX 文档与 Overleaf 项目的首选方案。当需要编写或编辑 .tex 文件、编译 LaTeX 项目并获取 PDF、创建或管理 Overleaf 项目、查看或解决 review 评论时触发。 |
Overleaf Skill
通过 Git 协议操作 Overleaf 项目文件(克隆、拉取、编辑、提交、推送),通过 REST API 创建新项目,通过 Review API 管理评论线程(列出、解决),通过 Compile API 触发远程编译并下载 PDF。
所有文件级操作(浏览目录、读写文件、创建删除、下载项目)统一通过 git clone/git pull + 本地编辑 + git push 完成,不再使用 WebSocket/REST 逐文件操作。
Skill 目录结构
scripts/ 与本 SKILL.md 同级,位于 SKILL.md 所在目录下:
<skill-dir>/ ← 本 SKILL.md 所在目录
├── SKILL.md
└── scripts/
├── ol.sh # 入口:环境准备 + 转发给 ol.py
├── ol.py # CLI 入口:命令解析与调度
└── edge_cookies.py # 从 Edge 浏览器提取 Cookie
使用前先确定 SKILL_DIR(从 AGENTS.md 中本 skill 的 <location> 标签推导):
SKILL_DIR="$(dirname "$(grep -A1 'name: overleaf' ~/.pi/agent/AGENTS.md | grep location | sed 's/.*<location>\(.*\)\/SKILL.md.*/\1/')")"
⚠️ 始终用 $SKILL_DIR/scripts/ol.sh 调用,不要使用 ~/scripts/ 或其他猜测路径。
环境准备
获取 overleaf 认证信息
Cookie 支持自动获取:当 OVERLEAF_COOKIE 环境变量未设置时,ol.sh 会自动从 macOS Edge 浏览器提取对应域名的 Cookie(需要 Edge 已登录 Overleaf)。
因此通常只需设置 OVERLEAF_HOST,Cookie 会自动处理:
export OVERLEAF_HOST="overleaf.mycompany.com"
| 变量名 | 说明 | 是否必须 |
|---|
OVERLEAF_HOST | Overleaf 实例域名(不含 https://) | 是(默认 www.overleaf.com) |
OVERLEAF_COOKIE | 浏览器 Cookie 头部字符串 | 否(未设置时自动从 Edge 获取) |
自动获取依赖 macOS Keychain 授权(首次会弹窗确认)。若自动获取失败,可手动设置:
获取 Cookie:浏览器打开 Overleaf → F12 → Network → 任意请求 → Request Headers → Cookie。
export OVERLEAF_COOKIE="overleaf_session2=s%3Axxx; gke-route=yyy"
Git 认证信息
Git 凭据默认已配置在 osxkeychain 中,可直接使用 git clone https://...。
若失败,提示用户配置相关 token。
调用方式
Review/获取项目对应 git 地址 的操作通过 wrapper 脚本:
bash "$SKILL_DIR/scripts/ol.sh" <命令> [参数]
Cookie 会自动从 Edge 浏览器获取,无需手动 source 或设置环境变量。
获取 git url后,直接使用 git 命令行进行管理。
命令参考
创建新项目
bash "$SKILL_DIR/scripts/ol.sh" create "My New Paper"
bash "$SKILL_DIR/scripts/ol.sh" create "My New Paper" --template example
bash "$SKILL_DIR/scripts/ol.sh" create "My New Paper" --compact
输出字段:project_id、project_name、template、git_url、git_clone_url、web_url。
获取项目 Git 地址
bash "$SKILL_DIR/scripts/ol.sh" git urls
bash "$SKILL_DIR/scripts/ol.sh" git urls --compact
bash "$SKILL_DIR/scripts/ol.sh" git urls --base-url "https://git.example.com"
输出字段:project_id、project_name、git_url、git_clone_url。
获取 review 评论线程
bash "$SKILL_DIR/scripts/ol.sh" review list "MyProject"
bash "$SKILL_DIR/scripts/ol.sh" review list "MyProject" --compact
解决 review 线程
bash "$SKILL_DIR/scripts/ol.sh" review resolve "MyProject" "69c2745dc0f84b044e000001"
bash "$SKILL_DIR/scripts/ol.sh" review resolve "MyProject" "69c2745dc0f84b044e000001" --user-id "69a65a7a8f69a4e6b57d0ddd"
编译项目
bash "$SKILL_DIR/scripts/ol.sh" compile "MyProject"
bash "$SKILL_DIR/scripts/ol.sh" compile "MyProject" --compact
bash "$SKILL_DIR/scripts/ol.sh" compile "MyProject" --compiler xelatex
输出字段:status(success / failure / error)、pdf_url、output_files(含 .pdf、.log、.bbl 等)。
编译并下载 PDF
bash "$SKILL_DIR/scripts/ol.sh" pdf "MyProject"
bash "$SKILL_DIR/scripts/ol.sh" pdf "MyProject" --output /tmp/paper.pdf
bash "$SKILL_DIR/scripts/ol.sh" pdf "MyProject" --compiler xelatex
典型工作流
创建项目并开始编辑
bash "$SKILL_DIR/scripts/ol.sh" create "My New Paper"
git clone https://git@overleaf.mycompany.com/git/<project_id> /tmp/my-new-paper
cd /tmp/my-new-paper
git add -A
git commit -m "initial content"
git push
克隆并编辑项目
bash "$SKILL_DIR/scripts/ol.sh" git urls
git clone https://git@overleaf.mycompany.com/git/<project_id> /tmp/my-project
cd /tmp/my-project
git add -A
git commit -m "update content"
git push
在已克隆的项目中同步他人更改
当项目已经克隆到本地,提交前需要先拉取协作者的最新更改:
cd /tmp/my-project
git pull --rebase
git add -A
git rebase --continue
git push
处理 review 评论
bash "$SKILL_DIR/scripts/ol.sh" review list "MyProject"
git clone https://git@overleaf.mycompany.com/git/<project_id> /tmp/my-project
cd /tmp/my-project
git add -A
git commit -m "address review comments"
git push
bash "$SKILL_DIR/scripts/ol.sh" review resolve "MyProject" "<thread_id>"
编译并获取 PDF
cd /tmp/my-project
git add -A && git commit -m "final edits" && git push
bash "$SKILL_DIR/scripts/ol.sh" pdf "MyProject"
bash "$SKILL_DIR/scripts/ol.sh" compile "MyProject"
curl -L -b "$OVERLEAF_COOKIE" "<pdf_url>" -o paper.pdf
已知限制
- Cookie 认证依赖浏览器登录状态,过期后需重新获取
review list/resolve 依赖 Overleaf 内部评论线程与 joinDoc 接口(非官方公开 API),不同私有部署可能有差异
compile / pdf 依赖 POST /project/{id}/compile 接口(非官方公开 API),不同私有部署可能有差异
git urls 依赖 GET /user/projects 接口;若实例关闭或 Cookie 无权限会返回 401/403
- Git 推送后 Overleaf 编辑器需刷新页面才能看到更新
依赖
pyoverleaf:通过 uv tool install pyoverleaf 安装(仅 review 功能需要)
- Python 解释器路径:
~/.local/share/uv/tools/pyoverleaf/bin/python
git:系统 Git 客户端,凭据已配置在 osxkeychain
代码风格偏好
扩展或修改本 skill 的脚本时,优先拆分为多个子模块,而非将所有逻辑堆入单一文件:
scripts/
ol.sh # 入口:环境准备 + 转发给 ol.py
ol.py # CLI 入口:只做命令解析与调度,不含业务逻辑
edge_cookies.py # 子模块:从 Edge 浏览器提取 Cookie
api.py # 子模块:Overleaf REST/WebSocket API 封装
git_utils.py # 子模块:Git URL 构造与项目列表
review.py # 子模块:review 线程获取与解析
compile.py # 子模块:编译与 PDF 下载
...
每个子模块职责单一,ol.py 只做 import 和 CLI 注册。新增功能时,新建子模块文件,不要直接往 ol.py 追加几百行。