@sitrozyi/repomix-semantic-compressor 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sitrozyi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # repomix-semantic-compressor
2
+
3
+ [![test](https://github.com/Sitrozyi/repomix-semantic-compressor/actions/workflows/test.yml/badge.svg)](https://github.com/Sitrozyi/repomix-semantic-compressor/actions/workflows/test.yml)
4
+
5
+ Context compressor for Repomix. On tested repositories it reduces prompt tokens by 45–80% by replacing function bodies while preserving type contracts, interfaces, docstrings, and database schemas ([Benchmark](#benchmark)).
6
+
7
+ - **TypeScript / JavaScript**: Full AST-based compression via Babel. Function bodies are replaced with `throw new Error(...)` (inferred `never` return type), so strict type checkers pass without `any` escapes. React hook dependency arrays (`useEffect`, `useMemo`) are retained. Constructors and setters are the exception: constructors are emptied while preserving `super()` calls, and setters are emptied, since injecting `throw` there would break class initialization or violate the `set` contract.
8
+ - **Python / Go**: Line-based function stubbing. Signatures and leading `"""docstrings"""` are preserved; Python bodies become `raise NotImplementedError`, Go bodies become `panic(...)`.
9
+ - **Focus Mode** currently resolves imports and dependency graphs for TypeScript / JavaScript only. Python and Go files are compressed in full-repo mode but not dependency-traced.
10
+
11
+ ![Demo](./assets/repomix-compressor-demo.gif)
12
+
13
+ ## How It Compresses
14
+
15
+ - **Action/Event Protocol Extraction (TS/JS)**: For truncated reducers, emitters, and dispatchers, `switch (action.type)` cases, `emitter.emit('X')`, `dispatch({ type: 'X' })`, and `action.payload.foo` destructuring are summarized into a single `@payloads` line (e.g. `LOGIN_USER(userId, authToken)`), preserving the wire contract without the implementation.
16
+ - **Domain Logic Protection**: Keeps implementations intact for utility/logic functions matching `is*`, `has*`, `can*`, `calc*`, `validate*`, `check*`, etc.
17
+ - **Schemas & Assets**: Retains SQL DDL (`CREATE TABLE`) while truncating bulk `INSERT` seeds. Keeps CSS `:root` tokens and layout properties while omitting decorative rules. Truncates long SVG paths and base64 strings.
18
+ - **JSON**: Minifies JSON artifacts by parsing and re-serializing them, stripping redundant whitespace and trailing commas. No structural transformation is applied.
19
+ - **YAML**: Strips full-line comments and collapses blank runs, while leaving block scalars (`|`, `>`) verbatim since their content is string data, not comments.
20
+ - **Dockerfile**: Collapses long multi-line `RUN` instructions while preserving stage structure (`FROM`, `COPY`, `CMD`, `ENTRYPOINT`) and all other directives.
21
+ - **Markdown**: Truncates fenced code blocks longer than 32 lines. Headings, prose, tables, and short examples are preserved verbatim.
22
+
23
+ ## Usage
24
+
25
+ Run in your repository root. Auto-pack is enabled by default: if `repomix-output.xml` does not exist, it runs `npx repomix` automatically. Pass `--no-auto-pack` to disable this.
26
+
27
+ ```bash
28
+ npx repomix-semantic-compressor
29
+ ```
30
+
31
+ ### Options
32
+
33
+ | Option | Description |
34
+ | :--- | :--- |
35
+ | `-f, --focus <path>` | Retain full implementation for target path/module; skeletonize 1-hop imports; summarize the rest (TS/JS only) |
36
+ | `-o, --output <file>` | Output file path (default: `repomix-optimized.md`) |
37
+ | `-i, --input <file>` | Input artifact path (`.xml` or `.json`) |
38
+ | `-m, --max-preserve-lines <n>` | Max lines to keep without truncation (default: `8`). For TS/JS this counts the whole function including signature; for Python/Go it counts the body only. |
39
+ | `-e, --exact-tokens` | Use the exact `cl100k_base` BPE tokenizer instead of byte approximation |
40
+ | `--no-auto-pack` | Disable automatic Repomix execution if artifact is missing |
41
+
42
+ ### Focus Mode
43
+
44
+ Keep full code for the module you are editing and reduce everything else to skeletons or summaries:
45
+
46
+ ```bash
47
+ npx repomix-semantic-compressor --focus src/auth -o auth-context.md
48
+ ```
49
+
50
+ Dependency tracing (import resolution, 1-hop dependency skeletons) is currently implemented for TypeScript / JavaScript. Files matching type/contract paths (`types/`, `interfaces/`, `models/`, `schemas/`, `constants/`, `contracts/`, `entities/`, and `*.d.ts`) are transitively followed so that type information stays complete. For Python and Go, Focus Mode still emits full implementations for matched files, but non-focused files are not dependency-resolved.
51
+
52
+ ## MCP Server (Cursor / Claude Desktop / Windsurf)
53
+
54
+ Exposes semantic skeleton extraction and file inspection as MCP tools. Add to your MCP configuration:
55
+
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "repomix-semantic-compressor": {
60
+ "command": "npx",
61
+ "args": ["-y", "repomix-semantic-compressor", "--mcp"]
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ ### Exposed Tools
68
+
69
+ - `get_repo_skeleton`: Returns the compressed semantic skeleton of the workspace.
70
+ - `get_file_implementation`: Retrieves uncompressed full source code for a specific file.
71
+ - `compress_repomix_file`: Compresses a repomix artifact to a destination file.
72
+
73
+ ## Benchmark
74
+
75
+ Measured on 2026-09-12 on real-world repositories. Token counts use byte-length approximation (`bytes / 3.8`); run with `--exact-tokens` for exact `cl100k_base` BPE counts.
76
+
77
+ | Repository | Language | Size (before) | Size (after) | Tokens (before) | Tokens (after) | Reduction |
78
+ | :--- | :--- | ---: | ---: | ---: | ---: | ---: |
79
+ | `sindresorhus/ky` | TypeScript | 737 kB | 382 kB | 198,637 | 102,929 | **-48.2%** |
80
+ | `honojs/hono` | TypeScript | 2,774 kB | 839 kB | 747,527 | 225,979 | **-69.8%** |
81
+ | `tailwindlabs/tailwindcss` | JS / CSS | 5,138 kB | 2,183 kB | 1,384,441 | 588,376 | **-57.5%** |
82
+ | `gin-gonic/gin` | Go | 849 kB | 454 kB | 228,807 | 122,329 | **-46.5%** |
83
+
84
+ To reproduce:
85
+
86
+ ```bash
87
+ git clone https://github.com/Sitrozyi/repomix-semantic-compressor
88
+ cd repomix-semantic-compressor
89
+ npm install
90
+ npm run benchmark
91
+ ```
92
+
93
+ `npm run benchmark` runs all four repositories shown in the table above. You can also pass a custom repository URL directly:
94
+
95
+ ```bash
96
+ npm run benchmark -- https://github.com/gin-gonic/gin.git
97
+ ```
98
+
99
+ ## Requirements
100
+
101
+ - Node.js >= 18.3.0 (uses `node:worker_threads` and the global `performance` API).
102
+
103
+ ## License
104
+
105
+ MIT (c) 2026 Sitrozyi
package/bin/cli.mjs ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { main } from '../src/core.mjs';
4
+ import { startMCPServer } from '../src/mcp.mjs';
5
+
6
+ if (process.argv.includes('--mcp')) {
7
+ startMCPServer().catch((err) => {
8
+ console.error(`MCP server fatal error: ${err.message}`);
9
+ process.exit(1);
10
+ });
11
+ } else {
12
+ main().catch((err) => {
13
+ console.error(`fatal error: ${err.message}`);
14
+ process.exit(1);
15
+ });
16
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { startMCPServer } from '../src/mcp.mjs';
4
+
5
+ startMCPServer().catch((err) => {
6
+ console.error(`MCP Server fatal error: ${err.message}`);
7
+ process.exit(1);
8
+ });
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@sitrozyi/repomix-semantic-compressor",
3
+ "version": "0.1.2",
4
+ "description": "AST-powered semantic compressor for Repomix. Drastically reduce LLM context token usage while preserving complete schema integrity and core logic.",
5
+ "main": "src/core.mjs",
6
+ "exports": {
7
+ ".": "./src/core.mjs",
8
+ "./package.json": "./package.json"
9
+ },
10
+ "bin": {
11
+ "repomix-semantic-compressor": "bin/cli.mjs",
12
+ "repomix-compress": "bin/cli.mjs",
13
+ "rsc": "bin/cli.mjs",
14
+ "repomix-compress-mcp": "bin/mcp-server.mjs"
15
+ },
16
+ "type": "module",
17
+ "keywords": [
18
+ "repomix",
19
+ "repopack",
20
+ "llm",
21
+ "token-reduction",
22
+ "ast",
23
+ "babel",
24
+ "prompt-optimization",
25
+ "claude",
26
+ "chatgpt"
27
+ ],
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/Sitrozyi/repomix-semantic-compressor.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/Sitrozyi/repomix-semantic-compressor/issues"
34
+ },
35
+ "homepage": "https://github.com/Sitrozyi/repomix-semantic-compressor#readme",
36
+ "author": "Sitrozyi",
37
+ "license": "MIT",
38
+ "files": [
39
+ "bin",
40
+ "src",
41
+ "README.md",
42
+ "LICENSE"
43
+ ],
44
+ "scripts": {
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "mcp": "node bin/mcp-server.mjs",
48
+ "benchmark": "node benchmarks/run.mjs"
49
+ },
50
+ "dependencies": {
51
+ "@babel/generator": "^7.24.0",
52
+ "@babel/parser": "^7.24.0",
53
+ "@babel/traverse": "^7.24.0",
54
+ "@modelcontextprotocol/sdk": "^1.30.0",
55
+ "fast-xml-parser": "^4.4.0",
56
+ "js-tiktoken": "^1.0.21",
57
+ "postcss": "^8.5.26"
58
+ },
59
+ "devDependencies": {
60
+ "vitest": "^1.6.0"
61
+ },
62
+ "engines": {
63
+ "node": ">=18.3.0"
64
+ }
65
+ }