@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
104 lines • 4.93 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.containerLogsCommand = containerLogsCommand;
const node_child_process_1 = require("node:child_process");
const checkDockerAvailable_1 = require("../utils/docker/checkDockerAvailable");
const getContainerName_1 = require("../utils/docker/getContainerName");
const getContainerStatus_1 = require("../utils/docker/getContainerStatus");
const logger_1 = require("../utils/logger");
function processLogLine(trimmedLine, tokenLineBuffer) {
if (!trimmedLine)
return false;
// In JSON mode, use special filtering logic
if (global.log_as_json) {
if (trimmedLine.startsWith('[aidev]')) {
// Before outputting [aidev] line, flush any buffered token line
if (tokenLineBuffer.current) {
(0, logger_1.log)(`Running Claude Code: ${tokenLineBuffer.current}`, 'info');
tokenLineBuffer.current = null;
}
// Output the [aidev] line
(0, logger_1.log)(trimmedLine, 'info');
return true;
}
else if (trimmedLine.includes('tokens')) {
// Buffer this token line - it will be output before the next [aidev] line
tokenLineBuffer.current = trimmedLine;
return false;
}
return false;
}
// Normal mode: output everything
(0, logger_1.log)(trimmedLine, 'info');
return true;
}
function processOutputLines(output, isJsonMode) {
const outputLines = output.split('\n');
const tokenLineBuffer = { current: null };
for (const line of outputLines) {
processLogLine(line.trim(), tokenLineBuffer);
}
// Flush any remaining token line at the end
if (isJsonMode && tokenLineBuffer.current) {
(0, logger_1.log)(`Running Claude Code: ${tokenLineBuffer.current}`, 'info');
}
}
function containerLogsCommand(options) {
return __awaiter(this, void 0, void 0, function* () {
const { name, lines = 50 } = options;
try {
// Check Docker availability
const docker = yield (0, checkDockerAvailable_1.checkDockerAvailable)();
if (!docker.available) {
(0, logger_1.log)(docker.error || 'Docker is not available', 'error');
throw new Error('Docker is required to view container logs');
}
const containerName = (0, getContainerName_1.getContainerName)(name);
// Check if container exists
const status = yield (0, getContainerStatus_1.getContainerStatus)(containerName);
if (!status) {
(0, logger_1.log)(`Container ${containerName} not found`, 'error');
throw new Error(`Container ${containerName} does not exist`);
}
(0, logger_1.log)(`Showing logs for ${containerName}:`, 'info');
(0, logger_1.log)('─'.repeat(50), 'info');
// For non-follow mode, use execSync to get complete output at once
const args = ['logs', '--tail', String(lines), containerName];
try {
const output = (0, node_child_process_1.execSync)(`docker ${args.join(' ')}`, {
encoding: 'utf8',
maxBuffer: 10 * 1024 * 1024 // 10MB buffer
});
// Process complete lines
processOutputLines(output, global.log_as_json);
}
catch (error) {
// execSync throws if there's stderr output or non-zero exit
if (error.stdout)
processOutputLines(error.stdout, global.log_as_json);
if (error.stderr) {
const errorLines = error.stderr.split('\n');
errorLines.forEach((line) => {
if (line.trim()) {
(0, logger_1.log)(line, 'error');
}
});
}
}
}
catch (error) {
(0, logger_1.log)(`Failed to get container logs: ${error instanceof Error ? error.message : String(error)}`, 'error');
throw error;
}
});
}
//# sourceMappingURL=containerLogsCommand.js.map