Skip to content

Commit 304924e

Browse files
refactor(skills): consolidate hooks documentation to eliminate duplication
- Revived objectstack-hooks skill as canonical reference (removed deprecation) - Created objectstack-hooks/references/ with data-hooks.md and plugin-hooks.md - Replaced objectstack-schema/rules/hooks.md with reference pointer - Replaced objectstack-plugin/rules/hooks-events.md with reference pointer - Updated all cross-references in SKILL.md files - Established single source of truth for all hooks documentation Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/121cb9bd-5a46-4612-bc44-314fe4196da5 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent a5a0d9d commit 304924e

File tree

7 files changed

+1688
-1292
lines changed

7 files changed

+1688
-1292
lines changed

skills/objectstack-hooks/SKILL.md

Lines changed: 126 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,155 @@
11
---
22
name: objectstack-hooks
33
description: >
4-
⚠️ DEPRECATED: This skill has been integrated into objectstack-schema.
5-
Please use the objectstack-schema skill and refer to rules/hooks.md for
6-
data lifecycle hook documentation.
4+
Canonical reference for all ObjectStack hooks and lifecycle events.
5+
Use when implementing data lifecycle hooks, plugin hooks, kernel events,
6+
or understanding the hook system architecture. This skill serves as the
7+
single source of truth for hook documentation across the platform.
78
license: Apache-2.0
89
compatibility: Requires @objectstack/spec v4+, @objectstack/objectql v4+
910
metadata:
1011
author: objectstack-ai
11-
version: "1.0"
12+
version: "2.0"
1213
domain: hooks
13-
tags: hooks, lifecycle, validation, business-logic, side-effects, data-enrichment
14-
deprecated: true
15-
replacement: objectstack-schema
14+
tags: hooks, lifecycle, validation, business-logic, side-effects, data-enrichment, events, plugin-hooks
1615
---
1716

18-
# ⚠️ DEPRECATED: Hooks Skill Migrated
17+
# Hooks System — ObjectStack Canonical Reference
1918

20-
This skill has been **deprecated** and integrated into the **objectstack-schema** skill.
19+
This skill is the **single source of truth** for all hook and event documentation in ObjectStack.
20+
It consolidates hook patterns across data lifecycle, plugin system, and kernel events to eliminate
21+
duplication and ensure consistency.
2122

22-
## Migration
23+
---
2324

24-
For data lifecycle hook documentation, please use:
25+
## When to Use This Skill
2526

26-
**New location:** [`objectstack-schema/rules/hooks.md`](../objectstack-schema/rules/hooks.md)
27+
- You need to understand the **complete hooks architecture** across ObjectStack
28+
- You are implementing **data lifecycle hooks** (beforeInsert, afterUpdate, etc.)
29+
- You are working with **plugin hooks** (kernel:ready, data:*, custom events)
30+
- You need to compare **data hooks vs plugin hooks** patterns
31+
- You are designing hook-based integrations or extensions
32+
- You want to reference hook best practices and common patterns
2733

28-
## Rationale
34+
---
2935

30-
Hooks are a core part of data operations and are best documented alongside object definitions, field types, and validations. The objectstack-schema skill now provides comprehensive coverage of:
36+
## Skill Organization
3137

32-
- Object and field schema design
33-
- Validation rules
34-
- Index strategy
35-
- **Data lifecycle hooks** (before/after patterns, all 14 events)
38+
This skill is organized into two main reference documents:
3639

37-
This consolidation reduces skill overlap and makes it easier for AI assistants to understand the complete data layer in ObjectStack.
40+
### 1. **Data Lifecycle Hooks**[references/data-hooks.md](./references/data-hooks.md)
3841

39-
## What Was Moved
42+
Comprehensive guide for data operation hooks:
43+
- 14 lifecycle events (beforeFind, afterFind, beforeInsert, afterInsert, etc.)
44+
- Hook definition schema and HookContext API
45+
- Registration methods (declarative, programmatic, file-based)
46+
- Common patterns (validation, defaults, audit logging, workflows)
47+
- Performance considerations and best practices
48+
- Complete code examples and testing strategies
4049

41-
All content from this skill is now available at:
50+
**Use for:** Object-level business logic, validation, data enrichment, side effects during CRUD operations.
4251

43-
- **Full documentation:** [`../objectstack-schema/rules/hooks.md`](../objectstack-schema/rules/hooks.md)
44-
- **Parent skill:** [`../objectstack-schema/SKILL.md`](../objectstack-schema/SKILL.md)
52+
### 2. **Plugin & Kernel Hooks**[references/plugin-hooks.md](./references/plugin-hooks.md)
4553

46-
The objectstack-schema skill now includes:
47-
- Hook definition schema
48-
- Hook context API
49-
- 14 lifecycle events (before/after for find/insert/update/delete, etc.)
50-
- Common patterns (validation, defaults, audit logging, workflows)
51-
- Performance considerations
52-
- Testing hooks
53-
- Best practices
54+
Guide for plugin-level hooks and event system:
55+
- Kernel lifecycle hooks (kernel:ready, kernel:shutdown)
56+
- Plugin event system (ctx.hook, ctx.trigger)
57+
- Built-in data events (data:beforeInsert, data:afterInsert, etc.)
58+
- Custom plugin events and namespacing
59+
- Hook handler patterns and error handling
60+
- Cross-plugin communication
61+
62+
**Use for:** Plugin development, kernel events, cross-plugin communication, system-level hooks.
63+
64+
---
65+
66+
## Quick Comparison: Data Hooks vs Plugin Hooks
67+
68+
| Aspect | Data Hooks | Plugin Hooks |
69+
|:-------|:-----------|:-------------|
70+
| **Defined in** | Object metadata (Stack) | Plugin code (init/start) |
71+
| **Registration** | `hooks: [...]` in stack config | `ctx.hook()` in plugin |
72+
| **Context** | Rich HookContext with input/result/api | Flexible arguments per event |
73+
| **Scope** | Object-specific or global (`object: '*'`) | Global, across all objects |
74+
| **Priority** | Explicit `priority` field | Plugin dependency order |
75+
| **Use case** | Business logic tied to objects | System integration, cross-cutting concerns |
76+
77+
---
78+
79+
## References from Other Skills
80+
81+
This skill is referenced by:
82+
83+
- **[objectstack-schema](../objectstack-schema/SKILL.md)** — Uses data hooks for object lifecycle
84+
- **[objectstack-plugin](../objectstack-plugin/SKILL.md)** — Uses plugin hooks for kernel integration
85+
- **[objectstack-automation](../objectstack-automation/SKILL.md)** — Flows can trigger via hooks
86+
87+
---
88+
89+
## Documentation Map
90+
91+
```
92+
objectstack-hooks/
93+
├── SKILL.md (this file)
94+
└── references/
95+
├── data-hooks.md — Data lifecycle hooks (14 events)
96+
└── plugin-hooks.md — Plugin & kernel hooks
97+
```
5498

5599
---
56100

57-
## Quick Reference (for backwards compatibility)
101+
## Quick Start
102+
103+
### For Data Lifecycle Hooks
104+
105+
See [references/data-hooks.md](./references/data-hooks.md) for complete documentation.
106+
107+
Quick example:
108+
```typescript
109+
import { Hook, HookContext } from '@objectstack/spec/data';
110+
111+
const hook: Hook = {
112+
name: 'validate_account',
113+
object: 'account',
114+
events: ['beforeInsert', 'beforeUpdate'],
115+
handler: async (ctx: HookContext) => {
116+
if (!ctx.input.email?.includes('@')) {
117+
throw new Error('Valid email required');
118+
}
119+
},
120+
};
121+
```
122+
123+
### For Plugin Hooks
58124

59-
For hook lifecycle documentation, see:
125+
See [references/plugin-hooks.md](./references/plugin-hooks.md) for complete documentation.
60126

61-
- [objectstack-schema/rules/hooks.md](../objectstack-schema/rules/hooks.md) — Complete hook documentation
62-
- [objectstack-schema/SKILL.md](../objectstack-schema/SKILL.md) — Schema skill overview
127+
Quick example:
128+
```typescript
129+
async init(ctx: PluginContext) {
130+
ctx.hook('kernel:ready', async () => {
131+
ctx.logger.info('System ready');
132+
});
133+
134+
ctx.hook('data:afterInsert', async (objectName, record, result) => {
135+
console.log(`Created ${objectName}:`, result.id);
136+
});
137+
}
138+
```
139+
140+
---
141+
142+
## Design Philosophy
143+
144+
1. **Single Source of Truth** — All hook documentation lives here, other skills reference it
145+
2. **Clear Separation** — Data hooks vs plugin hooks serve different purposes
146+
3. **Consistency** — Patterns and best practices apply across both systems
147+
4. **Cross-References** — Easy navigation between related concepts
148+
149+
---
63150

64-
For kernel-level hooks (kernel:ready, kernel:shutdown, custom plugin events), see:
151+
## See Also
65152

66-
- [objectstack-plugin/rules/hooks-events.md](../objectstack-plugin/rules/hooks-events.md) — Plugin hook system
67-
- [objectstack-plugin/SKILL.md](../objectstack-plugin/SKILL.md) — Plugin skill overview
153+
- [objectstack-schema/SKILL.md](../objectstack-schema/SKILL.md) — Object and field definitions
154+
- [objectstack-plugin/SKILL.md](../objectstack-plugin/SKILL.md) — Plugin development guide
155+
- [objectstack-automation/SKILL.md](../objectstack-automation/SKILL.md) — Flows and workflows

0 commit comments

Comments
 (0)