maiass 5.9.18 → 5.9.19
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/lib/commit.js +10 -7
- package/lib/logger.js +72 -13
- package/lib/machine-fingerprint.js +2 -2
- package/package.json +1 -1
package/lib/commit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Commit functionality for MAIASS - port of maiass.sh commit behavior
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
|
-
import { log } from './logger.js';
|
|
3
|
+
import { log, redact } from './logger.js';
|
|
4
4
|
import { SYMBOLS } from './symbols.js';
|
|
5
5
|
import { getGitInfo, getGitStatus } from './git-info.js';
|
|
6
6
|
import readline from 'readline';
|
|
@@ -171,7 +171,7 @@ async function createAnonymousSubscriptionIfNeeded() {
|
|
|
171
171
|
|
|
172
172
|
if (debugMode) {
|
|
173
173
|
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Creating anonymous subscription at: ${endpoint}/v1/token`);
|
|
174
|
-
log.
|
|
174
|
+
log.trace(SYMBOLS.INFO, `[MAIASS TRACE] Machine fingerprint: ${JSON.stringify(machineFingerprint, null, 2)}`);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
log.info(SYMBOLS.INFO, 'Requesting anonymous subscription...');
|
|
@@ -209,7 +209,8 @@ async function createAnonymousSubscriptionIfNeeded() {
|
|
|
209
209
|
const data = await response.json();
|
|
210
210
|
|
|
211
211
|
if (debugMode) {
|
|
212
|
-
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Anonymous subscription
|
|
212
|
+
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Anonymous subscription: api_key=${redact(data.apiKey || data.api_key || data.token)}, credits=${data.creditsRemaining || data.credits_remaining || data.credits}`);
|
|
213
|
+
log.trace(SYMBOLS.INFO, `[MAIASS TRACE] Anonymous subscription response: ${JSON.stringify(data, null, 2)}`);
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
// Extract fields - try multiple field names for compatibility
|
|
@@ -294,7 +295,7 @@ async function getAICommitSuggestion(gitInfo) {
|
|
|
294
295
|
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] AI Endpoint: ${aiEndpoint}`);
|
|
295
296
|
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Token available: ${maiassToken ? 'Yes' : 'No'}`);
|
|
296
297
|
if (maiassToken) {
|
|
297
|
-
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Token
|
|
298
|
+
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Token: ${redact(maiassToken)}`);
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
|
|
@@ -416,7 +417,8 @@ ${gitDiff}`;
|
|
|
416
417
|
if (debugMode) {
|
|
417
418
|
log.debug(SYMBOLS.INFO, '[MAIASS DEBUG] --- Making AI API Request ---');
|
|
418
419
|
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Request URL: ${aiEndpoint}`);
|
|
419
|
-
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Request
|
|
420
|
+
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Request model=${requestBody.model} max_tokens=${requestBody.max_tokens}`);
|
|
421
|
+
log.trace(SYMBOLS.INFO, `[MAIASS TRACE] Request body: ${JSON.stringify(requestBody, null, 2)}`);
|
|
420
422
|
}
|
|
421
423
|
|
|
422
424
|
// Set timeout for API call (default 30 seconds)
|
|
@@ -456,7 +458,7 @@ ${gitDiff}`;
|
|
|
456
458
|
|
|
457
459
|
if (debugMode) {
|
|
458
460
|
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Response status: ${response.status} ${response.statusText}`);
|
|
459
|
-
log.
|
|
461
|
+
log.trace(SYMBOLS.INFO, `[MAIASS TRACE] Response headers: ${JSON.stringify(Object.fromEntries(response.headers), null, 2)}`);
|
|
460
462
|
}
|
|
461
463
|
|
|
462
464
|
if (!response.ok) {
|
|
@@ -472,7 +474,8 @@ ${gitDiff}`;
|
|
|
472
474
|
const data = await response.json();
|
|
473
475
|
|
|
474
476
|
if (debugMode) {
|
|
475
|
-
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Response
|
|
477
|
+
log.debug(SYMBOLS.INFO, `[MAIASS DEBUG] Response status: ${data.choices?.length || 0} choices, model=${data.model || 'unknown'}`);
|
|
478
|
+
log.trace(SYMBOLS.INFO, `[MAIASS TRACE] Response data: ${JSON.stringify(data, null, 2)}`);
|
|
476
479
|
}
|
|
477
480
|
|
|
478
481
|
if (data.choices && data.choices.length > 0) {
|
package/lib/logger.js
CHANGED
|
@@ -12,6 +12,60 @@ let env = {};
|
|
|
12
12
|
let debugBuffer = [];
|
|
13
13
|
let sessionId = null;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Get the effective verbosity level, accounting for MAIASS_DEBUG
|
|
17
|
+
* @returns {string} 'brief' | 'normal' | 'verbose' | 'debug' | 'trace'
|
|
18
|
+
*/
|
|
19
|
+
function getVerbosity() {
|
|
20
|
+
return env.MAIASS_VERBOSITY || process.env.MAIASS_VERBOSITY || 'brief';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Check if trace mode is active (MAIASS_VERBOSITY=trace)
|
|
25
|
+
* Trace-level output goes to the log file only, never stdout/stderr.
|
|
26
|
+
*/
|
|
27
|
+
function isTrace() {
|
|
28
|
+
return getVerbosity() === 'trace';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check if debug mode is active (MAIASS_DEBUG=true, or verbosity is debug/trace)
|
|
33
|
+
*/
|
|
34
|
+
function isDebug() {
|
|
35
|
+
if (env.MAIASS_DEBUG === 'true' || env.MAIASS_DEBUG === true ||
|
|
36
|
+
process.env.MAIASS_DEBUG === 'true' || process.env.MAIASS_DEBUG === true) return true;
|
|
37
|
+
const v = getVerbosity();
|
|
38
|
+
return v === 'debug' || v === 'trace';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Redact a sensitive value for safe display.
|
|
43
|
+
* "anon_b5bf3eb9-26b9-4c67-99c3-4fd1737ef6a4" → "anon_b5b...a4"
|
|
44
|
+
*/
|
|
45
|
+
export function redact(value) {
|
|
46
|
+
if (value == null) return 'null';
|
|
47
|
+
const s = String(value);
|
|
48
|
+
if (s.length <= 8) return '***';
|
|
49
|
+
return `${s.slice(0, 8)}...${s.slice(-2)}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Write a message to maiass.log (append).
|
|
54
|
+
* Respects MAIASS_LOGGING and MAIASS_LOG_FILE.
|
|
55
|
+
*/
|
|
56
|
+
function writeToLogFile(message) {
|
|
57
|
+
const loggingEnabled = env.MAIASS_LOGGING || process.env.MAIASS_LOGGING;
|
|
58
|
+
if (loggingEnabled !== 'true' && loggingEnabled !== true) return;
|
|
59
|
+
|
|
60
|
+
const logFile = env.MAIASS_LOG_FILE || process.env.MAIASS_LOG_FILE || 'maiass.log';
|
|
61
|
+
try {
|
|
62
|
+
const timestamp = new Date().toISOString().replace('T', ' ').replace(/\.\d+Z$/, '');
|
|
63
|
+
fs.appendFileSync(logFile, `[${timestamp}] ${message}\n`);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// Silently ignore log write failures
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
15
69
|
/**
|
|
16
70
|
* Initialize debug collection session
|
|
17
71
|
*/
|
|
@@ -86,7 +140,7 @@ export function initLogger(environment) {
|
|
|
86
140
|
* @returns {boolean} - Whether to show the message
|
|
87
141
|
*/
|
|
88
142
|
function shouldLog(level) {
|
|
89
|
-
const verbosity =
|
|
143
|
+
const verbosity = getVerbosity();
|
|
90
144
|
|
|
91
145
|
// Always show errors, prompts, and critical messages
|
|
92
146
|
if (['error', 'critical', 'prompt'].includes(level)) return true;
|
|
@@ -101,8 +155,8 @@ function shouldLog(level) {
|
|
|
101
155
|
return ['error', 'warning', 'success', 'info', 'critical', 'prompt'].includes(level);
|
|
102
156
|
}
|
|
103
157
|
|
|
104
|
-
// For verbose/debug: show everything
|
|
105
|
-
if (verbosity === 'verbose' || verbosity === 'debug') {
|
|
158
|
+
// For verbose/debug/trace: show everything
|
|
159
|
+
if (verbosity === 'verbose' || verbosity === 'debug' || verbosity === 'trace') {
|
|
106
160
|
return true;
|
|
107
161
|
}
|
|
108
162
|
|
|
@@ -209,34 +263,39 @@ export const log = {
|
|
|
209
263
|
console.log(colorFn(message));
|
|
210
264
|
},
|
|
211
265
|
|
|
212
|
-
// debug message (with MAIASS branding)
|
|
266
|
+
// debug message (with MAIASS branding) — shown on stderr, redacted
|
|
213
267
|
debug: (label, data) => {
|
|
214
|
-
|
|
215
|
-
process.env.MAIASS_DEBUG === 'true' || process.env.MAIASS_DEBUG === true;
|
|
216
|
-
if (!debugEnabled) return;
|
|
268
|
+
if (!isDebug()) return;
|
|
217
269
|
|
|
218
270
|
const timestamp = new Date().toISOString();
|
|
219
271
|
const debugPrefix = colors.BSoftPink('|)) ') + colors.Blue('🐛 ');
|
|
220
272
|
const timestampStr = colors.Gray(`[${timestamp}]`);
|
|
221
273
|
|
|
222
|
-
// Ensure we're writing to stderr to avoid mixing with other output
|
|
223
274
|
const output = process.stderr;
|
|
224
|
-
|
|
225
|
-
// Write the debug message header
|
|
226
275
|
output.write(`${debugPrefix} ${timestampStr} ${colors.Blue(label)}\n`);
|
|
227
276
|
|
|
228
|
-
// If we have data, pretty-print it with 2-space indentation
|
|
229
277
|
if (data !== undefined) {
|
|
230
278
|
const jsonStr = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
|
|
231
|
-
// Split into lines and indent each line
|
|
232
279
|
const lines = jsonStr.split('\n');
|
|
233
280
|
for (const line of lines) {
|
|
234
281
|
output.write(` ${colors.Gray(line)}\n`);
|
|
235
282
|
}
|
|
236
283
|
}
|
|
237
284
|
|
|
238
|
-
// Ensure everything is flushed
|
|
239
285
|
output.write('');
|
|
286
|
+
|
|
287
|
+
// Also write to log file (unredacted) if logging is enabled
|
|
288
|
+
const dataStr = data !== undefined ? (typeof data === 'string' ? data : JSON.stringify(data)) : '';
|
|
289
|
+
writeToLogFile(`DEBUG: ${label} ${dataStr}`);
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
// trace message — log file ONLY, never stdout/stderr.
|
|
293
|
+
// Use for full API responses, .env dumps, fingerprint details, etc.
|
|
294
|
+
trace: (label, data) => {
|
|
295
|
+
if (!isTrace()) return;
|
|
296
|
+
|
|
297
|
+
const dataStr = data !== undefined ? (typeof data === 'string' ? data : JSON.stringify(data, null, 2)) : '';
|
|
298
|
+
writeToLogFile(`TRACE: ${label} ${dataStr}`);
|
|
240
299
|
},
|
|
241
300
|
|
|
242
301
|
// Indented with arrow (for config values, etc.)
|
|
@@ -156,7 +156,7 @@ export function generateMachineFingerprintV1() {
|
|
|
156
156
|
|
|
157
157
|
const hash = crypto.createHash('sha256').update(fingerprintInput).digest('hex');
|
|
158
158
|
|
|
159
|
-
logger.
|
|
159
|
+
logger.trace('Machine fingerprint V1 components:', {
|
|
160
160
|
mac: mac,
|
|
161
161
|
cpu: cpu,
|
|
162
162
|
disk: disk,
|
|
@@ -193,7 +193,7 @@ export function generateMachineFingerprint() {
|
|
|
193
193
|
// Generate SHA-256 hash in hex format to match bashmaiass
|
|
194
194
|
const hash = crypto.createHash('sha256').update(fingerprintInput).digest('hex');
|
|
195
195
|
|
|
196
|
-
logger.
|
|
196
|
+
logger.trace('Machine fingerprint V2 components:', {
|
|
197
197
|
mac: mac,
|
|
198
198
|
cpu: cpu,
|
|
199
199
|
disk: disk,
|