$npx -y skills add toroleapinc/claude-brain --skill brain-shareShare a skill, agent, or rule with the team by copying it to the shared namespace
| 1 | Share an artifact with the team by copying it to the shared namespace. |
| 2 | |
| 3 | Usage: /brain-share <type> <name> |
| 4 | - type: 'skill', 'agent', or 'rule' |
| 5 | - name: the filename (e.g., 'my-skill.md' or 'important-rule.md') |
| 6 | - Use `/brain-share --list` to see what's currently shared |
| 7 | |
| 8 | Arguments: $ARGUMENTS |
| 9 | |
| 10 | ## Steps |
| 11 | |
| 12 | 1. Parse arguments: |
| 13 | ```bash |
| 14 | ARGS=($ARGUMENTS) |
| 15 | TYPE="${ARGS[0]:-}" |
| 16 | NAME="${ARGS[1]:-}" |
| 17 | |
| 18 | # Handle --list flag |
| 19 | if [ "$TYPE" = "--list" ] || [ "$TYPE" = "list" ]; then |
| 20 | echo "Delegating to /brain-shared-list..." |
| 21 | # The agent should invoke /brain-shared-list skill instead |
| 22 | exit 0 |
| 23 | fi |
| 24 | |
| 25 | if [ -z "$TYPE" ] || [ -z "$NAME" ]; then |
| 26 | echo "Usage: /brain-share <type> <name>" |
| 27 | echo " /brain-share --list" |
| 28 | echo "Types: skill, agent, rule" |
| 29 | echo "Example: /brain-share skill my-useful-tool.md" |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | # Validate type |
| 34 | case "$TYPE" in |
| 35 | skill|agent|rule) ;; |
| 36 | *) echo "ERROR: Type must be 'skill', 'agent', or 'rule'"; exit 1 ;; |
| 37 | esac |
| 38 | ``` |
| 39 | |
| 40 | 2. Check if the artifact exists locally: |
| 41 | ```bash |
| 42 | source "${CLAUDE_PLUGIN_ROOT}/scripts/common.sh" |
| 43 | |
| 44 | case "$TYPE" in |
| 45 | skill) SOURCE_FILE="${CLAUDE_DIR}/skills/${NAME}" ;; |
| 46 | agent) SOURCE_FILE="${CLAUDE_DIR}/agents/${NAME}" ;; |
| 47 | rule) SOURCE_FILE="${CLAUDE_DIR}/rules/${NAME}" ;; |
| 48 | esac |
| 49 | |
| 50 | if [ ! -f "$SOURCE_FILE" ]; then |
| 51 | echo "ERROR: $TYPE '$NAME' not found at: $SOURCE_FILE" |
| 52 | echo "" |
| 53 | echo "Available ${TYPE}s:" |
| 54 | case "$TYPE" in |
| 55 | skill) ls "${CLAUDE_DIR}/skills/" 2>/dev/null || echo " (none)" ;; |
| 56 | agent) ls "${CLAUDE_DIR}/agents/" 2>/dev/null || echo " (none)" ;; |
| 57 | rule) ls "${CLAUDE_DIR}/rules/" 2>/dev/null || echo " (none)" ;; |
| 58 | esac |
| 59 | exit 1 |
| 60 | fi |
| 61 | ``` |
| 62 | |
| 63 | 3. **Ask the user for confirmation** before sharing: |
| 64 | "Share $TYPE '$NAME' with all machines in the brain network? This will be visible to all machines that sync with this brain." |
| 65 | Wait for user to confirm before proceeding. |
| 66 | |
| 67 | 4. Copy to shared namespace: |
| 68 | ```bash |
| 69 | # Create shared directory structure |
| 70 | mkdir -p "${BRAIN_REPO}/shared/skills" "${BRAIN_REPO}/shared/agents" "${BRAIN_REPO}/shared/rules" |
| 71 | |
| 72 | case "$TYPE" in |
| 73 | skill) TARGET_FILE="${BRAIN_REPO}/shared/skills/${NAME}" ;; |
| 74 | agent) TARGET_FILE="${BRAIN_REPO}/shared/agents/${NAME}" ;; |
| 75 | rule) TARGET_FILE="${BRAIN_REPO}/shared/rules/${NAME}" ;; |
| 76 | esac |
| 77 | |
| 78 | # Copy the file |
| 79 | cp "$SOURCE_FILE" "$TARGET_FILE" |
| 80 | log_info "Copied $TYPE '$NAME' to shared namespace" |
| 81 | |
| 82 | # Show the content preview |
| 83 | echo "" |
| 84 | echo "Shared $TYPE content preview:" |
| 85 | echo "---" |
| 86 | head -20 "$TARGET_FILE" |
| 87 | if [ $(wc -l < "$TARGET_FILE") -gt 20 ]; then |
| 88 | echo "... (truncated, total $(wc -l < "$TARGET_FILE") lines)" |
| 89 | fi |
| 90 | echo "---" |
| 91 | ``` |
| 92 | |
| 93 | 5. Commit and push: |
| 94 | ```bash |
| 95 | cd "${BRAIN_REPO}" |
| 96 | git add shared/ |
| 97 | if git diff --cached --quiet 2>/dev/null; then |
| 98 | echo "No changes to commit (file may already be shared)." |
| 99 | else |
| 100 | git commit -m "Share $TYPE: $NAME (from $(hostname))" |
| 101 | |
| 102 | # Try to push |
| 103 | if git push origin main 2>/dev/null; then |
| 104 | echo "" |
| 105 | echo "✓ $TYPE '$NAME' has been shared with the team!" |
| 106 | echo " Team members will receive it on their next brain sync." |
| 107 | else |
| 108 | echo "" |
| 109 | echo "⚠ $TYPE shared locally, but failed to push to remote." |
| 110 | echo " Run /brain-sync to retry pushing to the team." |
| 111 | fi |
| 112 | fi |
| 113 | ``` |
| 114 | |
| 115 | 6. Show sharing info: |
| 116 | ```bash |
| 117 | echo "" |
| 118 | echo "Shared artifact location: shared/$TYPE/$NAME" |
| 119 | echo "Team members will see this $TYPE after their next sync." |
| 120 | ``` |