chati-dev 1.4.0 → 2.0.2

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 (208) hide show
  1. package/README.md +40 -24
  2. package/framework/agents/build/dev.md +343 -0
  3. package/framework/agents/clarity/architect.md +112 -0
  4. package/framework/agents/clarity/brief.md +182 -0
  5. package/framework/agents/clarity/brownfield-wu.md +181 -0
  6. package/framework/agents/clarity/detail.md +110 -0
  7. package/framework/agents/clarity/greenfield-wu.md +153 -0
  8. package/framework/agents/clarity/ux.md +112 -0
  9. package/framework/config.yaml +3 -3
  10. package/framework/constitution.md +31 -1
  11. package/framework/context/governance.md +37 -0
  12. package/framework/context/protocols.md +34 -0
  13. package/framework/context/quality.md +27 -0
  14. package/framework/context/root.md +24 -0
  15. package/framework/data/entity-registry.yaml +1 -1
  16. package/framework/domains/agents/architect.yaml +51 -0
  17. package/framework/domains/agents/brief.yaml +47 -0
  18. package/framework/domains/agents/brownfield-wu.yaml +49 -0
  19. package/framework/domains/agents/detail.yaml +47 -0
  20. package/framework/domains/agents/dev.yaml +49 -0
  21. package/framework/domains/agents/devops.yaml +43 -0
  22. package/framework/domains/agents/greenfield-wu.yaml +47 -0
  23. package/framework/domains/agents/orchestrator.yaml +49 -0
  24. package/framework/domains/agents/phases.yaml +47 -0
  25. package/framework/domains/agents/qa-implementation.yaml +43 -0
  26. package/framework/domains/agents/qa-planning.yaml +44 -0
  27. package/framework/domains/agents/tasks.yaml +48 -0
  28. package/framework/domains/agents/ux.yaml +50 -0
  29. package/framework/domains/constitution.yaml +77 -0
  30. package/framework/domains/global.yaml +64 -0
  31. package/framework/domains/workflows/brownfield-discovery.yaml +16 -0
  32. package/framework/domains/workflows/brownfield-fullstack.yaml +26 -0
  33. package/framework/domains/workflows/brownfield-service.yaml +22 -0
  34. package/framework/domains/workflows/brownfield-ui.yaml +22 -0
  35. package/framework/domains/workflows/greenfield-fullstack.yaml +26 -0
  36. package/framework/hooks/constitution-guard.js +101 -0
  37. package/framework/hooks/mode-governance.js +92 -0
  38. package/framework/hooks/model-governance.js +76 -0
  39. package/framework/hooks/prism-engine.js +89 -0
  40. package/framework/hooks/session-digest.js +60 -0
  41. package/framework/hooks/settings.json +44 -0
  42. package/framework/i18n/en.yaml +3 -3
  43. package/framework/i18n/es.yaml +3 -3
  44. package/framework/i18n/fr.yaml +3 -3
  45. package/framework/i18n/pt.yaml +3 -3
  46. package/framework/intelligence/decision-engine.md +1 -1
  47. package/framework/migrations/v1.4-to-v2.0.yaml +167 -0
  48. package/framework/migrations/v2.0-to-v2.0.1.yaml +132 -0
  49. package/framework/orchestrator/chati.md +284 -6
  50. package/framework/tasks/architect-api-design.md +63 -0
  51. package/framework/tasks/architect-consolidate.md +47 -0
  52. package/framework/tasks/architect-db-design.md +73 -0
  53. package/framework/tasks/architect-design.md +95 -0
  54. package/framework/tasks/architect-security-review.md +62 -0
  55. package/framework/tasks/architect-stack-selection.md +53 -0
  56. package/framework/tasks/brief-consolidate.md +249 -0
  57. package/framework/tasks/brief-constraint-identify.md +277 -0
  58. package/framework/tasks/brief-extract-requirements.md +339 -0
  59. package/framework/tasks/brief-stakeholder-map.md +176 -0
  60. package/framework/tasks/brief-validate-completeness.md +121 -0
  61. package/framework/tasks/brownfield-wu-architecture-map.md +394 -0
  62. package/framework/tasks/brownfield-wu-deep-discovery.md +312 -0
  63. package/framework/tasks/brownfield-wu-dependency-scan.md +359 -0
  64. package/framework/tasks/brownfield-wu-migration-plan.md +483 -0
  65. package/framework/tasks/brownfield-wu-report.md +325 -0
  66. package/framework/tasks/brownfield-wu-risk-assess.md +424 -0
  67. package/framework/tasks/detail-acceptance-criteria.md +372 -0
  68. package/framework/tasks/detail-consolidate.md +138 -0
  69. package/framework/tasks/detail-edge-case-analysis.md +300 -0
  70. package/framework/tasks/detail-expand-prd.md +389 -0
  71. package/framework/tasks/detail-nfr-extraction.md +223 -0
  72. package/framework/tasks/dev-code-review.md +404 -0
  73. package/framework/tasks/dev-consolidate.md +543 -0
  74. package/framework/tasks/dev-debug.md +322 -0
  75. package/framework/tasks/dev-implement.md +252 -0
  76. package/framework/tasks/dev-iterate.md +411 -0
  77. package/framework/tasks/dev-pr-prepare.md +497 -0
  78. package/framework/tasks/dev-refactor.md +342 -0
  79. package/framework/tasks/dev-test-write.md +306 -0
  80. package/framework/tasks/devops-ci-setup.md +412 -0
  81. package/framework/tasks/devops-consolidate.md +712 -0
  82. package/framework/tasks/devops-deploy-config.md +598 -0
  83. package/framework/tasks/devops-monitoring-setup.md +658 -0
  84. package/framework/tasks/devops-release-prepare.md +673 -0
  85. package/framework/tasks/greenfield-wu-analyze-empty.md +169 -0
  86. package/framework/tasks/greenfield-wu-report.md +266 -0
  87. package/framework/tasks/greenfield-wu-scaffold-detection.md +203 -0
  88. package/framework/tasks/greenfield-wu-tech-stack-assess.md +255 -0
  89. package/framework/tasks/orchestrator-deviation.md +260 -0
  90. package/framework/tasks/orchestrator-escalate.md +276 -0
  91. package/framework/tasks/orchestrator-handoff.md +243 -0
  92. package/framework/tasks/orchestrator-health.md +372 -0
  93. package/framework/tasks/orchestrator-mode-switch.md +262 -0
  94. package/framework/tasks/orchestrator-resume.md +189 -0
  95. package/framework/tasks/orchestrator-route.md +169 -0
  96. package/framework/tasks/orchestrator-spawn-terminal.md +358 -0
  97. package/framework/tasks/orchestrator-status.md +260 -0
  98. package/framework/tasks/orchestrator-suggest-mode.md +372 -0
  99. package/framework/tasks/phases-breakdown.md +91 -0
  100. package/framework/tasks/phases-dependency-mapping.md +67 -0
  101. package/framework/tasks/phases-mvp-scoping.md +94 -0
  102. package/framework/tasks/qa-impl-consolidate.md +522 -0
  103. package/framework/tasks/qa-impl-performance-test.md +487 -0
  104. package/framework/tasks/qa-impl-regression-check.md +413 -0
  105. package/framework/tasks/qa-impl-sast-scan.md +402 -0
  106. package/framework/tasks/qa-impl-test-execute.md +344 -0
  107. package/framework/tasks/qa-impl-verdict.md +339 -0
  108. package/framework/tasks/qa-planning-consolidate.md +309 -0
  109. package/framework/tasks/qa-planning-coverage-plan.md +338 -0
  110. package/framework/tasks/qa-planning-gate-define.md +339 -0
  111. package/framework/tasks/qa-planning-risk-matrix.md +631 -0
  112. package/framework/tasks/qa-planning-test-strategy.md +217 -0
  113. package/framework/tasks/tasks-acceptance-write.md +75 -0
  114. package/framework/tasks/tasks-consolidate.md +57 -0
  115. package/framework/tasks/tasks-decompose.md +80 -0
  116. package/framework/tasks/tasks-estimate.md +66 -0
  117. package/framework/tasks/ux-a11y-check.md +49 -0
  118. package/framework/tasks/ux-component-map.md +55 -0
  119. package/framework/tasks/ux-consolidate.md +46 -0
  120. package/framework/tasks/ux-user-flow.md +46 -0
  121. package/framework/tasks/ux-wireframe.md +76 -0
  122. package/package.json +2 -2
  123. package/scripts/bundle-framework.js +2 -0
  124. package/scripts/changelog-generator.js +222 -0
  125. package/scripts/codebase-mapper.js +728 -0
  126. package/scripts/commit-message-generator.js +167 -0
  127. package/scripts/coverage-analyzer.js +260 -0
  128. package/scripts/dependency-analyzer.js +280 -0
  129. package/scripts/framework-analyzer.js +308 -0
  130. package/scripts/generate-constitution-domain.js +253 -0
  131. package/scripts/health-check.js +481 -0
  132. package/scripts/ide-sync.js +327 -0
  133. package/scripts/performance-analyzer.js +325 -0
  134. package/scripts/plan-tracker.js +278 -0
  135. package/scripts/populate-entity-registry.js +481 -0
  136. package/scripts/pr-review.js +317 -0
  137. package/scripts/rollback-manager.js +310 -0
  138. package/scripts/stuck-detector.js +343 -0
  139. package/scripts/test-quality-assessment.js +257 -0
  140. package/scripts/validate-agents.js +367 -0
  141. package/scripts/validate-tasks.js +465 -0
  142. package/src/autonomy/autonomous-gate.js +293 -0
  143. package/src/autonomy/index.js +51 -0
  144. package/src/autonomy/mode-manager.js +225 -0
  145. package/src/autonomy/mode-suggester.js +283 -0
  146. package/src/autonomy/progress-reporter.js +268 -0
  147. package/src/autonomy/safety-net.js +320 -0
  148. package/src/context/bracket-tracker.js +79 -0
  149. package/src/context/domain-loader.js +107 -0
  150. package/src/context/engine.js +144 -0
  151. package/src/context/formatter.js +184 -0
  152. package/src/context/index.js +4 -0
  153. package/src/context/layers/l0-constitution.js +28 -0
  154. package/src/context/layers/l1-global.js +37 -0
  155. package/src/context/layers/l2-agent.js +39 -0
  156. package/src/context/layers/l3-workflow.js +42 -0
  157. package/src/context/layers/l4-task.js +24 -0
  158. package/src/decision/analyzer.js +167 -0
  159. package/src/decision/engine.js +270 -0
  160. package/src/decision/index.js +38 -0
  161. package/src/decision/registry-healer.js +450 -0
  162. package/src/decision/registry-updater.js +330 -0
  163. package/src/gates/circuit-breaker.js +119 -0
  164. package/src/gates/g1-planning-complete.js +153 -0
  165. package/src/gates/g2-qa-planning.js +153 -0
  166. package/src/gates/g3-implementation.js +188 -0
  167. package/src/gates/g4-qa-implementation.js +207 -0
  168. package/src/gates/g5-deploy-ready.js +180 -0
  169. package/src/gates/gate-base.js +144 -0
  170. package/src/gates/index.js +46 -0
  171. package/src/installer/brownfield-upgrader.js +249 -0
  172. package/src/installer/core.js +82 -11
  173. package/src/installer/file-hasher.js +51 -0
  174. package/src/installer/manifest.js +117 -0
  175. package/src/installer/templates.js +17 -15
  176. package/src/installer/transaction.js +229 -0
  177. package/src/installer/validator.js +18 -1
  178. package/src/intelligence/registry-manager.js +2 -2
  179. package/src/memory/agent-memory.js +255 -0
  180. package/src/memory/gotchas-injector.js +72 -0
  181. package/src/memory/gotchas.js +361 -0
  182. package/src/memory/index.js +35 -0
  183. package/src/memory/search.js +233 -0
  184. package/src/memory/session-digest.js +239 -0
  185. package/src/merger/env-merger.js +112 -0
  186. package/src/merger/index.js +56 -0
  187. package/src/merger/replace-merger.js +51 -0
  188. package/src/merger/yaml-merger.js +127 -0
  189. package/src/orchestrator/agent-selector.js +285 -0
  190. package/src/orchestrator/deviation-handler.js +350 -0
  191. package/src/orchestrator/handoff-engine.js +271 -0
  192. package/src/orchestrator/index.js +67 -0
  193. package/src/orchestrator/intent-classifier.js +264 -0
  194. package/src/orchestrator/pipeline-manager.js +492 -0
  195. package/src/orchestrator/pipeline-state.js +223 -0
  196. package/src/orchestrator/session-manager.js +409 -0
  197. package/src/tasks/executor.js +195 -0
  198. package/src/tasks/handoff.js +226 -0
  199. package/src/tasks/index.js +4 -0
  200. package/src/tasks/loader.js +210 -0
  201. package/src/tasks/router.js +182 -0
  202. package/src/terminal/collector.js +216 -0
  203. package/src/terminal/index.js +30 -0
  204. package/src/terminal/isolation.js +129 -0
  205. package/src/terminal/monitor.js +277 -0
  206. package/src/terminal/spawner.js +269 -0
  207. package/src/upgrade/checker.js +1 -1
  208. package/src/wizard/i18n.js +3 -3
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Decision Engine - Core COMPASS module for chati.dev
3
+ * Analyzes intent and recommends: REUSE (>=90%), ADAPT (60-89%), CREATE (<60%)
4
+ *
5
+ * @module decision/engine
6
+ */
7
+
8
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
9
+ import { join } from 'path';
10
+ import yaml from 'js-yaml';
11
+
12
+ /**
13
+ * Analyze a request against existing entities and recommend action.
14
+ * Uses keyword matching to find similar existing artifacts.
15
+ *
16
+ * @param {string} projectDir
17
+ * @param {object} request - { description, type, keywords, agent }
18
+ * @returns {{ recommendation: 'REUSE'|'ADAPT'|'CREATE', score: number, matches: object[], reasoning: string }}
19
+ */
20
+ export function analyzeRequest(projectDir, request) {
21
+ const registryPath = join(projectDir, 'chati.dev', 'entity-registry.yaml');
22
+
23
+ if (!existsSync(registryPath)) {
24
+ return {
25
+ recommendation: 'CREATE',
26
+ score: 0,
27
+ matches: [],
28
+ reasoning: 'No entity registry found - first artifact in project'
29
+ };
30
+ }
31
+
32
+ const registry = yaml.load(readFileSync(registryPath, 'utf8'));
33
+ const entities = flattenEntities(registry);
34
+
35
+ // Calculate similarity scores for all entities
36
+ const scoredMatches = entities
37
+ .map(entity => ({
38
+ entity,
39
+ score: calculateSimilarity(request, entity)
40
+ }))
41
+ .filter(match => match.score > 0)
42
+ .sort((a, b) => b.score - a.score);
43
+
44
+ const topScore = scoredMatches.length > 0 ? scoredMatches[0].score : 0;
45
+ const topMatches = scoredMatches.slice(0, 5).map(m => ({
46
+ path: m.entity.path,
47
+ type: m.entity.type,
48
+ score: m.score,
49
+ purpose: m.entity.purpose || 'No purpose defined'
50
+ }));
51
+
52
+ let recommendation;
53
+ let reasoning;
54
+
55
+ if (topScore >= 90) {
56
+ recommendation = 'REUSE';
57
+ reasoning = `High similarity (${topScore}%) - existing artifact meets requirements`;
58
+ } else if (topScore >= 60) {
59
+ recommendation = 'ADAPT';
60
+ reasoning = `Moderate similarity (${topScore}%) - adapt existing artifact`;
61
+ } else {
62
+ recommendation = 'CREATE';
63
+ reasoning = topScore > 0
64
+ ? `Low similarity (${topScore}%) - create new artifact`
65
+ : 'No similar artifacts found - create new';
66
+ }
67
+
68
+ const decision = {
69
+ timestamp: new Date().toISOString(),
70
+ request: {
71
+ description: request.description,
72
+ type: request.type,
73
+ keywords: request.keywords,
74
+ agent: request.agent
75
+ },
76
+ recommendation,
77
+ score: topScore,
78
+ reasoning,
79
+ topMatches: topMatches.slice(0, 3)
80
+ };
81
+
82
+ recordDecision(projectDir, decision);
83
+
84
+ return {
85
+ recommendation,
86
+ score: topScore,
87
+ matches: topMatches,
88
+ reasoning
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Calculate similarity between a request and an entity.
94
+ * Uses keyword overlap (Jaccard similarity) + type matching.
95
+ *
96
+ * @param {object} request - { keywords, type }
97
+ * @param {object} entity - { keywords, type, purpose }
98
+ * @returns {number} Score 0-100
99
+ */
100
+ export function calculateSimilarity(request, entity) {
101
+ // Normalize and collect keywords
102
+ const requestKeywords = new Set(
103
+ (request.keywords || []).map(k => k.toLowerCase())
104
+ );
105
+
106
+ const entityKeywords = new Set();
107
+
108
+ // Extract from entity keywords (primary source)
109
+ if (entity.keywords) {
110
+ entity.keywords.forEach(k => entityKeywords.add(k.toLowerCase()));
111
+ }
112
+
113
+ // Extract from entity name (secondary source - only key terms)
114
+ if (entity.name) {
115
+ const nameWords = entity.name
116
+ .toLowerCase()
117
+ .replace(/[._-]/g, ' ')
118
+ .split(/\W+/)
119
+ .filter(w => w.length > 3);
120
+ nameWords.forEach(w => entityKeywords.add(w));
121
+ }
122
+
123
+ if (requestKeywords.size === 0 || entityKeywords.size === 0) {
124
+ return 0;
125
+ }
126
+
127
+ // Calculate Jaccard similarity
128
+ const intersection = new Set(
129
+ [...requestKeywords].filter(k => entityKeywords.has(k))
130
+ );
131
+ const union = new Set([...requestKeywords, ...entityKeywords]);
132
+
133
+ let score = (intersection.size / union.size) * 100;
134
+
135
+ // Add bonus points for type match (additive, not multiplicative)
136
+ if (request.type && entity.type && request.type === entity.type) {
137
+ score = Math.min(100, score + 25);
138
+ }
139
+
140
+ // Add bonus for high intersection ratio (more matches = better)
141
+ const intersectionRatio = intersection.size / requestKeywords.size;
142
+ if (intersectionRatio >= 0.8) {
143
+ score = Math.min(100, score + 15);
144
+ } else if (intersectionRatio >= 0.5) {
145
+ score = Math.min(100, score + 10);
146
+ }
147
+
148
+ return Math.round(score);
149
+ }
150
+
151
+ /**
152
+ * Get decision history for auditing.
153
+ * @param {string} projectDir
154
+ * @returns {object[]} Recent decisions
155
+ */
156
+ export function getDecisionHistory(projectDir) {
157
+ const historyPath = join(projectDir, '.chati', 'decisions', 'history.json');
158
+
159
+ if (!existsSync(historyPath)) {
160
+ return [];
161
+ }
162
+
163
+ try {
164
+ const content = readFileSync(historyPath, 'utf8');
165
+ const data = JSON.parse(content);
166
+ return data.decisions || [];
167
+ } catch {
168
+ return [];
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Record a decision for audit trail.
174
+ * @param {string} projectDir
175
+ * @param {object} decision
176
+ */
177
+ export function recordDecision(projectDir, decision) {
178
+ const decisionsDir = join(projectDir, '.chati', 'decisions');
179
+ const historyPath = join(decisionsDir, 'history.json');
180
+
181
+ // Ensure directory exists
182
+ if (!existsSync(decisionsDir)) {
183
+ mkdirSync(decisionsDir, { recursive: true });
184
+ }
185
+
186
+ let history = { decisions: [] };
187
+
188
+ if (existsSync(historyPath)) {
189
+ try {
190
+ const content = readFileSync(historyPath, 'utf8');
191
+ history = JSON.parse(content);
192
+ } catch {
193
+ // Keep empty history if parse fails
194
+ }
195
+ }
196
+
197
+ history.decisions = history.decisions || [];
198
+ history.decisions.push(decision);
199
+
200
+ // Keep last 100 decisions
201
+ if (history.decisions.length > 100) {
202
+ history.decisions = history.decisions.slice(-100);
203
+ }
204
+
205
+ writeFileSync(historyPath, JSON.stringify(history, null, 2), 'utf8');
206
+ }
207
+
208
+ /**
209
+ * Get engine statistics.
210
+ * @param {string} projectDir
211
+ * @returns {object} { totalDecisions, byRecommendation: { REUSE, ADAPT, CREATE }, avgScore }
212
+ */
213
+ export function getEngineStats(projectDir) {
214
+ const history = getDecisionHistory(projectDir);
215
+
216
+ const stats = {
217
+ totalDecisions: history.length,
218
+ byRecommendation: {
219
+ REUSE: 0,
220
+ ADAPT: 0,
221
+ CREATE: 0
222
+ },
223
+ avgScore: 0
224
+ };
225
+
226
+ if (history.length === 0) {
227
+ return stats;
228
+ }
229
+
230
+ let totalScore = 0;
231
+
232
+ history.forEach(decision => {
233
+ if (decision.recommendation) {
234
+ stats.byRecommendation[decision.recommendation] =
235
+ (stats.byRecommendation[decision.recommendation] || 0) + 1;
236
+ }
237
+ totalScore += decision.score || 0;
238
+ });
239
+
240
+ stats.avgScore = Math.round(totalScore / history.length);
241
+
242
+ return stats;
243
+ }
244
+
245
+ /**
246
+ * Flatten entity registry into array of entities.
247
+ * @private
248
+ * @param {object} registry
249
+ * @returns {object[]}
250
+ */
251
+ function flattenEntities(registry) {
252
+ const entities = [];
253
+
254
+ if (!registry.entities) {
255
+ return entities;
256
+ }
257
+
258
+ Object.entries(registry.entities).forEach(([type, typeEntities]) => {
259
+ if (Array.isArray(typeEntities)) {
260
+ typeEntities.forEach(entity => {
261
+ entities.push({
262
+ ...entity,
263
+ type
264
+ });
265
+ });
266
+ }
267
+ });
268
+
269
+ return entities;
270
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Decision Engine - COMPASS for chati.dev
3
+ * Barrel exports for decision engine modules
4
+ *
5
+ * @module decision
6
+ */
7
+
8
+ export {
9
+ analyzeRequest,
10
+ calculateSimilarity,
11
+ getDecisionHistory,
12
+ recordDecision,
13
+ getEngineStats
14
+ } from './engine.js';
15
+
16
+ export {
17
+ analyzeImpact,
18
+ buildDependencyGraph,
19
+ getTransitiveDependents
20
+ } from './analyzer.js';
21
+
22
+ export {
23
+ updateRegistry,
24
+ detectNewEntities,
25
+ detectRemovedEntities,
26
+ generateEntityMeta
27
+ } from './registry-updater.js';
28
+
29
+ export {
30
+ healRegistry,
31
+ detectMissingEntities,
32
+ detectOrphanedEntries,
33
+ detectStaleMetadata,
34
+ detectDuplicates,
35
+ detectInvalidPaths,
36
+ detectCountMismatch,
37
+ applyFixes
38
+ } from './registry-healer.js';