Skip to content

topmindspace/topmind-writing-skills / topmind-x-article

topmind-x-article

Verified

创作或整理 X Article 深度长文,支持论点推进、工具/插件介绍、产品实测评测与多源研究;按需导出可复制 HTML、纯文本、封面与发布清单。普通短帖用 topmind-briefs 或 topmind-viral-posts,纯格式化用 topmind-format。

FileKindSize
.gitignoreother31 B
README.en.mdmarkdown1.7 KB
README.mdmarkdown2.0 KB
SKILL.mdskill md4.6 KB
examples/01-长文-慢慢写.mdmarkdown1.8 KB
examples/02-长文-周末短途.mdmarkdown1.4 KB
examples/README.mdmarkdown716 B
knowledge/README.mdmarkdown9.4 KB
knowledge/cards/atlas-local-fix.mdmarkdown781 B
knowledge/cards/brief-news-to-post.mdmarkdown3.0 KB
knowledge/cards/brief-news.mdmarkdown916 B
knowledge/cards/brief-paper.mdmarkdown760 B
knowledge/cards/brief-tools.mdmarkdown617 B
knowledge/cards/brief-value-first.mdmarkdown3.1 KB
knowledge/cards/cover-abstract.mdmarkdown1.3 KB
knowledge/cards/cover-brief.mdmarkdown1.3 KB
knowledge/cards/cover-collage.mdmarkdown1.3 KB
knowledge/cards/cover-color.mdmarkdown1.2 KB
knowledge/cards/cover-culture.mdmarkdown1013 B
knowledge/cards/cover-editorial.mdmarkdown1.2 KB
knowledge/cards/cover-material.mdmarkdown1.3 KB
knowledge/cards/cover-photo.mdmarkdown1.1 KB
knowledge/cards/cover-playful.mdmarkdown1.0 KB
knowledge/cards/cover-scene.mdmarkdown962 B
knowledge/cards/cover-series.mdmarkdown1017 B
knowledge/cards/cover-typography.mdmarkdown1.3 KB
knowledge/cards/creative-choice.mdmarkdown807 B
knowledge/cards/crop-independent.mdmarkdown719 B
knowledge/cards/de-ai-mechanisms.mdmarkdown3.6 KB
knowledge/cards/experience-loop.mdmarkdown801 B
knowledge/cards/format-fidelity.mdmarkdown501 B
knowledge/cards/format-layouts.mdmarkdown502 B
knowledge/cards/poster-paging.mdmarkdown726 B
knowledge/cards/poster-structure.mdmarkdown646 B
knowledge/cards/poster-voices.mdmarkdown530 B
knowledge/cards/reference-reading.mdmarkdown857 B
knowledge/cards/revise-depth.mdmarkdown677 B
knowledge/cards/revise-feedback.mdmarkdown609 B
knowledge/cards/revise-learn-from-edits.mdmarkdown3.1 KB
knowledge/cards/revise-preserve.mdmarkdown788 B
knowledge/cards/viral-mechanisms.mdmarkdown535 B
knowledge/cards/viral-observation.mdmarkdown544 B
knowledge/cards/viral-play-dumb.mdmarkdown2.8 KB
knowledge/cards/viral-replies.mdmarkdown722 B
knowledge/cards/visual-density-and-evidence.mdmarkdown2.8 KB
knowledge/cards/voice-peer-stance.mdmarkdown2.7 KB
knowledge/cards/wechat-decide.mdmarkdown746 B
knowledge/cards/wechat-explain.mdmarkdown820 B
knowledge/cards/wechat-plugin-and-review.mdmarkdown2.5 KB
knowledge/cards/wechat-story.mdmarkdown798 B
knowledge/cards/x-adapt.mdmarkdown643 B
knowledge/cards/x-argument.mdmarkdown770 B
knowledge/cards/x-evidence.mdmarkdown608 B
knowledge/index.jsonconfig39.9 KB
package.jsonmanifest445 B
references/core-voice.mdmarkdown9.9 KB
references/creative-practice.mdmarkdown5.0 KB
references/de-ai-rules.mdmarkdown17.9 KB
references/image-sourcing.mdmarkdown2.7 KB
references/information-design.mdmarkdown5.0 KB
references/knowledge-library.mdmarkdown5.5 KB
references/platform-cover-specs.mdmarkdown7.4 KB
references/platform-operations.mdmarkdown2.5 KB
references/publish-checklist.mdmarkdown2.2 KB
references/research-mode.mdmarkdown1.6 KB
references/revision-workflow.mdmarkdown5.9 KB
references/social-writing-principles.mdmarkdown7.7 KB
references/workspace.mdmarkdown2.3 KB
references/x-delivery-contract.mdmarkdown3.6 KB
references/x-format.mdmarkdown3.5 KB
references/x-html-format.mdmarkdown6.8 KB
references/x-post-format.mdmarkdown2.5 KB
scripts/article_scaffold.pyscript5.6 KB
scripts/audit-provenance.pyscript14.9 KB
scripts/audit_css.pyscript1.1 KB
scripts/audit_docs.pyscript3.1 KB
scripts/audit_skill.pyscript3.1 KB
scripts/audit_styles.pyscript1.6 KB
scripts/check_article.pyscript13.9 KB
scripts/count_words.pyscript3.0 KB
scripts/de_ai_lint.pyscript41.5 KB
scripts/info_design_hints.pyscript14.2 KB
scripts/knowledge.pyscript11.8 KB
scripts/lint_x_post.pyscript20.0 KB
scripts/md2x-html.pyscript39.8 KB
scripts/md2x.pyscript15.4 KB
scripts/negative_tests.pyscript10.5 KB
scripts/package_skill.pyscript6.6 KB
scripts/revise_check.pyscript15.2 KB

scripts/knowledge.py

View on GitHub
#!/usr/bin/env python3
"""Search small knowledge catalogs, read selected cards, or capture a candidate locally.

Standard library only. No network, global discovery, execution of card contents,
implicit promotion, or writes to the bundled knowledge pack.
"""
from __future__ import annotations

import argparse
from datetime import date
import json
import os
from pathlib import Path, PurePosixPath
import re
import sys
import tempfile

ROOT = Path(__file__).resolve().parent.parent
BUNDLED = ROOT / 'knowledge'
SKILLS = {'topmind-briefs', 'topmind-cover', 'topmind-format', 'topmind-poster',
          'topmind-revise', 'topmind-viral-posts', 'topmind-wechat-post', 'topmind-x-article'}
KINDS = {'direction', 'technique', 'example', 'case', 'lesson'}
EVIDENCE = {'illustrative', 'observed', 'sourced', 'user-confirmed', 'unverified'}
STATES = {'candidate', 'active', 'retired'}
ID = re.compile(r'^[a-z0-9]+(?:-[a-z0-9]+)*$')


def card_path(root, value):
    rel = PurePosixPath(value)
    if rel.is_absolute() or '..' in rel.parts or '\\' in value or rel.suffix != '.md':
        raise ValueError(f'Invalid card path: {value}')
    target = (root / value).resolve()
    if not target.is_relative_to(root.resolve()):
        raise ValueError(f'Card escapes pack directory: {value}')
    return target


def validate(data, root, check_bodies=True):
    if not isinstance(data, dict) or data.get('schema_version') != 1:
        raise ValueError('Knowledge catalog requires schema_version=1')
    if not ID.fullmatch(str(data.get('id', ''))) or not isinstance(data.get('version'), str):
        raise ValueError('Pack requires a stable id and string version')
    if not isinstance(data.get('entries'), list):
        raise ValueError('Pack requires an entries list')
    ids, paths = set(), set()
    for item in data['entries']:
        if not isinstance(item, dict):
            raise ValueError('Each entry must be an object')
        ident = item.get('id', '')
        if not isinstance(ident, str) or not ID.fullmatch(ident) or ident in ids:
            raise ValueError(f'Invalid or duplicate card id: {ident}')
        ids.add(ident)
        for field in ['title', 'summary', 'scope', 'limits', 'path']:
            if not isinstance(item.get(field), str) or not item[field].strip():
                raise ValueError(f'{ident}: requires nonempty {field}')
        for field in ['skills', 'tags']:
            value = item.get(field)
            if not isinstance(value, list) or not value or any(not isinstance(v, str) or not v.strip() for v in value):
                raise ValueError(f'{ident}: requires a nonempty string list: {field}')
        if not set(item['skills']) <= SKILLS | {'*'}:
            raise ValueError(f'{ident}: unknown skill')
        for field, choices in [('kind', KINDS), ('evidence', EVIDENCE), ('status', STATES)]:
            if item.get(field) not in choices:
                raise ValueError(f'{ident}: invalid {field}')
        sources = item.get('sources')
        if not isinstance(sources, list) or not sources or any(
                not isinstance(s, dict) or not isinstance(s.get('ref'), str) or not s['ref'].strip()
                or s.get('kind') not in {'original', 'source', 'observation', 'feedback'} for s in sources):
            raise ValueError(f'{ident}: requires source/provenance records')
        target = card_path(root, item['path'])
        if target in paths or not target.is_file() or (not target.read_text(encoding='utf-8').strip() if check_bodies else target.stat().st_size == 0):
            raise ValueError(f'{ident}: duplicate, missing or empty card: {item["path"]}')
        paths.add(target)
    return data


def load(root, check_bodies=False):
    root = Path(root).resolve()
    index = (root / 'index.json').resolve()
    if not index.is_relative_to(root):
        raise ValueError('Catalog escapes pack directory')
    with index.open(encoding='utf-8') as stream:
        data = json.load(stream)
    return root, validate(data, root, check_bodies)


def tokens(text):
    result = set()
    for word in re.findall(r'[a-z0-9][a-z0-9_-]*|[\u3400-\u9fff]+', text.lower()):
        result.add(word)
        if re.fullmatch(r'[\u3400-\u9fff]+', word):
            result.update(word[i:i + 2] for i in range(len(word) - 1))
    return result


def search(packs, query, skill, include_candidates=False, limit=5):
    wanted = tokens(query)
    found = []
    for root, data in packs:
        for item in data['entries']:
            if item['status'] != 'active' and not (include_candidates and item['status'] == 'candidate'):
                continue
            if skill != 'all' and skill not in item['skills'] and '*' not in item['skills']:
                continue
            score, matched = 0, set()
            for field, weight in [('title', 6), ('tags', 5), ('summary', 3), ('scope', 1)]:
                value = ' '.join(item[field]) if isinstance(item[field], list) else item[field]
                hits = wanted & tokens(value)
                score += len(hits) * weight
                matched.update(hits)
            if not score:
                continue
            result = {**item, 'key': f'{data["id"]}:{item["id"]}',
                      'file': str(card_path(root, item['path'])), 'matched': sorted(matched)}
            found.append((score, result))
    found.sort(key=lambda pair: (-pair[0], pair[1]['key']))
    return [item for _, item in found[:limit]]


def read_card(packs, key, max_chars):
    matches = [(root, data, item) for root, data in packs for item in data['entries']
               if key in (item['id'], f'{data["id"]}:{item["id"]}')]
    if len(matches) != 1:
        raise ValueError('Card not found or id is ambiguous; use pack-id:card-id from search')
    root, data, item = matches[0]
    body = card_path(root, item['path']).read_text(encoding='utf-8')
    header = f'{data["id"]}:{item["id"]} | {item["status"]} | evidence={item["evidence"]}\nScope: {item["scope"]}\nLimits: {item["limits"]}\n'
    text = header + body
    if len(text) > max_chars:
        text = text[:max_chars] + f'\n[Truncated; {len(text)} characters total. Raise --max-chars or read the named file.]'
    return text


