@compilr-dev/sdk 0.10.8 → 0.10.9
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/dist/compressors/bash.js +223 -0
- package/dist/detection/common.js +13 -2
- package/package.json +1 -1
package/dist/compressors/bash.js
CHANGED
|
@@ -40,6 +40,27 @@ export function compressBashOutput(command, stdout) {
|
|
|
40
40
|
// curl / wget (HTTP responses)
|
|
41
41
|
if (cmd.match(/^(curl|wget)\b/))
|
|
42
42
|
return compressCurlOutput(stdout);
|
|
43
|
+
// GitHub CLI (verbose detail commands — pr/issue view, run view)
|
|
44
|
+
// List commands (pr list, issue list, run list) are already tabular and compact;
|
|
45
|
+
// pass them through unchanged.
|
|
46
|
+
if (cmd.match(/^gh\s+(pr|issue|run)\s+view\b/))
|
|
47
|
+
return compressGhView(stdout);
|
|
48
|
+
// Docker
|
|
49
|
+
// `docker logs` — cap to last N lines (logs blow up the context fast)
|
|
50
|
+
if (cmd.match(/^docker\s+logs\b/))
|
|
51
|
+
return compressLogsOutput(stdout);
|
|
52
|
+
// `docker pull/push/build` — strip noisy progress lines, keep summary
|
|
53
|
+
if (cmd.match(/^docker\s+(pull|push|build)\b/))
|
|
54
|
+
return compressDockerProgress(stdout);
|
|
55
|
+
// `docker ps`, `docker images`, `docker stats` — already tabular and compact, pass through
|
|
56
|
+
// kubectl
|
|
57
|
+
// `kubectl logs` — same as docker logs
|
|
58
|
+
if (cmd.match(/^kubectl\s+logs\b/))
|
|
59
|
+
return compressLogsOutput(stdout);
|
|
60
|
+
// `kubectl describe` — verbose, often deeply indented; strip noise + cap repeated events
|
|
61
|
+
if (cmd.match(/^kubectl\s+describe\b/))
|
|
62
|
+
return compressKubectlDescribe(stdout);
|
|
63
|
+
// `kubectl get` — already tabular and compact, pass through
|
|
43
64
|
return null; // No compressor matched
|
|
44
65
|
}
|
|
45
66
|
// ─── Git Status ─────────────────────────────────────────────────────────────
|
|
@@ -296,6 +317,208 @@ function compressLsOutput(output) {
|
|
|
296
317
|
}
|
|
297
318
|
return result.join('\n');
|
|
298
319
|
}
|
|
320
|
+
// ─── GitHub CLI: pr/issue/run view ──────────────────────────────────────────
|
|
321
|
+
/**
|
|
322
|
+
* Compress `gh pr view`, `gh issue view`, `gh run view` output.
|
|
323
|
+
*
|
|
324
|
+
* Strips noise that has zero signal for the agent:
|
|
325
|
+
* - HTML comments (often left over from PR/issue templates)
|
|
326
|
+
* - Markdown badge images and image-only lines
|
|
327
|
+
* - Empty metadata lines (`labels:`, `projects:`, `milestone:` with no value)
|
|
328
|
+
* - "🤖 Generated with [Claude Code]" / "Co-Authored-By: ..." footers
|
|
329
|
+
* (only the duplicated trailing block — preserves any in-body co-authors
|
|
330
|
+
* that appear before the body's last paragraph)
|
|
331
|
+
* - The trailing "View this pull request on GitHub: <url>" footer
|
|
332
|
+
* - Runs of 3+ blank lines collapsed to a single blank
|
|
333
|
+
*
|
|
334
|
+
* Pass-through: keeps title, status, body, labels with values, code blocks.
|
|
335
|
+
*/
|
|
336
|
+
function compressGhView(output) {
|
|
337
|
+
// Drop HTML comments first (multiline regex)
|
|
338
|
+
const cleaned = output.replace(/<!--[\s\S]*?-->/g, '');
|
|
339
|
+
const lines = cleaned.split('\n');
|
|
340
|
+
const kept = [];
|
|
341
|
+
let consecutiveBlanks = 0;
|
|
342
|
+
for (const line of lines) {
|
|
343
|
+
const trimmed = line.trim();
|
|
344
|
+
// Trailing "View this pull request on GitHub: ..." / "View this issue on GitHub: ..."
|
|
345
|
+
if (/^View this (pull request|issue|workflow run) on GitHub:/i.test(trimmed))
|
|
346
|
+
continue;
|
|
347
|
+
// Empty metadata lines: `labels:`, `projects:`, `milestone:`, `assignees:`,
|
|
348
|
+
// `reviewers:` with no value after the colon.
|
|
349
|
+
if (/^(labels|projects|milestone|assignees|reviewers|tags):\s*$/i.test(trimmed)) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
// Badge image / image-only markdown lines
|
|
353
|
+
if (/^\[!\[[^\]]*\]\([^)]*\)\]\([^)]*\)$/.test(trimmed))
|
|
354
|
+
continue; // [](link)
|
|
355
|
+
if (/^!\[[^\]]*\]\([^)]*\)$/.test(trimmed))
|
|
356
|
+
continue; // 
|
|
357
|
+
// Collapse runs of blank lines (max 1 consecutive)
|
|
358
|
+
if (trimmed === '') {
|
|
359
|
+
consecutiveBlanks++;
|
|
360
|
+
if (consecutiveBlanks > 1)
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
consecutiveBlanks = 0;
|
|
365
|
+
}
|
|
366
|
+
kept.push(line);
|
|
367
|
+
}
|
|
368
|
+
// Strip a trailing "🤖 Generated with [Claude Code]" / "Co-Authored-By:" footer
|
|
369
|
+
// if it's the last non-blank block. We only strip if it's clearly the tail —
|
|
370
|
+
// we don't want to lose co-authors that appear inside the body.
|
|
371
|
+
while (kept.length > 0) {
|
|
372
|
+
const last = kept[kept.length - 1].trim();
|
|
373
|
+
if (last === '') {
|
|
374
|
+
kept.pop();
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (last.startsWith('🤖 Generated with [Claude Code]') || /^Co-Authored-By:/i.test(last)) {
|
|
378
|
+
kept.pop();
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
return kept.join('\n');
|
|
384
|
+
}
|
|
385
|
+
// ─── Container logs (docker logs / kubectl logs) ────────────────────────────
|
|
386
|
+
const LOGS_MAX_LINES = 100;
|
|
387
|
+
/**
|
|
388
|
+
* Cap container logs to the last N lines. Logs typically blow up token
|
|
389
|
+
* usage fast (a single container can produce thousands of lines), and the
|
|
390
|
+
* agent almost always wants the tail (most-recent failure / state).
|
|
391
|
+
*
|
|
392
|
+
* Drops a single banner line at the top noting how many lines were truncated
|
|
393
|
+
* so the agent knows the output was clipped.
|
|
394
|
+
*/
|
|
395
|
+
function compressLogsOutput(output) {
|
|
396
|
+
const lines = output.split('\n');
|
|
397
|
+
// Don't compress small outputs — the cap is the only thing this compressor does.
|
|
398
|
+
if (lines.length <= LOGS_MAX_LINES)
|
|
399
|
+
return output;
|
|
400
|
+
const truncated = lines.length - LOGS_MAX_LINES;
|
|
401
|
+
const tail = lines.slice(-LOGS_MAX_LINES);
|
|
402
|
+
return `... (${String(truncated)} earlier log lines truncated — showing last ${String(LOGS_MAX_LINES)})\n${tail.join('\n')}`;
|
|
403
|
+
}
|
|
404
|
+
// ─── docker pull / push / build (strip progress noise) ──────────────────────
|
|
405
|
+
/**
|
|
406
|
+
* Strip per-layer progress lines from `docker pull/push/build`. Keeps the
|
|
407
|
+
* digest / "Status: Image is up to date" / "Successfully built" summary lines.
|
|
408
|
+
*
|
|
409
|
+
* Patterns dropped (all common Docker progress chatter):
|
|
410
|
+
* - "<hash>: Pulling fs layer"
|
|
411
|
+
* - "<hash>: Waiting"
|
|
412
|
+
* - "<hash>: Verifying Checksum"
|
|
413
|
+
* - "<hash>: Downloading [====> ] 12.3MB/45.6MB"
|
|
414
|
+
* - "<hash>: Pull complete" / "Extracting" / "Download complete"
|
|
415
|
+
* - BuildKit progress lines: "#5 [internal] load build context"
|
|
416
|
+
* - Build context transfer lines
|
|
417
|
+
*/
|
|
418
|
+
function compressDockerProgress(output) {
|
|
419
|
+
const lines = output.split('\n');
|
|
420
|
+
const kept = [];
|
|
421
|
+
for (const line of lines) {
|
|
422
|
+
const trimmed = line.trim();
|
|
423
|
+
// Per-layer progress patterns (hash prefix + colon + status)
|
|
424
|
+
if (/^[a-f0-9]{12}:\s+(Pulling fs layer|Waiting|Verifying Checksum|Download complete|Pull complete|Extracting|Downloading|Pushing|Pushed|Mounted from|Layer already exists|Preparing|Already exists)/i.test(trimmed)) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
// BuildKit transfer lines: "#N transferring context: 1.23MB"
|
|
428
|
+
if (/^#\d+\s+(transferring|sha256:|extracting|naming to|exporting layers|writing image)/.test(trimmed))
|
|
429
|
+
continue;
|
|
430
|
+
// Plain "Downloading [====> ] 12MB/45MB" without hash prefix
|
|
431
|
+
if (/^\s*Downloading\s+\[/.test(line))
|
|
432
|
+
continue;
|
|
433
|
+
kept.push(line);
|
|
434
|
+
}
|
|
435
|
+
return kept.join('\n');
|
|
436
|
+
}
|
|
437
|
+
// ─── kubectl describe (collapse indentation noise, dedupe events) ───────────
|
|
438
|
+
/**
|
|
439
|
+
* Compress `kubectl describe` output. The verbose describe format is highly
|
|
440
|
+
* indented and includes long Events tables that often duplicate the same
|
|
441
|
+
* message N times ("Back-off restarting failed container").
|
|
442
|
+
*
|
|
443
|
+
* Strategy:
|
|
444
|
+
* - Trim trailing whitespace on every line (huge amount of padding)
|
|
445
|
+
* - Collapse 3+ consecutive blank lines to a single blank
|
|
446
|
+
* - In the Events: section, dedupe identical messages — keep first occurrence
|
|
447
|
+
* plus a count of repeats ("(x42)")
|
|
448
|
+
*/
|
|
449
|
+
function compressKubectlDescribe(output) {
|
|
450
|
+
const lines = output.split('\n');
|
|
451
|
+
const kept = [];
|
|
452
|
+
let inEvents = false;
|
|
453
|
+
let consecutiveBlanks = 0;
|
|
454
|
+
// Track event message → count (only used inside Events: section)
|
|
455
|
+
const eventCounts = new Map();
|
|
456
|
+
const eventOrder = [];
|
|
457
|
+
for (const line of lines) {
|
|
458
|
+
const rstripped = line.replace(/\s+$/, '');
|
|
459
|
+
const trimmed = rstripped.trim();
|
|
460
|
+
// Section header transitions
|
|
461
|
+
if (/^Events:\s*$/.test(trimmed)) {
|
|
462
|
+
inEvents = true;
|
|
463
|
+
kept.push(rstripped);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (inEvents && /^\S/.test(rstripped) && !/^Events:/.test(trimmed)) {
|
|
467
|
+
// A non-indented, non-Events: line means we've left the Events section.
|
|
468
|
+
// Flush deduped events first.
|
|
469
|
+
flushEvents(kept, eventCounts, eventOrder);
|
|
470
|
+
inEvents = false;
|
|
471
|
+
}
|
|
472
|
+
if (inEvents) {
|
|
473
|
+
// Inside Events table — collect by "type + reason + message" (drop timestamp/age columns)
|
|
474
|
+
// Lines look like:
|
|
475
|
+
// " Type Reason Age From Message"
|
|
476
|
+
// " ---- ------ --- ---- -------"
|
|
477
|
+
// " Warning BackOff 1m kubelet Back-off restarting failed container"
|
|
478
|
+
if (trimmed === '' || /^(Type|----)/.test(trimmed)) {
|
|
479
|
+
kept.push(rstripped);
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
// Extract the message (everything after the first 4 whitespace-separated columns)
|
|
483
|
+
const parts = trimmed.split(/\s{2,}/); // 2+ spaces between columns
|
|
484
|
+
const key = parts.length > 4 ? parts.slice(-1)[0] : trimmed;
|
|
485
|
+
const count = eventCounts.get(key) ?? 0;
|
|
486
|
+
if (count === 0)
|
|
487
|
+
eventOrder.push(rstripped);
|
|
488
|
+
eventCounts.set(key, count + 1);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
// Collapse runs of blank lines
|
|
492
|
+
if (trimmed === '') {
|
|
493
|
+
consecutiveBlanks++;
|
|
494
|
+
if (consecutiveBlanks > 1)
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
consecutiveBlanks = 0;
|
|
499
|
+
}
|
|
500
|
+
kept.push(rstripped);
|
|
501
|
+
}
|
|
502
|
+
// Flush any pending events at the end
|
|
503
|
+
if (inEvents)
|
|
504
|
+
flushEvents(kept, eventCounts, eventOrder);
|
|
505
|
+
return kept.join('\n');
|
|
506
|
+
}
|
|
507
|
+
function flushEvents(kept, counts, order) {
|
|
508
|
+
for (const line of order) {
|
|
509
|
+
const parts = line.trim().split(/\s{2,}/);
|
|
510
|
+
const key = parts.length > 4 ? parts.slice(-1)[0] : line.trim();
|
|
511
|
+
const count = counts.get(key) ?? 1;
|
|
512
|
+
if (count > 1) {
|
|
513
|
+
kept.push(`${line} (x${String(count)})`);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
kept.push(line);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
counts.clear();
|
|
520
|
+
order.length = 0;
|
|
521
|
+
}
|
|
299
522
|
// ─── curl / wget ────────────────────────────────────────────────────────────
|
|
300
523
|
function compressCurlOutput(output) {
|
|
301
524
|
const lines = output.split('\n');
|
package/dist/detection/common.js
CHANGED
|
@@ -79,6 +79,11 @@ function readGitRemote(projectPath) {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Read description from README.md or COMPILR.md (first non-heading paragraph).
|
|
82
|
+
*
|
|
83
|
+
* Skips noise commonly found above the first prose paragraph in auto-generated
|
|
84
|
+
* READMEs: headings, badge images, HTML comments, block-quote callouts, URL-only
|
|
85
|
+
* lines, and `**Key**: value` bold-metadata lines (e.g. Lovable's `**URL**: ...`,
|
|
86
|
+
* v0/Vercel templates with `**Demo**: ...`).
|
|
82
87
|
*/
|
|
83
88
|
function readDescription(projectPath) {
|
|
84
89
|
const candidates = ['README.md', 'readme.md', 'COMPILR.md'];
|
|
@@ -89,7 +94,7 @@ function readDescription(projectPath) {
|
|
|
89
94
|
try {
|
|
90
95
|
const content = readFileSync(filePath, 'utf-8');
|
|
91
96
|
const lines = content.split('\n');
|
|
92
|
-
// Find first non-empty, non-heading line
|
|
97
|
+
// Find first non-empty, non-heading, non-metadata line
|
|
93
98
|
for (const line of lines) {
|
|
94
99
|
const trimmed = line.trim();
|
|
95
100
|
if (!trimmed)
|
|
@@ -99,7 +104,13 @@ function readDescription(projectPath) {
|
|
|
99
104
|
if (trimmed.startsWith('!['))
|
|
100
105
|
continue; // badge images
|
|
101
106
|
if (trimmed.startsWith('<!--'))
|
|
102
|
-
continue;
|
|
107
|
+
continue; // HTML comments
|
|
108
|
+
if (trimmed.startsWith('>'))
|
|
109
|
+
continue; // block-quote callouts / "Note:" disclaimers
|
|
110
|
+
if (/^\*\*[\w\s/-]+\*\*\s*:/.test(trimmed))
|
|
111
|
+
continue; // bold-key metadata: **URL**: ..., **Live Demo**: ...
|
|
112
|
+
if (/^https?:\/\/\S+\s*$/.test(trimmed))
|
|
113
|
+
continue; // URL-only lines
|
|
103
114
|
// Found a content line — take up to 200 chars
|
|
104
115
|
return trimmed.length > 200 ? trimmed.slice(0, 200) + '...' : trimmed;
|
|
105
116
|
}
|