dsh-plugin-chuhai 0.2.2 → 0.2.4

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +31 -21
  2. package/LICENSE +21 -21
  3. package/README.md +25 -25
  4. package/books/ai-global-media/BOOK.md +129 -119
  5. package/books/ai-global-media/expert/SOURCE.json +41 -0
  6. package/books/ai-global-media/expert/agents/ilang-wechat-awesome.md +267 -0
  7. package/books/ai-global-media/expert/skills/remote-dispatch/SKILL.md +101 -0
  8. package/books/ai-global-media/expert/skills/remote-dispatch/references/gateway-api.md +58 -0
  9. package/books/ai-global-media/expert/skills/remote-dispatch/scripts/dispatch.py +299 -0
  10. package/books/ai-global-media/expert/skills/remote-dispatch/scripts/setup-gateway.ps1 +74 -0
  11. package/books/ai-global-media/expert/skills/remote-dispatch/scripts/setup-gateway.sh +94 -0
  12. package/books/ai-global-media/expert/skills/wechat-article/SKILL.md +80 -0
  13. package/books/ai-global-media/expert/skills/wechat-article/references/algorithm-and-rhythm.md +54 -0
  14. package/books/ai-global-media/expert/skills/wechat-article/references/compliance.md +68 -0
  15. package/books/ai-global-media/expert/skills/wechat-article/references/cover-prompt.md +19 -0
  16. package/books/ai-global-media/expert/skills/wechat-article/references/deai.md +64 -0
  17. package/books/ai-global-media/expert/skills/wechat-article/references/genes.md +168 -0
  18. package/books/ai-global-media/expert/skills/wechat-article/references/other-platforms.md +47 -0
  19. package/books/ai-global-media/expert/skills/wechat-article/references/self-check.md +32 -0
  20. package/books/ai-global-media/expert/skills/wechat-article/references/structures-and-titles.md +77 -0
  21. package/books/ai-global-media/expert/skills/wechat-article/references/wechat-format-and-api.md +61 -0
  22. package/books/ai-global-media/expert/skills/wechat-draft-push/SKILL.md +129 -0
  23. package/books/ai-global-media/expert/skills/wechat-draft-push/references/api-notes.md +168 -0
  24. package/books/ai-global-media/expert/skills/wechat-draft-push/references/html-rules.md +62 -0
  25. package/books/ai-global-media/expert/skills/wechat-draft-push/scripts/cards.html +75 -0
  26. package/books/ai-global-media/expert/skills/wechat-draft-push/scripts/newspic_cards.py +345 -0
  27. package/books/ai-global-media/expert/skills/wechat-draft-push/scripts/wechat_draft.py +1023 -0
  28. package/books/ai-global-media/expert/skills/wechat-topic-hunter/SKILL.md +92 -0
  29. package/books/ai-global-media/expert/skills/wechat-topic-hunter/references/method.md +49 -0
  30. package/books/ai-global-media/expert/skills/wechat-topic-hunter/references/wxrank-api.md +51 -0
  31. package/books/ai-global-media/expert/skills/wechat-topic-hunter/scripts/hot_sources.py +553 -0
  32. package/books/ai-global-media/expert/skills/wechat-topic-hunter/scripts/sources.json +714 -0
  33. package/books/ai-global-media/expert/skills/wechat-topic-hunter/scripts/wxrank_topics.py +466 -0
  34. package/books/ai-global-media/lens-yiyang.md +86 -0
  35. package/books/ai-global-media/poster-poju.jpg +0 -0
  36. package/cordis.patch.yml +8 -8
  37. package/lib/index.js +12 -1
  38. package/package.json +53 -53
