Skip to content

LeoYeAI/agent-master-skills / skills/baoyu-post-to-wechat

baoyu-post-to-wechat

Flagged

Posts content to WeChat Official Account (微信公众号) via API or Chrome CDP. Supports article posting (文章) with HTML, markdown, or plain text input, and image-text posting (贴图, formerly 图文) with multiple images. Markdown article workflows default to converting ordinary external links into bottom citations for WeChat-friendly output. Use when user mentions "发布公众号", "post to wechat", "微信公众号", or "贴图/图文/文章".

FileKindSize
SKILL.mdskill md19.7 KB
_meta.jsonconfig826 B
references/article-posting.mdmarkdown2.5 KB
references/config/first-time-setup.mdmarkdown5.2 KB
references/image-text-posting.mdmarkdown2.8 KB
scripts/bun.lockother38.7 KB
scripts/cdp.tsscript8.2 KB
scripts/check-permissions.tsscript8.6 KB
scripts/copy-to-clipboard.tsscript11.9 KB
scripts/md-to-wechat.tsscript4.7 KB
scripts/md/LICENSEother650 B
scripts/md/cli.tsscript5.7 KB
scripts/md/code-themes/1c-light.min.cssother1.1 KB
scripts/md/code-themes/a11y-dark.min.cssother1.1 KB
scripts/md/code-themes/a11y-light.min.cssother1.1 KB
scripts/md/code-themes/agate.min.cssother1.3 KB
scripts/md/code-themes/an-old-hope.min.cssother961 B
scripts/md/code-themes/androidstudio.min.cssother611 B
scripts/md/code-themes/arduino-light.min.cssother844 B
scripts/md/code-themes/arta.min.cssother673 B
scripts/md/code-themes/ascetic.min.cssother454 B
scripts/md/code-themes/atom-one-dark-reasonable.min.cssother1.2 KB
scripts/md/code-themes/atom-one-dark.min.cssother856 B
scripts/md/code-themes/atom-one-light.min.cssother856 B
scripts/md/code-themes/brown-paper.min.cssother656 B
scripts/md/code-themes/codepen-embed.min.cssother600 B
scripts/md/code-themes/color-brewer.min.cssother631 B
scripts/md/code-themes/dark.min.cssother625 B
scripts/md/code-themes/default.min.cssother1.1 KB
scripts/md/code-themes/devibeans.min.cssother1.1 KB
scripts/md/code-themes/docco.min.cssother837 B
scripts/md/code-themes/far.min.cssother669 B
scripts/md/code-themes/felipec.min.cssother1.2 KB
scripts/md/code-themes/foundation.min.cssother779 B
scripts/md/code-themes/github-dark-dimmed.min.cssother1.2 KB
scripts/md/code-themes/github-dark.min.cssother1.3 KB
scripts/md/code-themes/github.min.cssother1.3 KB
scripts/md/code-themes/gml.min.cssother787 B
scripts/md/code-themes/googlecode.min.cssother835 B
scripts/md/code-themes/gradient-dark.min.cssother1.1 KB
scripts/md/code-themes/gradient-light.min.cssother1.1 KB
scripts/md/code-themes/grayscale.min.cssother1.6 KB
scripts/md/code-themes/hybrid.min.cssother897 B
scripts/md/code-themes/idea.min.cssother906 B
scripts/md/code-themes/intellij-light.min.cssother1.0 KB
scripts/md/code-themes/ir-black.min.cssother694 B
scripts/md/code-themes/isbl-editor-dark.min.cssother971 B
scripts/md/code-themes/isbl-editor-light.min.cssother952 B
scripts/md/code-themes/kimbie-dark.min.cssother652 B
scripts/md/code-themes/kimbie-light.min.cssother652 B
scripts/md/code-themes/lightfair.min.cssother831 B
scripts/md/code-themes/lioshi.min.cssother715 B
scripts/md/code-themes/magula.min.cssother642 B
scripts/md/code-themes/mono-blue.min.cssother631 B
scripts/md/code-themes/monokai-sublime.min.cssother826 B
scripts/md/code-themes/monokai.min.cssother814 B
scripts/md/code-themes/night-owl.min.cssother1.4 KB
scripts/md/code-themes/nnfx-dark.min.cssother1.4 KB
scripts/md/code-themes/nnfx-light.min.cssother1.4 KB
scripts/md/code-themes/nord.min.cssother2.6 KB
scripts/md/code-themes/obsidian.min.cssother882 B
scripts/md/code-themes/panda-syntax-dark.min.cssother1.1 KB
scripts/md/code-themes/panda-syntax-light.min.cssother1.0 KB
scripts/md/code-themes/paraiso-dark.min.cssother637 B
scripts/md/code-themes/paraiso-light.min.cssother637 B
scripts/md/code-themes/pojoaque.min.cssother814 B
scripts/md/code-themes/purebasic.min.cssother734 B
scripts/md/code-themes/qtcreator-dark.min.cssother815 B
scripts/md/code-themes/qtcreator-light.min.cssother810 B
scripts/md/code-themes/rainbow.min.cssother826 B
scripts/md/code-themes/routeros.min.cssother862 B
scripts/md/code-themes/school-book.min.cssother664 B
scripts/md/code-themes/shades-of-purple.min.cssother854 B
scripts/md/code-themes/srcery.min.cssother795 B
scripts/md/code-themes/stackoverflow-dark.min.cssother1.2 KB
scripts/md/code-themes/stackoverflow-light.min.cssother1.3 KB
scripts/md/code-themes/sunburst.min.cssother950 B
scripts/md/code-themes/tokyo-night-dark.min.cssother1.2 KB
scripts/md/code-themes/tokyo-night-light.min.cssother1.2 KB
scripts/md/code-themes/tomorrow-night-blue.min.cssother648 B
scripts/md/code-themes/tomorrow-night-bright.min.cssother648 B
scripts/md/code-themes/vs.min.cssother640 B
scripts/md/code-themes/vs2015.min.cssother1.1 KB
scripts/md/code-themes/xcode.min.cssother945 B
scripts/md/code-themes/xt256.min.cssother765 B
scripts/md/constants.tsscript3.3 KB
scripts/md/extend-config.tsscript2.3 KB
scripts/md/extensions/alert.tsscript19.3 KB
scripts/md/extensions/footnotes.tsscript2.4 KB
scripts/md/extensions/index.tsscript280 B
scripts/md/extensions/infographic.tsscript3.6 KB
scripts/md/extensions/katex.tsscript4.6 KB
scripts/md/extensions/markup.tsscript2.3 KB
scripts/md/extensions/plantuml.tsscript8.1 KB
scripts/md/extensions/ruby.tsscript3.9 KB
scripts/md/extensions/slider.tsscript2.9 KB
scripts/md/extensions/toc.tsscript2.1 KB
scripts/md/html-builder.tsscript4.4 KB
scripts/md/package-lock.jsonmanifest50.2 KB
scripts/md/package.jsonmanifest321 B
scripts/md/render.tsscript3.8 KB
scripts/md/renderer.tsscript13.0 KB
scripts/md/themes.tsscript1.8 KB
scripts/md/themes/base.cssother816 B
scripts/md/themes/default.cssother7.7 KB
scripts/md/themes/grace.cssother2.5 KB
scripts/md/themes/modern.cssother8.2 KB
scripts/md/themes/simple.cssother2.7 KB
scripts/md/types.tsscript1.8 KB
scripts/md/utils/languages.tsscript8.1 KB
scripts/package.jsonmanifest261 B
scripts/paste-from-clipboard.tsscript5.5 KB
scripts/wechat-agent-browser.tsscript11.1 KB
scripts/wechat-api.tsscript25.3 KB
scripts/wechat-article.tsscript32.0 KB
scripts/wechat-browser.tsscript27.7 KB
scripts/wechat-extend-config.test.tsscript4.3 KB
scripts/wechat-extend-config.tsscript9.8 KB
scripts/wechat-image-processor.tsscript7.1 KB

