SuperAPI AI 工具集

script-kit-logging

部署与运维

查看项目

更新于 10-15 23:34

技能介绍

用途:为 Script Kit GPUI 提供结构化日志与可观测性模式,适用于添加日志、调试或理解其日志系统。

主要能力:支持 AI 紧凑日志模式(SCRIPT_KIT_AI_LOG=1),输出紧凑 stderr 格式 SS.mmm|L|C|message,其中 L 为级别(i INFO、w WARN、e ERROR、d DEBUG、t TRACE),C 为类别(如 P position、A app、U UI、S stdin、H hotkey、E exec、K key、F focus、T theme、C cache、R perf、W window_mgr、X error 等)。同时支持 JSONL 日志,写入 ~/.scriptkit/logs/script-kit-gpui.jsonl,行内含 timestamp、level、target、message、fields 等字段。

使用方式:启用紧凑 AI 日志可运行 SCRIPT_KIT_AI_LOG=1 ./target/debug/script-kit-gpui 2>&1;完整调试用 RUST_LOG=debug;针对单个模块用 RUST_LOG=script_kit::theme=debug。日志查询示例:grep '"correlation_id":"abc-123"' ~/.scriptkit/logs/script-kit-gpui.jsonl;grep '"duration_ms":' ~/.scriptkit/logs/script-kit-gpui.jsonl | jq 'select(.fields.duration_ms > 100)';grep '"level":"ERROR"' ~/.scriptkit/logs/script-kit-gpui.jsonl | tail -50。

tracing 模式:使用 tracing 与 tracing-subscriber,用 #[instrument] 创建 span,记录 duration_ms 并在慢时(如 >100ms)告警;为每次用户操作或运行生成 UUID 作为 correlation_id 并附加到 span,使嵌套日志继承。相关字段包括 correlation_id、duration_ms、bead_id、agent_name、files_touched。日志级别:error 失败、warn 意外但已处理、info 关键事件、debug 开发、trace 非常详细。可按模块路径过滤,如 script_kit::ui、script_kit::executor、script_kit::theme。

错误处理:应用错误用 anyhow::Result 并在边界加 .context();领域/库错误在调用方需匹配变体时用 thiserror;面向用户的错误用 NotifyResultExt,先 tracing::error! 记录再弹 toast。最佳实践:不要 unwrap()/expect(),每层添加上下文,日志使用类型化字段而非插值字符串。

限制:资料未提供安装步骤、收费、平台支持范围及性能数据,暂未提供。