skills-experimental/graceful-shutdown/SKILL.md
Graceful shutdown mechanism: cleanup terminal modes, execute SessionEnd hooks, flush analytics, print resume hint. Failsafe timer with SIGKILL fallback. Use when shutting down, cleaning up resources, or handling SIGTERM/SIGINT.
npx skillsauth add bianhaifeng789-hue/openclaw-config graceful-shutdownInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
会话结束时执行清理操作,确保数据完整保存。
场景:
Claude Code 方案:gracefulShutdown.ts + failsafe timer OpenClaw 飞书适配:SessionEnd hooks + 飞书卡片关闭提示
// 清理 terminal 状态
function cleanupTerminalModes(): void {
// ANSI CSI sequences
process.stdout.write('\x1b[?25h') // Show cursor
process.stdout.write('\x1b[0m') // Reset colors
process.stdout.write('\x1b[2J') // Clear screen
process.stdout.write('\x1b[H') // Reset cursor
}
async function executeSessionEndHooks(): Promise<void> {
const hooks = getSessionEndHooks()
for (const hook of hooks) {
try {
await executeHook(hook, { timeout: 5000 })
} catch (error) {
logError('SessionEnd hook failed', error)
}
}
}
async function flushAnalytics(): Promise<void> {
try {
await analytics.flush({ timeout: 500 })
} catch (error) {
// Analytics flush 失败不阻塞关闭
logError('Analytics flush failed', error)
}
}
function printResumeHint(): void {
const sessionId = getSessionId()
console.log(`\nSession ended. Resume with: /resume ${sessionId}`)
console.log(`Or start a new session.`)
}
// 强制退出机制
const FAILSAFE_TIMEOUT = 5000 // 5 seconds
const HOOK_BUDGET = 2000 // 2 seconds for hooks
async function gracefulShutdown(): Promise<void> {
// 设置 failsafe timer
const failsafe = setTimeout(() => {
console.log('Failsafe timeout reached, forcing exit')
process.exit(1) // Exit immediately
}, FAILSAFE_TIMEOUT)
try {
// 执行清理流程
cleanupTerminalModes()
await executeSessionEndHooks()
await flushAnalytics()
printResumeHint()
// 清除 failsafe
clearTimeout(failsafe)
// 正常退出
process.exit(0)
} catch (error) {
// 异常时强制退出
clearTimeout(failsafe)
process.exit(1)
}
}
{
"config": {"wide_screen_mode": true},
"elements": [
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": "**🛑 Session Ended**\n\n**会话已结束**\n\n---\n\n**清理操作**:\n✅ Terminal modes 清理\n✅ SessionEnd hooks 执行\n✅ Analytics 数据保存\n✅ Memory 状态更新\n\n---\n\n**恢复提示**:\n下次可直接开始新对话,或使用 `/resume` 恢复此会话\n\n---\n\n**Session ID**:`session-abc123`\n\n**时长**:45 分钟\n\n**Messages**:28 条"
}
}
]
}
Graceful Shutdown:
1. 接收到关闭信号(SIGINT/SIGTERM)
2. 启动 failsafe timer
3. 执行清理流程
4. 发送飞书卡片
5. 正常退出
async function executeShutdown(): Promise<void> {
// 1. 清理 terminal
cleanupTerminalModes()
// 2. 执行 hooks(有 timeout)
await executeSessionEndHooks({ timeout: HOOK_BUDGET })
// 3. 刷新 analytics
await flushAnalytics({ timeout: 500 })
// 4. 更新 memory 状态
await updateMemoryState()
// 5. 发送飞书卡片
await sendSessionEndCard()
// 6. 打印恢复提示
printResumeHint()
}
// memory/graceful-shutdown-state.json
{
"shutdowns": [
{
"sessionId": "session-1",
"timestamp": "2026-04-12T00:00:00Z",
"hooksExecuted": 3,
"analyticsFlushed": true,
"duration": "45 minutes",
"messages": 28
}
],
"stats": {
"totalShutdowns": 0,
"successfulShutdowns": 0,
"forcedShutdowns": 0
},
"config": {
"failsafeTimeoutMs": 5000,
"hookBudgetMs": 2000,
"analyticsFlushTimeoutMs": 500
}
}
| Claude Code | OpenClaw 飞书场景 | |-------------|------------------| | cleanupTerminalModes | 飞书无 terminal,跳过 | | executeSessionEndHooks | SessionEnd hooks | | analytics.flush | OpenClaw analytics | | printResumeHint | 飞书卡片提示 | | Failsafe timer | 同样需要 |
此 Skill 在 session end 或系统关闭时自动触发。
business
IAA 日报飞书输出能力。 支持把固定 CSV 模板一键转换成: - 中文运营结论 - 飞书卡片 JSON - 飞书发送载荷 Use when: - 需要把 IAA 日报直接发到飞书 - 需要从 CSV 一键生成运营日报
data-ai
IAA日报分析模型 功能: - 渠道日报自动分析 - 小时级+日级ROI联动判断 - 按地区输出加量/降量/停投建议 - 按产品类型输出阈值 - 自动识别利润区/观察区/止损区 Use when: - 分析每天投放数据 - 生成运营日报结论 - 判断是否加量/降量/停投 - 对比美加澳/日韩表现 Keywords: - 日报模型, 投放日报, 加量, 降量, 停投, ROI日报, 分地区分析
data-ai
IAA固定日报分析模板 功能: - 固定字段模板(可直接贴每天数据) - 自动输出总盘结论 - 自动输出美加澳/日韩结论 - 自动给出加量/降量/停投建议 - 适配文件修复/清理两类产品 Use when: - 需要固定日报格式 - 每天复盘渠道表现 - 给运营团队出统一结论 Keywords: - 固定模板, 日报模板, ROI模板, IAA日报, 运营模板
development
# HyperlinkPool Pattern Skill HyperlinkPool Pattern - HyperlinkPool class + strings array + stringMap + Index 0 no hyperlink + intern(hyperlink) + get(id) + undefined handling + 5-minute reset + OSC8 hyperlink interning。 ## 功能概述 从Claude Code的ink/screen.ts提取的HyperlinkPool模式,用于OpenClaw的OSC8超链接池管理。 ## 核心机制 ### HyperlinkPool Class ```typescript export class HyperlinkPool { private strings: string[] = [''] // Index 0 = no hyperlink private stringMap = new Map<string, number>() // strings