scripts/check-permissions.ts

View on GitHub
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import process from 'node:process';
import { findChromeExecutable, getDefaultProfileDir } from './cdp.ts';

interface CheckResult {
  name: string;
  ok: boolean;
  detail: string;
}

const results: CheckResult[] = [];

function log(label: string, ok: boolean, detail: string): void {
  results.push({ name: label, ok, detail });
  const icon = ok ? '✅' : '❌';
  console.log(`${icon} ${label}: ${detail}`);
}

function warn(label: string, detail: string): void {
  results.push({ name: label, ok: true, detail });
  console.log(`⚠️  ${label}: ${detail}`);
}

async function checkChrome(): Promise<void> {
  const chromePath = findChromeExecutable();
  if (chromePath) {
    log('Chrome', true, chromePath);
  } else {
    log('Chrome', false, 'Not found. Set WECHAT_BROWSER_CHROME_PATH env var or install Chrome.');
  }
}

async function checkProfileIsolation(): Promise<void> {
  const profileDir = getDefaultProfileDir();
  const userChromeDir = process.platform === 'darwin'
    ? path.join(os.homedir(), 'Library', 'Application Support', 'Google', 'Chrome')
    : process.platform === 'win32'
      ? path.join(os.homedir(), 'AppData', 'Local', 'Google', 'Chrome', 'User Data')
      : path.join(os.homedir(), '.config', 'google-chrome');

  const isIsolated = !profileDir.startsWith(userChromeDir);
  log('Profile isolation', isIsolated, `Skill profile: ${profileDir}`);

  if (isIsolated) {
    const exists = fs.existsSync(profileDir);
    if (exists) {
      log('Profile dir', true, 'Exists and accessible');
    } else {
      try {
        fs.mkdirSync(profileDir, { recursive: true });
        log('Profile dir', true, 'Created successfully');
      } catch (e) {
        log('Profile dir', false, `Cannot create: ${e instanceof Error ? e.message : String(e)}`);
      }
    }
  }
}

async function checkAccessibility(): Promise<void> {
  if (process.platform !== 'darwin') {
    log('Accessibility', true, `Skipped (not macOS, platform: ${process.platform})`);
    return;
  }

  const result = spawnSync('osascript', ['-e', `
    tell application "System Events"
      set frontApp to name of first application process whose frontmost is true
      return frontApp
    end tell
  `], { stdio: 'pipe', timeout: 10_000 });

  if (result.status === 0) {
    const app = result.stdout?.toString().trim();
    log('Accessibility (System Events)', true, `Frontmost app: ${app}`);
  } else {
    const stderr = result.stderr?.toString().trim() || '';
    if (stderr.includes('not allowed assistive access') || stderr.includes('1002')) {
      log('Accessibility (System Events)', false,
        'Denied. Grant access: System Settings → Privacy & Security → Accessibility → enable your terminal app');
    } else {
      log('Accessibility (System Events)', false, `Failed: ${stderr}`);
    }
  }
}

async function checkClipboardCopy(): Promise<void> {
  if (process.platform !== 'darwin') {
    log('Clipboard copy (image)', true, `Skipped (not macOS)`);
    return;
  }

  const tmpDir = await mkdtemp(path.join(os.tmpdir(), 'wechat-check-'));
  try {
    const testPng = path.join(tmpDir, 'test.png');
    const swiftSrc = `import AppKit
import Foundation
let size = NSSize(width: 2, height: 2)
let image = NSImage(size: size)
image.lockFocus()
NSColor.red.set()
NSBezierPath.fill(NSRect(origin: .zero, size: size))
image.unlockFocus()
guard let tiff = image.tiffRepresentation,
      let rep = NSBitmapImageRep(data: tiff),
      let png = rep.representation(using: .png, properties: [:]) else {
  FileHandle.standardError.write("Failed to create test PNG\\n".data(using: .utf8)!)
  exit(1)
}
try png.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))
`;
    const genScript = path.join(tmpDir, 'gen.swift');
    await writeFile(genScript, swiftSrc, 'utf8');
    const genResult = spawnSync('swift', [genScript, testPng], { stdio: 'pipe', timeout: 30_000 });
    if (genResult.status !== 0) {
      log('Clipboard copy (image)', false, `Cannot create test image: ${genResult.stderr?.toString().trim()}`);
      return;
    }

    const clipSrc = `import AppKit
import Foundation
guard let image = NSImage(contentsOfFile: CommandLine.arguments[1]) else {
  FileHandle.standardError.write("Failed to load image\\n".data(using: .utf8)!)
  exit(1)
}
let pb = NSPasteboard.general
pb.clearContents()
if !pb.writeObjects([image]) {
  FileHandle.standardError.write("Failed to write to clipboard\\n".data(using: .utf8)!)
  exit(1)
}
`;
    const clipScript = path.join(tmpDir, 'clip.swift');
    await writeFile(clipScript, clipSrc, 'utf8');
    const clipResult = spawnSync('swift', [clipScript, testPng], { stdio: 'pipe', timeout: 30_000 });
    if (clipResult.status === 0) {
      log('Clipboard copy (image)', true, 'Can copy image to clipboard via Swift/AppKit');
    } else {
      log('Clipboard copy (image)', false, `Failed: ${clipResult.stderr?.toString().trim()}`);
    }
  } finally {
    await rm(tmpDir, { recursive: true, force: true });
  }
}

async function checkPasteKeystroke(): Promise<void> {
  if (process.platform === 'darwin') {
    const result = spawnSync('osascript', ['-e', `
      tell application "System Events"
        set canSend to true
        return canSend
      end tell
    `], { stdio: 'pipe', timeout: 10_000 });

    if (result.status === 0) {
      log('Paste keystroke (osascript)', true, 'System Events can send keystrokes');
    } else {
      const stderr = result.stderr?.toString().trim() || '';
      log('Paste keystroke (osascript)', false, `Cannot send keystrokes: ${stderr}`);
    }
  } else if (process.platform === 'linux') {
    const xdotool = spawnSync('which', ['xdotool'], { stdio: 'pipe' });
    const ydotool = spawnSync('which', ['ydotool'], { stdio: 'pipe' });
    if (xdotool.status === 0) {
      log('Paste keystroke', true, 'xdotool available (X11)');
    } else if (ydotool.status === 0) {
      log('Paste keystroke', true, 'ydotool available (Wayland)');
    } else {
      log('Paste keystroke', false, 'No tool found. Install xdotool (X11) or ydotool (Wayland).');
    }
  } else if (process.platform === 'win32') {
    log('Paste keystroke', true, 'Windows uses PowerShell SendKeys (built-in)');
  }
}

async function checkBun(): Promise<void> {
  const result = spawnSync('npx', ['-y', 'bun', '--version'], { stdio: 'pipe', timeout: 30_000 });
  if (result.status === 0) {
    log('Bun runtime', true, `v${result.stdout?.toString().trim()}`);
  } else {
    log('Bun runtime', false, 'Cannot run bun. Install: brew install oven-sh/bun/bun (macOS) or npm install -g bun');
  }
}

async function checkApiCredentials(): Promise<void> {
  const cwd = process.cwd();
  const projectEnv = path.join(cwd, '.baoyu-skills', '.env');
  const userEnv = path.join(os.homedir(), '.baoyu-skills', '.env');

  let found = false;
  for (const envPath of [projectEnv, userEnv]) {
    if (fs.existsSync(envPath)) {
      const content = fs.readFileSync(envPath, 'utf8');
      if (content.includes('WECHAT_APP_ID')) {
        log('API credentials', true, `Found in ${envPath}`);
        found = true;
        break;
      }
    }
  }

  if (!found) {
    warn('API credentials', 'Not found. Required for API publishing method. Run the skill to set up via guided flow.');
  }
}

async function checkRunningChromeConflict(): Promise<void> {
  if (process.platform !== 'darwin') return;

  const result = spawnSync('pgrep', ['-f', 'Google Chrome'], { stdio: 'pipe' });
  const pids = result.stdout?.toString().trim().split('\n').filter(Boolean) || [];

  if (pids.length > 0) {
    warn('Running Chrome instances', `${pids.length} Chrome process(es) detected. The skill uses --user-data-dir for isolation, so this is safe.`);
  } else {
    log('Running Chrome instances', true, 'No existing Chrome processes');
  }
}

async function main(): Promise<void> {
  console.log('=== baoyu-post-to-wechat: Permission & Environment Check ===\n');

  await checkChrome();
  await checkProfileIsolation();
  await checkBun();
  await checkAccessibility();
  await checkClipboardCopy();
  await checkPasteKeystroke();
  await checkApiCredentials();
  await checkRunningChromeConflict();

  console.log('\n--- Summary ---');
  const failed = results.filter((r) => !r.ok);
  if (failed.length === 0) {
    console.log('All checks passed. Ready to post to WeChat.');
  } else {
    console.log(`${failed.length} issue(s) found:`);
    for (const f of failed) {
      console.log(`  ❌ ${f.name}: ${f.detail}`);
    }
    process.exit(1);
  }
}

await main().catch((err) => {
  console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
  process.exit(1);
});
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall