aios-core 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,6 +105,11 @@ commands:
105
105
  visibility: [full]
106
106
  description: "Planning mode before implementation"
107
107
 
108
+ # Service Generation (WIS-11)
109
+ - name: create-service
110
+ visibility: [full, quick]
111
+ description: "Create new service from Handlebars template (api-integration, utility, agent-tool)"
112
+
108
113
  # Quality & Debt
109
114
  - name: apply-qa-fixes
110
115
  visibility: [quick, key]
@@ -152,6 +157,7 @@ dependencies:
152
157
  - story-dod-checklist.md
153
158
  tasks:
154
159
  - apply-qa-fixes.md
160
+ - create-service.md # WIS-11: Service scaffolding from templates
155
161
  - dev-develop-story.md
156
162
  - execute-checklist.md
157
163
  - dev-improve-code-quality.md
@@ -322,6 +328,7 @@ dependencies:
322
328
  **Story Development:**
323
329
  - `*develop {story-id}` - Implement story tasks
324
330
  - `*run-tests` - Execute linting and tests
331
+ - `*create-service` - Scaffold new service from template
325
332
 
326
333
  **Quality & Debt:**
327
334
  - `*apply-qa-fixes` - Apply QA fixes
@@ -0,0 +1,391 @@
1
+ # Create Service
2
+
3
+ ## Purpose
4
+
5
+ Create a new service using standardized Handlebars templates from WIS-10. Generates consistent TypeScript service structures with proper configuration, testing, and documentation.
6
+
7
+ ## Task Definition (AIOS Task Format V1.0)
8
+
9
+ ```yaml
10
+ task: createService()
11
+ agent: "@dev"
12
+ responsável: Dex (Developer)
13
+ responsavel_type: Agente
14
+ atomic_layer: Config
15
+
16
+ elicit: true
17
+
18
+ inputs:
19
+ - name: service_name
20
+ type: string
21
+ required: true
22
+ pattern: "^[a-z][a-z0-9-]*$"
23
+ validation: Must be kebab-case, start with letter
24
+
25
+ - name: service_type
26
+ type: enum
27
+ options: ["api-integration", "utility", "agent-tool"]
28
+ required: true
29
+ default: "utility"
30
+
31
+ - name: has_auth
32
+ type: boolean
33
+ required: false
34
+ default: false
35
+
36
+ - name: description
37
+ type: string
38
+ required: true
39
+ validation: Non-empty, max 200 characters
40
+
41
+ - name: env_vars
42
+ type: array
43
+ required: false
44
+ default: []
45
+
46
+ outputs:
47
+ - name: service_directory
48
+ type: directory
49
+ location: ".aios-core/infrastructure/services/{service_name}/"
50
+ persistido: true
51
+
52
+ - name: files_created
53
+ type: array
54
+ destino: Memory
55
+ persistido: false
56
+ ```
57
+
58
+ ---
59
+
60
+ ## Pre-Conditions
61
+
62
+ ```yaml
63
+ pre-conditions:
64
+ - [ ] WIS-10 templates exist at .aios-core/development/templates/service-template/
65
+ tipo: pre-condition
66
+ blocker: true
67
+ validação: Check template directory exists with required .hbs files
68
+ error_message: "Templates not found. Run WIS-10 first."
69
+
70
+ - [ ] Service name is unique (no existing service with same name)
71
+ tipo: pre-condition
72
+ blocker: true
73
+ validação: Check .aios-core/infrastructure/services/{name}/ does not exist
74
+ error_message: "Service '{name}' already exists. Choose a different name."
75
+
76
+ - [ ] Service name follows kebab-case pattern
77
+ tipo: pre-condition
78
+ blocker: true
79
+ validação: Regex match ^[a-z][a-z0-9-]*$
80
+ error_message: "Invalid name. Use kebab-case (e.g., my-api-service)"
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Interactive Elicitation Process
86
+
87
+ ### Step 1: Service Name
88
+ ```
89
+ ELICIT: Service Name
90
+
91
+ What is the service name?
92
+ (Use kebab-case, e.g., "github-api", "file-processor", "auth-helper")
93
+
94
+ → Validation: ^[a-z][a-z0-9-]*$
95
+ → Check: Unique (not existing)
96
+ → On invalid: Re-prompt with error message
97
+ ```
98
+
99
+ ### Step 2: Service Type
100
+ ```
101
+ ELICIT: Service Type
102
+
103
+ What type of service is this?
104
+
105
+ 1. api-integration - External API client with rate limiting and auth
106
+ 2. utility - Internal helper/utility service
107
+ 3. agent-tool - Tool for AIOS agents
108
+
109
+ → Default: utility
110
+ → If api-integration: Enable client.ts generation
111
+ ```
112
+
113
+ ### Step 3: Authentication
114
+ ```
115
+ ELICIT: Authentication Required
116
+
117
+ Does this service require authentication?
118
+
119
+ 1. Yes - Include auth configuration and secure headers
120
+ 2. No - No authentication needed
121
+
122
+ → Default: No
123
+ → If Yes: Add auth placeholders to config
124
+ ```
125
+
126
+ ### Step 4: Description
127
+ ```
128
+ ELICIT: Service Description
129
+
130
+ Brief description of the service:
131
+ (Max 200 characters, will appear in README and JSDoc)
132
+
133
+ → Validation: Non-empty, <= 200 chars
134
+ ```
135
+
136
+ ### Step 5: Environment Variables
137
+ ```
138
+ ELICIT: Environment Variables
139
+
140
+ What environment variables does this service need?
141
+ (Enter comma-separated list, or 'none')
142
+
143
+ Examples: API_KEY, BASE_URL, TIMEOUT_MS
144
+
145
+ → Default: none
146
+ → Parse: Split by comma, trim whitespace
147
+ → Generate: .env.example entries
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Implementation Steps
153
+
154
+ ### Step 1: Validate Inputs
155
+ ```javascript
156
+ // Validate service_name
157
+ const namePattern = /^[a-z][a-z0-9-]*$/;
158
+ if (!namePattern.test(serviceName)) {
159
+ throw new Error(`Invalid service name: ${serviceName}. Use kebab-case.`);
160
+ }
161
+
162
+ // Check uniqueness
163
+ const targetDir = `.aios-core/infrastructure/services/${serviceName}/`;
164
+ if (fs.existsSync(targetDir)) {
165
+ throw new Error(`Service '${serviceName}' already exists.`);
166
+ }
167
+ ```
168
+
169
+ ### Step 2: Load Templates
170
+ ```javascript
171
+ const templateDir = '.aios-core/development/templates/service-template/';
172
+ const templates = [
173
+ 'README.md.hbs',
174
+ 'index.ts.hbs',
175
+ 'types.ts.hbs',
176
+ 'errors.ts.hbs',
177
+ 'package.json.hbs',
178
+ 'tsconfig.json', // Static (no .hbs)
179
+ 'jest.config.js', // Static (no .hbs)
180
+ '__tests__/index.test.ts.hbs'
181
+ ];
182
+
183
+ // Conditional: client.ts.hbs only for api-integration
184
+ if (serviceType === 'api-integration') {
185
+ templates.push('client.ts.hbs');
186
+ }
187
+ ```
188
+
189
+ ### Step 3: Prepare Template Context
190
+ ```javascript
191
+ const context = {
192
+ serviceName: serviceName, // kebab-case
193
+ pascalCase: toPascalCase(serviceName), // PascalCase
194
+ camelCase: toCamelCase(serviceName), // camelCase
195
+ description: description,
196
+ isApiIntegration: serviceType === 'api-integration',
197
+ hasAuth: hasAuth,
198
+ envVars: envVars.map(v => ({
199
+ name: v,
200
+ description: `${v} environment variable`
201
+ })),
202
+ storyId: 'WIS-11',
203
+ createdAt: new Date().toISOString().split('T')[0]
204
+ };
205
+ ```
206
+
207
+ ### Step 4: Generate Files
208
+ ```javascript
209
+ // Create target directory
210
+ fs.mkdirSync(targetDir, { recursive: true });
211
+ fs.mkdirSync(`${targetDir}__tests__/`, { recursive: true });
212
+
213
+ // Process each template
214
+ for (const templateFile of templates) {
215
+ const templatePath = `${templateDir}${templateFile}`;
216
+ const isHandlebars = templateFile.endsWith('.hbs');
217
+
218
+ // Determine output filename
219
+ const outputFile = isHandlebars
220
+ ? templateFile.replace('.hbs', '')
221
+ : templateFile;
222
+ const outputPath = `${targetDir}${outputFile}`;
223
+
224
+ if (isHandlebars) {
225
+ // Render Handlebars template
226
+ const template = fs.readFileSync(templatePath, 'utf8');
227
+ const compiled = Handlebars.compile(template);
228
+ const content = compiled(context);
229
+ fs.writeFileSync(outputPath, content);
230
+ } else {
231
+ // Copy static file
232
+ fs.copyFileSync(templatePath, outputPath);
233
+ }
234
+ }
235
+ ```
236
+
237
+ ### Step 5: Post-Generation
238
+ ```bash
239
+ # Navigate to service directory
240
+ cd .aios-core/infrastructure/services/{service_name}/
241
+
242
+ # Install dependencies
243
+ npm install
244
+
245
+ # Build TypeScript
246
+ npm run build
247
+
248
+ # Run tests
249
+ npm test
250
+ ```
251
+
252
+ ---
253
+
254
+ ## Handlebars Helpers Required
255
+
256
+ The following helpers must be available:
257
+
258
+ ```javascript
259
+ Handlebars.registerHelper('pascalCase', (str) => {
260
+ return str.split('-').map(word =>
261
+ word.charAt(0).toUpperCase() + word.slice(1)
262
+ ).join('');
263
+ });
264
+
265
+ Handlebars.registerHelper('camelCase', (str) => {
266
+ const pascal = str.split('-').map(word =>
267
+ word.charAt(0).toUpperCase() + word.slice(1)
268
+ ).join('');
269
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
270
+ });
271
+
272
+ Handlebars.registerHelper('kebabCase', (str) => {
273
+ return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
274
+ });
275
+
276
+ Handlebars.registerHelper('upperCase', (str) => {
277
+ return str.toUpperCase().replace(/-/g, '_');
278
+ });
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Post-Conditions
284
+
285
+ ```yaml
286
+ post-conditions:
287
+ - [ ] All template files generated successfully
288
+ tipo: post-condition
289
+ blocker: true
290
+ validação: Verify all expected files exist in target directory
291
+
292
+ - [ ] TypeScript compiles without errors
293
+ tipo: post-condition
294
+ blocker: false
295
+ validação: Run npm run build, check exit code
296
+
297
+ - [ ] Tests pass
298
+ tipo: post-condition
299
+ blocker: false
300
+ validação: Run npm test, check exit code
301
+ ```
302
+
303
+ ---
304
+
305
+ ## Error Handling
306
+
307
+ | Error | Cause | Resolution |
308
+ |-------|-------|------------|
309
+ | Service name exists | Directory already present | Prompt for different name |
310
+ | Template not found | WIS-10 not installed | Error: "Run WIS-10 first" |
311
+ | npm install fails | Network/package issues | Warning, continue without deps |
312
+ | Build fails | TypeScript errors | Warning, show errors, continue |
313
+ | Invalid name format | Name not kebab-case | Re-prompt with validation error |
314
+
315
+ **Error Recovery Strategy:**
316
+ ```javascript
317
+ // Atomic generation - rollback on failure
318
+ try {
319
+ generateAllFiles(targetDir, templates, context);
320
+ } catch (error) {
321
+ // Clean up partial files
322
+ if (fs.existsSync(targetDir)) {
323
+ fs.rmSync(targetDir, { recursive: true, force: true });
324
+ }
325
+ throw error;
326
+ }
327
+ ```
328
+
329
+ ---
330
+
331
+ ## Performance
332
+
333
+ ```yaml
334
+ duration_expected: 5-30s (excluding npm install)
335
+ cost_estimated: $0.002-0.005
336
+ token_usage: ~1,000-2,000 tokens
337
+ ```
338
+
339
+ ---
340
+
341
+ ## Success Output
342
+
343
+ ```
344
+ ============================================
345
+ SERVICE CREATED SUCCESSFULLY
346
+ ============================================
347
+
348
+ Service: {service_name}
349
+ Type: {service_type}
350
+ Location: .aios-core/infrastructure/services/{service_name}/
351
+
352
+ Files Created:
353
+ README.md
354
+ index.ts
355
+ types.ts
356
+ errors.ts
357
+ client.ts (if api-integration)
358
+ package.json
359
+ tsconfig.json
360
+ jest.config.js
361
+ __tests__/index.test.ts
362
+
363
+ Next Steps:
364
+ 1. cd .aios-core/infrastructure/services/{service_name}
365
+ 2. Review generated code
366
+ 3. Implement service methods in index.ts
367
+ 4. Add tests in __tests__/
368
+ 5. Update environment variables as needed
369
+
370
+ ============================================
371
+ ```
372
+
373
+ ---
374
+
375
+ ## Metadata
376
+
377
+ ```yaml
378
+ story: WIS-11
379
+ version: 1.0.0
380
+ created: 2025-12-24
381
+ author: "@dev (Dex)"
382
+ dependencies:
383
+ templates:
384
+ - service-template/ (from WIS-10)
385
+ tasks: []
386
+ tags:
387
+ - service-generation
388
+ - scaffolding
389
+ - handlebars
390
+ - typescript
391
+ ```
@@ -0,0 +1,158 @@
1
+ # {{pascalCase serviceName}} Service
2
+
3
+ > {{description}}
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @aios/{{kebabCase serviceName}}
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { create{{pascalCase serviceName}}Service } from '@aios/{{kebabCase serviceName}}';
15
+
16
+ const service = create{{pascalCase serviceName}}Service({
17
+ {{#each envVars}}
18
+ {{camelCase this.name}}: process.env.{{this.name}},
19
+ {{/each}}
20
+ });
21
+
22
+ // Use the service
23
+ const result = await service.execute();
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ ### Environment Variables
29
+
30
+ | Variable | Required | Description |
31
+ |----------|----------|-------------|
32
+ {{#each envVars}}
33
+ | `{{this.name}}` | {{#if this.required}}Yes{{else}}No{{/if}} | {{this.description}} |
34
+ {{/each}}
35
+
36
+ ### Programmatic Configuration
37
+
38
+ ```typescript
39
+ import { create{{pascalCase serviceName}}Service, {{pascalCase serviceName}}Config } from '@aios/{{kebabCase serviceName}}';
40
+
41
+ const config: {{pascalCase serviceName}}Config = {
42
+ {{#each envVars}}
43
+ {{camelCase this.name}}: '{{this.example}}',
44
+ {{/each}}
45
+ };
46
+
47
+ const service = create{{pascalCase serviceName}}Service(config);
48
+ ```
49
+
50
+ {{#if isApiIntegration}}
51
+ ## API Integration
52
+
53
+ This service integrates with an external API. Features include:
54
+
55
+ - **Rate Limiting**: Automatic request throttling
56
+ - **Retry Logic**: Exponential backoff on failures
57
+ - **Error Handling**: Typed errors with actionable messages
58
+
59
+ ### Rate Limits
60
+
61
+ > **Note:** The values below are placeholders. Update them according to your API's actual rate limits.
62
+
63
+ | Tier | Requests/min | Burst |
64
+ |------|--------------|-------|
65
+ | Free | 60 | 10 |
66
+ | Pro | 600 | 100 |
67
+
68
+ {{/if}}
69
+ ## Usage Examples
70
+
71
+ ### Basic Usage
72
+
73
+ ```typescript
74
+ const service = create{{pascalCase serviceName}}Service(config);
75
+
76
+ try {
77
+ const result = await service.execute();
78
+ console.log('Success:', result);
79
+ } catch (error) {
80
+ if (error instanceof {{pascalCase serviceName}}Error) {
81
+ console.error('Service error:', error.code, error.message);
82
+ }
83
+ throw error;
84
+ }
85
+ ```
86
+
87
+ {{#if hasAuth}}
88
+ ### Authentication
89
+
90
+ This service requires authentication. Set your credentials via environment variables or config:
91
+
92
+ ```typescript
93
+ const service = create{{pascalCase serviceName}}Service({
94
+ apiKey: process.env.{{upperCase serviceName}}_API_KEY,
95
+ // or
96
+ accessToken: process.env.{{upperCase serviceName}}_ACCESS_TOKEN,
97
+ });
98
+ ```
99
+
100
+ {{/if}}
101
+ ## Error Handling
102
+
103
+ The service provides typed errors for common failure scenarios:
104
+
105
+ ```typescript
106
+ import { {{pascalCase serviceName}}Error, {{pascalCase serviceName}}ErrorCode } from '@aios/{{kebabCase serviceName}}';
107
+
108
+ try {
109
+ await service.execute();
110
+ } catch (error) {
111
+ if (error instanceof {{pascalCase serviceName}}Error) {
112
+ switch (error.code) {
113
+ case {{pascalCase serviceName}}ErrorCode.CONFIGURATION_ERROR:
114
+ // Handle configuration issues
115
+ break;
116
+ case {{pascalCase serviceName}}ErrorCode.NETWORK_ERROR:
117
+ // Handle network issues
118
+ break;
119
+ {{#if isApiIntegration}}
120
+ case {{pascalCase serviceName}}ErrorCode.RATE_LIMIT_EXCEEDED:
121
+ // Handle rate limiting
122
+ break;
123
+ {{/if}}
124
+ default:
125
+ // Handle other errors
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ ## API Reference
132
+
133
+ See the [TypeScript definitions](./dist/types.d.ts) for complete API documentation.
134
+
135
+ ## Development
136
+
137
+ ```bash
138
+ # Install dependencies
139
+ npm install
140
+
141
+ # Run tests
142
+ npm test
143
+
144
+ # Build
145
+ npm run build
146
+
147
+ # Type check
148
+ npm run typecheck
149
+ ```
150
+
151
+ ## License
152
+
153
+ MIT
154
+
155
+ ---
156
+
157
+ *Generated by AIOS-FullStack Service Template*
158
+ *Story: {{storyId}}*