chati-dev 4.2.2 → 4.3.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.
Files changed (220) hide show
  1. package/README.md +80 -53
  2. package/bin/chati.js +150 -5
  3. package/framework/agents/build/dev.md +509 -76
  4. package/framework/agents/deploy/devops.md +40 -25
  5. package/framework/agents/discover/brief.md +156 -22
  6. package/framework/agents/discover/brownfield-wu.md +24 -14
  7. package/framework/agents/discover/greenfield-wu.md +100 -14
  8. package/framework/agents/plan/architect-data-engineer.md +6 -6
  9. package/framework/agents/plan/architect-system.md +46 -12
  10. package/framework/agents/plan/architect.md +40 -20
  11. package/framework/agents/plan/detail.md +36 -24
  12. package/framework/agents/plan/phases.md +36 -26
  13. package/framework/agents/plan/tasks.md +114 -33
  14. package/framework/agents/plan/ux-brand-architect.md +240 -8
  15. package/framework/agents/plan/ux-component-engineer.md +28 -13
  16. package/framework/agents/plan/ux-researcher.md +7 -6
  17. package/framework/agents/plan/ux.md +55 -22
  18. package/framework/agents/quality/qa-implementation.md +143 -74
  19. package/framework/agents/quality/qa-planning.md +115 -42
  20. package/framework/agents/quality/qa-visual.md +439 -0
  21. package/framework/agents/shared/visualizer.md +128 -0
  22. package/framework/config.yaml +7 -6
  23. package/framework/constitution.md +127 -44
  24. package/framework/context/governance.md +12 -7
  25. package/framework/context/quality.md +6 -5
  26. package/framework/context/root.md +6 -6
  27. package/framework/data/entity-registry.yaml +377 -4
  28. package/framework/data/model-limits.json +19 -0
  29. package/framework/domains/agents/qa-visual.yaml +74 -0
  30. package/framework/domains/constitution.yaml +46 -2
  31. package/framework/domains/workflows/greenfield-fullstack.yaml +2 -2
  32. package/framework/hooks/advance-trigger.js +131 -0
  33. package/framework/hooks/brief-validator.js +83 -0
  34. package/framework/hooks/constitution-guard.js +24 -5
  35. package/framework/hooks/license-guard.js +62 -27
  36. package/framework/hooks/mode-governance.js +13 -2
  37. package/framework/hooks/model-governance.js +1 -0
  38. package/framework/hooks/post-dev.js +207 -0
  39. package/framework/hooks/prism-engine.js +274 -105
  40. package/framework/hooks/reasoning-escalator.js +371 -0
  41. package/framework/hooks/reference-trigger.js +117 -0
  42. package/framework/hooks/session-digest.js +50 -1
  43. package/framework/hooks/settings.json +32 -1
  44. package/framework/hooks/style-guard.js +25 -6
  45. package/framework/hooks/team-quality-gate.js +19 -12
  46. package/framework/hooks/undercover-guard.js +4 -2
  47. package/framework/i18n/en.yaml +3 -3
  48. package/framework/i18n/es.yaml +3 -3
  49. package/framework/i18n/fr.yaml +3 -3
  50. package/framework/i18n/pt.yaml +3 -3
  51. package/framework/intelligence/context-engine.md +4 -5
  52. package/framework/intelligence/decision-engine.md +1 -1
  53. package/framework/intelligence/hooks-performance.md +3 -3
  54. package/framework/migrations/v1.0-to-v1.1.yaml +1 -1
  55. package/framework/migrations/v1.4-to-v2.0.yaml +11 -11
  56. package/framework/migrations/v4.0-to-v4.1.yaml +2 -2
  57. package/framework/migrations/v4.2-to-v4.3.yaml +29 -0
  58. package/framework/orchestrator/chati-router.js +387 -0
  59. package/framework/orchestrator/chati-update.md +40 -40
  60. package/framework/orchestrator/chati.md +294 -94
  61. package/framework/scaffold/motion-premium/README.md +89 -0
  62. package/framework/scaffold/motion-premium/app/globals.css.template +400 -0
  63. package/framework/scaffold/motion-premium/app/layout.tsx.template +110 -0
  64. package/framework/scaffold/motion-premium/components/animation/BackgroundCrossfadeProvider.tsx.template +170 -0
  65. package/framework/scaffold/motion-premium/components/animation/LenisProvider.tsx.template +49 -0
  66. package/framework/scaffold/motion-premium/components/animation/PageTransitionWrapper.tsx.template +83 -0
  67. package/framework/scaffold/motion-premium/components/animation/Preloader.tsx.template +171 -0
  68. package/framework/scaffold/motion-premium/components/ui/Container.tsx.template +69 -0
  69. package/framework/scaffold/motion-premium/components/ui/PageSection.tsx.template +74 -0
  70. package/framework/scaffold/motion-premium/lib/animations/gsap.ts.template +112 -0
  71. package/framework/scaffold/motion-premium/lib/animations/refreshCoordinator.ts.template +75 -0
  72. package/framework/scaffold/motion-premium/lib/animations/tokens.ts.template +119 -0
  73. package/framework/scaffold/motion-premium/lib/animations/useGsapContext.ts.template +92 -0
  74. package/framework/scaffold/motion-premium/lib/animations/useScrollSnapStepper.ts.template +265 -0
  75. package/framework/scaffold/motion-premium/lib/animations/useSmoothScroll.ts.template +67 -0
  76. package/framework/scaffold/motion-premium/lib/brand.ts.template +43 -0
  77. package/framework/scaffold/motion-premium/scaffold.yaml +174 -0
  78. package/framework/scaffold/motion-premium-3d/README.md +80 -0
  79. package/framework/scaffold/motion-premium-3d/app/(3d)/scroll-demo/ScrollDemoCanvas.tsx.template +81 -0
  80. package/framework/scaffold/motion-premium-3d/app/(3d)/scroll-demo/ScrollDemoClient.tsx.template +75 -0
  81. package/framework/scaffold/motion-premium-3d/app/(3d)/scroll-demo/page.tsx.template +26 -0
  82. package/framework/scaffold/motion-premium-3d/components/3d/CameraRig.tsx.template +100 -0
  83. package/framework/scaffold/motion-premium-3d/components/3d/CanvasProvider.tsx.template +85 -0
  84. package/framework/scaffold/motion-premium-3d/components/3d/InvalidateOnScroll.tsx.template +51 -0
  85. package/framework/scaffold/motion-premium-3d/components/3d/MeshCrossfade.tsx.template +79 -0
  86. package/framework/scaffold/motion-premium-3d/components/3d/ScrollCrossfade.tsx.template +88 -0
  87. package/framework/scaffold/motion-premium-3d/components/3d/ScrollScene.tsx.template +121 -0
  88. package/framework/scaffold/motion-premium-3d/components/webgl/SceneFallback.tsx.template +65 -0
  89. package/framework/scaffold/motion-premium-3d/components/webgl/WebGLContext.tsx.template +68 -0
  90. package/framework/scaffold/motion-premium-3d/lib/webgl/detect.ts.template +69 -0
  91. package/framework/scaffold/motion-premium-3d/scaffold.yaml +133 -0
  92. package/framework/schemas/session.schema.json +109 -21
  93. package/framework/scripts/reference-capture.js +430 -0
  94. package/framework/scripts/visual-qa.js +674 -0
  95. package/framework/tasks/orchestrator-handoff.md +1 -1
  96. package/framework/tasks/orchestrator-resume.md +1 -1
  97. package/framework/tasks/orchestrator-route.md +1 -1
  98. package/framework/tasks/orchestrator-status.md +3 -3
  99. package/framework/tasks/qa-planning-gate-define.md +1 -1
  100. package/framework/templates/brandbook-html-tmpl.md +1 -1
  101. package/framework/templates/brandbook-tmpl.yaml +1 -1
  102. package/framework/templates/component-spec-tmpl.yaml +1 -1
  103. package/framework/templates/design-token-tmpl.yaml +1 -1
  104. package/framework/templates/icon-system-tmpl.yaml +1 -1
  105. package/framework/templates/team-planning-tasks.yaml +6 -5
  106. package/framework/workflows/brownfield-discovery.yaml +2 -2
  107. package/framework/workflows/brownfield-fullstack.yaml +15 -11
  108. package/framework/workflows/brownfield-service.yaml +14 -10
  109. package/framework/workflows/brownfield-ui.yaml +15 -11
  110. package/framework/workflows/greenfield-fullstack.yaml +16 -13
  111. package/framework/workflows/quick-flow.yaml +3 -3
  112. package/framework/workflows/standard-flow.yaml +12 -9
  113. package/package.json +10 -5
  114. package/src/autonomy/autonomous-gate.js +1 -0
  115. package/src/autonomy/build-state.js +1 -2
  116. package/src/autonomy/progress-reporter.js +1 -1
  117. package/src/config/agent-customizer.js +11 -3
  118. package/src/config/claude-settings-generator.js +27 -7
  119. package/src/config/context-file-generator.js +41 -21
  120. package/src/config/framework-adapter.js +1 -0
  121. package/src/config/gemini-hooks-generator.js +19 -7
  122. package/src/config/mcp-configs.js +1 -0
  123. package/src/context/layers/l1-global.js +2 -1
  124. package/src/dashboard/data-reader.js +4 -3
  125. package/src/dashboard/layout.js +2 -1
  126. package/src/decision/analyzer.js +6 -30
  127. package/src/decision/engine.js +4 -28
  128. package/src/decision/registry-healer.js +3 -2
  129. package/src/decision/registry-updater.js +23 -14
  130. package/src/extensions/loader.js +2 -8
  131. package/src/gates/g1-planning-complete.js +2 -1
  132. package/src/gates/g2-qa-planning.js +2 -1
  133. package/src/gates/g3-implementation.js +2 -1
  134. package/src/gates/g4-qa-implementation.js +3 -2
  135. package/src/gates/g5-deploy-ready.js +2 -1
  136. package/src/health/engine.js +4 -3
  137. package/src/installer/core.js +422 -81
  138. package/src/installer/preflight.js +131 -0
  139. package/src/installer/provider-overlay.js +3 -3
  140. package/src/installer/scaffold-applier.js +358 -0
  141. package/src/installer/templates.js +46 -29
  142. package/src/installer/validator.js +17 -12
  143. package/src/intelligence/registry-manager.js +22 -29
  144. package/src/intelligence/timeline.js +11 -6
  145. package/src/license/commands.js +1 -1
  146. package/src/license/wait.js +102 -0
  147. package/src/memory/agent-memory.js +81 -0
  148. package/src/memory/dream.js +32 -1
  149. package/src/merger/replace-merger.js +28 -15
  150. package/src/orchestrator/agent-selector.js +2 -1
  151. package/src/orchestrator/cli.js +1869 -71
  152. package/src/orchestrator/doctor.js +270 -0
  153. package/src/orchestrator/handoff-engine.js +4 -3
  154. package/src/orchestrator/index.js +2 -0
  155. package/src/orchestrator/pipeline-manager.js +306 -15
  156. package/src/orchestrator/session-manager.js +331 -6
  157. package/src/tasks/handoff.js +3 -2
  158. package/src/telemetry/config.js +4 -3
  159. package/src/telemetry/schema.js +1 -0
  160. package/src/terminal/collector.js +3 -2
  161. package/src/terminal/index.js +1 -2
  162. package/src/terminal/isolation.js +52 -18
  163. package/src/terminal/prompt-builder.js +42 -25
  164. package/src/terminal/run-parallel.js +1 -1
  165. package/src/terminal/run-team.js +3 -3
  166. package/src/terminal/team-task-list.js +43 -4
  167. package/src/upgrade/backup.js +3 -2
  168. package/src/upgrade/checker.js +3 -2
  169. package/src/upgrade/migrator.js +65 -7
  170. package/src/upgrade/tracked-files-detector.js +86 -0
  171. package/src/upgrade/user-messages.js +94 -0
  172. package/src/utils/config-parser.js +2 -1
  173. package/src/utils/feature-flags.js +2 -1
  174. package/src/utils/flatten-entities.js +69 -0
  175. package/src/utils/framework-dir.js +16 -0
  176. package/src/utils/model-id.js +85 -0
  177. package/src/utils/provider-limits.js +84 -23
  178. package/src/utils/schema-validator.js +1 -1
  179. package/src/wizard/i18n.js +5 -4
  180. package/src/wizard/index.js +14 -0
  181. package/assets/logo - c/303/263pia.png +0 -0
  182. package/assets/logo.svg +0 -42
  183. package/assets/logo2.png +0 -0
  184. package/assets/social-preview.png +0 -0
  185. package/scripts/bundle-framework.js +0 -69
  186. package/scripts/changelog-generator.js +0 -222
  187. package/scripts/codebase-mapper.js +0 -728
  188. package/scripts/commit-message-generator.js +0 -167
  189. package/scripts/coverage-analyzer.js +0 -260
  190. package/scripts/dependency-analyzer.js +0 -280
  191. package/scripts/doctor/checks/agents.js +0 -77
  192. package/scripts/doctor/checks/constitution.js +0 -41
  193. package/scripts/doctor/checks/domain-alignment.js +0 -58
  194. package/scripts/doctor/checks/prism-layers.js +0 -84
  195. package/scripts/doctor/checks/registry.js +0 -55
  196. package/scripts/doctor/checks/schemas.js +0 -61
  197. package/scripts/doctor/fixes/reference-fix.js +0 -100
  198. package/scripts/doctor/fixes/registry-fix.js +0 -56
  199. package/scripts/doctor/index.js +0 -212
  200. package/scripts/framework-analyzer.js +0 -308
  201. package/scripts/generate-constitution-domain.js +0 -253
  202. package/scripts/generate-signing-key.js +0 -33
  203. package/scripts/health-check.js +0 -481
  204. package/scripts/ide-sync.js +0 -326
  205. package/scripts/performance-analyzer.js +0 -325
  206. package/scripts/plan-tracker.js +0 -278
  207. package/scripts/populate-entity-registry.js +0 -481
  208. package/scripts/pr-review.js +0 -317
  209. package/scripts/rollback-manager.js +0 -310
  210. package/scripts/semantic-lint.js +0 -328
  211. package/scripts/sign-manifest.js +0 -53
  212. package/scripts/stuck-detector.js +0 -343
  213. package/scripts/test-quality-assessment.js +0 -257
  214. package/scripts/validate-agents.js +0 -368
  215. package/scripts/validate-package.js +0 -505
  216. package/scripts/validate-tasks.js +0 -465
  217. package/src/autonomy/worktree-manager.js +0 -250
  218. package/src/intelligence/decision-engine.js +0 -256
  219. package/src/intelligence/document-sharder.js +0 -221
  220. package/src/intelligence/elicitation.js +0 -265
