kiro-spec-engine 1.13.1 → 1.15.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,53 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.15.0] - 2026-01-30
11
+
12
+ ### Added
13
+ - **.gitignore Auto-Fix for Team Collaboration**: Automatic detection and fixing of .gitignore configuration
14
+ - Detects old blanket `.kiro/` exclusion patterns that prevent Spec sharing
15
+ - Replaces with layered strategy: commit Specs, exclude personal state
16
+ - Integrated into `kse adopt` and `kse upgrade` flows (automatic)
17
+ - Standalone command: `kse doctor --fix-gitignore`
18
+ - Creates backup before modification (stored in `.kiro/backups/gitignore-{timestamp}`)
19
+ - Preserves all user rules (non-.kiro patterns)
20
+ - Handles different line endings (CRLF/LF) correctly
21
+ - 26 unit tests covering detection, transformation, backup, and integration
22
+
23
+ ### Technical Details
24
+ - **GitignoreDetector**: Analyzes .gitignore status (missing, old-pattern, incomplete, compliant)
25
+ - **GitignoreTransformer**: Applies layered exclusion strategy while preserving user rules
26
+ - **GitignoreBackup**: Creates timestamped backups with metadata
27
+ - **GitignoreIntegration**: Coordinates detection → backup → transform → report
28
+ - **Layered Strategy**: Commits `.kiro/specs/` while excluding personal state (CURRENT_CONTEXT.md, environments.json, backups/, logs/)
29
+ - **Cross-platform**: Preserves original line ending style (CRLF on Windows, LF on Unix)
30
+
31
+ ### Documentation
32
+ - Updated `docs/adoption-guide.md` with .gitignore auto-fix information
33
+ - Updated `docs/upgrade-guide.md` with .gitignore verification steps
34
+ - Comprehensive `docs/team-collaboration-guide.md` already exists (500+ lines)
35
+
36
+ ## [1.14.0] - 2026-01-30
37
+
38
+ ### Added
39
+ - **Environment Configuration Management**: Lightweight multi-environment configuration system
40
+ - Register and manage multiple environment configurations (development, staging, production, etc.)
41
+ - Quick environment switching with automatic file copying
42
+ - Automatic backup system before each switch (maintains up to 10 backups per file)
43
+ - Rollback capability to restore previous environment state
44
+ - Support for multiple configuration file mappings per environment
45
+ - Environment verification with custom commands (optional)
46
+ - Commands: `kse env list`, `kse env switch`, `kse env info`, `kse env register`, `kse env unregister`, `kse env rollback`
47
+ - Comprehensive user documentation in `docs/environment-management-guide.md`
48
+ - 66 unit tests covering all core functionality
49
+
50
+ ### Technical Details
51
+ - **EnvironmentRegistry**: JSON-based persistent storage (`.kiro/environments.json`)
52
+ - **EnvironmentManager**: Core logic for environment operations
53
+ - **BackupSystem**: Automatic backup/restore with history management
54
+ - **CLI Integration**: Seamless integration with existing kse commands
55
+ - **Cross-platform**: Consistent behavior on Windows, Linux, and Mac
56
+
10
57
  ## [1.13.1] - 2026-01-29
11
58
 
12
59
  ### Fixed
@@ -176,6 +176,7 @@ program
176
176
  .command('doctor')
177
177
  .description(t('cli.commands.doctor.description'))
178
178
  .option('--docs', 'Show detailed document governance diagnostics')
179
+ .option('--fix-gitignore', 'Check and fix .gitignore for team collaboration')
179
180
  .action((options) => {
180
181
  doctorCommand(options);
181
182
  });
@@ -460,6 +461,18 @@ workspaceCmd
460
461
  await workspaceCommand.infoWorkspace(name);
461
462
  });
462
463
 
464
+ // Environment configuration management commands
465
+ const envCommand = require('../lib/commands/env');
466
+
467
+ const envCmd = program
468
+ .command('env <subcommand> [args...]')
469
+ .description('Manage environment configurations');
470
+
471
+ envCmd.action(async (subcommand, args, options) => {
472
+ const exitCode = await envCommand.handleCommand([subcommand, ...args]);
473
+ process.exit(exitCode);
474
+ });
475
+
463
476
  // 更新项目配置的辅助函数
