chati-dev 2.1.2 → 3.0.1

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.
Files changed (95) hide show
  1. package/README.md +95 -24
  2. package/bin/chati.js +1 -1
  3. package/framework/agents/build/dev.md +1 -0
  4. package/framework/agents/deploy/devops.md +1 -0
  5. package/framework/agents/discover/brief.md +1 -0
  6. package/framework/agents/discover/brownfield-wu.md +1 -0
  7. package/framework/agents/discover/greenfield-wu.md +1 -0
  8. package/framework/agents/plan/architect.md +1 -0
  9. package/framework/agents/plan/detail.md +1 -0
  10. package/framework/agents/plan/phases.md +3 -2
  11. package/framework/agents/plan/tasks.md +1 -0
  12. package/framework/agents/plan/ux.md +1 -0
  13. package/framework/agents/quality/qa-implementation.md +1 -0
  14. package/framework/agents/quality/qa-planning.md +1 -0
  15. package/framework/config.yaml +21 -2
  16. package/framework/constitution.md +67 -2
  17. package/framework/context/governance.md +16 -3
  18. package/framework/context/root.md +3 -3
  19. package/framework/data/entity-registry.yaml +1 -1
  20. package/framework/domains/agents/brownfield-wu.yaml +4 -0
  21. package/framework/domains/agents/detail.yaml +1 -1
  22. package/framework/domains/agents/dev.yaml +4 -0
  23. package/framework/domains/agents/orchestrator.yaml +8 -0
  24. package/framework/domains/agents/phases.yaml +2 -2
  25. package/framework/domains/agents/tasks.yaml +2 -2
  26. package/framework/domains/constitution.yaml +30 -2
  27. package/framework/domains/global.yaml +20 -0
  28. package/framework/hooks/model-governance.js +17 -15
  29. package/framework/hooks/read-protection.js +1 -0
  30. package/framework/i18n/en.yaml +11 -4
  31. package/framework/i18n/es.yaml +11 -4
  32. package/framework/i18n/fr.yaml +11 -4
  33. package/framework/i18n/pt.yaml +11 -4
  34. package/framework/intelligence/context-engine.md +31 -2
  35. package/framework/intelligence/decision-engine.md +1 -1
  36. package/framework/intelligence/memory-layer.md +17 -0
  37. package/framework/orchestrator/chati.md +94 -14
  38. package/framework/patterns/elicitation-library.yaml +2 -2
  39. package/framework/schemas/config.schema.json +44 -0
  40. package/framework/schemas/session.schema.json +27 -0
  41. package/framework/tasks/brownfield-wu-dependency-scan.md +1 -1
  42. package/framework/tasks/brownfield-wu-migration-plan.md +4 -4
  43. package/framework/tasks/brownfield-wu-risk-assess.md +2 -2
  44. package/framework/tasks/detail-expand-prd.md +2 -2
  45. package/framework/tasks/greenfield-wu-report.md +1 -1
  46. package/framework/tasks/orchestrator-handoff.md +2 -2
  47. package/framework/tasks/orchestrator-resume.md +1 -1
  48. package/framework/tasks/qa-impl-performance-test.md +2 -2
  49. package/framework/tasks/qa-impl-sast-scan.md +6 -6
  50. package/framework/tasks/qa-planning-consolidate.md +1 -1
  51. package/framework/tasks/qa-planning-coverage-plan.md +9 -9
  52. package/framework/tasks/qa-planning-gate-define.md +6 -6
  53. package/framework/tasks/qa-planning-risk-matrix.md +1 -1
  54. package/framework/tasks/tasks-consolidate.md +5 -5
  55. package/package.json +5 -1
  56. package/scripts/changelog-generator.js +2 -2
  57. package/scripts/ide-sync.js +9 -4
  58. package/scripts/pr-review.js +5 -5
  59. package/scripts/semantic-lint.js +3 -3
  60. package/src/autonomy/build-loop.js +194 -0
  61. package/src/autonomy/build-state.js +269 -0
  62. package/src/autonomy/execution-profile.js +151 -0
  63. package/src/config/context-file-generator.js +203 -0
  64. package/src/config/ide-configs.js +6 -6
  65. package/src/gates/g2-qa-planning.js +4 -2
  66. package/src/gates/g4-qa-implementation.js +5 -2
  67. package/src/gates/gate-base.js +33 -1
  68. package/src/health/engine.js +245 -0
  69. package/src/installer/core.js +54 -16
  70. package/src/installer/templates.js +131 -2
  71. package/src/installer/validator.js +5 -3
  72. package/src/intelligence/file-tracker.js +117 -0
  73. package/src/intelligence/registry-manager.js +2 -2
  74. package/src/intelligence/timeline.js +144 -0
  75. package/src/memory/gotchas-auto-capture.js +253 -0
  76. package/src/preview/detector.js +1 -1
  77. package/src/terminal/adapters/claude-adapter.js +33 -0
  78. package/src/terminal/adapters/codex-adapter.js +31 -0
  79. package/src/terminal/adapters/copilot-adapter.js +28 -0
  80. package/src/terminal/adapters/gemini-adapter.js +28 -0
  81. package/src/terminal/adapters/index.js +8 -0
  82. package/src/terminal/cli-registry.js +190 -0
  83. package/src/terminal/prompt-builder.js +9 -20
  84. package/src/terminal/run-agent.js +2 -1
  85. package/src/terminal/spawner.js +44 -14
  86. package/src/terminal/wave-analyzer.js +143 -0
  87. package/src/utils/config-parser.js +97 -0
  88. package/src/wizard/feedback.js +1 -1
  89. package/src/wizard/i18n.js +11 -4
  90. package/src/wizard/index.js +22 -10
  91. package/src/wizard/questions.js +50 -2
  92. package/framework/manifest.json +0 -5
  93. package/framework/manifest.sig +0 -1
  94. /package/assets/{logo - co/314/201pia.png" → logo - c/303/263pia.png"} +0 -0
  95. /package/assets/{logo - co/314/201pia.svg" → logo - c/303/263pia.svg"} +0 -0
