Skip to content

kkfor30/kk-sessions / skills/kk-session-route

kk-session-route

Verified

新会话第一轮做会话归位:按工作区地图判断这次内容属于哪个分区和目录,建主题目录、切目录、按统一格式命名、归入侧栏分区。Claude Code 由启动钩子触发,先处理用户的请求、本轮结束前完成归位;Codex 的标题和分区由后台钩子自动完成,会话本身只负责把产物写到目标目录;用户说"路由一下""这个会话归到哪""重新归类"时也使用。支持 Claude Code 桌面端和 Codex 桌面端。不用于中途换话题时自动迁移;批量整理旧会话用 kk-session-tidy,首次生成地图用 kk-session-setup。

FileKindSize
SKILL.mdskill md9.0 KB
scripts/codex_route.pyscript28.3 KB
scripts/kit.pyscript979 B
scripts/restore.pyscript7.2 KB
scripts/session_start.pyscript1.8 KB
scripts/stop_check.pyscript2.8 KB
scripts/turn_hint.pyscript5.8 KB

scripts/stop_check.py

View on GitHub
"""Stop 钩子(Claude Code):新会话第一轮结束前,检查是否已按 kk-session-route 归位。

没归位就拦一次,让模型补做;以下情况直接放行:
- 不是桌面端(命令行、`claude -p`、Agent SDK 没有侧栏,拦了也改不了标题)
- 已经拦过一次(stop_hook_active)
- 还没有工作区地图(未初始化)
- 不是第一轮(用户已发过多条消息,旧会话交给 kk-session-tidy)
- 标题已是 `<类型emoji> <主题>|…` 格式
"""
import json
import re
import sys
from pathlib import Path

TYPE_EMOJI = ("✍️", "🔍", "🧪", "🎬", "📤", "🛠️", "🐛", "💬")
# 变体选择符 U+FE0F 可有可无:模型或输入法常把 ✍️ 写成 ✍
TITLE_RE = re.compile(r"^(%s)️? .+[||]" % "|".join(re.escape(e.rstrip("️")) for e in TYPE_EMOJI))
REASON = ("[kk-session-route] 本会话还没归位。结束前请按 kk-session-route 的「回答后」一节完成:"
          "改标题、归入侧栏分区(要产出文件的任务再切目录),最后一句话说明结果。"
          "如果你已在回复里问用户这个会话该归哪里,直接结束即可。")


def scan(path):
    """返回 (用户消息数, 自定义标题, 入口)。入口:桌面端是 claude-desktop,命令行和 SDK 是别的值。"""
    prompts, title, entry = 0, None, None
    for line in Path(path).read_text(encoding="utf-8", errors="replace").splitlines():
        try:
            d = json.loads(line)
        except ValueError:
            continue
        entry = entry or d.get("entrypoint")
        if d.get("type") == "custom-title":
            title = d.get("customTitle") or title
        elif d.get("type") == "user" and not d.get("isMeta"):
            c = d.get("message", {}).get("content")
            if isinstance(c, list):
                if any(i.get("type") == "tool_result" for i in c):
                    continue
                c = " ".join(i.get("text", "") for i in c if i.get("type") == "text")
            if isinstance(c, str) and c.strip() and not c.startswith("[Request interrupted"):
                prompts += 1
    return prompts, title, entry


def main():
    try:
        data = json.load(sys.stdin)
    except ValueError:
        return
    if data.get("stop_hook_active"):
        return
    if not (Path.home() / ".agent-rules" / "workspace-map.md").exists():
        return
    sys.path.insert(0, str(Path(__file__).resolve().parent))
    from kit import keep_restore_kit
    keep_restore_kit()
    path = data.get("transcript_path")
    if not path or not Path(path).exists():
        return
    prompts, title, entry = scan(path)
    if entry != "claude-desktop" or prompts > 1 or (title and TITLE_RE.match(title)):
        return
    print(json.dumps({"decision": "block", "reason": REASON}))


if __name__ == "__main__":
    main()
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall