Skip to content

chang-zy/xiaohongshu-skill

xiaohongshu-skills

Verified

小红书(RedNote / Xiaohongshu / XHS / RED / Little Red Book)浏览器自动化技能集合。 支持认证登录、内容发布、搜索发现、账号与评论分析、社交互动和复合运营。 当用户提到小红书、红书、RedNote、Xiaohongshu、XHS、RED、Little Red Book, 或要求发笔记、搜笔记、分析博主、评论、登录、点赞、收藏时触发。

scripts/title_utils.py

View on GitHub
"""UTF-16 标题长度计算,对应 Go pkg/xhsutil/title.go。"""

from __future__ import annotations

MAX_TITLE_LENGTH = 20


def truncate_title(s: str, max_length: int = MAX_TITLE_LENGTH) -> str:
    """将标题裁剪到 max_length 以内(逐字符从末尾去除)。

    Args:
        s: 原始标题。
        max_length: 最大允许长度(默认 20)。

    Returns:
        满足长度要求的标题字符串。
    """
    if calc_title_length(s) <= max_length:
        return s
    while s and calc_title_length(s) > max_length:
        s = s[:-1]
    return s


def calc_title_length(s: str) -> int:
    """计算小红书标题长度。

    规则(同 Go CalcTitleLength):
    - 非 ASCII 字符(中文、全角符号、emoji 代码单元等)算 2
    - ASCII 字符算 1
    - 最终结果向上取整除以 2,上限 MAX_TITLE_LENGTH = 20

    Emoji 按 UTF-16 码元计数:
    - 基础 emoji(如 ✨ U+2728, BMP)= 1 码元 → 权重 2 → 贡献 1
    - SMP emoji(如 💇 U+1F487,surrogate pair)= 2 码元 → 权重 4 → 贡献 2
    - ZWJ 序列(如 💇‍♀️)= 5 码元 → 权重 10 → 贡献 5
    - 旗帜(如 🇨🇳,2 个 regional indicator)= 4 码元 → 权重 8 → 贡献 4

    Examples:
        >>> calc_title_length("你好世界")
        4
        >>> calc_title_length("hello")
        3
        >>> calc_title_length("OOTD穿搭分享")
        6
        >>> calc_title_length("💇\u200d♀️")
        5
    """
    byte_len = 0
    encoded = s.encode("utf-16-le")
    for i in range(0, len(encoded), 2):
        code_unit = int.from_bytes(encoded[i : i + 2], "little")
        if code_unit > 127:
            byte_len += 2
        else:
            byte_len += 1
    return (byte_len + 1) // 2
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 323kUpdated Claude CodeCodexVerifiedInstall