anarlog todo 插件权限系统完全指南Tauri 命令级权限配置与源码实现解析【免费下载链接】anarlogOpen source Granola AI Alternative项目地址: https://gitcode.com/GitHub_Trending/hy/anarlog本篇技术指南以 anarlog开源 Granola AI 替代方案桌面端 todo 插件为核心系统讲解其基于 Tauri 插件权限框架的命令级权限模型从默认权限集合、完整权限表到每条命令的底层实现与跨平台行为。读完本文你将掌握如何阅读与定制tauri-plugin-todo的权限配置并能结合源码理解每个权限标识符对应的实际命令能力。权限体系概述todo 插件crate 名tauri-plugin-todo见 plugins/todo/Cargo.toml在 anarlog 桌面端中承担统一待办/工单入口的职责它同时对接 Apple RemindersmacOS 原生提醒事项、Linear团队与工单和 GitHub Issues公开仓库 Issue/PR。由于这些能力横跨本地系统数据与第三方云服务插件采用 Tauri 的标准权限框架进行命令级管控——前端只能调用被显式允许的命令未被授权的命令直接无法发起。权限参考文档位于 plugins/todo/permissions/autogenerated/reference.md它是自动生成的文件其上游来源是 plugins/todo/permissions/autogenerated/commands/ 目录下的 13 个命令权限描述文件以及 plugins/todo/permissions/schemas/schema.json 中定义的权限 schema。每个命令权限文件如 fetch_todos.toml顶部都标注着# Automatically generated - DO NOT EDIT!说明这类文件由构建期工具tauri-plugin 的 build 能力见 Cargo.toml 中的[build-dependencies] tauri-plugin生成手动修改会被覆盖。默认权限集合插件在 plugins/todo/permissions/default.toml 中声明了默认权限集合。只要在宿主应用中注册该插件而未做额外配置以下 12 个allow-*权限会被默认授予allow-authorization-statusallow-request-full-accessallow-list-todo-listsallow-fetch-todosallow-read-pathallow-create-todoallow-complete-todoallow-delete-todoallow-linear-list-teamsallow-linear-list-ticketsallow-github-issue-stateallow-github-issue-detail对照权限参考文档可以注意到两个值得留意的细节默认集合不包含allow-ping。权限表reference.md 中todo:allow-ping/todo:deny-ping条目虽为ping命令生成了权限对但默认集合刻意没有放开它说明该命令属于可选能力需要宿主显式配置。默认集合覆盖三大数据源Apple 本地待办authorization-status、request-full-access、list-todo-lists、fetch-todos、create-todo、complete-todo、delete-todo、read-path、Linear 云工单linear-list-teams、linear-list-tickets、GitHub Issuegithub-issue-state、github-issue-detail。默认全部放行意味着插件的目标使用场景是开箱即用的完整待办能力。权限标识符采用{plugin-name}:{permission-identifier}的命名空间形式例如todo:allow-fetch-todos。宿主应用如需在默认集合基础上做收紧可在tauri.conf.json/ capabilities 文件中以最小权限原则显式列出所需权限并用deny-*条目覆盖默认的allow-*。权限表全解参考文档中的 Permission Table 覆盖 13 个命令的allow/deny权限对共 26 个标识符。下表整理为更易检索的矩阵形式行为描述与原文档一致命令Allow 权限标识符Deny 权限标识符启用行为authorization_statustodo:allow-authorization-statustodo:deny-authorization-status查询 Apple 待办授权状态request_full_accesstodo:allow-request-full-accesstodo:deny-request-full-access请求 Apple 待办完全访问权限list_todo_liststodo:allow-list-todo-liststodo:deny-list-todo-lists枚举 Apple 提醒事项列表fetch_todostodo:allow-fetch-todostodo:deny-fetch-todos按过滤器拉取 Apple 提醒事项read_pathtodo:allow-read-pathtodo:deny-read-path通过统一路径语法读取多源数据create_todotodo:allow-create-todotodo:deny-create-todo创建新的提醒事项complete_todotodo:allow-complete-todotodo:deny-complete-todo完成指定提醒事项delete_todotodo:allow-delete-todotodo:deny-delete-todo删除指定提醒事项linear_list_teamstodo:allow-linear-list-teamstodo:deny-linear-list-teams列出 Linear 团队集合linear_list_ticketstodo:allow-linear-list-ticketstodo:deny-linear-list-tickets列出 Linear 工单github_issue_statetodo:allow-github-issue-statetodo:deny-github-issue-state查询 GitHub Issue 状态github_issue_detailtodo:allow-github-issue-detailtodo:deny-github-issue-detail获取 GitHub Issue 详情需要指出的是权限表本身不含ping之外的其他遗漏项但从源码看存在一个有趣的不对称插件的命令注册表plugins/todo/src/lib.rs 中的make_specta_builder实际注册了 13 个命令其中包括github_issue_comments——而权限参考文档中并没有为它生成allow-github-issue-comments/deny-github-issue-comments权限对。这暗示该命令在权限框架下可能走默认放行或属于较新的扩展阅读权限文档时需对照 commands.rs 的命令清单交叉验证。权限背后的命令实现每条权限都与一个真实的 Tauri command 一一对应全部声明于 plugins/todo/src/commands.rs并统一通过tauri_specta::collect_commands!注册lib.rs同时由 specta 自动导出 TypeScript 绑定js/bindings.gen.ts前端入口见 js/index.ts。命令可按数据源分为三组Apple RemindersmacOS 专属以下命令全部通过anlg_apple_todocrate 的Handle操作 macOS 提醒事项并且在非 macOS 平台返回Error::UnsupportedPlatform见 commands.rs 的模式authorization_status()返回当前授权状态字符串如已授权/受限/未确定来自Handle::authorization_status()request_full_access()弹出系统授权流程返回是否取得完全访问权list_todo_lists()返回VecReminderListfetch_todos(filter)接收ReminderFilter过滤条件返回VecRemindercreate_todo(input)接收CreateReminderInput返回新提醒的标识符字符串complete_todo(target)/delete_todo(target)以ReminderIdentifierInput定位并完成/删除提醒。Linear / GitHub 云数据通过后端 API 代理linear_list_teams、linear_list_tickets、github_issue_state、github_issue_detail走两条不同的链路Linear 系列需要登录态。命令首先从tauri_plugin_auth插件获取 access tokencommands.rs 的require_access_token未认证时返回Auth(not authenticated)错误再通过anlg_api_client调用后端 APIapi_base_url在 lib.rs 中定义release 构建取VITE_API_URL环境变量debug 构建默认http://localhost:3001最终封装为CollectionPage/TicketPage分页结果fetch.rs。GitHub 系列走公开 API 直连、无需登录的路径。github_state.rs 中实现了一个仅支持GET的PublicGitHubHttpClientPOST/PUT/PATCH/DELETE 一律返回unsupported错误向https://api.github.com发起请求并携带application/vnd.githubjson与User-Agent: anarlog-desktop头对私有仓库的请求失败时调用方应回退到带鉴权的代理链路。resolve_state还会把带merged_at的 PR 判定为Merged状态因此github_issue_state的返回枚举为Open/Closed/Merged。read_path统一路径语法read_path(path, limit?, cursor?)是最具特色的命令它把三类数据源抽象为类文件系统的路径read_path.rs路径模式解析结果返回类型apple或apple/subpathAppleReminderLists/Reminderslinear/connection_id、linear/connection_id/teams、.../collectionsLinearTeamsCollectionslinear/connection_id/teams/team_id、.../ticketsLinearTicketsTicketsgithub/connection_id、.../repos、.../collectionsGithubReposCollectionsgithub/connection_id/repos/owner/repo、.../ticketsGithubTicketsTickets其他返回InvalidReadPath错误—路径解析容忍首尾多余的/并支持省略tickets/collections后缀的别名写法解析器的边界行为有完整单测覆盖read_path.rs例如linear/conn-1/teams/team-1与/linear/conn-1/teams/team-1/tickets/等价而linear缺少 connection_id或github/conn-1/repos/openai/char/pulls未知后缀会被拒绝。limit与cursor参数用于分页游标Linear/GitHub 分支会将二者透传给后端 API。平台限制与错误模型权限能否生效还受平台条件约束。authorization_status、request_full_access、list_todo_lists、fetch_todos、create_todo、complete_todo、delete_todo及read_path的apple分支都在非 macOS 上直接返回UnsupportedPlatform——即使权限被allow调用依然会失败。这一点对跨平台打包的宿主应用很重要权限只决定能不能调用平台决定调用是否成功。插件统一使用 error.rs 中定义的Error枚举包含AppleTodo、UnsupportedPlatform、InvalidReadPath、Auth、Api、Http、InvalidHeader等变体错误在序列化时以字符串形式暴露给前端且实现了specta::Type因此错误信息会进入自动生成的 TypeScript 类型体系前端可用instanceof-less 的字符串比对方式做错误分支。配置实践建议最小权限定制若宿主应用只使用 Apple 待办可将 capabilities 中的权限收窄为todo:allow-authorization-status、todo:allow-list-todo-lists、todo:allow-fetch-todos、todo:allow-create-todo、todo:allow-complete-todo、todo:allow-delete-todo、todo:allow-read-path并显式deny掉 Linear/GitHub 相关权限。留意自动生成文件default.toml、permissions/autogenerated/与reference.md均由构建期自动生成定制应改在宿主应用的 capability/ACL 配置中而非直接编辑这些文件。权限与命令清单联动以 lib.rs 的collect_commands!为准核对命令全集含github_issue_comments再对照 reference.md 的权限表避免因自动生成滞后而遗漏新命令的权限配置。运行环境前提debug 构建默认 API 地址为http://localhost:3001lib.rsrelease 构建需注入VITE_API_URLGitHub 公开 API 直连不需要 token但 Linear 系列命令依赖tauri-plugin-auth的登录态。通过本文的权限表与源码对照你可以准确判断每个todo:*权限标识符的实际能力边界、平台约束与调用链路为 anarlog 桌面端 todo 功能做精准的权限裁剪与排障。【免费下载链接】anarlogOpen source Granola AI Alternative项目地址: https://gitcode.com/GitHub_Trending/hy/anarlog创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
