magi-ai 0.1.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 (300) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +377 -0
  3. package/README.md +377 -0
  4. package/dist/bin/magi-benchmark.d.ts +14 -0
  5. package/dist/bin/magi-benchmark.js +93 -0
  6. package/dist/bin/magi-mcp.d.ts +8 -0
  7. package/dist/bin/magi-mcp.js +28 -0
  8. package/dist/bin/magi.d.ts +2 -0
  9. package/dist/bin/magi.js +634 -0
  10. package/dist/src/adapters/base.d.ts +34 -0
  11. package/dist/src/adapters/base.js +149 -0
  12. package/dist/src/adapters/claude.d.ts +29 -0
  13. package/dist/src/adapters/claude.js +65 -0
  14. package/dist/src/adapters/codex.d.ts +21 -0
  15. package/dist/src/adapters/codex.js +41 -0
  16. package/dist/src/adapters/gemini.d.ts +18 -0
  17. package/dist/src/adapters/gemini.js +31 -0
  18. package/dist/src/adapters/registry.d.ts +19 -0
  19. package/dist/src/adapters/registry.js +59 -0
  20. package/dist/src/audit/hash-chain.d.ts +21 -0
  21. package/dist/src/audit/hash-chain.js +70 -0
  22. package/dist/src/audit/types.d.ts +25 -0
  23. package/dist/src/audit/types.js +1 -0
  24. package/dist/src/audit/writer.d.ts +18 -0
  25. package/dist/src/audit/writer.js +100 -0
  26. package/dist/src/benchmark/golden-tasks.d.ts +9 -0
  27. package/dist/src/benchmark/golden-tasks.js +476 -0
  28. package/dist/src/benchmark/reporter.d.ts +5 -0
  29. package/dist/src/benchmark/reporter.js +107 -0
  30. package/dist/src/benchmark/runner.d.ts +30 -0
  31. package/dist/src/benchmark/runner.js +224 -0
  32. package/dist/src/benchmark/scorer.d.ts +12 -0
  33. package/dist/src/benchmark/scorer.js +124 -0
  34. package/dist/src/benchmark/types.d.ts +54 -0
  35. package/dist/src/benchmark/types.js +1 -0
  36. package/dist/src/cache/deliberation-cache.d.ts +49 -0
  37. package/dist/src/cache/deliberation-cache.js +127 -0
  38. package/dist/src/cli/commands/config-cmd.d.ts +11 -0
  39. package/dist/src/cli/commands/config-cmd.js +190 -0
  40. package/dist/src/cli/commands/demo.d.ts +12 -0
  41. package/dist/src/cli/commands/demo.js +66 -0
  42. package/dist/src/cli/commands/setup.d.ts +7 -0
  43. package/dist/src/cli/commands/setup.js +182 -0
  44. package/dist/src/cli/i18n.d.ts +89 -0
  45. package/dist/src/cli/i18n.js +176 -0
  46. package/dist/src/cli/interactive-select.d.ts +27 -0
  47. package/dist/src/cli/interactive-select.js +130 -0
  48. package/dist/src/cli/tui-setup.d.ts +24 -0
  49. package/dist/src/cli/tui-setup.js +42 -0
  50. package/dist/src/config/cli-detector.d.ts +37 -0
  51. package/dist/src/config/cli-detector.js +99 -0
  52. package/dist/src/config/user-config.d.ts +81 -0
  53. package/dist/src/config/user-config.js +134 -0
  54. package/dist/src/context/auto-collector.d.ts +43 -0
  55. package/dist/src/context/auto-collector.js +337 -0
  56. package/dist/src/context/manager.d.ts +35 -0
  57. package/dist/src/context/manager.js +162 -0
  58. package/dist/src/context/serializer.d.ts +20 -0
  59. package/dist/src/context/serializer.js +52 -0
  60. package/dist/src/demo/recorded-deliberation.d.ts +13 -0
  61. package/dist/src/demo/recorded-deliberation.js +277 -0
  62. package/dist/src/engine/angel-detector.d.ts +83 -0
  63. package/dist/src/engine/angel-detector.js +334 -0
  64. package/dist/src/engine/at-field.d.ts +40 -0
  65. package/dist/src/engine/at-field.js +195 -0
  66. package/dist/src/engine/berserk-orchestrator.d.ts +66 -0
  67. package/dist/src/engine/berserk-orchestrator.js +378 -0
  68. package/dist/src/engine/change-metrics.d.ts +56 -0
  69. package/dist/src/engine/change-metrics.js +214 -0
  70. package/dist/src/engine/consensus.d.ts +20 -0
  71. package/dist/src/engine/consensus.js +146 -0
  72. package/dist/src/engine/dead-sea-scrolls.d.ts +132 -0
  73. package/dist/src/engine/dead-sea-scrolls.js +610 -0
  74. package/dist/src/engine/drift-detector.d.ts +39 -0
  75. package/dist/src/engine/drift-detector.js +225 -0
  76. package/dist/src/engine/dummy-plug.d.ts +44 -0
  77. package/dist/src/engine/dummy-plug.js +190 -0
  78. package/dist/src/engine/engram-manager.d.ts +55 -0
  79. package/dist/src/engine/engram-manager.js +306 -0
  80. package/dist/src/engine/events.d.ts +130 -0
  81. package/dist/src/engine/events.js +44 -0
  82. package/dist/src/engine/gospel.d.ts +30 -0
  83. package/dist/src/engine/gospel.js +129 -0
  84. package/dist/src/engine/hallucination-detector.d.ts +33 -0
  85. package/dist/src/engine/hallucination-detector.js +215 -0
  86. package/dist/src/engine/human-resolver.d.ts +19 -0
  87. package/dist/src/engine/human-resolver.js +89 -0
  88. package/dist/src/engine/instrumentality.d.ts +64 -0
  89. package/dist/src/engine/instrumentality.js +297 -0
  90. package/dist/src/engine/iruel-battle.d.ts +79 -0
  91. package/dist/src/engine/iruel-battle.js +319 -0
  92. package/dist/src/engine/kernel/deliberation-kernel.d.ts +12 -0
  93. package/dist/src/engine/kernel/deliberation-kernel.js +303 -0
  94. package/dist/src/engine/kernel/index.d.ts +8 -0
  95. package/dist/src/engine/kernel/index.js +7 -0
  96. package/dist/src/engine/kernel/phase-runner.d.ts +10 -0
  97. package/dist/src/engine/kernel/phase-runner.js +155 -0
  98. package/dist/src/engine/kernel/post-processor.d.ts +17 -0
  99. package/dist/src/engine/kernel/post-processor.js +131 -0
  100. package/dist/src/engine/kernel/types.d.ts +107 -0
  101. package/dist/src/engine/kernel/types.js +1 -0
  102. package/dist/src/engine/kernel/unit-executor.d.ts +6 -0
  103. package/dist/src/engine/kernel/unit-executor.js +132 -0
  104. package/dist/src/engine/lcl-manager.d.ts +44 -0
  105. package/dist/src/engine/lcl-manager.js +143 -0
  106. package/dist/src/engine/middleware/cache.d.ts +7 -0
  107. package/dist/src/engine/middleware/cache.js +29 -0
  108. package/dist/src/engine/middleware/chain.d.ts +18 -0
  109. package/dist/src/engine/middleware/chain.js +45 -0
  110. package/dist/src/engine/middleware/firewall.d.ts +8 -0
  111. package/dist/src/engine/middleware/firewall.js +24 -0
  112. package/dist/src/engine/middleware/index.d.ts +4 -0
  113. package/dist/src/engine/middleware/index.js +3 -0
  114. package/dist/src/engine/middleware/types.d.ts +43 -0
  115. package/dist/src/engine/middleware/types.js +1 -0
  116. package/dist/src/engine/nebuchadnezzar-key.d.ts +61 -0
  117. package/dist/src/engine/nebuchadnezzar-key.js +203 -0
  118. package/dist/src/engine/neon-genesis.d.ts +52 -0
  119. package/dist/src/engine/neon-genesis.js +203 -0
  120. package/dist/src/engine/objective-judge.d.ts +53 -0
  121. package/dist/src/engine/objective-judge.js +214 -0
  122. package/dist/src/engine/offline-mode.d.ts +18 -0
  123. package/dist/src/engine/offline-mode.js +46 -0
  124. package/dist/src/engine/orchestrator.d.ts +79 -0
  125. package/dist/src/engine/orchestrator.js +58 -0
  126. package/dist/src/engine/secret-cipher.d.ts +26 -0
  127. package/dist/src/engine/secret-cipher.js +114 -0
  128. package/dist/src/engine/seele-council.d.ts +90 -0
  129. package/dist/src/engine/seele-council.js +482 -0
  130. package/dist/src/engine/self-destruct.d.ts +61 -0
  131. package/dist/src/engine/self-destruct.js +231 -0
  132. package/dist/src/engine/self-evolution.d.ts +64 -0
  133. package/dist/src/engine/self-evolution.js +368 -0
  134. package/dist/src/engine/sync-rate.d.ts +45 -0
  135. package/dist/src/engine/sync-rate.js +151 -0
  136. package/dist/src/engine/type666-firewall.d.ts +76 -0
  137. package/dist/src/engine/type666-firewall.js +343 -0
  138. package/dist/src/engine/umbilical-cable.d.ts +41 -0
  139. package/dist/src/engine/umbilical-cable.js +192 -0
  140. package/dist/src/index.d.ts +106 -0
  141. package/dist/src/index.js +426 -0
  142. package/dist/src/mcp/server.d.ts +38 -0
  143. package/dist/src/mcp/server.js +196 -0
  144. package/dist/src/metrics/token-tracker.d.ts +38 -0
  145. package/dist/src/metrics/token-tracker.js +112 -0
  146. package/dist/src/parsers/json-extractor.d.ts +9 -0
  147. package/dist/src/parsers/json-extractor.js +239 -0
  148. package/dist/src/parsers/opinion-schema.d.ts +81 -0
  149. package/dist/src/parsers/opinion-schema.js +147 -0
  150. package/dist/src/parsers/unstructured-parser.d.ts +20 -0
  151. package/dist/src/parsers/unstructured-parser.js +122 -0
  152. package/dist/src/pipelines/architecture.d.ts +10 -0
  153. package/dist/src/pipelines/architecture.js +9 -0
  154. package/dist/src/pipelines/bug-analysis.d.ts +9 -0
  155. package/dist/src/pipelines/bug-analysis.js +8 -0
  156. package/dist/src/pipelines/code-review.d.ts +10 -0
  157. package/dist/src/pipelines/code-review.js +30 -0
  158. package/dist/src/pipelines/custom.d.ts +14 -0
  159. package/dist/src/pipelines/custom.js +29 -0
  160. package/dist/src/pipelines/registry.d.ts +9 -0
  161. package/dist/src/pipelines/registry.js +20 -0
  162. package/dist/src/prompts/personas.d.ts +6 -0
  163. package/dist/src/prompts/personas.js +44 -0
  164. package/dist/src/prompts/schemas.d.ts +4 -0
  165. package/dist/src/prompts/schemas.js +24 -0
  166. package/dist/src/prompts/templates.d.ts +6 -0
  167. package/dist/src/prompts/templates.js +91 -0
  168. package/dist/src/repl/accessibility.d.ts +23 -0
  169. package/dist/src/repl/accessibility.js +46 -0
  170. package/dist/src/repl/banner.d.ts +4 -0
  171. package/dist/src/repl/banner.js +28 -0
  172. package/dist/src/repl/boot-animation.d.ts +13 -0
  173. package/dist/src/repl/boot-animation.js +143 -0
  174. package/dist/src/repl/completer.d.ts +21 -0
  175. package/dist/src/repl/completer.js +168 -0
  176. package/dist/src/repl/context.d.ts +24 -0
  177. package/dist/src/repl/context.js +42 -0
  178. package/dist/src/repl/display-utils.d.ts +13 -0
  179. package/dist/src/repl/display-utils.js +65 -0
  180. package/dist/src/repl/event-listener.d.ts +18 -0
  181. package/dist/src/repl/event-listener.js +112 -0
  182. package/dist/src/repl/export-formatter.d.ts +8 -0
  183. package/dist/src/repl/export-formatter.js +73 -0
  184. package/dist/src/repl/ghost-text.d.ts +31 -0
  185. package/dist/src/repl/ghost-text.js +119 -0
  186. package/dist/src/repl/handoff-animation.d.ts +15 -0
  187. package/dist/src/repl/handoff-animation.js +65 -0
  188. package/dist/src/repl/history.d.ts +16 -0
  189. package/dist/src/repl/history.js +130 -0
  190. package/dist/src/repl/job-registry.d.ts +26 -0
  191. package/dist/src/repl/job-registry.js +80 -0
  192. package/dist/src/repl/magi-repl.d.ts +72 -0
  193. package/dist/src/repl/magi-repl.js +1008 -0
  194. package/dist/src/repl/multiline-input.d.ts +45 -0
  195. package/dist/src/repl/multiline-input.js +78 -0
  196. package/dist/src/repl/prompt-builder.d.ts +19 -0
  197. package/dist/src/repl/prompt-builder.js +36 -0
  198. package/dist/src/repl/repl-state.d.ts +5 -0
  199. package/dist/src/repl/repl-state.js +19 -0
  200. package/dist/src/repl/result-display.d.ts +8 -0
  201. package/dist/src/repl/result-display.js +195 -0
  202. package/dist/src/repl/session-stats.d.ts +26 -0
  203. package/dist/src/repl/session-stats.js +119 -0
  204. package/dist/src/repl/slash-commands.d.ts +60 -0
  205. package/dist/src/repl/slash-commands.js +725 -0
  206. package/dist/src/repl/terminal-sanitize.d.ts +14 -0
  207. package/dist/src/repl/terminal-sanitize.js +19 -0
  208. package/dist/src/reporters/console.d.ts +7 -0
  209. package/dist/src/reporters/console.js +78 -0
  210. package/dist/src/reporters/json.d.ts +2 -0
  211. package/dist/src/reporters/json.js +3 -0
  212. package/dist/src/reporters/markdown.d.ts +2 -0
  213. package/dist/src/reporters/markdown.js +65 -0
  214. package/dist/src/reporters/streaming.d.ts +20 -0
  215. package/dist/src/reporters/streaming.js +178 -0
  216. package/dist/src/tui/activity-log.d.ts +23 -0
  217. package/dist/src/tui/activity-log.js +67 -0
  218. package/dist/src/tui/animations.d.ts +39 -0
  219. package/dist/src/tui/animations.js +167 -0
  220. package/dist/src/tui/ansi.d.ts +28 -0
  221. package/dist/src/tui/ansi.js +51 -0
  222. package/dist/src/tui/boot-sequence.d.ts +11 -0
  223. package/dist/src/tui/boot-sequence.js +98 -0
  224. package/dist/src/tui/colors.d.ts +101 -0
  225. package/dist/src/tui/colors.js +71 -0
  226. package/dist/src/tui/header.d.ts +24 -0
  227. package/dist/src/tui/header.js +122 -0
  228. package/dist/src/tui/index.d.ts +3 -0
  229. package/dist/src/tui/index.js +3 -0
  230. package/dist/src/tui/keypress.d.ts +25 -0
  231. package/dist/src/tui/keypress.js +95 -0
  232. package/dist/src/tui/layout.d.ts +74 -0
  233. package/dist/src/tui/layout.js +171 -0
  234. package/dist/src/tui/magi-tui.d.ts +101 -0
  235. package/dist/src/tui/magi-tui.js +754 -0
  236. package/dist/src/tui/panel.d.ts +45 -0
  237. package/dist/src/tui/panel.js +292 -0
  238. package/dist/src/tui/screen-buffer.d.ts +54 -0
  239. package/dist/src/tui/screen-buffer.js +262 -0
  240. package/dist/src/tui/status-bar.d.ts +25 -0
  241. package/dist/src/tui/status-bar.js +124 -0
  242. package/dist/src/tui/terminal-detect.d.ts +26 -0
  243. package/dist/src/tui/terminal-detect.js +44 -0
  244. package/dist/src/tui/tui-helpers.d.ts +12 -0
  245. package/dist/src/tui/tui-helpers.js +37 -0
  246. package/dist/src/types/adapter.d.ts +75 -0
  247. package/dist/src/types/adapter.js +36 -0
  248. package/dist/src/types/config.d.ts +108 -0
  249. package/dist/src/types/config.js +85 -0
  250. package/dist/src/types/consensus.d.ts +55 -0
  251. package/dist/src/types/consensus.js +17 -0
  252. package/dist/src/types/core.d.ts +178 -0
  253. package/dist/src/types/core.js +85 -0
  254. package/dist/src/types/magi-api.d.ts +62 -0
  255. package/dist/src/types/magi-api.js +7 -0
  256. package/dist/src/types/phase-h.d.ts +142 -0
  257. package/dist/src/types/phase-h.js +7 -0
  258. package/dist/src/types/phase-i.d.ts +186 -0
  259. package/dist/src/types/phase-i.js +6 -0
  260. package/dist/src/types/phase-k.d.ts +259 -0
  261. package/dist/src/types/phase-k.js +6 -0
  262. package/dist/src/types/phase-l.d.ts +199 -0
  263. package/dist/src/types/phase-l.js +6 -0
  264. package/dist/src/types/pipeline.d.ts +37 -0
  265. package/dist/src/types/pipeline.js +2 -0
  266. package/dist/src/utils/abstain-factory.d.ts +2 -0
  267. package/dist/src/utils/abstain-factory.js +18 -0
  268. package/dist/src/utils/errors.d.ts +34 -0
  269. package/dist/src/utils/errors.js +59 -0
  270. package/dist/src/utils/file-validator.d.ts +50 -0
  271. package/dist/src/utils/file-validator.js +124 -0
  272. package/dist/src/utils/fire-and-forget.d.ts +5 -0
  273. package/dist/src/utils/fire-and-forget.js +10 -0
  274. package/dist/src/utils/flag-validator.d.ts +21 -0
  275. package/dist/src/utils/flag-validator.js +79 -0
  276. package/dist/src/utils/freeze.d.ts +8 -0
  277. package/dist/src/utils/freeze.js +16 -0
  278. package/dist/src/utils/language-detector.d.ts +16 -0
  279. package/dist/src/utils/language-detector.js +159 -0
  280. package/dist/src/utils/latency-tracker.d.ts +45 -0
  281. package/dist/src/utils/latency-tracker.js +100 -0
  282. package/dist/src/utils/logger.d.ts +33 -0
  283. package/dist/src/utils/logger.js +112 -0
  284. package/dist/src/utils/process.d.ts +40 -0
  285. package/dist/src/utils/process.js +253 -0
  286. package/dist/src/utils/retry.d.ts +12 -0
  287. package/dist/src/utils/retry.js +30 -0
  288. package/dist/src/utils/safe-fs.d.ts +38 -0
  289. package/dist/src/utils/safe-fs.js +56 -0
  290. package/dist/src/utils/safe-json-parse.d.ts +15 -0
  291. package/dist/src/utils/safe-json-parse.js +49 -0
  292. package/dist/src/utils/sanitize.d.ts +14 -0
  293. package/dist/src/utils/sanitize.js +186 -0
  294. package/dist/src/utils/semaphore.d.ts +22 -0
  295. package/dist/src/utils/semaphore.js +57 -0
  296. package/dist/src/utils/shutdown.d.ts +6 -0
  297. package/dist/src/utils/shutdown.js +51 -0
  298. package/dist/src/utils/tty.d.ts +5 -0
  299. package/dist/src/utils/tty.js +7 -0
  300. package/package.json +82 -0
