Repository navigation
Expand file tree
/
Copy pathinstall.js
More file actions
executable file
·184 lines (158 loc) · 4.92 KB
/
Copy pathinstall.js
File metadata and controls
executable file
·184 lines (158 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env node
/**
* atomic-cline install
*
* Copies Atomic hook scripts into ~/Documents/Cline/Hooks/ (global hooks),
* and symlinks skills into ~/Documents/Cline/Workflows/ so they are available
* on demand as the /atomic-vault, /atomic-vcs, and /code-intelligence slash
* commands referenced by the rules.
*
* Cline discovers hooks as executable files in the Hooks/ directory, and
* workflows as markdown files in the Workflows/ directory (invoked via `/name`).
*
* Usage:
* npx atomic-cline # install
* node install.js # install from local checkout
* node install.js --silent # postinstall
* node install.js --uninstall # remove hooks and skill symlinks
*/
const fs = require("fs");
const path = require("path");
const os = require("os");
const silent = process.argv.includes("--silent");
const uninstall = process.argv.includes("--uninstall");
const PKG_DIR = __dirname;
const CLINE_DIR = path.join(os.homedir(), "Documents", "Cline");
const HOOKS_TARGET = path.join(CLINE_DIR, "Hooks");
const SKILLS_TARGET = path.join(CLINE_DIR, "Workflows");
const HOOK_PREFIX = "atomic-";
const HOOKS = [
"TaskStart",
"TaskResume",
"TaskComplete",
"TaskCancel",
"UserPromptSubmit",
"PostToolUse",
"PreToolUse",
];
// Skills are shipped under skills/<name>/SKILL.md and exposed as flat
// workflow files so they resolve as the `/<name>` slash commands the rules
// reference (e.g. /atomic-vault). Symlinked so package updates propagate.
const SKILL_LINKS = [
{ src: "skills/atomic-vault/SKILL.md", dst: "atomic-vault.md" },
{ src: "skills/atomic-vcs/SKILL.md", dst: "atomic-vcs.md" },
{ src: "skills/code-intelligence/SKILL.md", dst: "code-intelligence.md" },
];
function ensureDir(dir) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
function isOurSymlink(dstPath) {
try {
if (!fs.lstatSync(dstPath).isSymbolicLink()) return false;
return fs.readlinkSync(dstPath).startsWith(PKG_DIR);
} catch {
return false;
}
}
function installHooks() {
ensureDir(HOOKS_TARGET);
let installed = 0;
for (const hook of HOOKS) {
const src = path.join(PKG_DIR, "hooks", hook);
const dst = path.join(HOOKS_TARGET, HOOK_PREFIX + hook);
if (!fs.existsSync(src)) {
if (!silent) console.warn(` skip: ${hook} (not found in package)`);
continue;
}
fs.copyFileSync(src, dst);
fs.chmodSync(dst, 0o755);
installed++;
if (!silent) console.log(` hook: ${hook}`);
}
return installed;
}
function installSkills() {
ensureDir(SKILLS_TARGET);
let linked = 0;
let skipped = 0;
for (const { src, dst } of SKILL_LINKS) {
const srcPath = path.join(PKG_DIR, src);
const dstPath = path.join(SKILLS_TARGET, dst);
if (!fs.existsSync(srcPath)) {
if (!silent) console.warn(` skip: ${src} (not found in package)`);
continue;
}
// Never overwrite a user's own file at the destination.
if (fs.existsSync(dstPath) && !isOurSymlink(dstPath)) {
skipped++;
if (!silent) console.log(` keep: ${dst} (user file, not overwriting)`);
continue;
}
if (fs.existsSync(dstPath) || isOurSymlink(dstPath)) {
fs.unlinkSync(dstPath);
}
fs.symlinkSync(srcPath, dstPath);
linked++;
if (!silent) console.log(` skill: /${dst.replace(/\.md$/, "")}`);
}
return { linked, skipped };
}
function doInstall() {
const installed = installHooks();
const { linked, skipped } = installSkills();
if (!silent) {
console.log();
console.log(
`✓ atomic-cline installed (${installed} hooks, ${linked} skills linked${
skipped ? `, ${skipped} skipped` : ""
})`,
);
console.log(` Hooks: ${HOOKS_TARGET}`);
console.log(` Skills: ${SKILLS_TARGET}`);
console.log();
console.log(" Enable hooks in Cline's Hooks tab (scale icon).");
console.log();
console.log(" To add rules to a project:");
console.log(" mkdir -p .clinerules");
console.log(
` cp ${path.join(PKG_DIR, "rules", "atomic.md")} .clinerules/atomic.md`,
);
console.log();
}
}
function doUninstall() {
let removedHooks = 0;
for (const hook of HOOKS) {
const dst = path.join(HOOKS_TARGET, HOOK_PREFIX + hook);
if (fs.existsSync(dst)) {
fs.unlinkSync(dst);
removedHooks++;
if (!silent) console.log(` removed hook: ${hook}`);
}
}
let removedSkills = 0;
for (const { dst } of SKILL_LINKS) {
const dstPath = path.join(SKILLS_TARGET, dst);
if (isOurSymlink(dstPath)) {
fs.unlinkSync(dstPath);
removedSkills++;
if (!silent) console.log(` removed skill: /${dst.replace(/\.md$/, "")}`);
}
}
if (!silent) {
console.log();
console.log(
`✓ atomic-cline uninstalled (${removedHooks} hooks, ${removedSkills} skills removed)`,
);
console.log(
" Note: .clinerules/ files in projects must be removed manually.",
);
}
}
if (uninstall) {
doUninstall();
} else {
doInstall();
}