tuxevil-rotator 3.0.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.
Files changed (142) hide show
  1. package/CHANGELOG.md +773 -0
  2. package/LICENSE +21 -0
  3. package/README.md +341 -0
  4. package/bin/pi-antigravity-rotator.js +27 -0
  5. package/bin/tuxevil-rotator.js +5 -0
  6. package/package.json +63 -0
  7. package/src/account-store.ts +542 -0
  8. package/src/admin-auth.ts +126 -0
  9. package/src/body-limit.ts +52 -0
  10. package/src/cli.ts +293 -0
  11. package/src/compat/cache.ts +38 -0
  12. package/src/compat/model-specs.ts +82 -0
  13. package/src/compat/schema-sanitizer.ts +284 -0
  14. package/src/compat.ts +2357 -0
  15. package/src/compression/index.ts +92 -0
  16. package/src/compression/lite.ts +210 -0
  17. package/src/compression/preservation.ts +183 -0
  18. package/src/compression/rtk/command-detector.ts +170 -0
  19. package/src/compression/rtk/deduplicator.ts +39 -0
  20. package/src/compression/rtk/filter-loader.ts +84 -0
  21. package/src/compression/rtk/filter-types.ts +25 -0
  22. package/src/compression/rtk/filters/aws.json +34 -0
  23. package/src/compression/rtk/filters/biome.json +35 -0
  24. package/src/compression/rtk/filters/build-eslint.json +37 -0
  25. package/src/compression/rtk/filters/build-typescript.json +33 -0
  26. package/src/compression/rtk/filters/build-vite.json +41 -0
  27. package/src/compression/rtk/filters/build-webpack.json +34 -0
  28. package/src/compression/rtk/filters/bundle-install.json +35 -0
  29. package/src/compression/rtk/filters/composer.json +81 -0
  30. package/src/compression/rtk/filters/curl.json +34 -0
  31. package/src/compression/rtk/filters/df.json +34 -0
  32. package/src/compression/rtk/filters/docker-build.json +78 -0
  33. package/src/compression/rtk/filters/docker-logs.json +42 -0
  34. package/src/compression/rtk/filters/docker-ps.json +33 -0
  35. package/src/compression/rtk/filters/dotnet.json +47 -0
  36. package/src/compression/rtk/filters/du.json +33 -0
  37. package/src/compression/rtk/filters/error-stacktrace.json +41 -0
  38. package/src/compression/rtk/filters/gcloud.json +34 -0
  39. package/src/compression/rtk/filters/generic-output.json +32 -0
  40. package/src/compression/rtk/filters/gh.json +98 -0
  41. package/src/compression/rtk/filters/git-branch.json +45 -0
  42. package/src/compression/rtk/filters/git-diff.json +33 -0
  43. package/src/compression/rtk/filters/git-log.json +33 -0
  44. package/src/compression/rtk/filters/git-status.json +40 -0
  45. package/src/compression/rtk/filters/golangci-lint.json +34 -0
  46. package/src/compression/rtk/filters/gradle.json +47 -0
  47. package/src/compression/rtk/filters/json-output.json +40 -0
  48. package/src/compression/rtk/filters/kubectl.json +99 -0
  49. package/src/compression/rtk/filters/make.json +38 -0
  50. package/src/compression/rtk/filters/mypy.json +34 -0
  51. package/src/compression/rtk/filters/npm-audit.json +43 -0
  52. package/src/compression/rtk/filters/npm-install.json +41 -0
  53. package/src/compression/rtk/filters/nx.json +34 -0
  54. package/src/compression/rtk/filters/pip.json +41 -0
  55. package/src/compression/rtk/filters/playwright.json +42 -0
  56. package/src/compression/rtk/filters/poetry-install.json +35 -0
  57. package/src/compression/rtk/filters/prettier.json +40 -0
  58. package/src/compression/rtk/filters/ps.json +34 -0
  59. package/src/compression/rtk/filters/rsync.json +33 -0
  60. package/src/compression/rtk/filters/rubocop.json +34 -0
  61. package/src/compression/rtk/filters/ruff.json +40 -0
  62. package/src/compression/rtk/filters/shell-find.json +33 -0
  63. package/src/compression/rtk/filters/shell-grep.json +37 -0
  64. package/src/compression/rtk/filters/shell-ls.json +33 -0
  65. package/src/compression/rtk/filters/ssh.json +43 -0
  66. package/src/compression/rtk/filters/systemctl-status.json +43 -0
  67. package/src/compression/rtk/filters/terraform-plan.json +34 -0
  68. package/src/compression/rtk/filters/test-cargo.json +42 -0
  69. package/src/compression/rtk/filters/test-go.json +41 -0
  70. package/src/compression/rtk/filters/test-jest.json +43 -0
  71. package/src/compression/rtk/filters/test-pytest.json +41 -0
  72. package/src/compression/rtk/filters/test-vitest.json +43 -0
  73. package/src/compression/rtk/filters/tofu-plan.json +34 -0
  74. package/src/compression/rtk/filters/turbo.json +34 -0
  75. package/src/compression/rtk/filters/uv-sync.json +35 -0
  76. package/src/compression/rtk/filters/wget.json +34 -0
  77. package/src/compression/rtk/index.ts +103 -0
  78. package/src/compression/rtk/line-filter.ts +124 -0
  79. package/src/compression/rtk/smart-truncate.ts +71 -0
  80. package/src/config-defaults.ts +93 -0
  81. package/src/config-normalize.ts +48 -0
  82. package/src/config-storage.ts +21 -0
  83. package/src/dashboard.ts +1169 -0
  84. package/src/db-store.ts +188 -0
  85. package/src/doctor.ts +115 -0
  86. package/src/env.ts +15 -0
  87. package/src/exposure.ts +17 -0
  88. package/src/fetch-with-retry.ts +93 -0
  89. package/src/idempotency.ts +137 -0
  90. package/src/index.ts +267 -0
  91. package/src/key-auth.ts +159 -0
  92. package/src/key-migrations.ts +84 -0
  93. package/src/logger.ts +92 -0
  94. package/src/login.ts +48 -0
  95. package/src/notification-poller.ts +155 -0
  96. package/src/onboarding.ts +754 -0
  97. package/src/paths.ts +153 -0
  98. package/src/providers/adapter.ts +131 -0
  99. package/src/providers/credential-helpers.ts +72 -0
  100. package/src/providers/google-antigravity/code-assist.ts +161 -0
  101. package/src/providers/google-antigravity/credentials.ts +24 -0
  102. package/src/providers/google-antigravity/forward.ts +424 -0
  103. package/src/providers/google-antigravity/index.ts +168 -0
  104. package/src/providers/google-antigravity/login.ts +285 -0
  105. package/src/providers/google-antigravity/oauth.ts +314 -0
  106. package/src/providers/google-antigravity/quota.ts +152 -0
  107. package/src/providers/google-antigravity/translators.ts +1663 -0
  108. package/src/providers/ollama/api-key-validation.ts +59 -0
  109. package/src/providers/ollama/credentials.ts +28 -0
  110. package/src/providers/ollama/forward.ts +306 -0
  111. package/src/providers/ollama/index.ts +85 -0
  112. package/src/providers/ollama/login.ts +55 -0
  113. package/src/providers/ollama/prediction.ts +188 -0
  114. package/src/providers/ollama/quota-poll-store.ts +160 -0
  115. package/src/providers/ollama/quota.ts +189 -0
  116. package/src/providers/ollama/translators.ts +256 -0
  117. package/src/providers/ollama/usage-windows.ts +48 -0
  118. package/src/providers/proxy-dispatcher.ts +269 -0
  119. package/src/providers/registry.ts +70 -0
  120. package/src/proxy.ts +2446 -0
  121. package/src/rate-limit-parser.ts +126 -0
  122. package/src/response-headers.ts +98 -0
  123. package/src/responses-store.ts +159 -0
  124. package/src/rotator.ts +3614 -0
  125. package/src/settings-repository.ts +327 -0
  126. package/src/spend-logger.ts +696 -0
  127. package/src/static/dashboard-keys.js +384 -0
  128. package/src/static/dashboard-logs.js +797 -0
  129. package/src/static/dashboard.css +2740 -0
  130. package/src/static/dashboard.js +3177 -0
  131. package/src/storage.ts +105 -0
  132. package/src/systemd-env.ts +214 -0
  133. package/src/telemetry.ts +384 -0
  134. package/src/token-encryption.ts +199 -0
  135. package/src/types.ts +897 -0
  136. package/src/validators.ts +218 -0
  137. package/src/version-check.ts +225 -0
  138. package/src/virtual-keys.ts +312 -0
  139. package/tools/telemetry-receiver/README.md +147 -0
  140. package/tools/telemetry-receiver/package.json +13 -0
  141. package/tools/telemetry-receiver/receiver.js +2334 -0
  142. package/tuxevil-rotator_logo.png +0 -0
