social-agent-cli 1.0.0

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/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # social-agent-cli
2
+
3
+ AI-powered social media automation tool with self-healing browser automation. Teach it any action on any platform — it learns, adapts, and recovers from errors automatically.
4
+
5
+ ## How It Works
6
+
7
+ ```
8
+ You: "like this tweet and retweet it: https://x.com/..."
9
+
10
+ 1. [Planner] → Parses natural language command
11
+ 2. [Knowledge] → Loads platform-specific knowledge (URLs, selectors, limits)
12
+ 3. [Map Check] → Checks learned action maps
13
+ 4. [Learn] → If missing, opens Chrome, takes screenshot + DOM, AI creates selector map
14
+ 5. [Runner] → Executes steps sequentially
15
+ 6. [Heal] → On failure: screenshots page, AI re-plans remaining steps (effort escalates)
16
+ ```
17
+
18
+ ## Features
19
+
20
+ - **Natural language commands** — `social-agent run x "like and retweet this tweet"`
21
+ - **Self-healing** — When selectors break, AI sees the screen and re-plans from where it left off
22
+ - **Learning** — Teach any action once, reuse forever. Maps are saved as JSON
23
+ - **Combination** — Chains multiple learned actions in a single command
24
+ - **Real Chrome profile** — Uses your actual Chrome profile via CDP. No bot detection
25
+ - **Zero hardcode** — No platform-specific selectors in code. Everything is AI-learned
26
+ - **Free API drivers** — Mastodon, Bluesky, Telegram via direct API (no browser needed)
27
+ - **Browser automation** — X, LinkedIn, Instagram, Facebook via Chrome
28
+ - **Post history** — Logs every action. AI matches your tone in future posts
29
+ - **Git hook** — Notifies you after `git push` to suggest social media posts
30
+ - **Claude Code integration** — `claude-social` mode + `/social` slash command
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ npm install -g social-agent-cli
36
+ social-agent setup
37
+ ```
38
+
39
+ The setup wizard asks your name, social handles, API tokens, and configures everything — Chrome profile selection, git hooks, shell aliases.
40
+
41
+ ## Quick Start
42
+
43
+ ```bash
44
+ # 1. First-time setup
45
+ social-agent setup
46
+
47
+ # 2. Login to browser platforms (one-time)
48
+ social-agent login x
49
+ social-agent login linkedin
50
+
51
+ # 3. Teach actions
52
+ social-agent learn x # learn to post (default)
53
+ social-agent learn "learn to like tweets" x # learn liking
54
+ social-agent learn "learn to send connection request" linkedin
55
+
56
+ # 4. Use with natural language
57
+ social-agent run x "like this tweet: https://x.com/user/status/123"
58
+ social-agent run x "like and retweet: https://x.com/user/status/123"
59
+ social-agent run linkedin "send connection requests to 3 people"
60
+ social-agent post "New feature released!" --platforms mastodon,bluesky
61
+ ```
62
+
63
+ ## Commands
64
+
65
+ | Command | Description |
66
+ |---------|-------------|
67
+ | `social-agent setup` | First-time setup wizard |
68
+ | `social-agent login <platform>` | Select Chrome profile and verify login |
69
+ | `social-agent learn "<task>" <platform>` | AI learns a new action from the page |
70
+ | `social-agent run <platform> "<command>"` | Execute with natural language |
71
+ | `social-agent post "<text>" --platforms x,mastodon` | Post to platforms |
72
+ | `social-agent status` | Show connected platforms |
73
+ | `social-agent history` | Show action history |
74
+
75
+ ## Supported Platforms
76
+
77
+ ### API-based (free, no browser needed)
78
+ | Platform | Auth | Features |
79
+ |----------|------|----------|
80
+ | **Mastodon** | Access token | Post, media upload, like, boost, follow |
81
+ | **Bluesky** | App password | Post, media, like, repost, follow |
82
+ | **Telegram** | Bot token | Send messages, photos, videos to channels |
83
+
84
+ ### Browser-based (Chrome automation)
85
+ | Platform | Method | Notes |
86
+ |----------|--------|-------|
87
+ | **X (Twitter)** | CDP + real Chrome | Free tier friendly, no API costs |
88
+ | **LinkedIn** | CDP + real Chrome | Connection requests, posts, reactions |
89
+ | **Instagram** | CDP + real Chrome | Aggressive anti-bot, use with caution |
90
+ | **Facebook** | CDP + real Chrome | Checkpoint system, careful usage |
91
+
92
+ ## Self-Healing
93
+
94
+ When a step fails, AI doesn't just retry — it **sees the screen and re-plans**:
95
+
96
+ ```
97
+ Step 6: Click "Post" button ✗
98
+ [heal] AI analyzing screen (effort: low)...
99
+ → "Post button is inside a scrollable container, need to scroll first"
100
+ → New plan: scroll down + click with updated selector
101
+
102
+ Step 6 (new): Scroll down ✓
103
+ Step 7 (new): Click post button ✓
104
+ ```
105
+
106
+ Effort escalates on repeated failures: `low → medium → medium`
107
+
108
+ ## Selector Maps
109
+
110
+ Learned actions are saved as JSON in `~/.social-agent/maps/`:
111
+
112
+ ```json
113
+ {
114
+ "platform": "x",
115
+ "action": "like_tweet",
116
+ "parameters": ["{{TWEET_URL}}"],
117
+ "steps": [
118
+ { "action": "goto", "url": "{{TWEET_URL}}" },
119
+ { "action": "wait", "waitMs": 2000 },
120
+ { "action": "click", "selector": "[data-testid='like']",
121
+ "fallbackSelectors": ["[aria-label*='Like']"] },
122
+ { "action": "wait", "waitMs": 1000 }
123
+ ]
124
+ }
125
+ ```
126
+
127
+ ## Chrome Integration
128
+
129
+ - **CDP (Chrome DevTools Protocol)** connection
130
+ - Chrome open → connects to existing instance, opens new tab
131
+ - Chrome closed → launches with your selected profile
132
+ - Only closes the tab, **never kills Chrome**
133
+ - `navigator.webdriver = false` to avoid detection
134
+ - `--enable-automation` flag removed
135
+
136
+ ## Claude Code Integration
137
+
138
+ ### `claude-social` mode
139
+ Run Claude with social media awareness. It suggests posts at milestones:
140
+
141
+ ```bash
142
+ claude-social
143
+
144
+ # While working...
145
+ # AI: "This feature is worth sharing. Type /social to create a post."
146
+ ```
147
+
148
+ ### `/social` slash command
149
+ Creates a post from your current work context:
150
+ 1. Analyzes conversation history + git log + project info
151
+ 2. Reads post history for tone matching
152
+ 3. Asks which platforms
153
+ 4. Generates platform-optimized content
154
+ 5. Creates image (optional, platform-sized)
155
+ 6. Posts in background after approval
156
+
157
+ ## Data Directory
158
+
159
+ Everything lives in `~/.social-agent/`:
160
+
161
+ ```
162
+ ~/.social-agent/
163
+ ├── config.json # API keys and settings
164
+ ├── social-mode-prompt.md # AI assistant personality (editable)
165
+ ├── profile-map.json # Platform → Chrome profile mapping
166
+ ├── history.json # Action log
167
+ ├── knowledge/ # Platform knowledge files
168
+ │ ├── x.md # X/Twitter: selectors, URLs, limits
169
+ │ ├── linkedin.md # LinkedIn: aria-labels, anti-bot
170
+ │ ├── instagram.md # Instagram: aggressive anti-bot docs
171
+ │ ├── facebook.md # Facebook: checkpoint system
172
+ │ ├── mastodon.md # Mastodon: full API reference
173
+ │ ├── bluesky.md # Bluesky: AT Protocol API
174
+ │ └── telegram.md # Telegram: Bot API
175
+ ├── maps/ # Learned action maps (JSON)
176
+ ├── profiles/ # Chrome CDP working directory
177
+ └── screenshots/ # AI analysis screenshots
178
+ ```
179
+
180
+ ## Adding New Platforms
181
+
182
+ No code changes needed:
183
+
184
+ 1. Add URL to `BROWSER_PLATFORMS` in `cli.ts`
185
+ 2. Create `knowledge/platform.md`
186
+ 3. `social-agent login platform`
187
+ 4. `social-agent learn platform`
188
+ 5. `social-agent run platform "do something"`
189
+
190
+ ## Architecture
191
+
192
+ ```
193
+ social-agent/
194
+ ├── bin/social-agent.js # Global CLI entry point
195
+ ├── cli.ts # Command router
196
+ ├── install.ts # Setup wizard
197
+ ├── core/
198
+ │ ├── config.ts # Config & paths (~/.social-agent/)
199
+ │ ├── types.ts # TypeScript interfaces
200
+ │ ├── profiles.ts # Chrome profile discovery & selection
201
+ │ ├── history.ts # Action logging
202
+ │ └── screenshot.ts # HTML → JPEG converter
203
+ ├── ai/
204
+ │ ├── mapper.ts # Claude -p: create/heal selector maps
205
+ │ ├── planner.ts # Natural language → execution plan
206
+ │ ├── runner.ts # Execute plan with heal-on-failure
207
+ │ └── knowledge.ts # Platform knowledge reader
208
+ ├── platforms/
209
+ │ ├── mastodon.ts # Mastodon API driver
210
+ │ ├── bluesky.ts # Bluesky AT Protocol driver
211
+ │ └── browser/
212
+ │ └── driver.ts # Playwright + Chrome CDP + anti-detection
213
+ ├── knowledge/ # Platform knowledge (7 platforms, 7000+ lines)
214
+ └── hooks/
215
+ └── post-push # Git hook for post suggestions
216
+ ```
217
+
218
+ ## Requirements
219
+
220
+ - Node.js 18+
221
+ - Google Chrome (macOS — Linux/Windows support planned)
222
+ - [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) (`npm install -g @anthropic-ai/claude-code`)
223
+
224
+ ## License
225
+
226
+ MIT
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync } from "node:child_process";
4
+
5
+ try {
6
+ console.log(" Playwright Chromium yükleniyor...");
7
+ execSync("npx playwright install chromium", { stdio: "pipe" });
8
+ console.log(" ✓ Playwright Chromium yüklendi");
9
+ } catch {
10
+ console.log(" ⚠ Playwright Chromium otomatik yüklenemedi.");
11
+ console.log(" Manuel kur: npx playwright install chromium");
12
+ }
13
+
14
+ console.log(`
15
+ ✓ social-agent kuruldu!
16
+
17
+ Başlamak için:
18
+ social-agent setup
19
+ `);
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname, join } from "node:path";
5
+ import { existsSync, mkdirSync, readFileSync } from "node:fs";
6
+ import { execSync, spawn } from "node:child_process";
7
+ import { homedir } from "node:os";
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const PKG_DIR = join(__dirname, "..");
11
+
12
+ // Kullanıcının data dizini (~/.social-agent/)
13
+ const DATA_DIR = join(homedir(), ".social-agent");
14
+
15
+ // Data dizinini oluştur
16
+ for (const dir of ["maps", "profiles", "screenshots", "knowledge"]) {
17
+ mkdirSync(join(DATA_DIR, dir), { recursive: true });
18
+ }
19
+
20
+ // Knowledge dosyalarını kopyala (yoksa)
21
+ const knowledgeSrc = join(PKG_DIR, "knowledge");
22
+ const knowledgeDest = join(DATA_DIR, "knowledge");
23
+ if (existsSync(knowledgeSrc)) {
24
+ const { readdirSync, copyFileSync } = await import("node:fs");
25
+ for (const file of readdirSync(knowledgeSrc)) {
26
+ const dest = join(knowledgeDest, file);
27
+ if (!existsSync(dest)) {
28
+ copyFileSync(join(knowledgeSrc, file), dest);
29
+ }
30
+ }
31
+ }
32
+
33
+ const [,, command, ...args] = process.argv;
34
+
35
+ // Komuta göre doğru ts dosyasını çalıştır
36
+ const tsxPath = join(PKG_DIR, "node_modules", ".bin", "tsx");
37
+ const cwd = DATA_DIR;
38
+
39
+ function run(file, extraArgs = []) {
40
+ const proc = spawn(tsxPath, [join(PKG_DIR, file), ...extraArgs], {
41
+ cwd: DATA_DIR,
42
+ stdio: "inherit",
43
+ env: {
44
+ ...process.env,
45
+ SOCIAL_AGENT_DATA: DATA_DIR,
46
+ SOCIAL_AGENT_PKG: PKG_DIR,
47
+ },
48
+ });
49
+ proc.on("close", (code) => process.exit(code || 0));
50
+ }
51
+
52
+ switch (command) {
53
+ case "setup":
54
+ run("install.ts");
55
+ break;
56
+
57
+ case "login":
58
+ case "learn":
59
+ case "run":
60
+ case "post":
61
+ case "test":
62
+ case "status":
63
+ case "history":
64
+ run("cli.ts", [command, ...args]);
65
+ break;
66
+
67
+ case undefined:
68
+ case "--help":
69
+ case "-h":
70
+ console.log(`
71
+ social-agent - AI destekli sosyal medya otomasyon aracı
72
+
73
+ Kurulum:
74
+ social-agent setup İlk kurulum (isim, profil, platformlar)
75
+
76
+ Komutlar:
77
+ social-agent login <platform> Chrome profil seç ve giriş yap
78
+ social-agent learn "<görev>" <platform> AI ile aksiyon öğret
79
+ social-agent run <platform> "<komut>" Doğal dil ile çalıştır
80
+ social-agent post "<metin>" --platforms x,mastodon Post at
81
+ social-agent status Bağlı platformları göster
82
+ social-agent history Post geçmişi
83
+
84
+ Örnekler:
85
+ social-agent setup
86
+ social-agent login x
87
+ social-agent learn "tweet beğenmeyi öğren" x
88
+ social-agent run x "şu tweeti beğen: https://x.com/..."
89
+ social-agent run linkedin "3 insana bağlantı isteği gönder"
90
+ social-agent post "Yeni özellik!" --platforms x,mastodon
91
+
92
+ Ayarlar:
93
+ ~/.social-agent/ Data dizini
94
+ ~/.social-agent/config.json Platform API ayarları
95
+ ~/.social-agent/social-mode-prompt.md AI asistan profili (düzenlenebilir)
96
+ ~/.social-agent/knowledge/ Platform bilgileri
97
+ ~/.social-agent/maps/ Öğrenilmiş aksiyonlar
98
+ ~/.social-agent/history.json Post geçmişi
99
+
100
+ Claude Code entegrasyonu:
101
+ claude-social Sosyal medya farkındalıklı mod
102
+ /social Elle post oluştur
103
+ `);
104
+ break;
105
+
106
+ default:
107
+ console.log(`Bilinmeyen komut: ${command}. --help ile kullanımı gör.`);
108
+ process.exit(1);
109
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "mastodon": {
3
+ "instanceUrl": "https://mastodon.scot",
4
+ "accessToken": "mastodon-access-token-buraya"
5
+ },
6
+ "bluesky": {
7
+ "identifier": "kullanici.bsky.social",
8
+ "password": "app-password-buraya"
9
+ },
10
+ "telegram": {
11
+ "botToken": "123456:ABC-DEF...",
12
+ "chatId": "@kanal_adi"
13
+ },
14
+ "browser": {
15
+ "headless": true
16
+ },
17
+ "claude": {
18
+ "model": "sonnet"
19
+ }
20
+ }
@@ -0,0 +1,69 @@
1
+ #!/bin/bash
2
+ # ============================================================
3
+ # Git Post-Push Hook
4
+ # Push sonrası Claude Code'a post önerisi yapması için bildirim gönderir
5
+ #
6
+ # Kurulum:
7
+ # npx tsx install.ts (otomatik kurar)
8
+ # veya manuel: git config --global core.hooksPath ~/.git-hooks
9
+ # ============================================================
10
+
11
+ SOCIAL_AGENT_DIR="${SOCIAL_AGENT_DIR:-/Volumes/harici_ssd/postiz/social-agent}"
12
+
13
+ # Config yoksa sessizce çık
14
+ if [[ ! -f "$SOCIAL_AGENT_DIR/config.json" ]]; then
15
+ exit 0
16
+ fi
17
+
18
+ # Profil bilgisini al
19
+ PROMPT_FILE="$SOCIAL_AGENT_DIR/social-mode-prompt.md"
20
+ if [[ -f "$PROMPT_FILE" ]]; then
21
+ NAME=$(grep "Kullanıcının adı:" "$PROMPT_FILE" | head -1 | sed 's/.*: //')
22
+ else
23
+ NAME="Developer"
24
+ fi
25
+
26
+ # Mevcut repo bilgisi
27
+ REPO_NAME=$(basename "$(git rev-parse --show-toplevel)")
28
+ BRANCH=$(git rev-parse --abbrev-ref HEAD)
29
+
30
+ # Sadece önemli branch'lerde çalış
31
+ case "$BRANCH" in
32
+ main|master|dev|develop|release/*) ;;
33
+ *) exit 0 ;;
34
+ esac
35
+
36
+ # Son push'taki commitler
37
+ COMMITS=$(git log --oneline -5 2>/dev/null)
38
+ COMMIT_COUNT=$(echo "$COMMITS" | wc -l | tr -d ' ')
39
+
40
+ if [[ -z "$COMMITS" ]]; then
41
+ exit 0
42
+ fi
43
+
44
+ # Diff özeti
45
+ DIFF_STAT=$(git diff --stat HEAD~1..HEAD 2>/dev/null | tail -1)
46
+
47
+ # Önemsiz commit'leri atla
48
+ if echo "$COMMITS" | head -1 | grep -qiE "^[a-f0-9]+ (typo|fix typo|merge|bump|chore|docs:|ci:)"; then
49
+ exit 0
50
+ fi
51
+
52
+ # macOS bildirimi gönder
53
+ if command -v osascript &>/dev/null; then
54
+ osascript -e "display notification \"$REPO_NAME: $COMMIT_COUNT yeni commit. /social ile paylaşabilirsin.\" with title \"Social Agent\" subtitle \"$NAME, post önerisi var!\" sound name \"Glass\"" 2>/dev/null || true
55
+ fi
56
+
57
+ # Terminal'e bilgi yaz
58
+ echo ""
59
+ echo "┌─────────────────────────────────────────────┐"
60
+ echo "│ Social Agent: Post önerisi │"
61
+ echo "├─────────────────────────────────────────────┤"
62
+ echo "│ $REPO_NAME ($BRANCH) - $COMMIT_COUNT commit"
63
+ echo "│ $DIFF_STAT"
64
+ echo "│ │"
65
+ echo "│ claude-social ile çalışırken /social yaz │"
66
+ echo "│ veya: cd $SOCIAL_AGENT_DIR │"
67
+ echo "│ npx tsx cli.ts run x \"post at: ...\" │"
68
+ echo "└─────────────────────────────────────────────┘"
69
+ echo ""