{
  "version": "s04",
  "title": "Hooks",
  "description": "Lifecycle hooks attach logging, permission, and output handling around the same stable agent loop.",
  "steps": [
    {
      "type": "user_message",
      "content": "Read package.json and summarize the scripts.",
      "annotation": "UserPromptSubmit hooks run before the prompt enters the LLM call."
    },
    {
      "type": "system_event",
      "content": "trigger_hooks(UserPromptSubmit): log_user_prompt",
      "annotation": "Extension logic is outside the core loop."
    },
    {
      "type": "tool_call",
      "toolName": "read_file",
      "content": "{\"path\":\"package.json\"}",
      "annotation": "The LLM asks to use a tool."
    },
    {
      "type": "system_event",
      "content": "trigger_hooks(PreToolUse): permission_hook, log_hook -> allowed",
      "annotation": "PreToolUse hooks can block, audit, or annotate the tool call."
    },
    {
      "type": "tool_result",
      "toolName": "read_file",
      "content": "{ \"scripts\": { \"build\": \"next build\" } }",
      "annotation": "The handler executes only after hooks allow it."
    },
    {
      "type": "system_event",
      "content": "trigger_hooks(PostToolUse): large_output_hook",
      "annotation": "PostToolUse hooks see the result before it returns to the model."
    },
    {
      "type": "assistant_text",
      "content": "The project exposes a build script that runs Next's production build.",
      "annotation": "Stop hooks can run when the model no longer requests tools."
    }
  ]
}
