ntn-skills 0.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.zh-CN.md CHANGED
@@ -1,190 +1,271 @@
1
1
  <h1 align="center">ntn-skills</h1>
2
-
3
- <p align="center">让 Agent 和终端用上你在 Notion 中维护的工作流。<br>先找到合适的 Skill,再读取指令,整项任务始终使用同一版本。</p>
4
-
2
+ <p align="center">基于 Notion 极简三表控制面与零延迟本地消费的 AI Agent 技能管理器。</p>
5
3
  <p align="center">
6
4
  <a href="./README.md">English</a> · <a href="./README.zh-CN.md">简体中文</a>
7
5
  </p>
8
-
9
- <p align="center">
10
- <a href="#安装">安装</a> · <a href="#快速开始">快速开始</a> · <a href="#常用场景">常用场景</a> · <a href="#接入-agent">接入 Agent</a> · <a href="./docs/README.md">文档</a>
11
- </p>
12
-
13
6
  <p align="center">
14
- <a href="./CHANGELOG.md"><img src="https://img.shields.io/badge/status-experimental-orange" alt="状态:实验性"></a>
15
- <a href="https://nodejs.org"><img src="https://img.shields.io/badge/runtime-Node.js%20%3E%3D%2022.19.0-green" alt="运行时:Node.js >= 22.19.0"></a>
16
- <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="许可证:MIT"></a>
7
+ <a href="#快速开始">快速开始</a> ·
8
+ <a href="#双视角工作流">双视角工作流</a> ·
9
+ <a href="#命令速查">命令速查</a> ·
10
+ <a href="#安全与数据边界">安全与数据边界</a> ·
11
+ <a href="./INSTALL.md">Agent 安装协议 (<code>INSTALL.md</code>)</a> ·
12
+ <a href="./assets/ntn-skills/SKILL.md">内置手册 (<code>SKILL.md</code>)</a>
17
13
  </p>
18
14
 
