Skip to content

feat(hooks): SessionStart source 报告 "fork" (P2.2, CC 2.1.214) #79

Closed

Description

@dahai80

背景

enhance-0819.md P2.2 / CC 2.1.214: SessionStart hook 应在会话 fork 时报告 source: "fork" (非 "resume"),让用户 hook 能区分 fork 与普通 resume。

现状 (gap)

fusion-code 有两条 fork 路径:

  • CLI --fork-session (--continue/--resume 配合): main.tsx → loadConversationForResume (conversationRecovery.ts:575) 触发 processSessionStartHooks("resume") — fork 被报成 resume
  • /resume slash 命令 picker 中的 fork (entrypoint === "fork"): REPL.tsx:2473 触发 processSessionStartHooks("resume") — 同上

source union ("startup" | "resume" | "clear" | "compact") 4 处无 "fork":

  • src/utils/hooks.ts:3925 (executeSessionStartHooks 签名)
  • src/utils/sessionStart.ts:36 (processSessionStartHooks 签名)
  • src/entrypoints/sdk/coreSchemas.ts:497 (zod enum, 运行时校验)
  • src/utils/hooks/hooksConfigManager.ts:92 (可选值列表, hook 配置 UI/matcher)

hooks.ts:1657 matchQuery = hi.source — hook 按 source 值匹配。缺 "fork" 意味用户无法写一个只在 fork 会话时触发的 SessionStart hook。

设计

  1. 4 处加 "fork" 字面量 (类型 + schema + 可选值对齐)
  2. REPL.tsx:2473: source: entrypoint === "fork" ? "fork" : "resume" (entrypoint 已有 "fork" 区分, ResumeEntrypoint type src/types/command.ts:108)
  3. conversationRecovery.ts: loadConversationForResume 加可选 forkSession?: boolean 参数, :575 source: forkSession ? "fork" : "resume"; main.tsx 4 调用点传 forkSession: !!options.forkSession

验收

  • typecheck 0
  • 单测: fork 路径 emit source "fork", resume emit "resume", hook matcher 接受 "fork"
  • build + dev:full pass
  • 不回归既有 514 测试

不做

  • subagent spawn 路径已有独立 SubagentStart hook 事件, 不走 SessionStart — 本 issue 只管会话级 fork
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions