Character Count
Use this skill when text must fit within a strict character limit and guessing is not acceptable.
This skill is portable and self-contained. The counting logic lives in the bundled script at scripts/character_count.py.
Scope
This skill measures exact string length as seen by Python len(text).
- - It is suitable for generic hard-limit workflows.
- It is not a platform-specific compliance engine.
- If a platform applies custom weighting rules for URLs, Unicode, or special tokens, treat this skill as a deterministic local gate, not as a guarantee of platform acceptance.
Rules
- - Never estimate character counts manually.
- Always count the final text exactly as it will be posted or saved.
- If the text is too long, rewrite it and count again.
- Prefer the JSON output mode for deterministic downstream use.
- Do not describe the result as platform-accurate unless the target platform uses plain string length.
Recommended Usage
The bundled script requires python3. For broad portability, assume Python 3.8 or newer.
From the skill root, pass the exact final text over stdin so shell quoting does not alter the content:
CODEBLOCK0
If you are calling it from another working directory, use the full path to the script inside the installed skill folder.
If stdin is inconvenient, pass the text as an argument:
CODEBLOCK1
Output Contract
INLINECODE3 returns a single JSON object:
CODEBLOCK2
Field meanings:
- -
chars: exact Python string length of the provided text - INLINECODE5 : the configured limit
- INLINECODE6 : INLINECODE7
- INLINECODE8 :
true when INLINECODE10
Without --json, the script prints plain text key-value lines:
CODEBLOCK3
Twitter and X Workflow
For tweets and replies:
- 1. Draft the final post text.
- Count it with
--limit 280. - If
ok is false, shorten the text. - Count again.
- Post only after the script reports
ok=true. - If you need exact X enforcement, add a platform-specific validation step in addition to this skill.
Notes
- - Count the exact final text, including spaces, punctuation, hashtags, and URLs.
- Do not add or remove characters after counting unless you count again.
- Use
printf '%s' instead of echo to avoid introducing a trailing newline. - If the script receives no text, treat that as a calling error and fix the invocation before proceeding.
字符计数
当文本必须符合严格的字符限制且不允许猜测时,使用此技能。
此技能可移植且独立运行。计数逻辑位于捆绑脚本 scripts/character_count.py 中。
范围
此技能测量 Python len(text) 所见的精确字符串长度。
- - 适用于通用硬限制工作流程。
- 不是特定于平台的合规引擎。
- 如果平台对 URL、Unicode 或特殊标记应用自定义加权规则,请将此技能视为确定性的本地门控,而非平台接受的保证。
规则
- - 切勿手动估算字符数。
- 始终精确计算最终文本的字符数,如同将要发布或保存时一样。
- 如果文本过长,请重写并重新计数。
- 优先使用 JSON 输出模式以实现确定性的下游使用。
- 除非目标平台使用纯字符串长度,否则不要将结果描述为平台精确。
推荐用法
捆绑脚本需要 python3。为广泛可移植性,假设使用 Python 3.8 或更高版本。
从技能根目录,通过标准输入传递精确的最终文本,以便 shell 引用不会改变内容:
bash
printf %s $FINALTEXT | python3 scripts/charactercount.py --limit 280 --json
如果从其他工作目录调用,请使用已安装技能文件夹内脚本的完整路径。
如果标准输入不方便,可将文本作为参数传递:
bash
python3 scripts/character_count.py --limit 280 --json --text Hello world
输出约定
--json 返回单个 JSON 对象:
json
{chars:11,limit:280,remaining:269,ok:true}
字段含义:
- - chars:提供文本的精确 Python 字符串长度
- limit:配置的限制
- remaining:limit - chars
- ok:当 chars <= limit 时为 true
不使用 --json 时,脚本以纯文本键值行形式输出:
text
chars=11
limit=280
remaining=269
ok=true
Twitter 和 X 工作流程
对于推文和回复:
- 1. 起草最终发布文本。
- 使用 --limit 280 进行计数。
- 如果 ok 为 false,缩短文本。
- 重新计数。
- 仅在脚本报告 ok=true 后发布。
- 如果需要精确的 X 强制执行,请在此技能之外添加特定于平台的验证步骤。
注意事项
- - 计算精确的最终文本,包括空格、标点、话题标签和 URL。
- 计数后不要添加或删除字符,除非重新计数。
- 使用 printf %s 而非 echo,以避免引入尾随换行符。
- 如果脚本未收到文本,请将其视为调用错误,并在继续之前修复调用。