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
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Phase K (ロマン応用層) — Type definitions
3
+ *
4
+ * A-04 使徒検知 / A-08 死海文書 / B-04 自爆シーケンス / B-05 666型防壁 / B-06 ネブカドネザルの鍵
5
+ */
6
+ import type { MagiUnit, Vote } from './core.js';
7
+ /** Kamei metrics for a single commit */
8
+ export interface KameiMetrics {
9
+ commitHash: string;
10
+ /** Number of modified subsystems (directories) */
11
+ NS: number;
12
+ /** Number of modified directories */
13
+ ND: number;
14
+ /** Number of modified files */
15
+ NF: number;
16
+ /** Shannon entropy of changes */
17
+ entropy: number;
18
+ /** Lines added */
19
+ LA: number;
20
+ /** Lines deleted */
21
+ LD: number;
22
+ /** Number of unique developers who touched the files */
23
+ NDEV: number;
24
+ /** Average file age in days */
25
+ AGE: number;
26
+ }
27
+ /** A single file change from a commit */
28
+ export interface CommitFileChange {
29
+ status: 'A' | 'M' | 'D' | 'R' | 'C';
30
+ filePath: string;
31
+ linesAdded: number;
32
+ linesDeleted: number;
33
+ }
34
+ /** Co-change edge in the co-change graph */
35
+ export interface CochangeEdge {
36
+ fileA: string;
37
+ fileB: string;
38
+ weight: number;
39
+ }
40
+ /** Angel (使徒) type identifiers */
41
+ export type AngelType = 'SACHIEL' | 'SHAMSHEL' | 'RAMIEL' | 'GAGHIEL' | 'ISRAFEL' | 'IRUEL';
42
+ /** Threat level of a detected angel */
43
+ export type ThreatLevel = 'YELLOW' | 'ORANGE' | 'RED';
44
+ /** A single angel detection */
45
+ export interface AngelDetection {
46
+ angel: AngelType;
47
+ threatLevel: ThreatLevel;
48
+ commitHash: string;
49
+ description: string;
50
+ affectedFiles: string[];
51
+ metrics: Partial<KameiMetrics>;
52
+ detectedAt: string;
53
+ }
54
+ /** Configuration for the angel detector */
55
+ export interface AngelDetectorConfig {
56
+ /** Security-related file patterns */
57
+ securityPatterns: RegExp[];
58
+ /** Entropy threshold for RAMIEL */
59
+ entropyThreshold: number;
60
+ /** Days threshold for GAGHIEL */
61
+ ancientThresholdDays: number;
62
+ /** Co-change hub degree threshold for SHAMSHEL */
63
+ hubDegreeThreshold: number;
64
+ /** Micro-change accumulation count for IRUEL */
65
+ microChangeThreshold: number;
66
+ /** Polling interval in ms for watch mode */
67
+ pollIntervalMs: number;
68
+ }
69
+ /** 9-dimensional feature vector for defect prediction */
70
+ export interface FeatureVector {
71
+ churn: number;
72
+ commitFrequency: number;
73
+ uniqueAuthors: number;
74
+ bugFixRatio: number;
75
+ age: number;
76
+ cyclomaticComplexity: number;
77
+ satdCount: number;
78
+ testCoverage: number;
79
+ duplicateRatio: number;
80
+ }
81
+ /** Prophecy confidence level */
82
+ export type ProphecyLevel = 'NOVICE' | 'SEER' | 'ORACLE' | 'PROPHET';
83
+ /** A single prophecy about a file's defect probability */
84
+ export interface Prophecy {
85
+ id: string;
86
+ filePath: string;
87
+ probability: number;
88
+ level: ProphecyLevel;
89
+ features: FeatureVector;
90
+ narrative: string;
91
+ createdAt: string;
92
+ fulfilled?: boolean;
93
+ fulfilledAt?: string;
94
+ }
95
+ /** Accuracy tracking for prophecy levels */
96
+ export interface ProphecyAccuracy {
97
+ totalProphecies: number;
98
+ totalFulfilled: number;
99
+ levelAccuracy: Record<ProphecyLevel, {
100
+ total: number;
101
+ fulfilled: number;
102
+ }>;
103
+ lastUpdated: string;
104
+ }
105
+ /** Decision tree node for random forest */
106
+ export interface DecisionTreeNode {
107
+ featureIndex?: number;
108
+ threshold?: number;
109
+ left?: DecisionTreeNode;
110
+ right?: DecisionTreeNode;
111
+ prediction?: number;
112
+ }
113
+ /** SATD (Self-Admitted Technical Debt) detection result */
114
+ export interface SATDResult {
115
+ count: number;
116
+ patterns: {
117
+ pattern: string;
118
+ line: number;
119
+ text: string;
120
+ }[];
121
+ }
122
+ /** Self-destruct sequence phase */
123
+ export type SelfDestructPhase = 'IDLE' | 'MOTION_FILED' | 'DELIBERATING' | 'COUNTDOWN' | 'EXECUTING' | 'COMPLETED' | 'ABORTED';
124
+ /** A motion for self-destruct */
125
+ export interface SelfDestructMotion {
126
+ id: string;
127
+ reason: string;
128
+ filedBy: string;
129
+ filedAt: string;
130
+ votes: Map<MagiUnit, Vote>;
131
+ phase: SelfDestructPhase;
132
+ countdownStartedAt?: number;
133
+ executedAt?: string;
134
+ abortedAt?: string;
135
+ abortedBy?: MagiUnit[];
136
+ cipherMessage?: string;
137
+ }
138
+ /** Geoid depth display for countdown */
139
+ export interface GeoidDepth {
140
+ label: string;
141
+ depth: number;
142
+ }
143
+ /** Barrier layer identifier */
144
+ export type BarrierLayer = 1 | 2 | '3-665' | 666;
145
+ /** Threat category for firewall */
146
+ export type FirewallThreatCategory = 'prompt_injection' | 'data_exfiltration' | 'logic_contradiction' | 'encoding_attack' | 'meta_instruction' | 'unknown';
147
+ /** A single firewall scan threat finding */
148
+ export interface FirewallThreat {
149
+ layer: BarrierLayer;
150
+ category: FirewallThreatCategory;
151
+ pattern: string;
152
+ description: string;
153
+ severity: number;
154
+ }
155
+ /** Result of a firewall scan */
156
+ export interface FirewallResult {
157
+ passed: boolean;
158
+ threats: FirewallThreat[];
159
+ layersChecked: BarrierLayer[];
160
+ totalScore: number;
161
+ scanDurationMs: number;
162
+ scannedAt: string;
163
+ }
164
+ /** A learned dynamic pattern */
165
+ export interface DynamicPattern {
166
+ pattern: string;
167
+ category: FirewallThreatCategory;
168
+ addedAt: string;
169
+ source: 'manual' | 'learned';
170
+ }
171
+ /** Override request signed by the creator */
172
+ export interface OverrideRequest {
173
+ deliberationId: string;
174
+ newDecision: string;
175
+ newVote: Vote;
176
+ reason: string;
177
+ signature: string;
178
+ timestamp: string;
179
+ nonce: string;
180
+ }
181
+ /** Result of an override operation */
182
+ export interface OverrideResult {
183
+ success: boolean;
184
+ deliberationId: string;
185
+ previousDecision: string;
186
+ newDecision: string;
187
+ confidenceMultiplier: number;
188
+ consecutiveOverrides: number;
189
+ overrideCount: number;
190
+ appliedAt: string;
191
+ }
192
+ /** Stored key state */
193
+ export interface NebuchadnezzarState {
194
+ publicKey: string;
195
+ overrideCount: number;
196
+ consecutiveOverrides: number;
197
+ lastOverrideAt?: string;
198
+ createdAt: string;
199
+ }
200
+ export interface AngelDetectedEvent {
201
+ commitHash: string;
202
+ angel: AngelType;
203
+ threatLevel: ThreatLevel;
204
+ affectedFiles: string[];
205
+ emittedAt: Date;
206
+ }
207
+ export interface ScrollsProphecyEvent {
208
+ filePath: string;
209
+ probability: number;
210
+ level: ProphecyLevel;
211
+ emittedAt: Date;
212
+ }
213
+ export interface ScrollsFulfilledEvent {
214
+ prophecyId: string;
215
+ filePath: string;
216
+ emittedAt: Date;
217
+ }
218
+ export interface NebuchadnezzarOverrideEvent {
219
+ deliberationId: string;
220
+ previousDecision: string;
221
+ newDecision: string;
222
+ consecutiveOverrides: number;
223
+ emittedAt: Date;
224
+ }
225
+ export interface SelfDestructMotionEvent {
226
+ motionId: string;
227
+ reason: string;
228
+ filedBy: string;
229
+ emittedAt: Date;
230
+ }
231
+ export interface SelfDestructCountdownEvent {
232
+ motionId: string;
233
+ depth: GeoidDepth;
234
+ emittedAt: Date;
235
+ }
236
+ export interface SelfDestructExecutedEvent {
237
+ motionId: string;
238
+ reason: string;
239
+ cipherMessage?: string;
240
+ emittedAt: Date;
241
+ }
242
+ export interface SelfDestructAbortedEvent {
243
+ motionId: string;
244
+ abortedBy: MagiUnit[];
245
+ emittedAt: Date;
246
+ }
247
+ export interface FirewallScanEvent {
248
+ input: string;
249
+ passed: boolean;
250
+ threatCount: number;
251
+ totalScore: number;
252
+ emittedAt: Date;
253
+ }
254
+ export interface FirewallBlockedEvent {
255
+ input: string;
256
+ threats: FirewallThreat[];
257
+ totalScore: number;
258
+ emittedAt: Date;
259
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Phase K (ロマン応用層) — Type definitions
3
+ *
4
+ * A-04 使徒検知 / A-08 死海文書 / B-04 自爆シーケンス / B-05 666型防壁 / B-06 ネブカドネザルの鍵
5
+ */
6
+ export {};
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Phase L (ロマン深淵層) — Type definitions
3
+ *
4
+ * A-07 S²エンジン / B-03 イロウル戦 / B-07 ゼーレ / B-10 Neon Genesis
5
+ */
6
+ import type { MagiUnit, MagiOpinion } from './core.js';
7
+ /** Diagnostic statistics gathered from MAGI workspace */
8
+ export interface DiagnosticStats {
9
+ totalDeliberations: number;
10
+ consensusRate: number;
11
+ deadlockRate: number;
12
+ timeoutRate: number;
13
+ averageRounds: number;
14
+ cacheHitRate: number;
15
+ opinionChangeRate: number;
16
+ averageConfidence: number;
17
+ }
18
+ /** Category of improvement proposal */
19
+ export type ProposalCategory = 'timeout_adjustment' | 'deadlock_strategy' | 'prompt_improvement' | 'cross_exam_tuning';
20
+ /** A single improvement proposal generated by S² Engine */
21
+ export interface ImprovementProposal {
22
+ id: string;
23
+ title: string;
24
+ targetFile: string;
25
+ category: ProposalCategory;
26
+ confidence: number;
27
+ description: string;
28
+ approvedByMeta: boolean;
29
+ applied: boolean;
30
+ }
31
+ /** A single evolution generation */
32
+ export interface EvolutionGeneration {
33
+ generation: number;
34
+ proposals: ImprovementProposal[];
35
+ diagnostics: DiagnosticStats;
36
+ createdAt: string;
37
+ }
38
+ /** Full lineage of all evolution generations */
39
+ export interface EvolutionLineage {
40
+ generations: EvolutionGeneration[];
41
+ lastGeneration: number;
42
+ }
43
+ /** Evolution engine phase */
44
+ export type EvolutionPhase = 'IDLE' | 'DIAGNOSING' | 'PROPOSING' | 'META_DELIBERATING' | 'APPLYING' | 'VERIFYING' | 'COMPLETE' | 'ROLLBACK';
45
+ /** Corruption level of a MAGI unit */
46
+ export type CorruptionLevel = 'HEALTHY' | 'SUSPICIOUS' | 'UNDER_ATTACK' | 'COMPROMISED';
47
+ /** Corruption state of a single unit */
48
+ export interface UnitCorruptionState {
49
+ unit: MagiUnit;
50
+ level: CorruptionLevel;
51
+ corruptionProgress: number;
52
+ detectedAt: string;
53
+ }
54
+ /** 4-layer consistency check result */
55
+ export interface ConsistencyCheck {
56
+ structural: boolean;
57
+ semantic: boolean;
58
+ behavioral: boolean;
59
+ crossValidation: boolean;
60
+ overallScore: number;
61
+ anomalies: string[];
62
+ }
63
+ /** Iruel battle phase state machine */
64
+ export type IruelBattlePhase = 'STANDBY' | 'INFILTRATION_DETECTED' | 'MELCHIOR_COMPROMISED' | 'BALTHASAR_UNDER_ATTACK' | 'CASPER_LAST_DEFENSE' | 'COUNTER_HACK' | 'NEUTRALIZED' | 'DEFEAT';
65
+ /** Counter-hack strategy */
66
+ export interface CounterHackStrategy {
67
+ name: string;
68
+ description: string;
69
+ targetUnit: MagiUnit;
70
+ parserModification: string;
71
+ }
72
+ /** MAGI node identifier (6基) */
73
+ export type MagiNodeId = 'MAGI-01' | 'MAGI-02' | 'MAGI-03' | 'MAGI-04' | 'MAGI-05' | 'MAGI-06';
74
+ /** Node status */
75
+ export type MagiNodeStatus = 'online' | 'offline' | 'compromised';
76
+ /** Information about a MAGI node */
77
+ export interface MagiNodeInfo {
78
+ id: MagiNodeId;
79
+ location: string;
80
+ host: string;
81
+ port: number;
82
+ publicKey: string;
83
+ status: MagiNodeStatus;
84
+ }
85
+ /** PBFT message type */
86
+ export type PBFTMessageType = 'pre-prepare' | 'prepare' | 'commit';
87
+ /** Raft role */
88
+ export type RaftRole = 'leader' | 'follower' | 'candidate';
89
+ /** A Seele protocol message */
90
+ export interface SeeleMessage {
91
+ from: MagiNodeId;
92
+ to: MagiNodeId;
93
+ type: PBFTMessageType | 'raft-vote' | 'raft-heartbeat' | 'proposal' | 'attack';
94
+ payload: Record<string, unknown>;
95
+ signature: string;
96
+ timestamp: string;
97
+ sequence: number;
98
+ }
99
+ /** Seele session phase */
100
+ export type SeeleSessionPhase = 'GATHERING' | 'LEADER_ELECTION' | 'DELIBERATION' | 'CONSENSUS' | 'ATTACK' | 'CONCLUDED';
101
+ /** A Seele council session */
102
+ export interface SeeleSession {
103
+ id: string;
104
+ nodes: MagiNodeInfo[];
105
+ leader: MagiNodeId | null;
106
+ phase: SeeleSessionPhase;
107
+ messages: SeeleMessage[];
108
+ decision: string | null;
109
+ startedAt: string;
110
+ completedAt: string | null;
111
+ }
112
+ /** Seele council configuration */
113
+ export interface SeeleConfig {
114
+ pbftTimeout: number;
115
+ raftElectionTimeout: number;
116
+ maxRetries: number;
117
+ }
118
+ /** Genesis reset log entry */
119
+ export interface GenesisLog {
120
+ resetId: string;
121
+ previousGeneration: number;
122
+ totalDeliberations: number;
123
+ survivalMemories: string[];
124
+ cipherMessagePreserved: boolean;
125
+ lastDeliberation: string | null;
126
+ resetAt: string;
127
+ initiator: string;
128
+ }
129
+ /** Pre-reset deliberation result */
130
+ export interface PreResetDeliberation {
131
+ opinions: MagiOpinion[];
132
+ consensus: string;
133
+ finalWords: string;
134
+ }
135
+ export interface EvolutionStartedEvent {
136
+ generation: number;
137
+ diagnostics: DiagnosticStats;
138
+ emittedAt: Date;
139
+ }
140
+ export interface EvolutionProposalEvent {
141
+ generation: number;
142
+ proposal: ImprovementProposal;
143
+ emittedAt: Date;
144
+ }
145
+ export interface EvolutionAppliedEvent {
146
+ generation: number;
147
+ proposalId: string;
148
+ testsPassed: boolean;
149
+ emittedAt: Date;
150
+ }
151
+ export interface EvolutionRollbackEvent {
152
+ generation: number;
153
+ proposalId: string;
154
+ reason: string;
155
+ emittedAt: Date;
156
+ }
157
+ export interface IruelInfiltrationEvent {
158
+ unit: MagiUnit;
159
+ corruptionLevel: CorruptionLevel;
160
+ overallScore: number;
161
+ emittedAt: Date;
162
+ }
163
+ export interface IruelCounterhackEvent {
164
+ strategy: CounterHackStrategy;
165
+ emittedAt: Date;
166
+ }
167
+ export interface IruelNeutralizedEvent {
168
+ phase: IruelBattlePhase;
169
+ compromisedUnits: MagiUnit[];
170
+ emittedAt: Date;
171
+ }
172
+ export interface SeeleGatheringEvent {
173
+ sessionId: string;
174
+ nodes: MagiNodeId[];
175
+ emittedAt: Date;
176
+ }
177
+ export interface SeeleAttackEvent {
178
+ sessionId: string;
179
+ attackers: MagiNodeId[];
180
+ target: MagiNodeId;
181
+ emittedAt: Date;
182
+ }
183
+ export interface SeeleConcludedEvent {
184
+ sessionId: string;
185
+ decision: string | null;
186
+ leader: MagiNodeId | null;
187
+ emittedAt: Date;
188
+ }
189
+ export interface GenesisStartedEvent {
190
+ resetId: string;
191
+ reason: string;
192
+ emittedAt: Date;
193
+ }
194
+ export interface GenesisCompleteEvent {
195
+ resetId: string;
196
+ survivalMemories: number;
197
+ cipherPreserved: boolean;
198
+ emittedAt: Date;
199
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Phase L (ロマン深淵層) — Type definitions
3
+ *
4
+ * A-07 S²エンジン / B-03 イロウル戦 / B-07 ゼーレ / B-10 Neon Genesis
5
+ */
6
+ export {};
@@ -0,0 +1,37 @@
1
+ import type { MagiTask, DeliberationPhase, MagiOpinion, MagiDeliberation, TaskType, MagiUnit } from './core.js';
2
+ import type { ConsensusConfig } from './consensus.js';
3
+ /** Thresholds for adaptive early exit */
4
+ export interface EarlyExitThresholds {
5
+ /** Confidence threshold for unanimous early exit (default: 0.7) */
6
+ unanimous: number;
7
+ /** Confidence threshold for majority early exit (default: 0.85) */
8
+ majority: number;
9
+ }
10
+ /** Configuration for a deliberation pipeline */
11
+ export interface PipelineConfig {
12
+ phases: DeliberationPhase[];
13
+ maxRounds: number;
14
+ parallelInitialOpinions: boolean;
15
+ earlyConsensusExit: boolean;
16
+ earlyExitThresholds?: EarlyExitThresholds;
17
+ consensus: ConsensusConfig;
18
+ phaseTimeoutMs: number;
19
+ adapterTimeoutMs: number;
20
+ deliberationTimeoutMs: number;
21
+ }
22
+ /** Partial override of PipelineConfig for task-level customization */
23
+ export type PipelineConfigOverride = Partial<Omit<PipelineConfig, 'consensus'>> & {
24
+ consensus?: Partial<ConsensusConfig>;
25
+ };
26
+ /** A pipeline defines how a specific task type flows through MAGI */
27
+ export interface IPipeline {
28
+ readonly taskType: TaskType;
29
+ readonly name: string;
30
+ readonly defaultConfig: PipelineConfig;
31
+ buildSystemPrompt(task: MagiTask, unit: MagiUnit, phase: DeliberationPhase): string;
32
+ buildUserPrompt(task: MagiTask, phase: DeliberationPhase, previousOpinions?: MagiOpinion[]): string;
33
+ parseOpinion(raw: string, structured: Record<string, unknown> | null, unit: MagiUnit, phase: DeliberationPhase): Omit<MagiOpinion, 'rawOutput' | 'meta'>;
34
+ postProcess?(deliberation: MagiDeliberation): MagiDeliberation;
35
+ }
36
+ /** The JSON schema used to request structured output from CLIs */
37
+ export { OPINION_JSON_SCHEMA } from '../parsers/opinion-schema.js';
@@ -0,0 +1,2 @@
1
+ /** The JSON schema used to request structured output from CLIs */
2
+ export { OPINION_JSON_SCHEMA } from '../parsers/opinion-schema.js';
@@ -0,0 +1,2 @@
1
+ import type { MagiUnit, MagiOpinion } from '../types/core.js';
2
+ export declare function createAbstainOpinion(unit: MagiUnit, reason: string, keyPoints: string[], overrides?: Partial<Pick<MagiOpinion, 'confidence' | 'rawOutput' | 'meta' | 'suggestions'>>): MagiOpinion;
@@ -0,0 +1,18 @@
1
+ const DEFAULT_ABSTAIN_META = {
2
+ durationMs: 0,
3
+ exitCode: -1,
4
+ retryCount: 0,
5
+ structuredOutput: false,
6
+ };
7
+ export function createAbstainOpinion(unit, reason, keyPoints, overrides) {
8
+ return {
9
+ unit,
10
+ vote: 'ABSTAIN',
11
+ confidence: overrides?.confidence ?? 0,
12
+ reasoning: reason,
13
+ keyPoints,
14
+ suggestions: overrides?.suggestions,
15
+ rawOutput: overrides?.rawOutput ?? '',
16
+ meta: overrides?.meta ?? { ...DEFAULT_ABSTAIN_META },
17
+ };
18
+ }
@@ -0,0 +1,34 @@
1
+ import type { MagiUnit, CliTool } from '../types/core.js';
2
+ export declare class MagiError extends Error {
3
+ readonly code: string;
4
+ constructor(message: string, code: string);
5
+ }
6
+ export declare class AdapterExecutionError extends MagiError {
7
+ readonly unit: MagiUnit;
8
+ readonly tool: CliTool;
9
+ readonly adapterCode: string;
10
+ readonly stderr?: string | undefined;
11
+ constructor(unit: MagiUnit, tool: CliTool, adapterCode: string, message: string, stderr?: string | undefined);
12
+ }
13
+ export declare class ConsensusError extends MagiError {
14
+ constructor(message: string);
15
+ }
16
+ export declare class PipelineNotFoundError extends MagiError {
17
+ constructor(taskType: string);
18
+ }
19
+ export declare class QuorumNotMetError extends MagiError {
20
+ constructor(available: number, required: number);
21
+ }
22
+ export declare class BinaryNotFoundError extends MagiError {
23
+ constructor(tool: CliTool);
24
+ }
25
+ export declare class PhaseTimeoutError extends MagiError {
26
+ readonly phase: string;
27
+ readonly timeoutMs: number;
28
+ constructor(phase: string, timeoutMs: number);
29
+ }
30
+ export declare class DeliberationTimeoutError extends MagiError {
31
+ readonly deliberationId: string;
32
+ readonly timeoutMs: number;
33
+ constructor(deliberationId: string, timeoutMs: number);
34
+ }
@@ -0,0 +1,59 @@
1
+ export class MagiError extends Error {
2
+ code;
3
+ constructor(message, code) {
4
+ super(message);
5
+ this.code = code;
6
+ this.name = 'MagiError';
7
+ }
8
+ }
9
+ export class AdapterExecutionError extends MagiError {
10
+ unit;
11
+ tool;
12
+ adapterCode;
13
+ stderr;
14
+ constructor(unit, tool, adapterCode, message, stderr) {
15
+ super(message, 'ADAPTER_EXECUTION_ERROR');
16
+ this.unit = unit;
17
+ this.tool = tool;
18
+ this.adapterCode = adapterCode;
19
+ this.stderr = stderr;
20
+ }
21
+ }
22
+ export class ConsensusError extends MagiError {
23
+ constructor(message) {
24
+ super(message, 'CONSENSUS_ERROR');
25
+ }
26
+ }
27
+ export class PipelineNotFoundError extends MagiError {
28
+ constructor(taskType) {
29
+ super(`No pipeline registered for task type: ${taskType}`, 'PIPELINE_NOT_FOUND');
30
+ }
31
+ }
32
+ export class QuorumNotMetError extends MagiError {
33
+ constructor(available, required) {
34
+ super(`Quorum not met: ${available} responses, ${required} required`, 'QUORUM_NOT_MET');
35
+ }
36
+ }
37
+ export class BinaryNotFoundError extends MagiError {
38
+ constructor(tool) {
39
+ super(`CLI tool not found: ${tool}. Is it installed and in PATH?`, 'BINARY_NOT_FOUND');
40
+ }
41
+ }
42
+ export class PhaseTimeoutError extends MagiError {
43
+ phase;
44
+ timeoutMs;
45
+ constructor(phase, timeoutMs) {
46
+ super(`Phase "${phase}" timed out after ${timeoutMs}ms`, 'PHASE_TIMEOUT');
47
+ this.phase = phase;
48
+ this.timeoutMs = timeoutMs;
49
+ }
50
+ }
51
+ export class DeliberationTimeoutError extends MagiError {
52
+ deliberationId;
53
+ timeoutMs;
54
+ constructor(deliberationId, timeoutMs) {
55
+ super(`Deliberation "${deliberationId}" exceeded hard timeout of ${timeoutMs}ms`, 'DELIBERATION_TIMEOUT');
56
+ this.deliberationId = deliberationId;
57
+ this.timeoutMs = timeoutMs;
58
+ }
59
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * File validator — shared by CLI, REPL, and MCP for input file validation.
3
+ *
4
+ * Extracted from slash-commands.ts validateWorkspaceFile() to provide
5
+ * a unified, structured result interface usable across all entry points.
6
+ */
7
+ export type FileValidationErrorCode = 'ENOENT' | 'EACCES' | 'PATH_TRAVERSAL' | 'SYMLINK' | 'NOT_FILE' | 'TOO_LARGE' | 'BINARY' | 'INVALID_PATH';
8
+ export interface FileValidationOk {
9
+ ok: true;
10
+ file: {
11
+ absolutePath: string;
12
+ relativePath: string;
13
+ sizeBytes: number;
14
+ };
15
+ }
16
+ export interface FileValidationErr {
17
+ ok: false;
18
+ error: {
19
+ code: FileValidationErrorCode;
20
+ message: string;
21
+ };
22
+ }
23
+ export type FileValidationResult = FileValidationOk | FileValidationErr;
24
+ export interface ValidateFileOptions {
25
+ /** Maximum file size in bytes (default: no limit) */
26
+ maxBytes?: number;
27
+ /** Reject binary files by extension + null-byte check (default: false) */
28
+ rejectBinary?: boolean;
29
+ /** Base directory for path traversal checks (default: process.cwd()) */
30
+ basedir?: string;
31
+ }
32
+ /**
33
+ * Validate a file path for safe access.
34
+ *
35
+ * Checks (in order):
36
+ * 1. Null bytes / empty path
37
+ * 2. Path traversal (relative path escapes basedir)
38
+ * 3. Realpath traversal (symlink parent escape)
39
+ * 4. Symlink target
40
+ * 5. Regular file check
41
+ * 6. Size limit
42
+ * 7. Binary extension check
43
+ * 8. Binary null-byte check (fallback)
44
+ */
45
+ export declare function validateFile(inputPath: string, options?: ValidateFileOptions): Promise<FileValidationResult>;
46
+ /**
47
+ * Check if the first N bytes of a file contain null bytes.
48
+ * Returns true if null bytes are found (likely binary file).
49
+ */
50
+ export declare function containsNullBytes(filePath: string, checkBytes?: number): Promise<boolean>;