sevdesk-agent-cli
使用时机
当任务涉及从当前工作空间访问Sevdesk API时使用此技能,尤其是当代理必须:
- 通过只读端点检查业务/会计状态;
- 搜索联系人、发票、凭证或交易,而不临时拼凑原始API过滤器;
- 通过类型化工作流创建或更新联系人、报价单、发票和凭证;
- 将凭证与银行交易匹配,并准备或执行记账;
- 快速执行写端点,同时保持对DELETE操作的显式保护;
- 生成上下文快照供后续代理运行使用。
前提条件
- 确保CLI在每台机器上全局可用(位于
PATH):- 推荐:
npm install -g @codecell-germany/sevdesk-agent-skill - Codex引导辅助:
npx -y -p @codecell-germany/sevdesk-agent-skill sevdesk-agent-skill install --force - 验证:
sevdesk-agent --help
- 推荐:
- 如果安装后仍然找不到
sevdesk-agent:- 检查npm全局前缀:
npm config get prefix - 如有需要,将
<prefix>/bin添加到当前shell的PATH中
- 检查npm全局前缀:
- 无需全局安装的临时回退方案:
npx -y -p @codecell-germany/sevdesk-agent-skill sevdesk-agent --help
- 对于支持技能的代理环境,显式安装技能载荷:
sevdesk-agent-skill install --force
- API令牌需要在环境变量中可用:
SEVDESK_API_TOKEN=<token>
- 可选环境变量:
SEVDESK_BASE_URL(默认值https://my.sevdesk.de/api/v1)SEVDESK_USER_AGENT
SEVDESK_ALLOW_WRITE=true(仅DELETE操作需要,除非使用--allow-write)
首次运行检测
在机器上执行第一个真实记账工作流之前,运行以下命令:
sevdesk-agent --help
sevdesk-agent doctor --json
sevdesk-agent read bookkeepingSystemVersion --output json
如果出现以下任一情况,则视为环境未就绪:
sevdesk-agent不在PATH上SEVDESK_API_TOKEN缺失doctor报告检查失败- 无法成功读取
bookkeepingSystemVersion
如果设置不完整,请先安装公共包,验证令牌,然后才能继续执行read、find-*或写入工作流。
核心工作流
- 发现操作ID:
sevdesk-agent ops list --read-onlysevdesk-agent op-show <operationId>sevdesk-agent ops-quirks- 稳定的解析器输出:
sevdesk-agent ops-quirks --json-array
- 首先执行读调用:
sevdesk-agent read <operationId> --query key=valuesevdesk-agent read find-contact --query term="<name>" --output json(顶层find-contact的别名)sevdesk-agent read resolve-billing-contact --query term="<name>" --output json(辅助命令的别名)sevdesk-agent read find-invoice --query term="<text>" --query deepScan=true --output json(辅助命令的别名)sevdesk-agent read find-transaction --query amount=119 --query booked=false --output json(辅助命令的别名)sevdesk-agent read match-transaction --query voucherId=<id> --output json(辅助命令的别名)- 本地联系人搜索辅助:
sevdesk-agent find-contact <term> --output json - 计费辅助:
sevdesk-agent resolve-billing-contact <term> --output json - 发票文本搜索:
sevdesk-agent find-invoice <term> --deep-scan --output json - 交易搜索:
sevdesk-agent find-transaction "<text>" --amount <n> --booked false --output json - 凭证到交易匹配:
sevdesk-agent match-transaction --voucher-id <id> --output json - 语义交易匹配:
sevdesk-agent transaction find-match --supplier "<name>" --amount <n> --date <yyyy-mm-dd> --direction expense --output json - 凭证检查:
sevdesk-agent voucher inspect --id <id> --output json - 默认情况下,读响应会针对已知的实时API异常进行标准化处理
- Shell引用:像
contact[id]这样的参数应加引号:--query 'contact[id]=123' - 发票日期过滤器(观察所得):在我们的测试中,
getInvoices支持startDate/endDate作为Unix时间戳(秒)。ISO日期如2026-01-01可能返回空结果。 示例:sevdesk-agent read getInvoices --query startDate=1767225600 --query endDate=1769903999 --output json - 生成完整的读操作参考文档:
sevdesk-agent docs read-ops --output knowledge/READ_OPERATIONS.md
- 对于写调用:
POST/PUT/PATCH:sevdesk-agent write <operationId> ...- 便捷实体编辑:
sevdesk-agent order edit --order-id <id> ... --verifysevdesk-agent contact edit --contact-id <id> ... --verify
- 可用的multipart写入,使用
--form-field key=value和--form-file file=/path/to/file DELETE:sevdesk-agent write <operationId> --execute --confirm-execute yes --allow-write ...- 对于
createContact/createOrder,默认执行本地预检验证 - 对于
createInvoiceByFactory,预检还会验证发票/交货日期一致性(提供--auto-fix-delivery-date) - 对于
voucherFactorySaveVoucher和bookVoucher,本地预检会在API调用前验证高风险会计字段 - 添加
--verify以执行只读写后检查(包括createInvoiceByFactory、voucherFactorySaveVoucher和bookVoucher) - 对于createContact工作流,优先使用
--verify-contact(包括客户编号不匹配检查;默认启用了自动修复,可以通过--no-fix-contact禁用)
- 持久化代理交接上下文:
- stdout(默认):
sevdesk-agent context snapshot - 可选文件导出:
sevdesk-agent context snapshot --output .context/sevdesk-context-snapshot.json
- stdout(默认):
标准操作手册:联系人 + 报价单 + PDF
- 发现:
sevdesk-agent ops list --read-onlysevdesk-agent op-show createContactsevdesk-agent op-show createOrder
- 查找/创建联系人:
sevdesk-agent find-contact "<name or customerNumber>" --output jsonsevdesk-agent write createContact ... --verify-contact
- 创建报价单:
sevdesk-agent write createOrder ... --verify
- PDF导出且无状态副作用:
sevdesk-agent read orderGetPdf --path orderId=<id> --decode-pdf output/<file>.pdf --suppress-content- 默认设置
preventSendBy=1(--no-safe-pdf禁用此功能)
- 交接:
sevdesk-agent context snapshot --include-default
其他发票辅助工具
- 从现有发票创建分期付款:
sevdesk-agent create-invoice-installment --from-invoice <id> --percent 70 --label "..." [--execute --verify]
- 为重复工作流克隆发票:
sevdesk-agent invoice clone --from <id> --date <...> --period <...>支持选择性位置覆盖
- 当通用发票变更不可用时的安全发票替换:
sevdesk-agent invoice recreate --from <id> --patch-file payloads/invoice.patch.json --verify
- 从本地PDF录入凭证:
sevdesk-agent create-voucher-from-pdf --file /absolute/path/to/beleg.pdf ... [--execute --verify]
- 凭证记账辅助工具:
sevdesk-agent voucher inspect --id <id> --output jsonsevdesk-agent voucher book-existing --voucher-id <id> --transaction-id <id> [--execute --verify]sevdesk-agent book-voucher --voucher-id <id> --check-account-id <id> --amount <n> [--transaction-id <id>] [--execute --verify]sevdesk-agent assign-voucher-to-transaction --voucher-id <id> --check-account-id <id> --transaction-id <id> --amount <n> [--execute --verify]sevdesk-agent expense process-paid --file /absolute/path/to/beleg.pdf --transaction-id <id> ... [--execute --verify]
- 自检和命令同步:
sevdesk-agent doctor --json
安全保障
- 默认行为对工作流友好:
POST/PUT/PATCH直接执行;DELETE在设置保护标志之前被阻止。 - 在生产工作流中,优先执行只读测试和只读探测。
- 对于
*GetPdf端点,响应通常是JSON格式,包裹在data.objects中(通常包含filename、mimetype和base64编码的content)。 - 对于
orderGetPdf/invoiceGetPdf,CLI默认应用preventSendBy=1(安全PDF模式)。 - 使用
--decode-pdf <path>直接输出PDF文件,无需jq/base64。 - 使用
--decode-pdf时,请使用--suppress-content(默认值)将大的base64载荷排除在CLI输出之外。 - 默认情况下,
create-voucher-from-pdf、book-voucher和assign-voucher-to-transaction为试运行模式;只有使用--execute才会执行真实写入。 voucher book-existing和expense process-paid默认也为试运行模式;仅在检查派生载荷后使用--execute。order edit、contact edit和invoice recreate像普通PUT/POST流程一样直接执行;使用--verify立即验证结果。- 当写入响应或内置验证返回
ok: false时,CLI现在会以非零Shell状态退出。不要在自动化中将其视为成功。 - 如果服务器返回非JSON二进制内容类型(pdf/xml/zip/csv),CLI将打印元数据(
binary、bytes、contentType)而不是原始字节。 - 对选定操作强制执行运行时必需的查询异常(例如
contactCustomerNumberAvailabilityCheck在运行时需要customerNumber)。 - 使用
op-show或ops-quirks查看特定操作的运行时异常。 ops-quirks --json返回一个对象映射;要获得稳定的数组解析,请使用ops-quirks --json-array。- 如果需要发票变更指导,但
updateInvoice缺失,请运行sevdesk-agent docs invoice-edit。 - 如果需要更改发票内容,优先使用
sevdesk-agent invoice recreate --from <id> ...,而不是猜测原始的updateInvoice载荷。 - 关于创建发票后的编号/定稿顺序,请运行
sevdesk-agent docs invoice-finalize。
参考
- 命令速查表:
references/command-cheatsheet.md - 报价单/订单写入说明(实时行为):
knowledge/SEVDESK_ORDER_WRITE_LEARNINGS.md