@@ -67,18 +67,18 @@ Present options and recommend:
67
67
 
68
68
  ### 3. Define Migration Phases
69
69
  Break migration into phases (typically 4-8 phases):
70
- - **Phase 0: Preparation**
70
+ - **Phase 1: Preparation**
71
71
  - Set up monitoring and observability
72
72
  - Increase test coverage for critical paths
73
73
  - Document current behavior
74
74
  - Fix critical security issues
75
75
  - Set up feature flags
76
- - **Phase 1: Foundation**
76
+ - **Phase 2: Foundation**
77
77
  - Update dependencies to secure versions
78
78
  - Standardize tooling (linting, formatting, testing)
79
79
  - Resolve circular dependencies
80
80
  - Set up CI/CD if missing
81
- - **Phase 2-N: Incremental Changes**
81
+ - **Phase 3-N: Incremental Changes**
82
82
  - Each phase targets a specific subsystem or concern
83
83
  - Maintain working system at end of each phase
84
84
  - Deploy and validate before next phase
@@ -152,7 +152,7 @@ For each phase, document:
152
152
  - Add 20-30% buffer for unknowns
153
153
  - Calculate calendar time based on:
154
154
  - Team size
155
- - Velocity (story points per sprint)
155
+ - Velocity (estimated hours per phase)
156
156
  - Availability (not 100% on migration)
157
157
  - Dependencies and waiting time
158
158
  - Provide optimistic, realistic, and pessimistic timelines
@@ -159,7 +159,7 @@ For each identified risk:
159
159
  ### 9. Prioritize Risks
160
160
  Sort risks by risk score descending:
161
161
  - **Critical Priority (Score 70-100)**: Address immediately
162
- - **High Priority (Score 40-69)**: Address in next sprint
162
+ - **High Priority (Score 40-69)**: Address in next phase
163
163
  - **Medium Priority (Score 20-39)**: Address within 3 months
164
164
  - **Low Priority (Score 1-19)**: Monitor, address when convenient
165
165
 
@@ -419,6 +419,6 @@ total_remediation_effort:
419
419
  next_steps:
420
420
  - Address 3 critical security risks immediately
421
421
  - Create detailed remediation plan for high priority risks
422
- - Schedule technical debt reduction sprints
422
+ - Schedule technical debt reduction phases
423
423
  - Set up monitoring to track new risks
424
424
  ```
@@ -10,7 +10,7 @@ handoff_to: detail-nfr-extraction
10
10
  autonomous_gate: true
11
11
  criteria:
12
12
  - All functional requirements expanded with details
13
- - User stories written in Given-When-Then format
13
+ - Requirements written in Given-When-Then format
14
14
  - Data models identified
15
15
  - API endpoints outlined
16
16
  ---
@@ -30,7 +30,7 @@ Read brief.yaml and extract all requirements and context.
30
30
  ### 2. Expand Each Functional Requirement
31
31
  For each FR, add:
32
32
  - **Description**: Detailed explanation of what it does
33
- - **User Story**: As a [persona], I want [action] so that [benefit]
33
+ - **Requirement**: As a [persona], I want [action] so that [benefit]
34
34
  - **Acceptance Criteria**: Given-When-Then scenarios
35
35
  - **Priority**: P0 (must-have), P1 (should-have), P2 (nice-to-have)
36
36
  - **Estimated Complexity**: Small (1-3 days), Medium (4-7 days), Large (8+ days)
@@ -98,7 +98,7 @@ Provide ordered list of immediate actions:
98
98
  ### 9. Add Recommendations
99
99
  Include actionable recommendations:
100
100
  - **Immediate**: Actions to take before writing code
101
- - **Short-term**: Set up during first sprint (CI/CD, testing)
101
+ - **Short-term**: Set up during Phase 1 (CI/CD, testing)
102
102
  - **Medium-term**: Add as project matures (monitoring, documentation site)
103
103
  - **Long-term**: Consider for scale (microservices, caching layers)
104
104
 
@@ -175,7 +175,7 @@ handoff_document:
175
175
 
176
176
  summary: |
177
177
  Completed detailed requirements analysis for HealthCare Portal.
178
- Identified 12 user stories across 4 modules (Authentication, Patient Records,
178
+ Identified 12 requirements across 4 modules (Authentication, Patient Records,
179
179
  Appointments, Billing). Mapped 3 external integrations (Payment Gateway,
180
180
  Insurance API, Lab Results). Defined data model with 8 core entities.
181
181
 
@@ -186,7 +186,7 @@ handoff_document:
186
186
  size_kb: 45
187
187
  - path: ".chati/artifacts/requirements/user-stories.yaml"
188
188
  type: "structured-data"
189
- description: "12 user stories with acceptance criteria"
189
+ description: "12 requirements with acceptance criteria"
190
190
  size_kb: 8
191
191
  - path: ".chati/artifacts/requirements/integrations.yaml"
192
192
  type: "structured-data"
@@ -173,7 +173,7 @@ session_state:
173
173
  file: ".chati/artifacts/handoffs/2026-02-13-detail.md"
174
174
  key_outputs:
175
175
  - "Functional requirements document"
176
- - "12 user stories identified"
176
+ - "12 requirements identified"
177
177
  - "3 external integrations mapped"
178
178
  context_summary:
179
179
  decisions_made: 8
@@ -461,7 +461,7 @@ assessment:
461
461
 
462
462
  recommendations:
463
463
  - Current performance acceptable for release
464
- - Consider YAML parser alternatives in future optimization sprint
464
+ - Consider YAML parser alternatives in future optimization phase
465
465
  - Monitor agent execution time in production, optimize if user complaints
466
466
 
467
467
  baseline_update:
@@ -477,7 +477,7 @@ next_steps:
477
477
  - Update performance baseline with improved metrics
478
478
  - Proceed to qa-impl-verdict (performance gate PASSED)
479
479
  - Monitor performance in production after release
480
- - Schedule optimization sprint for YAML parsing if user impact observed
480
+ - Schedule optimization phase for YAML parsing if user impact observed
481
481
 
482
482
  handoff:
483
483
  to: qa-impl-verdict
@@ -81,9 +81,9 @@ Run static analysis security testing (SAST) to identify security vulnerabilities
81
81
 
82
82
  9. **Analyze Trends (if historical data available)**
83
83
  - Compare findings with previous scan (if available)
84
- - Track new vulnerabilities introduced in this sprint
84
+ - Track new vulnerabilities introduced in this phase
85
85
  - Track resolved vulnerabilities since last scan
86
- - Calculate vulnerability velocity (new - resolved per sprint)
86
+ - Calculate vulnerability velocity (new - resolved per phase)
87
87
 
88
88
  10. **Generate Remediation Guidance**
89
89
  - For each CRITICAL/HIGH finding:
@@ -330,7 +330,7 @@ trends:
330
330
  previous_scan_date: YYYY-MM-DD (or null if first scan)
331
331
  new_vulnerabilities: 2
332
332
  resolved_vulnerabilities: 0
333
- vulnerability_velocity: +2 per sprint
333
+ vulnerability_velocity: +2 per phase
334
334
 
335
335
  remediation_roadmap:
336
336
  priority_1_blocking:
@@ -378,19 +378,19 @@ assessment:
378
378
  - Fix both HIGH severity exploitable vulnerabilities
379
379
  - Upgrade yaml package to 2.3.4+
380
380
  - Re-run SAST scan to verify fixes
381
- - Medium and low findings can be deferred to next sprint
381
+ - Medium and low findings can be deferred to next phase
382
382
 
383
383
  recommendations:
384
384
  - Priority 1: Fix SAST-001 with path validation (2 hours)
385
385
  - Priority 2: Fix SAST-002 with execFile (1 hour)
386
386
  - Priority 3: Upgrade yaml dependency (30 minutes)
387
- - Schedule code quality fixes for next sprint
387
+ - Schedule code quality fixes for next phase
388
388
 
389
389
  next_steps:
390
390
  - Return to dev agent for HIGH vulnerability remediation
391
391
  - Re-run qa-impl-sast-scan after fixes
392
392
  - If rerun passes (0 HIGH exploitable), proceed to qa-impl-regression-check
393
- - Track LOW/MEDIUM findings in backlog for future sprints
393
+ - Track LOW/MEDIUM findings in backlog for future phases
394
394
 
395
395
  handoff:
396
396
  to: dev
@@ -303,7 +303,7 @@ session_update:
303
303
 
304
304
  next_steps:
305
305
  - Orchestrator triggers dev agent (autonomous transition)
306
- - Dev agent begins Phase 0 (Installer) implementation
306
+ - Dev agent begins Phase 1 (Installer) implementation
307
307
  - QA-Implementation agent on standby for build phase
308
308
  - Revisit minor gaps during Phase 1 review
309
309
  ```
@@ -78,7 +78,7 @@ Create a detailed test coverage plan with specific targets for each module, comp
78
78
 
79
79
  8. **Establish Coverage Baselines**
80
80
  - **Initial Baseline**: Measure current coverage (if brownfield) or set 0% (if greenfield)
81
- - **Sprint Targets**: Define incremental improvement goals (e.g., +5% per sprint)
81
+ - **Phase Targets**: Define incremental improvement goals (e.g., +5% per phase)
82
82
  - **Release Targets**: Set minimum coverage for each release milestone
83
83
  - **Maintenance Target**: Steady-state coverage after initial development (e.g., 75%)
84
84
 
@@ -95,10 +95,10 @@ Create a detailed test coverage plan with specific targets for each module, comp
95
95
  - **Review Cadence**: When exception is revisited (quarterly)
96
96
 
97
97
  11. **Create Coverage Improvement Roadmap**
98
- - **Phase 0 (Installer)**: 70% target (focus on CLI and validation logic)
99
- - **Phase 1-3 (Core Agents)**: 75% target (add agent task execution tests)
100
- - **Phase 4-5 (Quality/Build)**: 80% target (comprehensive integration tests)
101
- - **Phase 6-7 (Deploy/Validate)**: 85% target (full pipeline coverage)
98
+ - **Phase 1 (Installer)**: 70% target (focus on CLI and validation logic)
99
+ - **Phase 2-4 (Core Agents)**: 75% target (add agent task execution tests)
100
+ - **Phase 5-6 (Quality/Build)**: 80% target (comprehensive integration tests)
101
+ - **Phase 7-8 (Deploy/Validate)**: 85% target (full pipeline coverage)
102
102
 
103
103
  12. **Compile Coverage Plan Document**
104
104
  - List all modules with specific targets
@@ -108,7 +108,7 @@ Create a detailed test coverage plan with specific targets for each module, comp
108
108
 
109
109
  ## Decision Points
110
110
 
111
- - **Target Adjustment for Legacy Code**: If brownfield project has existing low coverage, set realistic incremental targets rather than immediate 80% requirement. Example: 40% current → 50% sprint 1 → 60% sprint 2 → 70% sprint 3.
111
+ - **Target Adjustment for Legacy Code**: If brownfield project has existing low coverage, set realistic incremental targets rather than immediate 80% requirement. Example: 40% current → 50% Phase 1 → 60% Phase 2 → 70% Phase 3.
112
112
 
