rulemux 0.0.1 → 0.1.2

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.md CHANGED
@@ -1,31 +1,257 @@
1
1
  # rulemux
2
2
 
3
- > 一份**中央真源**规则 → 投递到各家 AI coding agent(Claude Code / Trae / CodeBuddy / WorkBuddy / Codex / OpenCode / DeepSeek Harness)。
4
- > 效果与 token 与直接写 `AGENTS.md` 一致:**永不淡出、不累积、不用软链、加删文件自由**。
3
+ > One set of rules, delivered to every AI coding agent.
4
+ > Same effect and same token cost as writing `AGENTS.md` by hand — **never fades out, never accumulates, no symlinks, free to add and remove files**.
5
5
 
6
- ## 这是什么
6
+ [中文版](README.zh-CN.md) | [Design docs](docs/design/architecture.md)
7
7
 
8
- 你有一份规则文档(编码约定、项目规矩……),希望每个 AI coding agent 在每个工作区都读到它,且效果和直接写进 `AGENTS.md` 一模一样。
9
- `rulemux` 负责把这份真源同步到各家 agent 的工作区规则目录 —— 一处管理,多处生效。
8
+ ---
10
9
 
11
- **核心做法**:hook 只当「投递员」,把真源文档**真实拷贝**进各 agent 原生加载的规则目录,由 harness 自己读 ⇒ 享有静态前缀语义,因此永不淡出、不累积。
12
- (为什么不靠 hook 注入:见 [`docs/design/architecture.md`](docs/design/architecture.md) §二)
10
+ ## 1. What is this
13
11
 
14
- ## 安装
12
+ You maintain a set of rule documents (coding conventions, project rules, …) and want every AI
13
+ coding agent to read them in every workspace — with the exact same effect as if you had written
14
+ `AGENTS.md` yourself.
15
15
 
16
- ⬜ 待补(项目尚未落码)。
16
+ `rulemux` takes the source files you list in a config and copies them into each agent's **native
17
+ workspace rules directory**. You manage them in one place; they take effect everywhere.
17
18
 
18
- ## 用法
19
+ - rulemux **does not own or maintain any rule content**. Your source files stay yours — rulemux
20
+ only copies them. Which agents / workspaces they apply to is declared in your config.
21
+ - **The session hook is only the courier.** It is not used to inject text. Files are really copied
22
+ into the directory the agent loads natively, so they enjoy static-prefix semantics: they never
23
+ fade out mid-conversation, and they never accumulate.
24
+ - Invariants: **no symlinks** (real copies only) and **free add/remove** (delete a source from the
25
+ config and its copy disappears on the next sync).
19
26
 
20
- ⬜ 待补(项目尚未落码)。
27
+ > Why not "just inject with a hook"? Hook injection lands in the dynamic part of the context: it
28
+ > gets summarised away on compaction (fades out) or re-appended every turn (token blow-up).
29
+ > See [design/architecture.md](docs/design/architecture.md) §一.
21
30
 
22
- ## 文档
31
+ ---
23
32
 