@@ -0,0 +1,43 @@
1
+ {
2
+ "id": "systemctl-status",
3
+ "label": "systemctl status",
4
+ "description": "Preserve unit status, active state, and journal errors.",
5
+ "category": "infra",
6
+ "priority": 77,
7
+ "match": {
8
+ "outputTypes": [],
9
+ "commands": ["^systemctl\\s+status\\b"],
10
+ "patterns": ["Loaded:", "Active:", "Main PID:"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "includePatterns": [
15
+ "Loaded:",
16
+ "Active:",
17
+ "Main PID:",
18
+ "CGroup:",
19
+ "error",
20
+ "failed",
21
+ "Started",
22
+ "Stopped"
23
+ ],
24
+ "dropPatterns": ["^\\s*$"],
25
+ "collapsePatterns": ["^\\s+Docs:"],
26
+ "deduplicate": true,
27
+ "maxLines": 100,
28
+ "headLines": 30,
29
+ "tailLines": 40
30
+ },
31
+ "preserve": {
32
+ "errorPatterns": ["failed", "error"],
33
+ "summaryPatterns": ["Active:", "Loaded:"]
34
+ },
35
+ "tests": [
36
+ {
37
+ "name": "inline sample",
38
+ "command": "systemctl status",
39
+ "input": "Loaded: loaded (/etc/systemd/system/app.service)\nActive: failed (Result: exit-code)\nMain PID: 123\nMay 1 app[123]: error boot failed\n",
40
+ "expected": "Loaded: loaded (/etc/systemd/system/app.service)\nActive: failed (Result: exit-code)\nMain PID: 123\nMay 1 app[123]: error boot failed"
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "id": "terraform-plan",
3
+ "label": "Terraform Plan",
4
+ "description": "Keep plan actions and summary while stripping refresh noise.",
5
+ "category": "infra",
6
+ "priority": 88,
7
+ "match": {
8
+ "outputTypes": [],
9
+ "commands": ["^terraform\\s+plan\\b"],
10
+ "patterns": ["Terraform will perform the following actions", "Plan: \\d+ to add"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "dropPatterns": ["Refreshing state", "Acquiring state lock", "Releasing state lock", "^\\s*$"],
15
+ "includePatterns": ["Terraform will perform", "^[ ]*[#~+\\-/]", "Plan: \\d+", "Error:"],
16
+ "collapsePatterns": [],
17
+ "deduplicate": false,
18
+ "maxLines": 160,
19
+ "headLines": 35,
20
+ "tailLines": 50
21
+ },
22
+ "preserve": {
23
+ "errorPatterns": ["Error:", "failed"],
24
+ "summaryPatterns": ["Plan: \\d+"]
25
+ },
26
+ "tests": [
27
+ {
28
+ "name": "inline sample",
29
+ "command": "terraform plan",
30
+ "input": "Refreshing state... [id=a]\nTerraform will perform the following actions:\n # aws_instance.web will be created\nPlan: 1 to add, 0 to change, 0 to destroy.\n",
31
+ "expected": "Terraform will perform the following actions:\n # aws_instance.web will be created\nPlan: 1 to add, 0 to change, 0 to destroy."
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "id": "test-cargo",
3
+ "label": "Cargo Test",
4
+ "description": "Keep Cargo test failures and final summary.",
5
+ "category": "test",
6
+ "priority": 90,
7
+ "match": {
8
+ "outputTypes": ["test-cargo"],
9
+ "commands": ["^cargo\\s+(?:test|nextest)\\b"],
10
+ "patterns": ["^running \\d+ tests?", "test result:"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "includePatterns": [
15
+ "^running \\d+ tests?",
16
+ "^test .* \\.\\.\\. FAILED",
17
+ "^failures:",
18
+ "^---- ",
19
+ "^thread ",
20
+ "^test result:",
21
+ "^error:"
22
+ ],
23
+ "dropPatterns": ["^test .* \\.\\.\\. ok$", "^\\s*$"],
24
+ "collapsePatterns": ["^\\s+at "],
25
+ "deduplicate": true,
26
+ "maxLines": 180,
27
+ "headLines": 40,
28
+ "tailLines": 70
29
+ },
30
+ "preserve": {
31
+ "errorPatterns": ["FAILED", "^error:", "^thread "],
32
+ "summaryPatterns": ["test result:"]
33
+ },
34
+ "tests": [
35
+ {
36
+ "name": "inline sample",
37
+ "command": "cargo (?:test|nextest)",
38
+ "input": "running 2 tests\ntest a ... ok\ntest b ... FAILED\nfailures:\n---- b stdout ----\nthread b panicked at boom\ntest result: FAILED. 1 passed; 1 failed\n",
39
+ "expected": "running 2 tests\ntest b ... FAILED\nfailures:\n---- b stdout ----\nthread b panicked at boom\ntest result: FAILED. 1 passed; 1 failed"
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "id": "test-go",
3
+ "label": "Go Test",
4
+ "description": "Keep failing Go tests and package summaries.",
5
+ "category": "test",
6
+ "priority": 90,
7
+ "match": {
8
+ "outputTypes": ["test-go"],
9
+ "commands": ["^go\\s+test\\b"],
10
+ "patterns": ["^--- FAIL:", "^(?:ok|FAIL)\\s+"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "includePatterns": [
15
+ "^--- FAIL:",
16
+ "^FAIL",
17
+ "^ok\\s+",
18
+ "^panic:",
19
+ "^\\s+.*_test\\.go:\\d+",
20
+ "^\\s*Error"
21
+ ],
22
+ "dropPatterns": ["^\\s*$"],
23
+ "collapsePatterns": ["^=== RUN"],
24
+ "deduplicate": true,
25
+ "maxLines": 160,
26
+ "headLines": 35,
27
+ "tailLines": 60
28
+ },
29
+ "preserve": {
30
+ "errorPatterns": ["^--- FAIL:", "^panic:", "^FAIL"],
31
+ "summaryPatterns": ["^ok\\s+", "^FAIL\\s+"]
32
+ },
33
+ "tests": [
34
+ {
35
+ "name": "inline sample",
36
+ "command": "go test",
37
+ "input": "=== RUN TestA\n--- FAIL: TestA (0.00s)\n a_test.go:1: boom\nFAIL\t./pkg\t0.1s\n",
38
+ "expected": "--- FAIL: TestA (0.00s)\n a_test.go:1: boom\nFAIL\t./pkg\t0.1s"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "id": "test-jest",
3
+ "label": "Jest",
4
+ "description": "Keep Jest failures and summary while removing passing noise.",
5
+ "category": "test",
6
+ "priority": 90,
7
+ "match": {
8
+ "outputTypes": ["test-jest"],
9
+ "commands": ["^(?:jest|npm\\s+(?:run\\s+)?test)\\b"],
10
+ "patterns": ["Test Suites:\\s+\\d+", "Tests:\\s+\\d+", "^PASS\\s+", "^FAIL\\s+"]
11
+ },
12
+ "rules": {
13
+ "includePatterns": [
14
+ "^FAIL\\s+",
15
+ "^\\s*●\\s+",
16
+ "Expected:",
17
+ "Received:",
18
+ "Test Suites:",
19
+ "Tests:",
20
+ "Snapshots:",
21
+ "Time:",
22
+ "\\s+at\\s+"
23
+ ],
24
+ "dropPatterns": ["^PASS\\s+", "^\\s*✓\\s+"],
25
+ "collapsePatterns": ["^\\s*at "],
26
+ "deduplicate": true,
27
+ "maxLines": 140,
28
+ "headLines": 24,
29
+ "tailLines": 50
30
+ },
31
+ "preserve": {
32
+ "errorPatterns": ["FAIL", "Expected:", "Received:", "Test Suites:"],
33
+ "summaryPatterns": []
34
+ },
35
+ "tests": [
36
+ {
37
+ "name": "inline sample",
38
+ "command": "(?:jest|npm (?:run )?test)",
39
+ "input": "PASS src/a.test.ts\nFAIL src/b.test.ts\nError: boom\nTest Suites: 1 failed, 1 passed\nTests: 1 failed, 1 passed\n",
40
+ "expected": "FAIL src/b.test.ts\nTest Suites: 1 failed, 1 passed\nTests: 1 failed, 1 passed"
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "id": "test-pytest",
3
+ "label": "Pytest",
4
+ "description": "Keep pytest failures, tracebacks and terminal summary.",
5
+ "category": "test",
6
+ "priority": 90,
7
+ "match": {
8
+ "outputTypes": ["test-pytest"],
9
+ "commands": ["^(?:pytest|python\\s+-m\\s+pytest)\\b"],
10
+ "patterns": ["=+\\s+(?:\\d+\\s+)?(?:passed|failed|errors?)", "^E\\s+", "^FAILED "]
11
+ },
12
+ "rules": {
13
+ "includePatterns": [
14
+ "^FAILED ",
15
+ "^ERROR ",
16
+ "^E\\s+",
17
+ "Traceback \\(most recent call last\\):",
18
+ "=+ short test summary info =+",
19
+ "=+ .*failed",
20
+ "AssertionError"
21
+ ],
22
+ "dropPatterns": ["^\\.", "^\\s*$"],
23
+ "collapsePatterns": ["^E\\s+"],
24
+ "deduplicate": true,
25
+ "maxLines": 160,
26
+ "headLines": 28,
27
+ "tailLines": 60
28
+ },
29
+ "preserve": {
30
+ "errorPatterns": ["FAILED", "ERROR", "Traceback", "AssertionError"],
31
+ "summaryPatterns": []
32
+ },
33
+ "tests": [
34
+ {
35
+ "name": "inline sample",
36
+ "command": "(?:pytest|python -m pytest)",
37
+ "input": "FAILED tests/test_a.py::test_a - AssertionError\nE assert 1 == 2\n================ 1 failed, 2 passed ================\n",
38
+ "expected": "FAILED tests/test_a.py::test_a - AssertionError\nE assert 1 == 2\n================ 1 failed, 2 passed ================"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "id": "test-vitest",
3
+ "label": "Vitest",
4
+ "description": "Keep failing suites, failed tests, stack headers, and final summary.",
5
+ "category": "test",
6
+ "priority": 92,
7
+ "match": {
8
+ "outputTypes": ["test-vitest"],
9
+ "commands": ["^(?:vitest|npm\\s+(?:run\\s+)?test:vitest)\\b"],
10
+ "patterns": ["\\bvitest\\b", "^ ✓ ", "^ ❯ ", "Test Files\\s+\\d+\\s+(?:passed|failed)"]
11
+ },
12
+ "rules": {
13
+ "includePatterns": [
14
+ "^\\s*FAIL\\s+",
15
+ "^\\s*❯\\s+",
16
+ "^\\s*×\\s+",
17
+ "Test Files\\s+",
18
+ "Tests\\s+",
19
+ "Duration\\s+",
20
+ "Error:",
21
+ "AssertionError",
22
+ "\\s+at\\s+"
23
+ ],
24
+ "dropPatterns": ["^\\s*✓\\s+", "^\\s*stdout \\|", "^\\s*stderr \\|"],
25
+ "collapsePatterns": ["^\\s*at "],
26
+ "deduplicate": true,
27
+ "maxLines": 140,
28
+ "headLines": 24,
29
+ "tailLines": 50
30
+ },
31
+ "preserve": {
32
+ "errorPatterns": ["FAIL", "Error:", "AssertionError", "Test Files"],
33
+ "summaryPatterns": []
34
+ },
35
+ "tests": [
36
+ {
37
+ "name": "inline sample",
38
+ "command": "(?:vitest|npm (?:run )?test:vitest)",
39
+ "input": " ✓ src/a.test.ts (1)\n ❯ src/b.test.ts (1)\n FAIL src/b.test.ts > fails\nError: boom\nTest Files 1 failed | 1 passed\nTests 1 failed | 1 passed\n",
40
+ "expected": " ❯ src/b.test.ts (1)\n FAIL src/b.test.ts > fails\nError: boom\nTest Files 1 failed | 1 passed\nTests 1 failed | 1 passed"
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "id": "tofu-plan",
3
+ "label": "OpenTofu Plan",
4
+ "description": "Keep OpenTofu plan actions and summary while stripping refresh noise.",
5
+ "category": "infra",
6
+ "priority": 87,
7
+ "match": {
8
+ "outputTypes": [],
9
+ "commands": ["^tofu\\s+plan\\b"],
10
+ "patterns": ["OpenTofu will perform the following actions", "Plan: \\d+ to add"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "dropPatterns": ["Refreshing state", "Acquiring state lock", "Releasing state lock", "^\\s*$"],
15
+ "includePatterns": ["OpenTofu will perform", "^[ ]*[#~+\\-/]", "Plan: \\d+", "Error:"],
16
+ "collapsePatterns": [],
17
+ "deduplicate": false,
18
+ "maxLines": 160,
19
+ "headLines": 35,
20
+ "tailLines": 50
21
+ },
22
+ "preserve": {
23
+ "errorPatterns": ["Error:", "failed"],
24
+ "summaryPatterns": ["Plan: \\d+"]
25
+ },
26
+ "tests": [
27
+ {
28
+ "name": "inline sample",
29
+ "command": "tofu plan",
30
+ "input": "Refreshing state... [id=a]\nOpenTofu will perform the following actions:\n # tofu_resource.web will be created\nPlan: 1 to add, 0 to change, 0 to destroy.\n",
31
+ "expected": "OpenTofu will perform the following actions:\n # tofu_resource.web will be created\nPlan: 1 to add, 0 to change, 0 to destroy."
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "id": "turbo",
3
+ "label": "Turborepo",
4
+ "description": "Compact turbo task cache and failure output.",
5
+ "category": "build",
6
+ "priority": 76,
7
+ "match": {
8
+ "outputTypes": [],
9
+ "commands": ["^turbo\\b", "^npx\\s+turbo\\b"],
10
+ "patterns": ["Tasks:", "Remote caching"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "dropPatterns": ["cache hit", "cache miss", "^\\s*$"],
15
+ "includePatterns": ["failed", "error", "Tasks:", "Cached:", "Time:", "successful"],
16
+ "collapsePatterns": ["^• Packages in scope"],
17
+ "deduplicate": true,
18
+ "maxLines": 120,
19
+ "headLines": 25,
20
+ "tailLines": 50
21
+ },
22
+ "preserve": {
23
+ "errorPatterns": ["failed", "error"],
24
+ "summaryPatterns": ["Tasks:", "Cached:", "Time:"]
25
+ },
26
+ "tests": [
27
+ {
28
+ "name": "inline sample",
29
+ "command": "turbo",
30
+ "input": "cache hit app#build\napp#test: failed\nTasks: 1 successful, 1 failed\nTime: 2s\n",
31
+ "expected": "app#test: failed\nTasks: 1 successful, 1 failed\nTime: 2s"
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "id": "uv-sync",
3
+ "label": "uv sync",
4
+ "description": "Compact uv sync/install output.",
5
+ "category": "package",
6
+ "priority": 72,
7
+ "match": {
8
+ "outputTypes": [],
9
+ "commands": ["^uv\\s+sync\\b", "^uv\\s+pip\\s+install\\b"],
10
+ "patterns": ["Resolved \\d+ packages?", "Prepared \\d+ packages?"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "dropPatterns": ["^Resolved ", "^Prepared ", "^Installed ", "^ \\+", "^\\s*$"],
15
+ "includePatterns": ["error", "failed", "Installed", "Uninstalled", "Resolved"],
16
+ "collapsePatterns": [],
17
+ "deduplicate": true,
18
+ "maxLines": 100,
19
+ "headLines": 25,
20
+ "tailLines": 35,
21
+ "onEmpty": "uv: ok"
22
+ },
23
+ "preserve": {
24
+ "errorPatterns": ["error", "failed"],
25
+ "summaryPatterns": ["Installed", "Resolved"]
26
+ },
27
+ "tests": [
28
+ {
29
+ "name": "inline sample",
30
+ "command": "uv sync",
31
+ "input": "Resolved 10 packages in 1ms\nInstalled 10 packages in 2ms\n",
32
+ "expected": "uv: ok"
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "id": "wget",
3
+ "label": "wget",
4
+ "description": "Remove wget progress output and keep final errors or saved-file summaries.",
5
+ "category": "cloud",
6
+ "priority": 70,
7
+ "match": {
8
+ "outputTypes": ["wget"],
9
+ "commands": ["^wget\\b"],
10
+ "patterns": ["^--\\d{4}-\\d{2}-\\d{2}", "^ERROR \\d{3}:"]
11
+ },
12
+ "rules": {
13
+ "stripAnsi": true,
14
+ "dropPatterns": ["^\\s*\\d+K", "^Saving to:", "^\\s*$"],
15
+ "includePatterns": ["^ERROR \\d{3}:", "saved \\[\\d", "^HTTP request sent"],
16
+ "collapsePatterns": [],
17
+ "deduplicate": true,
18
+ "maxLines": 100,
19
+ "headLines": 25,
20
+ "tailLines": 40
21
+ },
22
+ "preserve": {
23
+ "errorPatterns": ["^ERROR \\d{3}:", "failed", "unable to resolve"],
24
+ "summaryPatterns": ["saved \\[\\d", "^HTTP request sent"]
25
+ },
26
+ "tests": [
27
+ {
28
+ "name": "inline sample",
29
+ "command": "wget",
30
+ "input": "--2026-05-02-- https://example.test/file\nSaving to: 'file'\nHTTP request sent, awaiting response... 404 Not Found\nERROR 404: Not Found.\n",
31
+ "expected": "HTTP request sent, awaiting response... 404 Not Found\nERROR 404: Not Found."
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,103 @@
1
+ import type { ChatMessage } from "../../providers/google-antigravity/translators.js";
2
+ import {
3
+ extractPreservedBlocks,
4
+ restorePreservedBlocks,
5
+ } from "../preservation.js";
6
+ import { detectCommandType } from "./command-detector.js";
7
+ import { matchRtkFilter } from "./filter-loader.js";
8
+ import { applyLineFilter } from "./line-filter.js";
9
+
10
+ export interface RtkCompressionResult {
11
+ messages: ChatMessage[];
12
+ compressed: boolean;
13
+ techniquesUsed: string[];
14
+ appliedRules: string[];
15
+ linesStripped: number;
16
+ }
17
+
18
+ const _SHELL_TOOL_NAME_RE =
19
+ /\b(bash|shell|terminal|run_command|execute_command|exec|command)\b/i;
20
+
21
+ function isToolOrTerminalMessage(msg: ChatMessage): boolean {
22
+ if (msg.role === "tool") return true;
23
+ if (typeof msg.content === "string") {
24
+ // Check if string content has tool output markers
25
+ if (msg.content.includes("Command output:") || msg.content.includes("stdout:") || msg.content.includes("stderr:")) {
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ }
31
+
32
+ export function compressRTK(
33
+ messages: ChatMessage[],
34
+ options?: {
35
+ enabledFilters?: string[];
36
+ disabledFilters?: string[];
37
+ maxLinesPerResult?: number;
38
+ },
39
+ ): RtkCompressionResult {
40
+ const techniquesUsed: string[] = [];
41
+ const appliedRules: string[] = [];
42
+ let linesStripped = 0;
43
+ let compressed = false;
44
+
45
+ const resultMessages = messages.map((msg) => {
46
+ if (!isToolOrTerminalMessage(msg)) return msg;
47
+
48
+ let contentText = "";
49
+ if (typeof msg.content === "string") {
50
+ contentText = msg.content;
51
+ } else if (Array.isArray(msg.content)) {
52
+ contentText = msg.content
53
+ .map((part) => (typeof part === "string" ? part : part.text || ""))
54
+ .join("\n");
55
+ }
56
+
57
+ if (!contentText || contentText.length < 100) return msg;
58
+
59
+ // Preserve code, URLs, paths etc. before filtering lines
60
+ const preservation = extractPreservedBlocks(contentText);
61
+
62
+ const detection = detectCommandType(preservation.text);
63
+ const filter = matchRtkFilter(detection.type, detection.command, preservation.text);
64
+
65
+ if (!filter) return msg;
66
+
67
+ if (
68
+ options?.disabledFilters &&
69
+ options.disabledFilters.includes(filter.id)
70
+ ) {
71
+ return msg;
72
+ }
73
+
74
+ const filterRes = applyLineFilter(preservation.text, filter);
75
+ linesStripped += filterRes.strippedLines;
76
+
77
+ if (filterRes.strippedLines > 0 || filterRes.appliedRules.length > 0) {
78
+ compressed = true;
79
+ if (!techniquesUsed.includes(`rtk:${filter.id}`)) {
80
+ techniquesUsed.push(`rtk:${filter.id}`);
81
+ }
82
+ appliedRules.push(...filterRes.appliedRules);
83
+ }
84
+
85
+ const restoredText = restorePreservedBlocks(
86
+ filterRes.text,
87
+ preservation.blocks,
88
+ );
89
+
90
+ return {
91
+ ...msg,
92
+ content: restoredText,
93
+ };
94
+ });
95
+
96
+ return {
97
+ messages: resultMessages,
98
+ compressed,
99
+ techniquesUsed,
100
+ appliedRules,
101
+ linesStripped,
102
+ };
103
+ }
@@ -0,0 +1,124 @@
1
+ import type { RtkFilterDefinition } from "./filter-types.js";
2
+ import { smartTruncate } from "./smart-truncate.js";
3
+ import { deduplicateRepeatedLines } from "./deduplicator.js";
4
+
5
+ export interface LineFilterResult {
6
+ text: string;
7
+ strippedLines: number;
8
+ keptByRule: boolean;
9
+ appliedRules: string[];
10
+ }
11
+
12
+ const regexCache = new Map<string, RegExp>();
13
+
14
+ function getRegex(pattern: string, flags = "i"): RegExp | null {
15
+ const key = `${pattern}::${flags}`;
16
+ let re = regexCache.get(key);
17
+ if (!re) {
18
+ try {
19
+ re = new RegExp(pattern, flags);
20
+ regexCache.set(key, re);
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+ return re;
26
+ }
27
+
28
+ function stripAnsi(text: string): string {
29
+ // eslint-disable-next-line no-control-regex
30
+ return text.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "");
31
+ }
32
+
33
+ export function applyLineFilter(
34
+ text: string,
35
+ filter: RtkFilterDefinition,
36
+ ): LineFilterResult {
37
+ const appliedRules: string[] = [];
38
+ let currentText = text;
39
+
40
+ if (filter.rules?.stripAnsi !== false) {
41
+ currentText = stripAnsi(currentText);
42
+ appliedRules.push("strip-ansi");
43
+ }
44
+
45
+ const lines = currentText.split(/\r?\n/);
46
+ const totalOriginalLines = lines.length;
47
+ const filteredLines: string[] = [];
48
+
49
+ const dropRegexes = (filter.rules?.dropPatterns || [])
50
+ .map((p) => getRegex(p))
51
+ .filter((r): r is RegExp => r !== null);
52
+
53
+ const includeRegexes = (filter.rules?.includePatterns || [])
54
+ .map((p) => getRegex(p))
55
+ .filter((r): r is RegExp => r !== null);
56
+
57
+ const errorRegexes = (filter.preserve?.errorPatterns || [])
58
+ .map((p) => getRegex(p))
59
+ .filter((r): r is RegExp => r !== null);
60
+
61
+ const summaryRegexes = (filter.preserve?.summaryPatterns || [])
62
+ .map((p) => getRegex(p))
63
+ .filter((r): r is RegExp => r !== null);
64
+
65
+ for (const line of lines) {
66
+ const isError = errorRegexes.some((r) => r.test(line));
67
+ const isSummary = summaryRegexes.some((r) => r.test(line));
68
+
69
+ if (isError || isSummary) {
70
+ filteredLines.push(line);
71
+ continue;
72
+ }
73
+
74
+ if (dropRegexes.length > 0) {
75
+ const shouldDrop = dropRegexes.some((r) => r.test(line));
76
+ if (shouldDrop) {
77
+ continue;
78
+ }
79
+ }
80
+
81
+ if (includeRegexes.length > 0) {
82
+ const shouldInclude = includeRegexes.some((r) => r.test(line));
83
+ if (!shouldInclude) {
84
+ continue;
85
+ }
86
+ }
87
+
88
+ filteredLines.push(line);
89
+ }
90
+
91
+ let resultText = filteredLines.join("\n");
92
+
93
+ if (filter.rules?.collapseDuplicates !== false) {
94
+ const dedup = deduplicateRepeatedLines(resultText);
95
+ resultText = dedup.text;
96
+ if (dedup.collapsed > 0) {
97
+ appliedRules.push(`dedup:${dedup.collapsed}`);
98
+ }
99
+ }
100
+
101
+ const maxLines = filter.rules?.maxLines || filter.rtkTomlMaxLines || 100;
102
+ if (resultText.split("\n").length > maxLines) {
103
+ const truncated = smartTruncate(resultText, {
104
+ maxLines,
105
+ preserveHead: filter.rtkTomlHeadLines || 15,
106
+ preserveTail: filter.rtkTomlTailLines || 15,
107
+ priorityPatterns: [...errorRegexes, ...summaryRegexes],
108
+ });
109
+ resultText = truncated.text;
110
+ appliedRules.push("smart-truncate");
111
+ }
112
+
113
+ const strippedLines = Math.max(
114
+ 0,
115
+ totalOriginalLines - resultText.split("\n").length,
116
+ );
117
+
118
+ return {
119
+ text: resultText,
120
+ strippedLines,
121
+ keptByRule: filteredLines.length > 0,
122
+ appliedRules,
123
+ };
124
+ }