思源笔记任务管理自动化助手
简介
基于 SiYuan API 的自动化任务管理方案,通过 Python 脚本实现任务创建、状态追踪与文档关联,让本地知识库的任务管理更高效有序。
原始描述
Manage tasks in SiYuan Note via its HTTP API. Create, query, update, and organize tasks stored in the 任务清单 document (with a TASK database) and sub-documents for related materials. Use when the user mentions SiYuan, task management, or needs to track work items.
通过你的 Agent 添加
安装目录:siyuan-task/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
siyuan-task-skill 是一个专为思源笔记(SiYuan Note)设计的任务管理自动化工具,通过调用 SiYuan HTTP API 实现任务的全生命周期管理。
初始化配置:用户需编辑 config.env 配置 SiYuan 实例地址、API Token 和笔记本名称,然后运行 python3 task_ops.py init 自动创建「任务清单」文档及 TASK 数据库(属性视图)。
任务数据模型:任务以数据库行形式存储,包含任务名称(主键/关联子文档)、任务内容、相关方、重要程度、紧急程度、状态、备注、时间戳等10个字段。每个任务自动创建同名子文档,含「任务描述」「任务附件」「下一步」三段式模板。
CLI 操作:create 创建任务(自动建子文档)、list 列出全部任务、find 按状态筛选、start/complete/suspend 状态流转、rename 重命名(同步子文档)、attach-image 插入图片、delete 删除(级联子文档)。
程序化调用:可直接导入 TaskManager 类,在 Python 脚本中集成复杂工作流,如批量创建、状态自动化流转等。
显著优点
- 零依赖安全架构:仅使用 Python 标准库(urllib、json、pathlib),无第三方包引入,彻底规避供应链攻击风险
- 数据完全私有:所有任务数据存储于用户自管的 SiYuan 实例,零外部传输,符合隐私合规要求
- 双模型设计:数据库视图支持筛选统计,子文档支持富文本编辑与附件管理,兼顾结构化与灵活性
- 自动化关联:任务与子文档自动绑定,重命名、删除操作级联同步,减少人工维护成本
- 配置外部化:API 凭证与端点通过环境文件管理,无硬编码敏感信息
潜在缺点与局限性
- 网络依赖:需稳定连接 SiYuan 实例,离线状态无法操作
- HTTP 默认风险:默认配置使用明文 HTTP,内网环境虽可接受,但公网部署需额外配置 HTTPS
- 无权限管控:一旦获取 API Token,即可全权操作笔记本,缺乏细粒度 RBAC
- 状态流转硬编码:start/complete/suspend 为固定状态机,不支持自定义工作流
- 子文档模板固定:三段式模板不可配置,特殊场景需手动调整
适合人群
- 思源笔记重度用户,需在笔记系统内统一管理任务与知识
- 追求数据隐私、拒绝 SaaS 任务管理工具的个人或团队
- 开发者/技术用户,希望将任务管理集成到自动化工作流
- 本地优先(LoCal-first) 软件理念践行者
常规风险
风险项
说明
缓解措施
Token 泄露
config.env 明文存储 API Token
设置 600 权限、不提交 Git、定期轮换
中间人攻击
HTTP 传输无加密
内网/VPN 部署或启用 HTTPS
来源可信度
T3 个人开发者维护
关注更新动态、必要时 Fork 自维护
级联删除误操作
delete 命令同时删除子文档
操作前确认 row_id、建议先备份
- 网络依赖:需稳定连接 SiYuan 实例,离线状态无法操作
- HTTP 默认风险:默认配置使用明文 HTTP,内网环境虽可接受,但公网部署需额外配置 HTTPS
- 无权限管控:一旦获取 API Token,即可全权操作笔记本,缺乏细粒度 RBAC
- 状态流转硬编码:start/complete/suspend 为固定状态机,不支持自定义工作流
- 子文档模板固定:三段式模板不可配置,特殊场景需手动调整
适合人群
- 思源笔记重度用户,需在笔记系统内统一管理任务与知识
- 追求数据隐私、拒绝 SaaS 任务管理工具的个人或团队
- 开发者/技术用户,希望将任务管理集成到自动化工作流
- 本地优先(LoCal-first) 软件理念践行者
常规风险
风险项
说明
缓解措施
Token 泄露
config.env 明文存储 API Token
设置 600 权限、不提交 Git、定期轮换
中间人攻击
HTTP 传输无加密
内网/VPN 部署或启用 HTTPS
来源可信度
T3 个人开发者维护
关注更新动态、必要时 Fork 自维护
级联删除误操作
delete 命令同时删除子文档
操作前确认 row_id、建议先备份
| 风险项 | 说明 | 缓解措施 |
|---|---|---|
| Token 泄露 | config.env 明文存储 API Token | 设置 600 权限、不提交 Git、定期轮换 |
| 中间人攻击 | HTTP 传输无加密 | 内网/VPN 部署或启用 HTTPS |
| 来源可信度 | T3 个人开发者维护 | 关注更新动态、必要时 Fork 自维护 |
| 级联删除误操作 | delete 命令同时删除子文档 | 操作前确认 row_id、建议先备份 |
安全认证综合评分 89 分(A 级),属标准安全级别,适合日常使用。
技能正文
name: siyuan-task
description: Manage tasks in SiYuan Note via its HTTP API. Create, query, update, and organize tasks stored in the 任务清单 document (with a TASK database) and sub-documents for related materials. Use when the user mentions SiYuan, task management, or needs to track work items.
compatibility: Requires Python 3.7+ and network access to SiYuan Note instance.
metadata:
author: walter
version: "1.0"
allowed-tools: Bash(python3:*)
SiYuan Note Task Management
Manage tasks in SiYuan Note (思源笔记) via Python scripts. All connection settings are in config.env — modify that file when the SiYuan instance address or credentials change.
Configuration
Edit config.env in the skill root directory. Only 3 items need manual configuration:
SIYUAN_API_URL=http://100.64.0.11:52487
SIYUAN_API_TOKEN=xxxxxxxxxxxxxxxx
SIYUAN_NOTEBOOK_NAME=work
Note: SIYUAN_NOTEBOOK_ID is auto-resolved from SIYUAN_NOTEBOOK_NAME at runtime. You can still set it explicitly to skip the lookup.
Then run init to auto-create the database and write remaining config:
cd <skill_root>/scripts
python3 task_ops.py init
This creates the 任务清单 document, the TASK database, all columns, and writes AV_ID / COL_* IDs back to config.env automatically. If the 任务清单 document already contains a TASK database (e.g. copied from another notebook), init will detect and reuse it instead of creating a duplicate.
Task Data Model
Tasks are stored as rows in a TASK database (Attribute View) block inside the 任务清单 document. Each row has these columns:
| Column | Chinese | Type | Values / Colors |
|---|---|---|---|
| 主键 | 任务名称 | block | Primary key — task name |
| 任务内容 | 任务内容 | text | Task description / details (what the task is about) |
| 相关方 | 相关方 | text | Free text |
| 重要程度 | 重要程度 | select | 高(红) / 中(绿) / 低(灰) |
| 紧急程度 | 紧急程度 | select | 高(红) / 中(绿) / 低(灰) |
| 状态 | 状态 | select | 未开始(灰) / 进行中(绿) / 结束(红) / 挂起(蓝) |
| 备注 | 备注 | text | Extra notes / supplementary remarks (not the main task info) |
| 创建时间 | 创建时间 | created | Auto |
| 开始时间 | 开始时间 | date | Timestamp |
| 结束时间 | 结束时间 | date | Timestamp |
| 更新时间 | 更新时间 | updated | Auto |
Database IDs (auto-generated in config.env by init command):
AV_ID— Attribute View IDAV_BLOCK_ID— AV block IDCOL_*— Column IDs for each field
Each task automatically gets a sub-document under /任务清单/{task_name} with this template:
# 任务描述
# 任务附件
# 下一步
The sub-document name always matches the task name. The task's primary key in the database is linked to the sub-document (non-detached), showing a document icon. Renaming a task also renames its sub-document. Deleting a task also deletes its sub-document.
Scripts
All scripts are in the scripts/ directory. Run from that directory:
cd <skill_root>/scripts
siyuan_api.py — Base API Client
Low-level client wrapping all SiYuan HTTP API endpoints. Used by task_ops.py internally. Can also be imported directly for custom operations:
from siyuan_api import SiYuanClient
client = SiYuanClient()
result = client.sql_query("SELECT * FROM blocks WHERE type = 'd' LIMIT 5")
Key methods: sql_query, create_doc, append_block, update_block, delete_block, set_block_attrs, get_block_attrs, get_child_blocks, get_block_kramdown, export_md, upload_asset, push_msg. See references/API.md for full SiYuan API reference.
task_ops.py — Task CRUD Operations
High-level CLI for task management. All commands output JSON.
Create a task (auto-creates sub-document with template):
python3 task_ops.py create "任务名称" content="任务内容" importance="高" urgency="中" notes="备注信息"
Parameter mapping:
content→ 任务内容 (task description / main information about the task)notes→ 备注 (supplementary remarks, not the main task info)stakeholders→ 相关方importance→ 重要程度 (高/中/低)urgency→ 紧急程度 (高/中/低)status→ 状态 (default: 未开始)
List all tasks:
python3 task_ops.py list
Find tasks by status:
python3 task_ops.py find "进行中"
Change task status (pass row_id from list output):
python3 task_ops.py start <row_id>
python3 task_ops.py complete <row_id>
python3 task_ops.py suspend <row_id>
Rename a task (also renames sub-document):
python3 task_ops.py rename <row_id> "新名称"
Attach image to task sub-document (uploads file and inserts into section):
python3 task_ops.py attach-image <row_id> /path/to/image.png
python3 task_ops.py attach-image <row_id> /path/to/image.png section="任务描述"
Default section is 任务附件. On macOS, save clipboard image first: osascript -e 'set png to (the clipboard as «class PNGf»)' -e 'set f to open for access (POSIX file "/tmp/clip.png") with write permission' -e 'write png to f' -e 'close access f'
List sub-documents:
python3 task_ops.py list-docs
Delete a task (also deletes sub-document):
python3 task_ops.py delete <row_id>
Migrate database (apply schema changes and reorder columns):
python3 task_ops.py migrate
Programmatic Usage
For complex workflows, import TaskManager directly in Python:
import sys; sys.path.insert(0, "<skill_root>/scripts")
from task_ops import TaskManager
tm = TaskManager()
# Create task (auto-creates sub-document with template)
result = tm.create_task("实现用户登录", content="OAuth2 集成", importance="高", urgency="高")
row_id = result["row_id"]
doc_id = result["doc_id"]
# Rename task (also renames sub-document)
tm.rename_task(row_id, "实现OAuth2登录")
# Status transitions
tm.start_task(row_id)
tm.complete_task(row_id)
# Delete task (also deletes sub-document)
tm.delete_task(row_id)
# Attach image to task sub-document (default section: 任务附件)
tm.attach_image_to_task(row_id, "/path/to/image.png")
tm.attach_image_to_task(row_id, "/path/to/image.png", section="任务描述")
Important Notes
- The 任务清单 document and TASK database are auto-created on first use
- Tasks are stored as database rows (Attribute View), not plain blocks
row_id from list output is used for all update/delete operations
创建时间 and 更新时间 columns are auto-managed by SiYuan
- Block references use SiYuan format:
((<block_id> "anchor text"))
- All API responses have
code field — 0 means success
row_id from list output is used for all update/delete operations创建时间 and 更新时间 columns are auto-managed by SiYuan((<block_id> "anchor text"))code field — 0 means success正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。