@brickhouse-tech/sync-agents 0.1.7 → 0.1.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brickhouse-tech/sync-agents",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Simple scripts to DRY up common agent interactions across multiple LLM providers.",
5
5
  "keywords": [
6
6
  "agents",
@@ -184,7 +184,6 @@ cmd_init() {
184
184
  else
185
185
  # Inline fallback if template not found
186
186
  cat > "$PROJECT_ROOT/$AGENTS_DIR/STATE.md" <<'STATE_EOF'
187
-
188
187
  ---
189
188
  trigger: always_on
190
189
  ---
@@ -222,6 +221,9 @@ CONFIG_EOF
222
221
  warn "$AGENTS_MD already exists, skipping (run 'sync-agents index' to regenerate)"
223
222
  fi
224
223
 
224
+ # Add default .gitignore entries for agent tool directories
225
+ add_default_gitignore_entries
226
+
225
227
  info "Initialization complete. Directory structure:"
226
228
  print_tree "$PROJECT_ROOT/$AGENTS_DIR"
227
229
  }
@@ -270,7 +272,6 @@ cmd_add() {
270
272
  sed "s/\${NAME}/$name/g" "$TEMPLATES_DIR/RULE_TEMPLATE.md" > "$filepath"
271
273
  else
272
274
  cat > "$filepath" <<TMPL_EOF
273
-
274
275
  ---
275
276
  trigger: always_on
276
277
  ---
@@ -315,9 +316,162 @@ cmd_sync() {
315
316
  create_symlink "$AGENTS_MD" "$PROJECT_ROOT/CLAUDE.md" "$DRY_RUN"
316
317
  fi
317
318
 
319
+ # Update .gitignore with synced symlink entries
320
+ update_gitignore
321
+
318
322
  info "Sync complete."
319
323
  }
320
324
 
325
+ # --------------------------------------------------------------------------
326
+ # .gitignore management
327
+ # --------------------------------------------------------------------------
328
+
329
+ # Add default .gitignore entries for agent tool directories (called during init)
330
+ add_default_gitignore_entries() {
331
+ local gitignore="$PROJECT_ROOT/.gitignore"
332
+
333
+ # Create .gitignore if it doesn't exist
334
+ if [[ ! -f "$gitignore" ]]; then
335
+ touch "$gitignore"
336
+ info "Created .gitignore"
337
+ fi
338
+
339
+ # Check if .DS_Store is already present (case-insensitive check)
340
+ if ! grep -qiE "^\.DS_Store$" "$gitignore" 2>/dev/null; then
341
+ # Add .DS_Store if not present
342
+ if [[ -s "$gitignore" ]] && ! tail -c1 "$gitignore" | grep -q '^$'; then
343
+ echo "" >> "$gitignore"
344
+ fi
345
+ echo ".DS_Store" >> "$gitignore"
346
+ info "Added .DS_Store to .gitignore"
347
+ fi
348
+
349
+ # Define default entries (tool artifacts, not symlinks)
350
+ # Using pattern: ignore everything in dir, except specific files we want to track
351
+ local marker="# sync-agents — ignore tool artifacts, keep symlinks"
352
+
353
+ # Check if sync-agents section already exists
354
+ if grep -qF "$marker" "$gitignore"; then
355
+ # Section exists - check if we need to add any missing entries
356
+ local needs_update=false
357
+
358
+ # Check for each pattern
359
+ if ! grep -qF ".cursor/*" "$gitignore"; then needs_update=true; fi
360
+ if ! grep -qF "!.cursor/rules" "$gitignore"; then needs_update=true; fi
361
+ if ! grep -qF ".codex/*" "$gitignore"; then needs_update=true; fi
362
+ if ! grep -qF "!.codex/instructions.md" "$gitignore"; then needs_update=true; fi
363
+ if ! grep -qF ".github/copilot/*" "$gitignore"; then needs_update=true; fi
364
+ if ! grep -qF "!.github/copilot/instructions.md" "$gitignore"; then needs_update=true; fi
365
+
366
+ if [[ "$needs_update" == "true" ]]; then
367
+ # Rebuild section by reading the file, preserving everything else
368
+ local tmp
369
+ tmp="$(mktemp)"
370
+ local in_section=false
371
+
372
+ while IFS= read -r line; do
373
+ if [[ "$line" == "$marker" ]]; then
374
+ in_section=true
375
+ # Output the marker
376
+ {
377
+ echo "$line"
378
+ echo ".cursor/*"
379
+ echo "!.cursor/rules"
380
+ echo ".codex/*"
381
+ echo "!.codex/instructions.md"
382
+ echo ".github/copilot/*"
383
+ echo "!.github/copilot/instructions.md"
384
+ } >> "$tmp"
385
+ continue
386
+ fi
387
+
388
+ # Skip old entries in the sync-agents section (until we hit empty line or new section)
389
+ if [[ "$in_section" == "true" ]]; then
390
+ if [[ -z "$line" ]] || [[ "$line" == "#"* ]]; then
391
+ in_section=false
392
+ echo "$line" >> "$tmp"
393
+ fi
394
+ # Skip old entry lines (they're replaced above)
395
+ continue
396
+ fi
397
+
398
+ echo "$line" >> "$tmp"
399
+ done < "$gitignore"
400
+
401
+ mv "$tmp" "$gitignore"
402
+ info "Updated sync-agents section in .gitignore"
403
+ fi
404
+ else
405
+ # Section doesn't exist, add entire block
406
+ # Add separator if file is non-empty
407
+ if [[ -s "$gitignore" ]] && ! tail -c1 "$gitignore" | grep -q '^$'; then
408
+ echo "" >> "$gitignore"
409
+ fi
410
+
411
+ # Add all entries
412
+ {
413
+ echo "$marker"
414
+ echo ".cursor/*"
415
+ echo "!.cursor/rules"
416
+ echo ".codex/*"
417
+ echo "!.codex/instructions.md"
418
+ echo ".github/copilot/*"
419
+ echo "!.github/copilot/instructions.md"
420
+ } >> "$gitignore"
421
+
422
+ info "Added sync-agents section to .gitignore with 7 entries"
423
+ fi
424
+ }
425
+
426
+ update_gitignore() {
427
+ local gitignore="$PROJECT_ROOT/.gitignore"
428
+
429
+ # Build list of entries that should be ignored (synced symlinks)
430
+ local entries=()
431
+ for target in "${ACTIVE_TARGETS[@]}"; do
432
+ local target_dir
433
+ target_dir="$(resolve_target_dir "$target" "$PROJECT_ROOT")"
434
+ local rel_path="${target_dir#"$PROJECT_ROOT"/}/"
435
+ entries+=("$rel_path")
436
+ done
437
+ entries+=("CLAUDE.md")
438
+
439
+ if [[ "$DRY_RUN" == "true" ]]; then
440
+ for entry in "${entries[@]}"; do
441
+ if [[ ! -f "$gitignore" ]] || ! grep -qxF "$entry" "$gitignore"; then
442
+ echo " would add to .gitignore: $entry"
443
+ fi
444
+ done
445
+ return 0
446
+ fi
447
+
448
+ # Create .gitignore if it doesn't exist
449
+ [[ -f "$gitignore" ]] || touch "$gitignore"
450
+
451
+ local added=0
452
+ for entry in "${entries[@]}"; do
453
+ if ! grep -qxF "$entry" "$gitignore"; then
454
+ # Add sync-agents header on first addition
455
+ if [[ "$added" -eq 0 ]]; then
456
+ # Check if header already exists
457
+ if ! grep -qF "# sync-agents" "$gitignore"; then
458
+ # Add a blank line separator if file is non-empty
459
+ if [[ -s "$gitignore" ]]; then
460
+ echo "" >> "$gitignore"
461
+ fi
462
+ echo "# sync-agents (generated symlinks)" >> "$gitignore"
463
+ fi
464
+ fi
465
+ echo "$entry" >> "$gitignore"
466
+ added=$((added + 1))
467
+ fi
468
+ done
469
+
470
+ if [[ "$added" -gt 0 ]]; then
471
+ info "Added $added entries to .gitignore"
472
+ fi
473
+ }
474
+
321
475
  cmd_status() {
322
476
  echo -e "${BOLD}sync-agents${RESET} v${VERSION}"
323
477
  echo ""
@@ -749,7 +903,6 @@ generate_agents_md() {
749
903
  fi
750
904
 
751
905
  cat > "$outfile" <<'HEADER'
752
-
753
906
  ---
754
907
  trigger: always_on
755
908
  ---