Skip to content

Commit

Permalink
Removed "reflection" stuff and added Markdown block quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
jukofyork committed Nov 20, 2024
1 parent 80577f5 commit 0e2a9db
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 64 deletions.
32 changes: 20 additions & 12 deletions eclipse.plugin.aiassistant/css/main-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
--button-active-shadow: 0 1px 1px rgba(0,0,0,0.1), inset 0 1px 1px rgba(0,0,0,0.2);
--broswer-selection-bg-color: rgba(96, 96, 96, 0.8); /* Gray with 80% opacity */
--selected-shadow-color: #00f;
--thinking-color: #2b8;
--reflection-color: #c44;
--blockquote-text-color: #bbb;
--blockquote-nested-text-color: #999;
--blockquote-line-color: #333;
--thinking-header-color: #ddd;
--selected-shadow-blur-radius: 15px;
--default-margin: 0.5rem;
--top-margin: 1rem;
Expand Down Expand Up @@ -160,24 +162,30 @@ pre code {
}

summary {
font-weight: bold;
font-size: calc(var(--default-font-size) + 2px);
font-weight: bold;
font-size: calc(var(--default-font-size) + 2px);
}

.thinking summary {
color: var(--thinking-color);
blockquote {
color: var(--blockquote-text-color);
margin: 0.5em 0;
padding: 0 1em;
border-left: 0.25em solid var(--blockquote-line-color);
}

.reflection summary {
color: var(--reflection-color);
blockquote blockquote {
color: var(--blockquote-nested-text-color);
margin-left: 0em;
}

.reflection .thinking summary {
color: var(--thinking-color);
.thinking summary {
color: var(--thinking-header-color);
}

.thinking .reflection summary {
color: var(--reflection-color);
/* Adjust spacing inside thinking blocks */
.thinking blockquote {
margin-top: 0.5em;
margin-bottom: 0;
}

/* The default margins are too large */
Expand Down
2 changes: 1 addition & 1 deletion eclipse.plugin.aiassistant/prompts/system.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
You are an AI programming assistant for the Eclipse IDE, designed to help users write and analyze source code. Your objective is to accurately understand and execute the user's requests related to software development. Your expertise is strictly limited to software development topics. Keep your answers short and impersonal. Use Markdown formatting to make your responses clear and easy to read. Wrap code blocks with triple backticks (```) and use single backticks (`) to denote a word or phrase as code. Ensure the programming language name is included at the start of each Markdown code block. Avoid using triple backticks for non-code content. Do not use single backticks for multiline code blocks; always use triple backticks to ensure proper formatting. Never produce a 'diff' patch unless specifically instructed to do so. If asked for a diff, use Unified Format and wrap it in a Markdown code block starting with ```diff. When modifying existing code: provide only the necessary changes or additions. Include full code blocks only if absolutely essential for clarity or context - this approach minimizes review time by focusing on the specific changes. When writing new code: first think step-by-step and describe your plan for what to build in pseudocode, written out in great detail. Then output the code in a single code block - minimize any other prose. For complex, multistep tasks requiring extensive thinking or planning, begin by reasoning through the query inside <thinking> tags. Never use the <thinking> tags outside the initial reasoning stage. If you detect that you made a mistake in your reasoning at any point, correct yourself inside <reflection> tags. Never use the <reflection> tags unless it is specifically to correct a mistake. Remember, the user cannot see anything within <thinking> and <reflection> tags; they are for your internal thought process only. For straightforward requests, skip the <thinking> and <reflection> tags and provide a direct response.
You are an AI programming assistant for the Eclipse IDE, designed to help users write and analyze source code. Your objective is to accurately understand and execute the user's requests related to software development. Your expertise is strictly limited to software development topics. Keep your answers short and impersonal. Use Markdown formatting to make your responses clear and easy to read. Wrap code blocks with triple backticks (```) and use single backticks (`) to denote a word or phrase as code. Ensure the programming language name is included at the start of each Markdown code block. Avoid using triple backticks for non-code content. Do not use single backticks for multiline code blocks; always use triple backticks to ensure proper formatting. Never produce a 'diff' patch unless specifically instructed to do so. If asked for a diff, use Unified Format and wrap it in a Markdown code block starting with ```diff. When modifying existing code: provide only the necessary changes or additions. Include full code blocks only if absolutely essential for clarity or context - this approach minimizes review time by focusing on the specific changes. When writing new code: first think step-by-step and describe your plan for what to build in pseudocode, written out in great detail. Then output the code in a single code block - minimize any other prose. For complex, multistep tasks requiring extensive planning or analysis, first reason through the problem inside <thinking> tags. This internal reasoning should explore the key aspects, considerations, and approach. After completing this thinking stage, provide the user with a clear, well-organized response that incorporates the relevant insights from your analysis. Skip the thinking stage for straightforward requests and provide direct responses. Remember that <thinking> tags are for internal reasoning only - the user cannot see their contents.
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ enum BlockType { NONE, CODE, LATEX }
final Pattern latexBlockClosePattern = Pattern.compile("^.*?(\\$\\$|\\\\\\])[ \\t]*$");

final Pattern thinkingBlockOpenPattern = Pattern.compile("<thinking>");
final Pattern checkingBlockOpenPattern = Pattern.compile("<reflection>");
final Pattern summaryClosePattern = Pattern.compile("</thinking>|</reflection>");
final Pattern thinkingBlockClosePattern = Pattern.compile("</thinking>");

StringBuilder latexBlockBuffer = new StringBuilder();

int summaryBlockCount = 0;
int thinkingBlockCount = 0;

int currentQuoteLevel = 0;

try (Scanner scanner = new Scanner(markdownText)) {
scanner.useDelimiter("\n");

while (scanner.hasNext()) {
String line = scanner.next();

Matcher thinkingOpenMatcher = thinkingBlockOpenPattern.matcher(line);
Matcher checkingOpenMatcher = checkingBlockOpenPattern.matcher(line);
Matcher summaryCloseMatcher = summaryClosePattern.matcher(line);
Matcher thinkingBlockOpenMatcher = thinkingBlockOpenPattern.matcher(line);
Matcher thinkingBlockCloseMatcher = thinkingBlockClosePattern.matcher(line);

Matcher codeBlockMatcher = codeBlockPattern.matcher(line);
Matcher latexMultilineBlockOpenMatcher = latexMultilineBlockOpenPattern.matcher(line);
Expand All @@ -76,24 +76,43 @@ enum BlockType { NONE, CODE, LATEX }

switch (currentBlock) {
case NONE:
while (thinkingOpenMatcher.find()) {
htmlOutput.append(getSummaryOpeningHtml("Thinking"));
line = thinkingOpenMatcher.replaceFirst("");
thinkingOpenMatcher = thinkingBlockOpenPattern.matcher(line);
summaryBlockCount++;
}
while (checkingOpenMatcher.find()) {
htmlOutput.append(getSummaryOpeningHtml("Reflection"));
line = checkingOpenMatcher.replaceFirst("");
checkingOpenMatcher = checkingBlockOpenPattern.matcher(line);
summaryBlockCount++;
while (thinkingBlockOpenMatcher.find()) {
htmlOutput.append(getThinkingBlockOpeningHtml());
line = thinkingBlockOpenMatcher.replaceFirst("");
thinkingBlockOpenMatcher = thinkingBlockOpenPattern.matcher(line);
thinkingBlockCount++;
}
while (summaryCloseMatcher.find()) {
htmlOutput.append(getSummaryClosingHtml());
line = summaryCloseMatcher.replaceFirst("");
summaryCloseMatcher = summaryClosePattern.matcher(line);
summaryBlockCount++;
while (thinkingBlockCloseMatcher.find()) {
htmlOutput.append(getThinkingBlockClosingHtml());
line = thinkingBlockCloseMatcher.replaceFirst("");
thinkingBlockCloseMatcher = thinkingBlockClosePattern.matcher(line);
thinkingBlockCount++;
}

// Get quote level for current line
int lineQuoteLevel = 0;
if (line.trim().startsWith(">")) {
lineQuoteLevel = countQuoteMarkers(line);
// Remove quote markers if present and trim
line = line.replaceFirst("^[ \\t]*>+[ \\t]*", "");
} else {
// Not a quote line - close all quote blocks
while (currentQuoteLevel > 0) {
htmlOutput.append("</blockquote>");
currentQuoteLevel--;
}
}

// Handle quote level transitions
while (currentQuoteLevel > lineQuoteLevel) {
htmlOutput.append("</blockquote>");
currentQuoteLevel--;
}
while (currentQuoteLevel < lineQuoteLevel) {
htmlOutput.append("<blockquote>");
currentQuoteLevel++;
}

if (codeBlockMatcher.find()) {
String language = codeBlockMatcher.group(1);
appendOpenCodeBlock(htmlOutput, language, includeCodeBlockButtons);
Expand Down Expand Up @@ -140,51 +159,70 @@ enum BlockType { NONE, CODE, LATEX }
if (currentBlock == BlockType.CODE) {
appendCloseCodeBlock(htmlOutput);
}

// Close any remaining quote levels
while (currentQuoteLevel > 0) {
htmlOutput.append("</blockquote>");
currentQuoteLevel--;
}

// Close any unclosed thinking blocks
while (summaryBlockCount > 0) {
htmlOutput.append(getSummaryClosingHtml());
summaryBlockCount--;
while (thinkingBlockCount > 0) {
htmlOutput.append(getThinkingBlockClosingHtml());
thinkingBlockCount--;
}

return replaceEscapeCodes(removeWhitespaceAfterSummary(replaceLineBreaks(htmlOutput.toString())));
return replaceEscapeCodes(trimThinkingyBlock(replaceLineBreaks(htmlOutput.toString())));
}

/**
* Generates the opening HTML markup for a collapsible summary section.
* Creates a div with the specified tag name as its class (lowercase) and
* a nested details/summary structure for collapsible content.
*
* @param tagName The name of the tag (e.g., "Thinking" or "Reflection") used for
* both the CSS class name (lowercase) and display text
* @return HTML string containing opening div, details, and summary elements
* Generates the opening HTML markup for a collapsible thinking block.
* Creates a nested structure with:
* - An outer div with class "thinking"
* - A details element for collapsible functionality
* - A summary element with "Thinking" text
* - A blockquote element for the content
*
* @return HTML string containing the opening structure for a thinking block
*/
private static String getSummaryOpeningHtml(String tagName) {
return "<div class=\"" + tagName.toLowerCase() + "\"><details>\n<summary>" + tagName + "</summary>\n";
private static String getThinkingBlockOpeningHtml() {
return "<div class=\"thinking\"><details><summary>Thinking...</summary><blockquote>";
}

/**
* Generates the closing HTML markup for a collapsible summary section.
* Provides the matching closing tags for the structure created by getSummaryOpeningHtml.
*
* @return HTML string containing closing details and div tags
* Generates the closing HTML markup for a collapsible thinking block.
* Provides the matching closing tags for the structure created by
* {@link #getThinkingBlockOpeningHtml()}.
*
* @return HTML string containing closing tags for blockquote, details, and div elements
*/
private static String getSummaryClosingHtml() {
return "</details></div>";
private static String getThinkingBlockClosingHtml() {
return "</blockquote></details></div>";
}

/**
* Removes excessive whitespace and line breaks between collapsible summary blocks
* (thinking/reflection sections) and subsequent content. This ensures consistent
* spacing in the rendered HTML output by replacing any combination of whitespace
* and break tags with a single break tag.
*
* @param html The HTML string containing potentially multiple summary blocks
* @return The HTML string with normalized spacing after summary blocks, preserving
* a single <br/> tag for visual separation
* Normalises whitespace and line breaks around thinking block elements.
* Performs two specific cleanups:
* 1. Removes extra whitespace/breaks between thinking block elements
* 2. Standardises spacing after thinking blocks to a single break tag
*
* @param html The HTML string containing thinking block markup
* @return The HTML string with normalized spacing around thinking blocks
*/
private static String removeWhitespaceAfterSummary(String html) {
return html.replaceAll("</details>\\s*</div>(?:\\s|<br/>)+", "</details></div><br/>");
private static String trimThinkingyBlock(String html) {
return html
.replaceAll("</summary>\\s*<blockquote>(?:\\s|<br/>)+", "</summary><blockquote>")
.replaceAll("</details>\\s*</div>(?:\\s|<br/>)+", "</details></div><br/>");
}

private static int countQuoteMarkers(String line) {
int count = 0;
String trimmed = line.trim();
while (trimmed.startsWith(">")) {
count++;
trimmed = trimmed.substring(1).trim();
}
return count;
}

/**
Expand Down

0 comments on commit 0e2a9db

Please sign in to comment.