@chorus-protocol/skill 0.4.0 → 0.4.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 (2) hide show
  1. package/cli.mjs +110 -37
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -3,73 +3,146 @@
3
3
  import { readFileSync, mkdirSync, writeFileSync, existsSync, cpSync } from "fs";
4
4
  import { join, dirname } from "path";
5
5
  import { fileURLToPath } from "url";
6
+ import { homedir } from "os";
6
7
 
7
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
8
9
  const pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8"));
9
10
 
10
11
  const LANGS = ["en", "zh-CN"];
11
12
  const DEFAULT_LANG = "en";
13
+ const TARGETS = ["local", "openclaw", "claude-user", "claude-project"];
12
14
 
13
15
  const args = process.argv.slice(2);
14
16
  const command = args[0];
15
17
 
18
+ function getFlag(name) {
19
+ const i = args.indexOf(name);
20
+ return i !== -1 && args[i + 1] ? args[i + 1] : null;
21
+ }
22
+
23
+ function resolveTargetDir(target) {
24
+ if (target === "openclaw") return join(homedir(), ".openclaw", "skills", "chorus");
25
+ if (target === "claude-user") return join(homedir(), ".claude", "skills", "chorus");
26
+ if (target === "claude-project") return join(process.cwd(), ".claude", "skills", "chorus");
27
+ return join(process.cwd(), "chorus");
28
+ }
29
+
30
+ function copySkillFiles(targetDir, lang) {
31
+ const templateDir = join(__dirname, "templates", lang);
32
+ const sharedDir = join(__dirname, "templates", "shared");
33
+ const protocolFile = lang === "en" ? "PROTOCOL.md" : `PROTOCOL.${lang}.md`;
34
+ const skillFile = lang === "en" ? "SKILL.md" : `SKILL.${lang}.md`;
35
+
36
+ mkdirSync(targetDir, { recursive: true });
37
+ mkdirSync(join(targetDir, "examples"), { recursive: true });
38
+
39
+ writeFileSync(join(targetDir, "PROTOCOL.md"), readFileSync(join(templateDir, protocolFile)));
40
+ writeFileSync(join(targetDir, "SKILL.md"), readFileSync(join(templateDir, skillFile)));
41
+ writeFileSync(join(targetDir, "TRANSPORT.md"), readFileSync(join(sharedDir, "TRANSPORT.md")));
42
+ writeFileSync(join(targetDir, "envelope.schema.json"), readFileSync(join(sharedDir, "envelope.schema.json")));
43
+ cpSync(join(sharedDir, "examples"), join(targetDir, "examples"), { recursive: true });
44
+ }
45
+
46
+ function registerOpenClaw() {
47
+ const configPath = join(homedir(), ".openclaw", "openclaw.json");
48
+ if (!existsSync(configPath)) {
49
+ console.log(` OpenClaw config not found at ${configPath} — skipping registration`);
50
+ return false;
51
+ }
52
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
53
+ if (!config.skills) config.skills = {};
54
+ if (!config.skills.entries) config.skills.entries = {};
55
+ config.skills.entries.chorus = { enabled: true };
56
+ writeFileSync(configPath, JSON.stringify(config, null, 4));
57
+ return true;
58
+ }
59
+
60
+ function unregisterOpenClaw() {
61
+ const configPath = join(homedir(), ".openclaw", "openclaw.json");
62
+ if (!existsSync(configPath)) return false;
63
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
64
+ if (config.skills?.entries?.chorus) {
65
+ delete config.skills.entries.chorus;
66
+ writeFileSync(configPath, JSON.stringify(config, null, 4));
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+
16
72
  if (command === "init") {
17
- const langFlag = args.indexOf("--lang");
18
- const lang = langFlag !== -1 && args[langFlag + 1] ? args[langFlag + 1] : DEFAULT_LANG;
73
+ const lang = getFlag("--lang") || DEFAULT_LANG;
74
+ const target = getFlag("--target") || "local";
19
75
 
20
76
  if (!LANGS.includes(lang)) {
21
77
  console.error(`Unsupported language: ${lang}. Available: ${LANGS.join(", ")}`);
22
78
  process.exit(1);
23
79
  }
24
80
 
25
- const targetDir = join(process.cwd(), "chorus");
81
+ if (!TARGETS.includes(target)) {
82
+ console.error(`Unsupported target: ${target}. Available: ${TARGETS.join(", ")}`);
83
+ process.exit(1);
84
+ }
85
+
86
+ const targetDir = resolveTargetDir(target);
26
87
 
27
88
  if (existsSync(targetDir)) {
28
- console.error(`Directory "chorus/" already exists. Remove it first or choose a different location.`);
89
+ console.error(`Directory "${targetDir}" already exists. Remove it first or use "chorus-skill uninstall --target ${target}".`);
29
90
  process.exit(1);
30
91
  }
31
92
 
32
- mkdirSync(targetDir, { recursive: true });
33
- mkdirSync(join(targetDir, "examples"), { recursive: true });
93
+ copySkillFiles(targetDir, lang);
34
94
 
35
- const templateDir = join(__dirname, "templates", lang);
36
- const sharedDir = join(__dirname, "templates", "shared");
95
+ console.log(`Chorus Skill installed to ${targetDir} (${lang})`);
37
96
 
38
- const protocolFile = lang === "en" ? "PROTOCOL.md" : `PROTOCOL.${lang}.md`;
39
- const skillFile = lang === "en" ? "SKILL.md" : `SKILL.${lang}.md`;
97
+ if (target === "openclaw") {
98
+ const registered = registerOpenClaw();
99
+ if (registered) {
100
+ console.log(` Registered in ~/.openclaw/openclaw.json`);
101
+ }
102
+ }
40
103
 
41
- writeFileSync(
42
- join(targetDir, "PROTOCOL.md"),
43
- readFileSync(join(templateDir, protocolFile))
44
- );
45
- writeFileSync(
46
- join(targetDir, "SKILL.md"),
47
- readFileSync(join(templateDir, skillFile))
48
- );
49
- writeFileSync(
50
- join(targetDir, "TRANSPORT.md"),
51
- readFileSync(join(sharedDir, "TRANSPORT.md"))
52
- );
53
- writeFileSync(
54
- join(targetDir, "envelope.schema.json"),
55
- readFileSync(join(sharedDir, "envelope.schema.json"))
56
- );
104
+ console.log(`\nFiles created:`);
105
+ console.log(` PROTOCOL.md — Protocol specification`);
106
+ console.log(` SKILL.md — Agent learning document`);
107
+ console.log(` TRANSPORT.md — Default transport profile (optional)`);
108
+ console.log(` envelope.schema.json`);
109
+ console.log(` examples/`);
110
+ console.log(`\nGive your agent SKILL.md to teach it the Chorus protocol.`);
57
111
 
58
- cpSync(join(sharedDir, "examples"), join(targetDir, "examples"), { recursive: true });
112
+ } else if (command === "uninstall") {
113
+ const target = getFlag("--target");
114
+
115
+ if (!target || !TARGETS.includes(target) || target === "local") {
116
+ console.error(`Usage: chorus-skill uninstall --target openclaw|claude-user|claude-project`);
117
+ process.exit(1);
118
+ }
119
+
120
+ const targetDir = resolveTargetDir(target);
121
+
122
+ if (!existsSync(targetDir)) {
123
+ console.error(`Not installed at ${targetDir}`);
124
+ process.exit(1);
125
+ }
126
+
127
+ const { rmSync } = await import("fs");
128
+ rmSync(targetDir, { recursive: true });
129
+ console.log(`Removed ${targetDir}`);
130
+
131
+ if (target === "openclaw") {
132
+ const removed = unregisterOpenClaw();
133
+ if (removed) {
134
+ console.log(` Unregistered from ~/.openclaw/openclaw.json`);
135
+ }
136
+ }
59
137
 
60
- console.log(`Chorus Skill package initialized in ./chorus/ (${lang})`);
61
- console.log(`\nFiles created:`);
62
- console.log(` chorus/PROTOCOL.md — Protocol specification`);
63
- console.log(` chorus/SKILL.md — Agent learning document`);
64
- console.log(` chorus/TRANSPORT.md — Default transport profile (optional)`);
65
- console.log(` chorus/envelope.schema.json`);
66
- console.log(` chorus/examples/`);
67
- console.log(`\nGive your agent chorus/SKILL.md to teach it the Chorus protocol.`);
68
138
  } else {
69
139
  console.log(`@chorus-protocol/skill v${pkg.version}`);
70
140
  console.log(`\nUsage:`);
71
- console.log(` chorus-skill init [--lang en|zh-CN] Initialize Chorus Skill package`);
141
+ console.log(` chorus-skill init [--lang en|zh-CN] [--target local|openclaw|claude-user|claude-project]`);
142
+ console.log(` chorus-skill uninstall --target openclaw|claude-user|claude-project`);
72
143
  console.log(`\nExamples:`);
73
- console.log(` npx @chorus-protocol/skill init`);
144
+ console.log(` npx @chorus-protocol/skill init # ./chorus/`);
145
+ console.log(` npx @chorus-protocol/skill init --target openclaw # ~/.openclaw/skills/chorus/`);
146
+ console.log(` npx @chorus-protocol/skill init --target claude-user # ~/.claude/skills/chorus/`);
74
147
  console.log(` npx @chorus-protocol/skill init --lang zh-CN`);
75
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chorus-protocol/skill",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Chorus Protocol — Link agents across platforms. Install the Chorus Skill package for your agent.",
5
5
  "bin": {
6
6
  "chorus-skill": "./cli.mjs"