s9n-devops-agent 2.0.14 → 2.0.18-dev.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.
@@ -0,0 +1,743 @@
1
+ # DevOps Agent Instructions for Contract Generation
2
+
3
+ **Created:** 2024-12-02
4
+ **Version:** 1.0.0
5
+ **Purpose:** Instructions for DevOps Agent to generate and maintain contract files
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ This document provides step-by-step instructions for the **DevOps Agent** to:
12
+
13
+ 1. **Generate initial contract files** from existing codebase
14
+ 2. **Populate contracts** with discovered information
15
+ 3. **Maintain and update contracts** as code changes
16
+ 4. **Execute coding agent scripts** to automate contract generation
17
+ 5. **Validate contract completeness** and accuracy
18
+
19
+ ---
20
+
21
+ ## Phase 1: Initial Contract Generation
22
+
23
+ ### Objective
24
+
25
+ Scan the entire codebase and generate populated contract files for:
26
+ - Database schema
27
+ - SQL queries
28
+ - API endpoints
29
+ - Third-party integrations
30
+ - Features
31
+ - Infrastructure/environment variables
32
+
33
+ ### Prerequisites
34
+
35
+ - Repository cloned and accessible
36
+ - Read access to all source files
37
+ - Write access to `House_Rules_Contracts/` folder
38
+
39
+ ---
40
+
41
+ ## Step 1: Identify All Features
42
+
43
+ **Goal:** Create a comprehensive list of all features in the codebase.
44
+
45
+ ### Process:
46
+
47
+ 1. **Scan directory structure:**
48
+ ```bash
49
+ find src/ -type d -name "features" -o -name "modules"
50
+ ls -la src/features/ src/modules/
51
+ ```
52
+
53
+ 2. **Identify feature folders:**
54
+ - Look for: `src/features/*/`, `src/modules/*/`
55
+ - Each folder typically represents a feature
56
+
57
+ 3. **Analyze API routes:**
58
+ ```bash
59
+ # Find route definitions
60
+ grep -r "app.get\|app.post\|app.put\|app.delete\|router\." src/ --include="*.js"
61
+ grep -r "@app.route\|@router\." src/ --include="*.py"
62
+ ```
63
+
64
+ 4. **Group endpoints by feature:**
65
+ - `/api/v1/users/*` → User Management feature
66
+ - `/api/v1/auth/*` → Authentication feature
67
+ - `/api/v1/products/*` → Product Management feature
68
+
69
+ 5. **Check documentation:**
70
+ ```bash
71
+ find docs/ -name "*feature*" -o -name "*spec*" -o -name "*requirement*"
72
+ ```
73
+
74
+ 6. **Create feature list:**
75
+ - Assign Feature IDs: F-001, F-002, F-003, etc.
76
+ - Write feature names and brief descriptions
77
+ - Categorize by priority (Critical, High, Medium, Low)
78
+
79
+ ### Output:
80
+
81
+ Create initial `FEATURES_CONTRACT.md` with feature list:
82
+
83
+ ```markdown
84
+ ## Feature Overview
85
+
86
+ | Feature ID | Feature Name | Status | Owner Module | Priority | Completion |
87
+ |------------|--------------|--------|--------------|----------|------------|
88
+ | F-001 | User Authentication | Active | src/features/auth | Critical | 100% |
89
+ | F-002 | User Profile Management | Active | src/features/profile | High | 100% |
90
+ | F-003 | Product Catalog | Active | src/features/products | High | 80% |
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Step 2: Document Database Schema
96
+
97
+ **Goal:** Extract all database tables, columns, indexes, and relationships.
98
+
99
+ ### Process:
100
+
101
+ 1. **Find database migration files:**
102
+ ```bash
103
+ find . -path "*/migrations/*" -name "*.sql" -o -name "*.js" -o -name "*.py"
104
+ find . -path "*/alembic/*" -name "*.py"
105
+ ```
106
+
107
+ 2. **Find ORM model definitions:**
108
+ ```bash
109
+ # Sequelize (Node.js)
110
+ grep -r "sequelize.define\|class.*Model" src/ --include="*.js"
111
+
112
+ # SQLAlchemy (Python)
113
+ grep -r "class.*Base\|Column\|Table" src/ --include="*.py"
114
+
115
+ # Prisma
116
+ find . -name "schema.prisma"
117
+ ```
118
+
119
+ 3. **Extract CREATE TABLE statements:**
120
+ ```bash
121
+ grep -r "CREATE TABLE" . --include="*.sql"
122
+ ```
123
+
124
+ 4. **For each table, document:**
125
+ - Table name
126
+ - All columns (name, type, nullable, default, constraints)
127
+ - Primary keys
128
+ - Foreign keys
129
+ - Indexes
130
+ - Which modules/features use it
131
+
132
+ 5. **Identify relationships:**
133
+ - One-to-many
134
+ - Many-to-many
135
+ - Foreign key references
136
+
137
+ ### Output:
138
+
139
+ Populate `DATABASE_SCHEMA_CONTRACT.md` with all tables:
140
+
141
+ ```markdown
142
+ ### Table: users
143
+
144
+ **Created:** 2024-01-15
145
+ **Last Modified:** 2024-01-15
146
+ **Purpose:** Stores user account information
147
+
148
+ #### Schema Definition
149
+
150
+ \```sql
151
+ CREATE TABLE users (
152
+ id SERIAL PRIMARY KEY,
153
+ email VARCHAR(255) UNIQUE NOT NULL,
154
+ password_hash VARCHAR(255) NOT NULL,
155
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
156
+ );
157
+ \```
158
+
159
+ **Used By (Modules):**
160
+ - `auth-service` - User authentication
161
+ - `profile-service` - Profile management
162
+ ```
163
+
164
+ ---
165
+
166
+ ## Step 3: Extract SQL Queries
167
+
168
+ **Goal:** Find all SQL queries and document them in reusable format.
169
+
170
+ ### Process:
171
+
172
+ 1. **Search for SQL queries:**
173
+ ```bash
174
+ # Raw SQL strings
175
+ grep -r "SELECT\|INSERT\|UPDATE\|DELETE" src/ --include="*.js" --include="*.py"
176
+
177
+ # Database query calls
178
+ grep -r "db.query\|pool.query\|connection.execute" src/ --include="*.js"
179
+ grep -r "session.query\|db.session" src/ --include="*.py"
180
+ ```
181
+
182
+ 2. **Find SQL files:**
183
+ ```bash
184
+ find . -name "*.sql" -not -path "*/migrations/*"
185
+ find . -path "*/queries/*" -name "*.sql"
186
+ ```
187
+
188
+ 3. **For each unique query, extract:**
189
+ - SQL statement
190
+ - Parameters (?, $1, :param)
191
+ - Return type (single row, multiple rows, affected count)
192
+ - Which files/functions use it
193
+
194
+ 4. **Identify query patterns:**
195
+ - User lookup by email: `SELECT * FROM users WHERE email = $1`
196
+ - Product search: `SELECT * FROM products WHERE name LIKE $1`
197
+ - Order creation: `INSERT INTO orders (...) VALUES (...)`
198
+
199
+ 5. **Group similar queries:**
200
+ - Can they be parameterized into one reusable query?
201
+ - Example: `get_user_by_email` and `get_user_by_id` → `get_user_by_field`
202
+
203
+ ### Output:
204
+
205
+ Populate `SQL_CONTRACT.json` with all queries:
206
+
207
+ ```json
208
+ {
209
+ "queries": {
210
+ "get_user_by_email": {
211
+ "id": "get_user_by_email",
212
+ "name": "Get User By Email",
213
+ "sql": "SELECT id, email, username FROM users WHERE email = $1",
214
+ "parameters": [
215
+ {
216
+ "name": "email",
217
+ "type": "string",
218
+ "required": true
219
+ }
220
+ ],
221
+ "used_by_modules": [
222
+ {
223
+ "module": "auth-service",
224
+ "file": "src/auth/login.js",
225
+ "function": "authenticateUser"
226
+ }
227
+ ]
228
+ }
229
+ }
230
+ }
231
+ ```
232
+
233
+ ---
234
+
235
+ ## Step 4: Document API Endpoints
236
+
237
+ **Goal:** Extract all API endpoints with full specifications.
238
+
239
+ ### Process:
240
+
241
+ 1. **Find route definitions:**
242
+ ```bash
243
+ # Express (Node.js)
244
+ grep -r "app.get\|app.post\|app.put\|app.delete\|router\." src/ --include="*.js"
245
+
246
+ # FastAPI (Python)
247
+ grep -r "@app.get\|@app.post\|@router\." src/ --include="*.py"
248
+
249
+ # Flask (Python)
250
+ grep -r "@app.route\|@blueprint.route" src/ --include="*.py"
251
+ ```
252
+
253
+ 2. **For each endpoint, extract:**
254
+ - HTTP method (GET, POST, PUT, DELETE)
255
+ - Path (`/api/v1/users/{id}`)
256
+ - Controller/handler function
257
+ - Request parameters (path, query, body)
258
+ - Response format
259
+ - Authentication requirements
260
+ - Which feature it belongs to
261
+
262
+ 3. **Trace endpoint implementation:**
263
+ - Find controller function
264
+ - Find service layer calls
265
+ - Find database queries used
266
+ - Find third-party integrations called
267
+
268
+ 4. **Document request/response schemas:**
269
+ - Look for validation schemas (Joi, Pydantic, etc.)
270
+ - Check request body parsing
271
+ - Check response formatting
272
+
273
+ ### Output:
274
+
275
+ Populate `API_CONTRACT.md` with all endpoints:
276
+
277
+ ```markdown
278
+ #### `GET /api/v1/users/{id}`
279
+
280
+ **Description:** Retrieves a single user by ID
281
+
282
+ **Authentication Required:** YES
283
+ **Required Roles:** `user`, `admin`
284
+
285
+ **Path Parameters:**
286
+ | Parameter | Type | Required | Description |
287
+ |-----------|------|----------|-------------|
288
+ | `id` | integer | YES | User ID |
289
+
290
+ **Response (200 OK):**
291
+ \```json
292
+ {
293
+ "success": true,
294
+ "data": {
295
+ "id": 123,
296
+ "username": "john_doe",
297
+ "email": "john@example.com"
298
+ }
299
+ }
300
+ \```
301
+
302
+ **Implementation:**
303
+ - Controller: `src/api/controllers/UserController.js::getUser()`
304
+ - Service: `src/services/UserService.js::getUserById()`
305
+ - SQL Query: `get_user_by_id` (from SQL_CONTRACT.json)
306
+ ```
307
+
308
+ ---
309
+
310
+ ## Step 5: Document Third-Party Integrations
311
+
312
+ **Goal:** Find all external service integrations and document them.
313
+
314
+ ### Process:
315
+
316
+ 1. **Search for third-party SDKs:**
317
+ ```bash
318
+ # Check package.json
319
+ cat package.json | grep -E "stripe|sendgrid|aws-sdk|twilio|mailgun"
320
+
321
+ # Check requirements.txt (Python)
322
+ cat requirements.txt | grep -E "stripe|sendgrid|boto3|twilio"
323
+ ```
324
+
325
+ 2. **Find API client initialization:**
326
+ ```bash
327
+ # Stripe
328
+ grep -r "require('stripe')\|import stripe" src/ --include="*.js" --include="*.py"
329
+
330
+ # SendGrid
331
+ grep -r "require('@sendgrid/mail')\|import sendgrid" src/ --include="*.js" --include="*.py"
332
+
333
+ # AWS
334
+ grep -r "require('aws-sdk')\|import boto3" src/ --include="*.js" --include="*.py"
335
+ ```
336
+
337
+ 3. **Find API calls:**
338
+ ```bash
339
+ # Look for external API URLs
340
+ grep -r "https://api\." src/ --include="*.js" --include="*.py"
341
+ ```
342
+
343
+ 4. **For each integration, document:**
344
+ - Service name and purpose
345
+ - SDK/library used
346
+ - API key environment variable
347
+ - Binding module location
348
+ - Which modules use it
349
+ - API endpoints called
350
+ - Error handling strategy
351
+
352
+ 5. **Check for binding modules:**
353
+ ```bash
354
+ find src/integrations/ -type d
355
+ ls -la src/integrations/*/
356
+ ```
357
+
358
+ ### Output:
359
+
360
+ Populate `THIRD_PARTY_INTEGRATIONS.md`:
361
+
362
+ ```markdown
363
+ ### SendGrid (Email Service)
364
+
365
+ **Purpose:** Transactional email delivery
366
+
367
+ **Authentication:**
368
+ - Method: API Key
369
+ - Key Location: `SENDGRID_API_KEY`
370
+
371
+ **Binding Module:**
372
+ - Location: `src/integrations/sendgrid/`
373
+ - Main File: `src/integrations/sendgrid/client.js`
374
+
375
+ **Used By Modules:**
376
+ | Module | File | Usage |
377
+ |--------|------|-------|
378
+ | auth-service | `src/auth/register.js` | Email verification |
379
+ | auth-service | `src/auth/password-reset.js` | Password reset emails |
380
+ ```
381
+
382
+ ---
383
+
384
+ ## Step 6: Document Infrastructure
385
+
386
+ **Goal:** Extract all environment variables and configuration.
387
+
388
+ ### Process:
389
+
390
+ 1. **Find all environment variable usage:**
391
+ ```bash
392
+ # Node.js
393
+ grep -r "process.env\." src/ --include="*.js" | sort | uniq
394
+
395
+ # Python
396
+ grep -r "os.getenv\|os.environ" src/ --include="*.py" | sort | uniq
397
+ ```
398
+
399
+ 2. **Check configuration files:**
400
+ ```bash
401
+ cat .env.example
402
+ cat config/*.js
403
+ cat config/*.py
404
+ ```
405
+
406
+ 3. **Check Docker/deployment configs:**
407
+ ```bash
408
+ cat docker-compose.yml | grep -A 5 "environment:"
409
+ cat .github/workflows/*.yml | grep "env:"
410
+ ```
411
+
412
+ 4. **For each environment variable, document:**
413
+ - Name
414
+ - Type (string, integer, boolean)
415
+ - Required or optional
416
+ - Default value
417
+ - Description
418
+ - Example value
419
+ - Which modules use it
420
+
421
+ 5. **Categorize variables:**
422
+ - `DATABASE_*` - Database config
423
+ - `REDIS_*` - Cache config
424
+ - `JWT_*` - Authentication config
425
+ - `[SERVICE]_*` - Third-party services
426
+ - `FEATURE_*` - Feature flags
427
+
428
+ ### Output:
429
+
430
+ Populate `INFRA_CONTRACT.md`:
431
+
432
+ ```markdown
433
+ ### Database Configuration
434
+
435
+ | Variable | Type | Required | Default | Description | Example |
436
+ |----------|------|----------|---------|-------------|---------|
437
+ | `DATABASE_URL` | string | YES | - | Database connection string | `postgresql://...` |
438
+ | `DATABASE_POOL_MAX` | integer | NO | `20` | Max connection pool size | `20` |
439
+ ```
440
+
441
+ ---
442
+
443
+ ## Step 7: Cross-Reference All Contracts
444
+
445
+ **Goal:** Link related information across contracts.
446
+
447
+ ### Process:
448
+
449
+ 1. **For each feature in FEATURES_CONTRACT.md:**
450
+ - List API endpoints (link to API_CONTRACT.md)
451
+ - List database tables (link to DATABASE_SCHEMA_CONTRACT.md)
452
+ - List SQL queries (link to SQL_CONTRACT.json)
453
+ - List third-party services (link to THIRD_PARTY_INTEGRATIONS.md)
454
+ - List environment variables (link to INFRA_CONTRACT.md)
455
+
456
+ 2. **For each API endpoint in API_CONTRACT.md:**
457
+ - Link to feature that owns it
458
+ - Link to SQL queries it uses
459
+ - Link to database tables it accesses
460
+ - Link to third-party services it calls
461
+
462
+ 3. **For each database table in DATABASE_SCHEMA_CONTRACT.md:**
463
+ - Link to features that use it
464
+ - Link to SQL queries that access it
465
+ - Link to API endpoints that modify it
466
+
467
+ 4. **Verify consistency:**
468
+ - Every SQL query references existing tables
469
+ - Every API endpoint references existing queries
470
+ - Every feature references existing endpoints
471
+ - Every third-party integration has env vars documented
472
+
473
+ ---
474
+
475
+ ## Phase 2: Automated Contract Generation & Validation Script
476
+
477
+ ### Task: Create `validate-contracts` Automation
478
+
479
+ **Objective:** Create a script that strictly validates that the code matches the contracts. This script will eventually be part of the CI/CD pipeline and pre-commit hooks.
480
+
481
+ **Script Name:** `scripts/validate-contracts.js`
482
+
483
+ **Requirements:**
484
+ 1. **Drift Detection:**
485
+ * Fail if an API endpoint exists in code but not in `API_CONTRACT.md`.
486
+ * Fail if a database table exists in migrations but not in `DATABASE_SCHEMA_CONTRACT.md`.
487
+ * Fail if a Feature ID is referenced in code but missing from `FEATURES_CONTRACT.md`.
488
+ 2. **Schema Validation:**
489
+ * Verify JSON contracts (`SQL_CONTRACT.json`) are valid JSON.
490
+ 3. **Cross-Reference Validation:**
491
+ * Verify that links between contracts point to existing items.
492
+
493
+ **Execution:**
494
+ `npm run validate-contracts`
495
+
496
+ ### Task: Create `generate-contracts` Script
497
+
498
+ The DevOps Agent can invoke a Coding Agent to automate contract generation:
499
+
500
+ **Script Name:** `generate-contracts.js` or `generate-contracts.py`
501
+
502
+ **Script Responsibilities:**
503
+
504
+ 1. **Scan codebase** using the patterns above
505
+ 2. **Extract information** for each contract
506
+ 3. **Generate contract files** from templates
507
+ 4. **Populate with discovered data**
508
+ 5. **Cross-reference** all contracts
509
+ 6. **Validate completeness**
510
+ 7. **Report missing information** for manual review
511
+
512
+ **Execution:**
513
+
514
+ ```bash
515
+ # DevOps Agent executes:
516
+ node scripts/generate-contracts.js
517
+
518
+ # Or for Python:
519
+ python scripts/generate_contracts.py
520
+ ```
521
+
522
+ **Output:**
523
+
524
+ - Populated contract files in `House_Rules_Contracts/`
525
+ - Report of discovered items
526
+ - List of items needing manual review
527
+ - Validation errors or warnings
528
+
529
+ ---
530
+
531
+ ## Phase 3: Iterative Contract Improvement
532
+
533
+ ### Process:
534
+
535
+ 1. **Initial generation** (automated script)
536
+ 2. **Manual review** (DevOps Agent or human)
537
+ 3. **Fill gaps** (add missing information)
538
+ 4. **Validate cross-references** (ensure links are correct)
539
+ 5. **Test completeness** (can coding agents use contracts?)
540
+ 6. **Iterate** (improve as codebase evolves)
541
+
542
+ ### Validation Checklist:
543
+
544
+ - [ ] All features documented in FEATURES_CONTRACT.md
545
+ - [ ] All database tables documented in DATABASE_SCHEMA_CONTRACT.md
546
+ - [ ] All SQL queries documented in SQL_CONTRACT.json
547
+ - [ ] All API endpoints documented in API_CONTRACT.md
548
+ - [ ] All third-party services documented in THIRD_PARTY_INTEGRATIONS.md
549
+ - [ ] All environment variables documented in INFRA_CONTRACT.md
550
+ - [ ] All cross-references are correct
551
+ - [ ] All "Used By" sections are complete
552
+ - [ ] All examples are accurate
553
+ - [ ] All dates and versions are set
554
+
555
+ ---
556
+
557
+ ## Phase 5: Test Coverage Tracking
558
+
559
+ **Goal:** Explicitly track which Contracts are validated by tests.
560
+
561
+ ### Create `TEST_COVERAGE.md`
562
+ Create a file to map contracts to their test suites.
563
+
564
+ **Template:**
565
+ ```markdown
566
+ # Test Coverage Matrix
567
+
568
+ | Contract Item | Test File | Test Status | Last Verified |
569
+ |---------------|-----------|-------------|---------------|
570
+ | **Features** | | | |
571
+ | F-001 | `test_cases/features/auth.test.js` | ✅ Passing | 2024-12-10 |
572
+ | **API** | | | |
573
+ | GET /api/v1/users | `test_cases/api/users.test.js` | ✅ Passing | 2024-12-10 |
574
+ ```
575
+
576
+ ### Repo Hygiene
577
+ - Ensure `House_Rules_Contracts/` only contains active contracts.
578
+ - Move deprecated or superseded contracts to `House_Rules_Contracts/archive/`.
579
+
580
+ ### When Code Changes:
581
+
582
+ **Coding agents MUST update contracts when they:**
583
+
584
+ 1. **Add a new feature** → Update FEATURES_CONTRACT.md
585
+ 2. **Create a database table** → Update DATABASE_SCHEMA_CONTRACT.md
586
+ 3. **Write a SQL query** → Update SQL_CONTRACT.json
587
+ 4. **Create an API endpoint** → Update API_CONTRACT.md
588
+ 5. **Integrate a service** → Update THIRD_PARTY_INTEGRATIONS.md
589
+ 6. **Add an env variable** → Update INFRA_CONTRACT.md
590
+
591
+ ### DevOps Agent Responsibilities:
592
+
593
+ 1. **Monitor contract updates** in commits
594
+ 2. **Validate contract changes** are correct
595
+ 3. **Enforce contract usage** by coding agents
596
+ 4. **Regenerate contracts** periodically to catch missed updates
597
+ 5. **Report discrepancies** between code and contracts
598
+
599
+ ### Periodic Validation:
600
+
601
+ **Run automated validation script:**
602
+
603
+ ```bash
604
+ # Check if contracts match codebase
605
+ node scripts/validate-contracts.js
606
+
607
+ # Report:
608
+ # - Features in code but not in FEATURES_CONTRACT.md
609
+ # - Endpoints in code but not in API_CONTRACT.md
610
+ # - Tables in migrations but not in DATABASE_SCHEMA_CONTRACT.md
611
+ # - Queries in code but not in SQL_CONTRACT.json
612
+ # - Services in package.json but not in THIRD_PARTY_INTEGRATIONS.md
613
+ # - Env vars in code but not in INFRA_CONTRACT.md
614
+ ```
615
+
616
+ ---
617
+
618
+ ## Example: Automated Contract Generation Script
619
+
620
+ ### Pseudocode:
621
+
622
+ ```javascript
623
+ // generate-contracts.js
624
+
625
+ const fs = require('fs');
626
+ const path = require('path');
627
+ const glob = require('glob');
628
+
629
+ async function generateContracts() {
630
+ console.log('Starting contract generation...');
631
+
632
+ // Step 1: Scan for features
633
+ const features = await scanFeatures();
634
+ console.log(`Found ${features.length} features`);
635
+
636
+ // Step 2: Scan database schema
637
+ const tables = await scanDatabaseSchema();
638
+ console.log(`Found ${tables.length} tables`);
639
+
640
+ // Step 3: Extract SQL queries
641
+ const queries = await extractSQLQueries();
642
+ console.log(`Found ${queries.length} unique queries`);
643
+
644
+ // Step 4: Extract API endpoints
645
+ const endpoints = await extractAPIEndpoints();
646
+ console.log(`Found ${endpoints.length} endpoints`);
647
+
648
+ // Step 5: Find third-party integrations
649
+ const integrations = await findThirdPartyIntegrations();
650
+ console.log(`Found ${integrations.length} integrations`);
651
+
652
+ // Step 6: Extract environment variables
653
+ const envVars = await extractEnvVariables();
654
+ console.log(`Found ${envVars.length} environment variables`);
655
+
656
+ // Step 7: Generate contract files
657
+ await generateFeaturesContract(features);
658
+ await generateDatabaseContract(tables);
659
+ await generateSQLContract(queries);
660
+ await generateAPIContract(endpoints);
661
+ await generateIntegrationsContract(integrations);
662
+ await generateInfraContract(envVars);
663
+
664
+ // Step 8: Cross-reference
665
+ await crossReferenceContracts();
666
+
667
+ console.log('Contract generation complete!');
668
+ }
669
+
670
+ async function scanFeatures() {
671
+ // Find all feature folders
672
+ const featureDirs = glob.sync('src/features/*/');
673
+
674
+ const features = [];
675
+ for (const dir of featureDirs) {
676
+ const featureName = path.basename(dir);
677
+ const files = glob.sync(`${dir}**/*.js`);
678
+
679
+ features.push({
680
+ id: `F-${String(features.length + 1).padStart(3, '0')}`,
681
+ name: featureName,
682
+ files: files,
683
+ // Extract more details...
684
+ });
685
+ }
686
+
687
+ return features;
688
+ }
689
+
690
+ async function scanDatabaseSchema() {
691
+ // Find migration files
692
+ const migrations = glob.sync('migrations/**/*.sql');
693
+
694
+ const tables = [];
695
+ for (const file of migrations) {
696
+ const content = fs.readFileSync(file, 'utf8');
697
+ const tableMatches = content.match(/CREATE TABLE (\w+)/g);
698
+
699
+ if (tableMatches) {
700
+ for (const match of tableMatches) {
701
+ const tableName = match.replace('CREATE TABLE ', '');
702
+ // Extract columns, indexes, etc.
703
+ tables.push({
704
+ name: tableName,
705
+ // ... more details
706
+ });
707
+ }
708
+ }
709
+ }
710
+
711
+ return tables;
712
+ }
713
+
714
+ // ... more functions
715
+
716
+ generateContracts().catch(console.error);
717
+ ```
718
+
719
+ ---
720
+
721
+ ## Summary
722
+
723
+ **DevOps Agent should:**
724
+
725
+ 1. ✅ Execute automated contract generation script
726
+ 2. ✅ Review and validate generated contracts
727
+ 3. ✅ Fill in missing information manually
728
+ 4. ✅ Ensure cross-references are correct
729
+ 5. ✅ Commit populated contracts to repository
730
+ 6. ✅ Monitor ongoing contract updates by coding agents
731
+ 7. ✅ Periodically re-run validation to catch drift
732
+ 8. ✅ Enforce contract usage in code reviews
733
+
734
+ **This ensures:**
735
+ - Contracts stay up-to-date
736
+ - Coding agents have accurate information
737
+ - Duplication is prevented
738
+ - Conflicts are avoided
739
+ - Codebase remains organized and maintainable
740
+
741
+ ---
742
+
743
+ *This document is a living guide. Update as processes improve.*