113
113
  - **Integration Test Coverage**: For external dependencies (MCPs, file system), decide between mocking (higher coverage, less realistic) vs real integration (lower coverage, more realistic). Recommend hybrid: unit tests with mocks, separate integration tests with real dependencies.
114
114
 
@@ -287,9 +287,9 @@ exceptions:
287
287
  review_date: quarterly
288
288
 
289
289
  baselines:
290
- sprint_1: 70%
291
- sprint_2: 75%
292
- sprint_3: 80%
290
+ phase_1: 70%
291
+ phase_2: 75%
292
+ phase_3: 80%
293
293
  release_1.0: 75%
294
294
  maintenance: 75%
295
295
 
@@ -73,7 +73,7 @@ Define quality gates and enforcement thresholds for each stage of the chati.dev
73
73
  7. **Establish Threshold Levels**
74
74
  - **BLOCKER**: Must fix immediately, blocks all progress (test failures, critical vulnerabilities)
75
75
  - **CRITICAL**: Must fix before merge/release (high vulnerabilities, major regressions)
76
- - **MAJOR**: Should fix in current sprint (moderate issues, technical debt)
76
+ - **MAJOR**: Should fix in current phase (moderate issues, technical debt)
77
77
  - **MINOR**: Can defer to backlog (low priority issues, enhancements)
78
78
 
79
79
  8. **Define Gate Enforcement Mechanisms**
@@ -98,7 +98,7 @@ Define quality gates and enforcement thresholds for each stage of the chati.dev
98
98
  - **Gate Pass Rate**: Track percentage of clean gate passes
99
99
  - **Bypass Frequency**: Monitor override usage patterns
100
100
  - **Time in Gate**: Measure delay caused by gate failures
101
- - **Trend Analysis**: Track improvement/degradation over sprints
101
+ - **Trend Analysis**: Track improvement/degradation over phases
102
102
 
103
103
  12. **Compile Quality Gates Document**
104
104
  - Structure gates by pipeline stage
@@ -127,7 +127,7 @@ Define quality gates and enforcement thresholds for each stage of the chati.dev
127
127
 
128
128
  **Tool Integration Failures**
129
129
  - If CI/CD pipeline cannot enforce a gate automatically, define manual checklist
130
- - Flag for devops agent to implement automation in future sprint
130
+ - Flag for devops agent to implement automation in future phase
131
131
  - Ensure interim manual process is documented
132
132
 
133
133
  ## Output Format
@@ -253,14 +253,14 @@ severity_levels:
253
253
  resolution_time: same day
254
254
 
255
255
  MAJOR:
256
- description: Fix in current sprint
256
+ description: Fix in current phase
257
257
  examples: [moderate issues, technical debt, performance degradation]
258
- resolution_time: within sprint
258
+ resolution_time: within phase
259
259
 
260
260
  MINOR:
261
261
  description: Backlog eligible
262
262
  examples: [low priority issues, enhancements, cosmetic fixes]
263
- resolution_time: next sprint or later
263
+ resolution_time: next phase or later
264
264
 
265
265
  bypass_procedures:
266
266
  deviation_protocol:
@@ -607,7 +607,7 @@ risk_evolution:
607
607
 
608
608
  mid_phase:
609
609
  focus: [regression risks, performance risks, error handling]
610
- reassessment: per sprint
610
+ reassessment: per phase
611
611
 
612
612
  late_phase:
613
613
  focus: [upgrade risks, compatibility risks, edge cases]
@@ -27,8 +27,8 @@ Merge: tasks-list.yaml, estimates.yaml, task-criteria.yaml
27
27
  Organize tasks hierarchically:
28
28
  - Phase → Feature → Tasks
29
29
 
30
- ### 3. Add Sprint Planning Hints
31
- Suggest which tasks could be grouped into sprints.
30
+ ### 3. Add Phase Planning Hints
31
+ Suggest which tasks could be grouped into phases.
32
32
 
33
33
  ### 4. Generate Final Task List
34
34
  Complete, ready for development.
@@ -40,12 +40,12 @@ timestamp: 2026-02-13T18:00:00Z
40
40
  total_tasks: 67