464
477
  async function updateProjectConfig(projectName) {
465
478
  const envPath = path.join(process.cwd(), '.kiro/steering/ENVIRONMENT.md');
@@ -576,20 +576,27 @@ your-project/
576
576
 
577
577
  After successful adoption:
578
578
 
579
- 1. **Create your first spec**:
579
+ 1. **Verify .gitignore configuration**:
580
+ The adoption process automatically checks and fixes your `.gitignore` for team collaboration. If you see a warning about .gitignore, you can manually fix it:
581
+ ```bash
582
+ kse doctor --fix-gitignore
583
+ ```
584
+ Learn more: [Team Collaboration Guide](./team-collaboration-guide.md)
585
+
586
+ 2. **Create your first spec**:
580
587
  ```bash
581
588
  kse create-spec 01-00-my-feature
582
589
  ```
583
590
 
584
- 2. **Check project status**:
591
+ 3. **Check project status**:
585
592
  ```bash
586
593
  kse status
587
594
  ```
588
595
 
589
- 3. **Read the spec workflow guide**:
596
+ 4. **Read the spec workflow guide**:
590
597
  - See `.kiro/specs/SPEC_WORKFLOW_GUIDE.md`
591
598
 
592
- 4. **Explore Ultrawork**:
599
+ 5. **Explore Ultrawork**:
593
600
  ```bash
594
601
  kse enhance requirements .kiro/specs/01-00-my-feature/requirements.md
595
602
  ```
@@ -0,0 +1,526 @@
1
+ # Environment Configuration Management Guide
2
+
3
+ ## Overview
4
+
5
+ The Environment Configuration Management feature provides a lightweight solution for managing multiple environment configurations (development, staging, production, etc.) within your kse projects.
6
+
7
+ ## Quick Start
8
+
9
+ ### Installation and Project Adoption
10
+
11
+ **⚠️ Important**: When you install kse in a project, it automatically adopts the project and operates in autonomous mode by default. This means:
12
+
13
+ - ✅ kse takes ownership of the project structure
14
+ - ✅ AI assistants can make changes autonomously without frequent confirmations
15
+ - ✅ Faster development workflow with less interruption
16
+ - ✅ All changes are tracked and can be rolled back if needed
17
+
18
+ **Recommended Workflow**:
19
+
20
+ ```bash
21
+ # Install kse globally or in your project
22
+ npm install -g kiro-spec-engine
23
+
24
+ # Navigate to your project
25
+ cd your-project
26
+
27
+ # Check project status first (recommended)
28
+ kse status
29
+
30
+ # If issues are detected, run diagnostics
31
+ kse doctor
32
+
33
+ # Adopt the project (creates .kiro/ directory)
34
+ kse adopt
35
+
36
+ # kse is now managing your project autonomously
37
+ ```
38
+
39
+ **Note**: Future versions of kse will automatically check project status after installation/upgrade and prompt for diagnostics if needed.
40
+
41
+ ### 1. Register an Environment
42
+
43
+ Create a configuration file (e.g., `env-local.json`):
44
+
45
+ ```json
46
+ {
47
+ "name": "local-dev",
48
+ "description": "Local development environment",
49
+ "config_files": [
50
+ {
51
+ "source": ".env.local",
52
+ "target": ".env"
53
+ },
54
+ {
55
+ "source": "config/database.local.json",
56
+ "target": "config/database.json"
57
+ }
58
+ ]
59
+ }
60
+ ```
61
+
62
+ Register the environment:
63
+
64
+ ```bash
65
+ kse env register env-local.json
66
+ ```
67
+
68
+ ### 2. List Environments
69
+
70
+ ```bash
71
+ kse env list
72
+ ```
73
+
74
+ ### 3. Switch Environments
75
+
76
+ ```bash
77
+ kse env switch local-dev
78
+ ```
79
+
80
+ The system automatically:
81
+ - Creates a backup of existing target files
82
+ - Copies source files to target locations
83
+ - Updates the active environment
84
+
85
+ ### 4. View Active Environment
86
+
87
+ ```bash
88
+ kse env info
89
+ ```
90
+
91
+ ### 5. Rollback
92
+
93
+ If something goes wrong, rollback to the previous state:
94
+
95
+ ```bash
96
+ kse env rollback
97
+ ```
98
+
99
+ ## Commands
100
+
101
+ ### `kse env list`
102
+
103
+ List all registered environments with their status.
104
+
105
+ ### `kse env switch <name>`
106
+
107
+ Switch to the specified environment. Creates automatic backups before switching.
108
+
109
+ ### `kse env info`
110
+
111
+ Display details about the currently active environment.
112
+
113
+ ### `kse env register <config-file>`
114
+
115
+ Register a new environment from a JSON configuration file.
116
+
117
+ ### `kse env unregister <name> --force`
118
+
119
+ Remove an environment from the registry. Requires `--force` flag for confirmation.
120
+
121
+ ### `kse env rollback`
122
+
123
+ Restore the most recent backup, reverting to the previous environment state.
124
+
125
+ ### `kse env verify`
126
+
127
+ Verify the current environment configuration by running the verification command defined in the environment. If no verification rules are configured, reports success.
128
+
129
+ ### `kse env run "<command>"`
130
+
131
+ Run a command in the context of the current environment. Ensures the active environment is set before executing the command.
132
+
133
+ ## Configuration File Format
134
+
135
+ ```json
136
+ {
137
+ "name": "environment-name",
138
+ "description": "Human-readable description",
139
+ "config_files": [
140
+ {
141
+ "source": "path/to/source/file",
142
+ "target": "path/to/target/file"
143
+ }
144
+ ],
145
+ "verification": {
146
+ "command": "node verify.js",
147
+ "expected_output": "OK"
148
+ }
149
+ }
150
+ ```
151
+
152
+ ### Fields
153
+
154
+ - **name** (required): Unique environment name in kebab-case
155
+ - **description** (required): Human-readable description
156
+ - **config_files** (required): Array of source-to-target file mappings
157
+ - **verification** (optional): Verification command and expected output
158
+
159
+ ## Backup System
160
+
161
+ The backup system automatically:
162
+ - Creates timestamped backups before each environment switch
163
+ - Maintains up to 10 backups per target file
164
+ - Stores backups in `.kiro/env-backups/`
165
+ - Automatically cleans up old backups
166
+
167
+ ## Best Practices
168
+
169
+ 1. **Adopt projects with kse**: Run `kse adopt` to let kse manage your project autonomously, enabling faster AI-assisted development without constant confirmations
170
+ 2. **Use descriptive names**: Choose clear, descriptive names for your environments
171
+ 3. **Keep source files in version control**: Store all environment-specific configuration files in your repository
172
+ 4. **Selective .kiro/ version control**: Use layered .gitignore strategy:
173
+ - ✅ **DO commit**: `.kiro/specs/` (Spec documents), `.kiro/steering/CORE_PRINCIPLES.md`, `.kiro/steering/ENVIRONMENT.md`, `.kiro/steering/RULES_GUIDE.md`, `.kiro/tools/`, `.kiro/config/`
174
+ - ❌ **DO NOT commit**: `.kiro/steering/CURRENT_CONTEXT.md` (personal context), `.kiro/environments.json` (user-specific), `.kiro/backups/`, `.kiro/logs/`, `.kiro/reports/`
175
+ - **Why**: Share Spec documents and team rules, but avoid conflicts from personal state and user-specific configurations
176
+ 5. **Share environment templates**: Commit environment configuration JSON files (e.g., `env-local.json`, `env-production.json`) to your repository root or a `config/` directory, not in `.kiro/`
177
+ 6. **Test switches**: Test environment switches in a safe environment before using in production
178
+ 7. **Regular backups**: The system creates automatic backups, but consider additional backup strategies for critical configurations
179
+ 8. **Document verification**: Add verification rules to catch configuration errors early
180
+
181
+ ## Examples
182
+
183
+ ### Example 1: Simple Development/Production Setup
184
+
185
+ ```json
186
+ {
187
+ "name": "development",
188
+ "description": "Local development environment",
189
+ "config_files": [
190
+ { "source": ".env.development", "target": ".env" }
191
+ ]
192
+ }
193
+ ```
194
+
195
+ ```json
196
+ {
197
+ "name": "production",
198
+ "description": "Production environment",
199
+ "config_files": [
200
+ { "source": ".env.production", "target": ".env" }
201
+ ],
202
+ "verification": {
203
+ "command": "node scripts/verify-env.js",
204
+ "expected_output": "production"
205
+ }
206
+ }
207
+ ```
208
+
209
+ ### Example 2: Multiple Configuration Files
210
+
211
+ ```json
212
+ {
213
+ "name": "staging",
214
+ "description": "Staging environment with database and API configs",
215
+ "config_files": [
216
+ { "source": ".env.staging", "target": ".env" },
217
+ { "source": "config/database.staging.json", "target": "config/database.json" },
218
+ { "source": "config/api.staging.json", "target": "config/api.json" }
219
+ ]
220
+ }
221
+ ```
222
+
223
+ ## Troubleshooting
224
+
225
+ ### "Source file does not exist"
226
+
227
+ Ensure all source files specified in your configuration exist before registering or switching environments.
228
+
229
+ ### "Environment already exists"
230
+
231
+ Each environment must have a unique name. Use `kse env unregister <name> --force` to remove the existing environment first.
232
+
233
+ ### "Cannot unregister active environment"
234
+
235
+ Switch to a different environment before unregistering the currently active one.
236
+
237
+ ### "No backups available to restore"
238
+
239
+ Backups are only created during environment switches. If you haven't switched environments yet, there won't be any backups to restore.
240
+
241
+ ## Integration with Multi-Workspace
242
+
243
+ When using kse's multi-workspace feature, each workspace maintains its own independent environment registry. This allows different projects to have different environment configurations without interference.
244
+
245
+ ## See Also
246
+
247
+ - [Multi-Workspace Management](../README.md#multi-workspace-management)
248
+ - [Command Reference](command-reference.md)
249
+
250
+
251
+ ## Migration Guide
252
+
253
+ ### Migrating from Manual Configuration Management
254
+
255
+ If you're currently managing environment configurations manually (e.g., copying files, using shell scripts), here's how to migrate to kse environment management:
256
+
257
+ #### Step 1: Identify Your Environments
258
+
259
+ List all the environments you currently manage:
260
+ - Development (local)
261
+ - Staging
262
+ - Production
263
+ - Testing
264
+ - etc.
265
+
266
+ #### Step 2: Identify Configuration Files
267
+
268
+ For each environment, identify which files need to be switched:
269
+ - `.env` files
270
+ - Configuration files (e.g., `config/database.json`, `config/app.json`)
271
+ - API endpoint configurations
272
+ - Feature flags
273
+ - etc.
274
+
275
+ #### Step 3: Create Source Files
276
+
277
+ Create source files for each environment. Use a naming convention like:
278
+ - `.env.local` → `.env`
279
+ - `.env.staging` → `.env`
280
+ - `.env.production` → `.env`
281
+ - `config/database.local.json` → `config/database.json`
282
+
283
+ **Example structure**:
284
+ ```
285
+ your-project/
286
+ ├── .env.local # Source for local environment
287
+ ├── .env.staging # Source for staging environment
288
+ ├── .env.production # Source for production environment
289
+ ├── config/
290
+ │ ├── database.local.json
291
+ │ ├── database.staging.json
292
+ │ └── database.production.json
293
+ ```
294
+
295
+ #### Step 4: Create Environment Configuration Files
296
+
297
+ For each environment, create a JSON configuration file:
298
+
299
+ **local-env.json**:
300
+ ```json
301
+ {
302
+ "name": "local",
303
+ "description": "Local development environment",
304
+ "config_files": [
305
+ {
306
+ "source": ".env.local",
307
+ "target": ".env"
308
+ },
309
+ {
310
+ "source": "config/database.local.json",
311
+ "target": "config/database.json"
312
+ }
313
+ ],
314
+ "verification": {
315
+ "command": "node scripts/verify-env.js",
316
+ "expected_output": "Environment: local"
317
+ }
318
+ }
319
+ ```
320
+
321
+ **staging-env.json**:
322
+ ```json
323
+ {
324
+ "name": "staging",
325
+ "description": "Staging environment",
326
+ "config_files": [
327
+ {
328
+ "source": ".env.staging",
329
+ "target": ".env"
330
+ },
331
+ {
332
+ "source": "config/database.staging.json",
333
+ "target": "config/database.json"
334
+ }
335
+ ],
336
+ "verification": {
337
+ "command": "node scripts/verify-env.js",
338
+ "expected_output": "Environment: staging"
339
+ }
340
+ }
341
+ ```
342
+
343
+ #### Step 5: Register Environments
344
+
345
+ Register each environment with kse:
346
+
347
+ ```bash
348
+ kse env register local-env.json
349
+ kse env register staging-env.json
350
+ kse env register production-env.json
351
+ ```
352
+
353
+ #### Step 6: Verify Registration
354
+
355
+ List all registered environments:
356
+
357
+ ```bash
358
+ kse env list
359
+ ```
360
+
361
+ #### Step 7: Test Environment Switching
362
+
363
+ Switch to an environment and verify:
364
+
365
+ ```bash
366
+ # Switch to local environment
367
+ kse env switch local
368
+
369
+ # Verify the switch
370
+ kse env info
371
+
372
+ # Verify configuration is correct
373
+ kse env verify
374
+ ```
375
+
376
+ #### Step 8: Update Your Workflow
377
+
378
+ Replace your manual configuration management with kse commands:
379
+
380
+ **Before**:
381
+ ```bash
382
+ # Manual approach
383
+ cp .env.local .env
384
+ cp config/database.local.json config/database.json
385
+ ```
386
+
387
+ **After**:
388
+ ```bash
389
+ # kse approach
390
+ kse env switch local
391
+ ```
392
+
393
+ #### Step 9: Add to .gitignore
394
+
395
+ Add target files to `.gitignore` to avoid committing environment-specific configurations:
396
+
397
+ ```gitignore
398
+ # Environment target files (managed by kse)
399
+ .env
400
+ config/database.json
401
+ config/app.json
402
+
403
+ # Keep source files in version control
404
+ !.env.local
405
+ !.env.staging
406
+ !.env.production
407
+ !config/database.*.json
408
+ ```
409
+
410
+ ### Migrating from Other Tools
411
+
412
+ #### From direnv
413
+
414
+ If you're using direnv, you can migrate by:
415
+
416
+ 1. Keep your `.envrc` files as source files
417
+ 2. Create kse environment configurations that copy `.envrc.local` → `.envrc`
418
+ 3. Continue using direnv for environment variable loading
419
+ 4. Use kse for switching between environment configurations
420
+
421
+ #### From Docker Compose
422
+
423
+ If you're using Docker Compose with multiple environment files:
424
+
425
+ 1. Keep your `docker-compose.yml` and environment-specific files
426
+ 2. Create kse environments that switch between different compose files
427
+ 3. Use kse to manage which compose configuration is active
428
+
429
+ **Example**:
430
+ ```json
431
+ {
432
+ "name": "docker-local",
433
+ "description": "Docker local environment",
434
+ "config_files": [
435
+ {
436
+ "source": "docker-compose.local.yml",
437
+ "target": "docker-compose.override.yml"
438
+ },
439
+ {
440
+ "source": ".env.docker.local",
441
+ "target": ".env"
442
+ }
443
+ ]
444
+ }
445
+ ```
446
+
447
+ #### From Kubernetes ConfigMaps
448
+
449
+ If you're using Kubernetes ConfigMaps for configuration:
450
+
451
+ 1. Export ConfigMaps to local files for development
452
+ 2. Create kse environments for local development
453
+ 3. Use kse for local environment switching
454
+ 4. Keep ConfigMaps for production deployments
455
+
456
+ ### Best Practices for Migration
457
+
458
+ 1. **Start Small**: Begin with one or two environments, test thoroughly, then add more
459
+ 2. **Backup First**: Create backups of your current configuration files before migration
460
+ 3. **Test Verification**: Create verification scripts to ensure environment correctness
461
+ 4. **Document**: Document your environment configurations and switching procedures
462
+ 5. **Team Communication**: Inform your team about the new workflow and provide training
463
+ 6. **Gradual Rollout**: Migrate one project at a time, learn from each migration
464
+
465
+ ### Common Migration Issues
466
+
467
+ #### Issue: Source Files Don't Exist
468
+
469
+ **Problem**: Trying to register an environment but source files are missing.
470
+
471
+ **Solution**: Create source files first, then register the environment.
472
+
473
+ ```bash
474
+ # Create source file
475
+ cp .env .env.local
476
+
477
+ # Register environment
478
+ kse env register local-env.json
479
+ ```
480
+
481
+ #### Issue: Target Files Already Exist
482
+
483
+ **Problem**: Target files exist and you're worried about overwriting them.
484
+
485
+ **Solution**: kse automatically creates backups before switching. You can also manually backup first.
486
+
487
+ ```bash
488
+ # Manual backup (optional, kse does this automatically)
489
+ cp .env .env.backup
490
+
491
+ # Switch environment (creates automatic backup)
492
+ kse env switch local
493
+
494
+ # If needed, rollback
495
+ kse env rollback
496
+ ```
497
+
498
+ #### Issue: Verification Fails
499
+
500
+ **Problem**: Environment verification fails after switching.
501
+
502
+ **Solution**: Check the verification command and expected output. Update the environment configuration if needed.
503
+
504
+ ```bash
505
+ # Check what went wrong
506
+ kse env verify
507
+
508
+ # Update environment configuration
509
+ # Edit the JSON file and re-register
510
+ kse env register local-env.json
511
+ ```
512
+
513
+ ### Migration Checklist
514
+
515
+ - [ ] Identify all environments
516
+ - [ ] Identify all configuration files
517
+ - [ ] Create source files for each environment
518
+ - [ ] Create environment configuration JSON files
519
+ - [ ] Register all environments with kse
520
+ - [ ] Test switching between environments
521
+ - [ ] Create verification scripts (optional but recommended)
522
+ - [ ] Update .gitignore
523
+ - [ ] Update team documentation
524
+ - [ ] Train team members on new workflow
525
+ - [ ] Remove old manual scripts
526
+