Repository navigation
Expand file tree
/
Copy pathinstall.js
More file actions
317 lines (281 loc) · 8.12 KB
/
Copy pathinstall.js
File metadata and controls
317 lines (281 loc) · 8.12 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env node
/**
* atomic-kiro install
*
* Installs Atomic hooks (via atomic CLI if supported),
* symlinks skills into ~/.kiro/skills/,
* and symlinks steering files into ~/.kiro/steering/.
*
* Usage:
* npx atomic-kiro # install from npm
* node install.js # install from local checkout
* node install.js --silent # postinstall (no output on success)
* node install.js --uninstall # remove skills and steering symlinks
*/
const fs = require("fs");
const path = require("path");
const os = require("os");
const { execSync } = require("child_process");
const silent = process.argv.includes("--silent");
const uninstall = process.argv.includes("--uninstall");
const PKG_DIR = __dirname;
const KIRO_DIR = path.join(os.homedir(), ".kiro");
const SKILLS_TARGET = path.join(KIRO_DIR, "skills");
const STEERING_TARGET = path.join(KIRO_DIR, "steering");
const SKILL_LINKS = [
{
src: "skills/atomic-vault/SKILL.md",
dst: "atomic-vault/SKILL.md",
},
{
src: "skills/atomic-vcs/SKILL.md",
dst: "atomic-vcs/SKILL.md",
},
{
src: "skills/code-intelligence/SKILL.md",
dst: "code-intelligence/SKILL.md",
},
{
src: "skills/codebase-context/SKILL.md",
dst: "codebase-context/SKILL.md",
},
{
src: "skills/intent-builder/SKILL.md",
dst: "intent-builder/SKILL.md",
},
];
const STEERING_LINKS = [
{
src: "steering/atomic-agent.md",
dst: "atomic-agent.md",
},
];
function ensureDir(filePath) {
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
}
function isOurSymlink(dstPath) {
try {
if (!fs.lstatSync(dstPath).isSymbolicLink()) return false;
const target = fs.readlinkSync(dstPath);
return target.startsWith(PKG_DIR);
} catch {
return false;
}
}
function tryExec(cmd) {
try {
execSync(cmd, { stdio: "pipe" });
return true;
} catch {
return false;
}
}
function linkFiles(links, targetDir, label) {
let linked = 0;
let skipped = 0;
for (const { src, dst } of links) {
const srcPath = path.join(PKG_DIR, src);
const dstPath = path.join(targetDir, dst);
if (!fs.existsSync(srcPath)) {
if (!silent) console.warn(` skip: ${src} (not found in package)`);
continue;
}
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);
}
ensureDir(dstPath);
fs.symlinkSync(srcPath, dstPath);
linked++;
if (!silent) console.log(` link: ${label}/${dst}`);
}
return { linked, skipped };
}
function unlinkFiles(links, targetDir, label) {
let removed = 0;
for (const { dst } of links) {
const dstPath = path.join(targetDir, dst);
if (isOurSymlink(dstPath)) {
fs.unlinkSync(dstPath);
removed++;
if (!silent) console.log(` unlink: ${label}/${dst}`);
// Try to remove parent directory if empty
const dir = path.dirname(dstPath);
try {
fs.rmdirSync(dir);
} catch {
/* not empty */
}
}
}
return removed;
}
function doInstall() {
// 1. Kiro hooks are written directly as .kiro/hooks/*.kiro.hook files
// (step 4) and call `atomic agent hooks kiro <verb>` at runtime. Kiro has
// no global settings file to merge into, so there is no
// `atomic agent enable` step.
if (!silent && !tryExec("atomic --version")) {
console.warn(
" note: 'atomic' not on PATH — install it so the hooks work at runtime",
);
}
// 2. Symlink skills
const skills = linkFiles(SKILL_LINKS, SKILLS_TARGET, "skills");
// 3. Symlink steering
const steering = linkFiles(STEERING_LINKS, STEERING_TARGET, "steering");
// 4. Write .kiro/hooks/ files into the current working directory (project)
const cwd = process.cwd();
const hooksWritten = installKiroHooks(cwd);
if (!silent)
console.log(
` hooks: ${hooksWritten} hook files → ${path.join(cwd, ".kiro", "hooks")}/`,
);
if (!silent) {
console.log();
console.log(
`✓ atomic-kiro installed (${skills.linked} skills, ${steering.linked} steering files linked)`,
);
console.log();
console.log(
"Copy AGENTS.md into your project root to enable the agent prompt:",
);
console.log(
` cp ${path.join(PKG_DIR, "AGENTS.md")} /path/to/your/project/`,
);
console.log();
console.log("Or run from your project directory to install hooks there:");
console.log(" cd /path/to/your/project && npx atomic-kiro");
console.log();
}
}
const HOOK_SCRIPTS_DIR = path.join(PKG_DIR, "hooks");
const KIRO_HOOK_DEFS = [
{
file: "atomic-prompt-submit.kiro.hook",
name: "Atomic Turn Start",
when: { type: "promptSubmit" },
script: "prompt-submit.sh",
},
{
file: "atomic-turn-stop.kiro.hook",
name: "Atomic Turn Stop",
when: { type: "agentStop" },
script: "agent-stop.sh",
},
// Per-tool hooks so the tool name is passed as an argument
{
file: "atomic-pre-tool-write.kiro.hook",
name: "Atomic Pre Tool Use (write)",
when: { type: "preToolUse", toolTypes: ["write"] },
script: "pre-tool-use.sh write",
},
{
file: "atomic-pre-tool-shell.kiro.hook",
name: "Atomic Pre Tool Use (shell)",
when: { type: "preToolUse", toolTypes: ["shell"] },
script: "pre-tool-use.sh shell",
},
{
file: "atomic-pre-tool-read.kiro.hook",
name: "Atomic Pre Tool Use (read)",
when: { type: "preToolUse", toolTypes: ["read"] },
script: "pre-tool-use.sh read",
},
{
file: "atomic-post-tool-write.kiro.hook",
name: "Atomic Post Tool Use (write)",
when: { type: "postToolUse", toolTypes: ["write"] },
script: "post-tool-use.sh write",
},
{
file: "atomic-post-tool-shell.kiro.hook",
name: "Atomic Post Tool Use (shell)",
when: { type: "postToolUse", toolTypes: ["shell"] },
script: "post-tool-use.sh shell",
},
{
file: "atomic-post-tool-read.kiro.hook",
name: "Atomic Post Tool Use (read)",
when: { type: "postToolUse", toolTypes: ["read"] },
script: "post-tool-use.sh read",
},
{
file: "atomic-post-task.kiro.hook",
name: "Atomic Post Task Execution",
when: { type: "postTaskExecution" },
script: "post-task-execution.sh",
},
];
function installKiroHooks(projectDir) {
const hooksDir = path.join(projectDir, ".kiro", "hooks");
fs.mkdirSync(hooksDir, { recursive: true });
let written = 0;
for (const def of KIRO_HOOK_DEFS) {
const hook = {
version: "1.0.0",
enabled: true,
name: def.name,
when: def.when,
then: {
type: "runCommand",
command: path.join(HOOK_SCRIPTS_DIR, def.script),
},
};
fs.writeFileSync(
path.join(hooksDir, def.file),
JSON.stringify(hook, null, 2) + "\n",
);
written++;
}
return written;
}
function removeKiroHooks(projectDir) {
const hooksDir = path.join(projectDir, ".kiro", "hooks");
let removed = 0;
for (const def of KIRO_HOOK_DEFS) {
const hookPath = path.join(hooksDir, def.file);
if (fs.existsSync(hookPath)) {
fs.unlinkSync(hookPath);
removed++;
}
}
return removed;
}
function doUninstall() {
// Kiro's hooks are project .kiro/hooks files (removed below) — there is no
// global `atomic agent` registration to undo.
// 2. Remove skill symlinks
const skillsRemoved = unlinkFiles(SKILL_LINKS, SKILLS_TARGET, "skills");
// 3. Remove steering symlinks
const steeringRemoved = unlinkFiles(
STEERING_LINKS,
STEERING_TARGET,
"steering",
);
// 4. Remove .kiro/hooks files from current project
const hooksRemoved = removeKiroHooks(process.cwd());
if (!silent && hooksRemoved > 0)
console.log(
` hooks: ${hooksRemoved} hook files removed from .kiro/hooks/`,
);
if (!silent) {
console.log();
console.log(
`✓ atomic-kiro uninstalled (${skillsRemoved} skills, ${steeringRemoved} steering files removed)`,
);
console.log(" Note: AGENTS.md in project roots must be removed manually.");
}
}
if (uninstall) {
doUninstall();
} else {
doInstall();
}