cli-anything-zotero:让 Zotero 桌面端全面 Agent 原生的命令行工具链

cli-anything-zotero:让 Zotero 桌面端全面 Agent 原生的命令行工具链 cli-anything-zotero让 Zotero 桌面端全面 Agent 原生的命令行工具链【免费下载链接】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 原生命令行工具harness。它不重新实现 Zotero而是组合 Zotero 真实存在的本地能力层SQLite 离线只读清单、connector 端点的 GUI 状态感知与官方写入流程、Local API 的实时检索与 CSL 渲染以及一组带明确安全护栏的实验性 SQLite 写入命令。读完本文你将掌握如何安装与调用该工具、理解其背后四层架构与约束、用一条条可复制的命令完成文献导入、检索、笔记、导出、引文渲染与 LLM 上下文构建等完整工作流。本文基于仓库中的 skills/cli-anything-zotero/SKILL.md 展开并参考配套的 zotero/agent-harness/ZOTERO.md、zotero/agent-harness/cli_anything/zotero/README.md 与源码实现进行深化。设计哲学组合真实表面而非重写 Zoterocli-anything-zotero的核心定位是一条 Agent 原生的 Zotero CLI。它不做的事与做的事同样重要不重写 Zotero不重新实现翻译器translator或 citeproc 引擎组合真实本地表面把 Zotero 桌面端已经存在的能力SQLite 数据库、connector HTTP 服务、Local API通过 CLI 编排起来默认策略保守只要存在官方 Zotero 表面就优先使用非官方的写入能力一律隔离在显式--experimental标志之后。从源码结构看这一设计直接体现在 zotero/agent-harness/cli_anything/zotero/zotero_cli.py 的 Click 命令分组app/collection/item/search/tag/style/import/note/session以及core与utils两个子包的分工上core/catalog.py负责读路径core/imports.py负责 connector 写路径core/rendering.py负责 Local API 渲染core/experimental.py负责实验性 SQLite 写入。安装与入口安装要求Python 3.10 及以上见 zotero/agent-harness/setup.py 中python_requires3.10已安装 Zotero 桌面端存在可用的本地 Zotero profile 与数据目录。Windows 下的主要验证安装路径为C:\Program Files\Zotero对应 Zotero 7.0.32 的app/omni.ja内部源码锚点。安装命令pip install -e .若安装后cli-anything-zotero不在 PATH 中Python Scripts 目录未加入 PATH 的常见情况可退而使用模块入口python -m cli_anything.zotero --help两个入口等价setup.py中通过entry_points将cli-anything-zotero指向cli_anything.zotero.zotero_cli:entrypoint。顶层选项根命令支持若干影响全局行为的选项见 zotero_cli.py选项默认值说明--json关输出机器可读 JSONAgent 工作流推荐--backendautoauto/sqlite/api之一--data-dir自动发现显式指定 Zotero 数据目录--profile-dir自动发现显式指定 Zotero profile 目录--executable自动发现显式指定 Zotero 可执行文件路径重要约束先看清楚边界SKILL 文档明示了以下关键约束它们直接决定了哪些命令何时可用、为什么可用search items、item export、item citation、item bibliography需要启用 Zotero 的 Local APInote add依赖实时运行的 Zotero GUI 上下文并且要求应用内当前选中库与父条目所在库一致导入时段的 PDF 附件上传仅限同一 connector 会话内创建的条目任意既有条目的附件上传仍不在范围内实验性 SQLite 写入命令仅限本地、仅限用户库属于不稳定的高级操作若一个裸 key 在多个库中重复需先执行session use-library id再执行后续命令否则 CLI 会抛出歧义错误。架构Zotero 的四层本地能力从 zotero/agent-harness/ZOTERO.md 的架构说明看该 harness 将 Zotero 视为一个分层桌面系统SQLite本地清单与离线读取库、集合、条目、子笔记、附件、标注、标签、已存搜索、样式connector 端点GUI 感知状态与官方写入流程活动检测、选中集合读取、文件/JSON 导入、附件上传、子笔记创建、会话重定向与打标Local API 端点实时搜索、CSL 渲染、翻译器驱动的导出、已存搜索执行实验性 CLI-only SQLite 写入少数本地库管理任务建集合、条目归档/搬移。后端职责速览后端用途行为要点SQLite库/集合/条目/笔记/附件/标注/标签/搜索/样式清单常规只读使用moderoimmutable1实验性写操作使用独立的事务型可写连接Connector存活检测、选中集合、导入、导入期附件、子笔记、会话重定向要求 Zotero 运行中写入行为依赖 GUI 实时状态Local API关键词搜索、引文/参考文献渲染、导出、已存搜索要求 Zotero 运行中且 Local API 已启用用户库与群组库路由自动切换对 citeproc 与翻译器导出无本地假实现OpenAI可选的item analyze需要OPENAI_API_KEY与显式--modelZotero 关键常量来自 Zotero 7.0.32默认 HTTP 端口23119Local API 预置项默认值extensions.zotero.httpServer.localAPI.enabled falseZotero 7 默认关闭需显式开启connector 存活端点/connector/ping选中集合端点/connector/getSelectedCollection官方 connector 写端点/connector/import、/connector/saveItems、/connector/saveAttachment、/connector/updateSession。以上端点常量可直接在 zotero/agent-harness/cli_anything/zotero/utils/zotero_http.py 中一一印证例如connector_save_attachment会向/connector/saveAttachmentPOST PDF 字节流并在X-Metadata头中携带sessionID、parentItemID、title、url。启用 Local API一条命令搞定Local API 是搜索、引文、参考文献与导出命令的前提。推荐使用 CLI 路径cli-anything-zotero --json app enable-local-api cli-anything-zotero --json app enable-local-api --launch该命令会解析当前活动 Zotero profile → 向该 profile 的user.js写入extensions.zotero.httpServer.localAPI.enabledtrue→ 报告该预置项此前是否已启用 → 可选地启动 Zotero 并验证 connector 与 Local API 就绪。手动路径则是向活动 profile 的user.js添加一行后重启 Zoterouser_pref(extensions.zotero.httpServer.localAPI.enabled, true);验证cli-anything-zotero --json app status cli-anything-zotero --json app pingapp status应显示local_api_enabled_configured: trueZotero 运行后local_api_available: true。底层实现中zotero_http.local_api_is_available会请求/api/根路径并携带Zotero-API-Version: 3头LOCAL_API_VERSION 3返回 403 时明确报告local API disabled而不是含糊其辞。命令组全景App运行时检查命令说明是否需要 Zotero 运行后端status展示运行路径与各后端可用性否discoveryversion展示 harness 与 Zotero 版本否discoverylaunch启动 Zotero 并等待存活否executable connectorenable-local-api在user.js中启用 Local API否prefs writeping检查 connector 存活是connectorCollection集合检查与选择命令说明是否需要 Zotero 运行后端list列出集合否SQLitefind query按名称查找集合否SQLitetree展示嵌套集合结构否SQLiteget ref读取单个集合ID 或 key否SQLiteitems ref读取集合下条目否SQLiteuse-selected将 GUI 选中集合持久化到会话是connectorcreate name --experimental本地创建集合需 Zotero 关闭否Zotero 必须关闭experimental SQLiteItem条目检查与渲染命令说明是否需要 Zotero 运行后端list列出顶层条目否SQLitefind query关键词/标题查找推荐Local API SQLiteget ref读取单个条目否SQLitechildren ref读取所有子记录笔记/附件/标注否SQLitenotes ref只读子笔记否SQLiteattachments ref读取附件并解析storage:路径否SQLitefile ref解析单个附件文件路径否SQLiteexport ref --format fmt翻译器驱动的导出是Local APIcitation refCSL 引文渲染是Local APIbibliography refCSL 参考文献渲染是Local APIcontext ref构建结构化 LLM 上下文可选SQLite 可选 Local APIanalyze ref调用 OpenAI 分析API key 必需OpenAI 本地上下文add-to-collection ... --experimental追加集合归属否Zotero 必须关闭experimental SQLitemove-to-collection ... --experimental在集合间搬移条目否Zotero 必须关闭experimental SQLiteSearch已存搜索命令说明是否需要 Zotero 运行后端list列出已存搜索否SQLiteget ref读取单个已存搜索定义否SQLiteitems ref执行已存搜索是Local APITag标签命令说明后端list列出标签及条目计数SQLiteitems tag读取某个标签下的条目SQLiteStyleCSL 样式命令说明后端list读取已安装的 CSL 样式本地数据目录解析.csl文件Import官方导入与写入命令说明是否需要 Zotero 运行后端file path通过 Zotero 翻译器导入是connectorjson path保存官方 connector JSON 条目是connectorimport file支持可选的--attachments-manifest边车文件import json支持条目内联attachments数组。两者共同的选项还包括可重复的--tag导入后打标、--attachment-delay-ms默认 0URL 附件下载前延迟与--attachment-timeout默认 60 秒。Note子笔记读写命令说明是否需要 Zotero 运行后端get ref读取单条笔记否SQLiteadd item-ref创建子笔记是connectorSession会话与 REPL 上下文命令说明status展示当前会话状态use-library id持久化当前库1与L1等价统一归一化为libraryIDuse-collection ref持久化当前集合use-item ref持久化当前条目use-selected读取并持久化 Zotero 中选中的集合clear-library/clear-collection/clear-item清除对应上下文history展示近期命令历史实战示例从状态检查到 LLM 上下文1. 运行时状态检查cli-anything-zotero app status --json输出包含 profile、数据目录、SQLite 路径、connector 与 Local API 可用性等字段。2. 读取 GUI 中选中的集合cli-anything-zotero collection use-selected --json将 Zotero GUI 中当前选中的集合持久化到会话后续命令无需再显式传集合引用。3. 渲染引文cli-anything-zotero item citation item-key --style apa --locale en-US --json借助 Zotero 自己的 CSL 引擎Local API渲染引文支持--style、--locale、--linkwrap参数。4. 添加子笔记cli-anything-zotero note add item-key --text Key takeaway --json底层走 connector 的/connector/saveItems官方写入流程。text与markdown会先转换为安全 HTML 再提交html则原样透传。该版本仅支持子笔记独立笔记有意未纳入。5. 构建 LLM 上下文cli-anything-zotero item context item-key --include-notes --include-links --json聚合条目字段、创建者与标签、附件、可选笔记、可选导出如 BibTeX/CSL JSON、可选 DOI/URL 链接并输出一个可直接投喂任何 LLM 的prompt_context文本块。这是官方推荐的、模型无关的稳定 AI 接口对应core/analysis.py的build_item_context。端到端工作流图谱以下工作流均来自 zotero/agent-harness/ZOTERO.md 的 Workflow Map并可在 README 的 Workflow Guide 中看到完整命令细节导入文献到指定集合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 90目标解析顺序Zotero 运行时显式--collection→ 会话集合 → GUI 选中集合 → 用户库。导入期附件行为有严格约定仅上传本次会话新建条目的附件本地文件与下载 URL 必须通过 PDF magic-byte%PDF-前缀校验同一导入条目的重复附件描述符按幂等跳过若元数据成功但部分附件失败命令返回status: partial_success并以非零退出码结束见_import_exit_code与imports.py中的_ensure_pdf_bytes。import json支持 harness 私有的内联附件数组[ { 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通过边车 manifest 支持同样的附件描述符[ { index: 0, expected_title: Embodied Intelligence Paper, attachments: [ { path: C:\\papers\\embodied.pdf, title: PDF } ] } ]查找一篇论文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 10item find的默认行为是优先走 Local API 的库感知路由用户库/api/users/0/...、群组库/api/groups/libraryID/...并把 Local API 返回的 key 反查回 SQLite保证结果始终带本地itemID与keyLocal API 不可用或无结果时回退到 SQLite 标题搜索--exact-title强制走 SQLite 精确匹配。读取集合或单条论文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纯 SQLite 路径Zotero 不必运行。典型用途查看集合下的论文、检查单篇论文的字段/创建者/标签、解析本地 PDF 路径供下游处理。读取与添加笔记cli-anything-zotero --json item notes REG12345 cli-anything-zotero --json note get NOTEKEY cli-anything-zotero --json note add REG12345 --text Key takeaway: ... cli-anything-zotero --json note add REG12345 --file .\summary.md --format markdownitem notes只列出论文的子笔记note get按条目 ID 或 key 读取单条笔记全文note add恒为指定论文创建子笔记且要求 Zotero 运行中、GUI 当前库与父条目所在库一致。导出与引文渲染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支持导出格式即源码中rendering.SUPPORTED_EXPORT_FORMATSris、bibtex、biblatex、csljson、csv、mods、refer。这些命令自动按用户库/群组库切换 Local API 作用域对 citeproc 与翻译器导出没有本地假实现。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-notesitem analyze在item context之上叠加模型调用构建同样的结构化上下文、自动附加链接、将问题与上下文发送至 OpenAI Responses API。它要求OPENAI_API_KEY且必须显式指定--model不隐藏缺上下文的不确定性。设计上它只是可选的 AI 路径官方推荐先走可移植的item context。实验性集合重构直接写 zotero.sqlitecli-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 --experimentalZotero 的官方 HTTP 表面覆盖了导入与笔记保存但未暴露通用集合创建与任意既有条目重归档因此该 harness 提供了一条窄口径的实验性 SQLite 写入路径core/experimental.py。安全护栏--experimental为必选项Zotero 必须关闭_require_offline会在 connector 可用时直接报错每次写入前自动备份zotero.sqlite每个操作在单事务内执行失败回滚仅支持本地用户库_require_user_library会检查library[type] ! user并拒绝。语义上add-to-collection是纯追加保留全部现有集合归属move-to-collection先确保目标归属存在再从--from指定集合或--all-other-collections覆盖的其他集合中移除归属没有显式来源选择时不会隐式删除。条目引用模型item get与item find为何分离item get是按itemID或key的精确查找item find是按关键词或标题的发现式检索。这种分离让查找稳定、脚本行为可预测。引用解析规则数字 ID 全局有效裸 key 仅在恰好匹配一个库时被接受若裸 key 命中多个库CLI 抛出歧义错误并提示调用者先执行session use-library id。笔记模型与 LLM 分析模型笔记模型item notes列出某篇论文下的子笔记不含附件与标注note get直接读取单条笔记记录适合在拿到item notes的 note key 后做后续脚本化处理note add本版本仅支持子笔记独立笔记有意排除text/markdown转安全 HTMLhtml原样接受。LLM 分析模型推荐稳定接口item context可移植聚合条目字段、创建者与标签、附件、可选笔记、可选导出BibTeX/CSL JSON、可选 DOI/URL 链接并提供现成的prompt_context可选直连接口item analyze在item context之上叠加大模型调用需要OPENAI_API_KEY与显式--model。背后依赖的 SQLite 表CLI 领域Zotero 表库libraries集合collections、collectionItems条目items、itemTypes字段与标题itemData、itemDataValues、fields创建者creators、itemCreators标签tags、itemTags笔记itemNotes附件itemAttachments标注itemAnnotations搜索savedSearches、savedSearchConditions这些表的只读访问封装在 zotero/agent-harness/cli_anything/zotero/utils/zotero_sqlite.py 中实验性写入含备份与单事务回滚也由该模块承载。REPL 交互模式不带子命令直接运行cli-anything-zotero即进入有状态 REPL内置命令包括help、exit、current-library、current-collection、current-item、use-library id-or-Lid、use-collection id-or-key、use-item id-or-key、use-selected、status、history、state-path。REPL 与会话命令共用同一份会话状态文件实现REPL 与一次性命令上下文互通。测试与验证单元与集成测试位于 zotero/agent-harness/cli_anything/zotero/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 py -m pytest cli_anything/zotero/tests/ -v --tbno可选的真实写入端到端测试需要显式开启环境变量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 凭证与网络search items、item export、item citation、item bibliography要求 Local APInote add依赖 connector 行为与 GUI 当前库上下文实验性 SQLite 写入命令是本地高级功能而非稳定的 Zotero API无saveSnapshot快照捕获能力支持导入期 PDF 附件上传但任意既有条目的附件上传仍不在范围内无字处理软件集成事务客户端无 Zotero 内特权 JavaScript 执行。总体而言cli-anything-zotero为 Agent 与自动化脚本提供了一个以 Zotero 官方能力为地基、以离线 SQLite 读取为补充、以显式实验开关兜底的稳健命令行界面。无论是单条命令的脚本化调用还是通过 REPL 与item context串联起导入 → 检索 → 阅读 → 笔记 → 导出 → 喂给 LLM的完整研究流水线它都保持了官方表面优先、保守默认、可验证输出的一致设计。【免费下载链接】CLI-AnythingCLI-Anything: Making ALL Software Agent-Native -- CLI-Hub: https://clianything.cc/项目地址: https://gitcode.com/GitHub_Trending/cl/CLI-Anything创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考