@levnikolaevich/hex-line-mcp 1.3.3 → 1.3.5

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/lib/changes.mjs DELETED
@@ -1,176 +0,0 @@
1
- /**
2
- * Semantic diff: compare file against git ref using AST outlines.
3
- *
4
- * Shows added/removed/modified symbols — no line-level noise.
5
- * Uses outlineFromContent() to parse both current and git versions
6
- * without temp files.
7
- */
8
-
9
- import { execFileSync } from "node:child_process";
10
- import { statSync } from "node:fs";
11
- import { extname } from "node:path";
12
- import { validatePath, normalizePath } from "./security.mjs";
13
- import { readText } from "./format.mjs";
14
- import { outlineFromContent } from "./outline.mjs";
15
-
16
- /**
17
- * Extract symbol name from outline text.
18
- * Strips parameters, braces, generics — keeps the identifier.
19
- *
20
- * "export async function fileOutline(filePath)" → "fileOutline"
21
- * "const LANG_CONFIGS = {" → "LANG_CONFIGS"
22
- * "class MyClass extends Base {" → "MyClass"
23
- */
24
- function symbolName(text) {
25
- // Remove trailing { and whitespace
26
- const clean = text.replace(/\s*\{?\s*$/, "").trim();
27
- // Remove everything from first ( onward (params)
28
- const noParams = clean.replace(/\(.*$/, "").trim();
29
- // Take last word — that's the identifier
30
- const parts = noParams.split(/\s+/);
31
- // Skip assignment: "const X = ..." → take word before "="
32
- const eqIdx = parts.indexOf("=");
33
- if (eqIdx > 0) return parts[eqIdx - 1];
34
- return parts[parts.length - 1] || text;
35
- }
36
-
37
- /**
38
- * Parse outline entries into comparable symbol list.
39
- */
40
- function toSymbolMap(entries) {
41
- const map = new Map();
42
- for (const e of entries) {
43
- const name = symbolName(e.text);
44
- const lines = e.end - e.start + 1;
45
- map.set(name, { name, text: e.text, lines, start: e.start, end: e.end });
46
- }
47
- return map;
48
- }
49
-
50
- /**
51
- * Get relative path from git root for `git show`.
52
- */
53
- function gitRelativePath(absPath) {
54
- const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
55
- cwd: absPath.replace(/[/\\][^/\\]+$/, ""),
56
- encoding: "utf-8",
57
- timeout: 5000,
58
- }).trim().replace(/\\/g, "/");
59
-
60
- const normalized = absPath.replace(/\\/g, "/");
61
- // Ensure root and path are comparable (case-insensitive on Windows)
62
- const rootLower = root.toLowerCase();
63
- const pathLower = normalized.toLowerCase();
64
- if (!pathLower.startsWith(rootLower)) {
65
- throw new Error(`File ${absPath} is not inside git repo ${root}`);
66
- }
67
- return normalized.slice(root.length + 1);
68
- }
69
-
70
- /**
71
- * Compare file against git ref, returning semantic symbol diff.
72
- *
73
- * @param {string} filePath File path (absolute or relative)
74
- * @param {string} compareAgainst Git ref (default: "HEAD")
75
- * @returns {Promise<string>} Formatted diff
76
- */
77
- export async function fileChanges(filePath, compareAgainst = "HEAD") {
78
- filePath = normalizePath(filePath);
79
- const real = validatePath(filePath);
80
-
81
- // Directory: return git diff --stat (compact file list, no content reads)
82
- if (statSync(real).isDirectory()) {
83
- try {
84
- const stat = execFileSync("git", ["diff", "--stat", compareAgainst, "--", "."], {
85
- cwd: real,
86
- encoding: "utf-8",
87
- timeout: 10000,
88
- }).trim();
89
- if (!stat) return `No changes in ${filePath} vs ${compareAgainst}`;
90
- return `Changed files in ${filePath} vs ${compareAgainst}:\n\n${stat}\n\nUse changes on a specific file for symbol-level diff.`;
91
- } catch {
92
- return `No git history for ${filePath} or not a git repository.`;
93
- }
94
- }
95
-
96
- const ext = extname(real).toLowerCase();
97
-
98
- // Check if outline supports this extension
99
- const currentContent = readText(real);
100
- const currentResult = await outlineFromContent(currentContent, ext);
101
- if (!currentResult) {
102
- return `Cannot outline ${ext} files. Supported: .js .mjs .ts .py .go .rs .java .c .cpp .cs .rb .php .kt .swift .sh .bash`;
103
- }
104
-
105
- // Get git version
106
- const relPath = gitRelativePath(real);
107
- let gitContent;
108
- try {
109
- gitContent = execFileSync("git", ["show", `${compareAgainst}:${relPath}`], {
110
- cwd: real.replace(/[/\\][^/\\]+$/, ""),
111
- encoding: "utf-8",
112
- timeout: 5000,
113
- }).replace(/\r\n/g, "\n");
114
- } catch {
115
- return `NEW FILE: ${filePath} (not in ${compareAgainst})`;
116
- }
117
-
118
- // Outline the git version from content — no temp files
119
- const gitResult = await outlineFromContent(gitContent, ext);
120
- if (!gitResult) {
121
- return `Cannot outline git version of ${filePath}`;
122
- }
123
-
124
- // Compare symbol maps
125
- const currentMap = toSymbolMap(currentResult.entries);
126
- const gitMap = toSymbolMap(gitResult.entries);
127
-
128
- const added = [];
129
- const removed = [];
130
- const modified = [];
131
-
132
- for (const [name, sym] of currentMap) {
133
- if (!gitMap.has(name)) {
134
- added.push(sym);
135
- } else {
136
- const gitSym = gitMap.get(name);
137
- if (gitSym.lines !== sym.lines) {
138
- modified.push({ current: sym, git: gitSym });
139
- }
140
- }
141
- }
142
- for (const [name, sym] of gitMap) {
143
- if (!currentMap.has(name)) {
144
- removed.push(sym);
145
- }
146
- }
147
-
148
- // Format
149
- const parts = [`Changes in ${filePath} vs ${compareAgainst}:`];
150
-
151
- if (added.length) {
152
- parts.push("\nAdded:");
153
- for (const s of added) parts.push(` + ${s.start}-${s.end}: ${s.text}`);
154
- }
155
- if (removed.length) {
156
- parts.push("\nRemoved:");
157
- for (const s of removed) parts.push(` - ${s.start}-${s.end}: ${s.text}`);
158
- }
159
- if (modified.length) {
160
- parts.push("\nModified:");
161
- for (const m of modified) {
162
- const delta = m.current.lines - m.git.lines;
163
- const sign = delta > 0 ? "+" : "";
164
- parts.push(` ~ ${m.current.start}-${m.current.end}: ${m.current.text} (${sign}${delta} lines)`);
165
- }
166
- }
167
-
168
- if (!added.length && !removed.length && !modified.length) {
169
- parts.push("\nNo symbol changes detected.");
170
- }
171
-
172
- const summary = `${added.length} added, ${removed.length} removed, ${modified.length} modified`;
173
- parts.push(`\nSummary: ${summary}`);
174
-
175
- return parts.join("\n");
176
- }
package/lib/coerce.mjs DELETED
@@ -1 +0,0 @@
1
- export * from "@levnikolaevich/hex-common/runtime/coerce";