Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ three lines:
```
// [Focused Emitter] Tokens without tool: 7,083 → with tool: 3,133 (55% saved)
// vs a targeted read of just the relevant code (4,200 tokens): 25% saved
// session: 4 calls · raw saved 24,800 · net of 2,100 one-time MCP overhead = 22,700
// session: 4 calls · saved 24,800 · net 22,700 after 2,100 overhead
```
The first line compares against reading the **whole file** (a best case); the
second, when present, compares against reading **only the relevant code** (a
Expand All @@ -211,8 +211,8 @@ were guaranteed. If the second line is present, prefer it or give the range, e.g
"Used the focused emitter — saved ~25-55% tokens vs. reading the file."

If you view the **same file more than once** in a session (a different method, or
outline-then-minify), the first line is replaced by `repeat view of this file
this session — whole-file baseline already counted ...`. A file only costs its
outline-then-minify), the first line is replaced by `repeat view — whole-file
baseline already counted; adds N tokens ...`. A file only costs its
whole-file tokens once, so later views aren't credited that saving again and the
session total counts each file's baseline a single time. Don't re-report the
whole-file "% saved" for a repeat view — it was already counted on the first.
3 changes: 1 addition & 2 deletions Emitters/CEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public LanguageEmitResult Minify(string filePath)

var source = File.ReadAllText(filePath);
var output = CppMinifier.StripAndCollapse(source);
var notes = $"// C minify of {Path.GetFileName(filePath)}\n" +
$"// Comments stripped, whitespace collapsed, #directives preserved\n";
var notes = $"// C minify of {Path.GetFileName(filePath)} — comments stripped, whitespace collapsed, #directives preserved\n";
return new LanguageEmitResult(Found: true, Output: output,
OriginalChars: source.Length, OutputChars: output.Length, Notes: notes);
}
Expand Down
3 changes: 1 addition & 2 deletions Emitters/CppEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public LanguageEmitResult Minify(string filePath)

var source = File.ReadAllText(filePath);
var output = CppMinifier.StripAndCollapse(source);
var notes = $"// C++ minify of {Path.GetFileName(filePath)}\n" +
$"// Comments stripped, whitespace collapsed, #directives preserved\n";
var notes = $"// C++ minify of {Path.GetFileName(filePath)} — comments stripped, whitespace collapsed, #directives preserved\n";
return new LanguageEmitResult(Found: true, Output: output,
OriginalChars: source.Length, OutputChars: output.Length, Notes: notes);
}
Expand Down
3 changes: 1 addition & 2 deletions Emitters/CssEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = Strip(source);
var notes =
$"/* CSS minify of {Path.GetFileName(filePath)} */\n" +
$"/* Comments stripped, whitespace collapsed */\n";
$"/* CSS minify of {Path.GetFileName(filePath)} — comments stripped, whitespace collapsed */\n";