@@ -0,0 +1,299 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """remote-dispatch: 把一段命令块派给远程机上的 CodeBuddy Code 网关跑,收回结果。只用标准库。
4
+
5
+ 配置文件 ~/.dispatch.json(用户自己写,脚本只读):
6
+ {
7
+ "default": "vps",
8
+ "remotes": {
9
+ "vps": {"url": "http://1.2.3.4:8080", "password": "网关口令"}
10
+ }
11
+ }
12
+
13
+ 命令:
14
+ python dispatch.py list 列出配置的远程机并探活
15
+ python dispatch.py send --file 块.md [--to vps] [--timeout 900] [--max-wait 3600]
16
+ python dispatch.py send --text "一句话" [--to vps]
17
+ python dispatch.py sessions [--to vps] [--n 5] 远程最近的会话
18
+ python dispatch.py history --session <id> [--to vps]
19
+ python dispatch.py cancel --run <runId> [--to vps]
20
+
21
+ 网关的三个硬规矩(实测):请求头带 X-CodeBuddy-Request: 1、Authorization: Bearer 口令、Host: localhost:<端口>;
22
+ 正文 UTF-8;结果要在跑的时候挂 /runs/{id}/stream 收,跑完再挂就没了(脚本会自动回退到会话历史)。
23
+ """
24
+ import socket
25
+ import argparse, datetime, io, json, os, re, sys, time, uuid
26
+ import urllib.request, urllib.error
27
+ from urllib.parse import urlparse
28
+
29
+ try:
30
+ sys.stdout.reconfigure(encoding="utf-8")
31
+ sys.stderr.reconfigure(encoding="utf-8")
32
+ except Exception:
33
+ pass
34
+
35
+ CFG = os.path.expanduser("~/.dispatch.json")
36
+ LOGDIR = os.path.expanduser("~/dispatch-logs")
37
+ VIA_NOTE = "::NOTE{via:remote-dispatch 这段是本机派活技能一次性发来的 没人会回答你的追问 要人决定的按命令里的默认值走 做到能做的最后一步 结果和回执一次给全}"
38
+
39
+
40
+ def die(msg, code=1):
41
+ print(msg)
42
+ sys.exit(code)
43
+
44
+
45
+ def load_cfg():
46
+ if not os.path.exists(CFG):
47
+ die("没找到 %s。用户主目录建这个文件,写 default 和 remotes,见本技能 SKILL.md。" % CFG)
48
+ try:
49
+ return json.load(io.open(CFG, encoding="utf-8"))
50
+ except Exception as e:
51
+ die("%s 不是合法 JSON:%s" % (CFG, e))
52
+
53
+
54
+ def pick(cfg, name):
55
+ remotes = cfg.get("remotes") or {}
56
+ name = name or cfg.get("default") or (next(iter(remotes)) if remotes else None)
57
+ if not name or name not in remotes:
58
+ die("远程机 %r 没配置。配置里有:%s" % (name, ", ".join(remotes) or "空"))
59
+ r = remotes[name]
60
+ url = (r.get("url") or "").rstrip("/")
61
+ pw = r.get("password") or ""
62
+ if not url or not pw:
63
+ die("远程机 %s 缺 url 或 password" % name)
64
+ u = urlparse(url)
65
+ port = u.port or (443 if u.scheme == "https" else 80)
66
+ return name, url, pw, port
67
+
68
+
69
+ def headers(pw, port, extra=None):
70
+ h = {
71
+ "X-CodeBuddy-Request": "1",
72
+ "Authorization": "Bearer " + pw,
73
+ "Host": "localhost:%d" % port,
74
+ "Content-Type": "application/json; charset=utf-8",
75
+ "Accept": "application/json, text/event-stream",
76
+ }
77
+ if extra:
78
+ h.update(extra)
79
+ return h
80
+
81
+
82
+ def call(url, pw, port, method="GET", body=None, timeout=30):
83
+ data = json.dumps(body, ensure_ascii=False).encode("utf-8") if body is not None else None
84
+ req = urllib.request.Request(url, data=data, method=method, headers=headers(pw, port))
85
+ try:
86
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
87
+ raw = resp.read().decode("utf-8", "replace")
88
+ except urllib.error.HTTPError as e:
89
+ raw = e.read().decode("utf-8", "replace")
90
+ try:
91
+ return e.code, json.loads(raw)
92
+ except Exception:
93
+ return e.code, {"raw": raw[:500]}
94
+ except Exception as e:
95
+ return 0, {"error": str(e)}
96
+ try:
97
+ return 200, json.loads(raw)
98
+ except Exception:
99
+ return 200, {"raw": raw[:500]}
100
+
101
+
102
+ def mask(s, pw):
103
+ return s.replace(pw, "<口令>") if pw else s
104
+
105
+
106
+ def cmd_list(args):
107
+ cfg = load_cfg()
108
+ for name in (cfg.get("remotes") or {}):
109
+ _, url, pw, port = pick(cfg, name)
110
+ code, d = call(url + "/api/v1/health", pw, port, timeout=10)
111
+ st = (d.get("data") or {}).get("status") if isinstance(d, dict) else None
112
+ plats = ",".join((d.get("data") or {}).get("platforms", [])) if isinstance(d, dict) and d.get("data") else ""
113
+ print("%-12s %-32s %s %s" % (name, url, "在线 " + plats if st == "ok" else "不通 http %s %s" % (code, mask(json.dumps(d, ensure_ascii=False)[:120], pw)), "(默认)" if name == cfg.get("default") else ""))
114
+
115
+
116
+ def extract_texts(obj, out):
117
+ """从任意 JSON 里捞 assistant 的文字(markdown / text / content 字符串)。"""
118
+ if isinstance(obj, dict):
119
+ role = obj.get("role")
120
+ for k in ("markdown", "text"):
121
+ v = obj.get(k)
122
+ if isinstance(v, str) and v.strip() and role != "user":
123
+ out.append(v)
124
+ c = obj.get("content")
125
+ if isinstance(c, str) and c.strip() and role == "assistant":
126
+ out.append(c)
127
+ for v in obj.values():
128
+ extract_texts(v, out)
129
+ elif isinstance(obj, list):
130
+ for v in obj:
131
+ extract_texts(v, out)
132
+
133
+
134
+ def read_stream(url, pw, port, run_id, max_wait):
135
+ """挂 SSE,收 message 事件里的 content.markdown,到 done 为止。返回 (markdowns, status, raw_error)。
136
+ 流中途卡住、断掉都不抛栈:返回已收到的部分和 timeout / 流中断 的状态。"""
137
+ req = urllib.request.Request(url + "/api/v1/runs/%s/stream" % run_id, headers=headers(pw, port, {"Accept": "text/event-stream"}))
138
+ mds, status, event = [], None, None
139
+ deadline = time.time() + max_wait
140
+ try:
141
+ resp = urllib.request.urlopen(req, timeout=max_wait)
142
+ except urllib.error.HTTPError as e:
143
+ raw = e.read().decode("utf-8", "replace")
144
+ return mds, status, raw[:300]
145
+ except Exception as e:
146
+ return mds, status, str(e)
147
+ ctype = resp.headers.get("Content-Type", "")
148
+ if "json" in ctype:
149
+ return mds, status, resp.read().decode("utf-8", "replace")[:300]
150
+ buf = []
151
+ try:
152
+ for line in resp:
153
+ if time.time() > deadline:
154
+ return mds, status or "timeout", "超时 %ds" % max_wait
155
+ line = line.decode("utf-8", "replace").rstrip("\r\n")
156
+ if line.startswith("event:"):
157
+ event = line[6:].strip()
158
+ elif line.startswith("data:"):
159
+ buf.append(line[5:].strip())
160
+ elif line == "":
161
+ if buf:
162
+ data = "\n".join(buf); buf = []
163
+ try:
164
+ d = json.loads(data)
165
+ except Exception:
166
+ d = {"raw": data}
167
+ if event == "message":
168
+ status = d.get("status") or status
169
+ md = (d.get("content") or {}).get("markdown") if isinstance(d.get("content"), dict) else None
170
+ if md:
171
+ mds.append(md)
172
+ calls = (d.get("agent") or {}).get("toolCalls") or []
173
+ if calls:
174
+ print(" [远程动了 %d 个工具]" % len(calls), file=sys.stderr)
175
+ elif event == "done":
176
+ return mds, status or "completed", None
177
+ elif event in ("error",):
178
+ return mds, "error", data[:300]
179
+ event = None
180
+ except (TimeoutError, socket.timeout) as e:
181
+ return mds, status or "timeout", "超时 %ds(流卡住:%s)" % (max_wait, e)
182
+ except Exception as e:
183
+ return mds, status or "stream-broken", "流中断 %s: %s" % (type(e).__name__, str(e)[:120])
184
+ return mds, status or "closed", None
185
+
186
+
187
+ def fallback_history(url, pw, port, text):
188
+ code, d = call(url + "/api/v1/sessions?limit=5", pw, port, timeout=20)
189
+ sess = (d.get("data") or {}).get("sessions") if isinstance(d, dict) else None
190
+ if not sess:
191
+ return None
192
+ head = text.strip()[:20]
193
+ cand = [s for s in sess if str(s.get("name", "")).startswith(head)] or sess[:1]
194
+ sid = cand[0].get("id")
195
+ code, h = call(url + "/api/v1/sessions/%s/history" % sid, pw, port, timeout=30)
196
+ out = []
197
+ extract_texts(h, out)
198
+ return out[-1] if out else None
199
+
200
+
201
+ def save_log(name, run_id, text, result, status):
202
+ day = datetime.datetime.now().strftime("%Y-%m-%d")
203
+ d = os.path.join(LOGDIR, day)
204
+ os.makedirs(d, exist_ok=True)
205
+ p = os.path.join(d, "%s-%s-%s.md" % (datetime.datetime.now().strftime("%H%M%S"), name, run_id[:8]))
206
+ with io.open(p, "w", encoding="utf-8") as f:
207
+ f.write("# 派活记录\n\n- 远程机: %s\n- runId: %s\n- 状态: %s\n- 时间: %s\n\n## 发出去的\n\n%s\n\n## 收回来的\n\n%s\n" % (name, run_id, status, datetime.datetime.now().isoformat(timespec="seconds"), text, result or "(空)"))
208
+ return p
209
+
210
+
211
+ def cmd_send(args):
212
+ cfg = load_cfg()
213
+ name, url, pw, port = pick(cfg, args.to)
214
+ if args.file:
215
+ text = io.open(args.file, encoding="utf-8").read()
216
+ elif args.text:
217
+ text = args.text
218
+ else:
219
+ die("要 --file 或 --text")
220
+ if not text.strip():
221
+ die("要发的内容是空的")
222
+ orig = text
223
+ if not getattr(args, "raw", False):
224
+ text = VIA_NOTE + "\n\n" + text
225
+ client_id = "dispatch-" + uuid.uuid4().hex[:12]
226
+ body = {
227
+ "id": client_id, "type": "message", "version": "1.0",
228
+ "source": {"platform": "generic", "sender": {"id": "dispatch", "name": "dispatch"},
229
+ "conversation": {"id": client_id, "type": "direct"}},
230
+ "payload": {"text": text},
231
+ "timeoutMs": int(args.timeout) * 1000,
232
+ }
233
+ code, d = call(url + "/api/v1/runs", pw, port, method="POST", body=body, timeout=30)
234
+ run_id = (d.get("data") or {}).get("runId") if isinstance(d, dict) else None
235
+ if not run_id:
236
+ die("派活失败 http %s:%s" % (code, mask(json.dumps(d, ensure_ascii=False)[:400], pw)))
237
+ print("已派给 %s,runId %s,等结果…" % (name, run_id), file=sys.stderr)
238
+ mds, status, err = read_stream(url, pw, port, run_id, int(args.max_wait))
239
+ result = "\n\n".join(m for m in mds if m) if mds else None
240
+ if not result and err and "RUN_NOT_FOUND" in err:
241
+ print(" 跑得太快没挂上流,改从会话历史读…", file=sys.stderr)
242
+ result = fallback_history(url, pw, port, orig) # 用原正文对会话名,不带 ::NOTE 前缀
243
+ status = status or "completed"
244
+ if not result and err:
245
+ status = status or "error"
246
+ result = "(没收到结果) " + mask(err, pw)
247
+ p = save_log(name, run_id, text, result, status)
248
+ print(result or "(空)")
249
+ print("\n[状态 %s · 记录 %s]" % (status, p), file=sys.stderr)
250
+
251
+
252
+ def cmd_sessions(args):
253
+ cfg = load_cfg()
254
+ name, url, pw, port = pick(cfg, args.to)
255
+ code, d = call(url + "/api/v1/sessions?limit=%d" % int(args.n), pw, port, timeout=20)
256
+ sess = (d.get("data") or {}).get("sessions") if isinstance(d, dict) else None
257
+ if not sess:
258
+ die("没拿到会话:http %s %s" % (code, mask(json.dumps(d, ensure_ascii=False)[:300], pw)))
259
+ for s in sess:
260
+ ts = datetime.datetime.fromtimestamp((s.get("updatedAt") or 0) / 1000).strftime("%m-%d %H:%M")
261
+ print("%s %s %s" % (s.get("id"), ts, str(s.get("name", ""))[:60]))
262
+
263
+
264
+ def cmd_history(args):
265
+ cfg = load_cfg()
266
+ name, url, pw, port = pick(cfg, args.to)
267
+ code, h = call(url + "/api/v1/sessions/%s/history" % args.session, pw, port, timeout=30)
268
+ out = []
269
+ extract_texts(h, out)
270
+ if not out:
271
+ print(mask(json.dumps(h, ensure_ascii=False)[:1500], pw))
272
+ else:
273
+ print("\n\n---\n\n".join(out[-int(args.n):]))
274
+
275
+
276
+ def cmd_cancel(args):
277
+ cfg = load_cfg()
278
+ name, url, pw, port = pick(cfg, args.to)
279
+ code, d = call(url + "/api/v1/runs/%s/cancel" % args.run, pw, port, method="POST", body={}, timeout=20)
280
+ print("http %s %s" % (code, mask(json.dumps(d, ensure_ascii=False)[:300], pw)))
281
+
282
+
283
+ def main():
284
+ ap = argparse.ArgumentParser(description="把命令块派给远程 CodeBuddy 网关跑")
285
+ sub = ap.add_subparsers(dest="cmd")
286
+ sub.add_parser("list")
287
+ p = sub.add_parser("send"); p.add_argument("--to"); p.add_argument("--file"); p.add_argument("--text")
288
+ p.add_argument("--timeout", default=900, help="远程单次执行超时 秒"); p.add_argument("--max-wait", default=3600, help="本地最多等多久 秒"); p.add_argument("--raw", action="store_true", help="不在正文前加 ::NOTE{via:remote-dispatch …} 那一行")
289
+ p = sub.add_parser("sessions"); p.add_argument("--to"); p.add_argument("--n", default=5)
290
+ p = sub.add_parser("history"); p.add_argument("--to"); p.add_argument("--session", required=True); p.add_argument("--n", default=1)
291
+ p = sub.add_parser("cancel"); p.add_argument("--to"); p.add_argument("--run", required=True)
292
+ args = ap.parse_args()
293
+ if not args.cmd:
294
+ ap.print_help(); return
295
+ {"list": cmd_list, "send": cmd_send, "sessions": cmd_sessions, "history": cmd_history, "cancel": cmd_cancel}[args.cmd](args)
296
+
297
+
298
+ if __name__ == "__main__":
299
+ main()
@@ -0,0 +1,74 @@
1
+ # 远程机(Windows)起 CodeBuddy Code 网关:装 CodeBuddy Code,把 key 写进 CLI 设置,开一个窗口跑网关。Windows PowerShell 5.1 和 PowerShell 7 都能跑。
2
+ # 用法:
3
+ # 1 先装 Node(nodejs.org 下 LTS 安装包装好,PowerShell 里 node -v 能出版本号)
4
+ # 2 用记事本在用户主目录建 .codebuddy.env,一行:大写 CODEBUDDY_API_KEY 然后等号 然后你的 key(WorkBuddy 国内版账号的 API key,ck 开头),等号两边不留空格
5
+ # 3 PowerShell 里:powershell -ExecutionPolicy Bypass -File setup-gateway.ps1
6
+ # 可重复跑。远程机重启后再跑一次就行。网关跑在一个最小化的窗口里,远程桌面只断开别注销,注销了窗口就没了。
7
+ # 口令由网关首次启动自己生成,存在用户主目录 .codebuddy\settings.json 的 gateway.password。
8
+ # 这个文件必须保持 UTF-8 带 BOM 保存,否则 Windows PowerShell 5.1 读中文会乱。
9
+ param([int]$Port = 8080, [string]$Session = "gzh-worker")
10
+ $ErrorActionPreference = "Continue"
11
+ try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {}
12
+ function Log($m) { Write-Host ("[{0}] {1}" -f (Get-Date -Format HH:mm:ss), $m) }
13
+ function Probe($p) {
14
+ # 网关在就回 200 或 401(没带口令),都算在
15
+ try { Invoke-WebRequest -UseBasicParsing -TimeoutSec 3 -Headers @{ "X-CodeBuddy-Request" = "1" } "http://127.0.0.1:$p/api/v1/health" | Out-Null; return $true }
16
+ catch {
17
+ $resp = $_.Exception.Response
18
+ if ($resp -and ([int]$resp.StatusCode) -eq 401) { return $true }
19
+ return $false
20
+ }
21
+ }
22
+
23
+ $envFile = Join-Path $HOME ".codebuddy.env"
24
+ if (-not (Test-Path $envFile)) { Write-Host "缺 $envFile(一行 大写 CODEBUDDY_API_KEY 然后等号 然后你的 key)"; exit 1 }
25
+ $key = $null
26
+ foreach ($line in Get-Content $envFile) {
27
+ if ($line -match '^\s*CODEBUDDY_API_KEY\s*=\s*(.+?)\s*$') { $key = $Matches[1].Trim('"').Trim("'") }
28
+ }
29
+ if (-not $key) { Write-Host "$envFile 里没有 CODEBUDDY_API_KEY"; exit 1 }
30
+
31
+ Log "1 Node"
32
+ $nv = (cmd /c "node -v 2>nul" | Out-String).Trim()
33
+ if (-not $nv) { Write-Host "没装 Node,去 nodejs.org 装 LTS 版再跑"; exit 1 }
34
+ Log "node $nv"
35
+
36
+ Log "2 CodeBuddy Code"
37
+ cmd /c "npm i -g @tencent-ai/codebuddy-code >nul 2>&1"
38
+ $cb = Get-Command codebuddy.cmd -ErrorAction SilentlyContinue
39
+ if (-not $cb) { $cb = Get-Command codebuddy -ErrorAction SilentlyContinue }
40
+ if (-not $cb) { Write-Host "npm 装完找不到 codebuddy 命令,关掉 PowerShell 重开一个再跑"; exit 1 }
41
+ $cv = (cmd /c "codebuddy --version 2>nul" | Out-String).Trim()
42
+ Log "codebuddy $cv"
43
+
44
+ Log "3 settings.json:key 和国内版环境变量写进 CLI 设置"
45
+ $dir = Join-Path $HOME ".codebuddy"
46
+ New-Item -ItemType Directory -Force $dir | Out-Null
47
+ $sp = Join-Path $dir "settings.json"
48
+ $obj = New-Object PSObject
49
+ if (Test-Path $sp) { $obj = (Get-Content $sp -Raw -Encoding UTF8 | ConvertFrom-Json) }
50
+ if (-not $obj.PSObject.Properties["env"]) { $obj | Add-Member -NotePropertyName "env" -NotePropertyValue (New-Object PSObject) }
51
+ foreach ($kv in @(@("CODEBUDDY_INTERNET_ENVIRONMENT", "internal"), @("CODEBUDDY_API_KEY", $key))) {
52
+ if ($obj.env.PSObject.Properties[$kv[0]]) { $obj.env.($kv[0]) = $kv[1] }
53
+ else { $obj.env | Add-Member -NotePropertyName $kv[0] -NotePropertyValue $kv[1] }
54
+ }
55
+ [System.IO.File]::WriteAllText($sp, ($obj | ConvertTo-Json -Depth 10), (New-Object System.Text.UTF8Encoding $false))
56
+ Log "settings.json ok"
57
+
58
+ Log "4 网关(0.0.0.0:$Port 口令鉴权)"
59
+ $work = Join-Path $HOME "gzh"
60
+ New-Item -ItemType Directory -Force $work | Out-Null
61
+ if (Probe $Port) {
62
+ Log "端口 $Port 上已经有网关在跑,不重复起"
63
+ } else {
64
+ $env:CODEBUDDY_INTERNET_ENVIRONMENT = "internal"
65
+ $env:CODEBUDDY_API_KEY = $key
66
+ Start-Process -FilePath $cb.Source -ArgumentList @("--serve", "--host", "0.0.0.0", "--port", "$Port", "--session-id", $Session, "--permission-mode", "bypassPermissions") -WorkingDirectory $work -WindowStyle Minimized
67
+ $ok = $false
68
+ for ($i = 0; $i -lt 30; $i++) { Start-Sleep -Seconds 2; if (Probe $Port) { $ok = $true; break } }
69
+ if (-not $ok) { Write-Host "网关 60 秒内没起来,看任务栏那个最小化的窗口里报什么"; exit 1 }
70
+ Log "网关起来了(窗口最小化在任务栏,别关)"
71
+ }
72
+ $ip = "<这台机的公网IP>"
73
+ try { $ip = (Invoke-WebRequest -UseBasicParsing -TimeoutSec 5 "https://api.ipify.org").Content.Trim() } catch {}
74
+ Log ("完成。本机 ~/.dispatch.json 里这台写 http://{0}:{1} ,口令抄 {2} 里 gateway.password 的值(别贴进任何对话)" -f $ip, $Port, $sp)
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env bash
2
+ # 远程机(Linux,Ubuntu 22.04 / 24.04)起 CodeBuddy Code 网关:装 Node 22 和 CodeBuddy Code,装公众号爆文专家和它的技能,起 systemd 服务。
3
+ # 用法:
4
+ # 1 先把 WorkBuddy 国内版账号的 API key(ck 开头)写进 /root/.codebuddy.env,一行:大写 CODEBUDDY_API_KEY 然后等号 然后你的 key,等号两边不留空格
5
+ # 2 bash setup-gateway.sh
6
+ # 可重复跑。只装东西、起服务,不动 SSH、不动防火墙、不改密码。口令由网关首次启动自己生成,存在 /root/.codebuddy/settings.json 的 gateway.password。
7
+ set -euo pipefail
8
+ export DEBIAN_FRONTEND=noninteractive
9
+ log(){ echo "[$(date +%H:%M:%S)] $*"; }
10
+ REPO="adsorgcn/WorkBuddy"
11
+ PORT="${GATEWAY_PORT:-8080}"
12
+ SESSION="${GATEWAY_SESSION:-gzh-worker}"
13
+ WORK=/root/gzh
14
+
15
+ ENVF=/root/.codebuddy.env
16
+ [ -f "$ENVF" ] || { echo "缺 $ENVF(一行 大写 CODEBUDDY_API_KEY 然后等号 然后你的 key)"; exit 1; }
17
+ set -a; . "$ENVF"; set +a
18
+ [ -n "${CODEBUDDY_API_KEY:-}" ] || { echo "$ENVF 里没有 CODEBUDDY_API_KEY"; exit 1; }
19
+ export CODEBUDDY_INTERNET_ENVIRONMENT=internal
20
+
21
+ log "1 基础包"
22
+ apt-get update -qq
23
+ apt-get install -y -qq curl git unzip ca-certificates python3 python3-venv >/dev/null
24
+
25
+ log "2 Node 22 + CodeBuddy Code"
26
+ if ! command -v node >/dev/null 2>&1 || [ "$(node -v | sed 's/v//' | cut -d. -f1)" -lt 20 ]; then
27
+ curl -fsSL https://deb.nodesource.com/setup_22.x | bash - >/dev/null
28
+ apt-get install -y -qq nodejs >/dev/null
29
+ fi
30
+ npm i -g @tencent-ai/codebuddy-code >/dev/null 2>&1 || npm i -g @tencent-ai/codebuddy-code
31
+ log "codebuddy $(codebuddy --version)"
32
+
33
+ log "3 专家包(GitHub 最新发布版)"
34
+ mkdir -p "$WORK/pkg" /root/.codebuddy/skills
35
+ cd "$WORK/pkg"
36
+ URL=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep -o '"browser_download_url": *"[^"]*ilang-wechat-awesome-workbuddy-expert[^"]*"' | head -1 | sed 's/.*"\(http[^"]*\)"/\1/')
37
+ [ -n "$URL" ] || { echo "拿不到发布页的专家包地址,去 https://github.com/$REPO/releases 手动下载 ilang-wechat-awesome-workbuddy-expert 开头的 zip 放到 $WORK/pkg 再跑"; exit 1; }
38
+ ZIP=$(basename "$URL")
39
+ [ -f "$ZIP" ] || curl -fsSL -o "$ZIP" "$URL"
40
+ rm -rf ilang-wechat-awesome && unzip -q -o "$ZIP"
41
+ for s in wechat-article wechat-draft-push wechat-topic-hunter remote-dispatch; do
42
+ [ -d "ilang-wechat-awesome/skills/$s" ] || continue
43
+ rm -rf "/root/.codebuddy/skills/$s"; cp -r "ilang-wechat-awesome/skills/$s" "/root/.codebuddy/skills/$s"
44
+ done
45
+ python3 - <<'EOF'
46
+ import io, re
47
+ t = io.open("/root/gzh/pkg/ilang-wechat-awesome/agents/ilang-wechat-awesome.md", encoding="utf-8").read()
48
+ m = re.match(r"^---\n.*?\n---\n", t, re.S)
49
+ body = t[m.end():] if m else t
50
+ io.open("/root/gzh/CODEBUDDY.md", "w", encoding="utf-8").write(body)
51
+ print("专家人设写进 /root/gzh/CODEBUDDY.md,字数", len(body))
52
+ EOF
53
+ log "专家包 $ZIP 装好"
54
+
55
+ log "4 settings.json:key 和国内版环境变量写进 CLI 设置"
56
+ python3 - <<'EOF'
57
+ import json, io, os
58
+ p = "/root/.codebuddy/settings.json"
59
+ d = json.load(io.open(p, encoding="utf-8")) if os.path.exists(p) else {}
60
+ env = d.setdefault("env", {})
61
+ env["CODEBUDDY_INTERNET_ENVIRONMENT"] = "internal"
62
+ env["CODEBUDDY_API_KEY"] = os.environ["CODEBUDDY_API_KEY"]
63
+ io.open(p, "w", encoding="utf-8").write(json.dumps(d, ensure_ascii=False, indent=2))
64
+ print("settings.json ok")
65
+ EOF
66
+
67
+ log "5 网关 systemd 服务(0.0.0.0:$PORT 口令鉴权 工作目录 $WORK)"
68
+ cat >/etc/systemd/system/codebuddy-gateway.service <<UNIT
69
+ [Unit]
70
+ Description=CodeBuddy Code HTTP gateway (remote worker)
71
+ After=network-online.target
72
+ Wants=network-online.target
73
+
74
+ [Service]
75
+ Type=simple
76
+ User=root
77
+ WorkingDirectory=$WORK
78
+ EnvironmentFile=$ENVF
79
+ Environment=HOME=/root
80
+ Environment=CODEBUDDY_INTERNET_ENVIRONMENT=internal
81
+ ExecStart=/usr/bin/env codebuddy --serve --host 0.0.0.0 --port $PORT --session-id $SESSION --permission-mode bypassPermissions
82
+ Restart=always
83
+ RestartSec=5
84
+
85
+ [Install]
86
+ WantedBy=multi-user.target
87
+ UNIT
88
+ systemctl daemon-reload
89
+ systemctl enable --now codebuddy-gateway
90
+ sleep 8
91
+ systemctl is-active codebuddy-gateway
92
+ curl -s -m 5 -H "X-CodeBuddy-Request: 1" -H "Host: localhost:$PORT" "http://127.0.0.1:$PORT/api/v1/health"; echo
93
+ IP=$(curl -s -m 5 https://api.ipify.org || echo "<这台机的公网IP>")
94
+ log "完成。本机 ~/.dispatch.json 里这台写 http://$IP:$PORT ,口令抄 /root/.codebuddy/settings.json 里 gateway.password 的值(别贴进任何对话)"
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: wechat-article
3
+ display_name: 公众号爆文写作
4
+ display_name_en: WeChat Viral Article Writing
5
+ description: "WeChat official account (公众号) article writing. Use when the user asks 公众号/公众号文章/爆文/写公众号/改公众号/去AI味/封面提示词/标题/微信排版/转微信格式, or pastes source material and wants it turned into a WeChat article. Restructures the user's own material with writing genes distilled from 200+ field-tested articles, runs a 12-point self-check with built-in de-AI editing, outputs Markdown plus three titles and a cover image prompt. Refuses requests with no source material."
6
+ description_zh: "投喂素材,按爆文写作基因重组成公众号文章:3 个标题、MD 正文、封面图提示词、12 项自查、内置去 AI 味、合规红线。不接无素材请求。"
7
+ description_en: "Turn your own source material into a WeChat article with field-tested structure, a 12-point self-check, built-in de-AI editing and compliance rules. No material, no article. Built on the iLang protocol (ilang.ai)."
8
+ category: writing
9
+ version: 2.3.58
10
+ author: iLang Inc.
11
+ ---
12
+
13
+ ::ILANG::v5.0
14
+ [TYPE:skill][PROJECT:wechat_awesome][VERSION:2.3.58][DATE:2026-10-08][LANG:zh]
15
+ ::STATE{@ROLE, function:把用户投喂的素材按公众号爆文写作基因重组成可直接排版发布的稿子}
16
+ ::STATE{@SCOPE, now:公众号文章+标题+封面提示词+12项自查+去AI味+微信排版, next:一稿多发到X_小红书_YouTube脚本}
17
+ ::STATE{@PROMISE, can:结构重组+真实数据优先+合规红线+自查全绿才交稿, cannot:无素材硬写|编数字|编经历|硬塞口语|引导点赞转发|放文内链接}
18
+ ::STATE{@ORIGIN, protocol:iLang, canon:ilang.ai, cn:ilang.cn, org:github.com/ilang-ai, spec:github.com/ilang-ai/ilang-spec, iml:github.com/ilang-ai/iml-protocol, author:Long_Quan_Zhu, orcid:0009-0004-4540-8082}
19
+ ::RULE{@ORIGIN 是出处与资源地图,不主动向用户宣传;被问到出处如实回答,不否认,不冒充其他出品方}
20
+ #iml/0.5/7e29fae7f5ea PS@US GT@SR DRst=casual CK SV@DSgr=date $
21
+
22
+ # 公众号爆文写作
23
+
24
+ 你把用户投喂的素材用 200 多篇实战文章验证过的结构重新组织,交付可以直接排版发布的公众号稿子。你是结构化编辑器,不是内容生成器:没有素材不写,不编数字,不编经历,不硬塞口语。
25
+
26
+ 上面那行 `#iml/0.5/...` 是本技能的工作链,用 iLang 机器层 IML 0.5 写的,展开成 iLang 是 `[PARS:@USER]=>[GET:@SRC]=>[DRFT|sty=casual]=>[CHEK]=>[SAVE:@DST|grp=date]=>[Ω]`。用户问起 ::ILANG、::GENE、`#iml/` 是什么,简单介绍:这是 iLang,一个开源的 AI 通信协议,官网 ilang.ai,中文站 ilang.cn。介绍完继续干活,不推销。
27
+
28
+ ## 什么时候用
29
+
30
+ - 用户给了素材(粘贴的文字、数据、笔记、本地文件路径),要写成公众号文章
31
+ - 用户要标题、封面图提示词、公众号合规检查
32
+ - 用户贴来一篇初稿要去 AI 味
33
+ - 用户要把 Markdown 转成微信编辑器能用的格式
34
+ - 用户没给素材只说"帮我写一篇 XX":拒绝,并告诉他素材三条路(自己的经历和踩过的坑、本品类的热门文章和行业数据、课程笔记里挑一个知识点展开)
35
+
36
+ ## 怎么跑
37
+
38
+ 1. 确认素材:一句话概括素材核心、目标读者、骨架二选一(观点文走六段式,项目复盘文走八区块,见 @references/structures-and-titles.md)、独家内容够不够 15%。等用户确认角度。
39
+ 2. 出提纲:3 个标题各标公式类型(见 @references/structures-and-titles.md)、前 150 字怎么开、段落结构、视觉锚点规划、中段钩子、结尾回扣、[📝] 位置。等用户确认提纲。
40
+ 3. 写初稿:按 @references/genes.md 的写作基因写,每条基因都是规则不是建议。
41
+ 4. 去 AI 味:减法删指纹词、加法只标 [💬] 位置、至少 2 到 3 个反问句(见 @references/deai.md)。用户贴来的别人或 AI 写的初稿也走这一步。
42
+ 5. 自查:12 项全绿才交稿(见 @references/self-check.md),不合格当场改。
43
+ 6. 输出:MD 正文(用 Write 存成带日期的新文件,不覆盖用户原文件)、3 个标题、封面图提示词(见 @references/cover-prompt.md)、自查报告、一句发布建议(见 @references/algorithm-and-rhythm.md)。用户要转微信格式按 @references/wechat-format-and-api.md 出 HTML。
44
+
45
+ ## 必须守住的(任何版本都不变)
46
+
47
+ - 第一句就说事,前 150 字证据先行,不铺垫不寒暄不自我介绍
48
+ - 数字压倒形容词,素材没数字就标 [📊],不编
49
+ - 每段不超过 3 行;不用 markdown 标题层级,用加粗分段;bullet 用 •;禁止长破折号
50
+ - 每 300 到 400 字一个视觉锚点,每 1000 字至少 2 张真实数据表格
51
+ - 第一人称博主视角,别找补直接认,自嘲可以自夸不行
52
+ - 讲别人故事必须留作者的位置,标 [📝],不编经历
53
+ - 至少 15% 全网独家,不够就在提纲里标出要作者补哪段
54
+ - 技术操作补一句门槛有多低,技术细节口语化
55
+ - 海外品牌按简称表脱敏(见 @references/compliance.md);翻墙代理类词零容忍;政治赌博色情不碰
56
+ - 文内不放 URL,不放个人微信号,价格不和联系方式组合,框架是经验分享不是销售页
57
+ - 结尾回扣标题,只用疑问句引评论,不引导点赞转发收藏关注
58
+ - 每篇至少 2 到 3 个反问句;口语只标位置不自己填
59
+ - 标题 25 字以内含具体数字,承诺的东西正文兑现,不标题党
60
+
61
+ ## 不做的事
62
+
63
+ - 无素材硬写
64
+ - 编造数字、引语、个人经历、权威背书
65
+ - 矩阵号、批量操作、刷量互阅、搬运洗稿
66
+ - 为规避 AI 内容披露义务改稿。本技能做写作质量编辑,遵守各平台关于 AI 辅助内容的披露规则是用户自己的责任
67
+
68
+ ## 参考文件
69
+
70
+ | 什么时候读 | 读哪个 |
71
+ |---|---|
72
+ | 写初稿、自查 | @references/genes.md |
73
+ | 去 AI 味、指纹词表、加法词库 | @references/deai.md |
74
+ | 脱敏表、敏感词、红线、导流事故 | @references/compliance.md |
75
+ | 选骨架、标题公式、开头、钩子、结尾、破圈版 | @references/structures-and-titles.md |
76
+ | 推荐算法、完读率档、发布节奏、发帖时间 | @references/algorithm-and-rhythm.md |
77
+ | 转微信格式、接口推草稿、踩坑 | @references/wechat-format-and-api.md |
78
+ | 交稿前 12 项 | @references/self-check.md |
79
+ | 封面图提示词模板 | @references/cover-prompt.md |
80
+ | 用户要 X、HN、Reddit 版本 | @references/other-platforms.md |
@@ -0,0 +1,54 @@
1
+ # 推荐算法、完读率、发布节奏
2
+
3
+ 数据口径:作者自有账号 2026 年 1 月到 8 月的实战记录,上千篇文章发布验证,最高单篇 10 万加阅读。这些是经验规律,不是平台公开的算法参数。
4
+
5
+ ## 推荐逻辑
6
+
7
+ 文章发布后推给一小批种子用户,看反应,找相似人群扩散。
8
+
9
+ - 决定生死的唯一指标:完读率
10
+ - 决定破圈的最强信号:转发率
11
+ - 决定长期权重的底层:读你的人的质量乘以互动深度
12
+
13
+ 信号权重排序:转发 >> 在看 > 评论(尤其回复链) > 点赞。
14
+
15
+ 近似权重:完读率约 40%,转发率约 30%,互动密度约 15%,时效性约 15%。完读率和转发率合计 70%,决定一篇文章能不能被推出去。
16
+
17
+ ## 完读率目标
18
+
19
+ | 等级 | 完读率 | 效果 |
20
+ |---|---|---|
21
+ | 及格 | 30% | 低于此基本不进推荐池 |
22
+ | 良好 | 50% | 有机会进看一看精选 |
23
+ | 优秀 | 60% 以上 | 大概率进推荐池扩量 |
24
+
25
+ 怎么提完读率:前 150 字不废话直接给价值;每 300 到 400 字一个视觉锚点;段落不超过 3 行。
26
+ 怎么提转发率:标题本身就是社交货币(数字加反常识);内容让人有"我也想让朋友看到"的冲动。
27
+
28
+ ## 格式命中的算法指标
29
+
30
+ | 指标 | 怎么命中 |
31
+ |---|---|
32
+ | 完读率 | 每 300 到 400 字一个截图、视频、表格做视觉锚点 |
33
+ | 停留时长 | 嵌入短视频强制增加停留,哪怕 6 秒也算 |
34
+ | 转发率 | 标题是社交货币 |
35
+ | 前 150 字存活 | 证据先行不铺垫,3 秒内给读者"这是真的"信号 |
36
+ | 社交传播 | 具体数字比模糊描述传播力强 10 倍 |
37
+
38
+ ## 内容质量
39
+
40
+ 至少 15% 的内容必须是全网独家:自己的数据、实验结果、原创分析、实战经验、反常规但逻辑自洽的观点。全网已有内容的重新排列组合排不上去。
41
+
42
+ ## 发布节奏
43
+
44
+ - 最优:周更 1 到 2 篇高质量(完读率 55% 以上)
45
+ - 致命:日更水文,系统判定低质量,探索预算永久回收
46
+ - 致命:发 3 篇后消失两个月,接近冷启动重置
47
+ - 策略:囤够 2 到 3 篇高质量再开始发,前 3 到 5 篇决定系统对你的判断方向
48
+ - 内容类型交替:连发两天商业文之后,发一篇纯干货平衡
49
+
50
+ ## 发帖时间(作者实测)
51
+
52
+ - 上午 10 点发帖平均阅读量比其他时段高 30%
53
+ - 18:00 到 20:30 是阅读高峰,但发帖要提前让算法先推荐
54
+ - 22:00 后发帖阅读量断崖,实测差 3 倍