@@ -0,0 +1,387 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * chati-router.js — Deterministic Pipeline Router
4
+ *
5
+ * Runs ALL deterministic logic BEFORE Claude processes anything:
6
+ * 1. License validation + integrity check
7
+ * 2. Session state read
8
+ * 3. Pipeline routing (orchestrate next)
9
+ * 4. Team registration (orchestrate spawn-team) if needed
10
+ *
11
+ * Outputs a single JSON object that Claude consumes. Claude cannot skip
12
+ * any of these steps because they already ran as code.
13
+ *
14
+ * Usage (from .claude/commands/chati.md):
15
+ * node chati.dev/orchestrator/chati-router.js
16
+ */
17
+
18
+ import { existsSync, readFileSync } from 'fs';
19
+ import { join } from 'path';
20
+
21
+ const PROJECT_DIR = process.cwd();
22
+ const ROUTER_ARGS = process.argv.slice(2);
23
+
24
+ /**
25
+ * Find the chati-dev CLI module. Tries local node_modules first (fast),
26
+ * then monorepo dev layout. Returns the module or null.
27
+ */
28
+ async function findCliModule(projectDir) {
29
+ // Resolve framework dir (.chati.dev/ or chati.dev/ for legacy)
30
+ const fwDir = existsSync(join(projectDir, '.chati.dev')) ? '.chati.dev' : 'chati.dev';
31
+ const candidates = [
32
+ // PRIMARY: bundled CLI inside framework dir (self-contained install — no npx needed)
33
+ join(projectDir, fwDir, '_cli', 'orchestrator', 'cli.js'),
34
+ // Fallback: node_modules inside .chati.dev/
35
+ join(projectDir, fwDir, 'node_modules', 'chati-dev', 'src', 'orchestrator', 'cli.js'),
36
+ // Fallback: legacy node_modules at project root
37
+ join(projectDir, 'node_modules', 'chati-dev', 'src', 'orchestrator', 'cli.js'),
38
+ // Fallback: monorepo dev layout
39
+ join(projectDir, '..', '..', 'packages', 'chati-dev', 'src', 'orchestrator', 'cli.js'),
40
+ join(projectDir, '..', '..', '..', 'packages', 'chati-dev', 'src', 'orchestrator', 'cli.js'),
41
+ ];
42
+ for (const p of candidates) {
43
+ if (existsSync(p)) {
44
+ try { return await import(p); } catch { /* continue */ }
45
+ }
46
+ }
47
+ // Last resort: Node module resolution (global install)
48
+ try {
49
+ const { createRequire } = await import('module');
50
+ const require = createRequire(join(projectDir, 'package.json'));
51
+ const cliPath = require.resolve('chati-dev/src/orchestrator/cli.js');
52
+ return await import(cliPath);
53
+ } catch { /* not installed globally */ }
54
+ return null;
55
+ }
56
+
57
+ /**
58
+ * Call runOrchestrate and capture its stdout JSON output.
59
+ */
60
+ async function captureOrchestrate(mod, subCommand, args, projectDir) {
61
+ const chunks = [];
62
+ const origWrite = process.stdout.write;
63
+ process.stdout.write = (c) => { chunks.push(c); return true; };
64
+ try {
65
+ await mod.runOrchestrate(subCommand, args, projectDir);
66
+ } finally {
67
+ process.stdout.write = origWrite;
68
+ }
69
+ try {
70
+ return JSON.parse(chunks.join(''));
71
+ } catch (e) {
72
+ return { action: 'error', error: `invalid_json: ${e.message}` };
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Route `advance` command deterministically — same reliability as `next`.
78
+ * Called as: node chati-router.js advance --agent {name} --score {score}
79
+ */
80
+ async function routeAdvance(agentName, score) {
81
+ const result = {
82
+ ok: true,
83
+ advanced: false,
84
+ agent: agentName,
85
+ score: parseInt(score, 10),
86
+ next: null,
87
+ team: null,
88
+ error: null,
89
+ };
90
+
91
+ try {
92
+ const cliMod = await findCliModule(PROJECT_DIR);
93
+ if (!cliMod) {
94
+ result.ok = false;
95
+ result.error = 'cli_module_not_found';
96
+ return result;
97
+ }
98
+
99
+ const advanceResult = await captureOrchestrate(cliMod, 'advance',
100
+ ['--agent', agentName, '--score', String(score)], PROJECT_DIR);
101
+
102
+ result.advanced = advanceResult.advanced || false;
103
+ result.already_advanced = advanceResult.already_advanced || false;
104
+ if (advanceResult.status_summary) result.status_summary = advanceResult.status_summary;
105
+ result.next = advanceResult.next || advanceResult;
106
+
107
+ // If next action is spawn_team, register team immediately (deterministic)
108
+ if (result.next && result.next.action === 'spawn_team') {
109
+ const teamType = result.next.team_type || 'build';
110
+ const prevAgent = agentName;
111
+ try {
112
+ const teamResult = await captureOrchestrate(cliMod, 'spawn-team',
113
+ ['--team-type', teamType, '--previous-agent', prevAgent], PROJECT_DIR);
114
+
115
+ if (teamResult.fallback_required) {
116
+ result.next.action = 'spawn_parallel';
117
+ result.team = null;
118
+ } else {
119
+ result.team = {
120
+ team_id: teamResult.team_id,
121
+ team_type: teamResult.team_type,
122
+ members: teamResult.members,
123
+ task_list_path: teamResult.task_list_path,
124
+ mailbox_path: teamResult.mailbox_path,
125
+ };
126
+ }
127
+ } catch (err) {
128
+ result.next.action = 'spawn_parallel';
129
+ result.team = null;
130
+ result.error = `team_registration_failed: ${err.message?.slice(0, 200)}`;
131
+ }
132
+ }
133
+ } catch (err) {
134
+ result.ok = false;
135
+ result.error = `advance_failed: ${err.message?.slice(0, 200)}`;
136
+ }
137
+
138
+ return result;
139
+ }
140
+
141
+ // All orchestrate subcommands the router can dispatch locally
142
+ const VALID_ORCHESTRATE_SUBS = new Set([
143
+ 'next', 'advance', 'init', 'status', 'validate-handoff',
144
+ 'deviation', 'exit', 'providers', 'detect-flow', 'backlog',
145
+ 'qa-plan-score', 'qa-impl-score', 'qa-visual-score', 'scan',
146
+ 'spawn-team', 'team-status', 'team-dissolve',
147
+ 'wait-for-capture', 'wave-status', 'assess-coverage',
148
+ 'wait-for-license', 'doctor',
149
+ ]);
150
+
151
+ /**
152
+ * Parse --flag value pairs and standalone --flag bools from argv.
153
+ */
154
+ function parseFlagArgs(argv) {
155
+ const args = {};
156
+ for (let i = 0; i < argv.length; i++) {
157
+ const a = argv[i];
158
+ if (!a.startsWith('--')) continue;
159
+ const key = a.slice(2);
160
+ const next = argv[i + 1];
161
+ if (next && !next.startsWith('--')) {
162
+ args[key] = next;
163
+ i++;
164
+ } else {
165
+ args[key] = true;
166
+ }
167
+ }
168
+ return args;
169
+ }
170
+
171
+ /**
172
+ * Dispatch ANY orchestrate subcommand through the bundled local CLI.
173
+ * Returns the JSON result. Never falls back to npx.
174
+ */
175
+ async function dispatchOrchestrate(subCommand, argv) {
176
+ const cliMod = await findCliModule(PROJECT_DIR);
177
+ if (!cliMod) {
178
+ return {
179
+ ok: false,
180
+ action: 'error',
181
+ error: 'cli_module_not_found',
182
+ reason: 'Bundled CLI not found in .chati.dev/_cli/. Reinstall with: npx chati-dev init',
183
+ };
184
+ }
185
+ try {
186
+ return await captureOrchestrate(cliMod, subCommand, argv, PROJECT_DIR);
187
+ } catch (err) {
188
+ return {
189
+ ok: false,
190
+ action: 'error',
191
+ error: `dispatch_failed: ${err.message?.slice(0, 200)}`,
192
+ };
193
+ }
194
+ }
195
+
196
+ async function main() {
197
+ const subCommand = ROUTER_ARGS[0];
198
+
199
+ // Sub-command mode: `node chati-router.js <subcommand> [--flags...]`
200
+ // Routes to the local CLI for ANY orchestrate subcommand. No npx, no network.
201
+ if (subCommand && VALID_ORCHESTRATE_SUBS.has(subCommand)) {
202
+ if (subCommand === 'advance') {
203
+ // advance also needs team registration, kept as a special case
204
+ const flags = parseFlagArgs(ROUTER_ARGS.slice(1));
205
+ if (!flags.agent || !flags.score) {
206
+ console.log(JSON.stringify({ ok: false, error: 'Missing --agent or --score' }));
207
+ return;
208
+ }
209
+ const advResult = await routeAdvance(flags.agent, flags.score);
210
+ console.log(JSON.stringify(advResult));
211
+ return;
212
+ }
213
+ // Generic dispatch for init, status, detect-flow, etc.
214
+ const result = await dispatchOrchestrate(subCommand, ROUTER_ARGS.slice(1));
215
+ console.log(JSON.stringify(result));
216
+ return;
217
+ }
218
+
219
+ // No-subcommand mode (default): full router pipeline (license + integrity + session + next)
220
+ const result = {
221
+ ok: true,
222
+ license: null,
223
+ integrity: true,
224
+ session: null,
225
+ action: null,
226
+ pipeline: null,
227
+ team: null,
228
+ error: null,
229
+ };
230
+
231
+ // -----------------------------------------------------------------------
232
+ // 1. License validation
233
+ // -----------------------------------------------------------------------
234
+ try {
235
+ const fwDir = existsSync(join(PROJECT_DIR, '.chati.dev')) ? '.chati.dev' : 'chati.dev';
236
+ const hookPath = join(PROJECT_DIR, fwDir, 'hooks', 'license-guard.js');
237
+ if (!existsSync(hookPath)) {
238
+ result.ok = false;
239
+ result.error = 'license_guard_missing';
240
+ result.license = { valid: false, reason: 'License enforcement file missing. Reinstall with: npx chati-dev init' };
241
+ console.log(JSON.stringify(result));
242
+ return;
243
+ }
244
+
245
+ const mod = await import(hookPath);
246
+ const license = await mod.checkLicense();
247
+ result.license = license;
248
+
249
+ if (!license.valid) {
250
+ result.ok = false;
251
+ result.error = 'license_invalid';
252
+ console.log(JSON.stringify(result));
253
+ return;
254
+ }
255
+ } catch (err) {
256
+ // Fail-closed on license check errors
257
+ result.license = { valid: false, error: 'license_check_error' };
258
+ result.ok = false;
259
+ }
260
+
261
+ // -----------------------------------------------------------------------
262
+ // 2. Integrity check — are all required hooks registered in settings.json?
263
+ // Note: license-guard is registered under UserPromptSubmit (not PreToolUse).
264
+ // mode-governance, constitution-guard, and read-protection are in PreToolUse.
265
+ // -----------------------------------------------------------------------
266
+ try {
267
+ const settingsPath = join(PROJECT_DIR, '.claude', 'settings.json');
268
+ if (existsSync(settingsPath)) {
269
+ const settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
270
+ const ptu = settings.hooks?.PreToolUse || [];
271
+ const ups = settings.hooks?.UserPromptSubmit || [];
272
+ const ptuCmds = ptu.flatMap(g => (g.hooks || []).map(h => h.command || ''));
273
+ const upsCmds = ups.flatMap(g => (g.hooks || []).map(h => h.command || ''));
274
+ // license-guard lives in UserPromptSubmit; others live in PreToolUse
275
+ const missingHooks = [
276
+ ...(['mode-governance', 'constitution-guard', 'read-protection'].filter(h => !ptuCmds.some(c => c.includes(h)))),
277
+ ...(['license-guard'].filter(h => !upsCmds.some(c => c.includes(h)) && !ptuCmds.some(c => c.includes(h)))),
278
+ ];
279
+ result.integrity = missingHooks.length === 0;
280
+ if (missingHooks.length > 0) {
281
+ result.error = `integrity_failed: missing hooks: ${missingHooks.join(', ')}`;
282
+ }
283
+ } else {
284
+ result.integrity = false;
285
+ }
286
+
287
+ if (!result.integrity) {
288
+ result.ok = false;
289
+ result.error = 'integrity_failed';
290
+ console.log(JSON.stringify(result));
291
+ return;
292
+ }
293
+ } catch {
294
+ // Fail-closed on integrity check
295
+ result.integrity = false;
296
+ result.ok = false;
297
+ }
298
+
299
+ // -----------------------------------------------------------------------
300
+ // 3. Session state
301
+ // -----------------------------------------------------------------------
302
+ try {
303
+ const sessionPath = join(PROJECT_DIR, '.chati', 'session.yaml');
304
+ if (existsSync(sessionPath)) {
305
+ const raw = readFileSync(sessionPath, 'utf-8');
306
+ const extract = (key) => {
307
+ const m = raw.match(new RegExp(`^\\s*${key}:\\s*(.+)$`, 'm'));
308
+ return m ? m[1].trim().replace(/^["']|["']$/g, '') : null;
309
+ };
310
+ result.session = {
311
+ language: extract('language') || 'en',
312
+ project_name: extract('name') || '',
313
+ project_type: extract('type') || 'greenfield',
314
+ state: extract('state') || 'discover',
315
+ current_agent: extract('current_agent') || '',
316
+ workflow: extract('workflow') || 'full',
317
+ };
318
+ }
319
+ } catch {
320
+ result.session = null;
321
+ }
322
+
323
+ // -----------------------------------------------------------------------
324
+ // 4. Pipeline routing — orchestrate next
325
+ // Calls bundled local CLI ONLY. No npx/network dependency: every install
326
+ // is self-contained via the bundled .chati.dev/_cli/ source.
327
+ // -----------------------------------------------------------------------
328
+ try {
329
+ const cliMod = await findCliModule(PROJECT_DIR);
330
+ if (!cliMod) {
331
+ result.action = 'error';
332
+ result.error = 'cli_module_not_found: bundled CLI missing in .chati.dev/_cli/. Reinstall with: npx chati-dev init';
333
+ } else {
334
+ result.pipeline = await captureOrchestrate(cliMod, 'next', [], PROJECT_DIR);
335
+ result.action = result.pipeline.action;
336
+ }
337
+ } catch (err) {
338
+ result.action = 'error';
339
+ result.error = `pipeline_routing_failed: ${err.message?.slice(0, 200)}`;
340
+ }
341
+
342
+ // -----------------------------------------------------------------------
343
+ // 5. If spawn_team → register team (deterministic, MUST happen before Claude)
344
+ // -----------------------------------------------------------------------
345
+ if (result.action === 'spawn_team' && result.pipeline) {
346
+ try {
347
+ const teamType = result.pipeline.team_type || 'planning';
348
+ const prevAgent = result.pipeline.agent || 'brief';
349
+ const cliMod = await findCliModule(PROJECT_DIR);
350
+
351
+ let teamResult;
352
+ if (cliMod) {
353
+ teamResult = await captureOrchestrate(cliMod, 'spawn-team',
354
+ ['--team-type', teamType, '--previous-agent', prevAgent], PROJECT_DIR);
355
+ } else {
356
+ // No CLI module → cannot spawn team. Don't fall back to npx (version drift risk).
357
+ result.action = 'spawn_parallel';
358
+ result.team = null;
359
+ result.error = 'cli_module_not_found: cannot spawn team without bundled CLI. Reinstall.';
360
+ return console.log(JSON.stringify(result));
361
+ }
362
+
363
+ if (teamResult.fallback_required) {
364
+ result.action = 'spawn_parallel';
365
+ result.team = null;
366
+ } else {
367
+ result.team = {
368
+ team_id: teamResult.team_id,
369
+ team_type: teamResult.team_type,
370
+ members: teamResult.members,
371
+ task_list_path: teamResult.task_list_path,
372
+ mailbox_path: teamResult.mailbox_path,
373
+ };
374
+ }
375
+ } catch (err) {
376
+ result.action = 'spawn_parallel';
377
+ result.team = null;
378
+ result.error = `team_registration_failed: ${err.message?.slice(0, 200)}`;
379
+ }
380
+ }
381
+
382
+ console.log(JSON.stringify(result));
383
+ }
384
+
385
+ main().catch(err => {
386
+ console.log(JSON.stringify({ ok: false, error: err.message }));
387
+ });
@@ -1,4 +1,4 @@
1
- # /chati-update Evolution Advisor with Self-Validated Implementation
1
+ # /chati-update - Evolution Advisor with Self-Validated Implementation
2
2
 
3
3
  You are the **Chati Update Agent**, a specialized evolution advisor for the chati.dev framework. Your mission is to analyze an external repo/project, perform exhaustive cross-comparison with chati.dev's current state, propose improvements, and implement approved changes with ralph-wiggum self-validation at 95% threshold.
4
4
 
@@ -8,17 +8,17 @@ You are the **Chati Update Agent**, a specialized evolution advisor for the chat
8
8
 
9
9
  ## CRITICAL RULES
10
10
 
11
- 1. **NEVER copy blindly** Adapt concepts to chati.dev's identity and patterns
12
- 2. **NEVER break existing tests** All 989+ tests must continue passing
13
- 3. **NEVER violate the constitution** 19 articles are sacred
14
- 4. **NEVER skip comparison** Every finding MUST be validated against current state
15
- 5. **ALWAYS present options** Numbered 1, 2, 3 format before any implementation
16
- 6. **ALWAYS use sub-agents** Parallelize SCAN and COMPARE for throughput
17
- 7. **ORIGINALITY 100%** Zero copies, zero external framework references in code/docs
11
+ 1. **NEVER copy blindly** - Adapt concepts to chati.dev's identity and patterns
12
+ 2. **NEVER break existing tests** - All tests must continue passing (run `npm test` to verify)
13
+ 3. **NEVER violate the constitution** - 23 articles are sacred
14
+ 4. **NEVER skip comparison** - Every finding MUST be validated against current state
15
+ 5. **ALWAYS present options** - Numbered 1, 2, 3 format before any implementation
16
+ 6. **ALWAYS use sub-agents** - Parallelize SCAN and COMPARE for throughput
17
+ 7. **ORIGINALITY 100%** - Zero copies, zero external framework references in code/docs
18
18
 
19
19
  ---
20
20
 
21
- ## Phase 0: PREPARE Resolve Input
21
+ ## Phase 0: PREPARE - Resolve Input
22
22
 
23
23
  ```
24
24
  IF $ARGUMENTS is empty:
@@ -40,7 +40,7 @@ IF $ARGUMENTS is a GitHub shorthand (owner/repo):
40
40
 
41
41
  ---
42
42
 
43
- ## Phase 1: SCAN Deep Analysis of Reference Repo (Sub-Agent)
43
+ ## Phase 1: SCAN - Deep Analysis of Reference Repo (Sub-Agent)
44
44
 
45
45
  Launch a **Task agent (subagent_type=Explore, thoroughness=very thorough)** to analyze the reference repo at REF_PATH.
46
46
 
@@ -61,7 +61,7 @@ Analyze the repo at <REF_PATH> exhaustively. You must produce a comprehensive re
61
61
  - Configuration patterns (YAML, JSON, env)
62
62
  - CLI patterns and entry points
63
63
 
64
- 3. **INTERESTING CONCEPTS** (the gold be thorough)
64
+ 3. **INTERESTING CONCEPTS** (the gold - be thorough)
65
65
  - Novel patterns not commonly seen
66
66
  - Quality gates, validation systems
67
67
  - Context management strategies
@@ -80,19 +80,19 @@ Analyze the repo at <REF_PATH> exhaustively. You must produce a comprehensive re
80
80
  - Type safety patterns
81
81
  - Security patterns
82
82
 
83
- 5. **SPECIFIC ARTIFACTS** For each interesting file/pattern:
83
+ 5. **SPECIFIC ARTIFACTS** - For each interesting file/pattern:
84
84
  - File path
85
85
  - What it does
86
86
  - Why it's interesting
87
87
  - Key code snippets (actual content, not summaries)
88
88
 
89
- Be EXHAUSTIVE. Read every important file. Don't summarize extract actual patterns with code.
89
+ Be EXHAUSTIVE. Read every important file. Don't summarize - extract actual patterns with code.
90
90
  Minimum 30 files analyzed. No laziness.
91
91
  ```
92
92
 
93
93
  ---
94
94
 
95
- ## Phase 2: COMPARE Cross-Reference with Chati.dev (Sub-Agent)
95
+ ## Phase 2: COMPARE - Cross-Reference with Chati.dev (Sub-Agent)
96
96
 
97
97
  Launch **in parallel** with Phase 1 a **Task agent (subagent_type=Explore, thoroughness=very thorough)** to map chati.dev's current state.
98
98
 
@@ -101,44 +101,44 @@ Launch **in parallel** with Phase 1 a **Task agent (subagent_type=Explore, thoro
101
101
  ```
102
102
  Map the COMPLETE current state of chati.dev. Analyze:
103
103
 
104
- 1. **CONSTITUTION** Read chati.dev/constitution.md fully. Extract:
105
- - All 19 articles with key rules
104
+ 1. **CONSTITUTION** - Read chati.dev/constitution.md fully. Extract:
105
+ - All 23 articles with key rules
106
106
  - Quality thresholds
107
107
  - Governance patterns
108
108
 
109
- 2. **ALL AGENTS** Read every file in chati.dev/agents/**/*.md:
109
+ 2. **ALL AGENTS** - Read every file in chati.dev/agents/**/*.md:
110
110
  - Agent identity, role, pipeline position
111
111
  - Input/output contracts
112
112
  - Acceptance criteria
113
113
  - Key patterns each agent uses
114
114
 
115
- 3. **ORCHESTRATOR** Read chati.dev/orchestrator/chati.md fully:
115
+ 3. **ORCHESTRATOR** - Read chati.dev/orchestrator/chati.md fully:
116
116
  - Routing logic
117
117
  - Session management
118
118
  - Deviation handling
119
119
 
120
- 4. **WORKFLOWS** Read chati.dev/workflows/*.yaml:
120
+ 4. **WORKFLOWS** - Read chati.dev/workflows/*.yaml:
121
121
  - Workflow definitions
122
122
  - Step sequences
123
123
  - Gate conditions
124
124
 
125
- 5. **SCHEMAS** Read chati.dev/schemas/*.json:
125
+ 5. **SCHEMAS** - Read chati.dev/schemas/*.json:
126
126
  - Session schema
127
127
  - Handoff schema
128
128
  - Config schema
129
129
 
130
- 6. **HOOKS** Read packages/chati-dev/src/**/*:
130
+ 6. **HOOKS** - Read packages/chati-dev/src/**/*:
131
131
  - All 6 hooks
132
132
  - PRISM engine
133
133
  - Mode governance
134
134
  - Build loop / autonomy system
135
135
 
136
- 7. **TESTS** Map test structure:
136
+ 7. **TESTS** - Map test structure:
137
137
  - Test organization
138
138
  - Coverage patterns
139
139
  - Key test utilities
140
140
 
141
- 8. **CONFIG** Read chati.dev/config.yaml, package.json:
141
+ 8. **CONFIG** - Read chati.dev/config.yaml, package.json:
142
142
  - Version info
143
143
  - Dependencies
144
144
  - Scripts
@@ -149,7 +149,7 @@ This is the baseline for comparison. Be thorough.
149
149
 
150
150
  ---
151
151
 
152
- ## Phase 3: CROSS-ANALYZE Merge Findings
152
+ ## Phase 3: CROSS-ANALYZE - Merge Findings
153
153
 
154
154
  Once both sub-agents complete, YOU (main agent) perform the cross-analysis:
155
155
 
@@ -177,7 +177,7 @@ constitution_check: <which articles are relevant, any conflicts>
177
177
 
178
178
  ---
179
179
 
180
- ## Phase 4: PROPOSE Present to User
180
+ ## Phase 4: PROPOSE - Present to User
181
181
 
182
182
  Generate a structured report for the user:
183
183
 
@@ -193,7 +193,7 @@ Generate a structured report for the user:
193
193
 
194
194
  ## Recommendations (sorted by priority_score desc)
195
195
 
196
- ### ADOPT New Concepts Worth Adding
196
+ ### ADOPT - New Concepts Worth Adding
197
197
 
198
198
  1. **<Finding Name>** (Priority: X/10)
199
199
  - **What**: <description>
@@ -204,7 +204,7 @@ Generate a structured report for the user:
204
204
 
205
205
  2. ...
206
206
 
207
- ### ADAPT Existing Concepts Worth Improving
207
+ ### ADAPT - Existing Concepts Worth Improving
208
208
 
209
209
  1. **<Finding Name>** (Priority: X/10)
210
210
  - **Current**: <how chati.dev does it today>
@@ -214,10 +214,10 @@ Generate a structured report for the user:
214
214
 
215
215
  2. ...
216
216
 
217
- ### ALREADY_EXISTS Chati.dev Already Has This
217
+ ### ALREADY_EXISTS - Chati.dev Already Has This
218
218
  (brief list for transparency)
219
219
 
220
- ### IGNORE Not Applicable
220
+ ### IGNORE - Not Applicable
221
221
  (brief list with reasons)
222
222
  ```
223
223
 
@@ -226,14 +226,14 @@ Then ask the user:
226
226
 
227
227
  ---
228
228
 
229
- ## Phase 5: APPLY + RALPH Self-Validated Implementation
229
+ ## Phase 5: APPLY + RALPH - Self-Validated Implementation
230
230
 
231
231
  For the approved changes, enter ralph-wiggum mode:
232
232
 
233
233
  ### Pre-Ralph Checklist:
234
- 1. Run current tests: `npm test` record baseline (must be green)
235
- 2. Run lint: `npm run lint` record baseline
236
- 3. Git status ensure clean working directory
234
+ 1. Run current tests: `npm test` - record baseline (must be green)
235
+ 2. Run lint: `npm run lint` - record baseline
236
+ 3. Git status - ensure clean working directory
237
237
  4. Create branch: `git checkout -b chati-update/<repo-name>-<date>`
238
238
 
239
239
  ### Ralph Loop Activation:
@@ -247,15 +247,15 @@ Use `/ralph-loop` with the following prompt structure:
247
247
 
248
248
  REQUIREMENTS:
249
249
  1. Implement each change following chati.dev patterns and conventions
250
- 2. Respect the constitution (19 articles) especially originality
250
+ 2. Respect the constitution (23 articles) - especially originality
251
251
  3. Update relevant tests for each change
252
- 4. Run full test suite after each change ALL must pass
253
- 5. Run lint after each change must be clean
252
+ 4. Run full test suite after each change - ALL must pass
253
+ 5. Run lint after each change - must be clean
254
254
  6. Validate against constitution rules
255
255
  7. Each change must score >= 95% on self-validation
256
256
 
257
257
  SELF-VALIDATION CHECKLIST (must ALL be true):
258
- - [ ] All existing tests pass (989+)
258
+ - [ ] All existing tests pass (run `npm test` to verify)
259
259
  - [ ] New tests added for new functionality
260
260
  - [ ] Lint passes with zero errors
261
261
  - [ ] No external framework references (originality 100%)
@@ -272,7 +272,7 @@ When ALL items are validated at >= 95%, output:
272
272
 
273
273
  ---
274
274
 
275
- ## Phase 6: REPORT Final Summary
275
+ ## Phase 6: REPORT - Final Summary
276
276
 
277
277
  After ralph-wiggum completes, generate final report:
278
278
 
@@ -303,7 +303,7 @@ After ralph-wiggum completes, generate final report:
303
303
  ## Error Handling
304
304
 
305
305
  - **Clone fails**: Ask user for correct URL/path, suggest alternatives
306
- - **Tests fail at baseline**: STOP do not proceed with changes on a broken baseline. Report to user.
306
+ - **Tests fail at baseline**: STOP - do not proceed with changes on a broken baseline. Report to user.
307
307
  - **Ralph stuck (> 10 iterations without progress)**: Break loop, report what was achieved, ask user for guidance
308
308
  - **Constitution conflict detected**: STOP that specific change, report conflict, ask user for deviation approval
309
309
  - **Sub-agent returns incomplete data**: Re-run that specific sub-agent with more specific instructions
@@ -318,4 +318,4 @@ After ralph-wiggum completes, generate final report:
318
318
  - Don't modify the constitution
319
319
  - Don't skip the comparison phase ("it looks good, let's just add it")
320
320
  - Don't implement without user approval of the proposal
321
- - Don't rush thoroughness > speed
321
+ - Don't rush - thoroughness > speed