return new LanguageEmitResult(
Found: true,
Expand Down
30 changes: 9 additions & 21 deletions Emitters/FocusedEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,10 @@ IdentifierNameSyntax id when id.Parent is not MemberAccessExpressionSyntax
var originalLength = _tree.GetText().Length;

var notes = new StringBuilder();
notes.AppendLine($"// Focused emission of {Path.GetFileName(_tree.FilePath)}");
notes.AppendLine($"// Focus method(s): {allFocusMethods.Count} method(s) with full body ({string.Join(", ", foundNames)})");
var helperNote = depth >= 1 ? $" · helpers (depth {depth}): {expandedMethods.Count} full body" : "";
notes.AppendLine($"// Focused emission of {Path.GetFileName(_tree.FilePath)} — {allFocusMethods.Count} method(s) full body ({string.Join(", ", foundNames)}){helperNote} · {referencedSymbols.Count} other symbols signatures only");
if (notFound.Count > 0)
notes.AppendLine($"// Not found: {string.Join(", ", notFound)}");
if (depth >= 1)
notes.AppendLine($"// Expanded helpers (depth {depth}): {expandedMethods.Count} private member(s) with full body");
notes.AppendLine($"// Other members: {referencedSymbols.Count} symbols referenced, signatures only");

return new FocusResult(
Found: true,
Expand Down Expand Up @@ -383,8 +380,7 @@ public FocusResult EmitType(string typeName)
var output = sb.ToString();
var originalLength = _tree.GetText().Length;
var notes =
$"// Type focus: {typeName} in {Path.GetFileName(_tree.FilePath)}\n" +
$"// {fullBodyCount} non-private member(s) with full body; {sigOnlyCount} private member(s) as signatures\n";
$"// Type focus: {typeName} in {Path.GetFileName(_tree.FilePath)} — {fullBodyCount} non-private member(s) full body; {sigOnlyCount} private member(s) as signatures\n";

return new FocusResult(
Found: true,
Expand Down Expand Up @@ -432,8 +428,7 @@ public FocusResult EmitCallers(string targetMethodName, int depth = 0)

var result = EmitMultiple(callerNames, depth);
var notes =
$"// Callers of '{targetMethodName}' in {Path.GetFileName(_tree.FilePath)}\n" +
$"// {callerNames.Count} calling method(s): {string.Join(", ", callerNames)}\n";
$"// Callers of '{targetMethodName}' in {Path.GetFileName(_tree.FilePath)} — {callerNames.Count} calling method(s): {string.Join(", ", callerNames)}\n";

return result with { Notes = notes };
}
Expand All @@ -456,8 +451,7 @@ public FocusResult EmitMinified()
var output = normalized.ToFullString();
var originalLength = _tree.GetText().Length;

var notes = $"// Minified emission of {Path.GetFileName(_tree.FilePath)}\n" +
$"// Comments stripped, whitespace collapsed — logic preserved verbatim\n";
var notes = $"// Minified emission of {Path.GetFileName(_tree.FilePath)} — comments stripped, whitespace collapsed, logic preserved verbatim\n";

return new FocusResult(
Found: true,
Expand Down Expand Up @@ -498,8 +492,7 @@ public FocusResult EmitOutline()
var output = sb.ToString().TrimEnd() + "\n";
var originalLength = _tree.GetText().Length;
var notes =
$"// Outline of {Path.GetFileName(_tree.FilePath)}\n" +
$"// {typeCount} type(s), {memberCount} member(s) — signatures only, no bodies\n";
$"// Outline of {Path.GetFileName(_tree.FilePath)} — {typeCount} type(s), {memberCount} member(s), signatures only, no bodies\n";

return new FocusResult(
Found: true,
Expand Down Expand Up @@ -606,8 +599,7 @@ public FocusResult EmitAliased()
var output = sb.ToString();
var originalLength = _tree.GetText().Length;

var notes = $"// Aliased emission of {Path.GetFileName(_tree.FilePath)}\n" +
$"// {renames.Count} private symbols renamed; ledger inlined; logic preserved\n";
var notes = $"// Aliased emission of {Path.GetFileName(_tree.FilePath)} — {renames.Count} private symbols renamed; ledger inlined; logic preserved\n";

return new FocusResult(
Found: true,
Expand Down Expand Up @@ -1033,12 +1025,8 @@ private static bool IsPrivate(MemberDeclarationSyntax member)
private string BuildNotes(int focusCount, int refCount, TypeDeclarationSyntax type, int expandedCount, int depth)
{
var sb = new StringBuilder();
sb.AppendLine($"// Focused emission of {Path.GetFileName(_tree.FilePath)}");
sb.AppendLine($"// Focus method(s): {focusCount} overload(s) included with full body");
if (depth >= 1)
sb.AppendLine($"// Expanded helpers (depth {depth}): {expandedCount} private member(s) included with full body");
sb.AppendLine($"// Other members: {refCount} symbols referenced, signatures only");
sb.AppendLine($"// Containing type: {type.Identifier}");
var helperNote = depth >= 1 ? $" · helpers (depth {depth}): {expandedCount} full body" : "";
sb.AppendLine($"// Focused emission of {Path.GetFileName(_tree.FilePath)} — {focusCount} overload(s) full body{helperNote} · {refCount} other symbols signatures only · type: {type.Identifier}");
return sb.ToString();
}

Expand Down
3 changes: 1 addition & 2 deletions Emitters/HtmlEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = Strip(source);
var notes =
$"<!-- HTML minify of {Path.GetFileName(filePath)} -->\n" +
$"<!-- Comments stripped, inter-tag whitespace collapsed -->\n";
$"<!-- HTML minify of {Path.GetFileName(filePath)} — comments stripped, inter-tag whitespace collapsed -->\n";

return new LanguageEmitResult(
Found: true,
Expand Down
3 changes: 1 addition & 2 deletions Emitters/JavaScriptEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = JsLikeMinifier.StripAndCollapse(source);
var notes =
$"// JS minify of {Path.GetFileName(filePath)}\n" +
$"// Comments stripped, whitespace collapsed (POC — no regex-literal awareness)\n";
$"// JS minify of {Path.GetFileName(filePath)} — comments stripped, whitespace collapsed (POC — no regex-literal awareness)\n";

return new LanguageEmitResult(
Found: true,
Expand Down
3 changes: 1 addition & 2 deletions Emitters/JsonEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = Strip(source);
var notes =
$"// JSON minify of {Path.GetFileName(filePath)}\n" +
$"// Whitespace removed outside strings; // and /* */ comments stripped (JSONC)\n";
$"// JSON minify of {Path.GetFileName(filePath)} — whitespace removed outside strings; // and /* */ comments stripped (JSONC)\n";

return new LanguageEmitResult(
Found: true,
Expand Down
4 changes: 1 addition & 3 deletions Emitters/PythonEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = StripCommentsAndBlankRuns(source);
var notes =
$"# Python minify of {Path.GetFileName(filePath)}\n" +
$"# '#' comments stripped, trailing whitespace removed, blank runs collapsed\n" +
$"# Indentation preserved (Python is indent-sensitive); docstrings preserved\n";
$"# Python minify of {Path.GetFileName(filePath)} — '#' comments stripped, blank runs collapsed; indentation and docstrings preserved\n";

return new LanguageEmitResult(
Found: true,
Expand Down
3 changes: 1 addition & 2 deletions Emitters/RazorEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public LanguageEmitResult Minify(string filePath)

var output = sb.ToString();
var notes =
$"// Razor minify of {Path.GetFileName(filePath)}\n" +
$"// Markup processed by HtmlEmitter; @code by Roslyn\n";
$"// Razor minify of {Path.GetFileName(filePath)} — markup by HtmlEmitter; @code by Roslyn\n";

return new LanguageEmitResult(
Found: true,
Expand Down
3 changes: 1 addition & 2 deletions Emitters/TypeScriptEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = JsLikeMinifier.StripAndCollapse(source);
var notes =
$"// TS minify of {Path.GetFileName(filePath)}\n" +
$"// Comments stripped, whitespace collapsed (POC — lexical only, type-only decls not removed)\n";
$"// TS minify of {Path.GetFileName(filePath)} — comments stripped, whitespace collapsed (POC — lexical only, type-only decls not removed)\n";

return new LanguageEmitResult(
Found: true,
Expand Down
25 changes: 8 additions & 17 deletions Emitters/VBFocusedEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public FocusResult EmitMinified()
{
var stripped = new CommentStripper().Visit(_root)!;
var output = CollapseBlankRuns(stripped.ToFullString());
var notes = $"' Minified emission of {Path.GetFileName(_filePath)}\n" +
$"' Comments stripped, blank runs collapsed — logic preserved verbatim\n";
var notes = $"' Minified emission of {Path.GetFileName(_filePath)} — comments stripped, blank runs collapsed, logic preserved verbatim\n";
return new FocusResult(true, output, _originalChars, output.Length, "(minified)", notes);
}

Expand All @@ -65,8 +64,7 @@ public FocusResult EmitOutline()
sb.AppendLine();
}
var output = sb.ToString().TrimEnd() + "\n";
var notes = $"' Outline of {Path.GetFileName(_filePath)}\n" +
$"' {typeCount} type(s), {memberCount} member(s) — signatures only, no bodies\n";
var notes = $"' Outline of {Path.GetFileName(_filePath)} — {typeCount} type(s), {memberCount} member(s), signatures only, no bodies\n";
return new FocusResult(true, output, _originalChars, output.Length, "(outline)", notes);
}

Expand Down Expand Up @@ -132,11 +130,9 @@ public FocusResult EmitMultiple(IReadOnlyList<string> methodNames, int depth = 0
sb.AppendLine($"' NOT FOUND: {string.Join(", ", notFound)}");
var output = sb.ToString();
var notesBuilder = new StringBuilder();
notesBuilder.AppendLine($"' Focused emission of {Path.GetFileName(_filePath)}");
notesBuilder.AppendLine($"' Focus method(s): {allFocusMethods.Count} with full body ({string.Join(", ", foundNames)})");
var helperNote = depth >= 1 ? $" · helpers (depth {depth}): {expandedMethods.Count} full body" : "";
notesBuilder.AppendLine($"' Focused emission of {Path.GetFileName(_filePath)} — {allFocusMethods.Count} method(s) full body ({string.Join(", ", foundNames)}){helperNote} · {referencedSymbols.Count} other symbols signatures only");
if (notFound.Count > 0) notesBuilder.AppendLine($"' Not found: {string.Join(", ", notFound)}");
if (depth >= 1) notesBuilder.AppendLine($"' Expanded helpers (depth {depth}): {expandedMethods.Count}");
notesBuilder.AppendLine($"' Other members: {referencedSymbols.Count} symbols referenced, signatures only");
return new FocusResult(true, output, _originalChars, output.Length, string.Join(", ", methodNames), notesBuilder.ToString())
{
RelevantSourceText = relevant.ToString()
Expand Down Expand Up @@ -178,8 +174,7 @@ public FocusResult EmitType(string typeName)
sb.AppendLine(targetType.EndBlockStatement.ToString().Trim());
AppendNamespaceClose(sb, targetType);
var output = sb.ToString();
var notes = $"' Type focus: {typeName} in {Path.GetFileName(_filePath)}\n" +
$"' {fullBodyCount} non-private member(s) with full body; {sigOnlyCount} private member(s) as signatures\n";
var notes = $"' Type focus: {typeName} in {Path.GetFileName(_filePath)} — {fullBodyCount} non-private member(s) full body; {sigOnlyCount} private member(s) as signatures\n";
return new FocusResult(true, output, _originalChars, output.Length, $"(type:{typeName})", notes)
{
RelevantSourceText = relevant.ToString()
Expand All @@ -200,8 +195,7 @@ public FocusResult EmitCallers(string targetMethodName, int depth = 0)
return new FocusResult(false, $"' No callers of '{targetMethodName}' found in source",
_originalChars, 0, $"(callers:{targetMethodName})", "");
var result = EmitMultiple(callerNames, depth);
var notes = $"' Callers of '{targetMethodName}' in {Path.GetFileName(_filePath)}\n" +
$"' {callerNames.Count} calling method(s): {string.Join(", ", callerNames)}\n";
var notes = $"' Callers of '{targetMethodName}' in {Path.GetFileName(_filePath)} — {callerNames.Count} calling method(s): {string.Join(", ", callerNames)}\n";
return result with { Notes = notes };
}

Expand Down Expand Up @@ -435,11 +429,8 @@ private static string IndentLines(string text, string indent)
private string BuildNotes(int focusCount, int refCount, TypeBlockSyntax type, int expandedCount, int depth)
{
var sb = new StringBuilder();
sb.AppendLine($"' Focused emission of {Path.GetFileName(_filePath)}");
sb.AppendLine($"' Focus method(s): {focusCount} overload(s) with full body");
if (depth >= 1) sb.AppendLine($"' Expanded helpers (depth {depth}): {expandedCount} private member(s)");
sb.AppendLine($"' Other members: {refCount} symbols referenced, signatures only");
sb.AppendLine($"' Containing type: {GetTypeName(type)}");
var helperNote = depth >= 1 ? $" · helpers (depth {depth}): {expandedCount} full body" : "";
sb.AppendLine($"' Focused emission of {Path.GetFileName(_filePath)} — {focusCount} overload(s) full body{helperNote} · {refCount} other symbols signatures only · type: {GetTypeName(type)}");
return sb.ToString();
}

Expand Down
3 changes: 1 addition & 2 deletions Emitters/XmlEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = Strip(source);
var notes =
$"<!-- XML minify of {Path.GetFileName(filePath)} -->\n" +
$"<!-- <!-- --> comments stripped, trailing whitespace removed, blank runs collapsed -->\n";
$"<!-- XML minify of {Path.GetFileName(filePath)} — comments stripped, trailing whitespace removed, blank runs collapsed -->\n";

return new LanguageEmitResult(
Found: true,
Expand Down
3 changes: 1 addition & 2 deletions Emitters/XppEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public LanguageEmitResult Minify(string filePath)

var source = File.ReadAllText(filePath);
var output = XppMinifier.StripAndCollapse(source);
var notes = $"// X++ minify of {Path.GetFileName(filePath)}\n" +
$"// Comments stripped, whitespace collapsed, #macro directives preserved\n";
var notes = $"// X++ minify of {Path.GetFileName(filePath)} — comments stripped, whitespace collapsed, #macro directives preserved\n";
return new LanguageEmitResult(Found: true, Output: output,
OriginalChars: source.Length, OutputChars: output.Length, Notes: notes);
}
Expand Down
4 changes: 1 addition & 3 deletions Emitters/YamlEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public LanguageEmitResult Minify(string filePath)
var source = File.ReadAllText(filePath);
var output = Strip(source);
var notes =
$"# YAML minify of {Path.GetFileName(filePath)}\n" +
$"# '#' comments stripped, trailing whitespace removed, blank runs collapsed\n" +
$"# Indentation preserved (YAML is indent-sensitive)\n";
$"# YAML minify of {Path.GetFileName(filePath)} — '#' comments stripped, blank runs collapsed; indentation preserved\n";

return new LanguageEmitResult(
Found: true,
Expand Down
4 changes: 2 additions & 2 deletions mcp/FocusedEmitterTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ private static string BuildHeader(int before, int after, string toolName, string
// state plainly that this view only adds its own output to the context.
var callLine = firstView
? $"// [Focused Emitter] Tokens without tool: {before:N0} → with tool: {displayAfter:N0} ({pct}% saved) — mode: {mode}\n"
: $"// [Focused Emitter] repeat view of this file this session — whole-file baseline already counted; this view adds {displayAfter:N0} tokens, no new whole-file saving — mode: {mode}\n";
: $"// [Focused Emitter] repeat view — whole-file baseline already counted; adds {displayAfter:N0} tokens — mode: {mode}\n";

// Lower-bound baseline for the focused tools: the whole-file "without tool"
// figure assumes the alternative was reading the entire file, which is a best
Expand All @@ -824,7 +824,7 @@ private static string BuildHeader(int before, int after, string toolName, string
targetedLine = $"// vs a targeted read of just the relevant code ({relevant:N0} tokens): {relevantPct}% {verb}\n";
}

var sessionLine = $"// session: {calls} call{(calls == 1 ? "" : "s")} · raw saved {sessionSaved:N0} · net of {OverheadTokens:N0} one-time MCP overhead = {sessionNet:N0}\n";
var sessionLine = $"// session: {calls} call{(calls == 1 ? "" : "s")} · saved {sessionSaved:N0} · net {sessionNet:N0} after {OverheadTokens:N0} overhead\n";
return callLine + targetedLine + sessionLine;
}

Expand Down
Loading
Loading