rulesync-cli 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +222 -0
  3. package/package.json +40 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Masao Kitamura
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/dist/index.js ADDED
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { readFileSync as readFileSync3 } from "fs";
5
+ import { Command } from "commander";
6
+
7
+ // src/commands/login.ts
8
+ import { createInterface } from "readline";
9
+
10
+ // src/config.ts
11
+ import { readFileSync, writeFileSync, existsSync } from "fs";
12
+ import { join } from "path";
13
+ import { homedir } from "os";
14
+ var CONFIG_FILE = ".rulesync.json";
15
+ var AUTH_DIR = join(homedir(), ".rulesync");
16
+ var AUTH_FILE = join(AUTH_DIR, "auth.json");
17
+ async function loadProjectConfig() {
18
+ const configPath = join(process.cwd(), CONFIG_FILE);
19
+ if (!existsSync(configPath)) return null;
20
+ const raw = readFileSync(configPath, "utf-8");
21
+ return JSON.parse(raw);
22
+ }
23
+ async function saveProjectConfig(config) {
24
+ const configPath = join(process.cwd(), CONFIG_FILE);
25
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
26
+ }
27
+ async function loadAuthConfig() {
28
+ if (!existsSync(AUTH_FILE)) return null;
29
+ const raw = readFileSync(AUTH_FILE, "utf-8");
30
+ return JSON.parse(raw);
31
+ }
32
+ async function saveAuthConfig(config) {
33
+ const { mkdirSync } = await import("fs");
34
+ mkdirSync(AUTH_DIR, { recursive: true });
35
+ writeFileSync(AUTH_FILE, JSON.stringify(config, null, 2) + "\n");
36
+ }
37
+
38
+ // src/commands/login.ts
39
+ async function prompt(question) {
40
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
41
+ return new Promise((resolve) => {
42
+ rl.question(question, (answer) => {
43
+ rl.close();
44
+ resolve(answer.trim());
45
+ });
46
+ });
47
+ }
48
+ async function login() {
49
+ console.log("RuleSync Login\n");
50
+ const apiKey = await prompt("API Key (from Settings page): ");
51
+ if (!apiKey.startsWith("rs_")) {
52
+ console.error("Invalid key format. Keys start with rs_");
53
+ process.exit(1);
54
+ }
55
+ const apiUrl = await prompt("API URL [http://localhost:3000]: ");
56
+ await saveAuthConfig({
57
+ apiKey,
58
+ apiUrl: apiUrl || "http://localhost:3000"
59
+ });
60
+ console.log("\nAuthenticated! Config saved to ~/.rulesync/auth.json");
61
+ }
62
+
63
+ // src/commands/init.ts
64
+ import { createInterface as createInterface2 } from "readline";
65
+
66
+ // src/api.ts
67
+ async function apiRequest(path, options = {}) {
68
+ const authConfig = await loadAuthConfig();
69
+ if (!authConfig) {
70
+ throw new Error("Not authenticated. Run: rulesync login");
71
+ }
72
+ const url = `${authConfig.apiUrl}${path}`;
73
+ const res = await fetch(url, {
74
+ ...options,
75
+ headers: {
76
+ "Content-Type": "application/json",
77
+ Authorization: `Bearer ${authConfig.apiKey}`,
78
+ ...options.headers
79
+ }
80
+ });
81
+ if (!res.ok) {
82
+ const body = await res.text();
83
+ throw new Error(`API error ${res.status}: ${body}`);
84
+ }
85
+ return res.json();
86
+ }
87
+
88
+ // src/commands/init.ts
89
+ async function prompt2(question, defaultValue) {
90
+ const rl = createInterface2({ input: process.stdin, output: process.stdout });
91
+ const suffix = defaultValue ? ` [${defaultValue}]` : "";
92
+ return new Promise((resolve) => {
93
+ rl.question(`${question}${suffix}: `, (answer) => {
94
+ rl.close();
95
+ resolve(answer.trim() || defaultValue || "");
96
+ });
97
+ });
98
+ }
99
+ async function init() {
100
+ console.log("RuleSync Init\n");
101
+ const projectName = await prompt2("Project name");
102
+ const outputFile = await prompt2("Output file", "CLAUDE.md");
103
+ let rulesets = [];
104
+ try {
105
+ rulesets = await apiRequest("/api/rulesets");
106
+ } catch {
107
+ console.log("(Could not fetch rulesets \u2014 you can add them manually)");
108
+ }
109
+ let selectedSlugs = [];
110
+ if (rulesets.length > 0) {
111
+ console.log("\nAvailable rulesets:");
112
+ rulesets.forEach((rs, i) => {
113
+ console.log(` ${i + 1}. ${rs.name} (${rs.slug})`);
114
+ });
115
+ const selection = await prompt2(
116
+ "\nSelect rulesets (comma-separated numbers)"
117
+ );
118
+ if (selection) {
119
+ const indices = selection.split(",").map((s) => parseInt(s.trim()) - 1);
120
+ selectedSlugs = indices.filter((i) => i >= 0 && i < rulesets.length).map((i) => rulesets[i].slug);
121
+ }
122
+ }
123
+ await saveProjectConfig({
124
+ project: projectName,
125
+ output: outputFile,
126
+ rulesets: selectedSlugs
127
+ });
128
+ console.log(`
129
+ Created .rulesync.json`);
130
+ console.log('Run "rulesync-cli pull" to sync your rules file.');
131
+ }
132
+
133
+ // src/commands/pull.ts
134
+ import { writeFileSync as writeFileSync2 } from "fs";
135
+ import { join as join2 } from "path";
136
+ async function pull() {
137
+ const config = await loadProjectConfig();
138
+ if (!config) {
139
+ console.error("No .rulesync.json found. Run: rulesync-cli init");
140
+ process.exit(1);
141
+ }
142
+ console.log(
143
+ `Fetching rulesets: ${config.rulesets.join(", ")}...`
144
+ );
145
+ const data = await apiRequest(`/api/sync/${encodeURIComponent(config.project)}`);
146
+ const outputPath = join2(process.cwd(), config.output);
147
+ writeFileSync2(outputPath, data.content);
148
+ const rulesetInfo = data.rulesets.map((r) => `${r.slug}@v${r.version}`).join(", ");
149
+ console.log(
150
+ `Wrote ${config.output} (${data.rulesets.length} rulesets: ${rulesetInfo})`
151
+ );
152
+ }
153
+
154
+ // src/commands/push.ts
155
+ import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
156
+ import { join as join3 } from "path";
157
+ import { createInterface as createInterface3 } from "readline";
158
+ async function prompt3(question) {
159
+ const rl = createInterface3({ input: process.stdin, output: process.stdout });
160
+ return new Promise((resolve) => {
161
+ rl.question(question, (answer) => {
162
+ rl.close();
163
+ resolve(answer.trim());
164
+ });
165
+ });
166
+ }
167
+ async function push() {
168
+ const config = await loadProjectConfig();
169
+ if (!config) {
170
+ console.error("No .rulesync.json found. Run: rulesync-cli init");
171
+ process.exit(1);
172
+ }
173
+ const filePath = join3(process.cwd(), config.output);
174
+ if (!existsSync2(filePath)) {
175
+ console.error(`File not found: ${config.output}`);
176
+ process.exit(1);
177
+ }
178
+ const content = readFileSync2(filePath, "utf-8");
179
+ const slug = await prompt3("Upload to ruleset slug: ");
180
+ if (!slug) {
181
+ console.error("Slug is required.");
182
+ process.exit(1);
183
+ }
184
+ const result = await apiRequest(`/api/rulesets/${slug}/versions`, {
185
+ method: "POST",
186
+ body: JSON.stringify({ content })
187
+ });
188
+ console.log(`Published ${slug}@v${result.version}`);
189
+ }
190
+
191
+ // src/commands/status.ts
192
+ async function status() {
193
+ const auth = await loadAuthConfig();
194
+ const config = await loadProjectConfig();
195
+ console.log("RuleSync Status\n");
196
+ if (auth) {
197
+ console.log(`Auth: Configured (${auth.apiUrl})`);
198
+ console.log(`Key: ${auth.apiKey.slice(0, 12)}...`);
199
+ } else {
200
+ console.log("Auth: Not configured (run: rulesync-cli login)");
201
+ }
202
+ console.log("");
203
+ if (config) {
204
+ console.log(`Project: ${config.project}`);
205
+ console.log(`Output: ${config.output}`);
206
+ console.log(`Rulesets: ${config.rulesets.join(", ") || "(none)"}`);
207
+ } else {
208
+ console.log("Project: No .rulesync.json (run: rulesync-cli init)");
209
+ }
210
+ }
211
+
212
+ // src/index.ts
213
+ var pkg = JSON.parse(readFileSync3(new URL("../package.json", import.meta.url), "utf-8"));
214
+ var program = new Command();
215
+ program.name("rulesync-cli").description("Sync CLAUDE.md files across repos via RuleSync").version(pkg.version);
216
+ program.command("login").description("Authenticate with your RuleSync API key").action(login);
217
+ program.command("init").description("Initialize .rulesync.json in the current project").action(init);
218
+ program.command("pull").description("Fetch rulesets and write the rules file").action(pull);
219
+ program.command("push").description("Upload local rules file as a new ruleset version").action(push);
220
+ program.command("status").description("Show current config and auth status").action(status);
221
+ program.action(pull);
222
+ await program.parseAsync();
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "rulesync-cli",
3
+ "version": "0.1.1",
4
+ "description": "CLI to sync CLAUDE.md files across repos via RuleSync",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Masao Kitamura <masaok@gmail.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/masaok/rulesync-next.git"
11
+ },
12
+ "homepage": "https://rulesync.dev",
13
+ "keywords": [
14
+ "claude",
15
+ "claude-md",
16
+ "ai-rules",
17
+ "sync",
18
+ "cli",
19
+ "agents-md"
20
+ ],
21
+ "bin": {
22
+ "rulesync-cli": "dist/index.js"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "dev": "tsup --watch",
30
+ "prepublishOnly": "tsup",
31
+ "release": "npm version patch && npm publish --access public"
32
+ },
33
+ "dependencies": {
34
+ "commander": "^13.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "tsup": "^8.0.0",
38
+ "typescript": "^5.0.0"
39
+ }
40
+ }