41
41
  total_estimated_hours: 480
42
42
  [All task details consolidated]
43
- sprint_suggestions:
44
- sprint_1:
43
+ phase_suggestions:
44
+ phase_1:
45
45
  focus: Database schema and authentication backend
46
46
  tasks: [TASK-001, TASK-002, TASK-005, TASK-006]
47
47
  estimated_hours: 60
48
- sprint_2:
48
+ phase_2:
49
49
  focus: Authentication UI and post backend
50
50
  tasks: [TASK-003, TASK-004, TASK-010, TASK-011]
51
51
  estimated_hours: 72
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chati-dev",
3
- "version": "2.1.2",
3
+ "version": "3.0.1",
4
4
  "description": "AI-Powered Multi-Agent Orchestration System — Structured vibe coding for Full Stack Development",
5
5
  "type": "module",
6
6
  "bin": {
@@ -38,6 +38,10 @@
38
38
  "multi-agent",
39
39
  "cli",
40
40
  "claude",
41
+ "gemini",
42
+ "codex",
43
+ "copilot",
44
+ "multi-llm",
41
45
  "orchestration",
42
46
  "fullstack"
43
47
  ],
@@ -7,7 +7,7 @@
7
7
  * @module scripts/changelog-generator
8
8
  */
9
9
 
10
- import { execSync } from 'node:child_process';
10
+ import { execFileSync } from 'node:child_process';
11
11
 
12
12
  /**
13
13
  * @typedef {Object} ParsedCommit
@@ -84,7 +84,7 @@ export function getGitCommits(since = null, cwd = process.cwd()) {
84
84
 
85
85
  let output;
86
86
  try {
87
- output = execSync(`git log ${range} --pretty=format:"${format}"`, {
87
+ output = execFileSync('git', ['log', range, `--pretty=format:${format}`], {
88
88
  cwd,
89
89
  encoding: 'utf-8',
90
90
  stdio: ['pipe', 'pipe', 'pipe'],
@@ -49,13 +49,13 @@ export const IDE_CONFIGS = {
49
49
  description: 'AntiGravity',
50
50
  },
51
51
  'gemini-cli': {
52
- configDir: '.gemini/',
53
- extension: '.md',
54
- format: 'markdown',
52
+ commandDir: '.gemini/commands/',
53
+ extension: '.toml',
54
+ format: 'toml',
55
55
  description: 'Gemini CLI',
56
56
  },
57
57
  'github-copilot': {
58
- instructionsDir: '.github/copilot/',
58
+ agentsDir: '.github/agents/',
59
59
  extension: '.md',
60
60
  format: 'markdown',
61
61
  description: 'GitHub Copilot',
@@ -154,6 +154,11 @@ export function buildIDEContent(agentContent, format, agentName = '') {
154
154
  return lines.join('\n');
155
155
  }
156
156
 
157
+ case 'toml': {
158
+ // Gemini CLI uses TOML format for commands
159
+ return `description = "chati.dev agent — ${agentName}"\n\nprompt = """\n${agentContent}\n"""\n`;
160
+ }
161
+
157
162
  case 'markdown':
158
163
  default:
159
164
  return agentContent;
@@ -7,7 +7,7 @@
7
7
  * @module scripts/pr-review
8
8
  */
9
9
 
10
- import { execSync } from 'node:child_process';
10
+ import { execFileSync } from 'node:child_process';
11
11
  import { extname, dirname } from 'node:path';
12
12
 
13
13
  /**
@@ -64,13 +64,13 @@ export function getSensitivePaths() {
64
64
 
65
65
  /**
66
66
  * Executes a git command and returns the output.
67
- * @param {string} cmd
67
+ * @param {string[]} args - Git subcommand and arguments
68
68
  * @param {string} cwd
69
69
  * @returns {string}
70
70
  */
