zotero-pdf-upload
Use this skill for direct Zotero workflows that must stay safe, explicit, and reusable.
First-time setup check (do this BEFORE any Zotero operation)
Before running any command, check if config.json exists in the skill root directory.
If config.json does NOT exist, stop and inform the user:
This skill is not configured yet. You need to set it up first.
What you need to prepare:
- 1. Zotero API Key — Create one at zotero.org/settings/keys
- Go to Settings → Security → Create new private key
- Enable: Allow library access, Allow notes access, Allow write access
- If using group libraries, set Default Group Permissions to Read/Write
- Click "Save Key" and copy the generated key
- 2. Zotero Library URL — Open your library in a browser and copy the URL:
- Personal: https://www.zotero.org/<your-username>/library
- Group: https://www.zotero.org/groups/<group-id>/<group-name>/library
Run this one-line setup command from the skill directory:
CODEBLOCK0
Do NOT proceed with any Zotero operations until config.json has been created.
Included resources
- -
scripts/zotero_workflow.py: CLI entrypoint for parse/inspect/match/create operations. - INLINECODE6 : Zotero API client, URL parser, secret loading, collection matching, item creation, PDF upload.
- INLINECODE7 : no-network smoke tests.
- INLINECODE8 : runtime config template (uses unified
url field for both group and personal URLs). - INLINECODE10 : item metadata sample.
- INLINECODE11 : approval checkpoints and write safety policy.
Required operating policy
- 1. Start with read-only steps (
parse-url, list-collections, choose-collection). - If collection matching is weak or missing, return
pending-new-collection-approval. - Create collections only via explicit action (
create-collection --approve-create). - Create items only via explicit action (
create-item --approve-write). - Only upload PDF if explicitly requested and config allows it.
Secret handling
Load Zotero API key in this order (safe default):
- 1. Environment variable:
zotero.apiKeyEnv (default ZOTERO_API_KEY) - Secret file path: INLINECODE20
- Inline config value:
zotero.apiKey (least preferred)
Never print full API keys in output.
Security note: when resolving a personal library URL (username-based, no numeric ID),
the skill calls GET https://api.zotero.org/keys/{apiKey} to look up the userID.
This is the standard Zotero API pattern — the key appears in the URL and may be
visible in server access logs. Use a least-privilege key and prefer env/file loading
over inline config.
Core commands
Run from skill directory.
1) Parse a Zotero URL
CODEBLOCK1
Personal library URL:
CODEBLOCK2
2) List collections (read-only)
CODEBLOCK3
Optional matching context:
CODEBLOCK4
3) Choose collection (read-only, no auto-create)
CODEBLOCK5
- - If matched: status
matched-existing-collection. - If not matched: status
pending-new-collection-approval + suggested name.
4) Explicitly create collection (write)
CODEBLOCK6
5) Explicitly create item metadata (write)
CODEBLOCK7
Optional PDF attachment:
CODEBLOCK8
Approval points to enforce
- - Never call write subcommands without explicit human confirmation.
- Do not auto-create missing collections during matching.
- If matching confidence is weak, stop and ask whether to create/select a collection.
- Treat attachment upload failure as reportable; do not silently ignore.
Smoke test
CODEBLOCK9
zotero-pdf-upload
使用此技能进行直接、安全、明确且可复用的 Zotero 工作流。
首次使用设置检查(在任何 Zotero 操作之前执行)
在运行任何命令之前,检查技能根目录下是否存在 config.json 文件。
如果 config.json 不存在,请停止并告知用户:
此技能尚未配置。您需要先进行设置。
您需要准备的内容:
- 1. Zotero API 密钥 — 在 zotero.org/settings/keys 创建
- 前往 设置 → 安全 → 创建新的私有密钥
- 启用:允许访问文库、允许访问笔记、允许写入
- 如果使用群组文库,将默认群组权限设置为 读取/写入
- 点击保存密钥并复制生成的密钥
- 2. Zotero 文库 URL — 在浏览器中打开您的文库并复制 URL:
- 个人文库:https://www.zotero.org/<您的用户名>/library
- 群组文库:https://www.zotero.org/groups/<群组ID>/<群组名称>/library
从技能目录运行以下单行设置命令:
bash
python scripts/setup.py <您的文库URL> <您的API密钥>
在 config.json 创建完成之前,请勿执行任何 Zotero 操作。
包含的资源
- - scripts/zoteroworkflow.py:用于解析/检查/匹配/创建操作的 CLI 入口点。
- scripts/zoteroclient.py:Zotero API 客户端、URL 解析器、密钥加载、集合匹配、条目创建、PDF 上传。
- tests/smoketestzoteropdfupload.py:无网络烟雾测试。
- references/config.example.json:运行时配置模板(对群组和个人 URL 使用统一的 url 字段)。
- references/item.example.json:条目元数据示例。
- references/approval-flow.md:审批检查点和写入安全策略。
必需的操作策略
- 1. 从只读步骤开始(parse-url、list-collections、choose-collection)。
- 如果集合匹配不明确或缺失,返回 pending-new-collection-approval。
- 仅通过显式操作创建集合(create-collection --approve-create)。
- 仅通过显式操作创建条目(create-item --approve-write)。
- 仅在明确请求且配置允许时上传 PDF。
密钥处理
按以下顺序加载 Zotero API 密钥(安全默认值):
- 1. 环境变量:zotero.apiKeyEnv(默认为 ZOTEROAPIKEY)
- 密钥文件路径:zotero.apiKeyPath
- 内联配置值:zotero.apiKey(最不推荐)
切勿在输出中打印完整的 API 密钥。
安全说明:解析个人文库 URL(基于用户名,无数字 ID)时,
技能会调用 GET https://api.zotero.org/keys/{apiKey} 来查找用户 ID。
这是标准的 Zotero API 模式——密钥会出现在 URL 中,可能
在服务器访问日志中可见。请使用最小权限密钥,并优先使用环境变量/文件加载
而非内联配置。
核心命令
从技能目录运行。
1) 解析 Zotero URL
bash
python scripts/zotero_workflow.py parse-url --url https://www.zotero.org/groups/6320165/my-group/library
个人文库 URL:
bash
python scripts/zotero_workflow.py parse-url --url https://www.zotero.org/myusername/library
2) 列出集合(只读)
bash
python scripts/zotero_workflow.py list-collections --config ./tmp.config.json
可选的匹配上下文:
bash
python scripts/zotero_workflow.py list-collections \
--config ./tmp.config.json \
--title Practical Alignment Evaluation for LLM Agents \
--tags alignment llm
3) 选择集合(只读,不自动创建)
bash
python scripts/zotero_workflow.py choose-collection \
--config ./tmp.config.json \
--item-json references/item.example.json
- - 如果匹配:状态为 matched-existing-collection。
- 如果不匹配:状态为 pending-new-collection-approval + 建议名称。
4) 显式创建集合(写入)
bash
python scripts/zotero_workflow.py create-collection \
--config ./tmp.config.json \
--name LLM Safety \
--approve-create
5) 显式创建条目元数据(写入)
bash
python scripts/zotero_workflow.py create-item \
--config ./tmp.config.json \
--item-json references/item.example.json \
--auto-match-collection \
--approve-write
可选的 PDF 附件:
bash
python scripts/zotero_workflow.py create-item \
--config ./tmp.config.json \
--item-json references/item.example.json \
--collection-key ABCD1234 \
--attach-pdf /path/to/paper.pdf \
--approve-write
需要强制执行的审批点
- - 未经明确的人工确认,切勿调用写入子命令。
- 匹配过程中不要自动创建缺失的集合。
- 如果匹配置信度较低,请停止并询问是否创建/选择集合。
- 将附件上传失败视为可报告事件;不要静默忽略。
烟雾测试
bash
python tests/smoketestzoteropdfupload.py