package/README.md ADDED
@@ -0,0 +1,377 @@
1
+ # MAGI System
2
+
3
+ > English | **[日本語](./README.ja.md)**
4
+
5
+ [![CI](https://github.com/ryu-tada/MAGI-system/actions/workflows/ci.yml/badge.svg)](https://github.com/ryu-tada/MAGI-system/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-v24+-green.svg)](https://nodejs.org/)
8
+ [![Tests](https://img.shields.io/badge/tests-2135_passing-brightgreen.svg)](./test/)
9
+ [![Soul Systems](https://img.shields.io/badge/soul_systems-20-blueviolet.svg)](#soul-system--20-subsystems-that-give-magi-a-soul)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org/)
11
+
12
+ **When one AI isn't enough** — Three AI models debate, cross-examine, and vote. Catch what a single model misses.
13
+
14
+ > *Unofficial fan project inspired by Neon Genesis Evangelion. Not affiliated with Khara, Inc.*
15
+
16
+ <p align="center">
17
+ <img src="docs/demo.gif" alt="MAGI System Demo — Evangelion TUI deliberation" width="700">
18
+ </p>
19
+
20
+ ## Try It in 60 Seconds
21
+
22
+ No API keys needed. Watch a pre-recorded 3-body deliberation with the Evangelion TUI:
23
+
24
+ ```bash
25
+ npx magi-ai demo
26
+ ```
27
+
28
+ Ready to deliberate for real? See [Quick Start](#quick-start).
29
+
30
+ ---
31
+
32
+ ## Why Multi-AI Consensus?
33
+
34
+ Every AI model has blind spots. Claude is thorough but verbose. GPT is practical but sometimes overconfident. Gemini is cautious but can be vague. **Using any single model means inheriting its biases undetected.**
35
+
36
+ MAGI forces disagreement to surface. When three models independently analyze the same code and two flag a security issue that the third missed, you know the issue is real. When all three agree, you can act with higher confidence than any single review provides.
37
+
38
+ | Single-model review | MAGI 3-body review |
39
+ |---------------------|--------------------|
40
+ | One perspective, one bias | Three perspectives, biases cancel out |
41
+ | "Looks good to me" | 2/3 APPROVE, 1 REJECT (dissent recorded) |
42
+ | You trust the model | The models verify each other |
43
+ | Silent failures | Cross-examination catches oversights |
44
+
45
+ ---
46
+
47
+ ## What is MAGI?
48
+
49
+ In *Neon Genesis Evangelion*, the MAGI supercomputer consists of three systems, each imprinted with a different aspect of Dr. Naoko Akagi's personality, making decisions through collective deliberation.
50
+
51
+ This project recreates that architecture: three AI models from different providers analyze the same problem from distinct perspectives. Cross-validation between models eliminates provider-specific biases, achieving judgment quality that no single model can reach alone.
52
+
53
+ | MAGI Unit | CLI Tool | Persona | Focus |
54
+ |-----------|----------|---------|-------|
55
+ | **MELCHIOR-1** | Claude Code (Anthropic) | Scientist | Logic, consistency, structured reasoning |
56
+ | **BALTHASAR-2** | Codex CLI (OpenAI) | Engineer | Practicality, code quality |
57
+ | **CASPER-3** | Gemini CLI (Google) | Auditor | Safety, risk, holistic perspective |
58
+
59
+ > **N-body support**: Defaults to 3 units, but supports 2-7 arbitrary AI units for deliberation.
60
+
61
+ ---
62
+
63
+ ## How It Works
64
+
65
+ ```
66
+ Phase 1: INITIAL OPINION (parallel)
67
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
68
+ │ MELCHIOR │ │ BALTHASAR │ │ CASPER │
69
+ │ (Claude) │ │ (Codex) │ │ (Gemini) │
70
+ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
71
+ └────── Promise.allSettled() ─────┘
72
+
73
+ Early exit if unanimous
74
+
75
+ Phase 2: CROSS-EXAMINATION (parallel)
76
+ Each unit critiques the other two — may change position
77
+
78
+ Phase 3: FINAL VOTE (parallel)
79
+ Final vote informed by full deliberation history → Consensus Engine decides
80
+
81
+ ┌───────▼───────┐
82
+ │ MAGI DECISION │
83
+ └───────────────┘
84
+ ```
85
+
86
+ | Decision | Condition | Outcome |
87
+ |----------|-----------|---------|
88
+ | **Unanimous** | 3/3 agree | Immediate adoption |
89
+ | **Majority** | 2/3 agree | Adopted (dissent recorded) |
90
+ | **Deadlock** | All disagree | Tiebreak / Human-in-the-loop |
91
+ | **No quorum** | 2+ ABSTAIN | Unable to decide |
92
+
93
+ ---
94
+
95
+ ## Use Cases
96
+
97
+ | Scenario | Command | What MAGI adds |
98
+ |----------|---------|----------------|
99
+ | PR code review | `magi review src/auth.ts` | 3 models catch different bug classes |
100
+ | Architecture decision | `magi decide "PostgreSQL vs MongoDB?"` | Structured pros/cons from 3 perspectives |
101
+ | Security audit | `magi deliberate "Audit this endpoint"` | Cross-validation reduces false negatives |
102
+ | Technical debt assessment | `/ops prophecy src/legacy/` | Random forest prediction from git history |
103
+ | CI/CD gate | `magi review --output json` | Machine-readable consensus for merge gates |
104
+ | Team tie-breaking | `magi decide "Monorepo migration?"` | Objective multi-perspective arbitration |
105
+
106
+ ---
107
+
108
+ ## Quick Start
109
+
110
+ ### Prerequisites
111
+
112
+ - **Node.js v24+** (v20+ minimum)
113
+ - The following 3 AI CLIs installed and authenticated:
114
+
115
+ <details>
116
+ <summary><strong>Claude Code</strong> — MELCHIOR (Anthropic)</summary>
117
+
118
+ ```bash
119
+ # Install (either one)
120
+ curl -fsSL https://claude.ai/install.sh | bash # Recommended
121
+ npm install -g @anthropic-ai/claude-code # Via Node.js
122
+
123
+ # Auth — browser authentication opens on first launch
124
+ claude
125
+ ```
126
+
127
+ Requires a paid plan (Pro / Max / Teams / Enterprise). → [Official docs](https://docs.anthropic.com/en/docs/claude-code)
128
+
129
+ </details>
130
+
131
+ <details>
132
+ <summary><strong>Codex CLI</strong> — BALTHASAR (OpenAI)</summary>
133
+
134
+ ```bash
135
+ # Install
136
+ npm install -g @openai/codex
137
+
138
+ # Auth — setup wizard starts on first launch
139
+ codex
140
+ ```
141
+
142
+ Requires a ChatGPT subscription (Plus / Pro / Team / Enterprise). → [Official repo](https://github.com/openai/codex)
143
+
144
+ </details>
145
+
146
+ <details>
147
+ <summary><strong>Gemini CLI</strong> — CASPER (Google)</summary>
148
+
149
+ ```bash
150
+ # Install
151
+ npm install -g @google/gemini-cli
152
+
153
+ # Auth — select "Sign in with Google" on first launch
154
+ gemini
155
+ ```
156
+
157
+ Free with a Google account (60 req/min, 1,000 req/day). → [Official repo](https://github.com/google-gemini/gemini-cli)
158
+
159
+ </details>
160
+
161
+ ### Install
162
+
163
+ ```bash
164
+ npm install -g magi-ai
165
+ ```
166
+
167
+ ### Verify
168
+
169
+ ```bash
170
+ magi doctor
171
+ ```
172
+
173
+ ```
174
+ ✓ MELCHIOR: 2.x.x (Claude Code)
175
+ ✓ BALTHASAR: codex-cli 0.x.x
176
+ ✓ CASPER: 0.x.x
177
+ ```
178
+
179
+ ### Start
180
+
181
+ ```bash
182
+ magi
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Usage
188
+
189
+ On launch, a NERV boot sequence plays and the interactive REPL starts. Type a question in natural language and a 3-body deliberation begins, with the full-screen TUI showing the process in real time.
190
+
191
+ ```
192
+ ╔════════════════════════════════════════════╗
193
+ ║ M A G I S Y S T E M ║
194
+ ║ REPL INTERFACE READY ║
195
+ ╚════════════════════════════════════════════╝
196
+ Type a question to deliberate. /help for commands.
197
+
198
+ MAGI[01|NORM|3/3|CTX:0]> Should we mass-adopt this new ORM?
199
+ [Full-screen TUI → NERV boot → 3-body deliberation → result]
200
+
201
+ ╔═══════════════════════════════════════════════╗
202
+ ║ MAGI DECISION: MAJORITY_APPROVE CONF 82% ║
203
+ ╠═══════════════════════════════════════════════╣
204
+ ║ MELCHIOR ✓ APPROVE ████████░░ 84% ║
205
+ ║ BALTHASAR ✓ APPROVE ██████████ 95% ║
206
+ ║ CASPER ✗ REJECT ██████░░░░ 67% ║
207
+ ╚═══════════════════════════════════════════════╝
208
+
209
+ MAGI[02|NORM|3/3|CTX:1]> Can you elaborate on the risks?
210
+ [Re-deliberation with previous context auto-injected]
211
+ ```
212
+
213
+ Type any question to start deliberation. Slash commands provide specialized operations:
214
+
215
+ | Command | Action |
216
+ |---------|--------|
217
+ | `/review <file>` | Code review deliberation (Tab completion) |
218
+ | `/decide <question>` | Architecture decision |
219
+ | `/berserk <prompt>` | BERSERK mode (5 strategies x N units deathmatch) |
220
+ | `/status` | System dashboard |
221
+ | `/export [file]` | Export deliberation results |
222
+ | `/ops watch start` | Start Angel detection daemon |
223
+ | `/diag evolve` | S² Engine self-evolution |
224
+ | `/admin self-destruct <reason>` | Self-destruct sequence (unanimous required) |
225
+ | `/help` | Full command list |
226
+
227
+ **Context persistence:** The last 5 deliberation summaries are retained and automatically injected into follow-up questions. Project context (git status, package.json, related files) is also auto-collected.
228
+
229
+ ### MCP Server (Claude Code Integration)
230
+
231
+ An `.mcp.json` is included at the repo root. Restart Claude Code and the 4 tools (`magi_deliberate`, `magi_review`, `magi_decide`, `magi_doctor`) become available automatically. Verify with MCP Inspector: `npx @modelcontextprotocol/inspector magi-mcp`
232
+
233
+ ### Programmatic API
234
+
235
+ ```typescript
236
+ import { Magi } from 'magi-ai';
237
+
238
+ const magi = new Magi();
239
+ const result = await magi.deliberate({
240
+ type: 'code-review',
241
+ title: 'Review auth middleware',
242
+ artifacts: [{ type: 'file', path: 'src/auth.ts', content: '...', language: 'typescript' }],
243
+ });
244
+
245
+ console.log(result.consensus.decision); // => 'MAJORITY_APPROVE'
246
+ ```
247
+
248
+ > Non-interactive commands (`magi deliberate`, `magi review`, `magi decide`) are also available for CI/scripts. See `magi --help`.
249
+
250
+ ---
251
+
252
+ ## Features
253
+
254
+ ### Evangelion TUI
255
+
256
+ An Evangelion-themed full-screen interface launches by default. From the NERV boot sequence to the inverted-Y 3-panel vote visualization, it faithfully recreates the feel of the original. Zero additional dependencies (raw ANSI + chalk).
257
+
258
+ - NERV boot sequence (~1.5s)
259
+ - Inverted-Y panels — BALTHASAR (top center), CASPER (bottom left), MELCHIOR (bottom right)
260
+ - Breathing animation — panel borders pulse on a sin() curve while thinking
261
+ - Cascading vote reveal + decision stamps
262
+ - BERSERK flash — red flash on berserk warning
263
+ - Detail overlay — press `1`/`2`/`3` to view per-unit reasoning
264
+
265
+ ### Soul System — 20 Subsystems That Give MAGI a Soul
266
+
267
+ 20 subsystems that map Evangelion lore into technically meaningful features:
268
+
269
+ - **Memory & Personality (EngRam)** — TF-IDF similarity search, 3-layer memory, 12-dim drift detection
270
+ - **Sync Rate** — Beta-distribution Bayesian estimation for task-fitness tracking
271
+ - **A.T. Field** — Quantitative groupthink bias detection and neutralization
272
+ - **BERSERK Mode** — 5 strategies x N units in parallel, fitness-based selection deathmatch
273
+ - **Instrumentality** — MoA weighted reasoning fusion for deadlock resolution
274
+ - **LCL** — Phase-based information density control + 4-type hallucination detection/purification
275
+ - **Angel Detection** — Git-diff-based 6-type code threat pattern detection
276
+ - **Dead Sea Scrolls** — Random forest (50 trees) technical debt prediction
277
+ - **Type-666 Firewall** — 4-layer defense-in-depth firewall
278
+ - **Self-Destruct Sequence** — BFT f=0 unanimous irreversible operation ritual
279
+ - **S² Engine** — Self-diagnosis, improvement proposals, meta-deliberation self-evolution
280
+ - **SEELE Council** — PBFT+Raft distributed consensus protocol
281
+ - **Neon Genesis** — Fisher-Yates memory survival full reset
282
+
283
+ ### Security
284
+
285
+ 9-layer security hardening: Zod schema input validation → prompt injection prevention (9 patterns) → stdin delivery + dangerous flag detection → process sandbox (ENV/CMD allowlist) → SafeOpinionSchema output validation → SHA-256 hash-chain audit log → semaphore + timeouts → replay prevention nonce → random-salt encryption
286
+
287
+ ### Auto-Context Collection
288
+
289
+ Automatically collects and injects project context (git status, package.json, directory tree) and related files (imports, test files) during deliberation. Opt out with `--no-auto-context`. Sensitive files (.env, .key, credentials, etc.) are excluded automatically.
290
+
291
+ ---
292
+
293
+ ## Architecture
294
+
295
+ ```
296
+ MAGI-system/
297
+ ├── bin/ # CLI entry points (magi, magi-mcp, magi-benchmark)
298
+ ├── src/
299
+ │ ├── index.ts # Public API (Magi class)
300
+ │ ├── types/ # TypeScript types & Zod schemas
301
+ │ ├── adapters/ # CLI wrappers (claude, codex, gemini)
302
+ │ ├── engine/ # Core deliberation (kernel, consensus, middleware)
303
+ │ │ ├── kernel/ # Deliberation loop, phase runner, unit executor
304
+ │ │ └── middleware/ # Koa-style chain (cache, firewall)
305
+ │ ├── parsers/ # Opinion extraction (JSON extractor, Zod schema, unstructured)
306
+ │ ├── pipelines/ # Task-specific flows (code-review, architecture, bug-analysis)
307
+ │ ├── tui/ # Evangelion full-screen TUI (raw ANSI, double-buffered)
308
+ │ ├── repl/ # Interactive REPL (19 slash commands, state machine)
309
+ │ ├── mcp/ # MCP server (4 tools, stdio transport)
310
+ │ ├── context/ # Auto-context collection (git, imports, tests)
311
+ │ ├── cache/ # SHA-256 keyed result cache with TTL
312
+ │ ├── metrics/ # Token usage tracking
313
+ │ ├── audit/ # SHA-256 hash chain audit logging
314
+ │ └── utils/ # Shared utilities (process sandbox, file validation)
315
+ ├── test/ # 2135 tests (vitest)
316
+ │ ├── e2e/ # E2E with real CLIs (MAGI_E2E=1 gated)
317
+ │ ├── integration/ # Orchestrator + TUI integration
318
+ │ └── unit/ # Per-module unit tests
319
+ └── docs/ # User-facing documentation
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Development
325
+
326
+ To develop from source:
327
+
328
+ ```bash
329
+ git clone https://github.com/ryu-tada/MAGI-system.git
330
+ cd MAGI-system
331
+ npm install
332
+ npm test # 2135 tests
333
+ npm run typecheck # Type check
334
+ npm run build # Build
335
+ ```
336
+
337
+ ---
338
+
339
+ ## Documentation
340
+
341
+ - [Practical Examples](docs/EXAMPLES.md) — 8 scenarios with commands and expected output
342
+ - [Tuning Guide](docs/TUNING_GUIDE.md) — Configuration reference and optimization strategies
343
+ - [Troubleshooting](docs/TROUBLESHOOTING.md) — Common issues and solutions
344
+ - [Benchmark Results](docs/BENCHMARK_RESULTS.md) — Scoring framework validation (run with real CLIs for production data)
345
+ - [Contributing](CONTRIBUTING.md) — Development setup, adding adapters/pipelines
346
+ - [Changelog](CHANGELOG.md) — Release history
347
+
348
+ ---
349
+
350
+ ## Tech Stack
351
+
352
+ - **Language**: TypeScript (ESM)
353
+ - **Runtime**: Node.js v24+ (v20+ minimum)
354
+ - **Dependencies**: commander, chalk, zod, @modelcontextprotocol/sdk
355
+ - **Test**: Vitest (2135 tests)
356
+ - **Dev**: tsx
357
+
358
+ ---
359
+
360
+ ## Credits & Legal
361
+
362
+ > "The MAGI's answer is — unanimous."
363
+ > — Ritsuko Akagi, *Neon Genesis Evangelion*
364
+
365
+ MAGI System is inspired by the MAGI supercomputer system from *Neon Genesis Evangelion*, created by Hideaki Anno and produced by Gainax / Khara, Inc.
366
+
367
+ ### Disclaimer
368
+
369
+ This is an **unofficial, non-commercial, fan-made** open-source project. It is not affiliated with, endorsed by, or connected to Khara, Inc. or any official Evangelion production.
370
+
371
+ *Neon Genesis Evangelion* and related names are copyrighted works of Khara, Inc. All rights reserved by their respective owners.
372
+
373
+ ---
374
+
375
+ ## License
376
+
377
+ MIT — See [LICENSE](./LICENSE) for details.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MAGI Benchmark CLI
4
+ *
5
+ * Runs golden-task benchmarks comparing single-Claude vs MAGI 3-body deliberation.
6
+ *
7
+ * Usage:
8
+ * npx tsx bin/magi-benchmark.ts # Full benchmark
9
+ * npx tsx bin/magi-benchmark.ts --dry-run # MockAdapter dry-run
10
+ * npx tsx bin/magi-benchmark.ts --single-only # Single Claude only
11
+ * npx tsx bin/magi-benchmark.ts --magi-only # MAGI 3-body only
12
+ * npx tsx bin/magi-benchmark.ts --category security # Category filter
13
+ */
14
+ export {};
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MAGI Benchmark CLI
4
+ *
5
+ * Runs golden-task benchmarks comparing single-Claude vs MAGI 3-body deliberation.
6
+ *
7
+ * Usage:
8
+ * npx tsx bin/magi-benchmark.ts # Full benchmark
9
+ * npx tsx bin/magi-benchmark.ts --dry-run # MockAdapter dry-run
10
+ * npx tsx bin/magi-benchmark.ts --single-only # Single Claude only
11
+ * npx tsx bin/magi-benchmark.ts --magi-only # MAGI 3-body only
12
+ * npx tsx bin/magi-benchmark.ts --category security # Category filter
13
+ */
14
+ import { Command } from 'commander';
15
+ import chalk from 'chalk';
16
+ import { BenchmarkRunner } from '../src/benchmark/runner.js';
17
+ import { GOLDEN_TASKS } from '../src/benchmark/golden-tasks.js';
18
+ const program = new Command();
19
+ program
20
+ .name('magi-benchmark')
21
+ .description('Run MAGI quality benchmarks against golden tasks')
22
+ .option('--dry-run', 'Use MockAdapters for scoring logic validation')
23
+ .option('--single-only', 'Run single-Claude benchmark only')
24
+ .option('--magi-only', 'Run MAGI 3-body benchmark only')
25
+ .option('--category <name>', 'Filter by category (code-review|architecture|bug-analysis|security)')
26
+ .option('--output-dir <path>', 'Output directory for result JSON files')
27
+ .action(async (opts) => {
28
+ const categories = new Set(GOLDEN_TASKS.map(t => t.category));
29
+ if (opts.category && !categories.has(opts.category)) {
30
+ console.error(chalk.red(`Unknown category: ${opts.category}`));
31
+ console.error(`Available: ${[...categories].join(', ')}`);
32
+ process.exit(1);
33
+ }
34
+ const runner = new BenchmarkRunner({
35
+ dryRun: opts.dryRun,
36
+ singleOnly: opts.singleOnly,
37
+ magiOnly: opts.magiOnly,
38
+ category: opts.category,
39
+ outputDir: opts.outputDir,
40
+ });
41
+ const taskCount = opts.category
42
+ ? GOLDEN_TASKS.filter(t => t.category === opts.category).length
43
+ : GOLDEN_TASKS.length;
44
+ console.log(chalk.cyan('━'.repeat(60)));
45
+ console.log(chalk.cyan.bold(' MAGI Benchmark'));
46
+ console.log(chalk.cyan('━'.repeat(60)));
47
+ console.log(` Tasks: ${taskCount}`);
48
+ console.log(` Mode: ${opts.dryRun ? 'dry-run (MockAdapter)' : 'real CLI'}`);
49
+ if (opts.singleOnly)
50
+ console.log(' Scope: single-Claude only');
51
+ if (opts.magiOnly)
52
+ console.log(' Scope: MAGI 3-body only');
53
+ if (opts.category)
54
+ console.log(` Filter: ${opts.category}`);
55
+ console.log(chalk.cyan('━'.repeat(60)));
56
+ console.log();
57
+ try {
58
+ const { single, magi } = await runner.runAll();
59
+ if (single) {
60
+ console.log(chalk.yellow('── Single Claude ──'));
61
+ console.log(` Weighted Score: ${pct(single.aggregate.weightedScore)}`);
62
+ console.log(` Vote Accuracy: ${pct(single.aggregate.voteAccuracy)}`);
63
+ console.log(` Detection Coverage: ${pct(single.aggregate.detectionCoverage)}`);
64
+ console.log(` Avg Duration: ${Math.round(single.aggregate.avgDurationMs)}ms`);
65
+ console.log();
66
+ }
67
+ if (magi) {
68
+ console.log(chalk.green('── MAGI 3-Body ──'));
69
+ console.log(` Weighted Score: ${pct(magi.aggregate.weightedScore)}`);
70
+ console.log(` Vote Accuracy: ${pct(magi.aggregate.voteAccuracy)}`);
71
+ console.log(` Detection Coverage: ${pct(magi.aggregate.detectionCoverage)}`);
72
+ console.log(` Avg Duration: ${Math.round(magi.aggregate.avgDurationMs)}ms`);
73
+ console.log();
74
+ }
75
+ if (single && magi) {
76
+ const delta = magi.aggregate.weightedScore - single.aggregate.weightedScore;
77
+ const sign = delta >= 0 ? '+' : '';
78
+ const color = delta >= 0 ? chalk.green : chalk.red;
79
+ console.log(color(` Delta (MAGI - Single): ${sign}${(delta * 100).toFixed(1)}pp`));
80
+ console.log();
81
+ }
82
+ console.log(chalk.gray('Report saved to docs/BENCHMARK_RESULTS.md'));
83
+ console.log(chalk.gray('Result JSON saved to test/benchmark/results/'));
84
+ }
85
+ catch (err) {
86
+ console.error(chalk.red('Benchmark failed:'), err);
87
+ process.exit(1);
88
+ }
89
+ });
90
+ program.parse();
91
+ function pct(value) {
92
+ return `${(value * 100).toFixed(1)}%`;
93
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MAGI MCP Server — stdio transport entry point
4
+ *
5
+ * Prevents stdout pollution from libraries (ora, chalk, etc.)
6
+ * so only MCP JSON-RPC frames appear on stdout.
7
+ */
8
+ export {};
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MAGI MCP Server — stdio transport entry point
4
+ *
5
+ * Prevents stdout pollution from libraries (ora, chalk, etc.)
6
+ * so only MCP JSON-RPC frames appear on stdout.
7
+ */
8
+ // Layer 1: Redirect console.log/info to stderr before any imports
9
+ console.log = (...args) => console.error(...args);
10
+ console.info = (...args) => console.error(...args);
11
+ // Layer 2: Environment variables to suppress color/spinner output
12
+ process.env['NO_COLOR'] = '1';
13
+ process.env['FORCE_COLOR'] = '0';
14
+ process.env['CI'] = '1';
15
+ // Layer 3: Safety flag for future use
16
+ process.env['MAGI_MCP_MODE'] = '1';
17
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
18
+ import { createMagiMcpServer } from '../src/mcp/server.js';
19
+ async function main() {
20
+ const server = createMagiMcpServer();
21
+ const transport = new StdioServerTransport();
22
+ await server.connect(transport);
23
+ console.error('[magi-mcp] Server started on stdio');
24
+ }
25
+ main().catch((error) => {
26
+ console.error('[magi-mcp] Fatal error:', error);
27
+ process.exit(1);
28
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};