@cmkk/agentlink 0.1.0-beta.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.0] - 2026-05-11
8
+
9
+ 首次公开发布。
10
+
11
+ ### 新增
12
+
13
+ - **核心命令**:`init` / `sync` / `clean` / `unlink` / `doctor`
14
+ - `init` 交互式问 3 个问题(位置 / asset 类型 / adapter),按答案生成带教学注释的 JSONC 配置;`--yes` 一键默认,非 TTY 自动降级,`--dry-run` 完全不写盘
15
+ - `sync` 自动检测 source(4 级链:`--source` → `AGENTLINK_SOURCE` → `cwd/.agents` → `~/.agents`),按 adapter 投影到目标根;自动清理悬空链接
16
+ - `doctor` 只读健康检查:adapter 可用性 / link plan / 撞名 / dangling / orphan
17
+ - `unlink` 递归扫描所有内置 adapter rootDir,移除指向 source 的所有 link(不受 config gate 限制)
18
+ - **内置 adapter(v1)**:cursor(commands flatten、rules `.md → .mdc`)/ claude / codebuddy
19
+ - **JSONC 配置**:`agentlink.config.json` 支持 `//`、`/* */` 注释与尾逗号;zod 严格闭世界 schema 校验
20
+ - **配置文件就近发现**:cwd 上溯到 home 或 fs 根,与 git / eslint / tsconfig 对齐
21
+ - **`--user / -u`**:把投影根从 cwd 改为 `$HOME`,便于把个人 source 链到 `~/.cursor / ~/.claude / ...`
22
+ - **跨链接安全**:撞名检测(默认 warn + skip,`--strict` 升级为退出码 1);`targetSubdir` 拒绝 `..` 与绝对路径
23
+ - **退出码语义**:sync / clean / unlink / doctor 在任意 errored outcome 时设 `process.exitCode = 1`,便于 CI 集成
24
+
25
+ ### 工程
26
+
27
+ - 102 vitest 测试,9 个测试文件,覆盖 source / config 解析、layout、linker、各命令
28
+ - TypeScript strict + `exactOptionalPropertyTypes` + `noUncheckedIndexedAccess`
29
+ - ESM-only,tsup 打包,dts 同步生成
30
+ - Node ≥ 18
31
+
32
+ [Unreleased]: https://github.com/rankangkang/dot-agents/compare/agentlink-v0.1.0...HEAD
33
+ [0.1.0]: https://github.com/rankangkang/dot-agents/releases/tag/agentlink-v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rankangkang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # @cmkk/agentlink
2
+
3
+ > 一行 `npx`,把 `.agents/` 里的 skills / rules / commands 投影到 `.cursor`、`.claude`、`.codebuddy` 等多个 AI 工具目录。
4
+
5
+ `agentlink` 让 `.agents/` 成为**单一可信源**,再通过逐 agent 的轻量 **adapter**(处理 `flatten`、`rename`、`include / exclude`)投影到各家工具——全程 `symlink`,不复制。
6
+
7
+ ## 为什么需要 agentlink
8
+
9
+ `.agents/` 正在悄悄成为 AI 工具间的事实约定——Cursor、Codex 已经支持从 `.agents/skills/` 读取 `SKILL.md`,其他 agent 也在跟进。但在这个约定完全统一之前,**同时使用两个以上 AI 编码工具的人,都得在 `.cursor / .claude / .codebuddy / ...` 之间手动复制同一份 skill / rule / command**。而且各家工具还有自己的小约定:
10
+
11
+ - Cursor 的 commands 目录不支持嵌套(必须扁平)
12
+ - Cursor 的 rules 必须用 `.mdc` 后缀
13
+ - Claude Code 从 `.claude/skills/<name>/SKILL.md` 递归读取
14
+ - CodeBuddy 支持嵌套 commands
15
+
16
+ `agentlink` 就是为了弥合这个差距:
17
+
18
+ - **单一可信源** — 所有资产维护在一个 `.agents/` 目录(个人用 `~/.agents`,团队场景用项目内 `cwd/.agents`)。
19
+ - **投影而非复制** — agentlink 在每个目标 agent 的目录下,为每个一级条目创建一个 symlink,并通过声明式 adapter 处理 agent 特有约定(flatten、`.mdc` 重命名、扁平 vs 嵌套)。
20
+ - **与 [`skills.sh`][skills-sh] 互补** — `skills.sh` 负责把 skill 包**安装**(下载)到源目录;`agentlink` 负责把源目录**投影**到多个工具。两者解决的是同一工作流的不同环节:
21
+
22
+ ```bash
23
+ curl -fsSL skills.sh | sh -s install <pkg> # 安装到 ~/.agents/skills/<pkg>
24
+ agentlink sync # 投影到 .cursor / .claude / ...
25
+ ```
26
+
27
+ ### 为什么是"逐项 symlink"而不是"整目录 symlink"
28
+
29
+ 最朴素的实现是 `ln -s .agents/skills .cursor/skills`——整目录一条链接,简单。但这样做会让目标目录变成**实际只读**:你没法再往 `.cursor/skills/scratch/` 里临时塞一个一次性的 skill 做实验,因为整个目录已经是源目录的别名。
30
+
31
+ agentlink 改为**为每个一级条目单独创建一条 symlink**(或当 `flatten: true` 时,按文件粒度)。受管的 skill 与你手写的 skill 可以并存在同一目录里,`unlink` 也只会移除自己创建的那些链接——你的临时实验不会被波及。
32
+
33
+ [skills-sh]: https://skills.sh
34
+
35
+ ## 快速上手
36
+
37
+ ```bash
38
+ # 1. 在 ~/.agents 建脚手架(或加 --local 建在 ./.agents)
39
+ npx @cmkk/agentlink init
40
+
41
+ # 2. 把你的 skills/rules/commands 放进 ~/.agents/
42
+
43
+ # 3. 进入任何含 .cursor/、.claude/ 或 .codebuddy/ 的项目
44
+ cd ~/projects/some-app
45
+ npx @cmkk/agentlink sync
46
+ ```
47
+
48
+ ## 命令
49
+
50
+ ```
51
+ agentlink init [--local | --source <path>] [--force] [--yes]
52
+ 交互式创建 .agents/ 脚手架。三个简短提问:
53
+ 1) 放在哪里(~/.agents vs ./.agents)
54
+ 2) 启用哪些资产类型(skills/rules/commands/...)
55
+ 3) 投影到哪些 AI 工具(cursor/claude/codebuddy)
56
+ --yes / -y 全部用默认值,跳过交互(CI 友好)
57
+ --local 跳过位置选择,直接用 ./.agents
58
+ --source <p> 跳过位置选择,用指定路径(自定义路径会打印持久化提示)
59
+ --force 目标非空时仍然合并(默认会拒绝)
60
+ 管道 / 脚本场景(stdin 非 TTY)自动降级为默认值。
61
+ 生成的 agentlink.config.json 写在"未来 sync 会从哪跑"的位置
62
+ (--local 写 cwd,否则写 ~),不在 source 内部。
63
+
64
+ agentlink sync [--source <path>] [--target <dir> | --user] [-n] [-f] [--strict]
65
+ 刷新所有 symlink。source 按以下优先级解析:
66
+ --source flag → $AGENTLINK_SOURCE → ./.agents → ~/.agents
67
+ destination root 默认是 cwd;--user / -u 改为 $HOME(把 source
68
+ 投影到 ~/.cursor / ~/.claude / ...),--target <dir> 指定任意项目根。
69
+ --dry-run / -n 预览将做什么,不动文件系统
70
+ --force / -f 修复指向错误的 symlink
71
+ --strict flatten 撞名时报错退出(默认仅警告)
72
+
73
+ agentlink clean
74
+ 清掉每个启用 adapter 目录下的悬空 symlink(指向已删除文件)。
75
+
76
+ agentlink unlink
77
+ 移除所有指向 source 的 symlink,用于从项目中彻底卸载 agentlink。
78
+
79
+ agentlink doctor
80
+ 只读健康检查:adapter 可用性、link plan 大小、撞名预警、
81
+ 悬空链接、orphan 链接(之前 sync 留下、当前 plan 不再覆盖)。
82
+ ```
83
+
84
+ `-q/--quiet` 与 `-v/--verbose` 对所有命令通用。
85
+
86
+ ## source 与 config 解析
87
+
88
+ agentlink 把"**对什么数据操作**"(`.agents/` source)与"**怎么操作**"(`agentlink.config.json`)解耦:两者各有独立解析链,可以共享同一份 source 但每个项目用自己的 config 覆盖行为。
89
+
90
+ ### source 解析
91
+
92
+ | # | 来源 | 说明 |
93
+ |---|---|---|
94
+ | 1 | `--source <path>` | 显式 flag |
95
+ | 2 | `AGENTLINK_SOURCE` 环境变量 | 适合写在 shell rc |
96
+ | 3 | `./.agents` | **本地优先** — 克隆的项目自带 `.agents/` 时压过个人全局 |
97
+ | 4 | `~/.agents` | 个人推荐默认 |
98
+ | 5 | _(报错)_ | 提示用户跑 `agentlink init` |
99
+
100
+ ### config 解析
101
+
102
+ | # | 来源 | 说明 |
103
+ |---|---|---|
104
+ | 1 | `--config <path>` | 显式 flag |
105
+ | 2 | `AGENTLINK_CONFIG` 环境变量 | |
106
+ | 3 | 从 cwd 向上找最近的 `agentlink.config.json` | cwd 在 home 内时停在 home;cwd 在 home 外时走到 fs 根 |
107
+ | 4 | `~/agentlink.config.json` | 全局兜底 |
108
+ | 5 | _(默认值)_ | 没找到 = 视为空配置 `{}` |
109
+
110
+ 类似 git / eslint / tsconfig 的就近发现机制。
111
+
112
+ ## 配置文件
113
+
114
+ 配置文件可选——每个字段都是可选的且有合理默认值。格式是 **JSONC**(标准 JSON + `//` `/* */` 注释 + 尾逗号),所以 `agentlink init` 写出的种子文件自带注释,看一眼就能改,不必翻文档。
115
+
116
+ 严格的闭世界 schema(用 [zod] 校验):adapter 名、asset 类型、顶层字段拼错都会被友好地拒绝。
117
+
118
+ ```jsonc
119
+ {
120
+ // asset 类型白名单。默认:["skills", "rules", "commands"]
121
+ // 想启用 prompts / templates / agents 在这里加上即可
122
+ "include": ["skills", "rules", "commands"],
123
+
124
+ // asset 类型黑名单(永远压过 include)
125
+ "exclude": [],
126
+
127
+ // 各 adapter 的覆盖。值可以是 true / false / { layout: ... }
128
+ "adapters": {
129
+ "cursor": { "layout": { "commands": { "flatten": false } } },
130
+ "claude": true,
131
+ "codebuddy": false
132
+ }
133
+ }
134
+ ```
135
+
136
+ ## 内置 adapter(v1)
137
+
138
+ | 名称 | rootDir | Skills | Rules | Commands | Prompts |
139
+ |---|---|---|---|---|---|
140
+ | `cursor` | `.cursor/` | 嵌套 | 扁平,`.md` → `.mdc` | 扁平 | _跳过_ |
141
+ | `claude` | `.claude/` | 嵌套 | 嵌套 | 嵌套 | _未配置_ |
142
+ | `codebuddy` | `.codebuddy/` | 嵌套 | 嵌套 | 嵌套 | _未配置_ |
143
+
144
+ agentlink **只会**在 destination 下已经存在对应 rootDir 时才动它。**绝不会**主动帮你创建 `.cursor/`——要启用某个 agent,要么让 agent 自己跑一遍,要么手动 `mkdir .cursor` 表态。
145
+
146
+ 需要新 agent?v1 仅内置上述三家;提 PR 加一个新 adapter 文件即可。
147
+
148
+ ## 投影示意
149
+
150
+ ```
151
+ ~/.agents/skills/brainstorming/SKILL.md ─┐
152
+ ├─→ .cursor/skills/brainstorming/ (symlink)
153
+ ├─→ .claude/skills/brainstorming/ (symlink)
154
+ └─→ .codebuddy/skills/brainstorming/ (symlink)
155
+
156
+ ~/.agents/rules/coding.md ─→ .cursor/rules/coding.mdc (ext 重命名)
157
+ ~/.agents/commands/git/commit.md ─→ .cursor/commands/git__commit.md (flatten)
158
+ └→ .codebuddy/commands/git/commit.md (保留嵌套)
159
+ ```
160
+
161
+ ## 相比手写 symlink
162
+
163
+ - 所有链接都是**相对路径**:source 和 destination 一起搬家不会断
164
+ - `sync` 是**幂等的**:相同状态下重跑全部 `skipped`
165
+ - `unlink` 只移除"自己拥有"的(指向当前 source 的)链接,目录里其他手写内容不动
166
+ - `--dry-run` 精确告诉你"会做什么",零写盘
167
+
168
+ ## 运行要求
169
+
170
+ - Node 18+
171
+ - 支持 symlink 的 POSIX 风格文件系统。Windows 上请在 WSL 内运行或开启开发者模式
172
+
173
+ ## 状态
174
+
175
+ v1:skill / rule / command 链接、JSONC 配置、三个内置 adapter。
176
+
177
+ 不在 v1 范围(独立追踪):
178
+
179
+ - JS / TS 配置文件(`agentlink.config.{js,ts}`)
180
+ - 用户自定义 adapter(通过配置)
181
+ - `link <src> <dest>` 命令式接口
182
+ - watch 模式
183
+
184
+ ## 许可证
185
+
186
+ MIT.
187
+
188
+ [zod]: https://zod.dev
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import('../dist/cli.js').catch((err) => {
3
+ console.error('[agentlink] failed to start:', err);
4
+ process.exit(1);
5
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }