pty-initialization-debugging
Debug initialization crashes in PTY-interactive Python applications — sentinel objects, attribute ordering, __init__ sequencing
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Debug initialization crashes in PTY-interactive Python applications — sentinel objects, attribute ordering, __init__ sequencing
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Integration testing for AI Agent CLI systems — PTY-driven conversation simulation, tool chain verification, OpenSpec-driven test design, and real-API validation.
Extract web article content from WeChat MP, blogs, and other platforms, converting text, images, formatting, and tables to clean Markdown.
Configure, extend, or contribute to Hermes Agent.
Generate images, video, and audio with ComfyUI — install, launch, manage nodes/models, run workflows with parameter injection. Uses the official comfy-cli for lifecycle and direct REST/WebSocket API for execution.
Decomposition playbook + anti-temptation rules for an orchestrator profile routing work through Kanban. The "don't do the work yourself" rule and the basic lifecycle are auto-injected into every kanban worker's system prompt; this skill is the deeper playbook when you're specifically playing the orchestrator role.
Pitfalls, examples, and edge cases for Hermes Kanban workers. The lifecycle itself is auto-injected into every worker's system prompt as KANBAN_GUIDANCE (from agent/prompt_builder.py); this skill is what you load when you want deeper detail on specific scenarios.
| name | pty-initialization-debugging |
| description | Debug initialization crashes in PTY-interactive Python applications — sentinel objects, attribute ordering, __init__ sequencing |
| version | 1.0.0 |
| platforms | ["linux","macos","wsl"] |
| metadata | {"hermes":{"tags":["debugging","pty","python","initialization","tui"],"related_skills":["nanohermes-pty-testing"]}} |
PTY 启动 Python 应用时立即崩溃,报错 AttributeError: object has no attribute 或 NameError: name 'X' is not defined,但 python -c "import module" 正常。
NameError)# __init__ 签名中使用了 _UNSET 哨兵,但从未定义
def __init__(self, session_db=_UNSET): # NameError: _UNSET is not defined
修复:在类定义前添加 _UNSET = object()
AttributeError)def __init__(self):
self.status_bar = StatusBar(model=self.model) # AttributeError: no 'model'
# ... 50 lines later ...
self.model = config.model.name # model 赋值在 status_bar 之后
修复:将依赖 self.model 的对象创建延迟到 self.model 赋值之后。
def __init__(self):
if some_flag:
self.api_key = load_key()
# ... 后面使用 self.api_key 但不检查 some_flag
修复:确保所有分支都初始化了后续需要的属性,或在使用前加防御性检查。
确认是初始化崩溃还是运行时崩溃:
__init__ 或模块导入期 → 初始化问题用 python -B 排除缓存:
python -B -m src.main
如果 -B 能跑通但正常不行 → __pycache__ 过期
定位崩溃点:
python -c "from src.module import Class; Class()"
逐步缩小到具体类和行。
检查 __init__ 中属性赋值顺序:
__init__,标记每个 self.xxx = ...self.yyy 的使用点(包括方法调用、参数传递)_UNSET = object())__init__ 按依赖关系分组,用注释标注(如 # ── 步骤 7: 配置加载 ──)Optional 类型的属性访问问题__init__ 写简单的实例化测试(assert MyClass() 不抛异常)PTY 测试比单元测试更早暴露初始化顺序 bug,因为:
python -c "from src.cli.tui import TUIApp; TUIApp()" 做冒烟测试