ai-cli-log 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +26 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -49,16 +49,18 @@ if (!fs.existsSync(logsDir)) {
49
49
  fs.mkdirSync(logsDir);
50
50
  }
51
51
  // Initialize xterm.js in headless mode
52
+ const defaultRows = 24;
53
+ const defaultCols = 80;
52
54
  const xterm = new headless_1.Terminal({
53
- rows: process.stdout.rows,
54
- cols: process.stdout.columns,
55
+ rows: process.stdout.rows || defaultRows,
56
+ cols: process.stdout.columns || defaultCols,
55
57
  scrollback: Infinity, // Set scrollback to Infinity for unlimited buffer
56
58
  allowProposedApi: true,
57
59
  });
58
60
  const term = pty.spawn(command, commandArgs, {
59
61
  name: 'xterm-color',
60
- cols: process.stdout.columns,
61
- rows: process.stdout.rows,
62
+ cols: process.stdout.columns || defaultCols,
63
+ rows: process.stdout.rows || defaultRows,
62
64
  cwd: process.cwd(),
63
65
  env: process.env,
64
66
  });
@@ -68,26 +70,32 @@ term.onData((data) => {
68
70
  xterm.write(data);
69
71
  });
70
72
  // Pipe stdin to pty
71
- process.stdin.on('data', (data) => {
72
- term.write(data.toString());
73
- });
74
- process.stdin.setRawMode(true);
75
- process.stdin.resume();
73
+ if (process.stdin.isTTY) {
74
+ process.stdin.on('data', (data) => {
75
+ term.write(data.toString());
76
+ });
77
+ process.stdin.setRawMode(true);
78
+ process.stdin.resume();
79
+ }
76
80
  term.onExit(({ exitCode, signal }) => {
77
81
  // Add a small delay to ensure xterm.js has processed all output
78
82
  setTimeout(() => {
79
83
  // Extract rendered text from xterm.js buffer
80
- let renderedOutput = '';
84
+ let renderedOutputLines = [];
81
85
  // Iterate over the entire buffer, including scrollback.
82
86
  // The total number of lines is the sum of lines in scrollback (baseY) and visible rows.
83
87
  for (let i = 0; i < xterm.buffer.active.baseY + xterm.rows; i++) {
84
88
  const line = xterm.buffer.active.getLine(i);
85
89
  if (line) {
86
90
  // translateToString(true) gets the line content, and we trim trailing whitespace.
87
- const lineText = line.translateToString(true).replace(/\s+$/, '');
88
- renderedOutput += lineText + '\n';
91
+ renderedOutputLines.push(line.translateToString(true));
89
92
  }
90
93
  }
94
+ // Remove trailing blank lines
95
+ while (renderedOutputLines.length > 0 && renderedOutputLines[renderedOutputLines.length - 1].trim() === '') {
96
+ renderedOutputLines.pop();
97
+ }
98
+ const renderedOutput = renderedOutputLines.join('\n');
91
99
  const now = new Date();
92
100
  const year = now.getFullYear();
93
101
  const month = (now.getMonth() + 1).toString().padStart(2, '0');
@@ -96,8 +104,13 @@ term.onExit(({ exitCode, signal }) => {
96
104
  const minutes = now.getMinutes().toString().padStart(2, '0');
97
105
  const seconds = now.getSeconds().toString().padStart(2, '0');
98
106
  const prefix = command || 'session';
99
- const logFileName = `${prefix}-${year}${month}${day}-${hours}${minutes}${seconds}.md`;
107
+ const logFileName = `${prefix}-${year}${month}${day}-${hours}${minutes}${seconds}.txt`;
100
108
  const logFilePath = path.join(logsDir, logFileName);
109
+ if (renderedOutput.trim().length === 0) {
110
+ console.log('Session had no output, not saving log file.');
111
+ process.exit(exitCode);
112
+ return;
113
+ }
101
114
  fs.writeFile(logFilePath, renderedOutput, (err) => {
102
115
  if (err) {
103
116
  console.error('Error writing log file:', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-cli-log",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Seamlessly log your AI-powered coding conversations. This command-line interface (CLI) tool captures your terminal interactions with AI models like Gemini and Claude, saving entire sessions as clean plain text documents for easy review and documentation.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {