mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Remove terminal tool and dependencies.
- We now solely use the shell tool. This deletes all content around the legacy terminal tool so we can focus on improving the new Shell tool. - Remove instances from sandboxing, tests, utilities etc.
This commit is contained in:
committed by
N. Taylor Mullen
parent
dcb67c32a5
commit
cf91f72c5c
@@ -5,94 +5,9 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
findSafeSplitPoint,
|
||||
findLastSafeSplitPoint,
|
||||
} from './markdownUtilities.js';
|
||||
import { findLastSafeSplitPoint } from './markdownUtilities.js';
|
||||
|
||||
describe('markdownUtilities', () => {
|
||||
describe('findSafeSplitPoint', () => {
|
||||
it('should return content.length if content is shorter than idealMaxLength', () => {
|
||||
const content = 'short content';
|
||||
expect(findSafeSplitPoint(content, 100)).toBe(content.length);
|
||||
});
|
||||
|
||||
it('should split before a code block if idealMaxLength is inside it', () => {
|
||||
const content = 'text before ```code``` text after';
|
||||
expect(findSafeSplitPoint(content, 15)).toBe(12);
|
||||
});
|
||||
|
||||
it('should return 0 if idealMaxLength is inside a code block that starts at 0', () => {
|
||||
const content = '```code``` text after';
|
||||
expect(findSafeSplitPoint(content, 5)).toBe(0);
|
||||
});
|
||||
|
||||
it('should split at a double newline if possible', () => {
|
||||
const content = 'paragraph1\n\nparagraph2';
|
||||
expect(findSafeSplitPoint(content, 12)).toBe(22); // Updated expectation
|
||||
});
|
||||
|
||||
it('should split at a single newline if double newline is not available', () => {
|
||||
const content = 'line1\nline2';
|
||||
expect(findSafeSplitPoint(content, 7)).toBe(11); // Updated expectation
|
||||
});
|
||||
|
||||
it('should return content.length if no safe split point is found', () => {
|
||||
const content = 'longstringwithoutanysafesplitpoint';
|
||||
expect(findSafeSplitPoint(content, 10)).toBe(content.length);
|
||||
});
|
||||
|
||||
it('should handle content with multiple code blocks', () => {
|
||||
const content = 'text ```code1``` text ```code2``` text';
|
||||
expect(findSafeSplitPoint(content, 20)).toBe(38); // Updated expectation
|
||||
});
|
||||
|
||||
it('should prioritize splitting before a code block over a newline', () => {
|
||||
const content = 'text\nnewline ```code``` text';
|
||||
expect(findSafeSplitPoint(content, 15)).toBe(5); // Updated expectation
|
||||
});
|
||||
|
||||
// Known failure: Code has a bug
|
||||
it.fails(
|
||||
'should split after \n\n when idealMaxLength is not in a code block and a suitable \n\n exists after it',
|
||||
() => {
|
||||
const content = 'This is some text.\n\nThis is more text.';
|
||||
// idealMaxLength is 10, which is before the \n\n
|
||||
// The function should find the \n\n at index 20 and split after it (index 22)
|
||||
expect(findSafeSplitPoint(content, 10)).toBe(22);
|
||||
},
|
||||
);
|
||||
|
||||
it('should return content.length when idealMaxLength is not in a code block and no \n\n exists after it', () => {
|
||||
const content =
|
||||
'This is some text. This is more text and no double newline.';
|
||||
// idealMaxLength is 10
|
||||
// No \n\n after index 10
|
||||
expect(findSafeSplitPoint(content, 10)).toBe(content.length);
|
||||
});
|
||||
|
||||
it('should correctly split before a code block that idealMaxLength is inside, even if \n\n exists before it', () => {
|
||||
const content =
|
||||
'Paragraph before.\n\n```\nCode block content\n```\nParagraph after.';
|
||||
// idealMaxLength is 25, which is inside the code block
|
||||
// The split should be at index 19 (start of the code block)
|
||||
expect(findSafeSplitPoint(content, 25)).toBe(19);
|
||||
});
|
||||
|
||||
it('should split at the last \n before a code block if idealMaxLength is in the code block and no \n\n is found before it', () => {
|
||||
const content = 'Line before.\n```\nCode block\n```';
|
||||
// idealMaxLength is 15 (inside code block)
|
||||
// Split should be at 13 (after \n and before ```)
|
||||
expect(findSafeSplitPoint(content, 15)).toBe(13);
|
||||
});
|
||||
|
||||
it('should return 0 if idealMaxLength is in a code block starting at 0 and no prior newline exists', () => {
|
||||
const content =
|
||||
'```\nVery long code block that exceeds idealMaxLength\n```';
|
||||
expect(findSafeSplitPoint(content, 10)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findLastSafeSplitPoint', () => {
|
||||
it('should split at the last double newline if not in a code block', () => {
|
||||
const content = 'paragraph1\n\nparagraph2\n\nparagraph3';
|
||||
|
||||
@@ -90,101 +90,6 @@ const findEnclosingCodeBlockStart = (
|
||||
return -1;
|
||||
};
|
||||
|
||||
export const findSafeSplitPoint = (
|
||||
content: string,
|
||||
idealMaxLength: number = 500,
|
||||
): number => {
|
||||
if (content.length <= idealMaxLength) {
|
||||
return content.length;
|
||||
}
|
||||
|
||||
const enclosingBlockStartForIdealMax = findEnclosingCodeBlockStart(
|
||||
content,
|
||||
idealMaxLength,
|
||||
);
|
||||
|
||||
if (enclosingBlockStartForIdealMax !== -1) {
|
||||
// idealMaxLength is inside a code block. Try to split *before* this block.
|
||||
const textToSearchForNewline = content.substring(
|
||||
0,
|
||||
enclosingBlockStartForIdealMax,
|
||||
);
|
||||
|
||||
// Iteratively search for the last safe \n\n before enclosingBlockStartForIdealMax
|
||||
let currentSearchFromIndex = textToSearchForNewline.length;
|
||||
while (currentSearchFromIndex > 0) {
|
||||
// searchEndIndex refers to character count to search within
|
||||
const dnlIndex = textToSearchForNewline.lastIndexOf(
|
||||
'\n\n',
|
||||
currentSearchFromIndex - 1,
|
||||
); // fromIndex for lastIndexOf is 0-based
|
||||
if (dnlIndex === -1) break;
|
||||
|
||||
const potentialSplit = dnlIndex + 2;
|
||||
// The split must be strictly before the block idealMaxLength was in.
|
||||
// This is implicitly true if dnlIndex is found within textToSearchForNewline.
|
||||
if (!isIndexInsideCodeBlock(content, potentialSplit)) {
|
||||
// Condition: (potentialSplit > 0) OR (it's 0 AND the problematic block also started at 0)
|
||||
if (
|
||||
potentialSplit > 0 ||
|
||||
(enclosingBlockStartForIdealMax === 0 && potentialSplit === 0)
|
||||
) {
|
||||
return potentialSplit;
|
||||
}
|
||||
}
|
||||
currentSearchFromIndex = dnlIndex; // Continue search before the start of this found \n\n
|
||||
// (dnlIndex is start of \n\n, so next search is before it)
|
||||
}
|
||||
|
||||
// Iteratively search for the last safe \n
|
||||
currentSearchFromIndex = textToSearchForNewline.length;
|
||||
while (currentSearchFromIndex >= 0) {
|
||||
// Can be 0 if textToSearchForNewline has length 1 and it's \n
|
||||
const snlIndex = textToSearchForNewline.lastIndexOf(
|
||||
'\n',
|
||||
currentSearchFromIndex - 1,
|
||||
);
|
||||
if (snlIndex === -1) break;
|
||||
|
||||
const potentialSplit = snlIndex + 1;
|
||||
if (!isIndexInsideCodeBlock(content, potentialSplit)) {
|
||||
if (
|
||||
potentialSplit > 0 ||
|
||||
(enclosingBlockStartForIdealMax === 0 && potentialSplit === 0)
|
||||
) {
|
||||
return potentialSplit;
|
||||
}
|
||||
}
|
||||
currentSearchFromIndex = snlIndex;
|
||||
}
|
||||
|
||||
// Fallback: split right before this code block
|
||||
return enclosingBlockStartForIdealMax;
|
||||
}
|
||||
|
||||
// idealMaxLength is NOT inside a code block.
|
||||
// Search forwards from idealMaxLength for the next double newline (\n\n) not in a code block.
|
||||
let searchStartIndex = idealMaxLength;
|
||||
while (searchStartIndex < content.length) {
|
||||
const dnlIndex = content.indexOf('\n\n', searchStartIndex);
|
||||
if (dnlIndex === -1) {
|
||||
// No more double newlines found after idealMaxLength
|
||||
break;
|
||||
}
|
||||
|
||||
const potentialSplitPoint = dnlIndex + 2;
|
||||
if (!isIndexInsideCodeBlock(content, potentialSplitPoint)) {
|
||||
return potentialSplitPoint;
|
||||
}
|
||||
|
||||
searchStartIndex = potentialSplitPoint; // Continue search after the found \n\n
|
||||
}
|
||||
|
||||
// If no safe double newline found after idealMaxLength, return content.length
|
||||
// to keep the entire content as one piece.
|
||||
return content.length;
|
||||
};
|
||||
|
||||
export const findLastSafeSplitPoint = (content: string) => {
|
||||
const enclosingBlockStart = findEnclosingCodeBlockStart(
|
||||
content,
|
||||
|
||||
@@ -332,11 +332,6 @@ export async function start_sandbox(sandbox: string) {
|
||||
args.push('--env', `GEMINI_CODE_MODEL=${process.env.GEMINI_CODE_MODEL}`);
|
||||
}
|
||||
|
||||
// copy TERMINAL_TOOL to optionally enable shell tool
|
||||
if (process.env.TERMINAL_TOOL) {
|
||||
args.push('--env', `TERMINAL_TOOL=${process.env.TERMINAL_TOOL}`);
|
||||
}
|
||||
|
||||
// copy TERM and COLORTERM to try to maintain terminal setup
|
||||
if (process.env.TERM) {
|
||||
args.push('--env', `TERM=${process.env.TERM}`);
|
||||
|
||||
Reference in New Issue
Block a user