@sliday/tamp 0.5.9 → 0.8.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.
@@ -0,0 +1,49 @@
1
+ // Given a `targets` array and the raw body, return a parallel array of
2
+ // `path | null` such that targets[i] belongs to file paths[i].
3
+ // Strategy: scan message history for tool_use blocks whose id matches the
4
+ // tool_use_id of the tool_result; extract input.file_path (Anthropic Read),
5
+ // input.path, or input.filePath. Provider-specific — Anthropic only.
6
+
7
+ function buildToolUseIndex(messages) {
8
+ // Map<tool_use_id, { file_path }>. Scan assistant messages for tool_use
9
+ // blocks and record their resolved file path once.
10
+ const index = new Map()
11
+ if (!Array.isArray(messages)) return index
12
+
13
+ for (const msg of messages) {
14
+ if (msg?.role !== 'assistant' || !Array.isArray(msg.content)) continue
15
+ for (const block of msg.content) {
16
+ if (block?.type !== 'tool_use' || !block.id || !block.input) continue
17
+ const input = block.input
18
+ const filePath = input.file_path || input.path || input.filePath
19
+ if (typeof filePath === 'string' && filePath.length > 0) {
20
+ index.set(block.id, filePath)
21
+ }
22
+ }
23
+ }
24
+ return index
25
+ }
26
+
27
+ function findToolUseIdForTarget(body, target) {
28
+ // Target path shape (Anthropic): ['messages', mi, 'content', i, ...]
29
+ // The tool_result block lives at body.messages[mi].content[i].
30
+ const path = target?.path
31
+ if (!Array.isArray(path) || path[0] !== 'messages') return null
32
+ const mi = path[1]
33
+ const ci = path[3]
34
+ const msg = body?.messages?.[mi]
35
+ if (!msg || !Array.isArray(msg.content)) return null
36
+ const block = msg.content[ci]
37
+ if (!block || block.type !== 'tool_result') return null
38
+ return typeof block.tool_use_id === 'string' ? block.tool_use_id : null
39
+ }
40
+
41
+ export function extractTargetPaths(body, targets) {
42
+ const index = buildToolUseIndex(body?.messages)
43
+ return targets.map(target => {
44
+ if (!target || target.skip) return null
45
+ const toolUseId = findToolUseIdForTarget(body, target)
46
+ if (!toolUseId) return null
47
+ return index.get(toolUseId) || null
48
+ })
49
+ }
@@ -0,0 +1,55 @@
1
+ // Session-scoped LRU cache of last-seen Read bodies, keyed by
2
+ // `sessionKey + ':' + path`. Used by the `read-diff` stage to replace a
3
+ // re-read of a known file with a unified diff against the prior copy.
4
+ // Map insertion order gives us LRU for free.
5
+
6
+ const DEFAULT_TTL_MS = 2 * 60 * 60 * 1000
7
+ const DEFAULT_MAX_ENTRIES = 256
8
+
9
+ function makeKey(sessionKey, path) {
10
+ return `${sessionKey}:${path}`
11
+ }
12
+
13
+ export function createReadCache({ maxEntries = DEFAULT_MAX_ENTRIES, ttlMs = DEFAULT_TTL_MS } = {}) {
14
+ const store = new Map()
15
+ let hits = 0
16
+ let misses = 0
17
+
18
+ function prune() {
19
+ const cutoff = Date.now() - ttlMs
20
+ for (const [k, entry] of store) {
21
+ if (entry.lastSeen < cutoff) store.delete(k)
22
+ }
23
+ }
24
+
25
+ function get(sessionKey, path) {
26
+ if (!sessionKey || !path) return null
27
+ prune()
28
+ const key = makeKey(sessionKey, path)
29
+ const entry = store.get(key)
30
+ if (!entry) { misses += 1; return null }
31
+ // Refresh LRU position.
32
+ store.delete(key)
33
+ entry.lastSeen = Date.now()
34
+ store.set(key, entry)
35
+ hits += 1
36
+ return entry.text
37
+ }
38
+
39
+ function put(sessionKey, path, text) {
40
+ if (!sessionKey || !path || typeof text !== 'string') return
41
+ const key = makeKey(sessionKey, path)
42
+ if (store.has(key)) store.delete(key)
43
+ else if (store.size >= maxEntries) {
44
+ const oldest = store.keys().next().value
45
+ store.delete(oldest)
46
+ }
47
+ store.set(key, { text, lastSeen: Date.now() })
48
+ }
49
+
50
+ function stats() {
51
+ return { entries: store.size, hits, misses }
52
+ }
53
+
54
+ return { get, put, stats, prune, _store: store }
55
+ }
@@ -0,0 +1,50 @@
1
+ // Targets:
2
+ // cargo build / cargo check / cargo run / cargo test
3
+ //
4
+ // Strips: " Compiling foo v1.0.0 (path)" intermediate lines when followed by
5
+ // a "Finished" line; progress bar spinner lines like " Building [===> ]".
6
+ // Keeps: "Finished" line, warnings, errors, test results, panic traces.
7
+
8
+ const COMPILING_LINE = /^\s{2,}Compiling\s+[A-Za-z0-9_.\-]+\s+v[\d.]+/;
9
+ const PROGRESS_LINE = /^\s*Building\s+\[[=> ]+\]/;
10
+ const DOWNLOADING = /^\s{2,}(Downloading|Downloaded)\s+[A-Za-z0-9_.\-]+\s+v[\d.]+/;
11
+ const CARGO_SIG = /(^|\n)(\s{2,}(Compiling|Finished|Building|Downloading|Downloaded|Running|Fresh)\s|error\[E\d+\]|warning:\s)/;
12
+
13
+ export default {
14
+ name: 'cargo',
15
+
16
+ match(text) {
17
+ if (typeof text !== 'string' || text.length === 0) return false;
18
+ return CARGO_SIG.test(text);
19
+ },
20
+
21
+ rewrite(text) {
22
+ if (!text) return text;
23
+
24
+ // Only strip Compiling lines when a Finished line is present (build succeeded).
25
+ const hasFinished = /^\s{2,}Finished\s+/m.test(text);
26
+
27
+ const lines = text.split('\n');
28
+ const out = [];
29
+
30
+ for (const line of lines) {
31
+ if (PROGRESS_LINE.test(line)) continue;
32
+ if (DOWNLOADING.test(line)) continue;
33
+ if (hasFinished && COMPILING_LINE.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,54 @@
1
+ // Targets:
2
+ // docker build ...
3
+ // docker buildx build ...
4
+ //
5
+ // Strips: BuildKit spinner lines ("#5 [2/7] RUN ... 0.3s"), transferred-bytes
6
+ // progress ("=> => transferring context: 123kB 0.1s"), cache-hit duplicates
7
+ // "=> CACHED [foo] ..." retained, but "=> => resolve sha256:..." noise stripped.
8
+ // Keeps: "Successfully built <id>", "Successfully tagged <name>", ERROR lines,
9
+ // final image sha, step headings.
10
+
11
+ const BUILDKIT_SUB = /^#\d+\s+=>\s+=>\s+/; // "#5 => => transferring ..." / "=> => resolve sha256:..."
12
+ const BUILDKIT_TRANSFER = /^=>\s+=>\s+(transferring|resolve|sha256|naming to|writing image|exporting)/;
13
+ const SPINNER_BRAILLE = /^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/;
14
+ const LEGACY_PROGRESS = /^\s*[0-9a-f]{12}: (Downloading|Extracting|Pulling fs layer|Waiting|Verifying Checksum|Download complete|Pull complete)\s/;
15
+ const DOCKER_SIG = /(^|\n)(Successfully built |Successfully tagged |Step \d+\/\d+\s*:|Sending build context|#\d+\s+\[|ERROR: |=>\s+\[)/;
16
+
17
+ export default {
18
+ name: 'docker',
19
+
20
+ match(text) {
21
+ if (typeof text !== 'string' || text.length === 0) return false;
22
+ return DOCKER_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 (BUILDKIT_SUB.test(line)) continue;
32
+ if (BUILDKIT_TRANSFER.test(line)) continue;
33
+ if (SPINNER_BRAILLE.test(line)) continue;
34
+ if (LEGACY_PROGRESS.test(line)) continue;
35
+ // BuildKit "in-progress" duplicated step lines end with a fractional second
36
+ // marker and are re-emitted as DONE later; strip the non-DONE variants.
37
+ if (/^#\d+\s+\S.*\s\d+\.\d+s$/.test(line) && !/\sDONE\b/.test(line)) continue;
38
+ out.push(line);
39
+ }
40
+
41
+ const collapsed = [];
42
+ let blank = 0;
43
+ for (const l of out) {
44
+ if (l.trim() === '') {
45
+ blank++;
46
+ if (blank > 1) continue;
47
+ } else {
48
+ blank = 0;
49
+ }
50
+ collapsed.push(l);
51
+ }
52
+ return collapsed.join('\n');
53
+ },
54
+ };
@@ -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
+ };