AgentSkillsCN

new-hook

搭建一项新的 Hooks 注册。关键词:Hooks、事件、脚手架搭建。

SKILL.md
--- frontmatter
name: new-hook
description: "Scaffold a new hook registration. Keywords: hook, event, scaffolding."

Scaffold: New Hook Registration

This document is an entrypoint for hook scaffolding. The step-by-step flow is in /.system/skills/ssot/repo/scaffolding/new-hook/SKILL.md.


1. Purpose & Scope

Purpose: Register a new hook that responds to lifecycle events (PromptSubmit, PreAbilityCreate, PreAbilityCall, PostAbilityCall, SessionStop).

Scope:

  • Creates hook registration in /.system/hooks/
  • Validates handler references
  • Optionally creates handler implementation placeholder

Out of scope:

  • Implementing the actual handler logic
  • Modifying existing hooks
  • Runtime hook execution (handled by Hook Runner)

2. Inputs & Preconditions

Required Inputs

ParameterTypeDescription
idstringUnique hook identifier (e.g., ability_usage_tracker)
event_typeenumLifecycle event: PromptSubmit, PreAbilityCreate, PreAbilityCall, PostAbilityCall, SessionStop
enabledbooleanWhether hook is active
blockingbooleanWhether hook blocks execution
handler.kindenumHandler type: script, function
handler.commandstringHandler command or function reference

Optional Inputs

ParameterTypeDefaultDescription
summarystring""One-line description of what this hook does (max 200 chars)
matchobject{}Selective execution conditions (ability_pattern, scope_pattern)
orderinteger100Execution order (lower = earlier)

Preconditions

  1. Phase 4 registry tooling is available (scripts/devops/registry/hooks.py)
  2. id does not already exist in hook registry
  3. Handler reference is valid or will be created
  4. Hook file naming matches id (<id>.yaml)

3. Step-by-Step Flow (AI + Human)

See /.system/skills/ssot/repo/scaffolding/new-hook/SKILL.md.


4. Tools & Scripts

ToolPurpose
scripts/devops/scaffold/new_hook.pyOrchestrator script
scripts/devops/registry/hooks.pyHook validation

5. Outputs & Side Effects

Files Created

code
/.system/hooks/<id>.yaml                    # Hook registration
/.system/hooks/implementations/<id>.py      # Handler placeholder (optional)

Hook Registration Structure

yaml
id: ability_usage_tracker
event_type: PostAbilityCall
enabled: true
blocking: false
handler:
  kind: script
  command: scripts/hooks/<hook_id>.py
summary: Track ability usage for analytics
order: 100
match:
  ability_pattern: ".*"

6. Safety & Rollback

Safety Measures

  • --dry-run always available for preview
  • Human approval required before execution
  • Schema validation on hook registration
  • Consistency checks via hooks.py --check

Rollback Procedure

If registration fails or needs reverting:

  1. Delete the hook file:
    bash
    rm /.system/hooks/<id>.yaml
    
  2. Optionally delete the handler placeholder:
    bash
    rm /.system/hooks/implementations/<id>.py
    
  3. Verify with:
    bash
    python scripts/devops/registry/hooks.py --check
    

7. Event Type Reference

Event TypeWhen TriggeredTypical Use
PromptSubmitUser submits promptRouting hints, intent normalization
PreAbilityCreateBefore task.createPreflight validation, policy checks
PreAbilityCallBefore task.runGuardrails, approval gates
PostAbilityCallAfter task executionLogging, analytics, cleanup
SessionStopSession endsSummary generation, state persistence

8. Related Documents

  • /.system/skills/ssot/repo/architecture-core-mechanisms/hook-lifecycle/SKILL.md - Hook lifecycle workflow
  • /.system/hooks/AGENTS.md - Hook infrastructure strategy
  • /.system/registry/schemas/hook.schema.yaml - Hook schema
  • /.system/registry/schemas/V1_CORE.md - V1-core required fields