71
- function git(cmd, cwd) {
71
+ function git(args, cwd) {
72
72
  try {
73
- return execSync(`git ${cmd}`, {
73
+ return execFileSync('git', args, {
74
74
  cwd,
75
75
  encoding: 'utf-8',
76
76
  stdio: ['pipe', 'pipe', 'pipe'],
@@ -89,7 +89,7 @@ function git(cmd, cwd) {
89
89
  * @returns {ChangedFiles}
90
90
  */
91
91
  export function getChangedFiles(base, head, cwd = process.cwd()) {
92
- const output = git(`diff --name-status ${base}...${head}`, cwd);
92
+ const output = git(['diff', '--name-status', `${base}...${head}`], cwd);
93
93
  if (!output) {
94
94
  return { added: [], modified: [], deleted: [], renamed: [] };
95
95
  }
@@ -185,7 +185,7 @@ function checkSchemaExistence(frameworkDir, results) {
185
185
  }
186
186
 
187
187
  /**
188
- * Check constitution has >= 17 articles.
188
+ * Check constitution has >= 19 articles.
189
189
  */
190
190
  function checkConstitution(frameworkDir, results) {
191
191
  results.checks++;
@@ -199,11 +199,11 @@ function checkConstitution(frameworkDir, results) {
199
199
  const content = readFileSync(constitutionPath, 'utf-8');
200
200
  const articleCount = (content.match(/^## Article/gm) || []).length;
201
201
 
202
- if (articleCount >= 17) {
202
+ if (articleCount >= 19) {
203
203
  results.passed++;
204
204
  results.details.push(`Constitution: ${articleCount} articles found`);
205
205
  } else {
206
- results.errors.push(`Constitution has only ${articleCount} articles (expected >= 17)`);
206
+ results.errors.push(`Constitution has only ${articleCount} articles (expected >= 19)`);
207
207
  }
208
208
  }
209
209
 
@@ -0,0 +1,194 @@
1
+ /**
2
+ * @fileoverview Autonomous build loop (Ralph Wiggum v2).
3
+ *
4
+ * Executes tasks autonomously with checkpoint-based state management,
5
+ * retry logic, and quality gate integration.
6
+ *
7
+ * Named "Ralph Wiggum" internally — the autonomous execution mode
8
+ * that iterates until all tasks are complete or escalation is needed.
9
+ *
10
+ * Constitution Article XVII — Execution Mode Governance.
11
+ */
12
+
13
+ import {
14
+ createBuildState,
15
+ loadBuildState,
16
+ saveBuildState,
17
+ startBuild,
18
+ completeBuild,
19
+ failBuild,
20
+ updateCheckpoint,
21
+ getNextPendingTask,
22
+ isTaskExhausted,
23
+ isTimedOut,
24
+ getProgress,
25
+ CheckpointStatus,
26
+ BuildStatus,
27
+ } from './build-state.js';
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Build Loop
31
+ // ---------------------------------------------------------------------------
32
+
33
+ /**
34
+ * @typedef {object} BuildLoopConfig
35
+ * @property {string} projectDir - Project root directory
36
+ * @property {string[]} taskIds - Task IDs to execute
37
+ * @property {function(string): Promise<{success: boolean, output: string}>} executor - Task execution function
38
+ * @property {function(object): void} [onProgress] - Progress callback
39
+ * @property {boolean} [resume=false] - Whether to resume from existing state
40
+ */
41
+
42
+ /**
43
+ * @typedef {object} BuildLoopResult
44
+ * @property {string} status - Final build status
45
+ * @property {number} completed - Tasks completed
46
+ * @property {number} failed - Tasks failed
47
+ * @property {number} totalAttempts - Total execution attempts
48
+ * @property {string} duration - Human-readable duration
49
+ */
50
+
51
+ /**
52
+ * Run the autonomous build loop.
53
+ *
54
+ * Loop logic:
55
+ * 1. Load or create build state
56
+ * 2. Get next pending task
57
+ * 3. Execute task
58
+ * 4. Save checkpoint
59
+ * 5. If task failed and not exhausted, retry
60
+ * 6. If task exhausted, mark as failed and continue
61
+ * 7. Repeat until all tasks complete or global timeout
62
+ *
63
+ * @param {BuildLoopConfig} config
64
+ * @returns {Promise<BuildLoopResult>}
65
+ */
66
+ export async function runBuildLoop(config) {
67
+ const { projectDir, taskIds, executor, onProgress, resume = false } = config;
68
+
69
+ // Load or create state
70
+ let state = resume ? loadBuildState(projectDir) : null;
71
+
72
+ if (!state || state.status === BuildStatus.COMPLETED || state.status === BuildStatus.ABANDONED) {
73
+ state = createBuildState(taskIds);
74
+ }
75
+
76
+ state = startBuild(state);
77
+ saveBuildState(projectDir, state);
78
+
79
+ const startTime = Date.now();
80
+
81
+ // Main loop
82
+ while (true) {
83
+ // Check global timeout
84
+ if (isTimedOut(state)) {
85
+ state = failBuild(state, 'Global timeout exceeded');
86
+ saveBuildState(projectDir, state);
87
+ break;
88
+ }
89
+
90
+ // Get next task
91
+ const checkpoint = getNextPendingTask(state);
92
+ if (!checkpoint) {
93
+ // All tasks processed
94
+ const hasFailures = state.checkpoints.some((c) => c.status === CheckpointStatus.FAILED);
95
+ if (hasFailures) {
96
+ state = failBuild(state, 'Some tasks failed');
97
+ } else {
98
+ state = completeBuild(state);
99
+ }
100
+ saveBuildState(projectDir, state);
101
+ break;
102
+ }
103
+
104
+ // Check if task is exhausted
105
+ if (isTaskExhausted(checkpoint)) {
106
+ state = updateCheckpoint(state, checkpoint.taskId, {
107
+ status: CheckpointStatus.FAILED,
108
+ error: `Exceeded max iterations (${checkpoint.attempts})`,
109
+ });
110
+ saveBuildState(projectDir, state);
111
+
112
+ if (onProgress) {
113
+ onProgress({ type: 'task_exhausted', taskId: checkpoint.taskId, attempts: checkpoint.attempts });
114
+ }
115
+ continue;
116
+ }
117
+
118
+ // Mark task as in progress
119
+ state = updateCheckpoint(state, checkpoint.taskId, {
120
+ status: CheckpointStatus.IN_PROGRESS,
121
+ attempts: checkpoint.attempts + 1,
122
+ lastAttempt: new Date().toISOString(),
123
+ });
124
+ saveBuildState(projectDir, state);
125
+
126
+ if (onProgress) {
127
+ const progress = getProgress(state);
128
+ onProgress({ type: 'task_started', taskId: checkpoint.taskId, attempt: checkpoint.attempts + 1, progress });
129
+ }
130
+
131
+ // Execute task
132
+ try {
133
+ const result = await executor(checkpoint.taskId);
134
+
135
+ if (result.success) {
136
+ state = updateCheckpoint(state, checkpoint.taskId, {
137
+ status: CheckpointStatus.COMPLETED,
138
+ output: result.output?.slice(0, 1000) || 'Completed',
139
+ error: null,
140
+ });
141
+
142
+ if (onProgress) {
143
+ onProgress({ type: 'task_completed', taskId: checkpoint.taskId });
144
+ }
145
+ } else {
146
+ state = updateCheckpoint(state, checkpoint.taskId, {
147
+ status: CheckpointStatus.IN_PROGRESS, // Will retry
148
+ error: result.output?.slice(0, 500) || 'Task failed',
149
+ });
150
+
151
+ if (onProgress) {
152
+ onProgress({ type: 'task_failed', taskId: checkpoint.taskId, attempt: checkpoint.attempts + 1, error: result.output });
153
+ }
154
+ }
155
+ } catch (err) {
156
+ state = updateCheckpoint(state, checkpoint.taskId, {
157
+ status: CheckpointStatus.IN_PROGRESS, // Will retry
158
+ error: err.message?.slice(0, 500) || 'Execution error',
159
+ });
160
+ }
161
+
162
+ saveBuildState(projectDir, state);
163
+ }
164
+
165
+ const duration = Date.now() - startTime;
166
+ const progress = getProgress(state);
167
+
168
+ return {
169
+ status: state.status,
170
+ completed: progress.completed,
171
+ failed: progress.failed,
172
+ totalAttempts: state.totalAttempts,
173
+ duration: `${Math.round(duration / 1000)}s`,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Get current build loop status without executing.
179
+ *
180
+ * @param {string} projectDir
181
+ * @returns {object|null}
182
+ */
183
+ export function getBuildStatus(projectDir) {
184
+ const state = loadBuildState(projectDir);
185
+ if (!state) return null;
186
+
187
+ return {
188
+ sessionId: state.sessionId,
189
+ status: state.status,
190
+ progress: getProgress(state),
191
+ startedAt: state.startedAt,
192
+ lastCheckpoint: state.lastCheckpoint,
193
+ };
194
+ }