Skip to content

Commit 5f51fe1

Browse files
committed
feat(docs): Add "AI Development Context" sections to documentation for better understanding of package roles and usage
1 parent 11fa3a4 commit 5f51fe1

4 files changed

Lines changed: 66 additions & 47 deletions

File tree

content/docs/developers/ai-development-guide.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ This guide enables AI agents to build production-grade enterprise applications (
3131
3. **Convention over Configuration**: Follow file suffix system
3232
4. **Progressive Development**: From simple to complex, iterative layers
3333

34+
### 🤖 AI Context Awareness
35+
To better understand the codebase, every package now includes an **"AI Development Context"** section in its `README.md`. Agents should consult this section to understand:
36+
- The package's specific role (Source of Truth vs. Runtime vs. Tooling)
37+
- Implicit rules (e.g., "No business logic here")
38+
- Architecture relationships
39+
3440
## Quick Start
3541

3642
### Environment Setup

content/docs/developers/micro-kernel.mdx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ The context provides access to kernel services and hooks.
135135
interface PluginContext {
136136
// Service Registry
137137
registerService(name: string, service: any): void;
138+
// Factory registration with lifecycle control
139+
registerServiceFactory(options: {
140+
name: string;
141+
factory: (ctx: PluginContext) => T;
142+
lifecycle: 'singleton' | 'transient' | 'scoped';
143+
dependencies?: string[];
144+
}): void;
145+
138146
getService<T>(name: string): T;
139147
getServices(): Map<string, any>;
140148

@@ -150,15 +158,41 @@ interface PluginContext {
150158
}
151159
```
152160

153-
**Logger Methods:**
161+
## 🚀 Enhanced Capabilities
162+
163+
The ObjectKernel provides advanced runtime features to ensure stability and developer experience.
164+
165+
### 1. Advanced Dependency Injection
166+
Beyond simple static services, the Kernel supports sophisticated lifecycles:
167+
168+
- **Singleton**: Created once, shared forever. (Default)
169+
- **Transient**: Created every time it is requested.
170+
- **Scoped**: Created once per specific scope (e.g., HTTP Request).
171+
154172
```typescript
155-
logger.debug(message, metadata?) // Development/troubleshooting
156-
logger.info(message, metadata?) // General information
157-
logger.warn(message, metadata?) // Warnings
158-
logger.error(message, metadata?) // Errors
159-
logger.fatal(message, metadata?) // Fatal errors
173+
ctx.registerServiceFactory({
174+
name: 'my-service',
175+
lifecycle: 'singleton',
176+
factory: (context) => new MyService(context)
177+
});
160178
```
161179

180+
### 2. Runtime Circular Dependency Detection
181+
The Kernel protects against infinite recursion. If your plugins create a loop (Service A -> Service B -> Service A), the Kernel detects this at runtime and throws a clear error path instead of crashing the stack.
182+
183+
### 3. Configuration Validation
184+
Plugins can define a Zod schema for their configuration. The Kernel automatically validates the config on load.
185+
186+
```typescript
187+
const MyPlugin = {
188+
configSchema: z.object({ apiKey: z.string() }),
189+
init(ctx) { /* ... */ }
190+
}
191+
```
192+
193+
### 4. Reliable Error Handling
194+
Factory errors (e.g., database connection failure during init) are propagated correctly up the stack, preserving the original error message for easier debugging.
195+
162196
## Built-in Plugins
163197

164198
### ObjectQLPlugin

content/docs/developers/writing-plugins.mdx

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -154,58 +154,35 @@ import { startSyncJob } from './jobs/sync';
154154
const myPlugin: Plugin = {
155155
name: 'my-crm-plugin',
156156
version: '1.0.0',
157+
dependencies: ['com.objectstack.engine.objectql'],
157158

158159
/**
159-
* Called when the plugin is enabled.
160-
* Register objects, routes, jobs, and event listeners here.
160+
* Init Phase: Register services.
161161
*/
162-
init: async (context) => {
163-
// context comes from @objectstack/core
162+
init: (context) => {
163+
// context.logger.info('Init...');
164+
},
165+
166+
/**
167+
* Start Phase: Business Logic.
168+
*/
169+
start: async (context) => {
164170
const { logger } = context;
165-
166171
logger.info('My CRM Plugin enabled');
167172

168-
/*
169-
Note: Accessing services like 'ql' or 'router' depends on
170-
what plugins are installed in the kernel.
171-
const ql = context.getService('objectql');
172-
*/
173-
},
174-
175-
// Register custom objects
176-
await ql.registerObject(Account);
173+
// Get dependencies
174+
// const ql = context.getService('objectql');
177175

178-
// Register API routes
179-
registerWebhooks(router);
180-
181-
// Schedule background jobs
182-
const interval = await os.getConfig('my_crm_plugin.syncInterval');
183-
scheduler.schedule('sync-accounts', `*/${interval} * * * *`, () => {
184-
return startSyncJob(context);
185-
});
186-
187-
// Listen to events
188-
ql.on('account.created', async (event) => {
189-
logger.info('New account created', { id: event.record.id });
190-
await storage.set(`last_account_id`, event.record.id);
191-
});
192-
},
193-
194-
/**
195-
* Called when the plugin is disabled.
196-
* Clean up resources here.
197-
*/
198-
onDisable: async (context: PluginContext) => {
199-
context.logger.info('My CRM Plugin disabled');
200-
// Unregister listeners, close connections, etc.
176+
// Logic here
177+
// await ql.registerObject(Account);
201178
},
202179

203180
/**
204-
* Called when plugin settings are updated.
181+
* Destroy Phase: Cleanup.
205182
*/
206-
onSettingsChange: async (context: PluginContext, oldSettings, newSettings) => {
207-
context.logger.info('Settings updated', { oldSettings, newSettings });
208-
},
183+
destroy: async () => {
184+
console.log('Plugin stopped');
185+
}
209186
};
210187
```
211188

content/docs/references/packages.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ description: Complete reference of all ObjectStack packages in the monorepo
77

88
ObjectStack is distributed as a monorepo containing **10 packages** organized into core packages and plugins.
99

10+
> **Note for AI Agents**: Each package's `README.md` contains a specific "AI Development Context" section describing its architectural role and usage rules.
11+
1012
## Package Overview
1113

1214
| Category | Count | Description |

0 commit comments

Comments
 (0)