cli-anything-zotero 实战指南:让 Zotero 桌面版原生可被 Agent 与 LLM 调用 📅 发布时间:2026/9/11 13:29:59 👁 浏览次数: cli-anything-zotero 实战指南让 Zotero 桌面版原生可被 Agent 与 LLM 调用【免费下载链接】CLI-AnythingCLI-Anything: Making ALL Software Agent-Native -- CLI-Hub: https://clianything.cc/项目地址: https://gitcode.com/GitHub_Trending/cl/CLI-Anything本指南围绕cli-anything-zotero展开它是 CLI-Anything 体系中面向 Zotero 桌面版的Agent 原生命令行工具。它不重新实现 Zotero而是组合 Zotero 真实存在的本地能力SQLite 离线只读、connector 写入口、Local API 渲染与搜索为 AI Agent 提供稳定、可脚本化的接口。读完本文你将掌握它的安装、约束边界、全部命令组、十个核心工作流以及 REPL 会话与源码级后端原理能够直接把它接入自己的文献管理工作流或 Agent 编排。工具定位三种本地能力的组合从 SKILL.md 与 模块 README 可以看到cli-anything-zotero的设计哲学是组合而非重写它依赖三块真实存在的本地表面表面用途是否需要 Zotero 运行SQLitezotero.sqlite离线、只读的清单查询收藏集、条目、笔记、附件、标签、保存的搜索否connector 端点GUI 状态读取与官方写流程note add、import、use-selected是Local API引文、参考文献、导出、实时搜索与保存搜索执行是且需启用这一分层在源码中有直接对应discovery.py 负责探测可执行文件、profile、data dir、SQLite 路径以及 connector / Local API 可用性catalog.py 的只读查询全部落在 SQLiterendering.py 的导出与引文渲染要求 Local APIimports.py 与 notes.py 的写操作走 connector。环境要求与安装前置条件来自 README.mdPython 3.10已安装 Zotero 桌面版存在本地 Zotero profile 与数据目录Windows 上默认验证目标为C:\Program Files\Zotero。安装采用可编辑模式cd zotero/agent-harness py -m pip install -e .若随后cli-anything-zotero命令无法识别通常说明 Python Scripts 目录不在PATH中此时仍可用模块入口py -m cli_anything.zotero --help入口点SKILL 文档给出了两个等价入口cli-anything-zotero python -m cli_anything.zotero在 zotero_cli.py 中entrypoint()会调用dispatch()最终由 click 组cli承载所有子命令不带子命令运行时自动进入 REPLinvoke_without_commandTrue与run_repl()的实现。根级全局选项包括--json输出机器可读 JSON--backend auto|sqlite|api后端选择默认auto--data-dir显式指定 Zotero 数据目录--profile-dir显式指定 profile 目录--executable显式指定 Zotero 可执行文件路径emit()的统一输出逻辑会在--json时用json.dumps(..., ensure_asciiFalse, indent2)格式化非 JSON 模式则对无法编码的字符做backslashreplace兜底保证在 Windows 控制台等受限编码环境下不崩zotero_cli.py。启用 Local APISKILL 文档与 README 都强调search items、item export、item citation、item bibliography依赖 Zotero 的 Local API而 Zotero 7 默认关闭它。启用方式有两种方式一CLI 一键启用cli-anything-zotero --json app enable-local-api cli-anything-zotero --json app enable-local-api --launch--launch会在写入偏好后启动 Zotero 并等待 connector 与 Local API 就绪源码实现见 imports.py底层通过 discovery.py 的launch_zotero轮询/connector/ping与/api/。方式二手工编辑user.js在活动 profile 的user.js中加入user_pref(extensions.zotero.httpServer.localAPI.enabled, true);然后重启 Zotero。Local API 的 scope 解析在 catalog.py用户库使用/api/users/0组库使用/api/groups/libraryID所有依赖 Local API 的命令都会自动切换正确的 scope。重要约束必须提前知晓SKILL 文档明确列出以下边界使用前务必理解search items、item export、item citation、item bibliography需要启用 Local API。note add依赖活动的 Zotero GUI 上下文要求应用中当前选中的库与父条目所在库一致源码在 notes.py 中做了显式校验不一致会直接报错。导入时的 PDF 附件支持仅限本次导入会话创建的条目对既有条目任意上传附件仍超出范围。实验性 SQLite 写命令仅限本地用户库、仅在 Zotero 关闭时可用属于不稳定的高级操作。若一个裸 key 在多个库中重复需先执行session use-library id再执行后续命令否则 CLI 会抛出歧义错误。命令组全览SKILL 文档按组罗列了全部命令这里完整保留并补充每个命令的后端依据与 README.md 的命令组表格一致。App运行时与应用检查命令说明是否要求 Zotero 运行后端status显示可执行文件、profile、数据目录、SQLite 路径、connector 与 Local API 状态否discovery 探针version显示包版本与 Zotero 版本否discoverylaunch启动 Zotero 并等待 liveness默认等待 30 秒--wait-timeout可调否executable connectorenable-local-api在user.js启用 Local API可选--launch并验证否profile 偏好ping检查/connector/ping是connectorCollection收藏集检查与选择命令说明后端list列出当前库的收藏集SQLitefind query按名称查找收藏集默认--limit 20SQLitetree展示嵌套收藏集结构SQLiteget ref按 ID 或 key 读取单个收藏集SQLiteitems ref读取某收藏集下的条目SQLiteuse-selected持久化 GUI 当前选中的收藏集connectorcreate name --experimental本地创建收藏集带备份保护Zotero 必须关闭实验性 SQLiteItem条目检查与渲染命令说明后端list列出顶层常规条目SQLitefind query按关键词或完整标题查找Local API SQLiteget ref按 ID 或 key 读取单个条目SQLitechildren ref读取条目下的笔记、附件、标注SQLitenotes ref只读取条目下的子笔记SQLiteattachments ref读取附件元数据与解析后的真实路径SQLitefile ref解析单个附件的文件路径SQLiteexport ref --format fmt通过 Zotero 翻译器导出单个条目Local APIcitation ref渲染一条引文Local APIbibliography ref渲染一条参考文献条目Local APIcontext ref构建结构化、LLM-ready 上下文SQLite 可选 Local APIanalyze ref将条目上下文发给 OpenAI 分析OpenAI 本地上下文add-to-collection item collection --experimental追加一条收藏集归属实验性 SQLitemove-to-collection item collection --experimental在收藏集之间移动条目实验性 SQLiteSearch / Tag / Style / Import / Note / SessionSearch保存的搜索检查list列出保存的搜索SQLite、get ref读取保存的搜索定义SQLite、items ref执行一次保存的搜索Local API。Tag标签检查list列出标签及条目计数SQLite、items tag读取携带某标签的条目SQLite。Style已安装 CSL 样式检查list读取已安装的 CSL 样式SQLite 数据目录。源码 catalog.py 会扫描styles_dir下所有*.csl文件用 defusedxml 安全解析出id与title解析失败则标记valid: false。Import官方 Zotero 导入与写命令file path导入 RIS/BibTeX/BibLaTeX/Refer 等翻译器支持的文本文件connector、json path保存官方 Zotero connector 条目 JSONconnector。Note子笔记读写get ref按 ID 或 key 读取一条笔记SQLite、add item-ref在条目下创建子笔记connector。Session会话与 REPL 上下文status、use-library id、use-collection ref、use-item ref、use-selected、clear-library、clear-collection、clear-item、history。会话机制维护当前库、当前收藏集、当前条目与命令历史供 REPL 与一次性命令共用实现见 session.py。核心工作流SKILL 文档提供了 5 个速查示例下面将其融入 README 的完整 10 步工作流中逐条展开。1. 运行时状态检查cli-anything-zotero app status --json返回 payload 由 discovery.py 的to_status_payload()组装包含环境信息与backend、connector_available、local_api_available及对应 message。2. 读取 GUI 当前选中的收藏集cli-anything-zotero collection use-selected --json通过 connector 端点读取 GUI 选中项并持久化current_library与current_collection到会话状态zotero_cli.py。3. 向指定收藏集导入文献使用 Zotero 官方 connector 写路径cli-anything-zotero --json import file .\paper.ris --collection COLLAAAA --tag review cli-anything-zotero --json import json .\items.json --collection COLLAAAA --tag imported cli-anything-zotero --json import file .\paper.ris --collection COLLAAAA --attachments-manifest .\attachments.json cli-anything-zotero --json import json .\items-with-pdf.json --collection COLLAAAA --attachment-timeout 90import file/import json均支持--collection、可重复的--tag、--attachment-delay-msURL 下载前默认延迟默认 0与--attachment-timeout下载/上传超时默认 60 秒。import json支持 harness 私有的内联attachments数组每个条目可选[ { itemType: journalArticle, title: Embodied Intelligence Paper, attachments: [ { path: C:\\papers\\embodied.pdf, title: PDF }, { url: https://example.org/embodied.pdf, title: Publisher PDF, delay_ms: 500 } ] } ]import file通过 sidecar manifest 表达同样的附件描述按导入结果的index关联可选expected_title校验标题一致性[ { index: 0, expected_title: Embodied Intelligence Paper, attachments: [ { path: C:\\papers\\embodied.pdf, title: PDF } ] } ]附件行为的源码级细节imports.py附件只会上传到当前导入会话创建的条目本地文件与下载的 URL 都必须通过 PDF 魔数校验内容以%PDF-开头见_PDF_MAGIC同一导入条目的重复附件描述符会被幂等跳过分别按路径、URL 归一化、SHA-256 内容哈希三重去重若元数据导入成功但部分附件失败命令返回status: partial_success且以非零码退出_import_exit_code。Zotero 运行时目标解析顺序为1) 显式--collection2) 当前会话收藏集3) GUI 当前选中收藏集4) 用户库imports.py 的_resolve_target。该写流程要求 Zotero 正在运行。4. 查找收藏集cli-anything-zotero --json collection find robotics适合只记得文件夹名称而不知道 key 或 ID 的场景。后端为 SQLite不要求 Zotero 运行。5. 按关键词或完整标题查找论文cli-anything-zotero --json item find foundation model cli-anything-zotero --json item find A Very Specific Paper Title --exact-title cli-anything-zotero --json item find vision --collection COLLAAAA --limit 10行为要点默认模式优先 Local API 搜索必要时回退 SQLite 标题搜索使用 Local API 时自动在/api/users/0/...与/api/groups/libraryID/...间切换catalog.py--exact-title强制走 SQLite 精确标题匹配结果包含itemID与key可直接传给item get关键词搜索推荐 Zotero 运行中精确标题搜索不要求。6. 读取收藏集或单条条目cli-anything-zotero --json collection items COLLAAAA cli-anything-zotero --json item get REG12345 cli-anything-zotero --json item attachments REG12345 cli-anything-zotero --json item file REG12345典型用途查看收藏集下所有论文、检查单篇条目的字段/创建者/标签、解析本地 PDF 路径供下游处理。item file在条目为普通文献时会自动选取第一个附件并返回resolvedPath与existscatalog.py。后端为 SQLite不要求 Zotero 运行。7. 读取论文笔记cli-anything-zotero --json item notes REG12345 cli-anything-zotero --json note get NOTEKEYitem notes只列出论文下的子笔记note get按 item ID 或 key 读取单条笔记完整内容。后端 SQLite不要求 Zotero 运行。8. 添加子笔记cli-anything-zotero --json note add REG12345 --text Key takeaway: ... cli-anything-zotero --json note add REG12345 --file .\summary.md --format markdown行为要点始终创建挂在指定论文下的子笔记text与markdown会被转换为安全 HTML 后再保存markdown经 notes.py 的轻量转换器生成p/ul/h1..h6/code/strong/em文本均经html.escape转义html原样透传子笔记只能挂在顶层书目条目下不允许挂在 note/attachment/annotation 下notes.py必须提供--text与--file二者之一且只能其一。重要Zotero 必须运行且 UI 当前所在库必须与父条目一致。后端为 connector/connector/saveItems。9. 导出 BibTeX / CSL JSON / 引文 / 参考文献cli-anything-zotero --json item export REG12345 --format bibtex cli-anything-zotero --json item export REG12345 --format csljson cli-anything-zotero --json item citation REG12345 --style apa --locale en-US cli-anything-zotero --json item bibliography REG12345 --style apa --locale en-US引文与参考文献命令还支持--linkwrap标志。这些命令自动为用户库与组库选择正确的 Local API scope。支持的导出格式在 rendering.py 定义为ris、bibtex、biblatex、csljson、csv、mods、refer。后端 Local API要求 Zotero 运行。10. 生成 LLM-ready 上下文cli-anything-zotero --json item context REG12345 --include-notes --include-links --include-bibtex这是 AI 工作流中稳定、与模型无关的路径。返回内容见 analysis.py 的build_item_context条目元数据与字段附件与本地文件路径可选笔记--include-notes可选 BibTeX--include-bibtex与 CSL JSON--include-csljson可选 DOI 与 URL 链接--include-linksDOI 自动展开为https://doi.org/...一段可直接发给任意 LLM 的prompt_context文本块由_prompt_context拼装为Title / Item Key / Item Type / Creators / 字段 / Links / Attachments / Notes / Exports的纯文本结构。后端为 SQLite仅当请求 BibTeX 或 CSL JSON 导出时可选依赖 Local API。非 JSON 模式下该命令直接输出prompt_context文本。11. 让 OpenAI 分析论文set OPENAI_API_KEY... cli-anything-zotero --json item analyze REG12345 --question What is this papers likely contribution? --model gpt-5.4-mini --include-notes行为要点analysis.py复用item context的结构化上下文且自动加上链接将问题与上下文一起发送到 OpenAI Responses API并附带仅依据提供上下文作答、缺失时明确说明的 instructions要求设置OPENAI_API_KEY且必须显式提供--model返回answer、responseID以及完整context。推荐用法需要可移植数据用item context需要命令行内直接获得答案用item analyze。12. 实验性收藏集重构以下命令直接写zotero.sqlite被刻意标记为实验性cli-anything-zotero --json collection create New Topic --parent COLLAAAA --experimental cli-anything-zotero --json item add-to-collection REG12345 COLLBBBB --experimental cli-anything-zotero --json item move-to-collection REG67890 COLLAAAA --from COLLBBBB --experimental cli-anything-zotero --json item move-to-collection REG67890 COLLAAAA --all-other-collections --experimental--from可重复指定多个来源收藏集--all-other-collections表示加入目标后移除其他所有收藏集归属。安全规则Zotero 必须关闭--experimental为必传确认标志_require_experimental_flag会在缺失时直接报错见 zotero_cli.py写入前 harness 自动备份zotero.sqlite命令在单个事务中执行失败自动回滚仅支持本地用户库。语义add-to-collection只追加一条收藏集归属move-to-collection添加目标归属并移除指定来源的归属。交互式 REPL不带子命令直接运行即进入有状态 REPLcli-anything-zotero内置命令zotero_cli.pyhelp、exit/quitcurrent-library、current-collection、current-itemuse-library id-or-Lid、use-collection id-or-key、use-item id-or-keyuse-selected读取并持久化 Zotero 中选中的收藏集clear-library、clear-collection、clear-itemstatus、history [limit]、state-pathREPL 支持命令别名展开expand_repl_aliases_with_state任意输入行会被shlex.split后重新调度到同一套 CLI 命令session use-library 1与session use-library L1等价都会持久化归一化后的libraryID。测试与验证模块自带完整测试套件testspy -m pip install -e . py -m pytest cli_anything/zotero/tests/test_core.py -v py -m pytest cli_anything/zotero/tests/test_cli_entrypoint.py -v py -m pytest cli_anything/zotero/tests/test_agent_harness.py -v py -m pytest cli_anything/zotero/tests/test_full_e2e.py -v -s为验证安装态行为可设置CLI_ANYTHING_FORCE_INSTALLED1后重跑 entrypoint 相关测试。可选的实机写测试需要显式开启set CLI_ANYTHING_ZOTERO_ENABLE_WRITE_E2E1 set CLI_ANYTHING_ZOTERO_IMPORT_TARGETcollection-key-or-id py -m pytest cli_anything/zotero/tests/test_full_e2e.py -v -s已知限制item analyze依赖OPENAI_API_KEY与显式模型名search items、item export、item citation、item bibliography需要启用 Local APInote add依赖 connector 行为要求 Zotero UI 停留在父条目所在库实验性收藏集写命令刻意不作为稳定的 Zotero API 呈现不支持saveSnapshot导入时的 PDF 附件支持但既有条目任意附件上传不在范围无 Word 处理器集成事务客户端不在 Zotero 内部执行特权 JavaScript。版本当前版本为 0.1.0见 SKILL.md 与init.py。【免费下载链接】CLI-AnythingCLI-Anything: Making ALL Software Agent-Native -- CLI-Hub: https://clianything.cc/项目地址: https://gitcode.com/GitHub_Trending/cl/CLI-Anything创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考