19
- ```bash
20
- ntn-skills list
21
- ntn-skills read 'Release Review'
22
- ```
23
-
24
- `Release Review` 是示例名称,请选择你自己的 `list` 返回的 Skill。npm 安装包、命令和引导 Skill 都叫 **`ntn-skills`**。
25
-
26
- 已发布到 [npm](https://www.npmjs.com/package/ntn-skills)。从源码构建见[贡献指南](CONTRIBUTING.md#development-setup)。
27
-
28
- ## 它解决什么问题?
15
+ ---
29
16
 
30
- 你在 Notion 中维护了一组可复用的操作指令,但 Agent 在当前任务里只需要其中几项。`ntn-skills list` 先提供名称和描述,让 Agent 选出适用的工作流,再用 `read` 读取需要的文件,同时把该 Skill 的完整导出保存到本地。
17
+ `ntn-skills` 将 **Notion 的 3 张数据表**(`Sources`、`Skills`、`Files`)作为可视化、跨机器同步的技能控制面;同时在消费侧彻底去耦合,通过只读不可变快照、标准软链(`~/.agents/skills`)、受管副本目录(如云沙盒 `:copy` 模式)与自动合成的本地目录路由技能(`skill-catalog`),在任何 Agent 宿主上实现 **0 毫秒纯本地读取消费**。
31
18
 
32
- 任务执行期间,Notion 内容可能被修改。第一次成功读取会返回一个**快照**,把工作流和附件固定为一个本地版本。任务中持续使用返回的引用。普通未固定版本的读取可复用五分钟内验证过的内容;新任务需要确认远端最新内容时,在当前目标上加 `--refresh`。
19
+ 日常业务对话不挂 MCP、不发 Notion 网络请求、不塞爆默认上下文;而你随时可以在 Notion 网页或手机上改分组、调可见性、写草稿,或让 Agent 给任意上游技能打热补丁实测。
33
20
 
34
- | 你想做什么 | 使用的命令 |
35
- | --- | --- |
36
- | 找到工作流,避免一次加载整座库的正文 | `list` |
37
- | 从同一版本读取指令和附件 | `read`,再用 `files` |
38
- | 在本地文件和 Notion 之间迁移完整 Skill | `import`、`export` |
39
- | 明确新增一个 Skill 或替换一个文件 | `create`、`write` |
40
- | 同步已有 Notion 页面与本地 Skill 目录 | `sync bind`、`sync plan`、`sync apply` |
41
-
42
- ## 安装
43
-
44
- 安装 [Node.js](https://nodejs.org) **22.19.0 或更新版本**,其中包含 npm。在线操作还需要支持 `api --notion-version` 的[官方 Notion CLI](https://developers.notion.com/cli) **`ntn`**;本项目已使用 `ntn` 0.22.12 验证。
45
-
46
- 从官方 npm registry 安装已发布版本:
47
-
48
- ```bash
49
- npm install --global ntn-skills --registry https://registry.npmjs.org
50
- ntn-skills --version
51
- ntn-skills --help
52
- ```
53
-
54
- 版本命令输出已安装版本;帮助列出可用命令。使用者需要 Node.js 和 npm。[项目内安装](docs/usage.md#install-in-a-consuming-project)、[PATH 配置](docs/usage.md#install-from-npm-globally)与[本地 tarball 安装](docs/usage.md#install-a-local-tarball-globally)见使用指南。
55
-
56
- 需要自行生成安装包时,按[贡献指南中的开发与构建步骤](CONTRIBUTING.md#development-setup) 操作。Bun 用于开发和构建。
21
+ ---
57
22
 
58
23
  ## 快速开始
59
24
 
60
- ### 1. 连接 Notion
61
-
62
- 按[官方认证指南](https://developers.notion.com/cli/get-started/authentication) 配置 `ntn`。连接需要 Read content 权限,并能访问具备 `Description` 和 `References` 两个富文本属性的数据库。`References` 保存 Notion 页面提及或页面链接,CLI 将这些页面转成 `references/` 下的 Markdown。已有原生 Skills 数据库及其导出模式也可继续使用。
25
+ 将下面这句话直接发给 **Claude Code、Cursor、Pi、Codex、Grok Bot、Antigravity** 或任何具备终端能力的 Agent:
63
26
 
64
- 数据库中至少需要一个有效 Skill。比如,Notion 中的 Name 为 `Release Review`,其导出的 `SKILL.md` 必须包含 `name: release-review`。名称只能用英文字母,单词之间用一个空格,最多 64 个字符;描述和正文可以使用任何语言。[命名与数据库要求](docs/protocol.md#identity-and-references)。
27
+ ```text
28
+ 请阅读 https://raw.githubusercontent.com/yoyooyooo/ntn-skills/main/INSTALL.md 并帮我完成 ntn-skills 的安装与初始化。
29
+ ```
65
30
 
66
- 认证优先级为:已保存的 `config.token` → 非空 `NOTION_API_TOKEN` → 已有 `ntn login` 登录态。保存的 token 以明文存入私有配置文件;`config show` 只显示是否已配置。[设置与移除 token](docs/usage.md#authentication)。
31
+ 你的 Agent 会自动检测本机环境、安装 CLI(自动挂载随包内置的 `ntn-skills` 管理技能)、引导你将 Notion Token 写入 `0600` 权限的本地文件(绝不经聊天记录泄露),并在你提供的空白 Notion 页面上一键创建纯净 3 表、开启后台增量同步,最后用 `ntn-skills doctor`(`6/6 pass`)完成验收。
67
32
 
68
- ### 2. 检查访问权限,选择工作流
33
+ <details>
34
+ <summary>偏好手动安装?点击展开</summary>
69
35
 
70
36
  ```bash
37
+ # 1. 通过 npm / Bun 一键全局安装 CLI(需 Node >= 20 或 Bun >= 1.2;使用 Pi 可用下方 install.sh --with-pi)
38
+ npm install -g ntn-skills && ntn-skills skill --install
39
+ # 备选(含 Pi 扩展挂载):curl -fsSL https://raw.githubusercontent.com/yoyooyooo/ntn-skills/main/scripts/install.sh | bash -s -- --with-pi
40
+
41
+ # 2. 写入 Notion Integration Token(强制 0600 权限,原生遵循 XDG_CONFIG_HOME)
42
+ mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/ntn-skills"
43
+ cat > "${XDG_CONFIG_HOME:-$HOME/.config}/ntn-skills/credentials.env" <<'EOF'
44
+ NOTION_TOKEN=ntn_你的令牌
45
+ # 可选:避免 GitHub API 限流及拉取私有 GitHub 技能仓
46
+ # GITHUB_TOKEN=ghp_你的令牌
47
+ EOF
48
+ chmod 600 "${XDG_CONFIG_HOME:-$HOME/.config}/ntn-skills/credentials.env"
49
+
50
+ # 3. 传入空白 Notion 页面 URL(自动建 3 表 + 默认开启 discoverable 预物化 + 首次同步)或已有 Library URL
51
+ ntn-skills init --root "https://www.notion.so/你的页面链接"
52
+
53
+ # 4. 开启原生后台静默增量同步(macOS launchd / Linux systemd)
54
+ ntn-skills schedule install
55
+
56
+ # 5. 一键体检验收(预期 0 fail)
71
57
  ntn-skills doctor
72
- ntn-skills list
58
+ ntn-skills skill # 直接打印随当前二进制内置的权威 Agent 指南
73
59
  ```
74
60
 
75
- 有效 Skill 可访问时,`doctor` 应返回 `ok: true`、`authentication: "available"`、大于零的 `skill_count`,以及 `skill_read.available: true`。它实际读取并缓存一个 Skill,验证当前存储模式。`list` 返回元数据和覆盖范围,不加载工作流正文。
76
-
77
- Notion Search 可能漏掉数据库。请查看 `coverage`;如果已知数据库,可使用 `ntn-skills list --database 'DATABASE_ID_OR_URL'`,将其中的值替换成实际数据库 ID 或 URL。
78
-
79
- ### 3. 读取选中的 Skill
80
-
81
- 从 `skills` 中复制一个条目的 `ref`,替换下面的占位值:
82
-
83
- ```bash
84
- ntn-skills read 'REF_FROM_LIST'
61
+ </details>
62
+
63
+ ---
64
+
65
+ ## 运行前提与支持平台
66
+
67
+ - **操作系统**:macOS(原生 `launchd` 定时同步与系统废纸篓)与 Linux(`systemd --user` 定时同步与 XDG 回收站);Windows 建议通过 WSL2 运行。
68
+ - **运行依赖**:`git`,以及 **Node.js `>= 20`**(支持 `npm install -g ntn-skills` 直接运行)或 **[Bun](https://bun.sh) `>= 1.2.0`**。
69
+ - **Notion 准备**:一个 [Notion 内部集成令牌](https://www.notion.so/profile/integrations),并将该集成授权给你准备的一个空白 Notion 页面(或已有 `ntn-skills` 根页面)。
70
+ - **宿主兼容**:开箱兼容 Claude Code、Codex、Cursor、Pi、Antigravity、Grok Bot(`${HOME}/agent-data/workflows:copy`)及所有支持从本地目录读取 `SKILL.md` 的 Agent 环境。
71
+
72
+ ---
73
+
74
+ ## 双视角工作流
75
+
76
+ 理解 `ntn-skills` 最简单的方式,是把 **“人的日常操作”** 与 **“Agent 的后台行为”** 分开看——你平时根本不需要背下面的 CLI 参数。
77
+
78
+ ### 一、人的视角(你在 Notion 和对话里怎么用)
79
+
80
+ 1. **在 Notion 网页 / 手机上随手改表格字段**
81
+ - **做什么**:调整 `Visibility`(把高频技能设为 `always` 常驻顶层、把自用专项技能设为 `discoverable` 编入按需目录、把外部大仓长尾留在 `manual` 静默待命),修改触发描述 `Description`、领域分类 `Scenes`、多机分组 `Profiles`,或取消勾选 `Enabled` 停用技能。
82
+ - **怎么生效**:改完直接关网页即可。每台机器后台每 12 分钟自动增量同步并刷新本地软链与 `skill-catalog`;想下一秒立刻生效,对 Agent 说一句 *“同步下技能”*(`ntn-skills sync`)。
83
+
84
+ 2. **在 Notion 页面里直接改 `SKILL.md` 正文(注意一个关键区别)**
85
+ - **纯 Notion 自有草稿技能(`Origin` 为空)**:Notion 页面正文就是它的唯一正本,你在网页里怎么改,同步到本地就是什么样(若 Notion 偶发未刷新外层时间戳,跑一次 `ntn-skills sync --full` 即可强制重拉正文)。
86
+ - **来自 Git 仓库的上游技能(`Origin` 有值)**:默认 `Custom Main` 未勾选时,Notion 页面里的正文只是方便你阅读的**上游只读预览镜像**,本地实际消费仍以 Git 提交为准。如果你直接在 Notion 网页里改了上游技能正文并希望生效,**请同时勾选 `Custom Main`**(若忘记勾选,`sync` 会给出未生效漂移提醒,防止你误以为网页修改已上线)。
87
+
88
+ 3. **想微调某个外部/内部上游技能去实测,又不想 Fork 仓库**
89
+ - **怎么做**:直接在对话里对 Agent 说:*“给 `dagu` 技能加一段我们本机的路径约定和一个检查脚本,推回 Notion 让我实测几天。”*
90
+ - **效果**:Agent 自动拉起隔离工作区改好推回 Notion(自动置 `Custom Main = true` 并在 `Files` 表记录 `override / delete` 差异层),你的所有机器立刻消费「Git 上游基线 + Notion 热补丁」的合成版本。
91
+ - **两个收口方向**:
92
+ - 实测不满意:对 Agent 说 *“撤掉 `dagu` 的本地覆盖恢复原版”*(`reset-overlay`),一秒还原干净跟随上游;
93
+ - 实测成熟想正式入仓:对 Agent 说 *“把 `dagu` 导出干净源码到我的个人技能仓库提交”*(`pull --clean` + `attach` / `upstream apply`)。当上游 Git 追平补丁后,Notion 里的临时覆盖行会**自动归档清零**。
94
+
95
+ 4. **先在本机孵化试跑一个临时技能,确认好用后再存进 Notion**
96
+ - **怎么做**:先让 Agent 在 `~/.agents/skills/<新技能名>/` 下直接写一个普通本地技能目录,不用碰 Notion,直接在本地反复改、反复试跑(后台定时同步绝不触碰非受管的本地目录,且 `sync` 会在 `Local Pending` 中清晰提示未入库的本地技能)。
97
+ - **怎么转正**:试跑满意后,对 Agent 说一句 *“这个技能没问题了,存进 Notion 吧”*(`ntn-skills new ~/.agents/skills/<新技能名> [--always | --discoverable]`)。系统会在完整上传至 Notion 后,自动将原本地临时目录安全移入系统废纸篓,并原地无缝切换为受管只读软链(`always`)或编入 `skill-catalog`(`discoverable`)。
98
+
99
+ 5. **导入几百个技能的外部大仓 + 定期看一眼治理面板**
100
+ - 收藏第三方大仓时默认全进 `manual`(0 上下文负担);接入你自己的主力技能仓时可设为 `discoverable` 一键编入目录。
101
+ - 隔段时间看一眼 `ntn-skills status`:看近 30 天按需加载热度榜(`Hot Loads`)决定谁该升 `always`,看草稿池(`Draft Buffer`)和热补丁(`Overlays`)决定谁该毕业沉淀进 Git。
102
+
103
+ ### 二、Agent 的视角(99% 消费态 vs 1% 管理态严格隔离)
104
+
105
+ | 状态 | 触发时机 | Agent 看到与执行的内容 |
106
+ | :--- | :--- | :--- |
107
+ | **日常干活(消费态,99% 会话)** | 所有普通编码、调研、运维业务任务 | **完全不知道 Notion 的存在,0 网络请求**:<br>1. **`always` 技能**:已在 `~/.agents/skills/<name>`(或 `:copy` 目标目录)顶层就位,直接读取。<br>2. **`discoverable` 技能**:所有宿主顶层都会看到一个纯本地自动合成的只读目录技能 **`skill-catalog`** —— 遇到专项任务时,Agent 翻开 `skill-catalog/SKILL.md` -> 对应领域的 `references/<scene>.md` -> 直接读取本地已预物化的只读 `store/.../SKILL.md`(纯文件两跳直达,零插件依赖)。<br>3. **`manual` 技能**:平时完全隐身;在 Pi 中通过用户输入 `$skill` 或 `skill_find / skill_load` 工具按需唤醒,在其他宿主中通过策略型 Router 指引或 `ntn-skills load` 点名加载。<br>4. **只读红线**:`store/` 目录固定 `0444/0555` 只读权限,绝不允许原地修改。 |
108
+ | **技能维护(管理态,1% 会话)** | 仅当人类明确要求新建、修改、打补丁、导入源或排障技能库时 | 按需读取随 CLI 内置发布的 **`ntn-skills`** 技能(或运行 `ntn-skills skill` 获取与当前二进制版本严格对齐的手册),通过 `new / set / edit / diff --remote / push` 操作控制面,完活后自动将临时工作区移入系统废纸篓。 |
109
+
110
+ ---
111
+
112
+ ## 架构总览
113
+
114
+ ```mermaid
115
+ flowchart LR
116
+ subgraph Control["Notion 控制面(人类可视化工作台)"]
117
+ SRC["Sources 表
118
+ (外部与私有 Git 源)"]
119
+ SKL["Skills 表
120
+ (Visibility / Scenes / SKILL.md)"]
121
+ FIL["Files 表
122
+ (草稿附属文件 & 热补丁差异层)"]
123
+ end
124
+
125
+ subgraph Local["本机只读运行时($XDG_DATA_HOME/ntn-skills)"]
126
+ CAT["catalog.json & manifest.json
127
+ (增量游标 + 静态机器可读清单)"]
128
+ STO["只读不可变快照 store/
129
+ (0444/0555 · always + discoverable 预物化)"]
130
+ end
131
+
132
+ subgraph Hosts["跨宿主零延迟消费层"]
133
+ EXP["~/.agents/skills/ 或 :copy 目标目录
134
+ (always 技能 + 自动合成 skill-catalog)"]
135
+ ANY["任意宿主(Claude Code / Codex / Grok Bot / Cursor / Antigravity)
136
+ 纯文件 Read 两跳直达"]
137
+ PI["Pi 扩展
138
+ ($skill 内联注入 + skill_find / skill_load)"]
139
+ end
140
+
141
+ SRC --> SKL
142
+ FIL --> SKL
143
+ Control -- "每 12 分钟增量同步
144
+ (launchd / systemd)" --> CAT
145
+ CAT --> STO
146
+ STO -- "原子软链 / 受管副本" --> EXP
147
+ EXP --> ANY
148
+ CAT --> PI
149
+ STO --> PI
85
150
  ```
86
151
 
87
- 成功响应包含 `ok: true`、`content` 中的指令、以 `s_` 开头的 `snapshot_id`,以及包含 `?snapshot=...` 的固定版本 `ref`。`source: "notion"` 表示本次在线验证,`source: "local_cache"` 表示有时间边界的缓存观察。将 `freshness`、引用和快照 ID 保留在任务上下文中;需要确认当前访问权限与远端内容时,对当前引用加 `--refresh`。[响应字段说明](docs/protocol.md#success)。
152
+ ---
88
153
 
89
- ### 4. 从同一版本读取附件
154
+ ## 极简三表结构
90
155
 
91
- 每一步都用前一个命令返回的实际值替换占位值:
156
+ 由 `ntn-skills init --root <空白页链接>` 自动创建并双向关联:
92
157
 
93
- ```bash
94
- ntn-skills files 'SNAPSHOT_ID_FROM_READ'
95
- ntn-skills read 'ATTACHMENT_REF_FROM_FILES'
96
- ```
158
+ | 数据表 | 职责 | 核心字段 |
159
+ | :--- | :--- | :--- |
160
+ | **`Sources`** | 管理外部上游与自有私有 Git 仓库 | `Name`、`Repo URL`、`Ref`、`Pinned Commit`、`Policy` (`track \| pinned \| manual`)、`Enabled`、`Last Checked`、`Skills` |
161
+ | **`Skills`** | 技能总目录、三档可见性路由与 `SKILL.md` 正文 | `Name`、`Description`、`Enabled`、`Visibility` (`always \| discoverable \| manual`)、`Kind` (`skill \| router \| prompt`)、`Profiles`、`Scenes`、`Requires`、`Origin`、`Source Path`、`Custom Main`、`Revision`、`Preview Hash`、`Status`、`Supporting Files` |
162
+ | **`Files`** | 自有技能附属文件与上游技能差异补丁 | `Name`、`Skill`、`Path`、`Status` (`override \| delete`)、`Executable`、`SHA256`、`External URL`、`Attachment` |
97
163
 
98
- 用快照 ID 列出**全部**文件;传入某个文件的引用,只会列出那个文件。请选择 `files` 实际返回的附件。它的固定版本引用使用同一个快照,即使没有认证或网络,读取也会返回 `source: "local_snapshot"`。历史版本只能读取本机已经保存过的快照。
164
+ > **子树哈希剪枝与零冗余**:未改动的上游技能在 `Files` 表中占 **0 行**(上游文件清单自动展示在技能页第 1 行的只读子页 `Upstream Files` 中)。当多技能上游仓库有新提交时,未改动的同仓其他技能触发 **0 次 Notion 写入**,本地 `effectiveRev` 保持稳定不重物化。
99
165
 
100
- 二进制附件加上 `--output ./attachment.bin`,再用合适的查看器打开。文本可用 `--lines 10-30` 读取包含首尾的行区间,或用 `--raw` 输出 UTF-8 原文。脚本不会被自动执行。
166
+ ---
101
167
 
102
- ## 常用场景
103
-
104
- ### 按领域选择工作流库
105
-
106
- 为已知数据库注册领域别名,然后明确选择它。执行前替换数据库占位值:
168
+ ## 命令速查
107
169
 
170
+ ### 初始化、内置手册、体检与消费检索
108
171
  ```bash
109
- ntn-skills source add ops --database 'DATABASE_ID_OR_URL'
110
- ntn-skills list --database ops
111
- ntn-skills read 'Release Review' --database ops
172
+ # 若 XDG 配置中已有 default_library,重跑 init 可省略 --root
173
+ ntn-skills init [--root <notion-page-url>] [--export ~/.agents/skills] [--export '${HOME}/agent-data/workflows:copy'] [--profile default] [--prefetch discoverable]
174
+ ntn-skills skill [--path] [--install [--dest ~/.agents/skills] [--force]] [--uninstall]
175
+ ntn-skills doctor [--json]
176
+ ntn-skills status [--days 30] [--json]
177
+ ntn-skills sync [--full] [--coalesce] [--json]
178
+ ntn-skills find [关键词] [--scene <场景>] [--visibility always|discoverable|manual] [--kind skill|router|prompt] [--json]
179
+ ntn-skills info <name> [--json]
180
+ ntn-skills load <name> [--refresh] [--path-only]
112
181
  ```
113
182
 
114
- 数据库别名精确匹配,区分大小写。两个数据库存在同名 Skill 时,选择数据库,或使用 `list` 返回的包含页面 ID 的引用。已注册的来源会补充自动发现的范围。[发现、别名与覆盖范围](docs/usage.md#discovery-and-identity)。
115
-
116
- ### 导入、导出或更新 Skill
117
-
118
- Skill 可以来自文件夹、ZIP 或 Markdown 文件。先预览远端变更,再执行:
119
-
183
+ ### 草稿创建、批量元数据、Overlay 调优与入仓毕业
120
184
  ```bash
121
- ntn-skills import ./my-skill --database ops --dry-run
122
- ntn-skills import ./my-skill --database ops
123
- ntn-skills export 'My Skill' --database ops --output ./my-skill.zip
124
- ntn-skills write 'PINNED_REF_FROM_READ' --input ./SKILL.md --dry-run
185
+ # 隔离工作区编辑闭环(严禁直接修改只读 store/)
186
+ WORKDIR=$(ntn-skills edit "<name>")
187
+ ntn-skills diff "$WORKDIR" --remote
188
+ ntn-skills push "$WORKDIR" [--dry-run]
189
+ ntn-skills abort "$WORKDIR"
190
+
191
+ # 新建/原地收编纯 Notion 草稿技能 & 单个/按源批量修改元数据
192
+ ntn-skills new <dir> [--name <name>] [--visibility always|discoverable|manual] [--profiles default] [--scenes ops] [--no-adopt]
193
+ ntn-skills set [<name...>] [--source <source-name>] \
194
+ [--visibility always|discoverable|manual | --always | --discoverable | --manual] \
195
+ [--kind skill|router|prompt] [--enable|--disable] [--add-profile <p>] [--add-scene <s>] [--require <dep>]
196
+
197
+ # 导出干净源码入仓、草稿毕业挂源、解绑、回退补丁与软退役
198
+ ntn-skills pull <name> <git-repo-skill-dir> --clean
199
+ ntn-skills attach <name> --source <source-name> [--path <repo-relative-dir>]
200
+ ntn-skills detach <name>
201
+ ntn-skills reset-overlay <name> [<file-path>]
202
+ ntn-skills rm <name> # 软标记 retired 并撤回本地软链,绝不物理硬删
125
203
  ```
126
204
 
127
- `create` 要求名称尚不存在。`import` 会创建缺失的名称、复用相同内容,或替换已有同名 Skill 的正文、元数据和完整文件集。`write` 只替换一个文件,保留其他文件;确认预览后,去掉 `--dry-run` 执行。固定版本写入会在线核对当前版本,版本已变化就失败。[输入格式、冲突与部分成功的处理](docs/usage.md#creating-importing-exporting-and-updating-skills)。
128
-
129
- 用 `import ./my-skill --target 'CURRENT_PAGE_ID_OR_PINNED_MAIN_REF' --database ops --dry-run` 明确替换已有页面。即使导入的名称、描述变化,`--target` 仍保留选定页面身份;目标缺失、不可访问或版本过期时失败,不按导入名称回退或创建新页。
130
-
131
- ### 同步本地分发目录
132
-
133
- 将 `PAGE_ID`、`PLAN_ID` 替换为实际返回值。绑定标签是本地配置,与 Skill 调用别名分开。
134
-
205
+ ### 上游源维护与后台定时调度
135
206
  ```bash
136
- ntn-skills sync bind PAGE_ID --path ~/.agents/skills/release-review --as release-review-global
137
- ntn-skills sync plan release-review-global --from notion
138
- ntn-skills sync apply --plan PLAN_ID
139
- ntn-skills sync status release-review-global
140
- ntn-skills sync plan --all --output ./skills-plan.json
141
- ntn-skills sync apply --plan ./skills-plan.json
142
- ntn-skills sync reconcile release-review-global
143
- ntn-skills sync unbind release-review-global --dry-run
207
+ # 导入新 Git 源(外部大仓默认 manual;个人主力仓可加 --discoverable 与 --scenes)
208
+ ntn-skills source add <repo-url> [--name <name>] [--ref main] [--root skills] [--policy track|pinned|manual] [--discoverable] [--scenes ops,coding]
209
+ ntn-skills source list
210
+ ntn-skills source sync <name> [--update-pinned]
211
+ ntn-skills upstream check [<source>]
212
+ ntn-skills upstream apply [<source>] [--dry-run] [--max-sources 10] [--timeout-sec 180]
213
+
214
+ # 原生系统定时任务(macOS launchd / Linux systemd)与外部调度器模板导出
215
+ ntn-skills schedule install [--sync-every 12m] [--full-at 04:12] [--upstream-every 6h]
216
+ ntn-skills schedule status
217
+ ntn-skills schedule uninstall
218
+ ntn-skills schedule export --target dagu|github-actions|crontab
144
219
  ```
145
220
 
146
- 首次绑定两侧相同时可初始化共同基线;不同或本地普通目录末级尚不存在时,必须用 `--from local|notion` 明确选择初始化来源。后续计划按各绑定已确认的基线判断方向或报告冲突。执行前重新检查绑定、版本、内容、逻辑路径与真实目标;复制计划不能授权在另一台机器或另一绑定执行。`status` 默认只报告本地与已有远端观察,`--refresh` 才在线验证。`reconcile` 检查未完成回执,不重放写入。`unbind` 停用绑定并保留内容、基线、计划和回执。符号链接保留逻辑路径与链接;移除、替换的旧字节通过系统废纸篓保留。详见[同步使用说明](docs/usage.md#synchronizing-local-skills)。
147
-
148
- ### 在 Notion 中维护参考页面
221
+ ---
149
222
 
150
- 在富文本 `References` 属性中添加页面提及或链接。链接文字写成 `references/guide.md` 时固定本地路径,否则按页面标题生成文件名。正文照常使用 Notion 页面链接;CLI 读取和导出时转换为 `./references/guide.md` 等相对路径。参考文档互相引用时按所在文件目录解析,CLI 写回时恢复 Notion URL。其他网站链接和代码示例保持原样。
223
+ ## Pi 扩展
151
224
 
152
- `create`、`import` 将 `references/**/*.md` 创建为可编辑的子页面;`write` 更新对应参考页。导入时移除某个参考文件,会让它退出新快照,原 Notion 页面保留。纯页面库可以不设 `Files`;需要保留原始字节、额外 frontmatter 或非 Markdown 资源时继续保留它。详见 [References 契约](docs/protocol.md#references-pages)。
225
+ 安装时追加 `--with-pi`(或将 `packages/pi-extension` 软链至 `~/.pi/agent/extensions/ntn-skills`),即可在 Pi 中获得:
226
+ - **`$skill-name` 内联自动物化**:即使技能处于 `discoverable` 或 `manual` 档位,在提示词中直接写 `$技能名` 即可从本地只读存储按需注入本轮上下文;
227
+ - **`skill_find` 与 `skill_load` 原生工具**:支持按关键词、`scene`、`visibility`、`kind` 零网络检索本地全量目录并按需加载长尾技能,自动计入 `Hot Loads` 热度榜。
153
228
 
229
+ ---
154
230
 
155
- ## 接入 Agent
231
+ ## 安全与数据边界
156
232
 
157
- 把[引导 Skill](skills/ntn-skills/SKILL.md) 所在目录复制到 Agent 宿主支持的本地 Skill 目录。它让 Agent 通过终端命令发现元数据、读取选中的工作流,并沿固定版本引用读取附件。
233
+ - **日常消费零网络请求**:日常会话仅读取 `$XDG_DATA_HOME/ntn-skills/store/`(默认 `~/.local/share/ntn-skills/store/`)下的只读不可变快照(`0444/0555`);仅在显式运行同步/维护 CLI 或系统定时任务时访问 `api.notion.com` 与用户配置的 Git 远端。
234
+ - **本地凭据保护与零第三方遥测**:`credentials.env` 存放在 `$XDG_CONFIG_HOME/ntn-skills/`(默认 `~/.config/ntn-skills/credentials.env`),`doctor` 强制校验 `0600` 权限;工作区自动剥离 `.env` 等敏感文件;调用统计(`telemetry/usage.jsonl`)与同步日志(`2 MiB` 上限轮转)100% 留在本机,绝不外发。
235
+ - **非受管目录保护与零永久删除**:`export` 绝不覆盖宿主目录中已有的非受管文件或软链;工作区和过期缓存回收统一移入系统废纸篓;Notion 技能下线走软标记 `Status = retired`。
236
+ - **形式化验证**:核心并发锁、重叠窗口增量同步与原子快照切换不变量配有 TLA+ 规约(见 [`verification/`](https://github.com/yoyooyooo/ntn-skills/tree/main/verification))。
158
237
 
159
- 如果希望宿主启动时就知道所有可用工作流,需要启动钩子执行 `ntn-skills list` 并注入返回的元数据。仅安装引导 Skill,并不会在启动时自动暴露远端目录。直接使用 `Read skill://...` 需要宿主适配器;宿主提供终端工具时,即可通过 CLI 接入。[宿主接入契约](docs/host-integration.md)。
238
+ ---
160
239
 
161
- 检查或维护 Skill 不会激活其中的指令。宿主仅激活当前任务选择的工作流并保留其新鲜度信息;下载的内容、脚本不会自动执行。
240
+ ## 适用范围与非目标
162
241
 
163
- ## 使用边界与本地数据
242
+ - **聚焦 Agent Skills 生命周期**:`ntn-skills` 专注管理基于 `SKILL.md` 与附属脚本/参考文档的技能资产;不承担 MCP Server 托管代理、通用密钥管理或宿主系统初始化编排。
243
+ - **刻意保持单向同步边界**:`ntn-skills sync` 仅从 Notion/Git 向本机单向拉取并在 `Local Pending` 提示本地未入库增量,绝不静默将本地临时试验推上云端;所有写回均须显式经过 `new` 或 `edit -> diff --remote -> push`。
164
244
 
165
- - 本地已在 macOS arm64 的 Node.js 24.20.0 和 Linux arm64 的最低 Node.js 22.19.0 验证 npm 安装与预置快照的离线行为;真实 Notion 读取用 macOS 和 `ntn` 0.22.12 验证。CI 已配置 Ubuntu、macOS 15 上的 Node.js 22.19.0 和 24;工作流配置不代表新变更的运行已成功。Windows 未验证。
166
- - 明确执行 `create`、`import`、`write` 或 `sync apply` 会修改内容。版本检查属于客户端预检查;正文、属性和文件由不同请求更新。遇到部分成功或结果未知,先检查目标;未完成同步应先执行 `sync reconcile`,再生成新的执行计划。
167
- - 配置默认位于 `~/.config/ntn-skills/config.json`;快照、上传暂存和同步恢复状态位于 `~/.local/state/ntn-skills`;可丢弃观察缓存位于 `~/.cache/ntn-skills`。正文默认五分钟、目录元数据默认 60 秒;[缓存策略与清理](docs/usage.md#cache-policy-and-cleanup)说明配置及系统废纸篓保留。
168
- - 在线操作通过 `ntn` 和 Notion 的签名下载 URL 完成。未固定版本的离线查找必须能安全确定本地身份范围;官方登录身份可能仍需在线检查。缓存观察不能证明当前权限。CLI 自身不发送遥测请求;`ntn` 有自己的政策。导入的脚本不会自动执行。
169
-
170
- 详见[配置与存储](docs/protocol.md#environment-and-local-storage)、[错误恢复](docs/protocol.md#errors) 和[安全与隐私](SECURITY.md)。
245
+ ---
171
246
 
172
247
  ## 升级与卸载
173
248
 
174
- tarball 安装可获取新版已构建安装包,再执行 npm 安装命令。跨 0.x 次版本升级前,请阅读[变更记录](CHANGELOG.md)。源码构建按[贡献指南](CONTRIBUTING.md#development-setup) 操作。
249
+ ```bash
250
+ # 无损升级至最新版(保留已有配置、凭据与本地快照)
251
+ npm install -g ntn-skills@latest # 若通过源码脚本安装则重跑 scripts/install.sh
175
252
 
176
- 全局安装用 `npm uninstall --global ntn-skills` 卸载。配置、缓存和保留状态仍在,包括固定版本、同步基线、计划与未完成回执。需要移除已保存的 token 时,在卸载前执行 `ntn-skills config clear-token`。升级保留状态与配置,在独立缓存根重建可丢弃观察;原先假定每次未固定读取都在线的调用者应加 `--refresh`。[卸载与可选保留说明](docs/usage.md#upgrade-and-uninstall)说明应保留哪些数据。
253
+ # 干净卸载本机运行时(绝不会删除你的 Notion 云端数据)
254
+ ntn-skills schedule uninstall
255
+ ntn-skills skill --uninstall
256
+ # 随后将 ~/.local/share/ntn-skills、~/.config/ntn-skills 与 ~/.local/bin/ntn-skills 移入系统废纸篓即可
257
+ ```
177
258
 
178
- ## 文档与贡献
259
+ ---
179
260
 
180
- | 下一步 | 文档 |
181
- | --- | --- |
182
- | 安装变体与日常 CLI 操作 | [使用指南](docs/usage.md) |
183
- | 选择器、JSON 输出、存储与错误 | [CLI 与引用契约](docs/protocol.md) |
184
- | 启动时的元数据注入与 Read/Write 适配器 | [宿主接入](docs/host-integration.md) |
185
- | 开发环境与兼容政策 | [贡献指南](CONTRIBUTING.md) |
186
- | 发版与发布结果验证 | [发布流程](docs/releasing.md) |
261
+ ## 开发与开源治理
187
262
 
188
- 问题报告和使用咨询请在 [GitHub issues](https://github.com/yoyooyooo/notion-skills-cli/issues) 提交脱敏信息;漏洞通过[私下报告渠道](SECURITY.md#reporting-a-vulnerability) 提交。开发或构建 CLI 请从[贡献指南](CONTRIBUTING.md) 开始。
263
+ ```bash
264
+ bun install
265
+ bun run check # 依次执行 biome lint、tsc 类型检查与全套不变量单元测试
266
+ ```
189
267
 
190
- [文档目录](docs/README.md) · [变更记录](CHANGELOG.md) · [MIT 许可证](LICENSE)
268
+ - [贡献指南 (`CONTRIBUTING.md`)](./CONTRIBUTING.md)
269
+ - [安全策略 (`SECURITY.md`)](./SECURITY.md)
270
+ - [变更日志 (`CHANGELOG.md`)](./CHANGELOG.md)
271
+ - [MIT 许可证 (`LICENSE`)](./LICENSE)
package/SECURITY.md CHANGED
@@ -1,38 +1,19 @@
1
- # Security policy
1
+ # Security Policy
2
2
 
3
- ## Supported versions
3
+ ## Supported Versions
4
4
 
5
- Security fixes target the latest patch of the current 0.x minor series. Upgrade to that patch before relying on a fix; earlier patches and previous minor series are not maintained security branches.
5
+ | Version | Supported |
6
+ | :--- | :--- |
7
+ | `2.0.x` | Yes |
8
+ | `< 2.0.0` | No |
6
9
 
7
- ## Reporting a vulnerability
10
+ ## Data, Network & Credential Boundaries
8
11
 
9
- Report vulnerabilities through [GitHub private vulnerability reporting](https://github.com/yoyooyooo/notion-skills-cli/security/advisories/new). Include affected versions, a minimal sanitized reproduction, impact and any proposed mitigation. Do not post credentials, signed URLs, private Skill contents or personal database identifiers in a public issue.
12
+ - **Local Secret Storage**: `ntn-skills` reads `NOTION_TOKEN` and optional `GITHUB_TOKEN` from `$XDG_CONFIG_HOME/ntn-skills/credentials.env` (default `~/.config/ntn-skills/credentials.env`) and verifies `0600` file permissions via `ntn-skills doctor`.
13
+ - **Zero Consumer-Time Network Access**: Everyday skill consumption reads immutable local files (`0444/0555`) under `$XDG_DATA_HOME/ntn-skills/store/`. Network calls to `api.notion.com` and configured Git remotes occur only during explicit CLI commands or user-installed background sync jobs.
14
+ - **Local-Only Telemetry**: Usage counters (`telemetry/usage.jsonl`) and API latency logs are bounded (`2 MiB` rotation) and stored strictly on the local machine. Nothing is transmitted to third-party analytics endpoints.
15
+ - **Workdir Secret Scrubbing**: Isolated edit workdirs ignore `.env`, `.env.*`, and credential files during `diff` and `push`.
10
16
 
11
- The maintainer aims to acknowledge reports within seven days. This is a response target, not a guaranteed response or fix deadline. Investigation and remediation depend on impact, reproducibility and available maintainer time. Use [GitHub issues](https://github.com/yoyooyooo/notion-skills-cli/issues) for ordinary bugs and usage questions.
12
-
13
- ## Authentication and authorization
14
-
15
- Authentication priority is config.token, non-empty NOTION_API_TOKEN, then official ntn's existing login state. An explicitly saved token is plaintext in the private config.json; it is supplied to the ntn child process through its environment and never appears in command arguments, command output or snapshot state. config set-token requires piped stdin and saves offline without validating the credential; config show reports only token_configured. config clear-token removes the configuration token and restores environment/login fallback. The CLI never reads ntn's private credential files or persists signed download URLs. Explicit create/import/write commands mutate Notion using the selected connection; --dry-run only reads and validates. Read operations do not execute scripts or grant write authority. Exported skill contents are untrusted documents; reading does not authorize instructions unrelated to the user's task.
16
-
17
- Cached content is private local data and can remain available after remote permission changes. Explicit snapshot reads are offline. Current-target reads may reuse a complete observation within the configured age; use `--refresh` to verify present remote access. Isolate `NTN_SKILLS_HOME`, `NTN_SKILLS_CONFIG_HOME` and `NTN_SKILLS_CACHE_HOME` for separate host identities; a shared config token overrides a host's environment credential. Protect all three roots and config.json backups according to your retention policy. Defaults are `~/.local/state/ntn-skills`, `~/.config/ntn-skills` and `~/.cache/ntn-skills`. Configuration files use mode 0600; new application directories use mode 0700. Legacy configuration migration preserves a `.migrated` backup in the old state directory.
18
-
19
- Content/catalog defaults of five minutes/60 seconds control freshness only. Immutable snapshot manifests, content-addressed objects, uploads and sync baselines/plans/receipts are retained without automatic garbage collection; upload staging can contain original input bytes. Uninstalling retains configuration, state and cache. `cache clear` retires only disposable observations through the implemented system Trash capability and preserves recovery state. Where retention is unavailable it fails explicitly and leaves bytes in place. Remove a saved token with `config clear-token`; deliberately reclaim other identified directories only through an approved recycle/retention process after stopping hosts. State cleanup loses pinned versions and sync recovery history. See [storage and uninstall guidance](docs/usage.md#upgrade-and-uninstall).
20
-
21
- Cache retirement invalidates the selected content/catalog observation batch before moving bytes. A retention error leaves unmoved files in place but does not reactivate those observations or delayed publishers. Pinned content and recovery state remain usable; see the [retention contract](docs/protocol.md#environment-and-local-storage).
22
-
23
- ## Network and local access
24
-
25
- The CLI sends no analytics or telemetry requests of its own. Online commands invoke the executable selected by `NTN_SKILLS_NTN_BIN` (default `ntn`) for Notion authentication/API requests and uploads, then download export archives from signed URLs returned by Notion. This does not attest to the official CLI's telemetry, credential storage or network policies. Treat an executable override as executable code you trust.
26
-
27
- Local access covers configuration, retained state, disposable cache, explicitly selected ZIP/folder/Markdown or write inputs, requested outputs and registered logical sync directories with their resolved destinations. Explicit create/import/write and sync push operations may upload those inputs. `NOTION_WORKSPACE_ID` and `NOTION_API_BASE_URL` enter the cache scope and are inherited by `ntn`. Workspace selection follows its authentication rules; the API base URL override can direct authenticated requests to another endpoint, so use only an endpoint you trust. Signed archive downloads follow the URLs returned by the service independently. See [the environment contract](docs/protocol.md#environment-and-local-storage).
28
-
29
- ## Content and mutation boundaries
30
-
31
- Archives reject root escapes, duplicate entries, links and special files, with compressed/expanded limits. ZIPs expand in memory and verify checksums. Files preserves extra metadata, nested paths and binary bytes in a source ZIP without executing them. References mode reads the inclusion list of page mentions/links and rewrites only links to included pages; code examples and external URLs remain unchanged. Without Files, main/reference Markdown is normalized. Create rejects existing names; import replaces differing same-name content on the existing page and excludes omitted reference pages without deleting them. Write preserves unrelated logical files. Local read/export output verifies bytes, reuses identical output and rejects differing output without overwrite. Portable manifests add no generated remote identity or timestamps; original source fields may remain verbatim. Hashes detect corruption, not malicious authorized local modification.
32
-
33
- Pinned write refs are checked against the current authentication scope, page identity and complete version, including all referenced-page content. This is a client preflight check, not a server-side atomic commit. Body/properties/files can partially succeed; mutation requests are not automatically retried. Read back WRITE_PARTIAL/WRITE_OUTCOME_UNKNOWN before retrying. A new write returns a new snapshot and never edits historical objects. The configured default database affects creation only; explicit --database has priority.
34
-
35
- Sync plans/applies always validate online; read TTL cannot authorize a write. Saved plans retain binding, version, baseline, content and link preconditions. Unknown/partial outcomes retain receipts and fence overlapping resources until `sync reconcile` observes them without replay. Local links are preserved through real-destination writes, but Node commit guards are not atomic protection against a noncooperating process's link retargeting. Removed/replaced bytes require system Trash; unsupported hosts retain bytes and report the missing capability. [Synchronization contract](docs/protocol.md#synchronization).
36
-
37
- Database selection accepts one ID/URL or exact registered alias; IDs/URLs take priority and titles do not select targets. Unknown, conflicting or inaccessible aliases fail without redirecting to a default. Repeated --database flags fail before any command handler. Different databases may hold the same Skill name; name resolution fails on ambiguity, while page-ID refs remain exact. A pinned alias constraint checks local registration and snapshot database ownership without network access. Configuration registration aliases are local preferences, not remote identity or proof of permission.
17
+ ## Reporting a Vulnerability
38
18
 
19
+ Please **do not** open public issues for suspected security vulnerabilities or credential exposure bugs. Instead, report privately via [GitHub Private Vulnerability Reporting](https://github.com/yoyooyooo/ntn-skills/security/advisories/new) with reproduction steps and affected versions. We aim to acknowledge reports within 72 hours.