@sliday/tamp 0.5.8 → 0.7.0
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/README.md +13 -7
- package/bin/lifecycle.js +16 -4
- package/bin/tamp.js +46 -0
- package/bin/ui/Banner.js +7 -1
- package/bin/ui/Dashboard.js +1 -0
- package/compress.js +184 -4
- package/config.js +23 -2
- package/detect.js +10 -0
- package/index.js +67 -7
- package/lib/bm25.js +194 -0
- package/lib/br-cache.js +157 -0
- package/lib/disclosure.js +124 -0
- package/lib/path-extract.js +49 -0
- package/lib/read-cache.js +55 -0
- package/lib/rewriters/commands/cargo.js +50 -0
- package/lib/rewriters/commands/docker.js +54 -0
- package/lib/rewriters/commands/git.js +81 -0
- package/lib/rewriters/commands/jest.js +49 -0
- package/lib/rewriters/commands/npm.js +82 -0
- package/lib/rewriters/commands/pip.js +58 -0
- package/lib/rewriters/commands/prisma.js +50 -0
- package/lib/rewriters/commands/pytest.js +55 -0
- package/lib/rewriters/commands/terraform.js +49 -0
- package/lib/rewriters/commands/wget-curl.js +67 -0
- package/lib/rewriters/index.js +77 -0
- package/lib/rules-generator.js +45 -2
- package/metadata.js +37 -5
- package/package.json +2 -2
- package/providers.js +124 -1
- package/session-graph.js +36 -3
- package/stats.js +12 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// git clone <url>
|
|
3
|
+
// git fetch / git pull
|
|
4
|
+
// git push
|
|
5
|
+
//
|
|
6
|
+
// Strips: "remote: Counting objects: 42% (3/7)" repeated percentage lines,
|
|
7
|
+
// "remote: Compressing objects: 50% (1/2)", "Receiving objects: 42% (3/7)",
|
|
8
|
+
// "Resolving deltas: 50% (5/10)" — keeps only the final 100% line of each
|
|
9
|
+
// phase so the ratios/totals are preserved. Also strips carriage-return
|
|
10
|
+
// overwrite artifacts.
|
|
11
|
+
// Keeps: "Cloning into ...", remote: lines that are messages (not progress),
|
|
12
|
+
// "done.", final delta summary, error lines, "Unpacking objects" final 100%.
|
|
13
|
+
|
|
14
|
+
const PHASES = [
|
|
15
|
+
/^(remote:\s+)?Counting objects:\s+/,
|
|
16
|
+
/^(remote:\s+)?Compressing objects:\s+/,
|
|
17
|
+
/^(remote:\s+)?Enumerating objects:\s+/,
|
|
18
|
+
/^Receiving objects:\s+/,
|
|
19
|
+
/^Resolving deltas:\s+/,
|
|
20
|
+
/^Unpacking objects:\s+/,
|
|
21
|
+
/^Writing objects:\s+/,
|
|
22
|
+
/^remote:\s+Total\s+\d+/,
|
|
23
|
+
];
|
|
24
|
+
const GIT_SIG = /(^|\n)(Cloning into |remote: (Counting|Compressing|Enumerating) objects|Receiving objects:|Resolving deltas:|Unpacking objects:|Writing objects:|Fetching origin|To github\.com|Already up to date)/;
|
|
25
|
+
|
|
26
|
+
function phaseIndex(line) {
|
|
27
|
+
for (let i = 0; i < PHASES.length; i++) {
|
|
28
|
+
if (PHASES[i].test(line)) return i;
|
|
29
|
+
}
|
|
30
|
+
return -1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
name: 'git',
|
|
35
|
+
|
|
36
|
+
match(text) {
|
|
37
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
38
|
+
return GIT_SIG.test(text);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
rewrite(text) {
|
|
42
|
+
if (!text) return text;
|
|
43
|
+
|
|
44
|
+
// Split on both \n and \r so carriage-return overwritten progress frames
|
|
45
|
+
// become distinct lines we can filter. Normalize back to \n.
|
|
46
|
+
const lines = text.replace(/\r/g, '\n').split('\n');
|
|
47
|
+
const out = [];
|
|
48
|
+
const phaseBuffer = new Map(); // phaseIdx -> last line seen
|
|
49
|
+
|
|
50
|
+
const flush = () => {
|
|
51
|
+
if (phaseBuffer.size === 0) return;
|
|
52
|
+
// Emit in insertion order.
|
|
53
|
+
for (const line of phaseBuffer.values()) out.push(line);
|
|
54
|
+
phaseBuffer.clear();
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
const idx = phaseIndex(line);
|
|
59
|
+
if (idx >= 0) {
|
|
60
|
+
phaseBuffer.set(idx, line); // overwrite — keep the latest frame per phase
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
flush();
|
|
64
|
+
out.push(line);
|
|
65
|
+
}
|
|
66
|
+
flush();
|
|
67
|
+
|
|
68
|
+
const collapsed = [];
|
|
69
|
+
let blank = 0;
|
|
70
|
+
for (const l of out) {
|
|
71
|
+
if (l.trim() === '') {
|
|
72
|
+
blank++;
|
|
73
|
+
if (blank > 1) continue;
|
|
74
|
+
} else {
|
|
75
|
+
blank = 0;
|
|
76
|
+
}
|
|
77
|
+
collapsed.push(l);
|
|
78
|
+
}
|
|
79
|
+
return collapsed.join('\n');
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// jest / npx jest / yarn test (jest)
|
|
3
|
+
//
|
|
4
|
+
// Strips: "PASS path/to/file.test.ts (12 ms)" lines ONLY when the final Tests
|
|
5
|
+
// summary reports zero failures. Preserves every FAIL line verbatim, plus
|
|
6
|
+
// the Tests/Suites/Time/Snapshots summary and any stack traces.
|
|
7
|
+
|
|
8
|
+
const PASS_LINE = /^\s*PASS\s+\S+/;
|
|
9
|
+
const FAIL_LINE = /^\s*FAIL\s+\S+/;
|
|
10
|
+
const JEST_SIG = /(^|\n)(PASS\s+\S+|FAIL\s+\S+|Tests:\s+.*\d+\s+(passed|failed|total)|Test Suites:\s+\d)/;
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: 'jest',
|
|
14
|
+
|
|
15
|
+
match(text) {
|
|
16
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
17
|
+
return JEST_SIG.test(text);
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
rewrite(text) {
|
|
21
|
+
if (!text) return text;
|
|
22
|
+
|
|
23
|
+
const allPass = !FAIL_LINE.test(text) && /Tests:\s+[^,\n]*\d+\s+passed/.test(text);
|
|
24
|
+
if (!allPass) {
|
|
25
|
+
// Safety net: do not touch mixed / failing runs.
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const lines = text.split('\n');
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
if (PASS_LINE.test(line)) continue;
|
|
33
|
+
out.push(line);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const collapsed = [];
|
|
37
|
+
let blank = 0;
|
|
38
|
+
for (const l of out) {
|
|
39
|
+
if (l.trim() === '') {
|
|
40
|
+
blank++;
|
|
41
|
+
if (blank > 1) continue;
|
|
42
|
+
} else {
|
|
43
|
+
blank = 0;
|
|
44
|
+
}
|
|
45
|
+
collapsed.push(l);
|
|
46
|
+
}
|
|
47
|
+
return collapsed.join('\n');
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// npm install [pkg...]
|
|
3
|
+
// npm i [pkg...]
|
|
4
|
+
// npm ci
|
|
5
|
+
// npm run <script>
|
|
6
|
+
//
|
|
7
|
+
// Strips: spinner frames, progress dots, "npm fund" / "npm audit" preamble
|
|
8
|
+
// lines when no vulnerabilities follow, repeated ".........." lines, leading
|
|
9
|
+
// "⠋ idealTree" style lines.
|
|
10
|
+
// Keeps: error/warn lines, final "added N packages in Ns", vulnerability
|
|
11
|
+
// counts, "up to date", package trees.
|
|
12
|
+
|
|
13
|
+
const SPINNER_CHARS = /[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/;
|
|
14
|
+
const PROGRESS_LINE = /^\s*[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]\s+/;
|
|
15
|
+
const DOTS_ONLY = /^\s*\.{3,}\s*$/;
|
|
16
|
+
const NPM_SIG = /(^|\n)(npm (install|i|ci|run)\b|added \d+ packages?|up to date|changed \d+ packages?|removed \d+ packages?)/;
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
name: 'npm',
|
|
20
|
+
|
|
21
|
+
match(text) {
|
|
22
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
23
|
+
if (!NPM_SIG.test(text)) return false;
|
|
24
|
+
// Near-zero false positives: require either an npm invocation echo OR a
|
|
25
|
+
// characteristic npm summary line.
|
|
26
|
+
return (
|
|
27
|
+
/(^|\n)npm (install|i|ci|run)\b/.test(text) ||
|
|
28
|
+
/(^|\n)(added|removed|changed|up to date)/.test(text)
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
rewrite(text) {
|
|
33
|
+
if (!text) return text;
|
|
34
|
+
const lines = text.split('\n');
|
|
35
|
+
const out = [];
|
|
36
|
+
let lastWasDots = false;
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < lines.length; i++) {
|
|
39
|
+
const line = lines[i];
|
|
40
|
+
|
|
41
|
+
// Drop spinner lines and sole-dot lines.
|
|
42
|
+
if (PROGRESS_LINE.test(line) || SPINNER_CHARS.test(line)) continue;
|
|
43
|
+
if (DOTS_ONLY.test(line)) {
|
|
44
|
+
if (lastWasDots) continue;
|
|
45
|
+
lastWasDots = true;
|
|
46
|
+
continue; // drop dot-only lines entirely
|
|
47
|
+
}
|
|
48
|
+
lastWasDots = false;
|
|
49
|
+
|
|
50
|
+
// Drop the "run `npm fund` for details" preamble when no funding count follows.
|
|
51
|
+
if (/^\s*\d+ packages? are looking for funding\s*$/.test(line)) {
|
|
52
|
+
// Peek ahead — if next non-empty line is "run `npm fund`", drop both.
|
|
53
|
+
let j = i + 1;
|
|
54
|
+
while (j < lines.length && lines[j].trim() === '') j++;
|
|
55
|
+
if (j < lines.length && /run `npm fund`/.test(lines[j])) {
|
|
56
|
+
i = j; // skip the "run `npm fund`" line too
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (/^\s*run `npm fund` for details\s*$/.test(line)) continue;
|
|
61
|
+
|
|
62
|
+
// Drop "found 0 vulnerabilities" trailing audit preamble? Keep — it's signal.
|
|
63
|
+
|
|
64
|
+
out.push(line);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Collapse runs of blank lines to max 1.
|
|
68
|
+
const collapsed = [];
|
|
69
|
+
let blank = 0;
|
|
70
|
+
for (const l of out) {
|
|
71
|
+
if (l.trim() === '') {
|
|
72
|
+
blank++;
|
|
73
|
+
if (blank > 1) continue;
|
|
74
|
+
} else {
|
|
75
|
+
blank = 0;
|
|
76
|
+
}
|
|
77
|
+
collapsed.push(l);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return collapsed.join('\n');
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// pip install <pkg>
|
|
3
|
+
// pip install -r requirements.txt
|
|
4
|
+
//
|
|
5
|
+
// Strips: wheel download percentage lines, repeated "Collecting X" entries
|
|
6
|
+
// when the same package appears twice, "Using cached" blocks, progress bar
|
|
7
|
+
// block art.
|
|
8
|
+
// Keeps: "Successfully installed" summary, ERROR/WARNING lines, version pins.
|
|
9
|
+
|
|
10
|
+
const PROGRESS_BAR = /[█▏▎▍▌▋▊▉▐░▒▓|]{4,}/;
|
|
11
|
+
const PERCENT_LINE = /^\s*\|.*\|\s*\d+(\.\d+)?\s*[kKmMgG]?B\s/;
|
|
12
|
+
const DOWNLOADING = /^\s*Downloading\s+.*\([\d.]+\s*[kKmMgG]?B\)\s*$/;
|
|
13
|
+
const PIP_SIG = /(^|\n)(Collecting |Requirement already satisfied|Successfully installed|Installing collected packages)/;
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
name: 'pip',
|
|
17
|
+
|
|
18
|
+
match(text) {
|
|
19
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
20
|
+
return PIP_SIG.test(text);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
rewrite(text) {
|
|
24
|
+
if (!text) return text;
|
|
25
|
+
const lines = text.split('\n');
|
|
26
|
+
const out = [];
|
|
27
|
+
const seenCollecting = new Set();
|
|
28
|
+
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
if (PROGRESS_BAR.test(line)) continue;
|
|
31
|
+
if (PERCENT_LINE.test(line)) continue;
|
|
32
|
+
if (DOWNLOADING.test(line)) continue;
|
|
33
|
+
if (/^\s*Using cached\s+\S+\.whl\s*\([^)]+\)\s*$/.test(line)) continue;
|
|
34
|
+
|
|
35
|
+
const m = /^\s*Collecting\s+([A-Za-z0-9_.\-]+)/.exec(line);
|
|
36
|
+
if (m) {
|
|
37
|
+
const key = m[1].toLowerCase();
|
|
38
|
+
if (seenCollecting.has(key)) continue;
|
|
39
|
+
seenCollecting.add(key);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
out.push(line);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const collapsed = [];
|
|
46
|
+
let blank = 0;
|
|
47
|
+
for (const l of out) {
|
|
48
|
+
if (l.trim() === '') {
|
|
49
|
+
blank++;
|
|
50
|
+
if (blank > 1) continue;
|
|
51
|
+
} else {
|
|
52
|
+
blank = 0;
|
|
53
|
+
}
|
|
54
|
+
collapsed.push(l);
|
|
55
|
+
}
|
|
56
|
+
return collapsed.join('\n');
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// prisma generate / prisma migrate / prisma db push
|
|
3
|
+
// npx prisma generate
|
|
4
|
+
//
|
|
5
|
+
// Strips: "Environment variables loaded from .env", "Prisma schema loaded
|
|
6
|
+
// from prisma/schema.prisma", spinner frames with "✔" replaced characters,
|
|
7
|
+
// braille spinner lines. Keeps: "Generated Prisma Client" success line,
|
|
8
|
+
// error blocks, migration summaries, query engine paths.
|
|
9
|
+
|
|
10
|
+
const ENV_LINE = /^Environment variables loaded from\s+\S+\s*$/;
|
|
11
|
+
const SCHEMA_LINE = /^Prisma schema loaded from\s+\S+\s*$/;
|
|
12
|
+
const DATASOURCE_LINE = /^Datasource "\w+":\s/;
|
|
13
|
+
const SPINNER = /^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]\s+/;
|
|
14
|
+
const PRISMA_SIG = /(^|\n)(Prisma schema loaded from|Environment variables loaded from|Generated Prisma Client|Running generate|✔ Generated)/;
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
name: 'prisma',
|
|
18
|
+
|
|
19
|
+
match(text) {
|
|
20
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
21
|
+
return PRISMA_SIG.test(text);
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
rewrite(text) {
|
|
25
|
+
if (!text) return text;
|
|
26
|
+
const lines = text.split('\n');
|
|
27
|
+
const out = [];
|
|
28
|
+
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
if (ENV_LINE.test(line)) continue;
|
|
31
|
+
if (SCHEMA_LINE.test(line)) continue;
|
|
32
|
+
if (DATASOURCE_LINE.test(line)) continue;
|
|
33
|
+
if (SPINNER.test(line)) continue;
|
|
34
|
+
out.push(line);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const collapsed = [];
|
|
38
|
+
let blank = 0;
|
|
39
|
+
for (const l of out) {
|
|
40
|
+
if (l.trim() === '') {
|
|
41
|
+
blank++;
|
|
42
|
+
if (blank > 1) continue;
|
|
43
|
+
} else {
|
|
44
|
+
blank = 0;
|
|
45
|
+
}
|
|
46
|
+
collapsed.push(l);
|
|
47
|
+
}
|
|
48
|
+
return collapsed.join('\n');
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// pytest / python -m pytest
|
|
3
|
+
//
|
|
4
|
+
// Strips: the "collected N items" banner line, the per-test dot-progress line
|
|
5
|
+
// ("tests/foo_test.py ........ [ 50%]"), and the session
|
|
6
|
+
// start banner "platform darwin -- Python 3.11.4 ...". Keeps: FAIL summaries,
|
|
7
|
+
// the short test summary info block, and the final "=== N passed in Xs ===".
|
|
8
|
+
|
|
9
|
+
const COLLECTED = /^collected\s+\d+\s+items?\b/;
|
|
10
|
+
const DOT_PROGRESS = /^\S.*\s+[.FsxE]{2,}\s*(\[\s*\d+%\s*\])?\s*$/;
|
|
11
|
+
const SESSION_START = /^platform\s+\S+\s+--\s+Python\s+\d/;
|
|
12
|
+
const ROOTDIR = /^rootdir:\s+/;
|
|
13
|
+
const PLUGINS = /^plugins:\s+/;
|
|
14
|
+
const CACHEDIR = /^cachedir:\s+/;
|
|
15
|
+
const PYTEST_SIG = /(^|\n)(={3,}\s+test session starts\s+={3,}|collected\s+\d+\s+items?|={3,}\s+\d+\s+(passed|failed|error)s?\b)/;
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: 'pytest',
|
|
19
|
+
|
|
20
|
+
match(text) {
|
|
21
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
22
|
+
return PYTEST_SIG.test(text);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
rewrite(text) {
|
|
26
|
+
if (!text) return text;
|
|
27
|
+
const lines = text.split('\n');
|
|
28
|
+
const out = [];
|
|
29
|
+
|
|
30
|
+
for (const line of lines) {
|
|
31
|
+
if (COLLECTED.test(line)) continue;
|
|
32
|
+
if (SESSION_START.test(line)) continue;
|
|
33
|
+
if (ROOTDIR.test(line)) continue;
|
|
34
|
+
if (PLUGINS.test(line)) continue;
|
|
35
|
+
if (CACHEDIR.test(line)) continue;
|
|
36
|
+
// Drop dot-progress only if the line contains ONLY test status chars
|
|
37
|
+
// (not a traceback line that happens to end with dots).
|
|
38
|
+
if (DOT_PROGRESS.test(line) && !/error|FAILED|PASSED/.test(line)) continue;
|
|
39
|
+
out.push(line);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const collapsed = [];
|
|
43
|
+
let blank = 0;
|
|
44
|
+
for (const l of out) {
|
|
45
|
+
if (l.trim() === '') {
|
|
46
|
+
blank++;
|
|
47
|
+
if (blank > 1) continue;
|
|
48
|
+
} else {
|
|
49
|
+
blank = 0;
|
|
50
|
+
}
|
|
51
|
+
collapsed.push(l);
|
|
52
|
+
}
|
|
53
|
+
return collapsed.join('\n');
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// terraform plan / terraform apply
|
|
3
|
+
//
|
|
4
|
+
// Strips: every "<resource>: Refreshing state... [id=...]" line under plan,
|
|
5
|
+
// repetitive "Still creating... [Xs elapsed]" progress lines during apply.
|
|
6
|
+
// Keeps: the "Plan: N to add, M to change, K to destroy." summary, all
|
|
7
|
+
// Warning:/Error: blocks, resource diff output, variable prompts.
|
|
8
|
+
|
|
9
|
+
const REFRESH_LINE = /^\S[\w.\-\[\]"]*:\s+Refreshing state\.\.\./;
|
|
10
|
+
const STILL_LINE = /:\s+Still (creating|destroying|modifying)\.\.\.\s+\[\d+[smh]\s+elapsed\]/;
|
|
11
|
+
const READING_LINE = /:\s+Reading\.\.\.\s*$/;
|
|
12
|
+
const READ_COMPLETE_LINE = /:\s+Read complete after\s+\d+[smh]/;
|
|
13
|
+
const TF_SIG = /(^|\n)(Refreshing state\.\.\.|Terraform will perform the following actions|Plan: \d+ to add|Apply complete!|Terraform used the selected providers|Initializing the backend)/;
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
name: 'terraform',
|
|
17
|
+
|
|
18
|
+
match(text) {
|
|
19
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
20
|
+
return TF_SIG.test(text);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
rewrite(text) {
|
|
24
|
+
if (!text) return text;
|
|
25
|
+
const lines = text.split('\n');
|
|
26
|
+
const out = [];
|
|
27
|
+
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
if (REFRESH_LINE.test(line)) continue;
|
|
30
|
+
if (STILL_LINE.test(line)) continue;
|
|
31
|
+
if (READING_LINE.test(line)) continue;
|
|
32
|
+
if (READ_COMPLETE_LINE.test(line)) continue;
|
|
33
|
+
out.push(line);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const collapsed = [];
|
|
37
|
+
let blank = 0;
|
|
38
|
+
for (const l of out) {
|
|
39
|
+
if (l.trim() === '') {
|
|
40
|
+
blank++;
|
|
41
|
+
if (blank > 1) continue;
|
|
42
|
+
} else {
|
|
43
|
+
blank = 0;
|
|
44
|
+
}
|
|
45
|
+
collapsed.push(l);
|
|
46
|
+
}
|
|
47
|
+
return collapsed.join('\n');
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Targets:
|
|
2
|
+
// curl -O/-o <url>, curl <url>
|
|
3
|
+
// wget <url>
|
|
4
|
+
//
|
|
5
|
+
// Strips: the "% Total ... Time ... Current" header block and all mid-download
|
|
6
|
+
// percentage rows from curl; the tick-mark ASCII bar + per-line percentage
|
|
7
|
+
// rows from wget; leaves the final summary row / "100%" tail line intact.
|
|
8
|
+
// Keeps: final size/time summary, error lines, HTTP response headers if
|
|
9
|
+
// requested (-v / --verbose are untouched — we only match the download grid).
|
|
10
|
+
|
|
11
|
+
const CURL_HEADER = /^\s*%\s+Total\s+%\s+Received/;
|
|
12
|
+
const CURL_SECOND_HEADER = /^\s+Dload\s+Upload/;
|
|
13
|
+
const CURL_ROW = /^\s*\d{1,3}\s+\d[\d.kKMmGgTt]*\s+\d{1,3}\s+\d[\d.kKMmGgTt]*\s+\d+\s+\d+\s+\d[\d.kKMmGgTt]*\s+\d+\s+/;
|
|
14
|
+
const WGET_PROGRESS = /^\s*\d{1,3}%\s*\[[=> .]+\]/;
|
|
15
|
+
const WGET_TICKS = /^\s*[\d,]+[KMG]?\s+[.=]+\s+\d+%/;
|
|
16
|
+
const WGET_SIG = /(^|\n)(--\d{4}-\d{2}-\d{2}|Resolving |Connecting to |HTTP request sent|Length: |Saving to: )/;
|
|
17
|
+
const CURL_SIG = /(^|\n)\s*%\s+Total\s+%\s+Received/;
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
name: 'wget-curl',
|
|
21
|
+
|
|
22
|
+
match(text) {
|
|
23
|
+
if (typeof text !== 'string' || text.length === 0) return false;
|
|
24
|
+
return CURL_SIG.test(text) || WGET_SIG.test(text);
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
rewrite(text) {
|
|
28
|
+
if (!text) return text;
|
|
29
|
+
const lines = text.split('\n');
|
|
30
|
+
const out = [];
|
|
31
|
+
let lastCurlRow = null;
|
|
32
|
+
|
|
33
|
+
for (const line of lines) {
|
|
34
|
+
if (CURL_HEADER.test(line)) continue;
|
|
35
|
+
if (CURL_SECOND_HEADER.test(line)) continue;
|
|
36
|
+
if (WGET_PROGRESS.test(line)) continue;
|
|
37
|
+
if (WGET_TICKS.test(line)) continue;
|
|
38
|
+
|
|
39
|
+
if (CURL_ROW.test(line)) {
|
|
40
|
+
// Keep only the final row (last one seen) — buffer it.
|
|
41
|
+
lastCurlRow = line;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (lastCurlRow !== null) {
|
|
46
|
+
// Flush the last curl row right before the next non-row line.
|
|
47
|
+
out.push(lastCurlRow);
|
|
48
|
+
lastCurlRow = null;
|
|
49
|
+
}
|
|
50
|
+
out.push(line);
|
|
51
|
+
}
|
|
52
|
+
if (lastCurlRow !== null) out.push(lastCurlRow);
|
|
53
|
+
|
|
54
|
+
const collapsed = [];
|
|
55
|
+
let blank = 0;
|
|
56
|
+
for (const l of out) {
|
|
57
|
+
if (l.trim() === '') {
|
|
58
|
+
blank++;
|
|
59
|
+
if (blank > 1) continue;
|
|
60
|
+
} else {
|
|
61
|
+
blank = 0;
|
|
62
|
+
}
|
|
63
|
+
collapsed.push(l);
|
|
64
|
+
}
|
|
65
|
+
return collapsed.join('\n');
|
|
66
|
+
},
|
|
67
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Per-command stdout rewriters for the `cmd-strip` stage.
|
|
2
|
+
// Each rewriter module lives in ./commands/<name>.js and exports:
|
|
3
|
+
// { name, match(text) -> bool, rewrite(text) -> string }
|
|
4
|
+
//
|
|
5
|
+
// Priority order is frozen — most specific signatures first so that a noisy
|
|
6
|
+
// output like `npm install` never gets eaten by a looser matcher.
|
|
7
|
+
|
|
8
|
+
import npm from './commands/npm.js';
|
|
9
|
+
import pip from './commands/pip.js';
|
|
10
|
+
import cargo from './commands/cargo.js';
|
|
11
|
+
import docker from './commands/docker.js';
|
|
12
|
+
import prisma from './commands/prisma.js';
|
|
13
|
+
import terraform from './commands/terraform.js';
|
|
14
|
+
import git from './commands/git.js';
|
|
15
|
+
import pytest from './commands/pytest.js';
|
|
16
|
+
import jest from './commands/jest.js';
|
|
17
|
+
import wgetCurl from './commands/wget-curl.js';
|
|
18
|
+
|
|
19
|
+
const REGISTRY = Object.freeze({
|
|
20
|
+
npm,
|
|
21
|
+
pip,
|
|
22
|
+
cargo,
|
|
23
|
+
docker,
|
|
24
|
+
prisma,
|
|
25
|
+
terraform,
|
|
26
|
+
git,
|
|
27
|
+
pytest,
|
|
28
|
+
jest,
|
|
29
|
+
'wget-curl': wgetCurl,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const PRIORITY = Object.freeze([
|
|
33
|
+
'npm',
|
|
34
|
+
'pip',
|
|
35
|
+
'cargo',
|
|
36
|
+
'docker',
|
|
37
|
+
'prisma',
|
|
38
|
+
'terraform',
|
|
39
|
+
'git',
|
|
40
|
+
'pytest',
|
|
41
|
+
'jest',
|
|
42
|
+
'wget-curl',
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
export function getRewriter(name) {
|
|
46
|
+
if (!name) return null;
|
|
47
|
+
return REGISTRY[name] || null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function rewriteCommandOutput(text) {
|
|
51
|
+
if (typeof text !== 'string' || text.length === 0) {
|
|
52
|
+
return { text: text ?? '', rewriter: null, savedBytes: 0 };
|
|
53
|
+
}
|
|
54
|
+
for (const name of PRIORITY) {
|
|
55
|
+
const mod = REGISTRY[name];
|
|
56
|
+
if (!mod) continue;
|
|
57
|
+
let hit = false;
|
|
58
|
+
try {
|
|
59
|
+
hit = !!mod.match(text);
|
|
60
|
+
} catch {
|
|
61
|
+
hit = false;
|
|
62
|
+
}
|
|
63
|
+
if (!hit) continue;
|
|
64
|
+
let out = text;
|
|
65
|
+
try {
|
|
66
|
+
out = mod.rewrite(text);
|
|
67
|
+
} catch {
|
|
68
|
+
out = text;
|
|
69
|
+
}
|
|
70
|
+
if (typeof out !== 'string') out = text;
|
|
71
|
+
const savedBytes = Math.max(0, Buffer.byteLength(text, 'utf8') - Buffer.byteLength(out, 'utf8'));
|
|
72
|
+
return { text: out, rewriter: mod.name || name, savedBytes };
|
|
73
|
+
}
|
|
74
|
+
return { text, rewriter: null, savedBytes: 0 };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default { getRewriter, rewriteCommandOutput, PRIORITY };
|
package/lib/rules-generator.js
CHANGED
|
@@ -25,6 +25,34 @@ const DANGEROUS_TASK_PATTERNS = [
|
|
|
25
25
|
/test|spec|coverage/i,
|
|
26
26
|
]
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Per-agent rule overrides. Keyed by `config.agent` (lowercased short name).
|
|
30
|
+
* Shape: { <agent>: { safe?: string, dangerous?: string, complex?: string, conservative?: string } }
|
|
31
|
+
*
|
|
32
|
+
* Hook: populate these tables to tune phrasing per agent. A missing entry
|
|
33
|
+
* falls through to the shared rules. Codex CLI's post-processor already
|
|
34
|
+
* strips explanations, so we use terser phrasing there — other agents get
|
|
35
|
+
* the default rules until we have evidence they benefit from variants.
|
|
36
|
+
*/
|
|
37
|
+
export const PER_AGENT_OVERRIDES = Object.freeze({
|
|
38
|
+
codex: {
|
|
39
|
+
safe: `## Token-Efficient Output (Balanced / Codex)
|
|
40
|
+
- Code only. No prose, no preamble, no summary.
|
|
41
|
+
- Single-line status after the change (e.g., "done", "noop").
|
|
42
|
+
`,
|
|
43
|
+
complex: `## Token-Efficient Output (Balanced / Codex)
|
|
44
|
+
- Terse bullets. No filler sentences.
|
|
45
|
+
- Skip "Here's what I'll do" intros — just do it.
|
|
46
|
+
- Return code first; explanation only if non-obvious.
|
|
47
|
+
`,
|
|
48
|
+
},
|
|
49
|
+
// Intentionally empty — add overrides here if evidence warrants it.
|
|
50
|
+
cursor: {},
|
|
51
|
+
cline: {},
|
|
52
|
+
aider: {},
|
|
53
|
+
'claude-code': {},
|
|
54
|
+
})
|
|
55
|
+
|
|
28
56
|
/**
|
|
29
57
|
* Detect task type from user message
|
|
30
58
|
* @param {string} userMessage - User's input message
|
|
@@ -49,6 +77,15 @@ export function detectTaskType(userMessage) {
|
|
|
49
77
|
return 'complex'
|
|
50
78
|
}
|
|
51
79
|
|
|
80
|
+
/**
|
|
81
|
+
* True if the user's latest message matches a DANGEROUS_TASK_PATTERNS entry.
|
|
82
|
+
* Used by lossy stages (e.g., disclosure) to bypass when the task demands
|
|
83
|
+
* full fidelity (security/debug/refactor/test).
|
|
84
|
+
*/
|
|
85
|
+
export function isDangerousTask(userMessage) {
|
|
86
|
+
return detectTaskType(userMessage) === 'dangerous'
|
|
87
|
+
}
|
|
88
|
+
|
|
52
89
|
/**
|
|
53
90
|
* Output compression intensity levels
|
|
54
91
|
*/
|
|
@@ -83,14 +120,16 @@ export const OUTPUT_MODES = Object.freeze({
|
|
|
83
120
|
* Generate optimized CLAUDE.md rules for output compression
|
|
84
121
|
* @param {string} mode - Output mode (conservative | balanced | aggressive)
|
|
85
122
|
* @param {string} taskType - Task type (safe | dangerous | complex)
|
|
123
|
+
* @param {string} [agent] - Optional agent name for per-agent overrides
|
|
86
124
|
* @returns {string} - Optimized CLAUDE.md rules text
|
|
87
125
|
*/
|
|
88
|
-
export function generateOutputRules(mode = 'balanced', taskType = 'complex') {
|
|
126
|
+
export function generateOutputRules(mode = 'balanced', taskType = 'complex', agent) {
|
|
89
127
|
const modeConfig = OUTPUT_MODES[mode] || OUTPUT_MODES.balanced
|
|
90
128
|
|
|
91
129
|
// Conservative mode always generates minimal rules (for all task types)
|
|
92
130
|
if (mode === 'conservative') {
|
|
93
|
-
|
|
131
|
+
const override = agent && PER_AGENT_OVERRIDES[agent]?.conservative
|
|
132
|
+
return override || generateConservativeRules()
|
|
94
133
|
}
|
|
95
134
|
|
|
96
135
|
// Determine if we should compress based on mode + task type
|
|
@@ -105,6 +144,10 @@ export function generateOutputRules(mode = 'balanced', taskType = 'complex') {
|
|
|
105
144
|
return ''
|
|
106
145
|
}
|
|
107
146
|
|
|
147
|
+
// Check per-agent override for this (agent, taskType) pair
|
|
148
|
+
const override = agent && PER_AGENT_OVERRIDES[agent]?.[taskType]
|
|
149
|
+
if (override) return override
|
|
150
|
+
|
|
108
151
|
// Generate rules based on mode
|
|
109
152
|
const rules = {
|
|
110
153
|
balanced: generateBalancedRules(taskType),
|