104 lines
4.1 KiB
JavaScript
104 lines
4.1 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.AmazonQCliAgent = void 0;
|
|
const path = __importStar(require("path"));
|
|
const fs_1 = require("fs");
|
|
const FileSystemUtils_1 = require("../core/FileSystemUtils");
|
|
const merge_1 = require("../mcp/merge");
|
|
/**
|
|
* Amazon Q CLI agent adapter.
|
|
*/
|
|
class AmazonQCliAgent {
|
|
getIdentifier() {
|
|
return 'amazonqcli';
|
|
}
|
|
getName() {
|
|
return 'Amazon Q CLI';
|
|
}
|
|
async applyRulerConfig(concatenatedRules, projectRoot, rulerMcpJson, agentConfig, backup = true) {
|
|
const outputPaths = this.getDefaultOutputPath(projectRoot);
|
|
const rulesPath = path.resolve(projectRoot, agentConfig?.outputPath ||
|
|
agentConfig?.outputPathInstructions ||
|
|
outputPaths['instructions']);
|
|
// Write rules file to .amazonq/rules/
|
|
await (0, FileSystemUtils_1.ensureDirExists)(path.dirname(rulesPath));
|
|
if (backup) {
|
|
await (0, FileSystemUtils_1.backupFile)(rulesPath);
|
|
}
|
|
await (0, FileSystemUtils_1.writeGeneratedFile)(rulesPath, concatenatedRules);
|
|
// Handle MCP configuration if enabled and provided
|
|
const mcpEnabled = agentConfig?.mcp?.enabled ?? true;
|
|
if (mcpEnabled && rulerMcpJson) {
|
|
const mcpPath = path.resolve(projectRoot, agentConfig?.outputPathConfig ?? outputPaths['mcp']);
|
|
const mcpStrategy = agentConfig?.mcp?.strategy ?? 'merge';
|
|
await (0, FileSystemUtils_1.ensureDirExists)(path.dirname(mcpPath));
|
|
let existingMcpConfig = {};
|
|
try {
|
|
const raw = await fs_1.promises.readFile(mcpPath, 'utf8');
|
|
existingMcpConfig = JSON.parse(raw);
|
|
}
|
|
catch (err) {
|
|
if (err.code !== 'ENOENT') {
|
|
throw err;
|
|
}
|
|
// File doesn't exist, start with empty config
|
|
}
|
|
// Merge the MCP configurations using the standard merge function
|
|
const mergedConfig = (0, merge_1.mergeMcp)(existingMcpConfig, rulerMcpJson, mcpStrategy, 'mcpServers');
|
|
if (backup) {
|
|
await (0, FileSystemUtils_1.backupFile)(mcpPath);
|
|
}
|
|
await (0, FileSystemUtils_1.writeGeneratedFile)(mcpPath, JSON.stringify(mergedConfig, null, 2));
|
|
}
|
|
}
|
|
getDefaultOutputPath(projectRoot) {
|
|
return {
|
|
instructions: path.join(projectRoot, '.amazonq', 'rules', 'ruler_q_rules.md'),
|
|
mcp: path.join(projectRoot, '.amazonq', 'mcp.json'),
|
|
};
|
|
}
|
|
getMcpServerKey() {
|
|
return 'mcpServers';
|
|
}
|
|
supportsMcpStdio() {
|
|
return true;
|
|
}
|
|
supportsMcpRemote() {
|
|
return true;
|
|
}
|
|
}
|
|
exports.AmazonQCliAgent = AmazonQCliAgent;
|