Skip to content

feat(skills): record skill install state in agent.db - #786

Merged
ace331 merged 3 commits into
mainfrom
feat/skills-registry
Sep 22, 2026
Merged

ace331 merged 3 commits into
mainfrom
feat/skills-registry

Conversation

@ace331

@ace331 ace331 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

概要

在 agent.db 新增 skills 表(schema v2 → v3),记录 skill 元数据:名称、当前版本号、是否已删除。删除后记录保留为墓碑(tombstone),使 future init 的内置技能自动安装不再把用户已删除的技能装回来;显式安装会清除墓碑。安装、删除、升级时自动维护。

表结构

CREATE TABLE IF NOT EXISTS skills (
    name TEXT PRIMARY KEY NOT NULL,      -- 技能名(= 安装目录名 = 目录 id)
    version TEXT,                        -- 当前版本号
    deleted INTEGER NOT NULL DEFAULT 0,  -- 墓碑标记
    installed_at_ms INTEGER,
    updated_at_ms INTEGER NOT NULL
);
时机 行为
安装 / 升级 upsert:更新 version,deleted = 0
删除 只置 deleted = 1,行与最后版本保留
自动安装(bootstrap) 跳过墓碑集合中的技能

各进程接入

  • agent:skills::registry 模块持有权威 DDL、守卫协议(application_id / user_version 校验,拒绝陌生库)和维护函数;session schema 批次纳入该表,v2 库打开时自动迁移到 v3。registry 新建的库(agent 从未启动过的机器)会被 agent 接受并补齐其余表。
  • cli:install_skill 成功后记录;uninstall_skill 先写墓碑再删目录(两步之间崩溃不会丢失标记,失败时文件原样可重试);install_builtin_skills 过滤墓碑。读 registry 失败只告警不阻断安装。
  • desktop:镜像的 write-only 实现(desktop 不链接 agent crate,沿用 replace_skill_dir 的"同协议双实现"模式),接入 install_and_refresh / uninstall_and_refresh(sqlite 操作走 spawn_blocking)。

跨进程安全:WAL + busy_timeout,registry 打开 agent.db 遵循与 agent 相同的识别规则;对已存在的 v2 库只加表不动版本号(新旧 agent 均可打开),由 agent 的 schema 批次负责迁移。

顺带修复

skill_commit_rolls_back… 测试存在既有竞态:drop(lock) 后立即重新 flock,而并行测试 spawn 的子进程(unzip)在 fork 瞬间持有锁 fd 副本,try_lock 会短暂误报冲突。已加 2 秒有界重试(已用独立探针程序复现确认根因,非本 PR 功能引入)。

测试

  • agent 1834 / cli 749 / desktop 1326 全部通过;cargo fmt + clippy 干净。
  • 新增覆盖:安装→升级→删除→重装的完整往返与版本保留、registry 建库被 agent 接受、v2→v3 迁移、拒绝陌生/超版本库、与运行中 agent 连接共存(WAL)、bootstrap 跳过墓碑、desktop 命令全流程断言。

Add a `skills` table (schema v3) to agent.db tracking each skill's
name, current version and a deleted flag. The row for an uninstalled
skill is kept as a tombstone so builtin bootstrap (`future init`)
does not re-install skills the user removed; an explicit install
clears the tombstone again.

- agent: skills::registry module owns the canonical DDL, guard
  protocol (application_id/user_version) and maintenance functions;
  the session schema batch includes the table and migrates v2
- cli: install/uninstall/update/builtin paths record outcomes; the
  tombstone is written before the directory is removed so a crash
  cannot lose the mark; bootstrap filters tombstoned ids
- desktop: mirrored write-only helper (the desktop must not link the
  agent crate) wired into install_and_refresh/uninstall_and_refresh

Also fixes a latent flake in the skill_commit test: a concurrently
spawned child process can hold a forked copy of a dropped flock for
an instant, so the final commit retries briefly instead of treating
the transient window as a competing installer.
@ace331
ace331 enabled auto-merge (squash) September 22, 2026 23:26
@ace331
ace331 merged commit 9a6ec1a into main Sep 22, 2026
12 checks passed
@ace331
ace331 deleted the feat/skills-registry branch September 22, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant