Skip to content

Commit b110bad

Browse files
committed
feat: Implement .agent directory synchronization to merge new resources without overwriting existing ones.
1 parent 0cd7c09 commit b110bad

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ bunx @riligar/agents-kit init
3131

3232
### What happens behind the scenes?
3333

34-
1. Copies the `.agent` directory (containing all rules and skills) to your project root.
35-
2. Automatically updates your `.gitignore` to prevent committing agent configurations.
36-
3. Sets up your environment for AI Agent interaction without poluting your `node_modules`.
34+
1. Syncs the `.agent` directory (containing all rules and skills) to your project root, adding new resources without overwriting your existing ones.
35+
2. Automatically updates your `.gitignore` to ensure `.agent` is ignored.
36+
3. Sets up your environment for AI Agent interaction without polluting your `node_modules`.
3737

3838
## Development & Releases
3939

bin/cli.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@ async function init() {
1313
process.exit(1)
1414
}
1515

16-
if (fs.existsSync(target)) {
17-
console.log('.agent directory already exists in the destination. Skipping copy.')
18-
} else {
19-
console.log('Copying .agent directory to your project...')
20-
try {
21-
if (fs.cpSync) {
22-
fs.cpSync(source, target, {
23-
recursive: true,
24-
filter: src => !src.includes('.DS_Store'),
25-
})
26-
} else {
27-
execSync(`cp -r "${source}" "${target}"`)
28-
}
29-
console.log('Successfully installed .agent directory!')
30-
} catch (error) {
31-
console.error('Failed to copy .agent directory:', error.message)
32-
process.exit(1)
33-
}
16+
console.log('Syncing .agent directory to your project...')
17+
18+
const merge = (src, dest) => {
19+
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true })
20+
fs.readdirSync(src).forEach(item => {
21+
if (item === '.DS_Store') return
22+
const s = path.join(src, item),
23+
d = path.join(dest, item)
24+
if (fs.statSync(s).isDirectory()) merge(s, d)
25+
else if (!fs.existsSync(d)) fs.copyFileSync(s, d)
26+
})
27+
}
28+
29+
try {
30+
merge(source, target)
31+
console.log('Successfully installed/updated .agent directory!')
32+
} catch (error) {
33+
console.error('Failed to copy .agent directory:', error.message)
34+
process.exit(1)
3435
}
3536

3637
// Manage .gitignore

0 commit comments

Comments
 (0)