24
- | 想看 | 去哪 |
33
+ ## 2. Supported scope
34
+
35
+ rulemux ships **one adapter per agent**, and an adapter is only installable once its rules
36
+ directory and hook location have been confirmed by a real canary test. Today:
37
+
38
+ | Agent | Tier | Rules directory | Status |
39
+ |---|---|---|---|
40
+ | **codebuddy** | Tier-1 (real copy) | `.codebuddy/rules/` | ✅ **Verified — installable** |
41
+ | **workbuddy** | Tier-1 (real copy) | `.codebuddy/rules/` (shared with CodeBuddy) | ✅ **Verified — installable** |
42
+ | claude (Claude Code) | Tier-1 | `.claude/rules/` | ⚠️ registered, **not verified yet** — cannot be installed |
43
+ | trae (Trae) | Tier-1 | `.trae/rules/` | ⚠️ registered, **not verified yet** — cannot be installed |
44
+ | codex | Tier-2 (injection) | none — injects into context | ⚠️ registered, **not verified yet** |
45
+ | opencode | Tier-2 (injection) | none — injects into context | ⚠️ registered, **not verified yet** |
46
+
47
+ - `rulemux init` **refuses** any agent that is not verified — it will not half-install an adapter
48
+ whose behaviour has not been proven. `rulemux doctor` marks unverified agents with ⚠.
49
+ - **Tier-2 is a deliberate downgrade** for agents that have no rules directory (they only read a
50
+ single `AGENTS.md`). It injects via the session hook and never touches your own `AGENTS.md`, but
51
+ it cannot satisfy the "never fades out" bar. See
52
+ [design/features/hook-injection.md](docs/design/features/hook-injection.md).
53
+
54
+ ---
55
+
56
+ ## 3. Install
57
+
58
+ rulemux is a **single Go binary with zero third-party dependencies**.
59
+
60
+ ```bash
61
+ # a) from a GitHub Release (recommended): put the binary on your PATH
62
+ # e.g. /usr/local/bin/rulemux (Windows: rulemux.exe)
63
+
64
+ # b) from source
65
+ go install github.com/cq-guojia/rulemux@latest
66
+ # or
67
+ git clone https://github.com/cq-guojia/rulemux.git && cd rulemux && go build -o rulemux .
68
+
69
+ # c) via npm (convenience channel that puts the binary on your PATH)
70
+ npm i -g rulemux
71
+ ```
72
+
73
+ There is **no auto-update**. Upgrades are manual and handled by your package manager
74
+ (`go install …@latest`, Homebrew/Scoop/apt later on). This is a deliberate decision — see
75
+ [design/requirements.md](docs/design/requirements.md) §五.
76
+
77
+ ---
78
+
79
+ ## 4. Quick start
80
+
81
+ ```bash
82
+ # 1. Install the session hook for an agent (--agent is REQUIRED)
83
+ rulemux init --agent codebuddy
84
+ # First run also writes a sample config to ~/.rulemux/config.toml
85
+
86
+ # 2. Edit ~/.rulemux/config.toml and point `path` at your real rule files
87
+
88
+ rulemux doctor # 3. Self-check: binary/PATH, agents, config validity
89
+ rulemux verify # 4. Canary check: drop a probe and ask the agent to recite its token
90
+
91
+ # From now on every new session triggers `rulemux sync --agent codebuddy` automatically.
92
+
93
+ rulemux uninstall --agent codebuddy # remove rulemux again (--yes skips the confirmation)
94
+ ```
95
+
96
+ **Where the hook goes:** into the **user-level host config** `~/.codebuddy/settings.json` (the same
97
+ place a tool like Hindsight registers itself). **Install once, and it applies to every workspace** —
98
+ you do *not* re-run `init` per project. When it fires, rulemux uses the current workspace (its cwd)
99
+ to match the `workspace` entries in your config and decides what to deliver.
100
+
101
+ ---
102
+
103
+ ## 5. Configuration
104
+
105
+ Config file: `~/.rulemux/config.toml` (override with `--config <path>` on any command).
106
+
107
+ ### 5.1 Each `[[source]]`
108
+
109
+ | Field | Meaning |
110
+ |---|---|
111
+ | `path` | Source file(s), anywhere on disk. Single value or a list. A list shares the `agents`/`workspace` below. |
112
+ | `agents` | Which agents receive this batch. Omitted = all supported agents. |
113
+ | `workspace` | Which workspaces these rules apply to. Omitted / `"*"` / `"**"` / `"all"` = every workspace. Single value, a list, or a glob. |
114
+
115
+ Globbing follows the usual rules: `*` is one path segment, `**` spans segments and may appear in
116
+ the middle — e.g. `workspace = "/abs/**/B"` matches a directory named `B` at any depth.
117
+
118
+ ```toml
119
+ [[source]]
120
+ path = ["/your/rules/a.md", "/your/rules/b.md"]
121
+ agents = ["codebuddy"] # omit to target every supported agent
122
+ # workspace is omitted => every workspace
123
+ # workspace = ["/path/to/proj-a", "/path/to/proj-b"]
124
+ # workspace = "/abs/**/B" # glob: any depth, named B
125
+ ```
126
+
127
+ ### 5.2 Bundling with "groups" (optional)
128
+
129
+ When you have many files, bundle them and reference the bundle by name.
130
+
131
+ ```toml
132
+ # ---- File groups ---------------------------------------------------------
133
+ [[file_group]]
134
+ name = "base"
135
+ path = ["/your/rules/team-conventions.md", "/your/rules/style.md"]
136
+
137
+ [[file_group]]
138
+ name = "proj"
139
+ use = ["base"] # nests the base group (a list: ["base", "dev"])
140
+ path = ["/your/rules/project-a.md"]
141
+
142
+ # ---- Workspace groups ----------------------------------------------------
143
+ [[workspace_group]]
144
+ name = "dev"
145
+ workspace = ["/path/to/proj-1", "/path/to/proj-2"]
146
+
147
+ # ---- Use them ------------------------------------------------------------
148
+ [[source]]
149
+ groups = ["base", "proj"] # expands to every file in those groups
150
+ path = ["/your/rules/extra.md"] # mixing is allowed: groups + standalone files
151
+ agents = ["codebuddy"]
152
+ workspace_groups = ["dev"] # expands to every workspace in the group
153
+ workspace = ["/path/to/standalone"] # also allowed alongside workspace_groups
154
+ ```
155
+
156
+ Things worth knowing:
157
+
158
+ - **`use` is a list** — `use = ["dev", "qa"]` reuses several groups at once, and groups nest
159
+ (A pulls in B plus its own files).
160
+ - **Mixing is allowed**: `groups` with `path`, and `workspace_groups` with `workspace`, in the same
161
+ source. The result is the union.
162
+ - **Duplicates are harmless** — everything is deduplicated by value, so each file is processed once.
163
+ - File groups and workspace groups are **separate namespaces**; the same name may be used in both.
164
+
165
+ ### 5.3 What sync does, and what it never touches
166
+
167
+ On every sync rulemux computes the set of prefixed files that should exist, then removes any
168
+ `.rulemux__*` file that is not in that set, copies/overwrites the ones that are missing or changed,
169
+ and skips the rest.
170
+
171
+ - Destination name: `.rulemux__` + source basename (a short hash is appended on name collisions).
172
+ - **Your source files are only ever read** — never modified or deleted.
173
+ - **Files without the `.rulemux__` prefix in the rules directory are never touched**, so your own
174
+ rule files stay safe.
175
+
176
+ ---
177
+
178
+ ## 6. Uninstalling
179
+
180
+ ```bash
181
+ rulemux uninstall --agent codebuddy # one agent (comma-separated for several)
182
+ rulemux uninstall --off # every agent (--all is the same)
183
+ rulemux uninstall --agent codebuddy --yes # skip the confirmation prompt
184
+ ```
185
+
186
+ It removes rulemux's own hook entry (other tools' hooks in the same file are preserved) and deletes
187
+ the `.rulemux__*` files it previously delivered. Because the hook lives in the user-level config,
188
+ rulemux also **revisits every workspace recorded in its ledger** (`~/.rulemux/workspaces.json`) and
189
+ cleans those too — otherwise, with the hook gone, that residue could never be removed again. You are
190
+ shown the list of workspaces before anything is deleted.
191
+
192
+ ---
193
+
194
+ ## 7. Commands
195
+
196
+ | Command | What it does |
197
+ |---|---|
198
+ | `rulemux sync [--agent <id>] [--config <path>] [--workspace <dir>]` | Sync rules (called by each agent's SessionStart hook) |
199
+ | `rulemux inject --agent <id> [--config <path>]` | Tier-2: print rules to stdout for hook injection |
200
+ | `rulemux init --agent <id[,id...]> [--config <path>] [--workspace <dir>]` | Write a sample config and install the SessionStart hook |
201
+ | `rulemux doctor [--config <path>] [--workspace <dir>]` | Environment self-check |
202
+ | `rulemux verify --agent <id> [--clean] [--workspace <dir>]` | Canary acceptance test |
203
+ | `rulemux uninstall --agent <id[,id...]> \| --off \| --all [--yes]` | Remove hooks and delivered files |
204
+
205
+ Run `rulemux` with no arguments for the full help.
206
+
207
+ ---
208
+
209
+ ## 8. Roadmap
210
+
211
+ Ongoing work and what comes next are tracked in [docs/PROGRESS.md](docs/PROGRESS.md). In short:
212
+
213
+ - **More agents** — finish the adapters that are already registered but unverified:
214
+ - **Trae** (`.trae/rules/`) and **Claude Code** (`.claude/rules/`) as Tier-1;
215
+ - **Codex** and **OpenCode** as Tier-2 injection.
216
+ Each one needs its rules directory and hook location confirmed by a real canary run before it is
217
+ switched on. The checklist for adding an agent lives in
218
+ [design/features/agent-onboarding.md](docs/design/features/agent-onboarding.md).
219
+ - **Distribution** — GitHub Actions cross-compilation plus Release artifacts (this also feeds the
220
+ npm package), and publishing the npm package properly.
221
+ - **Verification tooling** — make the canary check repeatable per agent.
222
+ - Rule content transformation, templating, and automatic self-update are **explicitly out of scope**
223
+ ([design/requirements.md](docs/design/requirements.md) §五).
224
+
225
+ ---
226
+
227
+ ## 9. Releasing (maintainers)
228
+
229
+ ```bash
230
+ npm version patch|minor|major # bumps package.json and creates the git tag v0.x.y
231
+ git push --follow-tags
232
+ ```
233
+
234
+ Pushing the tag triggers [`.github/workflows/release.yml`](.github/workflows/release.yml):
235
+ cross-compile all platform binaries, attach them to a GitHub Release, and publish the
236
+ npm package with the tag's version. Set the `NPM_TOKEN` repository secret to enable
237
+ the npm step (it is skipped with a warning if absent). A plain CI run
238
+ ([`ci.yml`](.github/workflows/ci.yml)) runs build/vet/tests/smoke on every push.
239
+
240
+ ---
241
+
242
+ ## 10. License
243
+
244
+ MIT — see [LICENSE](LICENSE).
245
+
246
+ ---
247
+
248
+ ## 10. Documentation
249
+
250
+ | Want to read | Where |
25
251
  |---|---|
26
- | 现在做到哪、欠什么 | [`docs/PROGRESS.md`](docs/PROGRESS.md) |
27
- | 文档怎么摆、怎么写 | [`docs/README.md`](docs/README.md) |
28
- | **用户要什么**(需求 / 验收标准) | [`docs/design/requirements.md`](docs/design/requirements.md) |
29
- | 设计(核心原理 / 选型 / 命名) | [`docs/design/architecture.md`](docs/design/architecture.md) |
30
- | 功能列表 | [`docs/design/features.md`](docs/design/features.md) |
31
- | 各家 agent 的规则目录 | [`docs/design/external/agent-rules-dirs.md`](docs/design/external/agent-rules-dirs.md) |
252
+ | What the user actually wants (requirements / acceptance) | [docs/design/requirements.md](docs/design/requirements.md) |
253
+ | Why it is designed this way | [docs/design/architecture.md](docs/design/architecture.md) |
254
+ | Feature list | [docs/design/features.md](docs/design/features.md) |
255
+ | Checklist for adding a new agent | [docs/design/features/agent-onboarding.md](docs/design/features/agent-onboarding.md) |
256
+ | Each agent's rules directory (external facts) | [docs/design/external/agent-rules-dirs.md](docs/design/external/agent-rules-dirs.md) |
257
+ | Current progress and open items | [docs/PROGRESS.md](docs/PROGRESS.md) |
@@ -0,0 +1,241 @@
1
+ # rulemux
2
+
3
+ > 一份规则,投递到各家 AI coding agent。
4
+ > 效果与 token 与直接写 `AGENTS.md` 一致:**永不淡出、不累积、不用软链、加删文件自由**。
5
+
6
+ [English](README.md) | [设计文档](docs/design/architecture.md)
7
+
8
+ ---
9
+
10
+ ## 1. 这是什么
11
+
12
+ 你维护着一套规则文档(编码约定、项目规矩……),希望每个 AI coding agent 在每个工作区都读到它,
13
+ 且效果和直接写进 `AGENTS.md` 一模一样。
14
+
15
+ `rulemux` 把你在配置里列出的源文件,复制进各 agent **原生的工作区规则目录** —— 一处管理,多处生效。
16
+
17
+ - rulemux **不持有、不维护任何规则内容**。源文件完全由你维护,rulemux 只负责复制;
18
+ 「适用于哪些 agent / 哪些工作区」在你的配置里声明。
19
+ - **会话钩子只当「投递员」,不用来注入文本**。文件是真正拷进 agent 原生加载的目录,
20
+ 因此享有静态前缀语义 —— 不会随对话老化淡出,也不会每轮累积。
21
+ - 底线:**不用软链**(一律真实拷贝)、**加删自由**(配置里删掉某源文件,下次同步它的副本即消失)。
22
+
23
+ > 为什么不直接用钩子注入?注入落在上下文的动态区,压缩时会被摘要掉(淡出),
24
+ > 或每轮追加(token 爆炸)。见 [`docs/design/architecture.md`](docs/design/architecture.md) §一。
25
+
26
+ ---
27
+
28
+ ## 2. 支持范围
29
+
30
+ rulemux **每个 agent 一套适配器**;只有「规则目录 + 钩子落点」经真实 canary 实测坐实的 agent
31
+ 才允许安装。当前:
32
+
33
+ | Agent | 层级 | 规则目录 | 状态 |
34
+ |---|---|---|---|
35
+ | **codebuddy** | Tier-1(真实拷贝) | `.codebuddy/rules/` | ✅ **已验证,可安装** |
36
+ | **workbuddy** | Tier-1(真实拷贝) | `.codebuddy/rules/`(与 CodeBuddy 共用) | ✅ **已验证,可安装** |
37
+ | claude(Claude Code) | Tier-1 | `.claude/rules/` | ⚠️ 已注册,**尚未验证**,不可安装 |
38
+ | trae(Trae) | Tier-1 | `.trae/rules/` | ⚠️ 已注册,**尚未验证**,不可安装 |
39
+ | codex | Tier-2(注入) | 无 —— 注入上下文 | ⚠️ 已注册,**尚未验证** |
40
+ | opencode | Tier-2(注入) | 无 —— 注入上下文 | ⚠️ 已注册,**尚未验证** |
41
+
42
+ - `rulemux init` **会拒绝**未验证的 agent —— 不会给你装一个行为未经验证的半成品。
43
+ `rulemux doctor` 会给未验证的 agent 标 ⚠。
44
+ - **Tier-2 是刻意的降级**:面向没有规则目录、只认单个 `AGENTS.md` 的 agent,走会话钩子注入,
45
+ 且绝不碰你自己的 `AGENTS.md`;但它满足不了「永不淡出」。见
46
+ [`docs/design/features/hook-injection.md`](docs/design/features/hook-injection.md)。
47
+
48
+ ---
49
+
50
+ ## 3. 安装
51
+
52
+ rulemux 是**零第三方依赖的 Go 单二进制**。
53
+
54
+ ```bash
55
+ # a) 从 GitHub Release 取预编译产物(推荐),放到 PATH
56
+ # 例如 /usr/local/bin/rulemux(Windows 用 rulemux.exe)
57
+
58
+ # b) 从源码
59
+ go install github.com/cq-guojia/rulemux@latest
60
+ # 或
61
+ git clone https://github.com/cq-guojia/rulemux.git && cd rulemux && go build -o rulemux .
62
+
63
+ # c) 通过 npm(把二进制放进 PATH 的便捷通道)
64
+ npm i -g rulemux
65
+ ```
66
+
67
+ **没有自动更新**。升级手动、交给包管理器(`go install …@latest`,将来 Homebrew / Scoop / apt)。
68
+ 这是刻意决策,见 [`docs/design/requirements.md`](docs/design/requirements.md) §五。
69
+
70
+ ---
71
+
72
+ ## 4. 快速开始
73
+
74
+ ```bash
75
+ # 1. 为指定 agent 安装会话钩子(--agent 必填)
76
+ rulemux init --agent codebuddy
77
+ # 首次运行还会生成示例配置 ~/.rulemux/config.toml
78
+
79
+ # 2. 编辑 ~/.rulemux/config.toml,把 path 改成你真实的规则文件
80
+
81
+ rulemux doctor # 3. 自检:二进制/PATH、各 agent 状态、配置合法性
82
+ rulemux verify # 4. canary 验收:投放探针,开新会话让 agent 念出暗号
83
+
84
+ # 此后每次开新会话,都会自动触发 rulemux sync --agent codebuddy
85
+
86
+ rulemux uninstall --agent codebuddy # 卸载(--yes 跳过确认)
87
+ ```
88
+
89
+ **钩子装在哪**:装进 **user 级 host 配置** `~/.codebuddy/settings.json`(与 Hindsight 的落点同类)。
90
+ **一次安装、对所有工作区生效**,不必每个项目再跑一次 `init`。触发时 rulemux 以当前工作区(cwd)
91
+ 去匹配配置里的 `workspace` 条目,决定投递哪些规则。
92
+
93
+ ---
94
+
95
+ ## 5. 配置说明
96
+
97
+ 配置文件:`~/.rulemux/config.toml`(各命令均可用 `--config <path>` 指定其它路径)。
98
+
99
+ ### 5.1 每条 `[[source]]`
100
+
101
+ | 字段 | 含义 |
102
+ |---|---|
103
+ | `path` | 源文件,磁盘任意位置;单个值或数组。数组内文件共享下面的 `agents` / `workspace` |
104
+ | `agents` | 投递给哪些 agent;省略 = 全部已支持的 agent |
105
+ | `workspace` | 适用哪些工作区;省略 / `"*"` / `"**"` / `"all"` = 所有工作区;单个值、数组或 glob |
106
+
107
+ glob 沿用业界惯例:`*` 匹配单个路径段,`**` 跨段递归且可出现在中间 ——
108
+ 例如 `workspace = "/abs/**/B"` 匹配任意深度下名为 `B` 的目录。
109
+
110
+ ```toml
111
+ [[source]]
112
+ path = ["/你的规则/a.md", "/你的规则/b.md"]
113
+ agents = ["codebuddy"] # 省略则投递给全部已支持 agent
114
+ # workspace 省略 => 所有工作区
115
+ # workspace = ["/path/to/proj-a", "/path/to/proj-b"]
116
+ # workspace = "/abs/**/B" # glob:任意深度、名为 B
117
+ ```
118
+
119
+ ### 5.2 用「组」打包(可选)
120
+
121
+ 文件多了之后,可以打包成组,按组名引用。
122
+
123
+ ```toml
124
+ # ---- 文件组 --------------------------------------------------------------
125
+ [[file_group]]
126
+ name = "base"
127
+ path = ["/你的规则/team-conventions.md", "/你的规则/style.md"]
128
+
129
+ [[file_group]]
130
+ name = "proj"
131
+ use = ["base"] # 嵌套引用 base 组(数组:["base", "dev"])
132
+ path = ["/你的规则/project-a.md"]
133
+
134
+ # ---- 工作区分组 ----------------------------------------------------------
135
+ [[workspace_group]]
136
+ name = "dev"
137
+ workspace = ["/path/to/proj-1", "/path/to/proj-2"]
138
+
139
+ # ---- 引用它们 ------------------------------------------------------------
140
+ [[source]]
141
+ groups = ["base", "proj"] # 展开成这些组里的所有文件
142
+ path = ["/你的规则/extra.md"] # 允许混合:组 + 单独文件
143
+ agents = ["codebuddy"]
144
+ workspace_groups = ["dev"] # 展开成组内的所有工作区
145
+ workspace = ["/path/to/standalone"] # 也可与 workspace_groups 同时写
146
+ ```
147
+
148
+ 要点:
149
+
150
+ - **`use` 是数组** —— `use = ["dev", "qa"]` 一次复用多个组,且支持嵌套(A 组引入 B 组再加自己的文件)。
151
+ - **允许混合书写**:同一条 source 里 `groups` 可与 `path` 并存,`workspace_groups` 可与 `workspace` 并存,结果取并集。
152
+ - **重复无害** —— 最终按值去重,每个文件只处理一次。
153
+ - 文件组与工作区分组是**两套独立命名空间**,允许同名。
154
+
155
+ ### 5.3 同步做了什么,以及绝不碰什么
156
+
157
+ 每次同步:算出「应该存在的带前缀文件集合」,目标目录里不在这个集合中的 `.rulemux__*` 一律删除(删残留),
158
+ 缺失或内容不一致的复制/覆盖,其余跳过。
159
+
160
+ - 目标文件名:`.rulemux__` + 源 basename(同名冲突时追加短 hash)。
161
+ - **源文件只被读取** —— 绝不修改、绝不删除。
162
+ - **规则目录里不带 `.rulemux__` 前缀的文件绝不触碰**,你自己的规则文件始终安全。
163
+
164
+ ---
165
+
166
+ ## 6. 卸载
167
+
168
+ ```bash
169
+ rulemux uninstall --agent codebuddy # 单个 agent(逗号分隔可多个)
170
+ rulemux uninstall --off # 全部 agent(--all 等价)
171
+ rulemux uninstall --agent codebuddy --yes # 跳过交互确认
172
+ ```
173
+
174
+ 它会移除 rulemux 自己的钩子条目(同一文件里其它工具的钩子会保留),并删掉此前投递的 `.rulemux__*` 文件。
175
+ 由于钩子在 user 级配置里,rulemux 还会**按账本(~/.rulemux/workspaces.json)回访所有记录过的工作区**
176
+ 一并清理 —— 否则钩子一去,那些残留就再没机会被删掉了。删除前会把要回访的工作区列表给你确认。
177
+
178
+ ---
179
+
180
+ ## 7. 命令一览
181
+
182
+ | 命令 | 作用 |
183
+ |---|---|
184
+ | `rulemux sync [--agent <id>] [--config <path>] [--workspace <dir>]` | 同步规则(由各 agent 的 SessionStart 钩子调用) |
185
+ | `rulemux inject --agent <id> [--config <path>]` | Tier-2:把规则输出到 stdout 供钩子注入 |
186
+ | `rulemux init --agent <id[,id...]> [--config <path>] [--workspace <dir>]` | 生成示例配置并安装 SessionStart 钩子 |
187
+ | `rulemux doctor [--config <path>] [--workspace <dir>]` | 环境自检 |
188
+ | `rulemux verify --agent <id> [--clean] [--workspace <dir>]` | canary 验收 |
189
+ | `rulemux uninstall --agent <id[,id...]> \| --off \| --all [--yes]` | 移除钩子与已投递文件 |
190
+
191
+ 直接运行 `rulemux`(不带参数)可看完整帮助。
192
+
193
+ ---
194
+
195
+ ## 8. 后续计划
196
+
197
+ 在办事项见 [`docs/PROGRESS.md`](docs/PROGRESS.md)。概要:
198
+
199
+ - **接入更多 agent** —— 补齐已注册但尚未验证的适配器:
200
+ - **Trae**(`.trae/rules/`)、**Claude Code**(`.claude/rules/`)走 Tier-1;
201
+ - **Codex**、**OpenCode** 走 Tier-2 注入。
202
+ 每个 agent 都要先经真实 canary 坐实「规则目录 + 钩子落点」才开放。
203
+ 接入一个新 agent 的完整清单见
204
+ [`docs/design/features/agent-onboarding.md`](docs/design/features/agent-onboarding.md)。
205
+ - **分发** —— GitHub Actions 交叉编译 + Release 产物(同时供 npm 包使用),并正式发布 npm 包。
206
+ - **验证工具** —— 让 canary 验收对每个 agent 可重复执行。
207
+ - 规则内容改写/模板渲染、以及自动自我更新,**明确不做**
208
+ ([`docs/design/requirements.md`](docs/design/requirements.md) §五)。
209
+
210
+ ---
211
+
212
+ ## 9. 发版(维护者)
213
+
214
+ ```bash
215
+ npm version patch|minor|major # 更新 package.json 并创建 git tag v0.x.y
216
+ git push --follow-tags
217
+ ```
218
+
219
+ 推送 tag 会触发 [`.github/workflows/release.yml`](.github/workflows/release.yml):
220
+ 自动交叉编译全部平台二进制、挂到 GitHub Release、并按 tag 版本发布 npm 包。
221
+ 需在仓库 Secrets 里配置 `NPM_TOKEN` 才会发布 npm(未配置时跳过并告警)。
222
+ 普通的 CI([`ci.yml`](.github/workflows/ci.yml))在每次 push 时跑 build/vet/测试/冒烟。
223
+
224
+ ---
225
+
226
+ ## 10. 许可证
227
+
228
+ MIT —— 见 [LICENSE](LICENSE)。
229
+
230
+ ---
231
+
232
+ ## 10. 文档索引
233
+
234
+ | 想看什么 | 去哪 |
235
+ |---|---|
236
+ | 用户到底要什么(需求 / 验收标准) | [`docs/design/requirements.md`](docs/design/requirements.md) |
237
+ | 为什么这么设计 | [`docs/design/architecture.md`](docs/design/architecture.md) |
238
+ | 功能列表 | [`docs/design/features.md`](docs/design/features.md) |
239
+ | 接入新 agent 的清单 | [`docs/design/features/agent-onboarding.md`](docs/design/features/agent-onboarding.md) |
240
+ | 各家 agent 的规则目录(外部事实) | [`docs/design/external/agent-rules-dirs.md`](docs/design/external/agent-rules-dirs.md) |
241
+ | 当前进度与未决项 | [`docs/PROGRESS.md`](docs/PROGRESS.md) |
package/bin/rulemux.js ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // npm launcher for rulemux.
5
+ //
6
+ // rulemux itself is a single Go binary with no runtime dependencies. This shim
7
+ // exists only so that `npm i -g rulemux` puts a working `rulemux` command on your
8
+ // PATH. It resolves the real binary in this order:
9
+ //
10
+ // 1. a binary bundled for this platform in ../dist/ (produced by scripts/build-dist.sh)
11
+ // 2. a `rulemux` binary already on your PATH (e.g. installed from a GitHub Release)
12
+ // 3. otherwise: print install instructions and exit non-zero
13
+ //
14
+ // It never rewrites your arguments and always forwards the child's exit code.
15
+
16
+ const fs = require("fs");
17
+ const os = require("os");
18
+ const path = require("path");
19
+ const { spawnSync } = require("child_process");
20
+
21
+ function platformKey() {
22
+ const plat = process.platform === "win32" ? "windows" : process.platform;
23
+ let arch = process.arch;
24
+ if (arch === "x64") arch = "amd64";
25
+ else if (arch === "ia32") arch = "386";
26
+ return `${plat}-${arch}`;
27
+ }
28
+
29
+ function bundledCandidates() {
30
+ const ext = process.platform === "win32" ? ".exe" : "";
31
+ const key = platformKey();
32
+ return [
33
+ path.join(__dirname, "..", "dist", `rulemux-${key}${ext}`),
34
+ // Some cross-builds use the Go default naming; keep a couple of aliases.
35
+ path.join(__dirname, "..", "dist", `rulemux-${process.platform}-${process.arch}${ext}`),
36
+ ];
37
+ }
38
+
39
+ function onPath() {
40
+ const cmd = process.platform === "win32" ? "where" : "which";
41
+ const r = spawnSync(cmd, ["rulemux"], { stdio: "ignore" });
42
+ return r.status === 0 ? "rulemux" : null;
43
+ }
44
+
45
+ function resolve() {
46
+ for (const c of bundledCandidates()) {
47
+ if (fs.existsSync(c)) return c;
48
+ }
49
+ return onPath();
50
+ }
51
+
52
+ function main() {
53
+ const bin = resolve();
54
+ if (!bin) {
55
+ process.stderr.write(
56
+ "rulemux: no rulemux binary found.\n" +
57
+ "\n" +
58
+ "Install one of these first:\n" +
59
+ " go install github.com/cq-guojia/rulemux@latest\n" +
60
+ " or download a binary from https://github.com/cq-guojia/rulemux/releases\n" +
61
+ " and make sure it is on your PATH.\n"
62
+ );
63
+ process.exit(1);
64
+ }
65
+
66
+ // npm tarballs do not always preserve the executable bit; be defensive.
67
+ if (process.platform !== "win32" && fs.existsSync(bin)) {
68
+ try {
69
+ fs.chmodSync(bin, 0o755);
70
+ } catch (_) {
71
+ /* ignore: it may already be fine, or the fs may be read-only */
72
+ }
73
+ }
74
+
75
+ const r = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
76
+ if (r.error) {
77
+ process.stderr.write(`rulemux: failed to run ${bin}: ${r.error.message}\n`);
78
+ process.exit(1);
79
+ }
80
+ process.exit(r.status === null ? 1 : r.status);
81
+ }
82
+
83
+ main();
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,18 +1,42 @@
1
1
  {
2
2
  "name": "rulemux",
3
- "version": "0.0.1",
4
- "description": "一份中央真源规则 → 同步到各家 AI coding agent 的工作区规则目录;效果与 token 与直接写 AGENTS.md 一致。",
3
+ "version": "0.1.2",
4
+ "description": "One set of rules, delivered to every AI coding agent: copies the rule files you declare into each agent's native workspace rules directory, with the same effect and token cost as writing AGENTS.md by hand.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/cq-guojia/rulemux.git"
9
9
  },
10
+ "homepage": "https://github.com/cq-guojia/rulemux#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/cq-guojia/rulemux/issues"
13
+ },
14
+ "bin": {
15
+ "rulemux": "bin/rulemux.js"
16
+ },
17
+ "files": [
18
+ "bin",
19
+ "dist",
20
+ "README.md",
21
+ "README.zh-CN.md",
22
+ "LICENSE"
23
+ ],
24
+ "scripts": {
25
+ "build:dist": "bash scripts/build-dist.sh",
26
+ "prepublishOnly": "npm run build:dist"
27
+ },
28
+ "engines": {
29
+ "node": ">=16"
30
+ },
10
31
  "keywords": [
11
- "agents",
32
+ "rulemux",
12
33
  "rules",
34
+ "agents",
13
35
  "agents-md",
14
- "claude-code",
36
+ "ai-coding-agent",
15
37
  "codebuddy",
38
+ "workbuddy",
39
+ "claude-code",
16
40
  "trae",
17
41
  "codex",
18
42
  "opencode",