@bonginkan/maria 2.0.5 → 2.0.6
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.
- package/README.md +4 -4
- package/dist/bin/maria.js +134 -30
- package/dist/bin/maria.js.map +1 -1
- package/dist/cli.js +133 -29
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +307 -1
- package/dist/index.js +2388 -537
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,11 +7,12 @@ var generativeAi = require('@google/generative-ai');
|
|
|
7
7
|
var fetch3 = require('node-fetch');
|
|
8
8
|
var chalk13 = require('chalk');
|
|
9
9
|
var fs7 = require('fs');
|
|
10
|
-
var
|
|
10
|
+
var path10 = require('path');
|
|
11
11
|
var toml = require('toml');
|
|
12
|
-
var
|
|
13
|
-
var fs6 = require('fs/promises');
|
|
12
|
+
var os3 = require('os');
|
|
14
13
|
var events = require('events');
|
|
14
|
+
var fs11 = require('fs/promises');
|
|
15
|
+
var gpt3Encoder = require('gpt-3-encoder');
|
|
15
16
|
var uuid = require('uuid');
|
|
16
17
|
var commander = require('commander');
|
|
17
18
|
var Groq = require('groq-sdk');
|
|
@@ -20,7 +21,7 @@ var crypto = require('crypto');
|
|
|
20
21
|
var child_process = require('child_process');
|
|
21
22
|
var util = require('util');
|
|
22
23
|
var dotenv = require('dotenv');
|
|
23
|
-
var
|
|
24
|
+
var glob = require('glob');
|
|
24
25
|
|
|
25
26
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
26
27
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -48,9 +49,9 @@ var Anthropic__default = /*#__PURE__*/_interopDefault(Anthropic);
|
|
|
48
49
|
var fetch3__default = /*#__PURE__*/_interopDefault(fetch3);
|
|
49
50
|
var chalk13__default = /*#__PURE__*/_interopDefault(chalk13);
|
|
50
51
|
var fs7__namespace = /*#__PURE__*/_interopNamespace(fs7);
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
52
|
+
var path10__namespace = /*#__PURE__*/_interopNamespace(path10);
|
|
53
|
+
var os3__default = /*#__PURE__*/_interopDefault(os3);
|
|
54
|
+
var fs11__namespace = /*#__PURE__*/_interopNamespace(fs11);
|
|
54
55
|
var Groq__default = /*#__PURE__*/_interopDefault(Groq);
|
|
55
56
|
var readline__namespace = /*#__PURE__*/_interopNamespace(readline);
|
|
56
57
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
@@ -152,8 +153,8 @@ var init_openai_provider = __esm({
|
|
|
152
153
|
}
|
|
153
154
|
name = "OpenAI";
|
|
154
155
|
models = [
|
|
155
|
-
"gpt-5
|
|
156
|
-
"gpt-5-mini
|
|
156
|
+
"gpt-5",
|
|
157
|
+
"gpt-5-mini",
|
|
157
158
|
"gpt-4o",
|
|
158
159
|
"gpt-4o-mini",
|
|
159
160
|
"gpt-4-turbo",
|
|
@@ -281,7 +282,7 @@ var init_anthropic_provider = __esm({
|
|
|
281
282
|
}
|
|
282
283
|
name = "Anthropic";
|
|
283
284
|
models = [
|
|
284
|
-
"claude-
|
|
285
|
+
"claude-4.1",
|
|
285
286
|
"claude-3-5-sonnet-20241022",
|
|
286
287
|
"claude-3-5-haiku-20241022",
|
|
287
288
|
"claude-3-opus-20240229",
|
|
@@ -1231,7 +1232,7 @@ var init_logger = __esm({
|
|
|
1231
1232
|
function loadConfig() {
|
|
1232
1233
|
let currentDir = process.cwd();
|
|
1233
1234
|
while (currentDir !== "/") {
|
|
1234
|
-
const configPath =
|
|
1235
|
+
const configPath = path10.join(currentDir, CONFIG_FILE);
|
|
1235
1236
|
if (fs7.existsSync(configPath)) {
|
|
1236
1237
|
try {
|
|
1237
1238
|
const content = fs7.readFileSync(configPath, "utf-8");
|
|
@@ -1239,7 +1240,7 @@ function loadConfig() {
|
|
|
1239
1240
|
} catch {
|
|
1240
1241
|
}
|
|
1241
1242
|
}
|
|
1242
|
-
const parentDir =
|
|
1243
|
+
const parentDir = path10.join(currentDir, "..");
|
|
1243
1244
|
if (parentDir === currentDir) break;
|
|
1244
1245
|
currentDir = parentDir;
|
|
1245
1246
|
}
|
|
@@ -1274,18 +1275,18 @@ async function readConfig() {
|
|
|
1274
1275
|
}
|
|
1275
1276
|
return config2;
|
|
1276
1277
|
}
|
|
1277
|
-
async function writeConfig(config2,
|
|
1278
|
+
async function writeConfig(config2, path11) {
|
|
1278
1279
|
return new Promise((resolve, reject) => {
|
|
1279
1280
|
try {
|
|
1280
|
-
saveConfig(config2,
|
|
1281
|
+
saveConfig(config2, path11);
|
|
1281
1282
|
resolve();
|
|
1282
1283
|
} catch (error) {
|
|
1283
1284
|
reject(error);
|
|
1284
1285
|
}
|
|
1285
1286
|
});
|
|
1286
1287
|
}
|
|
1287
|
-
function saveConfig(config2,
|
|
1288
|
-
const configPath =
|
|
1288
|
+
function saveConfig(config2, path11) {
|
|
1289
|
+
const configPath = path11 || path10.join(process.cwd(), CONFIG_FILE);
|
|
1289
1290
|
const lines = [];
|
|
1290
1291
|
if (config2.user) {
|
|
1291
1292
|
lines.push("[user]");
|
|
@@ -1504,13 +1505,242 @@ var init_config = __esm({
|
|
|
1504
1505
|
"src/utils/config.ts"() {
|
|
1505
1506
|
init_cjs_shims();
|
|
1506
1507
|
CONFIG_FILE = ".maria-code.toml";
|
|
1507
|
-
GLOBAL_CONFIG_PATH =
|
|
1508
|
+
GLOBAL_CONFIG_PATH = path10.join(os3.homedir(), ".maria-code", "config.toml");
|
|
1508
1509
|
__name(loadConfig, "loadConfig");
|
|
1509
1510
|
__name(readConfig, "readConfig");
|
|
1510
1511
|
__name(writeConfig, "writeConfig");
|
|
1511
1512
|
__name(saveConfig, "saveConfig");
|
|
1512
1513
|
}
|
|
1513
1514
|
});
|
|
1515
|
+
var ChatContextService;
|
|
1516
|
+
var init_chat_context_service = __esm({
|
|
1517
|
+
"src/services/chat-context.service.ts"() {
|
|
1518
|
+
init_cjs_shims();
|
|
1519
|
+
ChatContextService = class _ChatContextService extends events.EventEmitter {
|
|
1520
|
+
static {
|
|
1521
|
+
__name(this, "ChatContextService");
|
|
1522
|
+
}
|
|
1523
|
+
static instance;
|
|
1524
|
+
contextWindow = [];
|
|
1525
|
+
fullHistory = [];
|
|
1526
|
+
config;
|
|
1527
|
+
currentTokens = 0;
|
|
1528
|
+
compressionCount = 0;
|
|
1529
|
+
sessionId;
|
|
1530
|
+
constructor(config2) {
|
|
1531
|
+
super();
|
|
1532
|
+
this.config = {
|
|
1533
|
+
maxTokens: config2?.maxTokens || 128e3,
|
|
1534
|
+
compressionThreshold: config2?.compressionThreshold || 0.8,
|
|
1535
|
+
summaryTokenLimit: config2?.summaryTokenLimit || 2e3,
|
|
1536
|
+
persistPath: config2?.persistPath || path10__namespace.join(process.env["HOME"] || "", ".maria", "context")
|
|
1537
|
+
};
|
|
1538
|
+
this.sessionId = this.generateSessionId();
|
|
1539
|
+
}
|
|
1540
|
+
static getInstance(config2) {
|
|
1541
|
+
if (!_ChatContextService.instance) {
|
|
1542
|
+
_ChatContextService.instance = new _ChatContextService(config2);
|
|
1543
|
+
}
|
|
1544
|
+
return _ChatContextService.instance;
|
|
1545
|
+
}
|
|
1546
|
+
generateSessionId() {
|
|
1547
|
+
return `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
1548
|
+
}
|
|
1549
|
+
countTokens(text) {
|
|
1550
|
+
try {
|
|
1551
|
+
return gpt3Encoder.encode(text).length;
|
|
1552
|
+
} catch {
|
|
1553
|
+
return Math.ceil(text.length / 4);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
async addMessage(message) {
|
|
1557
|
+
const tokens = this.countTokens(message.content);
|
|
1558
|
+
const fullMessage = {
|
|
1559
|
+
...message,
|
|
1560
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1561
|
+
tokens
|
|
1562
|
+
};
|
|
1563
|
+
this.fullHistory.push(fullMessage);
|
|
1564
|
+
this.contextWindow.push(fullMessage);
|
|
1565
|
+
this.currentTokens += tokens;
|
|
1566
|
+
await this.optimizeMemory();
|
|
1567
|
+
this.emit("message-added", fullMessage);
|
|
1568
|
+
this.emit("context-updated", this.getStats());
|
|
1569
|
+
}
|
|
1570
|
+
async optimizeMemory() {
|
|
1571
|
+
const usageRatio = this.currentTokens / this.config.maxTokens;
|
|
1572
|
+
if (usageRatio >= this.config.compressionThreshold) {
|
|
1573
|
+
await this.compressContext();
|
|
1574
|
+
}
|
|
1575
|
+
while (this.currentTokens > this.config.maxTokens && this.contextWindow.length > 1) {
|
|
1576
|
+
const removed = this.contextWindow.shift();
|
|
1577
|
+
if (removed?.tokens) {
|
|
1578
|
+
this.currentTokens -= removed.tokens;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
async compressContext() {
|
|
1583
|
+
if (this.contextWindow.length <= 2) return;
|
|
1584
|
+
const middleMessages = this.contextWindow.slice(1, -1);
|
|
1585
|
+
const summary = await this.generateSummary(middleMessages);
|
|
1586
|
+
if (summary) {
|
|
1587
|
+
const summaryMessage = {
|
|
1588
|
+
role: "system",
|
|
1589
|
+
content: `[Compressed context summary]: ${summary}`,
|
|
1590
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1591
|
+
tokens: this.countTokens(summary),
|
|
1592
|
+
metadata: { compressed: true, originalCount: middleMessages.length }
|
|
1593
|
+
};
|
|
1594
|
+
const firstMessage = this.contextWindow[0];
|
|
1595
|
+
const lastMessage = this.contextWindow[this.contextWindow.length - 1];
|
|
1596
|
+
if (!firstMessage || !lastMessage) return;
|
|
1597
|
+
this.contextWindow = [firstMessage, summaryMessage, lastMessage];
|
|
1598
|
+
this.recalculateTokens();
|
|
1599
|
+
this.compressionCount++;
|
|
1600
|
+
this.emit("context-compressed", {
|
|
1601
|
+
originalCount: middleMessages.length,
|
|
1602
|
+
summaryTokens: summaryMessage.tokens
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
async generateSummary(messages) {
|
|
1607
|
+
const keyPoints = messages.filter((m) => m.role === "user").map((m) => m.content.substring(0, 100)).join("; ");
|
|
1608
|
+
return `Previous discussion covered: ${keyPoints}`;
|
|
1609
|
+
}
|
|
1610
|
+
recalculateTokens() {
|
|
1611
|
+
this.currentTokens = this.contextWindow.reduce((sum, msg) => sum + (msg.tokens || 0), 0);
|
|
1612
|
+
}
|
|
1613
|
+
clearContext(options) {
|
|
1614
|
+
if (options?.soft) {
|
|
1615
|
+
this.emit("display-cleared");
|
|
1616
|
+
return;
|
|
1617
|
+
}
|
|
1618
|
+
if (options?.summary && this.contextWindow.length > 0) {
|
|
1619
|
+
this.generateSummary(this.contextWindow).then((summary) => {
|
|
1620
|
+
this.emit("summary-generated", summary);
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
const previousStats = this.getStats();
|
|
1624
|
+
this.contextWindow = [];
|
|
1625
|
+
this.currentTokens = 0;
|
|
1626
|
+
this.compressionCount = 0;
|
|
1627
|
+
if (!options?.soft) {
|
|
1628
|
+
this.fullHistory = [];
|
|
1629
|
+
this.sessionId = this.generateSessionId();
|
|
1630
|
+
}
|
|
1631
|
+
this.emit("context-cleared", previousStats);
|
|
1632
|
+
}
|
|
1633
|
+
getContext() {
|
|
1634
|
+
return [...this.contextWindow];
|
|
1635
|
+
}
|
|
1636
|
+
getFullHistory() {
|
|
1637
|
+
return [...this.fullHistory];
|
|
1638
|
+
}
|
|
1639
|
+
getStats() {
|
|
1640
|
+
return {
|
|
1641
|
+
totalMessages: this.fullHistory.length,
|
|
1642
|
+
totalTokens: this.currentTokens,
|
|
1643
|
+
maxTokens: this.config.maxTokens,
|
|
1644
|
+
usagePercentage: this.currentTokens / this.config.maxTokens * 100,
|
|
1645
|
+
messagesInWindow: this.contextWindow.length,
|
|
1646
|
+
compressedCount: this.compressionCount
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
async persistSession() {
|
|
1650
|
+
if (!this.config.persistPath) return;
|
|
1651
|
+
try {
|
|
1652
|
+
await fs11__namespace.mkdir(this.config.persistPath, { recursive: true });
|
|
1653
|
+
const sessionFile = path10__namespace.join(this.config.persistPath, `${this.sessionId}.json`);
|
|
1654
|
+
const sessionData = {
|
|
1655
|
+
sessionId: this.sessionId,
|
|
1656
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1657
|
+
stats: this.getStats(),
|
|
1658
|
+
contextWindow: this.contextWindow,
|
|
1659
|
+
fullHistory: this.fullHistory,
|
|
1660
|
+
compressionCount: this.compressionCount
|
|
1661
|
+
};
|
|
1662
|
+
await fs11__namespace.writeFile(sessionFile, JSON.stringify(sessionData, null, 2));
|
|
1663
|
+
this.emit("session-persisted", sessionFile);
|
|
1664
|
+
} catch (error) {
|
|
1665
|
+
this.emit("persist-error", error instanceof Error ? error : new Error(String(error)));
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
async loadSession(sessionId) {
|
|
1669
|
+
if (!this.config.persistPath) return false;
|
|
1670
|
+
try {
|
|
1671
|
+
const sessionFile = path10__namespace.join(this.config.persistPath, `${sessionId}.json`);
|
|
1672
|
+
const data = await fs11__namespace.readFile(sessionFile, "utf-8");
|
|
1673
|
+
const sessionData = JSON.parse(data);
|
|
1674
|
+
this.sessionId = sessionData.sessionId;
|
|
1675
|
+
this.contextWindow = sessionData.contextWindow;
|
|
1676
|
+
this.fullHistory = sessionData.fullHistory;
|
|
1677
|
+
this.compressionCount = sessionData.compressionCount;
|
|
1678
|
+
this.recalculateTokens();
|
|
1679
|
+
this.emit("session-loaded", sessionId);
|
|
1680
|
+
return true;
|
|
1681
|
+
} catch (error) {
|
|
1682
|
+
this.emit("load-error", error instanceof Error ? error : new Error(String(error)));
|
|
1683
|
+
return false;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
async exportContext(format = "json") {
|
|
1687
|
+
if (format === "markdown") {
|
|
1688
|
+
return this.contextWindow.map(
|
|
1689
|
+
(msg) => `### ${msg.role.toUpperCase()} (${msg.timestamp.toISOString()})
|
|
1690
|
+
${msg.content}
|
|
1691
|
+
`
|
|
1692
|
+
).join("\n---\n\n");
|
|
1693
|
+
}
|
|
1694
|
+
return JSON.stringify(
|
|
1695
|
+
{
|
|
1696
|
+
sessionId: this.sessionId,
|
|
1697
|
+
exportDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1698
|
+
stats: this.getStats(),
|
|
1699
|
+
context: this.contextWindow,
|
|
1700
|
+
fullHistory: this.fullHistory
|
|
1701
|
+
},
|
|
1702
|
+
null,
|
|
1703
|
+
2
|
|
1704
|
+
);
|
|
1705
|
+
}
|
|
1706
|
+
async importContext(data) {
|
|
1707
|
+
try {
|
|
1708
|
+
const imported = JSON.parse(data);
|
|
1709
|
+
if (imported.context && Array.isArray(imported.context)) {
|
|
1710
|
+
this.contextWindow = imported.context;
|
|
1711
|
+
this.fullHistory = imported.fullHistory || imported.context;
|
|
1712
|
+
this.recalculateTokens();
|
|
1713
|
+
this.sessionId = imported.sessionId || this.generateSessionId();
|
|
1714
|
+
this.emit("context-imported", this.getStats());
|
|
1715
|
+
}
|
|
1716
|
+
} catch (error) {
|
|
1717
|
+
this.emit("import-error", error instanceof Error ? error : new Error(String(error)));
|
|
1718
|
+
throw error;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
getTokenUsageIndicator() {
|
|
1722
|
+
const stats = this.getStats();
|
|
1723
|
+
const percentage = Math.round(stats.usagePercentage);
|
|
1724
|
+
const blocks = Math.round(percentage / 10);
|
|
1725
|
+
const filled = "\u2588".repeat(blocks);
|
|
1726
|
+
const empty = "\u2591".repeat(10 - blocks);
|
|
1727
|
+
let color = "\x1B[32m";
|
|
1728
|
+
if (percentage > 80)
|
|
1729
|
+
color = "\x1B[31m";
|
|
1730
|
+
else if (percentage > 60) color = "\x1B[33m";
|
|
1731
|
+
return `${color}[${filled}${empty}] ${percentage}% (${stats.totalTokens}/${stats.maxTokens} tokens)\x1B[0m`;
|
|
1732
|
+
}
|
|
1733
|
+
reset() {
|
|
1734
|
+
this.contextWindow = [];
|
|
1735
|
+
this.fullHistory = [];
|
|
1736
|
+
this.currentTokens = 0;
|
|
1737
|
+
this.compressionCount = 0;
|
|
1738
|
+
this.sessionId = this.generateSessionId();
|
|
1739
|
+
_ChatContextService.instance = null;
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
});
|
|
1514
1744
|
|
|
1515
1745
|
// src/services/code-generation.service.ts
|
|
1516
1746
|
var code_generation_service_exports = {};
|
|
@@ -1875,7 +2105,7 @@ Include: function descriptions, parameter explanations, return values, usage exa
|
|
|
1875
2105
|
// Helper methods
|
|
1876
2106
|
async detectFramework() {
|
|
1877
2107
|
try {
|
|
1878
|
-
const packageJson = await
|
|
2108
|
+
const packageJson = await fs11__namespace.readFile("package.json", "utf-8");
|
|
1879
2109
|
const pkg = JSON.parse(packageJson);
|
|
1880
2110
|
if (pkg.dependencies?.react || pkg.devDependencies?.react) return "React";
|
|
1881
2111
|
if (pkg.dependencies?.vue || pkg.devDependencies?.vue) return "Vue";
|
|
@@ -1889,7 +2119,7 @@ Include: function descriptions, parameter explanations, return values, usage exa
|
|
|
1889
2119
|
}
|
|
1890
2120
|
async detectProjectType() {
|
|
1891
2121
|
try {
|
|
1892
|
-
const files = await
|
|
2122
|
+
const files = await fs11__namespace.readdir(process.cwd());
|
|
1893
2123
|
if (files.includes("package.json")) return "Node.js";
|
|
1894
2124
|
if (files.includes("requirements.txt") || files.includes("setup.py")) return "Python";
|
|
1895
2125
|
if (files.includes("go.mod")) return "Go";
|
|
@@ -1902,7 +2132,7 @@ Include: function descriptions, parameter explanations, return values, usage exa
|
|
|
1902
2132
|
async detectTestFramework(context) {
|
|
1903
2133
|
if (context.language === "javascript" || context.language === "typescript") {
|
|
1904
2134
|
try {
|
|
1905
|
-
const packageJson = await
|
|
2135
|
+
const packageJson = await fs11__namespace.readFile("package.json", "utf-8");
|
|
1906
2136
|
const pkg = JSON.parse(packageJson);
|
|
1907
2137
|
if (pkg.devDependencies?.jest) return "Jest";
|
|
1908
2138
|
if (pkg.devDependencies?.mocha) return "Mocha";
|
|
@@ -1936,7 +2166,7 @@ Include: function descriptions, parameter explanations, return values, usage exa
|
|
|
1936
2166
|
__name(this, "LanguageDetector");
|
|
1937
2167
|
}
|
|
1938
2168
|
async detectFromFile(filePath) {
|
|
1939
|
-
const ext =
|
|
2169
|
+
const ext = path10__namespace.extname(filePath).toLowerCase();
|
|
1940
2170
|
const languageMap = {
|
|
1941
2171
|
".js": "javascript",
|
|
1942
2172
|
".jsx": "javascript",
|
|
@@ -5470,10 +5700,10 @@ var init_multi_agent_system = __esm({
|
|
|
5470
5700
|
/**
|
|
5471
5701
|
* Index current codebase for CodeRAG
|
|
5472
5702
|
*/
|
|
5473
|
-
async indexCurrentCodebase(
|
|
5703
|
+
async indexCurrentCodebase(path11 = ".", options = {}) {
|
|
5474
5704
|
try {
|
|
5475
|
-
logger.info(`Indexing codebase for CodeRAG: ${
|
|
5476
|
-
const result = await codeRAGService.indexCodebase(
|
|
5705
|
+
logger.info(`Indexing codebase for CodeRAG: ${path11}`);
|
|
5706
|
+
const result = await codeRAGService.indexCodebase(path11, {
|
|
5477
5707
|
fileTypes: options.fileTypes || [".ts", ".tsx", ".js", ".jsx"],
|
|
5478
5708
|
excludePaths: options.excludePaths || ["node_modules", "dist", ".git"],
|
|
5479
5709
|
chunkSize: 500,
|
|
@@ -5995,119 +6225,1370 @@ var init_llm_startup_manager = __esm({
|
|
|
5995
6225
|
console.log("\n\u{1F389} Ready! Using cloud providers");
|
|
5996
6226
|
}
|
|
5997
6227
|
}
|
|
5998
|
-
async checkService(service) {
|
|
5999
|
-
service.status = "checking";
|
|
6000
|
-
service.progress = 0;
|
|
6228
|
+
async checkService(service) {
|
|
6229
|
+
service.status = "checking";
|
|
6230
|
+
service.progress = 0;
|
|
6231
|
+
try {
|
|
6232
|
+
const { LLMHealthChecker: LLMHealthChecker2 } = await Promise.resolve().then(() => (init_llm_health_checker(), llm_health_checker_exports));
|
|
6233
|
+
const healthChecker = new LLMHealthChecker2();
|
|
6234
|
+
const healthStatus = await healthChecker.checkService(service.name);
|
|
6235
|
+
for (let progress = 0; progress <= 100; progress += 25) {
|
|
6236
|
+
service.progress = progress;
|
|
6237
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
6238
|
+
}
|
|
6239
|
+
if (healthStatus.isRunning) {
|
|
6240
|
+
service.status = "running";
|
|
6241
|
+
service.progress = 100;
|
|
6242
|
+
if (healthStatus.models && healthStatus.models.length > 0) {
|
|
6243
|
+
service.message = `${healthStatus.models.length} models available`;
|
|
6244
|
+
} else {
|
|
6245
|
+
service.message = "Running";
|
|
6246
|
+
}
|
|
6247
|
+
} else {
|
|
6248
|
+
service.status = "not-installed";
|
|
6249
|
+
service.message = "Not running";
|
|
6250
|
+
service.progress = 0;
|
|
6251
|
+
}
|
|
6252
|
+
} catch {
|
|
6253
|
+
service.status = "not-installed";
|
|
6254
|
+
service.message = "Skipping...";
|
|
6255
|
+
service.progress = 0;
|
|
6256
|
+
}
|
|
6257
|
+
}
|
|
6258
|
+
displayWelcome() {
|
|
6259
|
+
const frameWidth = 86;
|
|
6260
|
+
const horizontalLine = "\u2550".repeat(frameWidth - 2);
|
|
6261
|
+
const emptyLine = "\u2551" + " ".repeat(frameWidth - 2) + "\u2551";
|
|
6262
|
+
const centerText = /* @__PURE__ */ __name((text) => {
|
|
6263
|
+
const plainText = text.replace(/\u001B\[[0-9;]*m/g, "");
|
|
6264
|
+
const padding = Math.max(0, frameWidth - 2 - plainText.length);
|
|
6265
|
+
const leftPad = Math.floor(padding / 2);
|
|
6266
|
+
const rightPad = padding - leftPad;
|
|
6267
|
+
return "\u2551" + " ".repeat(leftPad) + text + " ".repeat(rightPad) + "\u2551";
|
|
6268
|
+
}, "centerText");
|
|
6269
|
+
console.log("\n");
|
|
6270
|
+
console.log(chalk13__default.default.magentaBright("\u2554" + horizontalLine + "\u2557"));
|
|
6271
|
+
console.log(chalk13__default.default.magentaBright(emptyLine));
|
|
6272
|
+
console.log(
|
|
6273
|
+
chalk13__default.default.magentaBright(
|
|
6274
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 "))
|
|
6275
|
+
)
|
|
6276
|
+
);
|
|
6277
|
+
console.log(
|
|
6278
|
+
chalk13__default.default.magentaBright(
|
|
6279
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557"))
|
|
6280
|
+
)
|
|
6281
|
+
);
|
|
6282
|
+
console.log(
|
|
6283
|
+
chalk13__default.default.magentaBright(
|
|
6284
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551"))
|
|
6285
|
+
)
|
|
6286
|
+
);
|
|
6287
|
+
console.log(
|
|
6288
|
+
chalk13__default.default.magentaBright(
|
|
6289
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551"))
|
|
6290
|
+
)
|
|
6291
|
+
);
|
|
6292
|
+
console.log(
|
|
6293
|
+
chalk13__default.default.magentaBright(
|
|
6294
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551"))
|
|
6295
|
+
)
|
|
6296
|
+
);
|
|
6297
|
+
console.log(
|
|
6298
|
+
chalk13__default.default.magentaBright(
|
|
6299
|
+
centerText(chalk13__default.default.bold.magentaBright("\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D"))
|
|
6300
|
+
)
|
|
6301
|
+
);
|
|
6302
|
+
console.log(chalk13__default.default.magentaBright(emptyLine));
|
|
6303
|
+
console.log(
|
|
6304
|
+
chalk13__default.default.magentaBright(centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557")))
|
|
6305
|
+
);
|
|
6306
|
+
console.log(
|
|
6307
|
+
chalk13__default.default.magentaBright(
|
|
6308
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D"))
|
|
6309
|
+
)
|
|
6310
|
+
);
|
|
6311
|
+
console.log(
|
|
6312
|
+
chalk13__default.default.magentaBright(
|
|
6313
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 "))
|
|
6314
|
+
)
|
|
6315
|
+
);
|
|
6316
|
+
console.log(
|
|
6317
|
+
chalk13__default.default.magentaBright(
|
|
6318
|
+
centerText(chalk13__default.default.bold.magentaBright("\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D "))
|
|
6319
|
+
)
|
|
6320
|
+
);
|
|
6321
|
+
console.log(
|
|
6322
|
+
chalk13__default.default.magentaBright(
|
|
6323
|
+
centerText(chalk13__default.default.bold.magentaBright("\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"))
|
|
6324
|
+
)
|
|
6325
|
+
);
|
|
6326
|
+
console.log(
|
|
6327
|
+
chalk13__default.default.magentaBright(
|
|
6328
|
+
centerText(chalk13__default.default.bold.magentaBright(" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"))
|
|
6329
|
+
)
|
|
6330
|
+
);
|
|
6331
|
+
console.log(chalk13__default.default.magentaBright(emptyLine));
|
|
6332
|
+
console.log(
|
|
6333
|
+
chalk13__default.default.magentaBright(centerText(chalk13__default.default.whiteBright("AI-Powered Development Platform")))
|
|
6334
|
+
);
|
|
6335
|
+
console.log(chalk13__default.default.magentaBright(centerText(chalk13__default.default.gray("(c) 2025 Bonginkan Inc."))));
|
|
6336
|
+
console.log(chalk13__default.default.magentaBright(emptyLine));
|
|
6337
|
+
console.log(chalk13__default.default.magentaBright("\u255A" + horizontalLine + "\u255D"));
|
|
6338
|
+
console.log("");
|
|
6339
|
+
}
|
|
6340
|
+
};
|
|
6341
|
+
}
|
|
6342
|
+
});
|
|
6343
|
+
|
|
6344
|
+
// src/slash-commands/base-command.ts
|
|
6345
|
+
exports.BaseCommand = void 0;
|
|
6346
|
+
var init_base_command = __esm({
|
|
6347
|
+
"src/slash-commands/base-command.ts"() {
|
|
6348
|
+
init_cjs_shims();
|
|
6349
|
+
init_logger();
|
|
6350
|
+
exports.BaseCommand = class {
|
|
6351
|
+
static {
|
|
6352
|
+
__name(this, "BaseCommand");
|
|
6353
|
+
}
|
|
6354
|
+
// Optional properties with defaults
|
|
6355
|
+
aliases = [];
|
|
6356
|
+
usage = "";
|
|
6357
|
+
examples = [];
|
|
6358
|
+
permissions;
|
|
6359
|
+
middleware = [];
|
|
6360
|
+
rateLimit;
|
|
6361
|
+
// Metadata with defaults
|
|
6362
|
+
metadata = {
|
|
6363
|
+
version: "1.0.0",
|
|
6364
|
+
author: "MARIA Team",
|
|
6365
|
+
deprecated: false,
|
|
6366
|
+
experimental: false
|
|
6367
|
+
};
|
|
6368
|
+
// Cache for frequently used data
|
|
6369
|
+
cache = /* @__PURE__ */ new Map();
|
|
6370
|
+
/**
|
|
6371
|
+
* Initialize the command (called once when registered)
|
|
6372
|
+
*/
|
|
6373
|
+
async initialize() {
|
|
6374
|
+
logger.debug(`Initializing command: ${this.name}`);
|
|
6375
|
+
}
|
|
6376
|
+
/**
|
|
6377
|
+
* Validate command arguments
|
|
6378
|
+
*/
|
|
6379
|
+
async validate(_args) {
|
|
6380
|
+
return { success: true };
|
|
6381
|
+
}
|
|
6382
|
+
/**
|
|
6383
|
+
* Cleanup resources (called when command is unregistered)
|
|
6384
|
+
*/
|
|
6385
|
+
async cleanup() {
|
|
6386
|
+
this.cache.clear();
|
|
6387
|
+
logger.debug(`Cleanup command: ${this.name}`);
|
|
6388
|
+
}
|
|
6389
|
+
/**
|
|
6390
|
+
* Rollback on error - override for custom rollback logic
|
|
6391
|
+
*/
|
|
6392
|
+
async rollback(_context, error) {
|
|
6393
|
+
logger.error(`Rollback for ${this.name}:`, error);
|
|
6394
|
+
}
|
|
6395
|
+
// Helper methods for subclasses
|
|
6396
|
+
/**
|
|
6397
|
+
* Parse command arguments into structured format
|
|
6398
|
+
*/
|
|
6399
|
+
parseArgs(raw) {
|
|
6400
|
+
const args = {
|
|
6401
|
+
raw,
|
|
6402
|
+
parsed: {},
|
|
6403
|
+
flags: {},
|
|
6404
|
+
options: {}
|
|
6405
|
+
};
|
|
6406
|
+
for (let i = 0; i < raw.length; i++) {
|
|
6407
|
+
const arg = raw[i];
|
|
6408
|
+
if (!arg) continue;
|
|
6409
|
+
if (arg.startsWith("--")) {
|
|
6410
|
+
const key = arg.slice(2);
|
|
6411
|
+
const nextArg = raw[i + 1];
|
|
6412
|
+
if (nextArg && !nextArg.startsWith("-")) {
|
|
6413
|
+
args.options[key] = nextArg;
|
|
6414
|
+
i++;
|
|
6415
|
+
} else {
|
|
6416
|
+
args.flags[key] = true;
|
|
6417
|
+
}
|
|
6418
|
+
} else if (arg && arg.startsWith("-") && arg.length === 2) {
|
|
6419
|
+
args.flags[arg.slice(1)] = true;
|
|
6420
|
+
} else {
|
|
6421
|
+
if (!args.parsed["positional"]) {
|
|
6422
|
+
args.parsed["positional"] = [];
|
|
6423
|
+
}
|
|
6424
|
+
args.parsed["positional"].push(arg);
|
|
6425
|
+
}
|
|
6426
|
+
}
|
|
6427
|
+
return args;
|
|
6428
|
+
}
|
|
6429
|
+
/**
|
|
6430
|
+
* Create a success response
|
|
6431
|
+
*/
|
|
6432
|
+
success(message, data, metadata) {
|
|
6433
|
+
return {
|
|
6434
|
+
success: true,
|
|
6435
|
+
message,
|
|
6436
|
+
data,
|
|
6437
|
+
metadata: {
|
|
6438
|
+
executionTime: Date.now(),
|
|
6439
|
+
commandVersion: this.metadata.version,
|
|
6440
|
+
...metadata
|
|
6441
|
+
}
|
|
6442
|
+
};
|
|
6443
|
+
}
|
|
6444
|
+
/**
|
|
6445
|
+
* Create an error response
|
|
6446
|
+
*/
|
|
6447
|
+
error(message, code, details) {
|
|
6448
|
+
return {
|
|
6449
|
+
success: false,
|
|
6450
|
+
message,
|
|
6451
|
+
data: { code, details },
|
|
6452
|
+
metadata: {
|
|
6453
|
+
executionTime: Date.now(),
|
|
6454
|
+
commandVersion: this.metadata.version
|
|
6455
|
+
}
|
|
6456
|
+
};
|
|
6457
|
+
}
|
|
6458
|
+
/**
|
|
6459
|
+
* Cache data with TTL
|
|
6460
|
+
*/
|
|
6461
|
+
setCache(key, data, ttlSeconds = 60) {
|
|
6462
|
+
this.cache.set(key, {
|
|
6463
|
+
data,
|
|
6464
|
+
expires: Date.now() + ttlSeconds * 1e3
|
|
6465
|
+
});
|
|
6466
|
+
}
|
|
6467
|
+
/**
|
|
6468
|
+
* Get cached data
|
|
6469
|
+
*/
|
|
6470
|
+
getCache(key) {
|
|
6471
|
+
const cached = this.cache.get(key);
|
|
6472
|
+
if (!cached) {
|
|
6473
|
+
return null;
|
|
6474
|
+
}
|
|
6475
|
+
if (cached.expires < Date.now()) {
|
|
6476
|
+
this.cache.delete(key);
|
|
6477
|
+
return null;
|
|
6478
|
+
}
|
|
6479
|
+
return cached.data;
|
|
6480
|
+
}
|
|
6481
|
+
/**
|
|
6482
|
+
* Check if user has required permissions
|
|
6483
|
+
*/
|
|
6484
|
+
async checkPermissions(context) {
|
|
6485
|
+
if (!this.permissions) {
|
|
6486
|
+
return { success: true };
|
|
6487
|
+
}
|
|
6488
|
+
const { requiresAuth, requiresPremium, role } = this.permissions;
|
|
6489
|
+
if (requiresAuth && !context.user) {
|
|
6490
|
+
return {
|
|
6491
|
+
success: false,
|
|
6492
|
+
error: "Authentication required",
|
|
6493
|
+
suggestions: ["Run /login to authenticate"]
|
|
6494
|
+
};
|
|
6495
|
+
}
|
|
6496
|
+
if (role && context.user?.role !== role) {
|
|
6497
|
+
return {
|
|
6498
|
+
success: false,
|
|
6499
|
+
error: `Required role: ${role}`,
|
|
6500
|
+
suggestions: [`Contact admin for ${role} access`]
|
|
6501
|
+
};
|
|
6502
|
+
}
|
|
6503
|
+
if (requiresPremium) {
|
|
6504
|
+
logger.warn("Premium check not implemented");
|
|
6505
|
+
}
|
|
6506
|
+
return { success: true };
|
|
6507
|
+
}
|
|
6508
|
+
/**
|
|
6509
|
+
* Format help text for this command
|
|
6510
|
+
*/
|
|
6511
|
+
formatHelp() {
|
|
6512
|
+
const lines = [];
|
|
6513
|
+
lines.push(`\u{1F4D8} ${this.name.toUpperCase()}`);
|
|
6514
|
+
lines.push("\u2500".repeat(40));
|
|
6515
|
+
lines.push(`
|
|
6516
|
+
${this.description}
|
|
6517
|
+
`);
|
|
6518
|
+
if (this.usage) {
|
|
6519
|
+
lines.push("**Usage:**");
|
|
6520
|
+
lines.push(` /${this.name} ${this.usage}
|
|
6521
|
+
`);
|
|
6522
|
+
}
|
|
6523
|
+
if (this.aliases && this.aliases.length > 0) {
|
|
6524
|
+
lines.push("**Aliases:**");
|
|
6525
|
+
lines.push(` ${this.aliases.map((a) => `/${a}`).join(", ")}
|
|
6526
|
+
`);
|
|
6527
|
+
}
|
|
6528
|
+
if (this.examples.length > 0) {
|
|
6529
|
+
lines.push("**Examples:**");
|
|
6530
|
+
this.examples.forEach((ex) => {
|
|
6531
|
+
lines.push(` ${ex.input}`);
|
|
6532
|
+
lines.push(` ${ex.description}`);
|
|
6533
|
+
if (ex.output) {
|
|
6534
|
+
lines.push(` \u2192 ${ex.output}`);
|
|
6535
|
+
}
|
|
6536
|
+
});
|
|
6537
|
+
lines.push("");
|
|
6538
|
+
}
|
|
6539
|
+
if (this.permissions) {
|
|
6540
|
+
lines.push("**Requirements:**");
|
|
6541
|
+
if (this.permissions.requiresAuth) {
|
|
6542
|
+
lines.push(" \u2022 Authentication required");
|
|
6543
|
+
}
|
|
6544
|
+
if (this.permissions.role) {
|
|
6545
|
+
lines.push(` \u2022 Role: ${this.permissions.role}`);
|
|
6546
|
+
}
|
|
6547
|
+
if (this.permissions.requiresPremium) {
|
|
6548
|
+
lines.push(" \u2022 Premium subscription");
|
|
6549
|
+
}
|
|
6550
|
+
lines.push("");
|
|
6551
|
+
}
|
|
6552
|
+
if (this.metadata.experimental) {
|
|
6553
|
+
lines.push("\u26A0\uFE0F **Experimental Feature**");
|
|
6554
|
+
}
|
|
6555
|
+
if (this.metadata.deprecated) {
|
|
6556
|
+
lines.push(`\u26A0\uFE0F **Deprecated** - Use ${this.metadata.replacedBy || "alternative"} instead`);
|
|
6557
|
+
}
|
|
6558
|
+
return lines.join("\n");
|
|
6559
|
+
}
|
|
6560
|
+
/**
|
|
6561
|
+
* Log command execution
|
|
6562
|
+
*/
|
|
6563
|
+
logExecution(args, context, result) {
|
|
6564
|
+
const logData = {
|
|
6565
|
+
command: this.name,
|
|
6566
|
+
args: args.raw,
|
|
6567
|
+
user: context.user?.id,
|
|
6568
|
+
success: result.success,
|
|
6569
|
+
executionTime: result.metadata?.executionTime
|
|
6570
|
+
};
|
|
6571
|
+
if (result.success) {
|
|
6572
|
+
logger.info("Command executed", logData);
|
|
6573
|
+
} else {
|
|
6574
|
+
logger.error("Command failed", { ...logData, error: result.message });
|
|
6575
|
+
}
|
|
6576
|
+
}
|
|
6577
|
+
};
|
|
6578
|
+
}
|
|
6579
|
+
});
|
|
6580
|
+
|
|
6581
|
+
// src/slash-commands/middleware/auth.ts
|
|
6582
|
+
var auth_exports = {};
|
|
6583
|
+
__export(auth_exports, {
|
|
6584
|
+
AuthMiddleware: () => AuthMiddleware,
|
|
6585
|
+
authMiddleware: () => authMiddleware
|
|
6586
|
+
});
|
|
6587
|
+
var AuthMiddleware, authMiddleware;
|
|
6588
|
+
var init_auth = __esm({
|
|
6589
|
+
"src/slash-commands/middleware/auth.ts"() {
|
|
6590
|
+
init_cjs_shims();
|
|
6591
|
+
init_logger();
|
|
6592
|
+
AuthMiddleware = class {
|
|
6593
|
+
static {
|
|
6594
|
+
__name(this, "AuthMiddleware");
|
|
6595
|
+
}
|
|
6596
|
+
name = "auth";
|
|
6597
|
+
priority = 10;
|
|
6598
|
+
// Run early in the chain
|
|
6599
|
+
async execute(command, _args, context, next) {
|
|
6600
|
+
const cmd = command;
|
|
6601
|
+
if (!cmd.permissions?.requiresAuth) {
|
|
6602
|
+
return next();
|
|
6603
|
+
}
|
|
6604
|
+
if (!context.user) {
|
|
6605
|
+
logger.warn(
|
|
6606
|
+
`Unauthenticated access attempt for command: ${command.name}`
|
|
6607
|
+
);
|
|
6608
|
+
return {
|
|
6609
|
+
success: false,
|
|
6610
|
+
message: "\u{1F512} Authentication required",
|
|
6611
|
+
data: {
|
|
6612
|
+
suggestions: ["Run /login to authenticate", "Or use /help login for more information"]
|
|
6613
|
+
},
|
|
6614
|
+
component: "auth-flow"
|
|
6615
|
+
};
|
|
6616
|
+
}
|
|
6617
|
+
logger.debug(`Authenticated user ${context.user.id} executing command`);
|
|
6618
|
+
return next();
|
|
6619
|
+
}
|
|
6620
|
+
};
|
|
6621
|
+
authMiddleware = new AuthMiddleware();
|
|
6622
|
+
}
|
|
6623
|
+
});
|
|
6624
|
+
|
|
6625
|
+
// src/slash-commands/middleware/validation.ts
|
|
6626
|
+
var validation_exports = {};
|
|
6627
|
+
__export(validation_exports, {
|
|
6628
|
+
ValidationMiddleware: () => ValidationMiddleware,
|
|
6629
|
+
validationMiddleware: () => validationMiddleware
|
|
6630
|
+
});
|
|
6631
|
+
var ValidationMiddleware, validationMiddleware;
|
|
6632
|
+
var init_validation = __esm({
|
|
6633
|
+
"src/slash-commands/middleware/validation.ts"() {
|
|
6634
|
+
init_cjs_shims();
|
|
6635
|
+
init_logger();
|
|
6636
|
+
ValidationMiddleware = class {
|
|
6637
|
+
static {
|
|
6638
|
+
__name(this, "ValidationMiddleware");
|
|
6639
|
+
}
|
|
6640
|
+
name = "validation";
|
|
6641
|
+
priority = 20;
|
|
6642
|
+
// Run after auth
|
|
6643
|
+
async execute(command, args, _context, next) {
|
|
6644
|
+
const validationResult = await this.validateArgs(command, args);
|
|
6645
|
+
if (!validationResult.success) {
|
|
6646
|
+
return validationResult;
|
|
6647
|
+
}
|
|
6648
|
+
return next();
|
|
6649
|
+
}
|
|
6650
|
+
async validateArgs(command, args) {
|
|
6651
|
+
if (args.flags["help"] || args.flags["h"]) {
|
|
6652
|
+
return {
|
|
6653
|
+
success: true,
|
|
6654
|
+
message: this.formatHelp(command),
|
|
6655
|
+
component: "help-dialog"
|
|
6656
|
+
};
|
|
6657
|
+
}
|
|
6658
|
+
if (command.usage) {
|
|
6659
|
+
const requiredArgs = this.parseRequiredArgs(command.usage);
|
|
6660
|
+
const positional = args.parsed["positional"] || [];
|
|
6661
|
+
if (requiredArgs.length > positional.length) {
|
|
6662
|
+
return {
|
|
6663
|
+
success: false,
|
|
6664
|
+
message: `Missing required arguments
|
|
6665
|
+
|
|
6666
|
+
Usage: /${command.name} ${command.usage}`,
|
|
6667
|
+
data: {
|
|
6668
|
+
missing: requiredArgs.slice(positional.length),
|
|
6669
|
+
examples: command.examples
|
|
6670
|
+
}
|
|
6671
|
+
};
|
|
6672
|
+
}
|
|
6673
|
+
}
|
|
6674
|
+
const validationErrors = [];
|
|
6675
|
+
const knownFlags = this.extractKnownFlags(command.usage);
|
|
6676
|
+
for (const flag of Object.keys(args.flags)) {
|
|
6677
|
+
if (!knownFlags.includes(flag) && flag !== "help" && flag !== "h") {
|
|
6678
|
+
validationErrors.push(`Unknown flag: --${flag}`);
|
|
6679
|
+
}
|
|
6680
|
+
}
|
|
6681
|
+
if (validationErrors.length > 0) {
|
|
6682
|
+
logger.warn(`Validation errors for command ${command.name}:`, validationErrors);
|
|
6683
|
+
return {
|
|
6684
|
+
success: false,
|
|
6685
|
+
message: validationErrors.join("\n"),
|
|
6686
|
+
data: {
|
|
6687
|
+
suggestions: [`Run /${command.name} --help for usage information`]
|
|
6688
|
+
}
|
|
6689
|
+
};
|
|
6690
|
+
}
|
|
6691
|
+
return { success: true, message: "" };
|
|
6692
|
+
}
|
|
6693
|
+
parseRequiredArgs(usage) {
|
|
6694
|
+
const required = [];
|
|
6695
|
+
const regex = /<([^>]+)>/g;
|
|
6696
|
+
let match;
|
|
6697
|
+
while ((match = regex.exec(usage)) !== null) {
|
|
6698
|
+
if (match[1]) {
|
|
6699
|
+
required.push(match[1]);
|
|
6700
|
+
}
|
|
6701
|
+
}
|
|
6702
|
+
return required;
|
|
6703
|
+
}
|
|
6704
|
+
extractKnownFlags(usage) {
|
|
6705
|
+
const flags = [];
|
|
6706
|
+
const regex = /--([a-z-]+)/g;
|
|
6707
|
+
let match;
|
|
6708
|
+
while ((match = regex.exec(usage)) !== null) {
|
|
6709
|
+
if (match[1]) {
|
|
6710
|
+
flags.push(match[1]);
|
|
6711
|
+
}
|
|
6712
|
+
}
|
|
6713
|
+
return flags;
|
|
6714
|
+
}
|
|
6715
|
+
formatHelp(command) {
|
|
6716
|
+
const lines = [];
|
|
6717
|
+
lines.push(`\u{1F4D8} **${command.name.toUpperCase()}**`);
|
|
6718
|
+
lines.push("\u2500".repeat(40));
|
|
6719
|
+
lines.push("");
|
|
6720
|
+
lines.push(command.description);
|
|
6721
|
+
lines.push("");
|
|
6722
|
+
if (command.usage) {
|
|
6723
|
+
lines.push("**Usage:**");
|
|
6724
|
+
lines.push(` /${command.name} ${command.usage}`);
|
|
6725
|
+
lines.push("");
|
|
6726
|
+
}
|
|
6727
|
+
if (command.aliases && command.aliases.length > 0) {
|
|
6728
|
+
lines.push("**Aliases:**");
|
|
6729
|
+
lines.push(` ${command.aliases.map((a) => `/${a}`).join(", ")}`);
|
|
6730
|
+
lines.push("");
|
|
6731
|
+
}
|
|
6732
|
+
if (command.examples && command.examples.length > 0) {
|
|
6733
|
+
lines.push("**Examples:**");
|
|
6734
|
+
command.examples.forEach((ex) => {
|
|
6735
|
+
lines.push(` ${ex.input}`);
|
|
6736
|
+
lines.push(` ${ex.description}`);
|
|
6737
|
+
if (ex.output) {
|
|
6738
|
+
lines.push(` \u2192 ${ex.output}`);
|
|
6739
|
+
}
|
|
6740
|
+
});
|
|
6741
|
+
lines.push("");
|
|
6742
|
+
}
|
|
6743
|
+
if (command.metadata.experimental) {
|
|
6744
|
+
lines.push("\u26A0\uFE0F **Experimental Feature**");
|
|
6745
|
+
}
|
|
6746
|
+
if (command.metadata.deprecated) {
|
|
6747
|
+
lines.push(
|
|
6748
|
+
`\u26A0\uFE0F **Deprecated** - Use ${command.metadata.replacedBy || "alternative"} instead`
|
|
6749
|
+
);
|
|
6750
|
+
}
|
|
6751
|
+
return lines.join("\n");
|
|
6752
|
+
}
|
|
6753
|
+
};
|
|
6754
|
+
validationMiddleware = new ValidationMiddleware();
|
|
6755
|
+
}
|
|
6756
|
+
});
|
|
6757
|
+
|
|
6758
|
+
// src/slash-commands/middleware/rate-limit.ts
|
|
6759
|
+
var rate_limit_exports = {};
|
|
6760
|
+
__export(rate_limit_exports, {
|
|
6761
|
+
RateLimitMiddleware: () => RateLimitMiddleware,
|
|
6762
|
+
rateLimitMiddleware: () => rateLimitMiddleware
|
|
6763
|
+
});
|
|
6764
|
+
var RateLimitMiddleware, rateLimitMiddleware;
|
|
6765
|
+
var init_rate_limit = __esm({
|
|
6766
|
+
"src/slash-commands/middleware/rate-limit.ts"() {
|
|
6767
|
+
init_cjs_shims();
|
|
6768
|
+
init_logger();
|
|
6769
|
+
RateLimitMiddleware = class {
|
|
6770
|
+
static {
|
|
6771
|
+
__name(this, "RateLimitMiddleware");
|
|
6772
|
+
}
|
|
6773
|
+
name = "rate-limit";
|
|
6774
|
+
priority = 15;
|
|
6775
|
+
// Run after auth, before validation
|
|
6776
|
+
limits = /* @__PURE__ */ new Map();
|
|
6777
|
+
async execute(command, _args, context, next) {
|
|
6778
|
+
if (!command.rateLimit) {
|
|
6779
|
+
return next();
|
|
6780
|
+
}
|
|
6781
|
+
const userId = context.user?.id || context.session.id;
|
|
6782
|
+
const limitKey = `${command.name}:${userId}`;
|
|
6783
|
+
const commandLimits = this.limits.get(command.name) || /* @__PURE__ */ new Map();
|
|
6784
|
+
const userLimit = commandLimits.get(userId);
|
|
6785
|
+
const now = Date.now();
|
|
6786
|
+
const windowMs = this.parseWindow(command.rateLimit.window);
|
|
6787
|
+
if (!userLimit || userLimit.resetAt < now) {
|
|
6788
|
+
commandLimits.set(userId, {
|
|
6789
|
+
count: 1,
|
|
6790
|
+
resetAt: now + windowMs
|
|
6791
|
+
});
|
|
6792
|
+
this.limits.set(command.name, commandLimits);
|
|
6793
|
+
return next();
|
|
6794
|
+
}
|
|
6795
|
+
if (userLimit.count >= command.rateLimit.requests) {
|
|
6796
|
+
const retryAfter = Math.ceil((userLimit.resetAt - now) / 1e3);
|
|
6797
|
+
logger.warn(`Rate limit exceeded for ${limitKey}`, {
|
|
6798
|
+
count: userLimit.count,
|
|
6799
|
+
limit: command.rateLimit.requests,
|
|
6800
|
+
retryAfter
|
|
6801
|
+
});
|
|
6802
|
+
return {
|
|
6803
|
+
success: false,
|
|
6804
|
+
message: `\u23F1\uFE0F Rate limit exceeded`,
|
|
6805
|
+
data: {
|
|
6806
|
+
error: `Too many requests. Please wait ${retryAfter} seconds before trying again.`,
|
|
6807
|
+
retryAfter,
|
|
6808
|
+
limit: command.rateLimit.requests,
|
|
6809
|
+
window: command.rateLimit.window
|
|
6810
|
+
}
|
|
6811
|
+
};
|
|
6812
|
+
}
|
|
6813
|
+
userLimit.count++;
|
|
6814
|
+
return next();
|
|
6815
|
+
}
|
|
6816
|
+
parseWindow(window) {
|
|
6817
|
+
const units = {
|
|
6818
|
+
s: 1e3,
|
|
6819
|
+
m: 60 * 1e3,
|
|
6820
|
+
h: 60 * 60 * 1e3,
|
|
6821
|
+
d: 24 * 60 * 60 * 1e3
|
|
6822
|
+
};
|
|
6823
|
+
const match = window.match(/^(\d+)([smhd])$/);
|
|
6824
|
+
if (!match) {
|
|
6825
|
+
logger.warn(`Invalid rate limit window: ${window}, defaulting to 1 minute`);
|
|
6826
|
+
return 6e4;
|
|
6827
|
+
}
|
|
6828
|
+
const [, num, unit] = match;
|
|
6829
|
+
const value = parseInt(num || "60", 10);
|
|
6830
|
+
const multiplier = unit ? units[unit] || 6e4 : 6e4;
|
|
6831
|
+
return value * multiplier;
|
|
6832
|
+
}
|
|
6833
|
+
/**
|
|
6834
|
+
* Clear rate limits for a specific user or command
|
|
6835
|
+
*/
|
|
6836
|
+
clearLimits(command, userId) {
|
|
6837
|
+
if (command && userId) {
|
|
6838
|
+
const commandLimits = this.limits.get(command);
|
|
6839
|
+
if (commandLimits) {
|
|
6840
|
+
commandLimits.delete(userId);
|
|
6841
|
+
}
|
|
6842
|
+
} else if (command) {
|
|
6843
|
+
this.limits.delete(command);
|
|
6844
|
+
} else {
|
|
6845
|
+
this.limits.clear();
|
|
6846
|
+
}
|
|
6847
|
+
}
|
|
6848
|
+
/**
|
|
6849
|
+
* Get current limit status for a user
|
|
6850
|
+
*/
|
|
6851
|
+
getStatus(command, userId) {
|
|
6852
|
+
const commandLimits = this.limits.get(command);
|
|
6853
|
+
if (!commandLimits) {
|
|
6854
|
+
return null;
|
|
6855
|
+
}
|
|
6856
|
+
const userLimit = commandLimits.get(userId);
|
|
6857
|
+
if (!userLimit) {
|
|
6858
|
+
return null;
|
|
6859
|
+
}
|
|
6860
|
+
const cmd = { rateLimit: { requests: 10 } };
|
|
6861
|
+
return {
|
|
6862
|
+
remaining: Math.max(0, (cmd.rateLimit?.requests) - userLimit.count),
|
|
6863
|
+
resetAt: userLimit.resetAt,
|
|
6864
|
+
limit: cmd.rateLimit?.requests || 10
|
|
6865
|
+
};
|
|
6866
|
+
}
|
|
6867
|
+
};
|
|
6868
|
+
rateLimitMiddleware = new RateLimitMiddleware();
|
|
6869
|
+
}
|
|
6870
|
+
});
|
|
6871
|
+
|
|
6872
|
+
// src/slash-commands/middleware/logging.ts
|
|
6873
|
+
var logging_exports = {};
|
|
6874
|
+
__export(logging_exports, {
|
|
6875
|
+
LoggingMiddleware: () => LoggingMiddleware,
|
|
6876
|
+
loggingMiddleware: () => loggingMiddleware
|
|
6877
|
+
});
|
|
6878
|
+
var LoggingMiddleware, loggingMiddleware;
|
|
6879
|
+
var init_logging = __esm({
|
|
6880
|
+
"src/slash-commands/middleware/logging.ts"() {
|
|
6881
|
+
init_cjs_shims();
|
|
6882
|
+
init_logger();
|
|
6883
|
+
LoggingMiddleware = class {
|
|
6884
|
+
static {
|
|
6885
|
+
__name(this, "LoggingMiddleware");
|
|
6886
|
+
}
|
|
6887
|
+
name = "logging";
|
|
6888
|
+
priority = 0;
|
|
6889
|
+
// Run first
|
|
6890
|
+
async execute(command, args, context, next) {
|
|
6891
|
+
const startTime = Date.now();
|
|
6892
|
+
const requestId = this.generateRequestId();
|
|
6893
|
+
logger.info("Command execution started", {
|
|
6894
|
+
requestId,
|
|
6895
|
+
command: command.name,
|
|
6896
|
+
args: args.raw,
|
|
6897
|
+
user: context.user?.id || "anonymous",
|
|
6898
|
+
session: context.session.id
|
|
6899
|
+
});
|
|
6900
|
+
try {
|
|
6901
|
+
const result = await next();
|
|
6902
|
+
const duration = Date.now() - startTime;
|
|
6903
|
+
logger.info("Command execution completed", {
|
|
6904
|
+
requestId,
|
|
6905
|
+
command: command.name,
|
|
6906
|
+
success: result.success,
|
|
6907
|
+
duration,
|
|
6908
|
+
user: context.user?.id || "anonymous"
|
|
6909
|
+
});
|
|
6910
|
+
if (!result.metadata) {
|
|
6911
|
+
result.metadata = {
|
|
6912
|
+
executionTime: duration
|
|
6913
|
+
};
|
|
6914
|
+
}
|
|
6915
|
+
result.metadata["requestId"] = requestId;
|
|
6916
|
+
result.metadata["duration"] = duration;
|
|
6917
|
+
return result;
|
|
6918
|
+
} catch (error) {
|
|
6919
|
+
const duration = Date.now() - startTime;
|
|
6920
|
+
logger.error("Command execution failed", {
|
|
6921
|
+
requestId,
|
|
6922
|
+
command: command.name,
|
|
6923
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
6924
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
6925
|
+
duration,
|
|
6926
|
+
user: context.user?.id || "anonymous"
|
|
6927
|
+
});
|
|
6928
|
+
throw error;
|
|
6929
|
+
}
|
|
6930
|
+
}
|
|
6931
|
+
generateRequestId() {
|
|
6932
|
+
return `cmd_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
6933
|
+
}
|
|
6934
|
+
};
|
|
6935
|
+
loggingMiddleware = new LoggingMiddleware();
|
|
6936
|
+
}
|
|
6937
|
+
});
|
|
6938
|
+
|
|
6939
|
+
// src/slash-commands/categories/conversation/clear.command.ts
|
|
6940
|
+
var clear_command_exports = {};
|
|
6941
|
+
__export(clear_command_exports, {
|
|
6942
|
+
ClearCommand: () => ClearCommand
|
|
6943
|
+
});
|
|
6944
|
+
var ClearCommand;
|
|
6945
|
+
var init_clear_command = __esm({
|
|
6946
|
+
"src/slash-commands/categories/conversation/clear.command.ts"() {
|
|
6947
|
+
init_cjs_shims();
|
|
6948
|
+
init_base_command();
|
|
6949
|
+
init_chat_context_service();
|
|
6950
|
+
init_logger();
|
|
6951
|
+
ClearCommand = class extends exports.BaseCommand {
|
|
6952
|
+
static {
|
|
6953
|
+
__name(this, "ClearCommand");
|
|
6954
|
+
}
|
|
6955
|
+
name = "clear";
|
|
6956
|
+
category = "conversation";
|
|
6957
|
+
description = "Clear the conversation context and start fresh";
|
|
6958
|
+
chatContext;
|
|
6959
|
+
constructor() {
|
|
6960
|
+
super();
|
|
6961
|
+
this.chatContext = ChatContextService.getInstance();
|
|
6962
|
+
}
|
|
6963
|
+
async execute(args, context) {
|
|
6964
|
+
try {
|
|
6965
|
+
const clearAll = args.flags["all"] || false;
|
|
6966
|
+
const keepSettings = args.flags["keep-settings"] || false;
|
|
6967
|
+
const clearOptions = {
|
|
6968
|
+
conversation: true,
|
|
6969
|
+
history: clearAll,
|
|
6970
|
+
settings: !keepSettings,
|
|
6971
|
+
cache: clearAll
|
|
6972
|
+
};
|
|
6973
|
+
logger.info("Clearing conversation context", {
|
|
6974
|
+
options: clearOptions,
|
|
6975
|
+
user: context.user?.id,
|
|
6976
|
+
session: context.session.id
|
|
6977
|
+
});
|
|
6978
|
+
if (clearOptions.conversation) {
|
|
6979
|
+
await this.clearConversation(context);
|
|
6980
|
+
}
|
|
6981
|
+
if (clearOptions.history) {
|
|
6982
|
+
await this.clearAllHistory(context);
|
|
6983
|
+
}
|
|
6984
|
+
if (clearOptions.settings && !keepSettings) {
|
|
6985
|
+
await this.clearSettings(context);
|
|
6986
|
+
}
|
|
6987
|
+
if (clearOptions.cache) {
|
|
6988
|
+
await this.clearCache();
|
|
6989
|
+
}
|
|
6990
|
+
const clearedItems = [];
|
|
6991
|
+
if (clearOptions.conversation) clearedItems.push("conversation");
|
|
6992
|
+
if (clearOptions.history) clearedItems.push("all history");
|
|
6993
|
+
if (clearOptions.settings && !keepSettings) clearedItems.push("settings");
|
|
6994
|
+
if (clearOptions.cache) clearedItems.push("cache");
|
|
6995
|
+
const message = this.buildSuccessMessage(clearedItems);
|
|
6996
|
+
return this.success(message, {
|
|
6997
|
+
cleared: clearedItems,
|
|
6998
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
6999
|
+
});
|
|
7000
|
+
} catch (error) {
|
|
7001
|
+
logger.error("Failed to clear conversation", error);
|
|
7002
|
+
return this.error(
|
|
7003
|
+
"Failed to clear conversation context",
|
|
7004
|
+
"CLEAR_ERROR",
|
|
7005
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
7006
|
+
);
|
|
7007
|
+
}
|
|
7008
|
+
}
|
|
7009
|
+
async clearConversation(context) {
|
|
7010
|
+
if (context.conversation) {
|
|
7011
|
+
context.conversation.history = [];
|
|
7012
|
+
}
|
|
7013
|
+
await this.chatContext.clearContext();
|
|
7014
|
+
logger.debug("Cleared current conversation");
|
|
7015
|
+
}
|
|
7016
|
+
async clearAllHistory(context) {
|
|
7017
|
+
if (context.session) {
|
|
7018
|
+
context.session.commandHistory = [];
|
|
7019
|
+
}
|
|
7020
|
+
logger.debug("Cleared all conversation history");
|
|
7021
|
+
}
|
|
7022
|
+
async clearSettings(_context) {
|
|
7023
|
+
logger.debug("Cleared user settings");
|
|
7024
|
+
}
|
|
7025
|
+
async clearCache() {
|
|
7026
|
+
this.cleanup();
|
|
7027
|
+
logger.debug("Cleared all caches");
|
|
7028
|
+
}
|
|
7029
|
+
buildSuccessMessage(clearedItems) {
|
|
7030
|
+
if (clearedItems.length === 0) {
|
|
7031
|
+
return "\u2705 Nothing to clear";
|
|
7032
|
+
}
|
|
7033
|
+
if (clearedItems.includes("all history")) {
|
|
7034
|
+
return "\u{1F9F9} All conversation history and data cleared. Starting fresh!";
|
|
7035
|
+
}
|
|
7036
|
+
if (clearedItems.length === 1 && clearedItems[0] === "conversation") {
|
|
7037
|
+
return "\u2728 Conversation cleared. Ready for a fresh start!";
|
|
7038
|
+
}
|
|
7039
|
+
return `\u2705 Cleared: ${clearedItems.join(", ")}`;
|
|
7040
|
+
}
|
|
7041
|
+
async validate(args) {
|
|
7042
|
+
if (args.flags["all"] && args.flags["keep-settings"]) {
|
|
7043
|
+
return {
|
|
7044
|
+
success: false,
|
|
7045
|
+
error: "Cannot use --all and --keep-settings together"
|
|
7046
|
+
};
|
|
7047
|
+
}
|
|
7048
|
+
const positional = args.parsed["positional"] || [];
|
|
7049
|
+
if (positional.length > 0) {
|
|
7050
|
+
return {
|
|
7051
|
+
success: false,
|
|
7052
|
+
error: `Unexpected arguments: ${positional.join(", ")}`
|
|
7053
|
+
};
|
|
7054
|
+
}
|
|
7055
|
+
return { success: true };
|
|
7056
|
+
}
|
|
7057
|
+
};
|
|
7058
|
+
}
|
|
7059
|
+
});
|
|
7060
|
+
|
|
7061
|
+
// src/slash-commands/categories/config/setup.command.ts
|
|
7062
|
+
var setup_command_exports = {};
|
|
7063
|
+
__export(setup_command_exports, {
|
|
7064
|
+
SetupCommand: () => SetupCommand,
|
|
7065
|
+
default: () => setup_command_default
|
|
7066
|
+
});
|
|
7067
|
+
var SetupCommand, setup_command_default;
|
|
7068
|
+
var init_setup_command = __esm({
|
|
7069
|
+
"src/slash-commands/categories/config/setup.command.ts"() {
|
|
7070
|
+
init_cjs_shims();
|
|
7071
|
+
init_base_command();
|
|
7072
|
+
init_logger();
|
|
7073
|
+
SetupCommand = class extends exports.BaseCommand {
|
|
7074
|
+
static {
|
|
7075
|
+
__name(this, "SetupCommand");
|
|
7076
|
+
}
|
|
7077
|
+
name = "setup";
|
|
7078
|
+
category = "config";
|
|
7079
|
+
description = "\u{1F680} First-time environment setup wizard";
|
|
7080
|
+
usage = "[--quick] [--advanced] [--config <file>] [--silent] [--fix] [--rollback]";
|
|
7081
|
+
examples = [
|
|
7082
|
+
{
|
|
7083
|
+
input: "/setup",
|
|
7084
|
+
description: "Start interactive setup wizard",
|
|
7085
|
+
output: "Complete environment configuration wizard"
|
|
7086
|
+
},
|
|
7087
|
+
{
|
|
7088
|
+
input: "/setup --quick",
|
|
7089
|
+
description: "Quick setup with sensible defaults",
|
|
7090
|
+
output: "Rapid 2-minute configuration"
|
|
7091
|
+
},
|
|
7092
|
+
{
|
|
7093
|
+
input: "/setup --advanced",
|
|
7094
|
+
description: "Advanced setup with full customization",
|
|
7095
|
+
output: "Complete setup with all options"
|
|
7096
|
+
},
|
|
7097
|
+
{
|
|
7098
|
+
input: "/setup --fix",
|
|
7099
|
+
description: "Fix existing configuration issues",
|
|
7100
|
+
output: "Configuration problems resolved"
|
|
7101
|
+
},
|
|
7102
|
+
{
|
|
7103
|
+
input: "/setup --rollback",
|
|
7104
|
+
description: "Rollback previous setup changes",
|
|
7105
|
+
output: "Setup changes reverted"
|
|
7106
|
+
}
|
|
7107
|
+
];
|
|
7108
|
+
async execute(args, context) {
|
|
7109
|
+
const { flags, options } = args;
|
|
7110
|
+
try {
|
|
7111
|
+
logger.info("Setup command started", { flags, options });
|
|
7112
|
+
if (flags["rollback"]) {
|
|
7113
|
+
return await this.rollbackSetup(context);
|
|
7114
|
+
}
|
|
7115
|
+
if (flags["fix"]) {
|
|
7116
|
+
return await this.fixConfiguration(context);
|
|
7117
|
+
}
|
|
7118
|
+
if (flags["quick"]) {
|
|
7119
|
+
return await this.quickSetup(context);
|
|
7120
|
+
}
|
|
7121
|
+
if (flags["advanced"]) {
|
|
7122
|
+
return await this.advancedSetup(context);
|
|
7123
|
+
}
|
|
7124
|
+
if (flags["silent"] && options["config"]) {
|
|
7125
|
+
return await this.silentSetup(context, options["config"]);
|
|
7126
|
+
}
|
|
7127
|
+
return await this.interactiveSetup(context);
|
|
7128
|
+
} catch (error) {
|
|
7129
|
+
logger.error("Setup failed:", error);
|
|
7130
|
+
return this.error(
|
|
7131
|
+
`Setup failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7132
|
+
"SETUP_ERROR",
|
|
7133
|
+
error
|
|
7134
|
+
);
|
|
7135
|
+
}
|
|
7136
|
+
}
|
|
7137
|
+
async interactiveSetup(context) {
|
|
7138
|
+
const startTime = Date.now();
|
|
7139
|
+
const result = {
|
|
7140
|
+
success: false,
|
|
7141
|
+
duration: 0,
|
|
7142
|
+
stepsCompleted: [],
|
|
7143
|
+
providersConfigured: [],
|
|
7144
|
+
filesGenerated: [],
|
|
7145
|
+
errors: [],
|
|
7146
|
+
warnings: []
|
|
7147
|
+
};
|
|
7148
|
+
try {
|
|
7149
|
+
logger.info("Starting system analysis...");
|
|
7150
|
+
await this.analyzeSystem();
|
|
7151
|
+
result.stepsCompleted.push("system-analysis");
|
|
7152
|
+
await this.showWelcomeScreen();
|
|
7153
|
+
result.stepsCompleted.push("welcome");
|
|
7154
|
+
await this.detectExistingConfiguration(context);
|
|
7155
|
+
result.stepsCompleted.push("config-detection");
|
|
7156
|
+
logger.info("Configuring AI providers...");
|
|
7157
|
+
const providerResult = await this.configureProviders(context);
|
|
7158
|
+
if (providerResult.success) {
|
|
7159
|
+
result.stepsCompleted.push("provider-setup");
|
|
7160
|
+
result.providersConfigured = providerResult.data?.providers || [];
|
|
7161
|
+
result.filesGenerated.push(...providerResult.data?.files || []);
|
|
7162
|
+
} else {
|
|
7163
|
+
result.errors.push("Provider configuration failed");
|
|
7164
|
+
}
|
|
7165
|
+
logger.info("Initializing project configuration...");
|
|
7166
|
+
const projectResult = await this.initializeProject(context);
|
|
7167
|
+
if (projectResult.success) {
|
|
7168
|
+
result.stepsCompleted.push("project-init");
|
|
7169
|
+
result.filesGenerated.push(...projectResult.data?.files || []);
|
|
7170
|
+
} else {
|
|
7171
|
+
result.warnings.push("Project initialization had issues");
|
|
7172
|
+
}
|
|
7173
|
+
logger.info("Validating setup...");
|
|
7174
|
+
await this.validateSetup(context);
|
|
7175
|
+
result.stepsCompleted.push("validation");
|
|
7176
|
+
await this.recordSetupCompletion(context, result);
|
|
7177
|
+
result.stepsCompleted.push("finalization");
|
|
7178
|
+
await this.showSuccessMessage(result);
|
|
7179
|
+
result.success = true;
|
|
7180
|
+
result.duration = Date.now() - startTime;
|
|
7181
|
+
return this.success("\u{1F389} Setup completed successfully!", {
|
|
7182
|
+
result,
|
|
7183
|
+
nextSteps: [
|
|
7184
|
+
"Try: maria chat - Start interactive mode",
|
|
7185
|
+
'Try: maria code "create a React component"',
|
|
7186
|
+
"Try: maria test - Generate tests",
|
|
7187
|
+
"Try: maria help - View all commands"
|
|
7188
|
+
]
|
|
7189
|
+
});
|
|
7190
|
+
} catch (error) {
|
|
7191
|
+
result.success = false;
|
|
7192
|
+
result.duration = Date.now() - startTime;
|
|
7193
|
+
result.errors.push(error instanceof Error ? error.message : "Unknown error");
|
|
7194
|
+
logger.error("Interactive setup failed:", error);
|
|
7195
|
+
return this.error(
|
|
7196
|
+
"Setup wizard failed. Run with --fix to attempt repair.",
|
|
7197
|
+
"INTERACTIVE_SETUP_FAILED",
|
|
7198
|
+
result
|
|
7199
|
+
);
|
|
7200
|
+
}
|
|
7201
|
+
}
|
|
7202
|
+
async quickSetup(context) {
|
|
7203
|
+
logger.info("Starting quick setup...");
|
|
7204
|
+
try {
|
|
7205
|
+
const startTime = Date.now();
|
|
7206
|
+
const envResult = await this.generateQuickEnvTemplate();
|
|
7207
|
+
if (!envResult.success) {
|
|
7208
|
+
return this.error(
|
|
7209
|
+
"Quick setup failed during environment configuration",
|
|
7210
|
+
"QUICK_SETUP_FAILED",
|
|
7211
|
+
envResult
|
|
7212
|
+
);
|
|
7213
|
+
}
|
|
7214
|
+
await this.recordSetupCompletion(context, {
|
|
7215
|
+
success: true,
|
|
7216
|
+
duration: Date.now() - startTime,
|
|
7217
|
+
stepsCompleted: ["quick-setup", "ai-providers"],
|
|
7218
|
+
providersConfigured: ["openai"],
|
|
7219
|
+
filesGenerated: [".env.local", ".env.local.sample", ".gitignore"],
|
|
7220
|
+
errors: [],
|
|
7221
|
+
warnings: []
|
|
7222
|
+
});
|
|
7223
|
+
return this.success("\u26A1 Quick setup completed in under 2 minutes!", {
|
|
7224
|
+
mode: "quick",
|
|
7225
|
+
configured: ["OpenAI GPT-4", "Environment variables", "Git ignore"],
|
|
7226
|
+
nextSteps: ["Run: maria chat", 'Try: maria code "Hello World function"']
|
|
7227
|
+
});
|
|
7228
|
+
} catch (error) {
|
|
7229
|
+
logger.error("Quick setup failed:", error);
|
|
7230
|
+
return this.error(
|
|
7231
|
+
`Quick setup failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7232
|
+
"QUICK_SETUP_ERROR",
|
|
7233
|
+
error
|
|
7234
|
+
);
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
async advancedSetup(context) {
|
|
7238
|
+
return this.success("Advanced setup mode - Full customization available", {
|
|
7239
|
+
features: [
|
|
7240
|
+
"Multiple AI provider configuration",
|
|
7241
|
+
"Advanced project settings",
|
|
7242
|
+
"Performance optimization",
|
|
7243
|
+
"Custom integrations"
|
|
7244
|
+
]
|
|
7245
|
+
});
|
|
7246
|
+
}
|
|
7247
|
+
async fixConfiguration(context) {
|
|
7248
|
+
logger.info("Analyzing configuration issues...");
|
|
7249
|
+
try {
|
|
7250
|
+
const issues = await this.detectConfigurationIssues(context);
|
|
7251
|
+
if (issues.length === 0) {
|
|
7252
|
+
return this.success("\u2705 No configuration issues detected", {
|
|
7253
|
+
status: "healthy",
|
|
7254
|
+
lastCheck: (/* @__PURE__ */ new Date()).toISOString()
|
|
7255
|
+
});
|
|
7256
|
+
}
|
|
7257
|
+
const fixes = [];
|
|
7258
|
+
for (const issue of issues) {
|
|
7259
|
+
try {
|
|
7260
|
+
await this.fixConfigurationIssue(issue, context);
|
|
7261
|
+
fixes.push({ issue: issue.description, fixed: true });
|
|
7262
|
+
} catch (error) {
|
|
7263
|
+
fixes.push({
|
|
7264
|
+
issue: issue.description,
|
|
7265
|
+
fixed: false,
|
|
7266
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
7267
|
+
});
|
|
7268
|
+
}
|
|
7269
|
+
}
|
|
7270
|
+
const fixedCount = fixes.filter((f) => f.fixed).length;
|
|
7271
|
+
const totalIssues = fixes.length;
|
|
7272
|
+
return this.success(`\u{1F527} Fixed ${fixedCount}/${totalIssues} configuration issues`, {
|
|
7273
|
+
fixes,
|
|
7274
|
+
summary: {
|
|
7275
|
+
total: totalIssues,
|
|
7276
|
+
fixed: fixedCount,
|
|
7277
|
+
failed: totalIssues - fixedCount
|
|
7278
|
+
}
|
|
7279
|
+
});
|
|
7280
|
+
} catch (error) {
|
|
7281
|
+
logger.error("Configuration fix failed:", error);
|
|
7282
|
+
return this.error(
|
|
7283
|
+
`Configuration fix failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7284
|
+
"CONFIG_FIX_ERROR",
|
|
7285
|
+
error
|
|
7286
|
+
);
|
|
7287
|
+
}
|
|
7288
|
+
}
|
|
7289
|
+
async rollbackSetup(context) {
|
|
7290
|
+
logger.info("Rolling back setup changes...");
|
|
7291
|
+
try {
|
|
7292
|
+
const setupRecord = await this.getSetupRecord(context);
|
|
7293
|
+
if (!setupRecord) {
|
|
7294
|
+
return this.error("No setup record found to rollback", "NO_SETUP_RECORD");
|
|
7295
|
+
}
|
|
7296
|
+
const restoredFiles = [];
|
|
7297
|
+
const errors = [];
|
|
7298
|
+
if (setupRecord.filesGenerated) {
|
|
7299
|
+
for (const file of setupRecord.filesGenerated) {
|
|
7300
|
+
try {
|
|
7301
|
+
const filePath = path10__namespace.default.join(context.environment.cwd, file);
|
|
7302
|
+
await fs11__namespace.default.unlink(filePath);
|
|
7303
|
+
restoredFiles.push(file);
|
|
7304
|
+
} catch (error) {
|
|
7305
|
+
errors.push(
|
|
7306
|
+
`Failed to remove ${file}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
7307
|
+
);
|
|
7308
|
+
}
|
|
7309
|
+
}
|
|
7310
|
+
}
|
|
7311
|
+
const setupRecordPath = path10__namespace.default.join(context.environment.cwd, ".maria", "setup.json");
|
|
7312
|
+
try {
|
|
7313
|
+
await fs11__namespace.default.unlink(setupRecordPath);
|
|
7314
|
+
} catch {
|
|
7315
|
+
}
|
|
7316
|
+
return this.success("\u21A9\uFE0F Setup changes rolled back successfully", {
|
|
7317
|
+
restoredFiles,
|
|
7318
|
+
errors,
|
|
7319
|
+
message: "Your environment has been restored to pre-setup state"
|
|
7320
|
+
});
|
|
7321
|
+
} catch (error) {
|
|
7322
|
+
logger.error("Rollback failed:", error);
|
|
7323
|
+
return this.error(
|
|
7324
|
+
`Rollback failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7325
|
+
"ROLLBACK_ERROR",
|
|
7326
|
+
error
|
|
7327
|
+
);
|
|
7328
|
+
}
|
|
7329
|
+
}
|
|
7330
|
+
async silentSetup(context, configPath) {
|
|
7331
|
+
return this.success("Silent setup completed from configuration file", {
|
|
7332
|
+
configPath,
|
|
7333
|
+
mode: "silent"
|
|
7334
|
+
});
|
|
7335
|
+
}
|
|
7336
|
+
async analyzeSystem() {
|
|
7337
|
+
const platform = os3__default.default.platform();
|
|
7338
|
+
const architecture = os3__default.default.arch();
|
|
7339
|
+
const nodeVersion = process.version;
|
|
7340
|
+
let packageManager = "npm";
|
|
7341
|
+
try {
|
|
7342
|
+
await fs11__namespace.default.access("pnpm-lock.yaml");
|
|
7343
|
+
packageManager = "pnpm";
|
|
7344
|
+
} catch {
|
|
7345
|
+
try {
|
|
7346
|
+
await fs11__namespace.default.access("yarn.lock");
|
|
7347
|
+
packageManager = "yarn";
|
|
7348
|
+
} catch {
|
|
7349
|
+
try {
|
|
7350
|
+
await fs11__namespace.default.access("bun.lockb");
|
|
7351
|
+
packageManager = "bun";
|
|
7352
|
+
} catch {
|
|
7353
|
+
packageManager = "npm";
|
|
7354
|
+
}
|
|
7355
|
+
}
|
|
7356
|
+
}
|
|
7357
|
+
const terminalCapabilities = {
|
|
7358
|
+
colorSupport: !!(process.stdout.isTTY && process.env["TERM"] !== "dumb"),
|
|
7359
|
+
unicodeSupport: process.env["LANG"]?.includes("UTF-8") || false,
|
|
7360
|
+
interactiveSupport: !!process.stdin.isTTY
|
|
7361
|
+
};
|
|
7362
|
+
const networkConnectivity = true;
|
|
7363
|
+
const memoryAvailable = os3__default.default.totalmem() / (1024 * 1024 * 1024);
|
|
7364
|
+
const diskSpace = 100;
|
|
7365
|
+
return {
|
|
7366
|
+
platform,
|
|
7367
|
+
architecture,
|
|
7368
|
+
nodeVersion,
|
|
7369
|
+
packageManager,
|
|
7370
|
+
terminalCapabilities,
|
|
7371
|
+
networkConnectivity,
|
|
7372
|
+
diskSpace,
|
|
7373
|
+
memoryAvailable
|
|
7374
|
+
};
|
|
7375
|
+
}
|
|
7376
|
+
async detectExistingConfiguration(context) {
|
|
7377
|
+
const cwd = context.environment.cwd;
|
|
7378
|
+
const existingEnvFile = await this.fileExists(path10__namespace.default.join(cwd, ".env.local"));
|
|
7379
|
+
const existingMARIAConfig = await this.fileExists(path10__namespace.default.join(cwd, ".maria-code.toml"));
|
|
7380
|
+
const gitRepository = await this.fileExists(path10__namespace.default.join(cwd, ".git"));
|
|
7381
|
+
const configuredProviders = [];
|
|
7382
|
+
if (existingEnvFile) {
|
|
7383
|
+
const envContent = await fs11__namespace.default.readFile(path10__namespace.default.join(cwd, ".env.local"), "utf-8");
|
|
7384
|
+
if (envContent.includes("OPENAI_API_KEY")) configuredProviders.push("openai");
|
|
7385
|
+
if (envContent.includes("ANTHROPIC_API_KEY")) configuredProviders.push("anthropic");
|
|
7386
|
+
if (envContent.includes("GOOGLE_AI_API_KEY")) configuredProviders.push("google");
|
|
7387
|
+
if (envContent.includes("GROQ_API_KEY")) configuredProviders.push("groq");
|
|
7388
|
+
}
|
|
7389
|
+
return {
|
|
7390
|
+
existingEnvFile,
|
|
7391
|
+
existingMARIAConfig,
|
|
7392
|
+
installedCLI: true,
|
|
7393
|
+
// If we're running, CLI is installed
|
|
7394
|
+
configuredProviders,
|
|
7395
|
+
workingDirectory: cwd,
|
|
7396
|
+
gitRepository
|
|
7397
|
+
};
|
|
7398
|
+
}
|
|
7399
|
+
async configureProviders(context) {
|
|
7400
|
+
return await this.generateQuickEnvTemplate();
|
|
7401
|
+
}
|
|
7402
|
+
async initializeProject(context) {
|
|
7403
|
+
const mariaDir = path10__namespace.default.join(context.environment.cwd, ".maria");
|
|
7404
|
+
try {
|
|
7405
|
+
await fs11__namespace.default.mkdir(mariaDir, { recursive: true });
|
|
7406
|
+
const config2 = {
|
|
7407
|
+
project: {
|
|
7408
|
+
name: path10__namespace.default.basename(context.environment.cwd),
|
|
7409
|
+
type: "web",
|
|
7410
|
+
language: "typescript"
|
|
7411
|
+
},
|
|
7412
|
+
ai: {
|
|
7413
|
+
default_provider: "openai",
|
|
7414
|
+
default_model: "gpt-4"
|
|
7415
|
+
},
|
|
7416
|
+
preferences: {
|
|
7417
|
+
theme: "dark",
|
|
7418
|
+
language: "auto"
|
|
7419
|
+
},
|
|
7420
|
+
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
7421
|
+
};
|
|
7422
|
+
const configPath = path10__namespace.default.join(context.environment.cwd, ".maria-code.toml");
|
|
7423
|
+
const tomlContent = this.generateTOMLConfig(config2);
|
|
7424
|
+
await fs11__namespace.default.writeFile(configPath, tomlContent, "utf-8");
|
|
7425
|
+
return this.success("Project initialized successfully", {
|
|
7426
|
+
files: [".maria-code.toml"]
|
|
7427
|
+
});
|
|
7428
|
+
} catch (error) {
|
|
7429
|
+
logger.error("Project initialization failed:", error);
|
|
7430
|
+
return this.error(
|
|
7431
|
+
`Project initialization failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7432
|
+
"PROJECT_INIT_ERROR",
|
|
7433
|
+
error
|
|
7434
|
+
);
|
|
7435
|
+
}
|
|
7436
|
+
}
|
|
7437
|
+
async validateSetup(context) {
|
|
7438
|
+
const checks = [
|
|
7439
|
+
this.validateEnvironmentFile(context),
|
|
7440
|
+
this.validateConfigFile(context),
|
|
7441
|
+
this.validateProviderConnections(context)
|
|
7442
|
+
];
|
|
7443
|
+
try {
|
|
7444
|
+
const results = await Promise.all(checks);
|
|
7445
|
+
return results.every((result) => result);
|
|
7446
|
+
} catch {
|
|
7447
|
+
return false;
|
|
7448
|
+
}
|
|
7449
|
+
}
|
|
7450
|
+
async recordSetupCompletion(context, result) {
|
|
7451
|
+
const mariaDir = path10__namespace.default.join(context.environment.cwd, ".maria");
|
|
7452
|
+
await fs11__namespace.default.mkdir(mariaDir, { recursive: true });
|
|
7453
|
+
const setupRecord = {
|
|
7454
|
+
...result,
|
|
7455
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7456
|
+
version: "1.0.0",
|
|
7457
|
+
environment: context.environment
|
|
7458
|
+
};
|
|
7459
|
+
const recordPath = path10__namespace.default.join(mariaDir, "setup.json");
|
|
7460
|
+
await fs11__namespace.default.writeFile(recordPath, JSON.stringify(setupRecord, null, 2), "utf-8");
|
|
7461
|
+
}
|
|
7462
|
+
async showWelcomeScreen() {
|
|
7463
|
+
logger.info(`
|
|
7464
|
+
\u{1F680} Welcome to MARIA CODE Setup Wizard!
|
|
7465
|
+
|
|
7466
|
+
This wizard will configure your environment in 4 simple steps:
|
|
7467
|
+
1. \u{1F511} AI Provider Setup (Required)
|
|
7468
|
+
2. \u{1F3D7}\uFE0F Project Configuration (Recommended)
|
|
7469
|
+
3. \u{1F39B}\uFE0F Personal Preferences (Optional)
|
|
7470
|
+
4. \u2705 Validation & Testing (Automatic)
|
|
7471
|
+
|
|
7472
|
+
Estimated time: 3-5 minutes
|
|
7473
|
+
`);
|
|
7474
|
+
}
|
|
7475
|
+
async showSuccessMessage(result) {
|
|
7476
|
+
logger.info(`
|
|
7477
|
+
\u{1F389} Setup Complete! Welcome to MARIA CODE!
|
|
7478
|
+
|
|
7479
|
+
\u2705 Environment configured
|
|
7480
|
+
\u2705 AI providers connected: ${result.providersConfigured.join(", ")}
|
|
7481
|
+
\u2705 Project initialized
|
|
7482
|
+
\u2705 All validation tests passed
|
|
7483
|
+
|
|
7484
|
+
\u{1F680} Ready to start! Try these commands:
|
|
7485
|
+
\u2022 maria chat - Start interactive mode
|
|
7486
|
+
\u2022 maria code "create a React component"
|
|
7487
|
+
\u2022 maria test - Generate tests
|
|
7488
|
+
\u2022 maria help - View all commands
|
|
7489
|
+
|
|
7490
|
+
Setup completed in ${Math.round(result.duration / 1e3)}s
|
|
7491
|
+
Happy coding! \u{1F680}
|
|
7492
|
+
`);
|
|
7493
|
+
}
|
|
7494
|
+
// Helper methods
|
|
7495
|
+
async fileExists(path11) {
|
|
7496
|
+
try {
|
|
7497
|
+
await fs11__namespace.default.access(path11);
|
|
7498
|
+
return true;
|
|
7499
|
+
} catch {
|
|
7500
|
+
return false;
|
|
7501
|
+
}
|
|
7502
|
+
}
|
|
7503
|
+
async detectConfigurationIssues(context) {
|
|
7504
|
+
const issues = [];
|
|
7505
|
+
if (!await this.fileExists(path10__namespace.default.join(context.environment.cwd, ".env.local"))) {
|
|
7506
|
+
issues.push({ description: "Missing .env.local file", severity: "error" });
|
|
7507
|
+
}
|
|
7508
|
+
if (!await this.fileExists(path10__namespace.default.join(context.environment.cwd, ".maria-code.toml"))) {
|
|
7509
|
+
issues.push({ description: "Missing .maria-code.toml file", severity: "warning" });
|
|
7510
|
+
}
|
|
7511
|
+
return issues;
|
|
7512
|
+
}
|
|
7513
|
+
async fixConfigurationIssue(issue, context) {
|
|
7514
|
+
if (issue.description.includes(".env.local")) {
|
|
7515
|
+
await this.generateQuickEnvTemplate();
|
|
7516
|
+
}
|
|
7517
|
+
}
|
|
7518
|
+
async getSetupRecord(context) {
|
|
6001
7519
|
try {
|
|
6002
|
-
const
|
|
6003
|
-
const
|
|
6004
|
-
|
|
6005
|
-
for (let progress = 0; progress <= 100; progress += 25) {
|
|
6006
|
-
service.progress = progress;
|
|
6007
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
6008
|
-
}
|
|
6009
|
-
if (healthStatus.isRunning) {
|
|
6010
|
-
service.status = "running";
|
|
6011
|
-
service.progress = 100;
|
|
6012
|
-
if (healthStatus.models && healthStatus.models.length > 0) {
|
|
6013
|
-
service.message = `${healthStatus.models.length} models available`;
|
|
6014
|
-
} else {
|
|
6015
|
-
service.message = "Running";
|
|
6016
|
-
}
|
|
6017
|
-
} else {
|
|
6018
|
-
service.status = "not-installed";
|
|
6019
|
-
service.message = "Not running";
|
|
6020
|
-
service.progress = 0;
|
|
6021
|
-
}
|
|
7520
|
+
const recordPath = path10__namespace.default.join(context.environment.cwd, ".maria", "setup.json");
|
|
7521
|
+
const content = await fs11__namespace.default.readFile(recordPath, "utf-8");
|
|
7522
|
+
return JSON.parse(content);
|
|
6022
7523
|
} catch {
|
|
6023
|
-
|
|
6024
|
-
service.message = "Skipping...";
|
|
6025
|
-
service.progress = 0;
|
|
7524
|
+
return null;
|
|
6026
7525
|
}
|
|
6027
7526
|
}
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
)
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
)
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
);
|
|
6091
|
-
console.log(
|
|
6092
|
-
chalk13__default.default.magentaBright(
|
|
6093
|
-
centerText(chalk13__default.default.bold.magentaBright("\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"))
|
|
6094
|
-
)
|
|
6095
|
-
);
|
|
6096
|
-
console.log(
|
|
6097
|
-
chalk13__default.default.magentaBright(
|
|
6098
|
-
centerText(chalk13__default.default.bold.magentaBright(" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"))
|
|
6099
|
-
)
|
|
6100
|
-
);
|
|
6101
|
-
console.log(chalk13__default.default.magentaBright(emptyLine));
|
|
6102
|
-
console.log(
|
|
6103
|
-
chalk13__default.default.magentaBright(centerText(chalk13__default.default.whiteBright("AI-Powered Development Platform")))
|
|
6104
|
-
);
|
|
6105
|
-
console.log(chalk13__default.default.magentaBright(centerText(chalk13__default.default.gray("(c) 2025 Bonginkan Inc."))));
|
|
6106
|
-
console.log(chalk13__default.default.magentaBright(emptyLine));
|
|
6107
|
-
console.log(chalk13__default.default.magentaBright("\u255A" + horizontalLine + "\u255D"));
|
|
6108
|
-
console.log("");
|
|
7527
|
+
async validateEnvironmentFile(context) {
|
|
7528
|
+
return this.fileExists(path10__namespace.default.join(context.environment.cwd, ".env.local"));
|
|
7529
|
+
}
|
|
7530
|
+
async validateConfigFile(context) {
|
|
7531
|
+
return this.fileExists(path10__namespace.default.join(context.environment.cwd, ".maria-code.toml"));
|
|
7532
|
+
}
|
|
7533
|
+
async validateProviderConnections(context) {
|
|
7534
|
+
return true;
|
|
7535
|
+
}
|
|
7536
|
+
async generateQuickEnvTemplate() {
|
|
7537
|
+
try {
|
|
7538
|
+
const envContent = `# MARIA CODE Environment Configuration
|
|
7539
|
+
# Generated by setup wizard on ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
7540
|
+
# Replace placeholder values with your actual credentials
|
|
7541
|
+
|
|
7542
|
+
# AI Provider API Keys
|
|
7543
|
+
OPENAI_API_KEY=your_openai_key_here
|
|
7544
|
+
ANTHROPIC_API_KEY=your_anthropic_key_here
|
|
7545
|
+
GOOGLE_AI_API_KEY=your_google_ai_key_here
|
|
7546
|
+
GROQ_API_KEY=your_groq_key_here
|
|
7547
|
+
|
|
7548
|
+
# Local AI Providers (Optional)
|
|
7549
|
+
LMSTUDIO_API_URL=http://localhost:1234
|
|
7550
|
+
OLLAMA_API_URL=http://localhost:11434
|
|
7551
|
+
VLLM_API_URL=http://localhost:8000
|
|
7552
|
+
|
|
7553
|
+
# Development Settings
|
|
7554
|
+
DEBUG=false
|
|
7555
|
+
LOG_LEVEL=info
|
|
7556
|
+
`;
|
|
7557
|
+
const envPath = path10__namespace.default.join(process.cwd(), ".env.local");
|
|
7558
|
+
await fs11__namespace.default.writeFile(envPath, envContent, "utf-8");
|
|
7559
|
+
return this.success("Environment template generated successfully", {
|
|
7560
|
+
files: [".env.local"],
|
|
7561
|
+
message: "Please edit .env.local and add your API keys"
|
|
7562
|
+
});
|
|
7563
|
+
} catch (error) {
|
|
7564
|
+
logger.error("Failed to generate environment template:", error);
|
|
7565
|
+
return this.error(
|
|
7566
|
+
`Environment template generation failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
7567
|
+
"ENV_TEMPLATE_ERROR",
|
|
7568
|
+
error
|
|
7569
|
+
);
|
|
7570
|
+
}
|
|
7571
|
+
}
|
|
7572
|
+
generateTOMLConfig(config2) {
|
|
7573
|
+
return `# MARIA CODE Configuration
|
|
7574
|
+
# Generated by setup wizard
|
|
7575
|
+
|
|
7576
|
+
[project]
|
|
7577
|
+
name = "${config2.project.name}"
|
|
7578
|
+
type = "web"
|
|
7579
|
+
language = "typescript"
|
|
7580
|
+
|
|
7581
|
+
[ai]
|
|
7582
|
+
default_provider = "openai"
|
|
7583
|
+
default_model = "gpt-4"
|
|
7584
|
+
|
|
7585
|
+
[preferences]
|
|
7586
|
+
theme = "dark"
|
|
7587
|
+
language = "auto"
|
|
7588
|
+
`;
|
|
6109
7589
|
}
|
|
6110
7590
|
};
|
|
7591
|
+
setup_command_default = new SetupCommand();
|
|
6111
7592
|
}
|
|
6112
7593
|
});
|
|
6113
7594
|
|
|
@@ -6135,7 +7616,9 @@ var GrokProvider = class extends BaseAIProvider {
|
|
|
6135
7616
|
}
|
|
6136
7617
|
name = "Grok";
|
|
6137
7618
|
models = [
|
|
6138
|
-
"grok-4
|
|
7619
|
+
"grok-4",
|
|
7620
|
+
"grok-beta",
|
|
7621
|
+
"grok-2",
|
|
6139
7622
|
"llama-3.3-70b-versatile",
|
|
6140
7623
|
"llama-3.1-70b-versatile",
|
|
6141
7624
|
"llama-3.1-8b-instant",
|
|
@@ -6986,6 +8469,30 @@ var AIProviderManager = class {
|
|
|
6986
8469
|
}
|
|
6987
8470
|
}
|
|
6988
8471
|
}
|
|
8472
|
+
const cloudProviders = ["openai", "anthropic", "google", "grok"];
|
|
8473
|
+
const defaultCloudModels = {
|
|
8474
|
+
openai: ["gpt-5", "gpt-5-mini", "gpt-4o", "gpt-4o-mini", "o1-preview", "o1-mini"],
|
|
8475
|
+
anthropic: ["claude-4.1", "claude-3-5-sonnet-20241022", "claude-3-5-haiku-20241022", "claude-3-opus-20240229"],
|
|
8476
|
+
google: ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-1.5-pro", "gemini-1.5-flash"],
|
|
8477
|
+
grok: ["grok-4", "grok-beta", "grok-2"]
|
|
8478
|
+
};
|
|
8479
|
+
for (const providerName of cloudProviders) {
|
|
8480
|
+
if (!this.availableProviders.has(providerName)) {
|
|
8481
|
+
const models = defaultCloudModels[providerName] || [];
|
|
8482
|
+
const modelInfos = models.map((modelName) => ({
|
|
8483
|
+
id: `${providerName}-${modelName}`,
|
|
8484
|
+
name: modelName,
|
|
8485
|
+
provider: providerName,
|
|
8486
|
+
description: `${modelName} from ${providerName}`,
|
|
8487
|
+
contextLength: 8192,
|
|
8488
|
+
capabilities: ["text", "code", "vision"],
|
|
8489
|
+
available: false,
|
|
8490
|
+
// Mark as unavailable (need API key)
|
|
8491
|
+
recommendedFor: ["general"]
|
|
8492
|
+
}));
|
|
8493
|
+
allModels.push(...modelInfos);
|
|
8494
|
+
}
|
|
8495
|
+
}
|
|
6989
8496
|
return allModels;
|
|
6990
8497
|
}
|
|
6991
8498
|
selectOptimalProvider(_taskType, priorityMode = "auto") {
|
|
@@ -7523,10 +9030,10 @@ var HealthMonitor = class extends events.EventEmitter {
|
|
|
7523
9030
|
*/
|
|
7524
9031
|
async saveHealthData() {
|
|
7525
9032
|
try {
|
|
7526
|
-
const healthDir =
|
|
9033
|
+
const healthDir = path10.join(os3.homedir(), ".maria", "health");
|
|
7527
9034
|
await fs7.promises.mkdir(healthDir, { recursive: true });
|
|
7528
9035
|
const systemHealth = this.getSystemHealth();
|
|
7529
|
-
const healthFile =
|
|
9036
|
+
const healthFile = path10.join(healthDir, "system-health.json");
|
|
7530
9037
|
await fs7.promises.writeFile(
|
|
7531
9038
|
healthFile,
|
|
7532
9039
|
JSON.stringify(
|
|
@@ -7547,7 +9054,7 @@ var HealthMonitor = class extends events.EventEmitter {
|
|
|
7547
9054
|
*/
|
|
7548
9055
|
async loadHealthData() {
|
|
7549
9056
|
try {
|
|
7550
|
-
const healthFile =
|
|
9057
|
+
const healthFile = path10.join(os3.homedir(), ".maria", "health", "system-health.json");
|
|
7551
9058
|
const data = await fs7.promises.readFile(healthFile, "utf8");
|
|
7552
9059
|
const parsed = JSON.parse(data);
|
|
7553
9060
|
return {
|
|
@@ -7634,7 +9141,9 @@ var ConfigManager = class _ConfigManager {
|
|
|
7634
9141
|
autoStart: true,
|
|
7635
9142
|
healthMonitoring: true,
|
|
7636
9143
|
language: "auto",
|
|
7637
|
-
offlineMode: false
|
|
9144
|
+
offlineMode: false,
|
|
9145
|
+
model: "gpt-5-mini",
|
|
9146
|
+
provider: "openai"
|
|
7638
9147
|
};
|
|
7639
9148
|
}
|
|
7640
9149
|
mergeConfig(newConfig) {
|
|
@@ -7691,27 +9200,27 @@ var ConfigManager = class _ConfigManager {
|
|
|
7691
9200
|
// Save configuration to file (for CLI usage)
|
|
7692
9201
|
async save(configPath) {
|
|
7693
9202
|
const { importNodeBuiltin: importNodeBuiltin2, safeDynamicImport: safeDynamicImport2 } = await Promise.resolve().then(() => (init_import_helper(), import_helper_exports));
|
|
7694
|
-
const
|
|
9203
|
+
const fs12 = await safeDynamicImport2("fs-extra").catch(
|
|
7695
9204
|
() => importNodeBuiltin2("fs")
|
|
7696
9205
|
);
|
|
7697
|
-
const
|
|
7698
|
-
const
|
|
7699
|
-
const targetPath = configPath ||
|
|
7700
|
-
await
|
|
7701
|
-
await
|
|
9206
|
+
const path11 = await importNodeBuiltin2("path");
|
|
9207
|
+
const os4 = await importNodeBuiltin2("os");
|
|
9208
|
+
const targetPath = configPath || path11.join(os4.homedir(), ".maria", "config.json");
|
|
9209
|
+
await fs12.ensureDir(path11.dirname(targetPath));
|
|
9210
|
+
await fs12.writeJson(targetPath, this.config, { spaces: 2 });
|
|
7702
9211
|
}
|
|
7703
9212
|
// Load configuration from file
|
|
7704
9213
|
static async load(configPath) {
|
|
7705
9214
|
const { importNodeBuiltin: importNodeBuiltin2, safeDynamicImport: safeDynamicImport2 } = await Promise.resolve().then(() => (init_import_helper(), import_helper_exports));
|
|
7706
|
-
const
|
|
9215
|
+
const fs12 = await safeDynamicImport2("fs-extra").catch(
|
|
7707
9216
|
() => importNodeBuiltin2("fs")
|
|
7708
9217
|
);
|
|
7709
|
-
const
|
|
7710
|
-
const
|
|
7711
|
-
const targetPath = configPath ||
|
|
7712
|
-
if (await
|
|
9218
|
+
const path11 = await importNodeBuiltin2("path");
|
|
9219
|
+
const os4 = await importNodeBuiltin2("os");
|
|
9220
|
+
const targetPath = configPath || path11.join(os4.homedir(), ".maria", "config.json");
|
|
9221
|
+
if (await fs12.pathExists(targetPath)) {
|
|
7713
9222
|
try {
|
|
7714
|
-
const savedConfig = await
|
|
9223
|
+
const savedConfig = await fs12.readJson(targetPath);
|
|
7715
9224
|
return new _ConfigManager(savedConfig);
|
|
7716
9225
|
} catch (error) {
|
|
7717
9226
|
console.warn("Failed to load config file, using defaults:", error);
|
|
@@ -7847,6 +9356,50 @@ Context from memory:
|
|
|
7847
9356
|
this.config.set("priority", mode);
|
|
7848
9357
|
this.router.updatePriorityMode(mode);
|
|
7849
9358
|
}
|
|
9359
|
+
/**
|
|
9360
|
+
* Switch to a specific model
|
|
9361
|
+
*/
|
|
9362
|
+
async switchModel(modelId) {
|
|
9363
|
+
try {
|
|
9364
|
+
const models = await this.getModels();
|
|
9365
|
+
const targetModel = models.find((m) => m.id === modelId || m.name === modelId);
|
|
9366
|
+
if (!targetModel) {
|
|
9367
|
+
return {
|
|
9368
|
+
success: false,
|
|
9369
|
+
message: `Model not found: ${modelId}`
|
|
9370
|
+
};
|
|
9371
|
+
}
|
|
9372
|
+
if (!targetModel.available) {
|
|
9373
|
+
return {
|
|
9374
|
+
success: false,
|
|
9375
|
+
message: `Model ${targetModel.name} is not available. Please check API keys.`
|
|
9376
|
+
};
|
|
9377
|
+
}
|
|
9378
|
+
this.config.set("model", targetModel.name);
|
|
9379
|
+
this.config.set("provider", targetModel.provider);
|
|
9380
|
+
this.router.updatePreferredProvider(targetModel.provider, targetModel.name);
|
|
9381
|
+
return {
|
|
9382
|
+
success: true,
|
|
9383
|
+
message: `Switched to ${targetModel.name} (${targetModel.provider})`
|
|
9384
|
+
};
|
|
9385
|
+
} catch (error) {
|
|
9386
|
+
return {
|
|
9387
|
+
success: false,
|
|
9388
|
+
message: `Failed to switch model: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
9389
|
+
};
|
|
9390
|
+
}
|
|
9391
|
+
}
|
|
9392
|
+
/**
|
|
9393
|
+
* Get current active model
|
|
9394
|
+
*/
|
|
9395
|
+
getCurrentModel() {
|
|
9396
|
+
const currentModel = this.config.get("model");
|
|
9397
|
+
const currentProvider = this.config.get("provider");
|
|
9398
|
+
if (currentModel && currentProvider) {
|
|
9399
|
+
return { name: currentModel, provider: currentProvider };
|
|
9400
|
+
}
|
|
9401
|
+
return null;
|
|
9402
|
+
}
|
|
7850
9403
|
/**
|
|
7851
9404
|
* Get current configuration
|
|
7852
9405
|
*/
|
|
@@ -12876,14 +14429,14 @@ var System2MemoryManager = class {
|
|
|
12876
14429
|
return Math.min(1, weightedSum / evidence.length);
|
|
12877
14430
|
}
|
|
12878
14431
|
traverseDecisionTree(node, context) {
|
|
12879
|
-
const
|
|
14432
|
+
const path11 = [node];
|
|
12880
14433
|
for (const child of node.children) {
|
|
12881
14434
|
if (child.type === "condition" && this.evaluateCondition(child, context)) {
|
|
12882
|
-
|
|
14435
|
+
path11.push(...this.traverseDecisionTree(child, context));
|
|
12883
14436
|
break;
|
|
12884
14437
|
}
|
|
12885
14438
|
}
|
|
12886
|
-
return
|
|
14439
|
+
return path11;
|
|
12887
14440
|
}
|
|
12888
14441
|
evaluateCondition(node, _context) {
|
|
12889
14442
|
return node.confidence > 0.5;
|
|
@@ -18989,7 +20542,7 @@ var TemplateManager = class _TemplateManager {
|
|
|
18989
20542
|
templatesDir;
|
|
18990
20543
|
builtInTemplates = /* @__PURE__ */ new Map();
|
|
18991
20544
|
constructor() {
|
|
18992
|
-
this.templatesDir =
|
|
20545
|
+
this.templatesDir = path10.join(os3.homedir(), ".maria-code", "templates");
|
|
18993
20546
|
this.ensureTemplatesDir();
|
|
18994
20547
|
this.initializeBuiltInTemplates();
|
|
18995
20548
|
this.loadUserTemplates();
|
|
@@ -19141,7 +20694,7 @@ var TemplateManager = class _TemplateManager {
|
|
|
19141
20694
|
files.forEach((file) => {
|
|
19142
20695
|
if (file.endsWith(".json")) {
|
|
19143
20696
|
try {
|
|
19144
|
-
const content = fs7.readFileSync(
|
|
20697
|
+
const content = fs7.readFileSync(path10.join(this.templatesDir, file), "utf-8");
|
|
19145
20698
|
const template = JSON.parse(content);
|
|
19146
20699
|
template.createdAt = new Date(template.createdAt);
|
|
19147
20700
|
template.updatedAt = new Date(template.updatedAt);
|
|
@@ -19160,7 +20713,7 @@ var TemplateManager = class _TemplateManager {
|
|
|
19160
20713
|
*/
|
|
19161
20714
|
saveTemplate(template) {
|
|
19162
20715
|
const filename = `${template.id}.json`;
|
|
19163
|
-
const filepath =
|
|
20716
|
+
const filepath = path10.join(this.templatesDir, filename);
|
|
19164
20717
|
fs7.writeFileSync(filepath, JSON.stringify(template, null, 2));
|
|
19165
20718
|
}
|
|
19166
20719
|
/**
|
|
@@ -19235,8 +20788,8 @@ var TemplateManager = class _TemplateManager {
|
|
|
19235
20788
|
}
|
|
19236
20789
|
this.templates.delete(id);
|
|
19237
20790
|
try {
|
|
19238
|
-
const
|
|
19239
|
-
|
|
20791
|
+
const fs12 = await import('fs');
|
|
20792
|
+
fs12.unlinkSync(path10.join(this.templatesDir, `${id}.json`));
|
|
19240
20793
|
} catch (error) {
|
|
19241
20794
|
logger.error("Failed to delete template file:", error);
|
|
19242
20795
|
}
|
|
@@ -19753,7 +21306,7 @@ var HotkeyManager = class _HotkeyManager {
|
|
|
19753
21306
|
isEnabled = true;
|
|
19754
21307
|
// private activeKeys: Set<string> = new Set(); // Reserved for future use
|
|
19755
21308
|
constructor() {
|
|
19756
|
-
this.configPath =
|
|
21309
|
+
this.configPath = path10.join(os3.homedir(), ".maria", "hotkeys.json");
|
|
19757
21310
|
this.loadBindings();
|
|
19758
21311
|
this.initializeDefaultBindings();
|
|
19759
21312
|
}
|
|
@@ -20138,7 +21691,7 @@ ${chalk13__default.default.gray("Use /hotkey to manage hotkeys")}
|
|
|
20138
21691
|
saveBindings() {
|
|
20139
21692
|
try {
|
|
20140
21693
|
const config2 = this.exportConfig();
|
|
20141
|
-
const dir =
|
|
21694
|
+
const dir = path10.join(os3.homedir(), ".maria");
|
|
20142
21695
|
if (!fs7.existsSync(dir)) {
|
|
20143
21696
|
fs7.mkdirSync(dir, { recursive: true });
|
|
20144
21697
|
}
|
|
@@ -20155,7 +21708,7 @@ init_cjs_shims();
|
|
|
20155
21708
|
// src/utils/env-loader.ts
|
|
20156
21709
|
init_cjs_shims();
|
|
20157
21710
|
function loadEnvironmentVariables() {
|
|
20158
|
-
const localEnvPath =
|
|
21711
|
+
const localEnvPath = path10__namespace.join(process.cwd(), ".env.local");
|
|
20159
21712
|
if (fs7__namespace.existsSync(localEnvPath)) {
|
|
20160
21713
|
const result = dotenv__namespace.config({ path: localEnvPath });
|
|
20161
21714
|
if (result.error) {
|
|
@@ -20164,14 +21717,14 @@ function loadEnvironmentVariables() {
|
|
|
20164
21717
|
console.log("\u2705 Loaded environment from .env.local");
|
|
20165
21718
|
}
|
|
20166
21719
|
}
|
|
20167
|
-
const envPath =
|
|
21720
|
+
const envPath = path10__namespace.join(process.cwd(), ".env");
|
|
20168
21721
|
if (fs7__namespace.existsSync(envPath)) {
|
|
20169
21722
|
const result = dotenv__namespace.config({ path: envPath, override: false });
|
|
20170
21723
|
if (result.error) {
|
|
20171
21724
|
console.warn("Error loading .env:", result.error);
|
|
20172
21725
|
}
|
|
20173
21726
|
}
|
|
20174
|
-
const lmstudioEnvPath =
|
|
21727
|
+
const lmstudioEnvPath = path10__namespace.join(process.cwd(), ".env.lmstudio");
|
|
20175
21728
|
if (fs7__namespace.existsSync(lmstudioEnvPath)) {
|
|
20176
21729
|
const result = dotenv__namespace.config({ path: lmstudioEnvPath, override: false });
|
|
20177
21730
|
if (result.error) {
|
|
@@ -20581,280 +22134,55 @@ var InteractiveModelSelector = class {
|
|
|
20581
22134
|
}
|
|
20582
22135
|
async loadLocalModel(modelId) {
|
|
20583
22136
|
try {
|
|
20584
|
-
console.log(chalk13__default.default.cyan(`
|
|
20585
|
-
\u23F3 Loading ${modelId}...`));
|
|
20586
|
-
await execAsync(`/Users/bongin_max/.lmstudio/bin/lms load ${modelId}`);
|
|
20587
|
-
console.log(chalk13__default.default.green(`\u2705 Model ${modelId} loaded successfully`));
|
|
20588
|
-
} catch (error) {
|
|
20589
|
-
console.error(chalk13__default.default.red(`Failed to load model: ${error}`));
|
|
20590
|
-
}
|
|
20591
|
-
}
|
|
20592
|
-
async updateEnvironment(model) {
|
|
20593
|
-
const envPath = path5__namespace.join(process.cwd(), ".env.local");
|
|
20594
|
-
if (model.type === "local") {
|
|
20595
|
-
process.env["AI_PROVIDER"] = "lmstudio";
|
|
20596
|
-
process.env["LMSTUDIO_DEFAULT_MODEL"] = model.id;
|
|
20597
|
-
process.env["OFFLINE_MODE"] = "true";
|
|
20598
|
-
} else {
|
|
20599
|
-
process.env["AI_PROVIDER"] = model.provider.toLowerCase();
|
|
20600
|
-
process.env["AI_MODEL"] = model.id;
|
|
20601
|
-
process.env["OFFLINE_MODE"] = "false";
|
|
20602
|
-
}
|
|
20603
|
-
if (fs7__namespace.existsSync(envPath)) {
|
|
20604
|
-
let content = fs7__namespace.readFileSync(envPath, "utf-8");
|
|
20605
|
-
if (model.type === "local") {
|
|
20606
|
-
content = content.replace(
|
|
20607
|
-
/LMSTUDIO_DEFAULT_MODEL=.*/g,
|
|
20608
|
-
`LMSTUDIO_DEFAULT_MODEL=${model.id}`
|
|
20609
|
-
);
|
|
20610
|
-
content = content.replace(/AI_PROVIDER=.*/g, "AI_PROVIDER=lmstudio");
|
|
20611
|
-
content = content.replace(/OFFLINE_MODE=.*/g, "OFFLINE_MODE=true");
|
|
20612
|
-
}
|
|
20613
|
-
fs7__namespace.writeFileSync(envPath, content);
|
|
20614
|
-
}
|
|
20615
|
-
}
|
|
20616
|
-
cleanup() {
|
|
20617
|
-
if (process.stdin.isTTY) {
|
|
20618
|
-
process.stdin.setRawMode(false);
|
|
20619
|
-
}
|
|
20620
|
-
process.stdin.removeAllListeners("keypress");
|
|
20621
|
-
this.rl.close();
|
|
20622
|
-
}
|
|
20623
|
-
};
|
|
20624
|
-
async function runInteractiveModelSelector() {
|
|
20625
|
-
const selector = new InteractiveModelSelector();
|
|
20626
|
-
await selector.initialize();
|
|
20627
|
-
return await selector.selectModel();
|
|
20628
|
-
}
|
|
20629
|
-
__name(runInteractiveModelSelector, "runInteractiveModelSelector");
|
|
20630
|
-
|
|
20631
|
-
// src/services/chat-context.service.ts
|
|
20632
|
-
init_cjs_shims();
|
|
20633
|
-
var ChatContextService = class _ChatContextService extends events.EventEmitter {
|
|
20634
|
-
static {
|
|
20635
|
-
__name(this, "ChatContextService");
|
|
20636
|
-
}
|
|
20637
|
-
static instance;
|
|
20638
|
-
contextWindow = [];
|
|
20639
|
-
fullHistory = [];
|
|
20640
|
-
config;
|
|
20641
|
-
currentTokens = 0;
|
|
20642
|
-
compressionCount = 0;
|
|
20643
|
-
sessionId;
|
|
20644
|
-
constructor(config2) {
|
|
20645
|
-
super();
|
|
20646
|
-
this.config = {
|
|
20647
|
-
maxTokens: config2?.maxTokens || 128e3,
|
|
20648
|
-
compressionThreshold: config2?.compressionThreshold || 0.8,
|
|
20649
|
-
summaryTokenLimit: config2?.summaryTokenLimit || 2e3,
|
|
20650
|
-
persistPath: config2?.persistPath || path5__namespace.join(process.env["HOME"] || "", ".maria", "context")
|
|
20651
|
-
};
|
|
20652
|
-
this.sessionId = this.generateSessionId();
|
|
20653
|
-
}
|
|
20654
|
-
static getInstance(config2) {
|
|
20655
|
-
if (!_ChatContextService.instance) {
|
|
20656
|
-
_ChatContextService.instance = new _ChatContextService(config2);
|
|
20657
|
-
}
|
|
20658
|
-
return _ChatContextService.instance;
|
|
20659
|
-
}
|
|
20660
|
-
generateSessionId() {
|
|
20661
|
-
return `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
20662
|
-
}
|
|
20663
|
-
countTokens(text) {
|
|
20664
|
-
try {
|
|
20665
|
-
return gpt3Encoder.encode(text).length;
|
|
20666
|
-
} catch {
|
|
20667
|
-
return Math.ceil(text.length / 4);
|
|
20668
|
-
}
|
|
20669
|
-
}
|
|
20670
|
-
async addMessage(message) {
|
|
20671
|
-
const tokens = this.countTokens(message.content);
|
|
20672
|
-
const fullMessage = {
|
|
20673
|
-
...message,
|
|
20674
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
20675
|
-
tokens
|
|
20676
|
-
};
|
|
20677
|
-
this.fullHistory.push(fullMessage);
|
|
20678
|
-
this.contextWindow.push(fullMessage);
|
|
20679
|
-
this.currentTokens += tokens;
|
|
20680
|
-
await this.optimizeMemory();
|
|
20681
|
-
this.emit("message-added", fullMessage);
|
|
20682
|
-
this.emit("context-updated", this.getStats());
|
|
20683
|
-
}
|
|
20684
|
-
async optimizeMemory() {
|
|
20685
|
-
const usageRatio = this.currentTokens / this.config.maxTokens;
|
|
20686
|
-
if (usageRatio >= this.config.compressionThreshold) {
|
|
20687
|
-
await this.compressContext();
|
|
20688
|
-
}
|
|
20689
|
-
while (this.currentTokens > this.config.maxTokens && this.contextWindow.length > 1) {
|
|
20690
|
-
const removed = this.contextWindow.shift();
|
|
20691
|
-
if (removed?.tokens) {
|
|
20692
|
-
this.currentTokens -= removed.tokens;
|
|
20693
|
-
}
|
|
20694
|
-
}
|
|
20695
|
-
}
|
|
20696
|
-
async compressContext() {
|
|
20697
|
-
if (this.contextWindow.length <= 2) return;
|
|
20698
|
-
const middleMessages = this.contextWindow.slice(1, -1);
|
|
20699
|
-
const summary = await this.generateSummary(middleMessages);
|
|
20700
|
-
if (summary) {
|
|
20701
|
-
const summaryMessage = {
|
|
20702
|
-
role: "system",
|
|
20703
|
-
content: `[Compressed context summary]: ${summary}`,
|
|
20704
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
20705
|
-
tokens: this.countTokens(summary),
|
|
20706
|
-
metadata: { compressed: true, originalCount: middleMessages.length }
|
|
20707
|
-
};
|
|
20708
|
-
const firstMessage = this.contextWindow[0];
|
|
20709
|
-
const lastMessage = this.contextWindow[this.contextWindow.length - 1];
|
|
20710
|
-
if (!firstMessage || !lastMessage) return;
|
|
20711
|
-
this.contextWindow = [firstMessage, summaryMessage, lastMessage];
|
|
20712
|
-
this.recalculateTokens();
|
|
20713
|
-
this.compressionCount++;
|
|
20714
|
-
this.emit("context-compressed", {
|
|
20715
|
-
originalCount: middleMessages.length,
|
|
20716
|
-
summaryTokens: summaryMessage.tokens
|
|
20717
|
-
});
|
|
20718
|
-
}
|
|
20719
|
-
}
|
|
20720
|
-
async generateSummary(messages) {
|
|
20721
|
-
const keyPoints = messages.filter((m) => m.role === "user").map((m) => m.content.substring(0, 100)).join("; ");
|
|
20722
|
-
return `Previous discussion covered: ${keyPoints}`;
|
|
20723
|
-
}
|
|
20724
|
-
recalculateTokens() {
|
|
20725
|
-
this.currentTokens = this.contextWindow.reduce((sum, msg) => sum + (msg.tokens || 0), 0);
|
|
20726
|
-
}
|
|
20727
|
-
clearContext(options) {
|
|
20728
|
-
if (options?.soft) {
|
|
20729
|
-
this.emit("display-cleared");
|
|
20730
|
-
return;
|
|
20731
|
-
}
|
|
20732
|
-
if (options?.summary && this.contextWindow.length > 0) {
|
|
20733
|
-
this.generateSummary(this.contextWindow).then((summary) => {
|
|
20734
|
-
this.emit("summary-generated", summary);
|
|
20735
|
-
});
|
|
20736
|
-
}
|
|
20737
|
-
const previousStats = this.getStats();
|
|
20738
|
-
this.contextWindow = [];
|
|
20739
|
-
this.currentTokens = 0;
|
|
20740
|
-
this.compressionCount = 0;
|
|
20741
|
-
if (!options?.soft) {
|
|
20742
|
-
this.fullHistory = [];
|
|
20743
|
-
this.sessionId = this.generateSessionId();
|
|
20744
|
-
}
|
|
20745
|
-
this.emit("context-cleared", previousStats);
|
|
20746
|
-
}
|
|
20747
|
-
getContext() {
|
|
20748
|
-
return [...this.contextWindow];
|
|
20749
|
-
}
|
|
20750
|
-
getFullHistory() {
|
|
20751
|
-
return [...this.fullHistory];
|
|
20752
|
-
}
|
|
20753
|
-
getStats() {
|
|
20754
|
-
return {
|
|
20755
|
-
totalMessages: this.fullHistory.length,
|
|
20756
|
-
totalTokens: this.currentTokens,
|
|
20757
|
-
maxTokens: this.config.maxTokens,
|
|
20758
|
-
usagePercentage: this.currentTokens / this.config.maxTokens * 100,
|
|
20759
|
-
messagesInWindow: this.contextWindow.length,
|
|
20760
|
-
compressedCount: this.compressionCount
|
|
20761
|
-
};
|
|
20762
|
-
}
|
|
20763
|
-
async persistSession() {
|
|
20764
|
-
if (!this.config.persistPath) return;
|
|
20765
|
-
try {
|
|
20766
|
-
await fs6__namespace.mkdir(this.config.persistPath, { recursive: true });
|
|
20767
|
-
const sessionFile = path5__namespace.join(this.config.persistPath, `${this.sessionId}.json`);
|
|
20768
|
-
const sessionData = {
|
|
20769
|
-
sessionId: this.sessionId,
|
|
20770
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
20771
|
-
stats: this.getStats(),
|
|
20772
|
-
contextWindow: this.contextWindow,
|
|
20773
|
-
fullHistory: this.fullHistory,
|
|
20774
|
-
compressionCount: this.compressionCount
|
|
20775
|
-
};
|
|
20776
|
-
await fs6__namespace.writeFile(sessionFile, JSON.stringify(sessionData, null, 2));
|
|
20777
|
-
this.emit("session-persisted", sessionFile);
|
|
20778
|
-
} catch (error) {
|
|
20779
|
-
this.emit("persist-error", error instanceof Error ? error : new Error(String(error)));
|
|
20780
|
-
}
|
|
20781
|
-
}
|
|
20782
|
-
async loadSession(sessionId) {
|
|
20783
|
-
if (!this.config.persistPath) return false;
|
|
20784
|
-
try {
|
|
20785
|
-
const sessionFile = path5__namespace.join(this.config.persistPath, `${sessionId}.json`);
|
|
20786
|
-
const data = await fs6__namespace.readFile(sessionFile, "utf-8");
|
|
20787
|
-
const sessionData = JSON.parse(data);
|
|
20788
|
-
this.sessionId = sessionData.sessionId;
|
|
20789
|
-
this.contextWindow = sessionData.contextWindow;
|
|
20790
|
-
this.fullHistory = sessionData.fullHistory;
|
|
20791
|
-
this.compressionCount = sessionData.compressionCount;
|
|
20792
|
-
this.recalculateTokens();
|
|
20793
|
-
this.emit("session-loaded", sessionId);
|
|
20794
|
-
return true;
|
|
22137
|
+
console.log(chalk13__default.default.cyan(`
|
|
22138
|
+
\u23F3 Loading ${modelId}...`));
|
|
22139
|
+
await execAsync(`/Users/bongin_max/.lmstudio/bin/lms load ${modelId}`);
|
|
22140
|
+
console.log(chalk13__default.default.green(`\u2705 Model ${modelId} loaded successfully`));
|
|
20795
22141
|
} catch (error) {
|
|
20796
|
-
|
|
20797
|
-
return false;
|
|
22142
|
+
console.error(chalk13__default.default.red(`Failed to load model: ${error}`));
|
|
20798
22143
|
}
|
|
20799
22144
|
}
|
|
20800
|
-
async
|
|
20801
|
-
|
|
20802
|
-
|
|
20803
|
-
|
|
20804
|
-
|
|
20805
|
-
|
|
20806
|
-
|
|
22145
|
+
async updateEnvironment(model) {
|
|
22146
|
+
const envPath = path10__namespace.join(process.cwd(), ".env.local");
|
|
22147
|
+
if (model.type === "local") {
|
|
22148
|
+
process.env["AI_PROVIDER"] = "lmstudio";
|
|
22149
|
+
process.env["LMSTUDIO_DEFAULT_MODEL"] = model.id;
|
|
22150
|
+
process.env["OFFLINE_MODE"] = "true";
|
|
22151
|
+
} else {
|
|
22152
|
+
process.env["AI_PROVIDER"] = model.provider.toLowerCase();
|
|
22153
|
+
process.env["AI_MODEL"] = model.id;
|
|
22154
|
+
process.env["OFFLINE_MODE"] = "false";
|
|
20807
22155
|
}
|
|
20808
|
-
|
|
20809
|
-
|
|
20810
|
-
|
|
20811
|
-
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
|
|
20816
|
-
|
|
20817
|
-
2
|
|
20818
|
-
);
|
|
20819
|
-
}
|
|
20820
|
-
async importContext(data) {
|
|
20821
|
-
try {
|
|
20822
|
-
const imported = JSON.parse(data);
|
|
20823
|
-
if (imported.context && Array.isArray(imported.context)) {
|
|
20824
|
-
this.contextWindow = imported.context;
|
|
20825
|
-
this.fullHistory = imported.fullHistory || imported.context;
|
|
20826
|
-
this.recalculateTokens();
|
|
20827
|
-
this.sessionId = imported.sessionId || this.generateSessionId();
|
|
20828
|
-
this.emit("context-imported", this.getStats());
|
|
22156
|
+
if (fs7__namespace.existsSync(envPath)) {
|
|
22157
|
+
let content = fs7__namespace.readFileSync(envPath, "utf-8");
|
|
22158
|
+
if (model.type === "local") {
|
|
22159
|
+
content = content.replace(
|
|
22160
|
+
/LMSTUDIO_DEFAULT_MODEL=.*/g,
|
|
22161
|
+
`LMSTUDIO_DEFAULT_MODEL=${model.id}`
|
|
22162
|
+
);
|
|
22163
|
+
content = content.replace(/AI_PROVIDER=.*/g, "AI_PROVIDER=lmstudio");
|
|
22164
|
+
content = content.replace(/OFFLINE_MODE=.*/g, "OFFLINE_MODE=true");
|
|
20829
22165
|
}
|
|
20830
|
-
|
|
20831
|
-
this.emit("import-error", error instanceof Error ? error : new Error(String(error)));
|
|
20832
|
-
throw error;
|
|
22166
|
+
fs7__namespace.writeFileSync(envPath, content);
|
|
20833
22167
|
}
|
|
20834
22168
|
}
|
|
20835
|
-
|
|
20836
|
-
|
|
20837
|
-
|
|
20838
|
-
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
let color = "\x1B[32m";
|
|
20842
|
-
if (percentage > 80)
|
|
20843
|
-
color = "\x1B[31m";
|
|
20844
|
-
else if (percentage > 60) color = "\x1B[33m";
|
|
20845
|
-
return `${color}[${filled}${empty}] ${percentage}% (${stats.totalTokens}/${stats.maxTokens} tokens)\x1B[0m`;
|
|
20846
|
-
}
|
|
20847
|
-
reset() {
|
|
20848
|
-
this.contextWindow = [];
|
|
20849
|
-
this.fullHistory = [];
|
|
20850
|
-
this.currentTokens = 0;
|
|
20851
|
-
this.compressionCount = 0;
|
|
20852
|
-
this.sessionId = this.generateSessionId();
|
|
20853
|
-
_ChatContextService.instance = null;
|
|
22169
|
+
cleanup() {
|
|
22170
|
+
if (process.stdin.isTTY) {
|
|
22171
|
+
process.stdin.setRawMode(false);
|
|
22172
|
+
}
|
|
22173
|
+
process.stdin.removeAllListeners("keypress");
|
|
22174
|
+
this.rl.close();
|
|
20854
22175
|
}
|
|
20855
22176
|
};
|
|
22177
|
+
async function runInteractiveModelSelector() {
|
|
22178
|
+
const selector = new InteractiveModelSelector();
|
|
22179
|
+
await selector.initialize();
|
|
22180
|
+
return await selector.selectModel();
|
|
22181
|
+
}
|
|
22182
|
+
__name(runInteractiveModelSelector, "runInteractiveModelSelector");
|
|
20856
22183
|
|
|
20857
22184
|
// src/services/slash-command-handler.ts
|
|
22185
|
+
init_chat_context_service();
|
|
20858
22186
|
init_code_generation_service();
|
|
20859
22187
|
|
|
20860
22188
|
// src/services/test-generation.service.ts
|
|
@@ -20947,7 +22275,7 @@ var TestGenerationService = class _TestGenerationService {
|
|
|
20947
22275
|
files.push(...await this.findTestableFiles("."));
|
|
20948
22276
|
}
|
|
20949
22277
|
} else {
|
|
20950
|
-
const stat2 = await
|
|
22278
|
+
const stat2 = await fs11__namespace.stat(target);
|
|
20951
22279
|
if (stat2.isDirectory()) {
|
|
20952
22280
|
files.push(...await this.findTestableFiles(target));
|
|
20953
22281
|
} else if (stat2.isFile() && this.isTestableFile(target)) {
|
|
@@ -20962,9 +22290,9 @@ var TestGenerationService = class _TestGenerationService {
|
|
|
20962
22290
|
// @ts-nocheck - Complex async type handling
|
|
20963
22291
|
async findTestableFiles(dir) {
|
|
20964
22292
|
const files = [];
|
|
20965
|
-
const entries = await
|
|
22293
|
+
const entries = await fs11__namespace.readdir(dir, { withFileTypes: true });
|
|
20966
22294
|
for (const entry of entries) {
|
|
20967
|
-
const fullPath =
|
|
22295
|
+
const fullPath = path10__namespace.join(dir, entry.name);
|
|
20968
22296
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
20969
22297
|
files.push(...await this.findTestableFiles(fullPath));
|
|
20970
22298
|
} else if (entry.isFile() && this.isTestableFile(entry.name)) {
|
|
@@ -20980,7 +22308,7 @@ var TestGenerationService = class _TestGenerationService {
|
|
|
20980
22308
|
isTestableFile(file) {
|
|
20981
22309
|
const testableExtensions = [".js", ".jsx", ".ts", ".tsx", ".py", ".go", ".rs", ".java"];
|
|
20982
22310
|
const excludePatterns = [".test.", ".spec.", ".min.", "test/", "tests/", "__tests__/"];
|
|
20983
|
-
const ext =
|
|
22311
|
+
const ext = path10__namespace.extname(file);
|
|
20984
22312
|
const isTestable = testableExtensions.includes(ext);
|
|
20985
22313
|
const isExcluded = excludePatterns.some((pattern) => file.includes(pattern));
|
|
20986
22314
|
return isTestable && !isExcluded;
|
|
@@ -20994,7 +22322,7 @@ var TestGenerationService = class _TestGenerationService {
|
|
|
20994
22322
|
const codeGenService = (await Promise.resolve().then(() => (init_code_generation_service(), code_generation_service_exports))).CodeGenerationService.getInstance();
|
|
20995
22323
|
for (const file of files) {
|
|
20996
22324
|
try {
|
|
20997
|
-
const content = await
|
|
22325
|
+
const content = await fs11__namespace.readFile(file, "utf-8");
|
|
20998
22326
|
const language = this.detectLanguage(file);
|
|
20999
22327
|
const existingTest = existingTests.get(file);
|
|
21000
22328
|
if (existingTest && existingTest.coverage > 80) {
|
|
@@ -21212,9 +22540,9 @@ BEGIN TEST GENERATION:
|
|
|
21212
22540
|
async writeTestFiles(tests, ___framework) {
|
|
21213
22541
|
for (const test of tests) {
|
|
21214
22542
|
try {
|
|
21215
|
-
const testDir =
|
|
21216
|
-
await
|
|
21217
|
-
await
|
|
22543
|
+
const testDir = path10__namespace.dirname(test.testFile);
|
|
22544
|
+
await fs11__namespace.mkdir(testDir, { recursive: true });
|
|
22545
|
+
await fs11__namespace.writeFile(test.testFile, test.content, "utf-8");
|
|
21218
22546
|
logger.info(`Created test file: ${test.testFile}`);
|
|
21219
22547
|
} catch (error) {
|
|
21220
22548
|
logger.error(`Failed to write test file ${test.testFile}:`, error);
|
|
@@ -21345,19 +22673,19 @@ BEGIN TEST GENERATION:
|
|
|
21345
22673
|
*/
|
|
21346
22674
|
// @ts-nocheck - Complex async type handling
|
|
21347
22675
|
getTestFileName(file, __framework) {
|
|
21348
|
-
const dir =
|
|
21349
|
-
const base =
|
|
21350
|
-
const ext =
|
|
22676
|
+
const dir = path10__namespace.dirname(file);
|
|
22677
|
+
const base = path10__namespace.basename(file, path10__namespace.extname(file));
|
|
22678
|
+
const ext = path10__namespace.extname(file);
|
|
21351
22679
|
if (framework === "Jest" || framework === "Vitest") {
|
|
21352
|
-
return
|
|
22680
|
+
return path10__namespace.join(dir, "__tests__", `${base}.test${ext}`);
|
|
21353
22681
|
} else if (framework === "Mocha") {
|
|
21354
|
-
return
|
|
22682
|
+
return path10__namespace.join(dir, "test", `${base}.spec${ext}`);
|
|
21355
22683
|
} else if (framework === "pytest") {
|
|
21356
|
-
return
|
|
22684
|
+
return path10__namespace.join(dir, `test_${base}.py`);
|
|
21357
22685
|
} else if (framework === "go test") {
|
|
21358
22686
|
return file.replace(".go", "_test.go");
|
|
21359
22687
|
} else {
|
|
21360
|
-
return
|
|
22688
|
+
return path10__namespace.join(dir, `${base}.test${ext}`);
|
|
21361
22689
|
}
|
|
21362
22690
|
}
|
|
21363
22691
|
/**
|
|
@@ -21365,7 +22693,7 @@ BEGIN TEST GENERATION:
|
|
|
21365
22693
|
*/
|
|
21366
22694
|
// @ts-nocheck - Complex async type handling
|
|
21367
22695
|
detectLanguage(file) {
|
|
21368
|
-
const ext =
|
|
22696
|
+
const ext = path10__namespace.extname(file).toLowerCase();
|
|
21369
22697
|
const languageMap = {
|
|
21370
22698
|
".js": "javascript",
|
|
21371
22699
|
".jsx": "javascript",
|
|
@@ -21418,7 +22746,7 @@ var TestFrameworkDetector = class {
|
|
|
21418
22746
|
}
|
|
21419
22747
|
async detect() {
|
|
21420
22748
|
try {
|
|
21421
|
-
const packageJson = await
|
|
22749
|
+
const packageJson = await fs11__namespace.readFile("package.json", "utf-8");
|
|
21422
22750
|
const pkg = JSON.parse(packageJson);
|
|
21423
22751
|
if (pkg.devDependencies?.jest || pkg.scripts?.test?.includes("jest")) {
|
|
21424
22752
|
return "Jest";
|
|
@@ -21432,12 +22760,12 @@ var TestFrameworkDetector = class {
|
|
|
21432
22760
|
} catch {
|
|
21433
22761
|
}
|
|
21434
22762
|
try {
|
|
21435
|
-
await
|
|
22763
|
+
await fs11__namespace.access("pytest.ini");
|
|
21436
22764
|
return "pytest";
|
|
21437
22765
|
} catch {
|
|
21438
22766
|
try {
|
|
21439
|
-
await
|
|
21440
|
-
const content = await
|
|
22767
|
+
await fs11__namespace.access("setup.cfg");
|
|
22768
|
+
const content = await fs11__namespace.readFile("setup.cfg", "utf-8");
|
|
21441
22769
|
if (content.includes("[tool:pytest]")) {
|
|
21442
22770
|
return "pytest";
|
|
21443
22771
|
}
|
|
@@ -21445,12 +22773,12 @@ var TestFrameworkDetector = class {
|
|
|
21445
22773
|
}
|
|
21446
22774
|
}
|
|
21447
22775
|
try {
|
|
21448
|
-
await
|
|
22776
|
+
await fs11__namespace.access("go.mod");
|
|
21449
22777
|
return "go test";
|
|
21450
22778
|
} catch {
|
|
21451
22779
|
}
|
|
21452
22780
|
try {
|
|
21453
|
-
await
|
|
22781
|
+
await fs11__namespace.access("Cargo.toml");
|
|
21454
22782
|
return "cargo test";
|
|
21455
22783
|
} catch {
|
|
21456
22784
|
}
|
|
@@ -22415,7 +23743,7 @@ Run /config to customize MARIA settings.`;
|
|
|
22415
23743
|
async handleInit() {
|
|
22416
23744
|
try {
|
|
22417
23745
|
const rootPath = process.cwd();
|
|
22418
|
-
const mariaPath =
|
|
23746
|
+
const mariaPath = path10__namespace.join(rootPath, "MARIA.md");
|
|
22419
23747
|
const exists = fs7__namespace.existsSync(mariaPath);
|
|
22420
23748
|
if (exists) {
|
|
22421
23749
|
console.log("\u{1F4CA} Analyzing codebase for MARIA.md update...");
|
|
@@ -22573,14 +23901,14 @@ ${availableServers.map((server) => `\u2022 ${server.name}: ${server.description}
|
|
|
22573
23901
|
}
|
|
22574
23902
|
if (options.summary) {
|
|
22575
23903
|
const summary = await this.chatContextService.exportContext("markdown");
|
|
22576
|
-
const summaryPath =
|
|
23904
|
+
const summaryPath = path10__namespace.join(
|
|
22577
23905
|
process.env["HOME"] || "",
|
|
22578
23906
|
".maria",
|
|
22579
23907
|
"summaries",
|
|
22580
23908
|
`summary-${Date.now()}.md`
|
|
22581
23909
|
);
|
|
22582
23910
|
try {
|
|
22583
|
-
await fs7__namespace.promises.mkdir(
|
|
23911
|
+
await fs7__namespace.promises.mkdir(path10__namespace.dirname(summaryPath), { recursive: true });
|
|
22584
23912
|
await fs7__namespace.promises.writeFile(summaryPath, summary);
|
|
22585
23913
|
this.chatContextService.clearContext({ summary: true });
|
|
22586
23914
|
if (context.history) {
|
|
@@ -22680,8 +24008,8 @@ ${indicator}`,
|
|
|
22680
24008
|
async handleResume(context) {
|
|
22681
24009
|
const resumeFile = `${process.cwd()}/.maria-session.json`;
|
|
22682
24010
|
try {
|
|
22683
|
-
const
|
|
22684
|
-
const resumeData = await
|
|
24011
|
+
const fs12 = await import('fs/promises');
|
|
24012
|
+
const resumeData = await fs12.readFile(resumeFile, "utf-8");
|
|
22685
24013
|
const savedContext = JSON.parse(resumeData);
|
|
22686
24014
|
if (!savedContext.history) {
|
|
22687
24015
|
return {
|
|
@@ -22722,7 +24050,7 @@ ${indicator}`,
|
|
|
22722
24050
|
)
|
|
22723
24051
|
};
|
|
22724
24052
|
}
|
|
22725
|
-
await
|
|
24053
|
+
await fs12.unlink(resumeFile);
|
|
22726
24054
|
return {
|
|
22727
24055
|
success: true,
|
|
22728
24056
|
message: `Conversation resumed: ${context.history.length} messages restored${context.currentTask ? ` (task: ${context.currentTask})` : ""}`,
|
|
@@ -22942,11 +24270,11 @@ ${allFeedback.slice(-3).map(
|
|
|
22942
24270
|
severity: this.assessBugSeverity(bugType, description),
|
|
22943
24271
|
reportId: `bug-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
|
|
22944
24272
|
};
|
|
22945
|
-
const
|
|
24273
|
+
const fs12 = await import('fs/promises');
|
|
22946
24274
|
const reportsDir = `${process.cwd()}/.maria-reports`;
|
|
22947
24275
|
try {
|
|
22948
|
-
await
|
|
22949
|
-
await
|
|
24276
|
+
await fs12.mkdir(reportsDir, { recursive: true });
|
|
24277
|
+
await fs12.writeFile(
|
|
22950
24278
|
`${reportsDir}/${bugReport.reportId}.json`,
|
|
22951
24279
|
JSON.stringify(bugReport, null, 2)
|
|
22952
24280
|
);
|
|
@@ -23122,10 +24450,10 @@ Vim keybindings disabled.`;
|
|
|
23122
24450
|
}
|
|
23123
24451
|
async handleVersion() {
|
|
23124
24452
|
try {
|
|
23125
|
-
const
|
|
23126
|
-
const
|
|
23127
|
-
const packagePath =
|
|
23128
|
-
const packageData = JSON.parse(await
|
|
24453
|
+
const fs12 = await import('fs/promises');
|
|
24454
|
+
const path11 = await import('path');
|
|
24455
|
+
const packagePath = path11.resolve(process.cwd(), "package.json");
|
|
24456
|
+
const packageData = JSON.parse(await fs12.readFile(packagePath, "utf8"));
|
|
23129
24457
|
return {
|
|
23130
24458
|
success: true,
|
|
23131
24459
|
message: `MARIA CODE CLI v${packageData["version"] || "1.0.0"}
|
|
@@ -23417,8 +24745,8 @@ Try:
|
|
|
23417
24745
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
23418
24746
|
const filename = `maria-aliases-${timestamp}.json`;
|
|
23419
24747
|
try {
|
|
23420
|
-
const
|
|
23421
|
-
await
|
|
24748
|
+
const fs12 = await import('fs/promises');
|
|
24749
|
+
await fs12.writeFile(filename, exportData);
|
|
23422
24750
|
return {
|
|
23423
24751
|
success: true,
|
|
23424
24752
|
message: `\u2705 Aliases exported to ${filename}
|
|
@@ -23441,8 +24769,8 @@ ${exportData}`
|
|
|
23441
24769
|
};
|
|
23442
24770
|
}
|
|
23443
24771
|
try {
|
|
23444
|
-
const
|
|
23445
|
-
const jsonData = await
|
|
24772
|
+
const fs12 = await import('fs/promises');
|
|
24773
|
+
const jsonData = await fs12.readFile(filename, "utf-8");
|
|
23446
24774
|
return await this.aliasSystem.importAliases(jsonData);
|
|
23447
24775
|
} catch (error) {
|
|
23448
24776
|
return {
|
|
@@ -23651,8 +24979,8 @@ Available commands: run, save, delete, view, export, import`
|
|
|
23651
24979
|
};
|
|
23652
24980
|
}
|
|
23653
24981
|
try {
|
|
23654
|
-
const
|
|
23655
|
-
const content = await
|
|
24982
|
+
const fs12 = await import('fs/promises');
|
|
24983
|
+
const content = await fs12.readFile(filename, "utf-8");
|
|
23656
24984
|
const commands2 = this.batchEngine.parseBatchString(content);
|
|
23657
24985
|
const result = await this.batchEngine.executeBatch(commands2, context, {
|
|
23658
24986
|
stopOnError: true
|
|
@@ -23831,8 +25159,8 @@ Batch execution ${result.success ? "completed successfully" : "completed with er
|
|
|
23831
25159
|
const config2 = this.hotkeyManager.exportConfig();
|
|
23832
25160
|
const filename = `hotkeys-${Date.now()}.json`;
|
|
23833
25161
|
try {
|
|
23834
|
-
const
|
|
23835
|
-
await
|
|
25162
|
+
const fs12 = await import('fs/promises');
|
|
25163
|
+
await fs12.writeFile(filename, JSON.stringify(config2, null, 2));
|
|
23836
25164
|
return {
|
|
23837
25165
|
success: true,
|
|
23838
25166
|
message: `\u2705 Hotkey configuration exported to ${filename}`,
|
|
@@ -23854,8 +25182,8 @@ Batch execution ${result.success ? "completed successfully" : "completed with er
|
|
|
23854
25182
|
};
|
|
23855
25183
|
}
|
|
23856
25184
|
try {
|
|
23857
|
-
const
|
|
23858
|
-
const content = await
|
|
25185
|
+
const fs12 = await import('fs/promises');
|
|
25186
|
+
const content = await fs12.readFile(filename, "utf-8");
|
|
23859
25187
|
const config2 = JSON.parse(content);
|
|
23860
25188
|
const result = this.hotkeyManager.importConfig(
|
|
23861
25189
|
config2
|
|
@@ -23906,7 +25234,7 @@ Batch execution ${result.success ? "completed successfully" : "completed with er
|
|
|
23906
25234
|
const shouldSave = context.history && context.history.length > 0;
|
|
23907
25235
|
if (shouldSave) {
|
|
23908
25236
|
try {
|
|
23909
|
-
const
|
|
25237
|
+
const fs12 = await import('fs/promises');
|
|
23910
25238
|
const sessionFile = `${process.cwd()}/.maria-session.json`;
|
|
23911
25239
|
const sessionData = {
|
|
23912
25240
|
sessionId: context.sessionId,
|
|
@@ -23915,7 +25243,7 @@ Batch execution ${result.success ? "completed successfully" : "completed with er
|
|
|
23915
25243
|
metadata: context.metadata,
|
|
23916
25244
|
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
23917
25245
|
};
|
|
23918
|
-
await
|
|
25246
|
+
await fs12.writeFile(sessionFile, JSON.stringify(sessionData, null, 2));
|
|
23919
25247
|
const stats = {
|
|
23920
25248
|
messages: context.history?.length || 0,
|
|
23921
25249
|
cost: context.metadata?.["cost"] || 0,
|
|
@@ -23946,8 +25274,8 @@ Session saved: ${stats.messages} messages, $${stats.cost.toFixed(6)}, ${Math.flo
|
|
|
23946
25274
|
async handleMigrateInstaller() {
|
|
23947
25275
|
try {
|
|
23948
25276
|
const { execSync } = await import('child_process');
|
|
23949
|
-
const
|
|
23950
|
-
const
|
|
25277
|
+
const fs12 = await import('fs/promises');
|
|
25278
|
+
const path11 = await import('path');
|
|
23951
25279
|
const globalInstallCheck = {
|
|
23952
25280
|
npm: false,
|
|
23953
25281
|
yarn: false,
|
|
@@ -23970,11 +25298,11 @@ Session saved: ${stats.messages} messages, $${stats.cost.toFixed(6)}, ${Math.flo
|
|
|
23970
25298
|
} catch {
|
|
23971
25299
|
}
|
|
23972
25300
|
const cwd = process.cwd();
|
|
23973
|
-
const packageJsonPath =
|
|
25301
|
+
const packageJsonPath = path11.join(cwd, "package.json");
|
|
23974
25302
|
let localInstall = false;
|
|
23975
25303
|
let packageJson = null;
|
|
23976
25304
|
try {
|
|
23977
|
-
const packageJsonContent = await
|
|
25305
|
+
const packageJsonContent = await fs12.readFile(packageJsonPath, "utf-8");
|
|
23978
25306
|
packageJson = JSON.parse(packageJsonContent);
|
|
23979
25307
|
const typedPackage = packageJson;
|
|
23980
25308
|
localInstall = !!(typedPackage["dependencies"]?.["@maria/code-cli"] || typedPackage["devDependencies"]?.["@maria/code-cli"]);
|
|
@@ -24232,7 +25560,7 @@ Run the steps above to complete your migration!`;
|
|
|
24232
25560
|
devDependencies: []
|
|
24233
25561
|
}
|
|
24234
25562
|
};
|
|
24235
|
-
const gitignorePath =
|
|
25563
|
+
const gitignorePath = path10__namespace.join(rootPath, ".gitignore");
|
|
24236
25564
|
const ignorePatterns = fs7__namespace.existsSync(gitignorePath) ? fs7__namespace.readFileSync(gitignorePath, "utf8").split("\n").filter((line) => line.trim() && !line.startsWith("#")) : ["node_modules", ".git", "dist", "build", ".env*"];
|
|
24237
25565
|
await this.analyzeDirectory(rootPath, rootPath, analysis, ignorePatterns);
|
|
24238
25566
|
this.inferTechStack(analysis);
|
|
@@ -24243,8 +25571,8 @@ Run the steps above to complete your migration!`;
|
|
|
24243
25571
|
try {
|
|
24244
25572
|
const items = fs7__namespace.readdirSync(currentPath);
|
|
24245
25573
|
for (const item of items) {
|
|
24246
|
-
const itemPath =
|
|
24247
|
-
const relativePath =
|
|
25574
|
+
const itemPath = path10__namespace.join(currentPath, item);
|
|
25575
|
+
const relativePath = path10__namespace.relative(rootPath, itemPath);
|
|
24248
25576
|
if (this.shouldIgnore(relativePath, ignorePatterns)) continue;
|
|
24249
25577
|
const stat2 = fs7__namespace.statSync(itemPath);
|
|
24250
25578
|
if (stat2.isDirectory()) {
|
|
@@ -24253,7 +25581,7 @@ Run the steps above to complete your migration!`;
|
|
|
24253
25581
|
} else if (stat2.isFile()) {
|
|
24254
25582
|
analysis.files.push(relativePath);
|
|
24255
25583
|
analysis.fileCount++;
|
|
24256
|
-
const ext =
|
|
25584
|
+
const ext = path10__namespace.extname(item).toLowerCase();
|
|
24257
25585
|
const language = this.getLanguageFromExtension(ext);
|
|
24258
25586
|
if (language && !analysis.languages.includes(language)) {
|
|
24259
25587
|
analysis.languages.push(language);
|
|
@@ -24325,7 +25653,7 @@ Run the steps above to complete your migration!`;
|
|
|
24325
25653
|
analysis.techStack.push("Lerna");
|
|
24326
25654
|
}
|
|
24327
25655
|
try {
|
|
24328
|
-
const packageJsonPath =
|
|
25656
|
+
const packageJsonPath = path10__namespace.join(rootPath, "package.json");
|
|
24329
25657
|
if (fs7__namespace.existsSync(packageJsonPath)) {
|
|
24330
25658
|
const packageJson = JSON.parse(fs7__namespace.readFileSync(packageJsonPath, "utf8"));
|
|
24331
25659
|
analysis.dependencies = {
|
|
@@ -24350,7 +25678,7 @@ Run the steps above to complete your migration!`;
|
|
|
24350
25678
|
analysis.techStack = [...new Set(analysis.techStack)];
|
|
24351
25679
|
}
|
|
24352
25680
|
async createMariaMd(rootPath, analysis) {
|
|
24353
|
-
const projectName =
|
|
25681
|
+
const projectName = path10__namespace.basename(rootPath);
|
|
24354
25682
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
24355
25683
|
return `# MARIA.md
|
|
24356
25684
|
|
|
@@ -25654,17 +26982,36 @@ async function showModels(maria) {
|
|
|
25654
26982
|
try {
|
|
25655
26983
|
const models = await maria.getModels();
|
|
25656
26984
|
const available = models.filter((m) => m.available);
|
|
25657
|
-
|
|
25658
|
-
|
|
26985
|
+
const unavailable = models.filter((m) => !m.available);
|
|
26986
|
+
if (available.length === 0 && unavailable.length === 0) {
|
|
26987
|
+
console.log(chalk13__default.default.yellow("No models found"));
|
|
25659
26988
|
return;
|
|
25660
26989
|
}
|
|
25661
|
-
|
|
25662
|
-
|
|
25663
|
-
const
|
|
25664
|
-
|
|
25665
|
-
|
|
26990
|
+
if (available.length > 0) {
|
|
26991
|
+
console.log(chalk13__default.default.green("\u2705 Available Models:"));
|
|
26992
|
+
for (const model of available) {
|
|
26993
|
+
const provider = chalk13__default.default.gray(`[${model.provider}]`);
|
|
26994
|
+
const capabilities = model.capabilities ? model.capabilities.join(", ") : "No capabilities listed";
|
|
26995
|
+
console.log(` \u2705 ${chalk13__default.default.bold(model.name)} ${provider}`);
|
|
26996
|
+
console.log(` ${chalk13__default.default.gray(capabilities)}`);
|
|
26997
|
+
}
|
|
26998
|
+
console.log("");
|
|
26999
|
+
}
|
|
27000
|
+
if (unavailable.length > 0) {
|
|
27001
|
+
console.log(chalk13__default.default.yellow("\u26A0\uFE0F Cloud Models (Require API Keys):"));
|
|
27002
|
+
for (const model of unavailable) {
|
|
27003
|
+
const provider = chalk13__default.default.gray(`[${model.provider}]`);
|
|
27004
|
+
const capabilities = model.capabilities ? model.capabilities.join(", ") : "No capabilities listed";
|
|
27005
|
+
console.log(` \u274C ${chalk13__default.default.white(model.name)} ${provider}`);
|
|
27006
|
+
console.log(` ${chalk13__default.default.gray(capabilities)}`);
|
|
27007
|
+
}
|
|
27008
|
+
console.log("");
|
|
27009
|
+
console.log(chalk13__default.default.gray("\u{1F4A1} To use cloud models, set environment variables:"));
|
|
27010
|
+
console.log(chalk13__default.default.cyan(" export OPENAI_API_KEY=your_key"));
|
|
27011
|
+
console.log(chalk13__default.default.cyan(" export ANTHROPIC_API_KEY=your_key"));
|
|
27012
|
+
console.log(chalk13__default.default.cyan(" export GOOGLE_API_KEY=your_key"));
|
|
27013
|
+
console.log("");
|
|
25666
27014
|
}
|
|
25667
|
-
console.log("");
|
|
25668
27015
|
} catch (error) {
|
|
25669
27016
|
console.error(chalk13__default.default.red("\u274C Failed to get models:"), error);
|
|
25670
27017
|
}
|
|
@@ -25731,26 +27078,34 @@ async function showModelSelector(maria, args) {
|
|
|
25731
27078
|
try {
|
|
25732
27079
|
const models = await maria.getModels();
|
|
25733
27080
|
const available = models.filter((m) => m.available);
|
|
27081
|
+
const allModels = models;
|
|
25734
27082
|
if (args.length > 0) {
|
|
25735
27083
|
const modelName = args.join(" ");
|
|
25736
|
-
const targetModel =
|
|
27084
|
+
const targetModel = allModels.find(
|
|
25737
27085
|
(m) => m.name.toLowerCase().includes(modelName.toLowerCase()) || m.provider.toLowerCase().includes(modelName.toLowerCase())
|
|
25738
27086
|
);
|
|
25739
27087
|
if (targetModel) {
|
|
25740
|
-
|
|
25741
|
-
|
|
25742
|
-
|
|
25743
|
-
|
|
25744
|
-
|
|
25745
|
-
|
|
25746
|
-
|
|
27088
|
+
if (targetModel.available) {
|
|
27089
|
+
console.log(
|
|
27090
|
+
chalk13__default.default.green(`\u2705 Target model found: ${targetModel.name} (${targetModel.provider})`)
|
|
27091
|
+
);
|
|
27092
|
+
console.log(chalk13__default.default.yellow("Note: Model switching will be implemented in a future version"));
|
|
27093
|
+
console.log(
|
|
27094
|
+
chalk13__default.default.gray("Currently, you can switch models using environment variables or CLI options")
|
|
27095
|
+
);
|
|
27096
|
+
} else {
|
|
27097
|
+
console.log(
|
|
27098
|
+
chalk13__default.default.yellow(`\u26A0\uFE0F Target model found but unavailable: ${targetModel.name} (${targetModel.provider})`)
|
|
27099
|
+
);
|
|
27100
|
+
console.log(chalk13__default.default.gray(`This model requires API key for ${targetModel.provider}`));
|
|
27101
|
+
}
|
|
25747
27102
|
} else {
|
|
25748
27103
|
console.log(chalk13__default.default.red(`\u274C Model not found: ${modelName}`));
|
|
25749
27104
|
console.log(chalk13__default.default.gray("Available models listed below:"));
|
|
25750
27105
|
}
|
|
25751
27106
|
return;
|
|
25752
27107
|
}
|
|
25753
|
-
await showInteractiveModelSelector(
|
|
27108
|
+
await showInteractiveModelSelector(allModels);
|
|
25754
27109
|
} catch (error) {
|
|
25755
27110
|
console.error(chalk13__default.default.red("\u274C Failed to access model selector:"), error);
|
|
25756
27111
|
}
|
|
@@ -25772,25 +27127,33 @@ async function showInteractiveModelSelector(models) {
|
|
|
25772
27127
|
console.log(chalk13__default.default.gray("Use \u2191/\u2193 to navigate, Enter to select, Esc to cancel\n"));
|
|
25773
27128
|
console.log(chalk13__default.default.yellow("\u{1F4CB} Available AI Models:\n"));
|
|
25774
27129
|
models.forEach((model, index) => {
|
|
25775
|
-
const status = model.available ? "\u2705" : "\
|
|
27130
|
+
const status = model.available ? "\u2705" : "\u274C";
|
|
25776
27131
|
const pricing = model.pricing ? ` ($${model.pricing.input}/${model.pricing.output})` : "";
|
|
25777
27132
|
const isSelected = index === selectedIndex;
|
|
27133
|
+
const availabilityNote = model.available ? "" : " (API key required)";
|
|
25778
27134
|
if (isSelected) {
|
|
25779
27135
|
console.log(
|
|
25780
|
-
chalk13__default.default.bgBlue.white(` \u25B6 ${status} ${model.name} [${model.provider}]${pricing}`)
|
|
27136
|
+
chalk13__default.default.bgBlue.white(` \u25B6 ${status} ${model.name} [${model.provider}]${pricing}${availabilityNote}`)
|
|
25781
27137
|
);
|
|
25782
27138
|
console.log(chalk13__default.default.bgBlue.white(` ${model.description}`));
|
|
25783
27139
|
if (model.capabilities && model.capabilities.length > 0) {
|
|
25784
27140
|
console.log(chalk13__default.default.bgBlue.white(` Capabilities: ${model.capabilities.join(", ")}`));
|
|
25785
27141
|
}
|
|
27142
|
+
if (!model.available) {
|
|
27143
|
+
console.log(chalk13__default.default.bgBlue.white(` Status: Requires ${model.provider.toUpperCase()}_API_KEY environment variable`));
|
|
27144
|
+
}
|
|
25786
27145
|
} else {
|
|
27146
|
+
const nameColor = model.available ? chalk13__default.default.bold : chalk13__default.default.white;
|
|
25787
27147
|
console.log(
|
|
25788
|
-
` ${status} ${
|
|
27148
|
+
` ${status} ${nameColor(model.name)} ${chalk13__default.default.gray(`[${model.provider}]`)}${pricing}${availabilityNote}`
|
|
25789
27149
|
);
|
|
25790
27150
|
console.log(` ${chalk13__default.default.gray(model.description)}`);
|
|
25791
27151
|
if (model.capabilities && model.capabilities.length > 0) {
|
|
25792
27152
|
console.log(` ${chalk13__default.default.cyan("Capabilities:")} ${model.capabilities.join(", ")}`);
|
|
25793
27153
|
}
|
|
27154
|
+
if (!model.available) {
|
|
27155
|
+
console.log(` ${chalk13__default.default.yellow("Status:")} Requires ${model.provider.toUpperCase()}_API_KEY environment variable`);
|
|
27156
|
+
}
|
|
25794
27157
|
}
|
|
25795
27158
|
console.log("");
|
|
25796
27159
|
});
|
|
@@ -25813,7 +27176,6 @@ async function showInteractiveModelSelector(models) {
|
|
|
25813
27176
|
renderModels();
|
|
25814
27177
|
break;
|
|
25815
27178
|
case "\r":
|
|
25816
|
-
isSelecting = false;
|
|
25817
27179
|
cleanup();
|
|
25818
27180
|
const selectedModel = models[selectedIndex];
|
|
25819
27181
|
console.log(
|
|
@@ -25831,13 +27193,11 @@ async function showInteractiveModelSelector(models) {
|
|
|
25831
27193
|
resolve();
|
|
25832
27194
|
break;
|
|
25833
27195
|
case "\x1B":
|
|
25834
|
-
isSelecting = false;
|
|
25835
27196
|
cleanup();
|
|
25836
27197
|
console.log(chalk13__default.default.gray("\n\u{1F4CB} Model selection cancelled\n"));
|
|
25837
27198
|
resolve();
|
|
25838
27199
|
break;
|
|
25839
27200
|
case "":
|
|
25840
|
-
isSelecting = false;
|
|
25841
27201
|
cleanup();
|
|
25842
27202
|
console.log(chalk13__default.default.gray("\n\u{1F4CB} Model selection cancelled\n"));
|
|
25843
27203
|
resolve();
|
|
@@ -25853,7 +27213,7 @@ async function showAvatar() {
|
|
|
25853
27213
|
console.log(chalk13__default.default.blue("\n\u{1F3AD} MARIA Avatar Interface\n"));
|
|
25854
27214
|
const avatarPath = "/Users/bongin_max/maria_code/face_only_96x96_ramp.txt";
|
|
25855
27215
|
try {
|
|
25856
|
-
const avatarData = await
|
|
27216
|
+
const avatarData = await fs11__namespace.readFile(avatarPath, "utf-8");
|
|
25857
27217
|
const lines = avatarData.split("\n").slice(0, 30);
|
|
25858
27218
|
console.log(chalk13__default.default.white("\u2550".repeat(80)));
|
|
25859
27219
|
lines.forEach((line) => {
|
|
@@ -26936,13 +28296,13 @@ __name(loadConfig2, "loadConfig");
|
|
|
26936
28296
|
async function loadEnvironmentConfig() {
|
|
26937
28297
|
try {
|
|
26938
28298
|
const { importNodeBuiltin: importNodeBuiltin2, safeDynamicImport: safeDynamicImport2 } = await Promise.resolve().then(() => (init_import_helper(), import_helper_exports));
|
|
26939
|
-
const
|
|
28299
|
+
const fs12 = await safeDynamicImport2("fs-extra").catch(
|
|
26940
28300
|
() => importNodeBuiltin2("fs")
|
|
26941
28301
|
);
|
|
26942
|
-
const
|
|
26943
|
-
const envPath =
|
|
26944
|
-
if (await
|
|
26945
|
-
const envContent = await
|
|
28302
|
+
const path11 = await importNodeBuiltin2("path");
|
|
28303
|
+
const envPath = path11.join(process.cwd(), ".env.local");
|
|
28304
|
+
if (await fs12.pathExists(envPath)) {
|
|
28305
|
+
const envContent = await fs12.readFile(envPath, "utf-8");
|
|
26946
28306
|
if (process.env["DEBUG"]) {
|
|
26947
28307
|
console.log("Loading environment from:", envPath);
|
|
26948
28308
|
}
|
|
@@ -27022,7 +28382,7 @@ async function checkOllamaInstalled() {
|
|
|
27022
28382
|
__name(checkOllamaInstalled, "checkOllamaInstalled");
|
|
27023
28383
|
async function installOllama() {
|
|
27024
28384
|
return new Promise((resolve, reject) => {
|
|
27025
|
-
const platform =
|
|
28385
|
+
const platform = os3__default.default.platform();
|
|
27026
28386
|
if (platform === "darwin") {
|
|
27027
28387
|
const brewChild = child_process.spawn("brew", ["install", "ollama"], { stdio: "inherit" });
|
|
27028
28388
|
brewChild.on("close", (code) => {
|
|
@@ -27114,15 +28474,15 @@ async function downloadOllamaModel(model) {
|
|
|
27114
28474
|
}
|
|
27115
28475
|
__name(downloadOllamaModel, "downloadOllamaModel");
|
|
27116
28476
|
async function setupEnvironmentVariables() {
|
|
27117
|
-
const homeDir =
|
|
28477
|
+
const homeDir = os3__default.default.homedir();
|
|
27118
28478
|
const shell = process.env["SHELL"] || "/bin/bash";
|
|
27119
28479
|
let rcFile = "";
|
|
27120
28480
|
if (shell.includes("zsh")) {
|
|
27121
|
-
rcFile =
|
|
28481
|
+
rcFile = path10__namespace.default.join(homeDir, ".zshrc");
|
|
27122
28482
|
} else if (shell.includes("bash")) {
|
|
27123
|
-
rcFile =
|
|
28483
|
+
rcFile = path10__namespace.default.join(homeDir, ".bashrc");
|
|
27124
28484
|
} else {
|
|
27125
|
-
rcFile =
|
|
28485
|
+
rcFile = path10__namespace.default.join(homeDir, ".profile");
|
|
27126
28486
|
}
|
|
27127
28487
|
const envVars = `
|
|
27128
28488
|
# MARIA Ollama Configuration
|
|
@@ -27181,8 +28541,8 @@ function registerSetupVllmCommand(program) {
|
|
|
27181
28541
|
if (!options.skipPythonCheck) {
|
|
27182
28542
|
await checkPythonVersion();
|
|
27183
28543
|
}
|
|
27184
|
-
const venvPath = options.venvPath.replace("~",
|
|
27185
|
-
const modelDir = options.modelDir.replace("~",
|
|
28544
|
+
const venvPath = options.venvPath.replace("~", os3__default.default.homedir());
|
|
28545
|
+
const modelDir = options.modelDir.replace("~", os3__default.default.homedir());
|
|
27186
28546
|
console.log(chalk13__default.default.yellow("\u{1F40D} Creating Python virtual environment..."));
|
|
27187
28547
|
await createVirtualEnvironment(venvPath);
|
|
27188
28548
|
console.log(chalk13__default.default.yellow("\u{1F4E6} Installing vLLM and dependencies..."));
|
|
@@ -27261,7 +28621,7 @@ async function createVirtualEnvironment(venvPath) {
|
|
|
27261
28621
|
}
|
|
27262
28622
|
__name(createVirtualEnvironment, "createVirtualEnvironment");
|
|
27263
28623
|
async function installVllm(venvPath) {
|
|
27264
|
-
const pipPath =
|
|
28624
|
+
const pipPath = path10__namespace.default.join(venvPath, "bin", "pip");
|
|
27265
28625
|
return new Promise((resolve, reject) => {
|
|
27266
28626
|
const upgradeChild = child_process.spawn(pipPath, ["install", "--upgrade", "pip"], { stdio: "inherit" });
|
|
27267
28627
|
upgradeChild.on("close", (code) => {
|
|
@@ -27285,8 +28645,8 @@ async function installVllm(venvPath) {
|
|
|
27285
28645
|
}
|
|
27286
28646
|
__name(installVllm, "installVllm");
|
|
27287
28647
|
async function downloadModel(venvPath, modelName, modelDir) {
|
|
27288
|
-
const pythonPath =
|
|
27289
|
-
const modelPath =
|
|
28648
|
+
const pythonPath = path10__namespace.default.join(venvPath, "bin", "python");
|
|
28649
|
+
const modelPath = path10__namespace.default.join(modelDir, modelName.replace("/", "_"));
|
|
27290
28650
|
return new Promise((resolve, reject) => {
|
|
27291
28651
|
console.log(chalk13__default.default.cyan(` Downloading ${modelName}...`));
|
|
27292
28652
|
const downloadScript = `
|
|
@@ -27317,9 +28677,9 @@ except Exception as e:
|
|
|
27317
28677
|
}
|
|
27318
28678
|
__name(downloadModel, "downloadModel");
|
|
27319
28679
|
async function createStartupScript(venvPath, modelDir, defaultModel) {
|
|
27320
|
-
const scriptsDir =
|
|
27321
|
-
const scriptPath =
|
|
27322
|
-
const modelPath =
|
|
28680
|
+
const scriptsDir = path10__namespace.default.join(process.cwd(), "scripts");
|
|
28681
|
+
const scriptPath = path10__namespace.default.join(scriptsDir, "start-vllm.sh");
|
|
28682
|
+
const modelPath = path10__namespace.default.join(modelDir, defaultModel.replace("/", "_"));
|
|
27323
28683
|
const scriptContent = `#!/bin/bash
|
|
27324
28684
|
|
|
27325
28685
|
# MARIA vLLM Startup Script
|
|
@@ -27380,15 +28740,15 @@ done
|
|
|
27380
28740
|
}
|
|
27381
28741
|
__name(createStartupScript, "createStartupScript");
|
|
27382
28742
|
async function setupEnvironmentVariables2() {
|
|
27383
|
-
const homeDir =
|
|
28743
|
+
const homeDir = os3__default.default.homedir();
|
|
27384
28744
|
const shell = process.env["SHELL"] || "/bin/bash";
|
|
27385
28745
|
let rcFile = "";
|
|
27386
28746
|
if (shell.includes("zsh")) {
|
|
27387
|
-
rcFile =
|
|
28747
|
+
rcFile = path10__namespace.default.join(homeDir, ".zshrc");
|
|
27388
28748
|
} else if (shell.includes("bash")) {
|
|
27389
|
-
rcFile =
|
|
28749
|
+
rcFile = path10__namespace.default.join(homeDir, ".bashrc");
|
|
27390
28750
|
} else {
|
|
27391
|
-
rcFile =
|
|
28751
|
+
rcFile = path10__namespace.default.join(homeDir, ".profile");
|
|
27392
28752
|
}
|
|
27393
28753
|
const envVars = `
|
|
27394
28754
|
# MARIA vLLM Configuration
|
|
@@ -27412,14 +28772,14 @@ export VLLM_DEFAULT_MODEL="DialoGPT-medium"
|
|
|
27412
28772
|
__name(setupEnvironmentVariables2, "setupEnvironmentVariables");
|
|
27413
28773
|
async function testVllmSetup(venvPath, modelDir, defaultModel) {
|
|
27414
28774
|
console.log(chalk13__default.default.yellow("\u{1F9EA} Testing vLLM setup..."));
|
|
27415
|
-
const pythonPath =
|
|
28775
|
+
const pythonPath = path10__namespace.default.join(venvPath, "bin", "python");
|
|
27416
28776
|
try {
|
|
27417
28777
|
await fs7.promises.access(pythonPath);
|
|
27418
28778
|
console.log(chalk13__default.default.green("\u2705 Virtual environment test passed"));
|
|
27419
28779
|
} catch (error) {
|
|
27420
28780
|
throw new Error("Virtual environment not found");
|
|
27421
28781
|
}
|
|
27422
|
-
const modelPath =
|
|
28782
|
+
const modelPath = path10__namespace.default.join(modelDir, defaultModel.replace("/", "_"));
|
|
27423
28783
|
try {
|
|
27424
28784
|
await fs7.promises.access(modelPath);
|
|
27425
28785
|
console.log(chalk13__default.default.green("\u2705 Model directory test passed"));
|
|
@@ -27460,14 +28820,14 @@ ${chalk13__default.default.cyan("Examples:")}
|
|
|
27460
28820
|
${chalk13__default.default.gray("$")} maria coderag similar "function calc()" # Find similar patterns
|
|
27461
28821
|
`
|
|
27462
28822
|
);
|
|
27463
|
-
coderagCommand.command("index").argument("<path>", "Path to codebase directory").option("--types <types>", "File types to include (comma-separated)", ".ts,.tsx,.js,.jsx").option("--exclude <paths>", "Paths to exclude (comma-separated)", "node_modules,dist,.git").option("--chunk-size <size>", "Chunk size for indexing", "500").description("Index codebase for vector search").action(async (
|
|
28823
|
+
coderagCommand.command("index").argument("<path>", "Path to codebase directory").option("--types <types>", "File types to include (comma-separated)", ".ts,.tsx,.js,.jsx").option("--exclude <paths>", "Paths to exclude (comma-separated)", "node_modules,dist,.git").option("--chunk-size <size>", "Chunk size for indexing", "500").description("Index codebase for vector search").action(async (path11, options) => {
|
|
27464
28824
|
try {
|
|
27465
28825
|
console.log(chalk13__default.default.blue("\u{1F50D} Indexing codebase for CodeRAG..."));
|
|
27466
|
-
console.log(chalk13__default.default.gray(`Path: ${
|
|
28826
|
+
console.log(chalk13__default.default.gray(`Path: ${path11}`));
|
|
27467
28827
|
const fileTypes = options.types.split(",").map((t) => t.trim());
|
|
27468
28828
|
const excludePaths = options.exclude.split(",").map((p) => p.trim());
|
|
27469
28829
|
await codeRAGService.initialize();
|
|
27470
|
-
const result = await codeRAGService.indexCodebase(
|
|
28830
|
+
const result = await codeRAGService.indexCodebase(path11, {
|
|
27471
28831
|
fileTypes,
|
|
27472
28832
|
excludePaths,
|
|
27473
28833
|
chunkSize: parseInt(options.chunkSize, 10),
|
|
@@ -27622,8 +28982,8 @@ ${chalk13__default.default.cyan("Examples:")}
|
|
|
27622
28982
|
if (status.indexedPaths.length > 0) {
|
|
27623
28983
|
console.log();
|
|
27624
28984
|
console.log(chalk13__default.default.cyan("Indexed paths:"));
|
|
27625
|
-
status.indexedPaths.forEach((
|
|
27626
|
-
console.log(` \u2022 ${
|
|
28985
|
+
status.indexedPaths.forEach((path11) => {
|
|
28986
|
+
console.log(` \u2022 ${path11}`);
|
|
27627
28987
|
});
|
|
27628
28988
|
}
|
|
27629
28989
|
} catch (error) {
|
|
@@ -28375,7 +29735,7 @@ __name(handleApprovalShow, "handleApprovalShow");
|
|
|
28375
29735
|
|
|
28376
29736
|
// package.json
|
|
28377
29737
|
var package_default = {
|
|
28378
|
-
version: "2.0.
|
|
29738
|
+
version: "2.0.5"};
|
|
28379
29739
|
|
|
28380
29740
|
// src/cli.ts
|
|
28381
29741
|
function createCLI() {
|
|
@@ -28463,7 +29823,7 @@ __name(generateCode, "generateCode");
|
|
|
28463
29823
|
async function processVision(imagePath, prompt, config2) {
|
|
28464
29824
|
const maria = new MariaAI(config2);
|
|
28465
29825
|
await maria.initialize();
|
|
28466
|
-
const
|
|
29826
|
+
const fs12 = await (async () => {
|
|
28467
29827
|
try {
|
|
28468
29828
|
return await import('fs-extra');
|
|
28469
29829
|
} catch {
|
|
@@ -28473,7 +29833,7 @@ async function processVision(imagePath, prompt, config2) {
|
|
|
28473
29833
|
})();
|
|
28474
29834
|
try {
|
|
28475
29835
|
console.log(chalk13__default.default.blue("\u{1F441}\uFE0F Analyzing image..."));
|
|
28476
|
-
const imageBuffer = await
|
|
29836
|
+
const imageBuffer = await fs12.readFile(imagePath);
|
|
28477
29837
|
const response = await maria.vision(imageBuffer, prompt);
|
|
28478
29838
|
console.log("\n" + chalk13__default.default.green(response.content));
|
|
28479
29839
|
} catch (error) {
|
|
@@ -28571,7 +29931,494 @@ async function checkHealth(options) {
|
|
|
28571
29931
|
}
|
|
28572
29932
|
__name(checkHealth, "checkHealth");
|
|
28573
29933
|
|
|
29934
|
+
// src/slash-commands/index.ts
|
|
29935
|
+
init_cjs_shims();
|
|
29936
|
+
|
|
29937
|
+
// src/slash-commands/types.ts
|
|
29938
|
+
init_cjs_shims();
|
|
29939
|
+
var CommandError = class extends Error {
|
|
29940
|
+
constructor(message, code, statusCode = 400, details) {
|
|
29941
|
+
super(message);
|
|
29942
|
+
this.code = code;
|
|
29943
|
+
this.statusCode = statusCode;
|
|
29944
|
+
this.details = details;
|
|
29945
|
+
this.name = "CommandError";
|
|
29946
|
+
}
|
|
29947
|
+
static {
|
|
29948
|
+
__name(this, "CommandError");
|
|
29949
|
+
}
|
|
29950
|
+
};
|
|
29951
|
+
|
|
29952
|
+
// src/slash-commands/index.ts
|
|
29953
|
+
init_base_command();
|
|
29954
|
+
|
|
29955
|
+
// src/slash-commands/registry.ts
|
|
29956
|
+
init_cjs_shims();
|
|
29957
|
+
init_logger();
|
|
29958
|
+
var CommandRegistry = class {
|
|
29959
|
+
static {
|
|
29960
|
+
__name(this, "CommandRegistry");
|
|
29961
|
+
}
|
|
29962
|
+
commands = /* @__PURE__ */ new Map();
|
|
29963
|
+
aliases = /* @__PURE__ */ new Map();
|
|
29964
|
+
middlewares = /* @__PURE__ */ new Map();
|
|
29965
|
+
rateLimits = /* @__PURE__ */ new Map();
|
|
29966
|
+
_initialized = false;
|
|
29967
|
+
get initialized() {
|
|
29968
|
+
return this._initialized;
|
|
29969
|
+
}
|
|
29970
|
+
set initialized(value) {
|
|
29971
|
+
this._initialized = value;
|
|
29972
|
+
}
|
|
29973
|
+
constructor() {
|
|
29974
|
+
this.setupDefaultMiddlewares();
|
|
29975
|
+
}
|
|
29976
|
+
/**
|
|
29977
|
+
* Register a command
|
|
29978
|
+
*/
|
|
29979
|
+
register(command) {
|
|
29980
|
+
if (this.commands.has(command.name)) {
|
|
29981
|
+
logger.warn(`Command ${command.name} already registered, overwriting`);
|
|
29982
|
+
}
|
|
29983
|
+
this.commands.set(command.name, command);
|
|
29984
|
+
if (command.aliases) {
|
|
29985
|
+
for (const alias of command.aliases) {
|
|
29986
|
+
if (this.aliases.has(alias)) {
|
|
29987
|
+
logger.warn(`Alias ${alias} already registered, overwriting`);
|
|
29988
|
+
}
|
|
29989
|
+
this.aliases.set(alias, command.name);
|
|
29990
|
+
}
|
|
29991
|
+
}
|
|
29992
|
+
logger.info(`Registered command: ${command.name}`);
|
|
29993
|
+
}
|
|
29994
|
+
/**
|
|
29995
|
+
* Unregister a command
|
|
29996
|
+
*/
|
|
29997
|
+
unregister(name) {
|
|
29998
|
+
const command = this.commands.get(name);
|
|
29999
|
+
if (!command) {
|
|
30000
|
+
return false;
|
|
30001
|
+
}
|
|
30002
|
+
if (command.aliases) {
|
|
30003
|
+
for (const alias of command.aliases) {
|
|
30004
|
+
this.aliases.delete(alias);
|
|
30005
|
+
}
|
|
30006
|
+
}
|
|
30007
|
+
if (command.cleanup) {
|
|
30008
|
+
command.cleanup().catch((err) => logger.error(`Error cleaning up command ${name}:`, err));
|
|
30009
|
+
}
|
|
30010
|
+
this.commands.delete(name);
|
|
30011
|
+
return true;
|
|
30012
|
+
}
|
|
30013
|
+
/**
|
|
30014
|
+
* Get a command by name or alias
|
|
30015
|
+
*/
|
|
30016
|
+
get(nameOrAlias) {
|
|
30017
|
+
const cleanName = nameOrAlias.startsWith("/") ? nameOrAlias.slice(1) : nameOrAlias;
|
|
30018
|
+
const command = this.commands.get(cleanName);
|
|
30019
|
+
if (command) {
|
|
30020
|
+
return command;
|
|
30021
|
+
}
|
|
30022
|
+
const actualName = this.aliases.get(cleanName);
|
|
30023
|
+
if (actualName) {
|
|
30024
|
+
return this.commands.get(actualName);
|
|
30025
|
+
}
|
|
30026
|
+
return void 0;
|
|
30027
|
+
}
|
|
30028
|
+
/**
|
|
30029
|
+
* Check if a command exists
|
|
30030
|
+
*/
|
|
30031
|
+
has(nameOrAlias) {
|
|
30032
|
+
return this.get(nameOrAlias) !== void 0;
|
|
30033
|
+
}
|
|
30034
|
+
/**
|
|
30035
|
+
* Get all registered commands
|
|
30036
|
+
*/
|
|
30037
|
+
getAll() {
|
|
30038
|
+
return Array.from(this.commands.values());
|
|
30039
|
+
}
|
|
30040
|
+
/**
|
|
30041
|
+
* Get commands by category
|
|
30042
|
+
*/
|
|
30043
|
+
getByCategory(category) {
|
|
30044
|
+
return this.getAll().filter((cmd) => cmd.category === category);
|
|
30045
|
+
}
|
|
30046
|
+
/**
|
|
30047
|
+
* Execute a command
|
|
30048
|
+
*/
|
|
30049
|
+
async execute(commandName, args, context) {
|
|
30050
|
+
const startTime = Date.now();
|
|
30051
|
+
try {
|
|
30052
|
+
const command = this.get(commandName);
|
|
30053
|
+
if (!command) {
|
|
30054
|
+
return {
|
|
30055
|
+
success: false,
|
|
30056
|
+
message: `Command not found: ${commandName}`,
|
|
30057
|
+
data: {
|
|
30058
|
+
suggestions: this.getSuggestions(commandName)
|
|
30059
|
+
}
|
|
30060
|
+
};
|
|
30061
|
+
}
|
|
30062
|
+
const parsedArgs = this.parseArguments(args);
|
|
30063
|
+
if (command.rateLimit) {
|
|
30064
|
+
const rateLimitResult = this.checkRateLimit(command, context);
|
|
30065
|
+
if (!rateLimitResult.success) {
|
|
30066
|
+
return rateLimitResult;
|
|
30067
|
+
}
|
|
30068
|
+
}
|
|
30069
|
+
const result = await this.runMiddlewareChain(command, parsedArgs, context, async () => {
|
|
30070
|
+
const permCheck = await this.checkPermissions(command, context);
|
|
30071
|
+
if (!permCheck.success) {
|
|
30072
|
+
return permCheck;
|
|
30073
|
+
}
|
|
30074
|
+
if (command.validate) {
|
|
30075
|
+
const validation = await command.validate(parsedArgs);
|
|
30076
|
+
if (!validation.success) {
|
|
30077
|
+
return {
|
|
30078
|
+
success: false,
|
|
30079
|
+
message: validation.error || "Validation failed",
|
|
30080
|
+
data: { suggestions: validation.suggestions }
|
|
30081
|
+
};
|
|
30082
|
+
}
|
|
30083
|
+
}
|
|
30084
|
+
const result2 = await command.execute(parsedArgs, context);
|
|
30085
|
+
result2.metadata = {
|
|
30086
|
+
...result2.metadata,
|
|
30087
|
+
executionTime: Date.now() - startTime,
|
|
30088
|
+
commandVersion: command.metadata.version
|
|
30089
|
+
};
|
|
30090
|
+
return result2;
|
|
30091
|
+
});
|
|
30092
|
+
this.logExecution(command, parsedArgs, context, result);
|
|
30093
|
+
return result;
|
|
30094
|
+
} catch (error) {
|
|
30095
|
+
if (error instanceof CommandError) {
|
|
30096
|
+
return {
|
|
30097
|
+
success: false,
|
|
30098
|
+
message: error.message,
|
|
30099
|
+
data: {
|
|
30100
|
+
code: error.code,
|
|
30101
|
+
details: error.details
|
|
30102
|
+
}
|
|
30103
|
+
};
|
|
30104
|
+
}
|
|
30105
|
+
logger.error(`Command execution error for ${commandName}:`, error);
|
|
30106
|
+
return {
|
|
30107
|
+
success: false,
|
|
30108
|
+
message: error instanceof Error ? error.message : "Command execution failed",
|
|
30109
|
+
metadata: {
|
|
30110
|
+
executionTime: Date.now() - startTime
|
|
30111
|
+
}
|
|
30112
|
+
};
|
|
30113
|
+
}
|
|
30114
|
+
}
|
|
30115
|
+
/**
|
|
30116
|
+
* Auto-register commands from directory
|
|
30117
|
+
*/
|
|
30118
|
+
async autoRegister(directory) {
|
|
30119
|
+
logger.info(`Auto-registering commands from ${directory}`);
|
|
30120
|
+
try {
|
|
30121
|
+
const pattern = path10__namespace.join(directory, "**/*.command.{ts,js}");
|
|
30122
|
+
const files = await glob.glob(pattern);
|
|
30123
|
+
logger.info(`Found ${files.length} command files`);
|
|
30124
|
+
for (const file of files) {
|
|
30125
|
+
try {
|
|
30126
|
+
const module = await import(file);
|
|
30127
|
+
if (module.default) {
|
|
30128
|
+
let command;
|
|
30129
|
+
if (typeof module.default === "function") {
|
|
30130
|
+
command = new module.default();
|
|
30131
|
+
} else {
|
|
30132
|
+
command = module.default;
|
|
30133
|
+
}
|
|
30134
|
+
if (this.isValidCommand(command)) {
|
|
30135
|
+
if (command.initialize) {
|
|
30136
|
+
await command.initialize();
|
|
30137
|
+
}
|
|
30138
|
+
this.register(command);
|
|
30139
|
+
} else {
|
|
30140
|
+
logger.warn(`Invalid command in ${file}`);
|
|
30141
|
+
}
|
|
30142
|
+
}
|
|
30143
|
+
for (const [key, value] of Object.entries(module)) {
|
|
30144
|
+
if (key !== "default" && this.isValidCommand(value)) {
|
|
30145
|
+
const command = value;
|
|
30146
|
+
if (command.initialize) {
|
|
30147
|
+
await command.initialize();
|
|
30148
|
+
}
|
|
30149
|
+
this.register(command);
|
|
30150
|
+
}
|
|
30151
|
+
}
|
|
30152
|
+
} catch (error) {
|
|
30153
|
+
logger.error(`Failed to load command from ${file}:`, error);
|
|
30154
|
+
}
|
|
30155
|
+
}
|
|
30156
|
+
this.initialized = true;
|
|
30157
|
+
logger.info(`Registered ${this.commands.size} commands total`);
|
|
30158
|
+
} catch (error) {
|
|
30159
|
+
logger.error("Auto-registration failed:", error);
|
|
30160
|
+
throw error;
|
|
30161
|
+
}
|
|
30162
|
+
}
|
|
30163
|
+
/**
|
|
30164
|
+
* Register a middleware
|
|
30165
|
+
*/
|
|
30166
|
+
registerMiddleware(middleware) {
|
|
30167
|
+
this.middlewares.set(middleware.name, middleware);
|
|
30168
|
+
logger.info(`Registered middleware: ${middleware.name}`);
|
|
30169
|
+
}
|
|
30170
|
+
// Private helper methods
|
|
30171
|
+
setupDefaultMiddlewares() {
|
|
30172
|
+
this.registerMiddleware({
|
|
30173
|
+
name: "logging",
|
|
30174
|
+
priority: 0,
|
|
30175
|
+
async execute(command, args, context, next) {
|
|
30176
|
+
logger.debug(`Executing command: ${command.name}`, {
|
|
30177
|
+
args: args.raw,
|
|
30178
|
+
user: context.user?.id
|
|
30179
|
+
});
|
|
30180
|
+
return next();
|
|
30181
|
+
}
|
|
30182
|
+
});
|
|
30183
|
+
this.registerMiddleware({
|
|
30184
|
+
name: "error-handler",
|
|
30185
|
+
priority: 1,
|
|
30186
|
+
async execute(_command, _args, _context, next) {
|
|
30187
|
+
try {
|
|
30188
|
+
return await next();
|
|
30189
|
+
} catch (error) {
|
|
30190
|
+
logger.error(`Command ${_command.name} failed:`, error);
|
|
30191
|
+
throw error;
|
|
30192
|
+
}
|
|
30193
|
+
}
|
|
30194
|
+
});
|
|
30195
|
+
}
|
|
30196
|
+
parseArguments(raw) {
|
|
30197
|
+
const args = {
|
|
30198
|
+
raw,
|
|
30199
|
+
parsed: {},
|
|
30200
|
+
flags: {},
|
|
30201
|
+
options: {}
|
|
30202
|
+
};
|
|
30203
|
+
const positional = [];
|
|
30204
|
+
for (let i = 0; i < raw.length; i++) {
|
|
30205
|
+
const arg = raw[i];
|
|
30206
|
+
if (!arg) continue;
|
|
30207
|
+
if (arg.startsWith("--")) {
|
|
30208
|
+
const key = arg.slice(2);
|
|
30209
|
+
const nextArg = raw[i + 1];
|
|
30210
|
+
if (nextArg && !nextArg.startsWith("-")) {
|
|
30211
|
+
args.options[key] = nextArg;
|
|
30212
|
+
i++;
|
|
30213
|
+
} else {
|
|
30214
|
+
args.flags[key] = true;
|
|
30215
|
+
}
|
|
30216
|
+
} else if (arg && arg.startsWith("-") && arg.length === 2) {
|
|
30217
|
+
args.flags[arg.slice(1)] = true;
|
|
30218
|
+
} else if (arg) {
|
|
30219
|
+
positional.push(arg);
|
|
30220
|
+
}
|
|
30221
|
+
}
|
|
30222
|
+
if (positional.length > 0) {
|
|
30223
|
+
args.parsed["positional"] = positional;
|
|
30224
|
+
}
|
|
30225
|
+
return args;
|
|
30226
|
+
}
|
|
30227
|
+
async checkPermissions(command, context) {
|
|
30228
|
+
if (!command.permissions) {
|
|
30229
|
+
return { success: true, message: "" };
|
|
30230
|
+
}
|
|
30231
|
+
const { requiresAuth, role } = command.permissions;
|
|
30232
|
+
if (requiresAuth && !context.user) {
|
|
30233
|
+
return {
|
|
30234
|
+
success: false,
|
|
30235
|
+
message: "Authentication required",
|
|
30236
|
+
data: { suggestions: ["Run /login to authenticate"] }
|
|
30237
|
+
};
|
|
30238
|
+
}
|
|
30239
|
+
if (role && context.user?.role !== role) {
|
|
30240
|
+
return {
|
|
30241
|
+
success: false,
|
|
30242
|
+
message: `Insufficient permissions. Required role: ${role}`
|
|
30243
|
+
};
|
|
30244
|
+
}
|
|
30245
|
+
return { success: true, message: "" };
|
|
30246
|
+
}
|
|
30247
|
+
checkRateLimit(command, context) {
|
|
30248
|
+
if (!command.rateLimit) {
|
|
30249
|
+
return { success: true, message: "" };
|
|
30250
|
+
}
|
|
30251
|
+
const userId = context.user?.id || "anonymous";
|
|
30252
|
+
const commandLimits = this.rateLimits.get(command.name) || /* @__PURE__ */ new Map();
|
|
30253
|
+
const userLimit = commandLimits.get(userId);
|
|
30254
|
+
const now = Date.now();
|
|
30255
|
+
const windowMs = this.parseWindow(command.rateLimit.window);
|
|
30256
|
+
if (!userLimit || userLimit.resetAt < now) {
|
|
30257
|
+
commandLimits.set(userId, {
|
|
30258
|
+
count: 1,
|
|
30259
|
+
resetAt: now + windowMs
|
|
30260
|
+
});
|
|
30261
|
+
this.rateLimits.set(command.name, commandLimits);
|
|
30262
|
+
return { success: true, message: "" };
|
|
30263
|
+
}
|
|
30264
|
+
if (userLimit.count >= command.rateLimit.requests) {
|
|
30265
|
+
const retryAfter = Math.ceil((userLimit.resetAt - now) / 1e3);
|
|
30266
|
+
return {
|
|
30267
|
+
success: false,
|
|
30268
|
+
message: `Rate limit exceeded. Try again in ${retryAfter} seconds`,
|
|
30269
|
+
data: { retryAfter }
|
|
30270
|
+
};
|
|
30271
|
+
}
|
|
30272
|
+
userLimit.count++;
|
|
30273
|
+
return { success: true, message: "" };
|
|
30274
|
+
}
|
|
30275
|
+
parseWindow(window) {
|
|
30276
|
+
const match = window.match(/^(\d+)([smhd])$/);
|
|
30277
|
+
if (!match) {
|
|
30278
|
+
return 6e4;
|
|
30279
|
+
}
|
|
30280
|
+
const [, num, unit] = match;
|
|
30281
|
+
const value = parseInt(num || "60", 10);
|
|
30282
|
+
switch (unit) {
|
|
30283
|
+
case "s":
|
|
30284
|
+
return value * 1e3;
|
|
30285
|
+
case "m":
|
|
30286
|
+
return value * 60 * 1e3;
|
|
30287
|
+
case "h":
|
|
30288
|
+
return value * 60 * 60 * 1e3;
|
|
30289
|
+
case "d":
|
|
30290
|
+
return value * 24 * 60 * 60 * 1e3;
|
|
30291
|
+
default:
|
|
30292
|
+
return 6e4;
|
|
30293
|
+
}
|
|
30294
|
+
}
|
|
30295
|
+
async runMiddlewareChain(command, args, context, execute) {
|
|
30296
|
+
const middlewareNames = command.middleware || [];
|
|
30297
|
+
const middlewares = middlewareNames.map((name) => this.middlewares.get(name)).filter(Boolean);
|
|
30298
|
+
middlewares.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
30299
|
+
let index = 0;
|
|
30300
|
+
const next = /* @__PURE__ */ __name(async () => {
|
|
30301
|
+
if (index < middlewares.length) {
|
|
30302
|
+
const middleware = middlewares[index++];
|
|
30303
|
+
return middleware ? middleware.execute(command, args, context, next) : execute();
|
|
30304
|
+
}
|
|
30305
|
+
return execute();
|
|
30306
|
+
}, "next");
|
|
30307
|
+
return next();
|
|
30308
|
+
}
|
|
30309
|
+
getSuggestions(input) {
|
|
30310
|
+
const suggestions = [];
|
|
30311
|
+
const cleanInput = input.replace("/", "").toLowerCase();
|
|
30312
|
+
for (const [name] of this.commands) {
|
|
30313
|
+
if (name.toLowerCase().includes(cleanInput) || cleanInput.includes(name.toLowerCase())) {
|
|
30314
|
+
suggestions.push(`/${name}`);
|
|
30315
|
+
}
|
|
30316
|
+
}
|
|
30317
|
+
for (const [alias] of this.aliases) {
|
|
30318
|
+
if (alias.toLowerCase().includes(cleanInput) || cleanInput.includes(alias.toLowerCase())) {
|
|
30319
|
+
suggestions.push(`/${alias}`);
|
|
30320
|
+
}
|
|
30321
|
+
}
|
|
30322
|
+
return suggestions.slice(0, 5);
|
|
30323
|
+
}
|
|
30324
|
+
isValidCommand(obj) {
|
|
30325
|
+
if (!obj || typeof obj !== "object") {
|
|
30326
|
+
return false;
|
|
30327
|
+
}
|
|
30328
|
+
const cmd = obj;
|
|
30329
|
+
return typeof cmd.name === "string" && typeof cmd.category === "string" && typeof cmd.description === "string" && typeof cmd.execute === "function";
|
|
30330
|
+
}
|
|
30331
|
+
logExecution(command, args, context, result) {
|
|
30332
|
+
const logData = {
|
|
30333
|
+
command: command.name,
|
|
30334
|
+
args: args.raw,
|
|
30335
|
+
user: context.user?.id,
|
|
30336
|
+
success: result.success,
|
|
30337
|
+
executionTime: result.metadata?.executionTime
|
|
30338
|
+
};
|
|
30339
|
+
if (result.success) {
|
|
30340
|
+
logger.info("Command executed", logData);
|
|
30341
|
+
} else {
|
|
30342
|
+
logger.error("Command failed", { ...logData, error: result.message });
|
|
30343
|
+
}
|
|
30344
|
+
}
|
|
30345
|
+
};
|
|
30346
|
+
var commandRegistry = new CommandRegistry();
|
|
30347
|
+
|
|
30348
|
+
// src/slash-commands/index.ts
|
|
30349
|
+
init_auth();
|
|
30350
|
+
init_validation();
|
|
30351
|
+
init_rate_limit();
|
|
30352
|
+
init_logging();
|
|
30353
|
+
init_clear_command();
|
|
30354
|
+
async function initializeSlashCommands() {
|
|
30355
|
+
const { authMiddleware: authMiddleware2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
|
|
30356
|
+
const { validationMiddleware: validationMiddleware2 } = await Promise.resolve().then(() => (init_validation(), validation_exports));
|
|
30357
|
+
const { rateLimitMiddleware: rateLimitMiddleware2 } = await Promise.resolve().then(() => (init_rate_limit(), rate_limit_exports));
|
|
30358
|
+
const { loggingMiddleware: loggingMiddleware2 } = await Promise.resolve().then(() => (init_logging(), logging_exports));
|
|
30359
|
+
commandRegistry.registerMiddleware(loggingMiddleware2);
|
|
30360
|
+
commandRegistry.registerMiddleware(authMiddleware2);
|
|
30361
|
+
commandRegistry.registerMiddleware(rateLimitMiddleware2);
|
|
30362
|
+
commandRegistry.registerMiddleware(validationMiddleware2);
|
|
30363
|
+
await registerBuiltInCommands();
|
|
30364
|
+
console.log(`\u2705 Initialized ${commandRegistry.getAll().length} slash commands`);
|
|
30365
|
+
}
|
|
30366
|
+
__name(initializeSlashCommands, "initializeSlashCommands");
|
|
30367
|
+
async function registerBuiltInCommands() {
|
|
30368
|
+
try {
|
|
30369
|
+
const { ClearCommand: ClearCommand2 } = await Promise.resolve().then(() => (init_clear_command(), clear_command_exports));
|
|
30370
|
+
const clearCommand = new ClearCommand2();
|
|
30371
|
+
if (clearCommand.initialize) {
|
|
30372
|
+
await clearCommand.initialize();
|
|
30373
|
+
}
|
|
30374
|
+
commandRegistry.register(clearCommand);
|
|
30375
|
+
const setupCommandModule = await Promise.resolve().then(() => (init_setup_command(), setup_command_exports));
|
|
30376
|
+
const setupCommand = setupCommandModule.default;
|
|
30377
|
+
if (setupCommand) {
|
|
30378
|
+
if (setupCommand.initialize) {
|
|
30379
|
+
await setupCommand.initialize();
|
|
30380
|
+
}
|
|
30381
|
+
commandRegistry.register(setupCommand);
|
|
30382
|
+
}
|
|
30383
|
+
} catch (error) {
|
|
30384
|
+
console.error("Failed to register built-in commands:", error);
|
|
30385
|
+
}
|
|
30386
|
+
}
|
|
30387
|
+
__name(registerBuiltInCommands, "registerBuiltInCommands");
|
|
30388
|
+
function getCommandSuggestions(input) {
|
|
30389
|
+
const commands = commandRegistry.getAll();
|
|
30390
|
+
const suggestions = [];
|
|
30391
|
+
const cleanInput = input.replace("/", "").toLowerCase();
|
|
30392
|
+
for (const command of commands) {
|
|
30393
|
+
if (command.name.toLowerCase().startsWith(cleanInput)) {
|
|
30394
|
+
suggestions.push(`/${command.name}`);
|
|
30395
|
+
}
|
|
30396
|
+
if (command.aliases) {
|
|
30397
|
+
for (const alias of command.aliases) {
|
|
30398
|
+
if (alias.toLowerCase().startsWith(cleanInput)) {
|
|
30399
|
+
suggestions.push(`/${alias}`);
|
|
30400
|
+
}
|
|
30401
|
+
}
|
|
30402
|
+
}
|
|
30403
|
+
}
|
|
30404
|
+
return suggestions.slice(0, 10);
|
|
30405
|
+
}
|
|
30406
|
+
__name(getCommandSuggestions, "getCommandSuggestions");
|
|
30407
|
+
function getCommandsByCategory2() {
|
|
30408
|
+
const commands = commandRegistry.getAll();
|
|
30409
|
+
const grouped = {};
|
|
30410
|
+
for (const command of commands) {
|
|
30411
|
+
if (!grouped[command.category]) {
|
|
30412
|
+
grouped[command.category] = [];
|
|
30413
|
+
}
|
|
30414
|
+
grouped[command.category].push(command);
|
|
30415
|
+
}
|
|
30416
|
+
return grouped;
|
|
30417
|
+
}
|
|
30418
|
+
__name(getCommandsByCategory2, "getCommandsByCategory");
|
|
30419
|
+
|
|
28574
30420
|
// src/index.ts
|
|
30421
|
+
init_base_command();
|
|
28575
30422
|
var VERSION = "1.1.0";
|
|
28576
30423
|
|
|
28577
30424
|
exports.DualMemoryEngine = DualMemoryEngine;
|
|
@@ -28580,7 +30427,11 @@ exports.MemoryCoordinator = MemoryCoordinator;
|
|
|
28580
30427
|
exports.System1Memory = System1MemoryManager;
|
|
28581
30428
|
exports.System2Memory = System2MemoryManager;
|
|
28582
30429
|
exports.VERSION = VERSION;
|
|
30430
|
+
exports.commandRegistry = commandRegistry;
|
|
28583
30431
|
exports.createCLI = createCLI;
|
|
30432
|
+
exports.getCommandSuggestions = getCommandSuggestions;
|
|
30433
|
+
exports.getCommandsByCategory = getCommandsByCategory2;
|
|
28584
30434
|
exports.getInternalModeService = getInternalModeService2;
|
|
30435
|
+
exports.initializeSlashCommands = initializeSlashCommands;
|
|
28585
30436
|
//# sourceMappingURL=index.js.map
|
|
28586
30437
|
//# sourceMappingURL=index.js.map
|