def add_candidate(args):
    if len(args.pack or []) != 1:
        raise ValueError('add requires exactly one explicit --pack output directory')
    root = Path(args.pack[0]).resolve()
    if root == BUNDLED.resolve() or (root.parent / 'SKILL.md').is_file() or (
            root.parent.name == 'shared' and (root.parent / 'manifest.json').is_file()):
        raise ValueError('add cannot modify a bundled pack; use a separate explicit local pack')
    if not ID.fullmatch(args.id):
        raise ValueError('Card id must be lowercase words separated by hyphens')
    body = Path(args.body).read_text(encoding='utf-8')
    if not body.strip():
        raise ValueError('Candidate body is empty')
    skills = [s.strip() for s in args.skills.split(',') if s.strip()]
    if not skills or not set(skills) <= SKILLS | {'*'}:
        raise ValueError('Unknown or empty --skills')
    tags = [s.strip() for s in args.tags.split(',') if s.strip()]
    if not tags:
        raise ValueError('At least one tag is required')
    path = f'cards/{args.id}.md'
    target = card_path(root, path)
    if target.exists():
        raise ValueError('Card already exists; add never overwrites a card')
    item = dict(id=args.id, title=args.title, summary=args.summary, skills=skills,
                tags=tags, kind=args.kind, status='candidate', evidence='unverified',
                scope=args.scope, limits=args.limits, path=path,
                sources=[{'kind': 'source' if args.source else 'original',
                          'ref': args.source or 'Local task note; not externally verified'}],
                updated=date.today().isoformat())
    root.mkdir(parents=True, exist_ok=True)
    target.parent.mkdir(parents=True, exist_ok=True)
    lock = root / '.write-lock'
    lock.mkdir()  # refuse concurrent writers instead of losing a candidate
    temporary = None
    created = False
    try:
        data = load(root)[1] if (root / 'index.json').exists() else {
            'schema_version': 1, 'id': args.pack_id, 'version': '0.1.0', 'entries': []}
        if any(entry['id'] == args.id for entry in data['entries']):
            raise ValueError('Card id already exists')
        with target.open('x', encoding='utf-8') as stream:
            created = True
            stream.write(body)
        data['entries'].append(item)
        validate(data, root)
        with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', dir=root, delete=False) as stream:
            temporary = Path(stream.name)
            json.dump(data, stream, ensure_ascii=False, indent=2)
            stream.write('\n')
        os.replace(temporary, root / 'index.json')
        temporary = None
    except Exception:
        if created:
            target.unlink(missing_ok=True)
        raise
    finally:
        if temporary:
            temporary.unlink(missing_ok=True)
        lock.rmdir()
    print(f'Captured candidate (not active): {data["id"]}:{args.id}\n{target}')


def main(argv=None):
    parser = argparse.ArgumentParser(description=__doc__)
    sub = parser.add_subparsers(dest='command', required=True)
    for command in ['search', 'show', 'validate', 'add']:
        p = sub.add_parser(command)
        p.add_argument('--pack', action='append', help='Explicit pack directory; repeat to read multiple packs')
        if command == 'search':
            p.add_argument('query')
            p.add_argument('--skill', choices=sorted(SKILLS) + ['all'], default=ROOT.name if ROOT.name in SKILLS else 'all')
            p.add_argument('--limit', type=int, default=5)
            p.add_argument('--include-candidates', action='store_true')
            p.add_argument('--json', action='store_true')
        elif command == 'show':
            p.add_argument('id')
            p.add_argument('--max-chars', type=int, default=6000)
        elif command == 'add':
            for flag in ['id', 'title', 'summary', 'skills', 'tags', 'body', 'scope', 'limits']:
                p.add_argument('--' + flag, required=True)
            p.add_argument('--pack-id', default='local-knowledge')
            p.add_argument('--kind', choices=sorted(KINDS), default='lesson')
            p.add_argument('--source')
    args = parser.parse_args(argv)
    try:
        if args.command == 'add':
            add_candidate(args)
            return 0
        roots = args.pack or [BUNDLED]
        packs = [load(root, args.command == 'validate') for root in roots]
        if len({data['id'] for _, data in packs}) != len(packs):
            raise ValueError('Duplicate pack ids; give each pack a distinct id')
        if args.command == 'validate':
            for root, data in packs:
                print(f'Valid pack: {data["id"]} {data["version"]}, {len(data["entries"])} cards ({root})')
        elif args.command == 'show':
            if args.max_chars < 1:
                raise ValueError('--max-chars must be positive')
            print(read_card(packs, args.id, args.max_chars))
        else:
            if not 1 <= args.limit <= 50:
                raise ValueError('--limit must be between 1 and 50')
            results = search(packs, args.query, args.skill, args.include_candidates, args.limit)
            if args.json:
                print(json.dumps(results, ensure_ascii=False, indent=2))
            elif not results:
                print('No matching cards. Continue from task materials or search relevant references; do not invent a rule.')
            else:
                for item in results:
                    print(f'{item["key"]} | {item["status"]} | {item["evidence"]}\n  {item["title"]}: {item["summary"]}\n  Scope: {item["scope"]}\n  Limits: {item["limits"]}\n  File: {item["file"]}')
        return 0
    except (OSError, ValueError, TypeError) as error:
        print(f'Knowledge error: {error}', file=sys.stderr)
        return 2


if __name__ == '__main__':
    sys.exit(main())
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall