Skills 调试:发现、执行和结果
确认是否找到说明、脚本是否真正运行、输出是否符合约定,按可观察现象定位故障。
学完这一章,你能够
- 确认是否找到说明、脚本是否真正运行、输出是否符合约定,按可观察现象定位故障。
先查技能是否能被发现
确认当前宿主、查找目录、文件名和权限,列出目录并确认 SKILL.md 非空。Bash 可用 ls 和 wc,Windows 可用 Get-ChildItem 和 Get-Content。用 YAML 校验器检查分隔行、name 与 description,具体语法交给解析器。必要时用宿主的明确入口做对照。
将测试按任务拆成正例、拒绝例及近邻请求。比起笼统的分析文件,写清 CSV 指标、期望表格或演示稿模板会让范围可核对。是否实际自动触发应回看宿主记录。
区分参数、权限、依赖和语法
复制同一文件和参数到独立项目直接运行,比较使用的解释器、cwd、参数、进程退出码和 stderr。--verbose 或 --debug 只有脚本提供时可用。FileNotFoundError 追查实际输入路径,PermissionError 核对目标授权与只读标志。
ModuleNotFoundError 先检查解释器及声明的依赖,用项目虚拟环境安装。旧示例用 --break-system-packages 绕过发行版保护,常规运行可使用 venv。托管 /mnt/user-data/uploads/ 与 /mnt/user-data/outputs/ 仅凭宿主提供的实际路径使用。
python -m py_compile 检查语法,bash -n 检查 Bash。它们不会运行脚本主流程。通过解析后仍需要用真实样本测试读取、依赖、计算和产物。本站分别实测缺输入、只读文件及缺 DOCX 模块的诊断。
从结果反查输入与任务理解
明确输出是本地文件还是文本,约定例如均值、中位数、标准差或 HTML 的摘要、数据表和结论。写诊断时记录已批准的文件、输出格式和必要步骤,避免记录敏感数据。
开发日志可以包括输入尺寸、格式和处理行数,放在 stderr。stdout 留给调用者生成机器可解析的结果。本站实测打开调试后 JSON 与普通运行一致。发布前移除临时日志或默认关闭,将语义断言与程序状态一起检查。
按故障发生阶段排查
| 条目 | 用途与条件 |
|---|---|
| 发现失败 | 核对目录、文件名、YAML 与描述。 |
| 执行失败 | 重跑命令,记录解释器、路径、权限及诊断。 |
| 结果错误 | 比对实际文档或数据和具体验收条件。 |
为测试消息写清目标
| 条目 | 用途与条件 |
|---|---|
| CSV 分析 | 说明数据范围、增长指标及需要的表格。 |
| 产品演示 | 指定素材、页面范围与图表验收要求。 |
识别实际异常
| 条目 | 用途与条件 |
|---|---|
| 模块缺失 | 确认脚本在所需隔离环境执行。 |
| 路径不存在 | 检查附件实际路径或工作目录。 |
| 权限不足 | 使用获准写入路径,确认是否只读。 |
| 语法错误 | 分别运行 Python 编译和 Bash 语法检查。 |
把验收条件写进说明
| 条目 | 用途与条件 |
|---|---|
| 交付位置 | 目标目录、文件名、格式和检查方式可明确验证。 |
| 统计定义 | 明确允许的列、缺失值处理、均值、中位数和标准差。 |
| 报告内容 | 指定摘要、表格与结论以及呈现位置。 |
定位文件错误、依赖缺失和调试输出
"""Render structured meeting notes to Markdown or a Word document."""
import argparse
import json
from pathlib import Path
import sys
def content(data):
topic = data.get("topic")
date = data.get("date")
if not all(isinstance(x,str) and x.strip() for x in (topic,date)):
raise ValueError("topic and date are required strings")
groups = {}
for label in ("participants","discussion","decisions"):
items=data.get(label)
if not isinstance(items,list) or not all(isinstance(x,str) and x.strip() for x in items):
raise ValueError(f"{label} must contain strings")
groups[label]=items
actions=data.get("actions")
if not isinstance(actions,list):
raise ValueError("actions must be a list")
action_lines=[]
for row in actions:
if not isinstance(row,dict) or not all(isinstance(row.get(k),str) and row[k].strip()
for k in ("task","owner","due")):
raise ValueError("each action needs task, owner and due")
action_lines.append(f"{row['task']} | {row['owner']} | {row['due']}")
return topic, [("Meeting information",[date,", ".join(groups["participants"])]),
("Discussion",groups["discussion"]),("Decisions",groups["decisions"]),("Actions",action_lines)]
def render(topic, sections, target):
if target.suffix.lower()==".docx":
from docx import Document
doc=Document()
doc.add_heading(topic,0)
for title,items in sections:
doc.add_heading(title,1)
for value in items:
doc.add_paragraph(value)
doc.save(target)
elif target.suffix.lower()==".md":
parts=[f"# {topic}"]
parts.extend("\n".join([f"## {title}",*(f"- {item}" for item in items)]) for title,items in sections)
target.write_text("\n\n".join(parts)+"\n",encoding="utf8")
else:
raise ValueError("output must end in .md or .docx")
def main(argv=None):
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument("source", type=Path)
parser.add_argument("target", type=Path)
parser.add_argument("--debug", action="store_true")
args=parser.parse_args(argv)
try:
raw=args.source.read_bytes()
meeting=json.loads(raw)
if not isinstance(meeting,dict):
raise ValueError("input must be an object")
topic, sections=content(meeting)
if args.debug:
print(f"[debug] source={args.source.name} format={args.target.suffix} input_bytes={len(raw)} "
f"actions={len(sections[-1][1])}",file=sys.stderr)
render(topic,sections,args.target)
except ValueError as error:
print(f"invalid input or format: {error}",file=sys.stderr)
return 2
except FileNotFoundError:
print("input or output directory not found",file=sys.stderr)
return 3
except PermissionError:
print("unable to write or read the requested path",file=sys.stderr)
return 4
except ModuleNotFoundError:
print("use the declared python-docx dependency for Word output",file=sys.stderr)
return 5
print(json.dumps({"output_file":args.target.name, "actions":len(sections[-1][1])}))
return 0
if __name__=="__main__":
raise SystemExit(main())
- 缺文件、只读目标和非法结构产生不同状态。开启调试时详细信息写 stderr,结果 JSON 仍可解析。Python 与 Bash 语法检查会拒绝坏样本。
所需环境:Windows、Python 3.12。各实验所需工具和版本见下载包 README。
当前源码 SHA256:309ee779fa389937e805305b8cd37bd74a8de81916ec10b683c8d262e79ca740
运行本地实验
解压后按 README 运行当前章节对应的脚本,并查看真实输出。
所需环境:Windows、Python 3.12。各实验所需工具和版本见下载包 README。
ZIP SHA256:9be72886036f1b9af2ea553ee979e0abd4e5dfee6328cd3f95b8aee98a5ae955
常见错误与边界
- 实际端口、文档资源与应用配置都应和测试条件一致。
练习与解答
程序退出 0 后还应核对什么?
展开参考解答
用固定输入核对生成文件的标题、字段、章节和内容,检查数据是否满足任务要求。