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/wechat-extend-config.ts

View on GitHub
import fs from "node:fs";
import path from "node:path";
import os from "node:os";

export interface WechatAccount {
  name: string;
  alias: string;
  default?: boolean;
  default_publish_method?: string;
  default_author?: string;
  need_open_comment?: number;
  only_fans_can_comment?: number;
  app_id?: string;
  app_secret?: string;
  chrome_profile_path?: string;
}

export interface WechatExtendConfig {
  default_theme?: string;
  default_color?: string;
  default_publish_method?: string;
  default_author?: string;
  need_open_comment?: number;
  only_fans_can_comment?: number;
  chrome_profile_path?: string;
  accounts?: WechatAccount[];
}

export interface ResolvedAccount {
  name?: string;
  alias?: string;
  default_publish_method?: string;
  default_author?: string;
  need_open_comment: number;
  only_fans_can_comment: number;
  app_id?: string;
  app_secret?: string;
  chrome_profile_path?: string;
}

function stripQuotes(s: string): string {
  return s.replace(/^['"]|['"]$/g, "");
}

function toBool01(v: string): number {
  return v === "1" || v === "true" ? 1 : 0;
}

function parseWechatExtend(content: string): WechatExtendConfig {
  const config: WechatExtendConfig = {};
  const lines = content.split("\n");
  let inAccounts = false;
  let current: Record<string, string> | null = null;
  const rawAccounts: Record<string, string>[] = [];

  for (const raw of lines) {
    const trimmed = raw.trim();
    if (!trimmed || trimmed.startsWith("#")) continue;

    if (trimmed === "accounts:") {
      inAccounts = true;
      continue;
    }

    if (inAccounts) {
      const listMatch = raw.match(/^\s+-\s+(.+)$/);
      if (listMatch) {
        if (current) rawAccounts.push(current);
        current = {};
        const kv = listMatch[1]!;
        const ci = kv.indexOf(":");
        if (ci > 0) {
          current[kv.slice(0, ci).trim()] = stripQuotes(kv.slice(ci + 1).trim());
        }
        continue;
      }

      if (current && /^\s{2,}/.test(raw) && !trimmed.startsWith("-")) {
        const ci = trimmed.indexOf(":");
        if (ci > 0) {
          current[trimmed.slice(0, ci).trim()] = stripQuotes(trimmed.slice(ci + 1).trim());
        }
        continue;
      }

      if (!/^\s/.test(raw)) {
        if (current) rawAccounts.push(current);
        current = null;
        inAccounts = false;
      } else {
        continue;
      }
    }

    const ci = trimmed.indexOf(":");
    if (ci < 0) continue;
    const key = trimmed.slice(0, ci).trim();
    const val = stripQuotes(trimmed.slice(ci + 1).trim());
    if (val === "null" || val === "") continue;

    switch (key) {
      case "default_theme": config.default_theme = val; break;
      case "default_color": config.default_color = val; break;
      case "default_publish_method": config.default_publish_method = val; break;
      case "default_author": config.default_author = val; break;
      case "need_open_comment": config.need_open_comment = toBool01(val); break;
      case "only_fans_can_comment": config.only_fans_can_comment = toBool01(val); break;
      case "chrome_profile_path": config.chrome_profile_path = val; break;
    }
  }

  if (current) rawAccounts.push(current);

  if (rawAccounts.length > 0) {
    config.accounts = rawAccounts.map(a => ({
      name: a.name || "",
      alias: a.alias || "",
      default: a.default === "true" || a.default === "1",
      default_publish_method: a.default_publish_method || undefined,
      default_author: a.default_author || undefined,
      need_open_comment: a.need_open_comment ? toBool01(a.need_open_comment) : undefined,
      only_fans_can_comment: a.only_fans_can_comment ? toBool01(a.only_fans_can_comment) : undefined,
      app_id: a.app_id || undefined,
      app_secret: a.app_secret || undefined,
      chrome_profile_path: a.chrome_profile_path || undefined,
    }));
  }

  return config;
}

export function loadWechatExtendConfig(): WechatExtendConfig {
  const paths = [
    path.join(process.cwd(), ".baoyu-skills", "baoyu-post-to-wechat", "EXTEND.md"),
    path.join(
      process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"),
      "baoyu-skills", "baoyu-post-to-wechat", "EXTEND.md"
    ),
    path.join(os.homedir(), ".baoyu-skills", "baoyu-post-to-wechat", "EXTEND.md"),
  ];
  for (const p of paths) {
    try {
      const content = fs.readFileSync(p, "utf-8");
      return parseWechatExtend(content);
    } catch {
      continue;
    }
  }
  return {};
}

function selectAccount(config: WechatExtendConfig, alias?: string): WechatAccount | undefined {
  if (!config.accounts || config.accounts.length === 0) return undefined;
  if (alias) return config.accounts.find(a => a.alias === alias);
  if (config.accounts.length === 1) return config.accounts[0];
  return config.accounts.find(a => a.default);
}

export function resolveAccount(config: WechatExtendConfig, alias?: string): ResolvedAccount {
  const acct = selectAccount(config, alias);
  return {
    name: acct?.name,
    alias: acct?.alias,
    default_publish_method: acct?.default_publish_method ?? config.default_publish_method,
    default_author: acct?.default_author ?? config.default_author,
    need_open_comment: acct?.need_open_comment ?? config.need_open_comment ?? 1,
    only_fans_can_comment: acct?.only_fans_can_comment ?? config.only_fans_can_comment ?? 0,
    app_id: acct?.app_id,
    app_secret: acct?.app_secret,
    chrome_profile_path: acct?.chrome_profile_path ?? config.chrome_profile_path,
  };
}

function loadEnvFile(envPath: string): Record<string, string> {
  const env: Record<string, string> = {};
  if (!fs.existsSync(envPath)) return env;
  const content = fs.readFileSync(envPath, "utf-8");
  for (const line of content.split("\n")) {
    const trimmed = line.trim();
    if (!trimmed || trimmed.startsWith("#")) continue;
    const eqIdx = trimmed.indexOf("=");
    if (eqIdx > 0) {
      const key = trimmed.slice(0, eqIdx).trim();
      let value = trimmed.slice(eqIdx + 1).trim();
      if ((value.startsWith('"') && value.endsWith('"')) ||
          (value.startsWith("'") && value.endsWith("'"))) {
        value = value.slice(1, -1);
      }
      env[key] = value;
    }
  }
  return env;
}

function aliasToEnvKey(alias: string): string {
  return alias.toUpperCase().replace(/-/g, "_");
}

interface CredentialSource {
  name: string;
  appIdKey: string;
  appSecretKey: string;
  appId?: string;
  appSecret?: string;
}

export interface LoadedCredentials {
  appId: string;
  appSecret: string;
  source: string;
  skippedSources: string[];
}

function normalizeCredentialValue(value?: string): string | undefined {
  const trimmed = value?.trim();
  return trimmed ? trimmed : undefined;
}

function describeMissingKeys(source: CredentialSource): string {
  const missingKeys: string[] = [];
  if (!source.appId) missingKeys.push(source.appIdKey);
  if (!source.appSecret) missingKeys.push(source.appSecretKey);
  return `${source.name} missing ${missingKeys.join(" and ")}`;
}

function buildCredentialSource(
  name: string,
  values: Record<string, string | undefined>,
  appIdKey: string,
  appSecretKey: string,
): CredentialSource {
  return {
    name,
    appIdKey,
    appSecretKey,
    appId: normalizeCredentialValue(values[appIdKey]),
    appSecret: normalizeCredentialValue(values[appSecretKey]),
  };
}

function resolveCredentialSource(
  sources: CredentialSource[],
  account?: ResolvedAccount,
): LoadedCredentials {
  const skippedSources: string[] = [];

  for (const source of sources) {
    if (source.appId && source.appSecret) {
      return {
        appId: source.appId,
        appSecret: source.appSecret,
        source: source.name,
        skippedSources,
      };
    }

    if (source.appId || source.appSecret) {
      skippedSources.push(describeMissingKeys(source));
    }
  }

  const hint = account?.alias ? ` (account: ${account.alias})` : "";
  const partialHint = skippedSources.length > 0
    ? `\nIncomplete credential sources skipped:\n- ${skippedSources.join("\n- ")}`
    : "";

  throw new Error(
    `Missing WECHAT_APP_ID or WECHAT_APP_SECRET${hint}.\n` +
    "Set via EXTEND.md account config, environment variables, or .baoyu-skills/.env file." +
    partialHint
  );
}

export function loadCredentials(account?: ResolvedAccount): LoadedCredentials {
  const cwdEnvPath = path.join(process.cwd(), ".baoyu-skills", ".env");
  const homeEnvPath = path.join(os.homedir(), ".baoyu-skills", ".env");
  const cwdEnv = loadEnvFile(cwdEnvPath);
  const homeEnv = loadEnvFile(homeEnvPath);

  const sources: CredentialSource[] = [];

  if (account?.app_id || account?.app_secret) {
    sources.push({
      name: account.alias ? `EXTEND.md account "${account.alias}"` : "EXTEND.md account config",
      appIdKey: "app_id",
      appSecretKey: "app_secret",
      appId: normalizeCredentialValue(account.app_id),
      appSecret: normalizeCredentialValue(account.app_secret),
    });
  }

  const prefix = account?.alias ? `WECHAT_${aliasToEnvKey(account.alias)}_` : "";
  if (prefix) {
    const prefixedKeyLabel = `${prefix}APP_ID/${prefix}APP_SECRET`;
    sources.push(
      buildCredentialSource(`process.env (${prefixedKeyLabel})`, process.env, `${prefix}APP_ID`, `${prefix}APP_SECRET`),
      buildCredentialSource(`<cwd>/.baoyu-skills/.env (${prefixedKeyLabel})`, cwdEnv, `${prefix}APP_ID`, `${prefix}APP_SECRET`),
      buildCredentialSource(`~/.baoyu-skills/.env (${prefixedKeyLabel})`, homeEnv, `${prefix}APP_ID`, `${prefix}APP_SECRET`),
    );
  }

  sources.push(
    buildCredentialSource("process.env", process.env, "WECHAT_APP_ID", "WECHAT_APP_SECRET"),
    buildCredentialSource("<cwd>/.baoyu-skills/.env", cwdEnv, "WECHAT_APP_ID", "WECHAT_APP_SECRET"),
    buildCredentialSource("~/.baoyu-skills/.env", homeEnv, "WECHAT_APP_ID", "WECHAT_APP_SECRET"),
  );

  return resolveCredentialSource(sources, account);
}

export function listAccounts(config: WechatExtendConfig): string[] {
  return (config.accounts || []).map(a => a.alias);
}
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