Merge branch 'main' into winarm64
This commit is contained in:
commit
a560f5c187
173 changed files with 4972 additions and 639 deletions
197
.github/workflows/compliance.yaml
vendored
Normal file
197
.github/workflows/compliance.yaml
vendored
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
name: PR Compliance Checks
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
conventional-commits:
|
||||
name: Validate Conventional Commits (Warning Only)
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ !github.event.pull_request.draft }}
|
||||
continue-on-error: true
|
||||
permissions:
|
||||
pull-requests: write
|
||||
issues: write
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Validate conventional commits
|
||||
id: commitlint
|
||||
uses: wagoid/commitlint-github-action@v6
|
||||
with:
|
||||
configFile: .commitlintrc.warning.json
|
||||
continue-on-error: true
|
||||
|
||||
- name: Add commit message guidance comment
|
||||
if: steps.commitlint.outcome == 'failure'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
});
|
||||
|
||||
const botComment = comments.find(comment =>
|
||||
comment.user.type === 'Bot' &&
|
||||
comment.body.includes('Conventional Commit Format')
|
||||
);
|
||||
|
||||
if (!botComment) {
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body: [
|
||||
"## ⚠️ Conventional Commit Format",
|
||||
"",
|
||||
"Your commit messages don't follow the conventional commit format, but **this won't block your PR from being merged**. We recommend downloading [this extension](https://marketplace.visualstudio.com/items?itemName=vivaxy.vscode-conventional-commits) if you are using VS Code.",
|
||||
"",
|
||||
"### Expected Format:",
|
||||
"```",
|
||||
"<type>[optional scope]: <description>",
|
||||
"",
|
||||
"[optional body]",
|
||||
"",
|
||||
"[optional footer(s)]",
|
||||
"```",
|
||||
"",
|
||||
"### Examples:",
|
||||
"- `feat: add changelog generation support`",
|
||||
"- `fix: resolve login redirect issue`",
|
||||
"- `docs: update README with new instructions`",
|
||||
"- `chore: update dependencies`",
|
||||
"",
|
||||
"### Valid Types:",
|
||||
"`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`",
|
||||
"",
|
||||
"This helps with:",
|
||||
"- 📝 Automatic changelog generation",
|
||||
"- 🚀 Automated semantic versioning",
|
||||
"- 📊 Better project history tracking",
|
||||
"",
|
||||
"*This is a non-blocking warning - your PR can still be merged without fixing this.*"
|
||||
].join('\n')
|
||||
});
|
||||
}
|
||||
|
||||
security-audit:
|
||||
name: Security Audit
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ !github.event.pull_request.draft }}
|
||||
permissions:
|
||||
security-events: write
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: "npm"
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Fix vulnerabilities
|
||||
run: npm audit fix
|
||||
|
||||
- name: Run npm audit
|
||||
run: npm audit --audit-level=moderate
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: javascript
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
||||
# Use this for any files that we want to be certain exist
|
||||
# Basically creates a forcing function to discuss were anyone to want to remove them
|
||||
file-validation:
|
||||
name: Required Files Check
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ !github.event.pull_request.draft }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Check required files
|
||||
run: |
|
||||
required_files=(
|
||||
"package.json"
|
||||
"package-lock.json"
|
||||
"README.md"
|
||||
"LICENSE"
|
||||
".gitignore"
|
||||
"tsconfig.json"
|
||||
"SECURITY.md"
|
||||
"CONTRIBUTING.md"
|
||||
".nvmrc"
|
||||
".prettierrc"
|
||||
".prettierignore"
|
||||
)
|
||||
|
||||
missing_files=()
|
||||
for file in "${required_files[@]}"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
missing_files+=("$file")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#missing_files[@]} -gt 0 ]]; then
|
||||
echo "❌ Missing required files:"
|
||||
printf '%s\n' "${missing_files[@]}"
|
||||
exit 1
|
||||
else
|
||||
echo "✅ All required files present"
|
||||
fi
|
||||
|
||||
compliance-summary:
|
||||
name: Compliance Summary
|
||||
runs-on: ubuntu-latest
|
||||
needs: [conventional-commits, security-audit, file-validation]
|
||||
if: always() && !github.event.pull_request.draft
|
||||
steps:
|
||||
- name: Check compliance status
|
||||
run: |
|
||||
echo "## 🔍 Compliance Check Results" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
if [[ "${{ needs.conventional-commits.result }}" == "success" ]]; then
|
||||
echo "✅ Conventional Commits: PASSED" >> $GITHUB_STEP_SUMMARY
|
||||
elif [[ "${{ needs.conventional-commits.result }}" == "failure" ]]; then
|
||||
echo "⚠️ Conventional Commits: WARNING (non-blocking)" >> $GITHUB_STEP_SUMMARY
|
||||
else
|
||||
echo "❌ Conventional Commits: SKIPPED" >> $GITHUB_STEP_SUMMARY
|
||||
fi
|
||||
|
||||
if [[ "${{ needs.security-audit.result }}" == "success" ]]; then
|
||||
echo "✅ Security Audit: PASSED" >> $GITHUB_STEP_SUMMARY
|
||||
else
|
||||
echo "❌ Security Audit: FAILED" >> $GITHUB_STEP_SUMMARY
|
||||
fi
|
||||
|
||||
if [[ "${{ needs.file-validation.result }}" == "success" ]]; then
|
||||
echo "✅ File Validation: PASSED" >> $GITHUB_STEP_SUMMARY
|
||||
else
|
||||
echo "❌ File Validation: FAILED" >> $GITHUB_STEP_SUMMARY
|
||||
fi
|
||||
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "📊 **Overall Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
|
||||
|
|
@ -8,8 +8,19 @@
|
|||
* we rarely ever need syntax highlighting outside of
|
||||
* creating a render of it.
|
||||
*/
|
||||
import {
|
||||
transformerMetaHighlight,
|
||||
transformerNotationDiff,
|
||||
transformerNotationFocus,
|
||||
transformerNotationHighlight,
|
||||
} from "@shikijs/transformers";
|
||||
import { JSDOM } from "jsdom";
|
||||
import { BundledTheme, codeToHtml, getSingletonHighlighter } from "shiki";
|
||||
import {
|
||||
BundledLanguage,
|
||||
BundledTheme,
|
||||
getSingletonHighlighter,
|
||||
Highlighter,
|
||||
} from "shiki";
|
||||
import { escapeForSVG, kebabOfStr } from "../util/text";
|
||||
|
||||
interface CodeRendererOptions {
|
||||
|
|
@ -42,6 +53,8 @@ export class CodeRenderer {
|
|||
private currentTheme: string = "dark-plus";
|
||||
private editorBackground: string = "#000000";
|
||||
private editorForeground: string = "#FFFFFF";
|
||||
private editorLineHighlight: string = "#000000";
|
||||
private highlighter: Highlighter | null = null;
|
||||
|
||||
private constructor() {}
|
||||
|
||||
|
|
@ -62,13 +75,17 @@ export class CodeRenderer {
|
|||
? "dark-plus"
|
||||
: kebabOfStr(themeName);
|
||||
|
||||
const highlighter = await getSingletonHighlighter({
|
||||
this.highlighter = await getSingletonHighlighter({
|
||||
langs: ["typescript"],
|
||||
themes: [this.currentTheme],
|
||||
});
|
||||
|
||||
const th = highlighter.getTheme(this.currentTheme);
|
||||
const th = this.highlighter.getTheme(this.currentTheme);
|
||||
|
||||
this.editorBackground = th.bg;
|
||||
this.editorForeground = th.fg;
|
||||
this.editorLineHighlight =
|
||||
th.colors!["editor.lineHighlightBackground"] ?? "#000000";
|
||||
} else {
|
||||
this.currentTheme = "dark-plus";
|
||||
}
|
||||
|
|
@ -148,10 +165,29 @@ export class CodeRenderer {
|
|||
async highlightCode(
|
||||
code: string,
|
||||
language: string = "javascript",
|
||||
currLineOffsetFromTop: number,
|
||||
): Promise<string> {
|
||||
return await codeToHtml(code, {
|
||||
const annotatedCode = code
|
||||
.split("\n")
|
||||
.map((line, i) =>
|
||||
i === currLineOffsetFromTop
|
||||
? line + " \/\/ \[\!code highlight\]"
|
||||
: line,
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
await this.highlighter!.loadLanguage(language as BundledLanguage);
|
||||
|
||||
return this.highlighter!.codeToHtml(annotatedCode, {
|
||||
lang: language,
|
||||
theme: this.currentTheme,
|
||||
transformers: [
|
||||
// transformerColorizedBrackets(),
|
||||
transformerMetaHighlight(),
|
||||
transformerNotationHighlight(),
|
||||
transformerNotationDiff(),
|
||||
transformerNotationFocus(),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -163,23 +199,40 @@ export class CodeRenderer {
|
|||
dimensions: Dimensions,
|
||||
lineHeight: number,
|
||||
options: ConversionOptions,
|
||||
currLineOffsetFromTop: number,
|
||||
): Promise<Buffer> {
|
||||
const highlightedCodeHtml = await this.highlightCode(code, language);
|
||||
const strokeWidth = 1;
|
||||
const highlightedCodeHtml = await this.highlightCode(
|
||||
code,
|
||||
language,
|
||||
currLineOffsetFromTop,
|
||||
);
|
||||
// console.log(highlightedCodeHtml);
|
||||
|
||||
const guts = this.convertShikiHtmlToSvgGut(
|
||||
const { guts, lineBackgrounds } = this.convertShikiHtmlToSvgGut(
|
||||
highlightedCodeHtml,
|
||||
fontSize,
|
||||
fontFamily,
|
||||
lineHeight,
|
||||
dimensions,
|
||||
);
|
||||
const backgroundColor = this.getBackgroundColor(highlightedCodeHtml);
|
||||
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${dimensions.width}" height="${dimensions.height}">
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${dimensions.width}" height="${dimensions.height}" shape-rendering="crispEdges">
|
||||
<style>
|
||||
:root {
|
||||
--purple: rgb(112, 114, 209);
|
||||
--green: rgb(136, 194, 163);
|
||||
--blue: rgb(107, 166, 205);
|
||||
}
|
||||
</style>
|
||||
<g>
|
||||
<rect width="${dimensions.width}" height="${dimensions.height}" fill="${backgroundColor}" stroke="${this.editorForeground}" stroke-width="1" />
|
||||
<rect x="0" y="0" rx="10" ry="10" width="${dimensions.width}" height="${dimensions.height}" fill="${this.editorBackground}" shape-rendering="crispEdges" />
|
||||
${lineBackgrounds}
|
||||
${guts}
|
||||
</g>
|
||||
</svg>`;
|
||||
console.log(svg);
|
||||
|
||||
return Buffer.from(svg, "utf8");
|
||||
}
|
||||
|
|
@ -189,7 +242,8 @@ export class CodeRenderer {
|
|||
fontSize: number,
|
||||
fontFamily: string,
|
||||
lineHeight: number,
|
||||
): string {
|
||||
dimensions: Dimensions,
|
||||
): { guts: string; lineBackgrounds: string } {
|
||||
const dom = new JSDOM(shikiHtml);
|
||||
const document = dom.window.document;
|
||||
|
||||
|
|
@ -204,19 +258,70 @@ export class CodeRenderer {
|
|||
const el = node as HTMLElement;
|
||||
const style = el.getAttribute("style") || "";
|
||||
const colorMatch = style.match(/color:\s*(#[0-9a-fA-F]{6})/);
|
||||
const fill = colorMatch ? ` fill="${colorMatch[1]}"` : "";
|
||||
const classes = el.getAttribute("class") || "";
|
||||
let fill = colorMatch ? ` fill="${colorMatch[1]}"` : "";
|
||||
if (classes.includes("highlighted")) {
|
||||
fill = ` fill="${this.editorLineHighlight}"`;
|
||||
}
|
||||
const content = el.textContent || "";
|
||||
return `<tspan xml:space="preserve"${fill}>${escapeForSVG(content)}</tspan>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
const y = (index + 1) * lineHeight;
|
||||
return `<text x="0" y="${y}" font-family="${fontFamily}" font-size="${fontSize.toString()}" xml:space="preserve">${spans}</text>`;
|
||||
// Typography notes:
|
||||
// Each line of code is a <text> inside a <rect>.
|
||||
// Math becomes interesting here; the y value is actually aligned to the topmost border.
|
||||
// So y = 0 will have the rect be flush with the top border.
|
||||
// More importantly, text will also be positioned that way.
|
||||
// Since y = 0 is the axis the text will align itself to, the default settings will actually have the text sitting "on top of" the y = 0 axis, which effectively shifts them up.
|
||||
// To prevent this, we want the alignment axis to be at the middle of each rect, and have the text align itself vertically to the center (skwered by the axis).
|
||||
// The first step is to add lineHeight / 2 to move the axis down.
|
||||
// The second step is to add 'dominant-baseline="central"' to vertically center the text.
|
||||
// Note that we choose "central" over "middle". "middle" will center the text too perfectly, which is actually undesirable!
|
||||
const y = index * lineHeight + lineHeight / 2;
|
||||
return `<text x="0" y="${y}" font-family="${fontFamily}" font-size="${fontSize.toString()}" xml:space="preserve" dominant-baseline="central" shape-rendering="crispEdges">${spans}</text>`;
|
||||
});
|
||||
|
||||
return `
|
||||
${svgLines.join("\n")}
|
||||
`.trim();
|
||||
const lineBackgrounds = lines
|
||||
.map((line, index) => {
|
||||
const classes = line?.getAttribute("class") || "";
|
||||
const bgColor = classes.includes("highlighted")
|
||||
? this.editorLineHighlight
|
||||
: this.editorBackground;
|
||||
const y = index * lineHeight;
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === lines.length - 1;
|
||||
const radius = 10;
|
||||
// SVG notes:
|
||||
// By default SVGs have anti-aliasing on.
|
||||
// This is undesirable in our case because pixel-perfect alignment of these rectangles will introduce thin gaps.
|
||||
// Turning it off with 'shape-rendering="crispEdges"' solves the issue.
|
||||
return isFirst
|
||||
? `<path d="M ${0} ${y + lineHeight}
|
||||
L ${0} ${y + radius}
|
||||
Q ${0} ${y} ${radius} ${y}
|
||||
L ${dimensions.width - radius} ${y}
|
||||
Q ${dimensions.width} ${y} ${dimensions.width} ${y + radius}
|
||||
L ${dimensions.width} ${y + lineHeight}
|
||||
Z"
|
||||
fill="${bgColor}" />`
|
||||
: isLast
|
||||
? `<path d="M ${0} ${y}
|
||||
L ${0} ${y + lineHeight - radius}
|
||||
Q ${0} ${y + lineHeight} ${radius} ${y + lineHeight}
|
||||
L ${dimensions.width - radius} ${y + lineHeight}
|
||||
Q ${dimensions.width} ${y + lineHeight} ${dimensions.width} ${y + lineHeight - 10}
|
||||
L ${dimensions.width} ${y}
|
||||
Z"
|
||||
fill="${bgColor}" />`
|
||||
: `<rect x="0" y="${y}" rx="${radius}" ry="${radius}" width="100%" height="${lineHeight}" fill="${bgColor}" shape-rendering="crispEdges" />`;
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return {
|
||||
guts: svgLines.join("\n"),
|
||||
lineBackgrounds,
|
||||
};
|
||||
}
|
||||
|
||||
getBackgroundColor(shikiHtml: string): string {
|
||||
|
|
@ -244,6 +349,7 @@ export class CodeRenderer {
|
|||
dimensions: Dimensions,
|
||||
lineHeight: number,
|
||||
options: ConversionOptions,
|
||||
currLineOffsetFromTop: number,
|
||||
): Promise<DataUri> {
|
||||
switch (options.imageType) {
|
||||
// case "png":
|
||||
|
|
@ -265,6 +371,7 @@ export class CodeRenderer {
|
|||
dimensions,
|
||||
lineHeight,
|
||||
options,
|
||||
currLineOffsetFromTop,
|
||||
);
|
||||
return `data:image/svg+xml;base64,${svgBuffer.toString("base64")}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -643,6 +643,7 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription {
|
|||
template: llm.template,
|
||||
completionOptions: llm.completionOptions,
|
||||
baseAgentSystemMessage: llm.baseAgentSystemMessage,
|
||||
basePlanSystemMessage: llm.basePlanSystemMessage,
|
||||
baseChatSystemMessage: llm.baseChatSystemMessage,
|
||||
requestOptions: llm.requestOptions,
|
||||
promptTemplates: serializePromptTemplates(llm.promptTemplates),
|
||||
|
|
@ -650,6 +651,7 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription {
|
|||
roles: llm.roles,
|
||||
configurationStatus: llm.getConfigurationStatus(),
|
||||
apiKeyLocation: llm.apiKeyLocation,
|
||||
envSecretLocations: llm.envSecretLocations,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1004,6 +1004,8 @@ declare global {
|
|||
type: "stdio";
|
||||
command: string;
|
||||
args: string[];
|
||||
env?: Record<string, string>;
|
||||
cwd?: string;
|
||||
}
|
||||
|
||||
interface WebSocketOptions {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ function convertYamlMcpToContinueMcp(
|
|||
command: server.command,
|
||||
args: server.args ?? [],
|
||||
env: server.env,
|
||||
cwd: server.cwd,
|
||||
} as any, // TODO: Fix the mcpServers types in config-yaml (discriminated union)
|
||||
timeout: server.connectionTimeout,
|
||||
};
|
||||
|
|
|
|||
128
core/config/yaml/loadYaml.vitest.ts
Normal file
128
core/config/yaml/loadYaml.vitest.ts
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
validateConfigYaml,
|
||||
AssistantUnrolledNonNullable,
|
||||
} from "@continuedev/config-yaml";
|
||||
|
||||
describe("MCP Server cwd configuration", () => {
|
||||
describe("YAML schema validation", () => {
|
||||
it("should accept valid MCP server with cwd", () => {
|
||||
const config: AssistantUnrolledNonNullable = {
|
||||
name: "test-assistant",
|
||||
version: "1.0.0",
|
||||
mcpServers: [
|
||||
{
|
||||
name: "test-server",
|
||||
command: "node",
|
||||
args: ["server.js"],
|
||||
env: { NODE_ENV: "production" },
|
||||
cwd: "/path/to/project",
|
||||
connectionTimeout: 5000,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const errors = validateConfigYaml(config);
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should accept MCP server without cwd", () => {
|
||||
const config: AssistantUnrolledNonNullable = {
|
||||
name: "test-assistant",
|
||||
version: "1.0.0",
|
||||
mcpServers: [
|
||||
{
|
||||
name: "test-server",
|
||||
command: "python",
|
||||
args: ["-m", "server"],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const errors = validateConfigYaml(config);
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should accept relative paths in cwd", () => {
|
||||
const config: AssistantUnrolledNonNullable = {
|
||||
name: "test-assistant",
|
||||
version: "1.0.0",
|
||||
mcpServers: [
|
||||
{
|
||||
name: "test-server",
|
||||
command: "cargo",
|
||||
args: ["run"],
|
||||
cwd: "./rust-project",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const errors = validateConfigYaml(config);
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should accept empty string cwd", () => {
|
||||
const config: AssistantUnrolledNonNullable = {
|
||||
name: "test-assistant",
|
||||
version: "1.0.0",
|
||||
mcpServers: [
|
||||
{
|
||||
name: "test-server",
|
||||
command: "deno",
|
||||
args: ["run", "server.ts"],
|
||||
cwd: "",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const errors = validateConfigYaml(config);
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MCP server configuration examples", () => {
|
||||
it("should support common MCP server patterns with cwd", () => {
|
||||
const configs = [
|
||||
{
|
||||
name: "Local project MCP server",
|
||||
server: {
|
||||
name: "project-mcp",
|
||||
command: "npm",
|
||||
args: ["run", "mcp-server"],
|
||||
cwd: "/Users/developer/my-project",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Python MCP with virtual environment",
|
||||
server: {
|
||||
name: "python-mcp",
|
||||
command: "python",
|
||||
args: ["-m", "my_mcp_server"],
|
||||
env: { PYTHONPATH: "./src" },
|
||||
cwd: "/home/user/python-project",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Relative path MCP server",
|
||||
server: {
|
||||
name: "relative-mcp",
|
||||
command: "node",
|
||||
args: ["index.js"],
|
||||
cwd: "../mcp-servers/filesystem",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
configs.forEach(({ name, server }) => {
|
||||
const config: AssistantUnrolledNonNullable = {
|
||||
name: "test-assistant",
|
||||
version: "1.0.0",
|
||||
mcpServers: [server],
|
||||
};
|
||||
|
||||
const errors = validateConfigYaml(config);
|
||||
expect(errors).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -63,6 +63,7 @@ async function modelConfigToBaseLLM({
|
|||
template: model.promptTemplates?.chat,
|
||||
promptTemplates: model.promptTemplates,
|
||||
baseAgentSystemMessage: model.chatOptions?.baseAgentSystemMessage,
|
||||
basePlanSystemMessage: model.chatOptions?.basePlanSystemMessage,
|
||||
baseChatSystemMessage: model.chatOptions?.baseSystemMessage,
|
||||
capabilities: {
|
||||
tools: model.capabilities?.includes("tool_use"),
|
||||
|
|
@ -126,6 +127,12 @@ async function modelConfigToBaseLLM({
|
|||
if ("profile" in env && typeof env.profile === "string") {
|
||||
options.profile = env.profile;
|
||||
}
|
||||
if ("accessKeyId" in env && typeof env.accessKeyId === "string") {
|
||||
options.accessKeyId = env.accessKeyId;
|
||||
}
|
||||
if ("secretAccessKey" in env && typeof env.secretAccessKey === "string") {
|
||||
options.secretAccessKey = env.secretAccessKey;
|
||||
}
|
||||
if ("modelArn" in env && typeof env.modelArn === "string") {
|
||||
options.modelArn = env.modelArn;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,6 +329,7 @@ class MCPConnection {
|
|||
command,
|
||||
args,
|
||||
env,
|
||||
cwd: options.transport.cwd,
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import MCPConnection from "./MCPConnection";
|
||||
import { StdioOptions } from "../../index.d.js";
|
||||
|
||||
describe("MCPConnection", () => {
|
||||
beforeEach(() => {
|
||||
|
|
@ -25,6 +26,27 @@ describe("MCPConnection", () => {
|
|||
expect(conn.status).toBe("not-connected");
|
||||
});
|
||||
|
||||
it("should create instance with stdio transport including cwd", () => {
|
||||
const options = {
|
||||
name: "test-mcp",
|
||||
id: "test-id",
|
||||
transport: {
|
||||
type: "stdio" as const,
|
||||
command: "test-cmd",
|
||||
args: ["--test"],
|
||||
env: { TEST: "true" },
|
||||
cwd: "/path/to/working/directory",
|
||||
},
|
||||
};
|
||||
|
||||
const conn = new MCPConnection(options);
|
||||
expect(conn).toBeInstanceOf(MCPConnection);
|
||||
expect(conn.status).toBe("not-connected");
|
||||
if (conn.options.transport.type === "stdio") {
|
||||
expect(conn.options.transport.cwd).toBe("/path/to/working/directory");
|
||||
}
|
||||
});
|
||||
|
||||
it("should create instance with websocket transport", () => {
|
||||
const options = {
|
||||
name: "test-mcp",
|
||||
|
|
|
|||
|
|
@ -55,7 +55,11 @@ export async function* addIndentation(
|
|||
}
|
||||
|
||||
function modelIsInept(model: string): boolean {
|
||||
return !(model.includes("gpt") || model.includes("claude"));
|
||||
return !(
|
||||
model.includes("gpt") ||
|
||||
model.includes("claude") ||
|
||||
model.includes("nova")
|
||||
);
|
||||
}
|
||||
|
||||
export async function* streamDiffLines({
|
||||
|
|
|
|||
15
core/index.d.ts
vendored
15
core/index.d.ts
vendored
|
|
@ -428,7 +428,7 @@ export interface PromptLog {
|
|||
completion: string;
|
||||
}
|
||||
|
||||
export type MessageModes = "chat" | "agent";
|
||||
export type MessageModes = "chat" | "agent" | "plan";
|
||||
|
||||
export type ToolStatus =
|
||||
| "generating"
|
||||
|
|
@ -568,6 +568,7 @@ export interface LLMOptions {
|
|||
title?: string;
|
||||
uniqueId?: string;
|
||||
baseAgentSystemMessage?: string;
|
||||
basePlanSystemMessage?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
autocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
contextLength?: number;
|
||||
|
|
@ -583,6 +584,7 @@ export interface LLMOptions {
|
|||
|
||||
// continueProperties
|
||||
apiKeyLocation?: string;
|
||||
envSecretLocations?: Record<string, string>;
|
||||
apiBase?: string;
|
||||
orgScopeId?: string | null;
|
||||
|
||||
|
|
@ -611,6 +613,8 @@ export interface LLMOptions {
|
|||
// AWS options
|
||||
profile?: string;
|
||||
modelArn?: string;
|
||||
accessKeyId?: string;
|
||||
secretAccessKey?: string;
|
||||
|
||||
// AWS and VertexAI Options
|
||||
region?: string;
|
||||
|
|
@ -1082,6 +1086,7 @@ export interface ModelDescription {
|
|||
|
||||
apiBase?: string;
|
||||
apiKeyLocation?: string;
|
||||
envSecretLocations?: Record<string, string>;
|
||||
orgScopeId?: string | null;
|
||||
|
||||
onPremProxyUrl?: string | null;
|
||||
|
|
@ -1091,6 +1096,7 @@ export interface ModelDescription {
|
|||
template?: TemplateType;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
baseAgentSystemMessage?: string;
|
||||
basePlanSystemMessage?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
requestOptions?: RequestOptions;
|
||||
promptTemplates?: { [key: string]: string };
|
||||
|
|
@ -1162,6 +1168,7 @@ export interface StdioOptions {
|
|||
command: string;
|
||||
args: string[];
|
||||
env?: Record<string, string>;
|
||||
cwd?: string;
|
||||
requestOptions?: RequestOptions;
|
||||
}
|
||||
|
||||
|
|
@ -1636,9 +1643,11 @@ export interface TerminalOptions {
|
|||
|
||||
export type RuleSource =
|
||||
| "default-chat"
|
||||
| "default-plan"
|
||||
| "default-agent"
|
||||
| "model-chat-options"
|
||||
| "model-agent-options"
|
||||
| "model-options-chat"
|
||||
| "model-options-plan"
|
||||
| "model-options-agent"
|
||||
| "rules-block"
|
||||
| "json-systemMessage"
|
||||
| ".continuerules";
|
||||
|
|
|
|||
|
|
@ -237,6 +237,11 @@ function autodetectTemplateType(model: string): TemplateType | undefined {
|
|||
return "none";
|
||||
}
|
||||
|
||||
// Nova Pro requests always sent through Converse API, so formatting not necessary
|
||||
if (lower.includes("nova")) {
|
||||
return "none";
|
||||
}
|
||||
|
||||
if (lower.includes("codestral")) {
|
||||
return "none";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,19 @@ test("autodetectTemplateType returns 'none' for Codestral models", () => {
|
|||
expect(autodetectTemplateType("codestral-22b")).toBe("none");
|
||||
});
|
||||
|
||||
test("autodetectTemplateType returns 'none' for Nova models", () => {
|
||||
expect(autodetectTemplateType("nova")).toBe("none");
|
||||
expect(autodetectTemplateType("Nova")).toBe("none");
|
||||
expect(autodetectTemplateType("nova-pro")).toBe("none");
|
||||
expect(autodetectTemplateType("nova-lite")).toBe("none");
|
||||
expect(autodetectTemplateType("nova-micro")).toBe("none");
|
||||
expect(autodetectTemplateType("nova-premier")).toBe("none");
|
||||
expect(autodetectTemplateType("amazon-nova-pro")).toBe("none");
|
||||
expect(autodetectTemplateType("amazon-nova-lite")).toBe("none");
|
||||
expect(autodetectTemplateType("amazon-nova-micro")).toBe("none");
|
||||
expect(autodetectTemplateType("amazon-nova-premier")).toBe("none");
|
||||
});
|
||||
|
||||
test("autodetectTemplateType returns 'alpaca' for Alpaca and Wizard models", () => {
|
||||
expect(autodetectTemplateType("alpaca")).toBe("alpaca");
|
||||
expect(autodetectTemplateType("Alpaca")).toBe("alpaca");
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ const DEFAULT_MAX_BATCH_SIZE = 64;
|
|||
export enum LLMConfigurationStatuses {
|
||||
VALID = "valid",
|
||||
MISSING_API_KEY = "missing-api-key",
|
||||
MISSING_ENV_SECRET = "missing-env-secret",
|
||||
}
|
||||
|
||||
export {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL =
|
||||
"https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts";
|
||||
|
||||
export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL =
|
||||
export const DEFAULT_SYSTEM_MESSAGES_URL =
|
||||
"https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts";
|
||||
|
||||
export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\
|
||||
|
|
@ -66,3 +63,17 @@ export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\
|
|||
|
||||
${CODEBLOCK_FORMATTING_INSTRUCTIONS}
|
||||
</important_rules>`;
|
||||
|
||||
// The note about read-only tools is for MCP servers
|
||||
// For now, all MCP tools are included so model can decide if they are read-only
|
||||
export const DEFAULT_PLAN_SYSTEM_MESSAGE = `\
|
||||
<important_rules>
|
||||
You are in plan mode, in which you help the user understand and construct a plan.
|
||||
Only use read-only tools. Do not use any tools that would write to non-temporary files.
|
||||
If the user wants to make changes, offer that they can switch to Agent mode to give you access to write tools to make the suggested updates.
|
||||
|
||||
${CODEBLOCK_FORMATTING_INSTRUCTIONS}
|
||||
${EDIT_CODE_INSTRUCTIONS}
|
||||
|
||||
In plan mode, only write code when directly suggesting changes. Prioritize understanding and developing a plan.
|
||||
</important_rules>`;
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
title?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
basePlanSystemMessage?: string;
|
||||
baseAgentSystemMessage?: string;
|
||||
contextLength: number;
|
||||
maxStopWords?: number | undefined;
|
||||
|
|
@ -155,6 +156,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
// continueProperties
|
||||
apiKeyLocation?: string;
|
||||
envSecretLocations?: Record<string, string>;
|
||||
apiBase?: string;
|
||||
orgScopeId?: string | null;
|
||||
|
||||
|
|
@ -172,6 +174,8 @@ export abstract class BaseLLM implements ILLM {
|
|||
accountId?: string;
|
||||
aiGatewaySlug?: string;
|
||||
profile?: string | undefined;
|
||||
accessKeyId?: string;
|
||||
secretAccessKey?: string;
|
||||
|
||||
// For IBM watsonx
|
||||
deploymentId?: string;
|
||||
|
|
@ -209,6 +213,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
this.title = options.title;
|
||||
this.uniqueId = options.uniqueId ?? "None";
|
||||
this.baseAgentSystemMessage = options.baseAgentSystemMessage;
|
||||
this.basePlanSystemMessage = options.basePlanSystemMessage;
|
||||
this.baseChatSystemMessage = options.baseChatSystemMessage;
|
||||
this.contextLength =
|
||||
options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH;
|
||||
|
|
@ -246,6 +251,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
// continueProperties
|
||||
this.apiKeyLocation = options.apiKeyLocation;
|
||||
this.envSecretLocations = options.envSecretLocations;
|
||||
this.orgScopeId = options.orgScopeId;
|
||||
this.apiBase = options.apiBase;
|
||||
|
||||
|
|
@ -270,6 +276,8 @@ export abstract class BaseLLM implements ILLM {
|
|||
this.region = options.region;
|
||||
this.projectId = options.projectId;
|
||||
this.profile = options.profile;
|
||||
this.accessKeyId = options.accessKeyId;
|
||||
this.secretAccessKey = options.secretAccessKey;
|
||||
|
||||
this.openaiAdapter = this.createOpenAiAdapter();
|
||||
|
||||
|
|
|
|||
|
|
@ -71,11 +71,7 @@ class Bedrock extends BaseLLM {
|
|||
if (!options.apiBase) {
|
||||
this.apiBase = `https://bedrock-runtime.${options.region}.amazonaws.com`;
|
||||
}
|
||||
if (options.profile) {
|
||||
this.profile = options.profile;
|
||||
} else {
|
||||
this.profile = "bedrock";
|
||||
}
|
||||
|
||||
this.requestOptions = {
|
||||
region: options.region,
|
||||
headers: {},
|
||||
|
|
@ -609,17 +605,24 @@ class Bedrock extends BaseLLM {
|
|||
}
|
||||
|
||||
private async _getCredentials() {
|
||||
if (this.accessKeyId && this.secretAccessKey) {
|
||||
return {
|
||||
accessKeyId: this.accessKeyId,
|
||||
secretAccessKey: this.secretAccessKey,
|
||||
};
|
||||
}
|
||||
const profile = this.profile ?? "bedrock";
|
||||
try {
|
||||
return await fromNodeProviderChain({
|
||||
profile: this.profile,
|
||||
profile: profile,
|
||||
ignoreCache: true,
|
||||
})();
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
`AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`,
|
||||
`AWS profile with name ${profile} not found in ~/.aws/credentials, using default profile`,
|
||||
);
|
||||
return await fromNodeProviderChain()();
|
||||
}
|
||||
return await fromNodeProviderChain()();
|
||||
}
|
||||
|
||||
// EMBED //
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import {
|
|||
LLMOptions,
|
||||
} from "../..";
|
||||
import { renderTemplatedString } from "../../util/handlebars/renderTemplatedString";
|
||||
import { DEFAULT_CHAT_SYSTEM_MESSAGE } from "../defaultSystemMessages";
|
||||
import { BaseLLM } from "../index";
|
||||
import Anthropic from "./Anthropic";
|
||||
import Asksage from "./Asksage";
|
||||
|
|
@ -141,9 +140,9 @@ export async function llmFromDescription(
|
|||
|
||||
let baseChatSystemMessage: string | undefined = undefined;
|
||||
if (desc.systemMessage !== undefined) {
|
||||
baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE;
|
||||
baseChatSystemMessage += "\n\n";
|
||||
baseChatSystemMessage += await renderTemplatedString(
|
||||
// baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE;
|
||||
// baseChatSystemMessage += "\n\n";
|
||||
baseChatSystemMessage = await renderTemplatedString(
|
||||
Handlebars,
|
||||
desc.systemMessage,
|
||||
{},
|
||||
|
|
@ -163,6 +162,7 @@ export async function llmFromDescription(
|
|||
cls.defaultOptions?.completionOptions?.maxTokens,
|
||||
},
|
||||
baseChatSystemMessage,
|
||||
basePlanSystemMessage: baseChatSystemMessage,
|
||||
baseAgentSystemMessage: baseChatSystemMessage,
|
||||
logger: llmLogger,
|
||||
uniqueId,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class ContinueProxy extends OpenAI {
|
|||
this.apiType = undefined;
|
||||
this.actualApiBase = options.apiBase;
|
||||
this.apiKeyLocation = options.apiKeyLocation;
|
||||
this.envSecretLocations = options.envSecretLocations;
|
||||
this.orgScopeId = options.orgScopeId;
|
||||
this.onPremProxyUrl = options.onPremProxyUrl;
|
||||
if (this.onPremProxyUrl) {
|
||||
|
|
@ -60,6 +61,7 @@ class ContinueProxy extends OpenAI {
|
|||
protected extraBodyProperties(): Record<string, any> {
|
||||
const continueProperties: ContinueProperties = {
|
||||
apiKeyLocation: this.apiKeyLocation,
|
||||
envSecretLocations: this.envSecretLocations,
|
||||
apiBase: this.actualApiBase,
|
||||
orgScopeId: this.orgScopeId ?? null,
|
||||
env: this.configEnv,
|
||||
|
|
@ -70,13 +72,24 @@ class ContinueProxy extends OpenAI {
|
|||
}
|
||||
|
||||
getConfigurationStatus() {
|
||||
if (!this.apiKeyLocation) {
|
||||
if (!this.apiKeyLocation && !this.envSecretLocations) {
|
||||
return LLMConfigurationStatuses.VALID;
|
||||
}
|
||||
|
||||
const secretLocation = decodeSecretLocation(this.apiKeyLocation);
|
||||
if (secretLocation.secretType === SecretType.NotFound) {
|
||||
return LLMConfigurationStatuses.MISSING_API_KEY;
|
||||
if (this.apiKeyLocation) {
|
||||
const secretLocation = decodeSecretLocation(this.apiKeyLocation);
|
||||
if (secretLocation.secretType === SecretType.NotFound) {
|
||||
return LLMConfigurationStatuses.MISSING_API_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.envSecretLocations) {
|
||||
for (const secretLocation of Object.values(this.envSecretLocations)) {
|
||||
const decoded = decodeSecretLocation(secretLocation);
|
||||
if (decoded.secretType === SecretType.NotFound) {
|
||||
return LLMConfigurationStatuses.MISSING_ENV_SECRET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return LLMConfigurationStatuses.VALID;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
"claude-3-7",
|
||||
"claude-3.7",
|
||||
"claude-sonnet-4",
|
||||
"claude-4-sonnet",
|
||||
"gpt-4",
|
||||
"o3",
|
||||
"gemini",
|
||||
|
|
@ -33,6 +34,7 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
"claude-3-7",
|
||||
"claude-3.7",
|
||||
"claude-sonnet-4",
|
||||
"claude-4-sonnet",
|
||||
"claude-opus-4",
|
||||
].some((part) => model.toLowerCase().startsWith(part))
|
||||
) {
|
||||
|
|
@ -95,7 +97,12 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
"claude-3-7-sonnet",
|
||||
"claude-3.7-sonnet",
|
||||
"claude-sonnet-4",
|
||||
"claude-4-sonnet",
|
||||
"claude-opus-4",
|
||||
"nova-lite",
|
||||
"nova-pro",
|
||||
"nova-micro",
|
||||
"nova-premier",
|
||||
].some((part) => model.toLowerCase().includes(part))
|
||||
) {
|
||||
return true;
|
||||
|
|
|
|||
89
core/package-lock.json
generated
89
core/package-lock.json
generated
|
|
@ -82,6 +82,8 @@
|
|||
"@babel/preset-env": "^7.24.7",
|
||||
"@biomejs/biome": "1.6.4",
|
||||
"@google/generative-ai": "^0.11.4",
|
||||
"@shikijs/colorized-brackets": "^3.7.0",
|
||||
"@shikijs/transformers": "^3.7.0",
|
||||
"@types/diff": "^7.0.1",
|
||||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/jest": "^29.5.12",
|
||||
|
|
@ -4752,66 +4754,87 @@
|
|||
"integrity": "sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/@shikijs/core": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.6.0.tgz",
|
||||
"integrity": "sha512-9By7Xb3olEX0o6UeJyPLI1PE1scC4d3wcVepvtv2xbuN9/IThYN4Wcwh24rcFeASzPam11MCq8yQpwwzCgSBRw==",
|
||||
"node_modules/@shikijs/colorized-brackets": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/colorized-brackets/-/colorized-brackets-3.7.0.tgz",
|
||||
"integrity": "sha512-4tGMLMTqP7cw3AddjIjz7AlpPFuXpm2aDO25+uUHhGOVJvyDkm3a4cVb5W66QiBZFYsOyU6mx+lnsSimNTLsWQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "3.6.0",
|
||||
"shiki": "3.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/core": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.7.0.tgz",
|
||||
"integrity": "sha512-yilc0S9HvTPyahHpcum8eonYrQtmGTU0lbtwxhA6jHv4Bm1cAdlPFRCJX4AHebkCm75aKTjjRAW+DezqD1b/cg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "3.7.0",
|
||||
"@shikijs/vscode-textmate": "^10.0.2",
|
||||
"@types/hast": "^3.0.4",
|
||||
"hast-util-to-html": "^9.0.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/engine-javascript": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-3.6.0.tgz",
|
||||
"integrity": "sha512-7YnLhZG/TU05IHMG14QaLvTW/9WiK8SEYafceccHUSXs2Qr5vJibUwsDfXDLmRi0zHdzsxrGKpSX6hnqe0k8nA==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-3.7.0.tgz",
|
||||
"integrity": "sha512-0t17s03Cbv+ZcUvv+y33GtX75WBLQELgNdVghnsdhTgU3hVcWcMsoP6Lb0nDTl95ZJfbP1mVMO0p3byVh3uuzA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "3.6.0",
|
||||
"@shikijs/types": "3.7.0",
|
||||
"@shikijs/vscode-textmate": "^10.0.2",
|
||||
"oniguruma-to-es": "^4.3.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/engine-oniguruma": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.6.0.tgz",
|
||||
"integrity": "sha512-nmOhIZ9yT3Grd+2plmW/d8+vZ2pcQmo/UnVwXMUXAKTXdi+LK0S08Ancrz5tQQPkxvjBalpMW2aKvwXfelauvA==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.7.0.tgz",
|
||||
"integrity": "sha512-5BxcD6LjVWsGu4xyaBC5bu8LdNgPCVBnAkWTtOCs/CZxcB22L8rcoWfv7Hh/3WooVjBZmFtyxhgvkQFedPGnFw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "3.6.0",
|
||||
"@shikijs/types": "3.7.0",
|
||||
"@shikijs/vscode-textmate": "^10.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/langs": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.6.0.tgz",
|
||||
"integrity": "sha512-IdZkQJaLBu1LCYCwkr30hNuSDfllOT8RWYVZK1tD2J03DkiagYKRxj/pDSl8Didml3xxuyzUjgtioInwEQM/TA==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.7.0.tgz",
|
||||
"integrity": "sha512-1zYtdfXLr9xDKLTGy5kb7O0zDQsxXiIsw1iIBcNOO8Yi5/Y1qDbJ+0VsFoqTlzdmneO8Ij35g7QKF8kcLyznCQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "3.6.0"
|
||||
"@shikijs/types": "3.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/themes": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.6.0.tgz",
|
||||
"integrity": "sha512-Fq2j4nWr1DF4drvmhqKq8x5vVQ27VncF8XZMBuHuQMZvUSS3NBgpqfwz/FoGe36+W6PvniZ1yDlg2d4kmYDU6w==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.7.0.tgz",
|
||||
"integrity": "sha512-VJx8497iZPy5zLiiCTSIaOChIcKQwR0FebwE9S3rcN0+J/GTWwQ1v/bqhTbpbY3zybPKeO8wdammqkpXc4NVjQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/types": "3.6.0"
|
||||
"@shikijs/types": "3.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/transformers": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/transformers/-/transformers-3.7.0.tgz",
|
||||
"integrity": "sha512-VplaqIMRNsNOorCXJHkbF5S0pT6xm8Z/s7w7OPZLohf8tR93XH0krvUafpNy/ozEylrWuShJF0+ftEB+wFRwGA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/core": "3.7.0",
|
||||
"@shikijs/types": "3.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@shikijs/types": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.6.0.tgz",
|
||||
"integrity": "sha512-cLWFiToxYu0aAzJqhXTQsFiJRTFDAGl93IrMSBNaGSzs7ixkLfdG6pH11HipuWFGW5vyx4X47W8HDQ7eSrmBUg==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.7.0.tgz",
|
||||
"integrity": "sha512-MGaLeaRlSWpnP0XSAum3kP3a8vtcTsITqoEPYdt3lQG3YCdQH4DnEhodkYcNMcU0uW0RffhoD1O3e0vG5eSBBg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
@ -16249,18 +16272,18 @@
|
|||
}
|
||||
},
|
||||
"node_modules/shiki": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/shiki/-/shiki-3.6.0.tgz",
|
||||
"integrity": "sha512-tKn/Y0MGBTffQoklaATXmTqDU02zx8NYBGQ+F6gy87/YjKbizcLd+Cybh/0ZtOBX9r1NEnAy/GTRDKtOsc1L9w==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/shiki/-/shiki-3.7.0.tgz",
|
||||
"integrity": "sha512-ZcI4UT9n6N2pDuM2n3Jbk0sR4Swzq43nLPgS/4h0E3B/NrFn2HKElrDtceSf8Zx/OWYOo7G1SAtBLypCp+YXqg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@shikijs/core": "3.6.0",
|
||||
"@shikijs/engine-javascript": "3.6.0",
|
||||
"@shikijs/engine-oniguruma": "3.6.0",
|
||||
"@shikijs/langs": "3.6.0",
|
||||
"@shikijs/themes": "3.6.0",
|
||||
"@shikijs/types": "3.6.0",
|
||||
"@shikijs/core": "3.7.0",
|
||||
"@shikijs/engine-javascript": "3.7.0",
|
||||
"@shikijs/engine-oniguruma": "3.7.0",
|
||||
"@shikijs/langs": "3.7.0",
|
||||
"@shikijs/themes": "3.7.0",
|
||||
"@shikijs/types": "3.7.0",
|
||||
"@shikijs/vscode-textmate": "^10.0.2",
|
||||
"@types/hast": "^3.0.4"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
"@babel/preset-env": "^7.24.7",
|
||||
"@biomejs/biome": "1.6.4",
|
||||
"@google/generative-ai": "^0.11.4",
|
||||
"@shikijs/colorized-brackets": "^3.7.0",
|
||||
"@shikijs/transformers": "^3.7.0",
|
||||
"@types/diff": "^7.0.1",
|
||||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/jest": "^29.5.12",
|
||||
|
|
|
|||
|
|
@ -56,7 +56,11 @@ Critical rules:
|
|||
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
||||
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
||||
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
||||
4. Special operations:
|
||||
4. Splitting up tool calls:
|
||||
* When making multiple closely related edits to the same file, you should try to use multiple SEARCH/REPLACE blocks in a single tool call, rather than making multiple separate tool calls
|
||||
* If you need to make follow up edits or group your work into logical segments, it is okay to perform additional tool calls
|
||||
* DO NOT make back-to-back tool calls. Instead interleave with brief explanation of what each will do. For example, instead of [explanation, tool call, tool call] you should do [explanation, tool call, explanation, tool call]
|
||||
5. Special operations:
|
||||
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
||||
* To delete code: Use empty REPLACE section
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,34 @@
|
|||
import { ToolImpl } from ".";
|
||||
import { getUrlContextItems } from "../../context/providers/URLContextProvider";
|
||||
|
||||
const DEFAULT_FETCH_URL_CHAR_LIMIT = 20000;
|
||||
|
||||
export const fetchUrlContentImpl: ToolImpl = async (args, extras) => {
|
||||
return getUrlContextItems(args.url, extras.fetch);
|
||||
const contextItems = await getUrlContextItems(args.url, extras.fetch);
|
||||
|
||||
// Track truncated content
|
||||
const truncatedUrls: string[] = [];
|
||||
|
||||
// Check and truncate each context item
|
||||
const processedItems = contextItems.map((item) => {
|
||||
if (item.content.length > DEFAULT_FETCH_URL_CHAR_LIMIT) {
|
||||
truncatedUrls.push(args.url);
|
||||
return {
|
||||
...item,
|
||||
content: item.content.substring(0, DEFAULT_FETCH_URL_CHAR_LIMIT),
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
// Add truncation warning if needed
|
||||
if (truncatedUrls.length > 0) {
|
||||
processedItems.push({
|
||||
name: "URL content truncation warning",
|
||||
description: "Informs that URL content was truncated",
|
||||
content: `The content from ${truncatedUrls.join(", ")} was truncated because it exceeded the ${DEFAULT_FETCH_URL_CHAR_LIMIT} character limit. If you need more content, consider fetching specific sections or using a more targeted approach.`,
|
||||
});
|
||||
}
|
||||
|
||||
return processedItems;
|
||||
};
|
||||
|
|
|
|||
91
core/tools/implementations/fetchUrlContent.vitest.ts
Normal file
91
core/tools/implementations/fetchUrlContent.vitest.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import { expect, test, vi } from "vitest";
|
||||
import { fetchUrlContentImpl } from "./fetchUrlContent";
|
||||
|
||||
vi.mock("../../context/providers/URLContextProvider", () => ({
|
||||
getUrlContextItems: vi.fn(),
|
||||
}));
|
||||
|
||||
import { ToolExtras } from "../..";
|
||||
import { getUrlContextItems } from "../../context/providers/URLContextProvider";
|
||||
const mockExtras = {
|
||||
fetch: vi.fn() as any,
|
||||
ide: {} as any,
|
||||
} as unknown as ToolExtras;
|
||||
|
||||
test("fetchUrlContent should not truncate content under character limit", async () => {
|
||||
const shortContent = "This is a short content";
|
||||
const mockContextItems = [
|
||||
{
|
||||
name: "Test URL",
|
||||
description: "Test URL description",
|
||||
content: shortContent,
|
||||
},
|
||||
];
|
||||
|
||||
(getUrlContextItems as any).mockResolvedValue(mockContextItems);
|
||||
|
||||
const result = await fetchUrlContentImpl(
|
||||
{ url: "https://example.com" },
|
||||
mockExtras,
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].content).toBe(shortContent);
|
||||
});
|
||||
|
||||
test("fetchUrlContent should truncate content exceeding character limit", async () => {
|
||||
const DEFAULT_FETCH_URL_CHAR_LIMIT = 20000;
|
||||
// Create a string exceeding the character limit
|
||||
const longContent = "a".repeat(DEFAULT_FETCH_URL_CHAR_LIMIT + 1000);
|
||||
const mockContextItems = [
|
||||
{
|
||||
name: "Test URL",
|
||||
description: "Test URL description",
|
||||
content: longContent,
|
||||
},
|
||||
];
|
||||
|
||||
(getUrlContextItems as any).mockResolvedValue(mockContextItems);
|
||||
|
||||
const result = await fetchUrlContentImpl(
|
||||
{ url: "https://example.com" },
|
||||
mockExtras,
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(2); // Original item + warning
|
||||
expect(result[0].content.length).toBe(DEFAULT_FETCH_URL_CHAR_LIMIT);
|
||||
expect(result[1].name).toBe("URL content truncation warning");
|
||||
expect(result[1].content).toContain("was truncated");
|
||||
expect(result[1].content).toContain("20000 character limit");
|
||||
});
|
||||
|
||||
test("fetchUrlContent should add truncation warning with multiple truncated items", async () => {
|
||||
const DEFAULT_FETCH_URL_CHAR_LIMIT = 20000;
|
||||
// Create strings exceeding the character limit
|
||||
const longContent1 = "a".repeat(DEFAULT_FETCH_URL_CHAR_LIMIT + 500);
|
||||
const longContent2 = "b".repeat(DEFAULT_FETCH_URL_CHAR_LIMIT + 1000);
|
||||
const mockContextItems = [
|
||||
{
|
||||
name: "Test URL 1",
|
||||
description: "Test URL description 1",
|
||||
content: longContent1,
|
||||
},
|
||||
{
|
||||
name: "Test URL 2",
|
||||
description: "Test URL description 2",
|
||||
content: longContent2,
|
||||
},
|
||||
];
|
||||
|
||||
(getUrlContextItems as any).mockResolvedValue(mockContextItems);
|
||||
|
||||
const result = await fetchUrlContentImpl(
|
||||
{ url: "https://example.com" },
|
||||
mockExtras,
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(3); // Two original items + warning
|
||||
expect(result[0].content.length).toBe(DEFAULT_FETCH_URL_CHAR_LIMIT);
|
||||
expect(result[1].content.length).toBe(DEFAULT_FETCH_URL_CHAR_LIMIT);
|
||||
expect(result[2].name).toBe("URL content truncation warning");
|
||||
});
|
||||
|
|
@ -2,30 +2,59 @@ import { ToolImpl } from ".";
|
|||
import { walkDir } from "../../indexing/walkDir";
|
||||
import { resolveRelativePathInDir } from "../../util/ideUtils";
|
||||
|
||||
export function resolveLsToolDirPath(dirPath: string | undefined) {
|
||||
if (!dirPath || dirPath === ".") {
|
||||
return "/";
|
||||
}
|
||||
if (dirPath.startsWith(".")) {
|
||||
return dirPath.slice(1);
|
||||
}
|
||||
return dirPath.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
const MAX_LS_TOOL_LINES = 200;
|
||||
|
||||
export const lsToolImpl: ToolImpl = async (args, extras) => {
|
||||
const uri = await resolveRelativePathInDir(args.dirPath, extras.ide);
|
||||
const dirPath = resolveLsToolDirPath(args?.dirPath);
|
||||
const uri = await resolveRelativePathInDir(dirPath, extras.ide);
|
||||
if (!uri) {
|
||||
throw new Error(
|
||||
`Directory ${args.dirPath} not found. Make sure to use forward-slash paths. Do not use e.g. "."`,
|
||||
`Directory ${args.dirPath} not found. Make sure to use forward-slash paths`,
|
||||
);
|
||||
}
|
||||
|
||||
const entries = await walkDir(uri, extras.ide, {
|
||||
returnRelativeUrisPaths: true,
|
||||
include: "both",
|
||||
recursive: args.recursive ?? false,
|
||||
recursive: args?.recursive ?? false,
|
||||
});
|
||||
|
||||
const content =
|
||||
entries.length > 0
|
||||
? entries.join("\n")
|
||||
: `No files/folders found in ${args.dirPath}`;
|
||||
const lines = entries.slice(0, MAX_LS_TOOL_LINES);
|
||||
|
||||
return [
|
||||
let content =
|
||||
lines.length > 0
|
||||
? lines.join("\n")
|
||||
: `No files/folders found in ${dirPath}`;
|
||||
|
||||
const contextItems = [
|
||||
{
|
||||
name: "File/folder list",
|
||||
description: `Files/folders in ${args.dirPath}`,
|
||||
description: `Files/folders in ${dirPath}`,
|
||||
content,
|
||||
},
|
||||
];
|
||||
|
||||
if (entries.length > MAX_LS_TOOL_LINES) {
|
||||
let warningContent = `${entries.length - MAX_LS_TOOL_LINES} ls entries were truncated`;
|
||||
if (args?.recursive) {
|
||||
warningContent += ". Try using a non-recursive search";
|
||||
}
|
||||
contextItems.push({
|
||||
name: "ls truncation warning",
|
||||
description: "Informs the model that ls results were truncated",
|
||||
content: warningContent,
|
||||
});
|
||||
}
|
||||
|
||||
return contextItems;
|
||||
};
|
||||
|
|
|
|||
96
core/tools/implementations/lsTool.vitest.ts
Normal file
96
core/tools/implementations/lsTool.vitest.ts
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
import { expect, test, vi } from "vitest";
|
||||
import { ToolExtras } from "../..";
|
||||
import * as walkDirModule from "../../indexing/walkDir";
|
||||
import { lsToolImpl, resolveLsToolDirPath } from "./lsTool";
|
||||
|
||||
vi.mock("../../indexing/walkDir");
|
||||
|
||||
const mockExtras = {
|
||||
ide: {
|
||||
fileExists: async (path: string) => true,
|
||||
getWorkspaceDirs: async () => ["dir1"],
|
||||
},
|
||||
} as unknown as ToolExtras;
|
||||
|
||||
test("resolveLsToolDirPath handles undefined path", () => {
|
||||
expect(resolveLsToolDirPath(undefined)).toBe("/");
|
||||
});
|
||||
|
||||
test("resolveLsToolDirPath handles empty string", () => {
|
||||
expect(resolveLsToolDirPath("")).toBe("/");
|
||||
});
|
||||
|
||||
test("resolveLsToolDirPath handles dot", () => {
|
||||
expect(resolveLsToolDirPath(".")).toBe("/");
|
||||
});
|
||||
|
||||
test("resolveLsToolDirPath handles dot relative", () => {
|
||||
expect(resolveLsToolDirPath("./hi")).toBe("/hi");
|
||||
});
|
||||
|
||||
test("resolveLsToolDirPath normalizes backslashes to forward slashes", () => {
|
||||
expect(resolveLsToolDirPath("path\\to\\dir")).toBe("path/to/dir");
|
||||
});
|
||||
|
||||
test("resolveLsToolDirPath preserves forward slashes", () => {
|
||||
expect(resolveLsToolDirPath("path/to/dir")).toBe("path/to/dir");
|
||||
});
|
||||
|
||||
test("lsToolImpl truncates output when entries exceed MAX_LS_TOOL_LINES", async () => {
|
||||
// Generate more than MAX_LS_TOOL_LINES entries (which is 200)
|
||||
const mockEntries = Array.from({ length: 250 }, (_, i) => `file${i}.txt`);
|
||||
|
||||
// Mock walkDir to return our large array
|
||||
vi.spyOn(walkDirModule, "walkDir").mockResolvedValue(mockEntries);
|
||||
|
||||
const result = await lsToolImpl(
|
||||
{ dirPath: "testDir", recursive: true },
|
||||
mockExtras,
|
||||
);
|
||||
|
||||
// Check that the result contains the truncation message
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0].content).toContain("file1.txt");
|
||||
expect(result[0].content).toContain("file199.txt");
|
||||
expect(result[1].content).toContain("Try using a non-recursive search");
|
||||
expect(result[1].content).toContain("50 ls entries were truncated");
|
||||
|
||||
// Check that only MAX_LS_TOOL_LINES entries are included
|
||||
const contentLines = result[0].content.split("\n");
|
||||
// Account for the truncation message line
|
||||
expect(contentLines.length).toBe(200);
|
||||
|
||||
// Check the suggestion to use non-recursive search is included
|
||||
expect(result[1].content).toContain("Try using a non-recursive search");
|
||||
});
|
||||
|
||||
test("lsToolImpl shows truncation message without suggestion for non-recursive search", async () => {
|
||||
// Generate more than MAX_LS_TOOL_LINES entries
|
||||
const mockEntries = Array.from({ length: 250 }, (_, i) => `file${i}.txt`);
|
||||
|
||||
// Mock walkDir to return our large array
|
||||
vi.spyOn(walkDirModule, "walkDir").mockResolvedValue(mockEntries);
|
||||
|
||||
const result = await lsToolImpl(
|
||||
{ dirPath: "testDir", recursive: false },
|
||||
mockExtras,
|
||||
);
|
||||
|
||||
// Check that the result contains the truncation message
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[1].content).toContain("50 ls entries were truncated");
|
||||
|
||||
// Check that the suggestion to use non-recursive search is NOT included
|
||||
expect(result[1].content).not.toContain("Try using a non-recursive search");
|
||||
});
|
||||
|
||||
test("lsToolImpl shows message when no files are found", async () => {
|
||||
// Mock walkDir to return empty array
|
||||
vi.spyOn(walkDirModule, "walkDir").mockResolvedValue([]);
|
||||
|
||||
const result = await lsToolImpl({ dirPath: "emptyDir" }, mockExtras);
|
||||
|
||||
// Check that the result contains the "no files found" message
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].content).toBe("No files/folders found in emptyDir");
|
||||
});
|
||||
|
|
@ -1,8 +1,36 @@
|
|||
import { ToolImpl } from ".";
|
||||
import { fetchSearchResults } from "../../context/providers/WebContextProvider";
|
||||
|
||||
import { ToolImpl } from ".";
|
||||
const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000;
|
||||
|
||||
export const searchWebImpl: ToolImpl = async (args, extras) => {
|
||||
const webResults = await fetchSearchResults(args.query, 5, extras.fetch);
|
||||
return webResults;
|
||||
|
||||
// Track truncated results
|
||||
const truncatedResults: string[] = [];
|
||||
|
||||
// Check and truncate each result
|
||||
const processedResults = webResults.map((result, index) => {
|
||||
if (result.content.length > DEFAULT_WEB_SEARCH_CHAR_LIMIT) {
|
||||
truncatedResults.push(
|
||||
result.name || result.description || `Result #${index + 1}`,
|
||||
);
|
||||
return {
|
||||
...result,
|
||||
content: result.content.substring(0, DEFAULT_WEB_SEARCH_CHAR_LIMIT),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
// Add truncation warning if needed
|
||||
if (truncatedResults.length > 0) {
|
||||
processedResults.push({
|
||||
name: "Web search truncation warning",
|
||||
description: "Informs that search results were truncated",
|
||||
content: `The content from the following search results was truncated because it exceeded the ${DEFAULT_WEB_SEARCH_CHAR_LIMIT} character limit: ${truncatedResults.join(", ")}. For more detailed information, consider refining your search query.`,
|
||||
});
|
||||
}
|
||||
|
||||
return processedResults;
|
||||
};
|
||||
|
|
|
|||
107
core/tools/implementations/searchWeb.vitest.ts
Normal file
107
core/tools/implementations/searchWeb.vitest.ts
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import { expect, test, vi } from "vitest";
|
||||
import { searchWebImpl } from "./searchWeb";
|
||||
|
||||
// Mock the fetchSearchResults function
|
||||
vi.mock("../../context/providers/WebContextProvider", () => ({
|
||||
fetchSearchResults: vi.fn(),
|
||||
}));
|
||||
const mockExtras = {
|
||||
fetch: vi.fn() as any,
|
||||
ide: {} as any,
|
||||
} as unknown as ToolExtras;
|
||||
|
||||
import { ToolExtras } from "../..";
|
||||
import { fetchSearchResults } from "../../context/providers/WebContextProvider";
|
||||
|
||||
test("searchWeb should not truncate results under character limit", async () => {
|
||||
const shortContent = "This is a short search result content";
|
||||
const mockSearchResults = [
|
||||
{
|
||||
name: "Result 1",
|
||||
description: "Search result description 1",
|
||||
content: shortContent,
|
||||
},
|
||||
{
|
||||
name: "Result 2",
|
||||
description: "Search result description 2",
|
||||
content: shortContent,
|
||||
},
|
||||
];
|
||||
|
||||
(fetchSearchResults as any).mockResolvedValue(mockSearchResults);
|
||||
|
||||
const result = await searchWebImpl({ query: "test query" }, mockExtras);
|
||||
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].content).toBe(shortContent);
|
||||
expect(result[1].content).toBe(shortContent);
|
||||
});
|
||||
|
||||
test("searchWeb should truncate results exceeding character limit", async () => {
|
||||
const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000;
|
||||
// Create a string exceeding the character limit
|
||||
const longContent = "a".repeat(DEFAULT_WEB_SEARCH_CHAR_LIMIT + 1000);
|
||||
const shortContent = "This is a short search result content";
|
||||
const mockSearchResults = [
|
||||
{
|
||||
name: "Result 1",
|
||||
description: "Search result description 1",
|
||||
content: longContent,
|
||||
},
|
||||
{
|
||||
name: "Result 2",
|
||||
description: "Search result description 2",
|
||||
content: shortContent,
|
||||
},
|
||||
];
|
||||
|
||||
(fetchSearchResults as any).mockResolvedValue(mockSearchResults);
|
||||
|
||||
const result = await searchWebImpl({ query: "test query" }, mockExtras);
|
||||
|
||||
expect(result).toHaveLength(3); // Two results + warning
|
||||
expect(result[0].content.length).toBe(DEFAULT_WEB_SEARCH_CHAR_LIMIT);
|
||||
expect(result[1].content).toBe(shortContent);
|
||||
expect(result[2].name).toBe("Web search truncation warning");
|
||||
expect(result[2].content).toContain("truncated");
|
||||
expect(result[2].content).toContain("Result 1");
|
||||
expect(result[2].content).not.toContain("Result 2");
|
||||
});
|
||||
|
||||
test("searchWeb should include all truncated results in the warning", async () => {
|
||||
const DEFAULT_WEB_SEARCH_CHAR_LIMIT = 8000;
|
||||
// Create strings exceeding the character limit
|
||||
const longContent1 = "a".repeat(DEFAULT_WEB_SEARCH_CHAR_LIMIT + 500);
|
||||
const longContent2 = "b".repeat(DEFAULT_WEB_SEARCH_CHAR_LIMIT + 1000);
|
||||
const shortContent = "This is a short search result content";
|
||||
const mockSearchResults = [
|
||||
{
|
||||
name: "Result 1",
|
||||
description: "Search result description 1",
|
||||
content: longContent1,
|
||||
},
|
||||
{
|
||||
name: "Result 2",
|
||||
description: "Search result description 2",
|
||||
content: longContent2,
|
||||
},
|
||||
{
|
||||
name: "Result 3",
|
||||
description: "Search result description 3",
|
||||
content: shortContent,
|
||||
},
|
||||
];
|
||||
|
||||
(fetchSearchResults as any).mockResolvedValue(mockSearchResults);
|
||||
|
||||
const result = await searchWebImpl({ query: "test query" }, mockExtras);
|
||||
|
||||
expect(result).toHaveLength(4); // Three results + warning
|
||||
expect(result[0].content.length).toBe(DEFAULT_WEB_SEARCH_CHAR_LIMIT);
|
||||
expect(result[1].content.length).toBe(DEFAULT_WEB_SEARCH_CHAR_LIMIT);
|
||||
expect(result[2].content).toBe(shortContent);
|
||||
expect(result[3].name).toBe("Web search truncation warning");
|
||||
expect(result[3].content).toContain("Result 1");
|
||||
expect(result[3].content).toContain("Result 2");
|
||||
expect(result[3].content).not.toContain("Result 3");
|
||||
});
|
||||
|
|
@ -1,15 +1,39 @@
|
|||
import { ToolImpl } from ".";
|
||||
import { ContextItem } from "../..";
|
||||
import { getDiffsFromCache } from "../../autocomplete/snippets/gitDiffCache";
|
||||
|
||||
export const DEFAULT_GIT_DIFF_LINE_LIMIT = 5000;
|
||||
|
||||
export const viewDiffImpl: ToolImpl = async (args, extras) => {
|
||||
const diffs = await getDiffsFromCache(extras.ide); // const diffs = await extras.ide.getDiff(true);
|
||||
// TODO includeUnstaged should be an option
|
||||
|
||||
return [
|
||||
const combinedDiff = diffs.join("\n");
|
||||
const diffLines = combinedDiff.split("\n");
|
||||
|
||||
let truncated = false;
|
||||
let processedDiff = combinedDiff;
|
||||
|
||||
if (diffLines.length > DEFAULT_GIT_DIFF_LINE_LIMIT) {
|
||||
truncated = true;
|
||||
processedDiff = diffLines.slice(0, DEFAULT_GIT_DIFF_LINE_LIMIT).join("\n");
|
||||
}
|
||||
|
||||
const contextItems: ContextItem[] = [
|
||||
{
|
||||
name: "Diff",
|
||||
description: "The current git diff",
|
||||
content: diffs.join("\n"),
|
||||
content: processedDiff,
|
||||
},
|
||||
];
|
||||
|
||||
if (truncated) {
|
||||
contextItems.push({
|
||||
name: "Diff truncation warning",
|
||||
description: "Informs that git diff was truncated",
|
||||
content: `The git diff was truncated because it exceeded ${DEFAULT_GIT_DIFF_LINE_LIMIT} lines. Consider viewing specific files or focusing on smaller changes.`,
|
||||
});
|
||||
}
|
||||
|
||||
return contextItems;
|
||||
};
|
||||
|
|
|
|||
87
core/tools/implementations/viewDiff.vitest.ts
Normal file
87
core/tools/implementations/viewDiff.vitest.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { expect, test, vi } from "vitest";
|
||||
import { DEFAULT_GIT_DIFF_LINE_LIMIT, viewDiffImpl } from "./viewDiff";
|
||||
|
||||
// Mock the getDiffsFromCache function
|
||||
vi.mock("../../autocomplete/snippets/gitDiffCache", () => ({
|
||||
getDiffsFromCache: vi.fn(),
|
||||
}));
|
||||
|
||||
import { ToolExtras } from "../..";
|
||||
import { getDiffsFromCache } from "../../autocomplete/snippets/gitDiffCache";
|
||||
const mockExtras = {
|
||||
fetch: vi.fn() as any,
|
||||
ide: {} as any,
|
||||
} as unknown as ToolExtras;
|
||||
|
||||
test("viewDiff should not truncate diffs under line limit", async () => {
|
||||
// Create a small diff with just a few lines
|
||||
const smallDiff = [
|
||||
"diff --git a/file1.txt b/file1.txt",
|
||||
"index 1234..5678 100644",
|
||||
"--- a/file1.txt",
|
||||
"+++ b/file1.txt",
|
||||
"@@ -1,3 +1,4 @@",
|
||||
" line1",
|
||||
"-line2",
|
||||
"+line2 modified",
|
||||
"+line3 added",
|
||||
];
|
||||
|
||||
(getDiffsFromCache as any).mockResolvedValue(smallDiff);
|
||||
|
||||
const result = await viewDiffImpl({}, mockExtras);
|
||||
|
||||
expect(result).toHaveLength(1); // Just the diff, no warning
|
||||
expect(result[0].name).toBe("Diff");
|
||||
expect(result[0].content).toBe(smallDiff.join("\n"));
|
||||
});
|
||||
|
||||
test("viewDiff should truncate diffs exceeding line limit", async () => {
|
||||
// Create a large diff that exceeds the line limit
|
||||
const largeDiffLines = Array(DEFAULT_GIT_DIFF_LINE_LIMIT + 1000).fill(
|
||||
"line content",
|
||||
);
|
||||
const largeDiff = [
|
||||
"diff --git a/file1.txt b/file1.txt",
|
||||
"index 1234..5678 100644",
|
||||
...largeDiffLines,
|
||||
];
|
||||
|
||||
(getDiffsFromCache as any).mockResolvedValue([largeDiff.join("\n")]);
|
||||
|
||||
const result = await viewDiffImpl({}, mockExtras);
|
||||
|
||||
expect(result).toHaveLength(2); // Diff + warning
|
||||
|
||||
// Count the number of lines in the result
|
||||
const resultLines = result[0].content.split("\n");
|
||||
expect(resultLines.length).toBe(DEFAULT_GIT_DIFF_LINE_LIMIT);
|
||||
|
||||
// Check the warning
|
||||
expect(result[1].name).toBe("Diff truncation warning");
|
||||
expect(result[1].content).toContain("truncated");
|
||||
expect(result[1].content).toContain(`${DEFAULT_GIT_DIFF_LINE_LIMIT} lines`);
|
||||
});
|
||||
|
||||
test("viewDiff should handle multiple diffs correctly", async () => {
|
||||
const DEFAULT_GIT_DIFF_LINE_LIMIT = 5000;
|
||||
|
||||
// Create multiple diffs that together exceed the line limit
|
||||
const diff1Lines = Array(3000).fill("diff1 line");
|
||||
const diff2Lines = Array(3000).fill("diff2 line");
|
||||
const diff1 = diff1Lines.join("\n");
|
||||
const diff2 = diff2Lines.join("\n");
|
||||
|
||||
(getDiffsFromCache as any).mockResolvedValue([diff1, diff2]);
|
||||
|
||||
const result = await viewDiffImpl({}, mockExtras);
|
||||
|
||||
expect(result).toHaveLength(2); // Diff + warning
|
||||
|
||||
// Count the number of lines in the result
|
||||
const resultLines = result[0].content.split("\n");
|
||||
expect(resultLines.length).toBe(DEFAULT_GIT_DIFF_LINE_LIMIT);
|
||||
|
||||
// Check the warning
|
||||
expect(result[1].name).toBe("Diff truncation warning");
|
||||
});
|
||||
|
|
@ -39,14 +39,13 @@ export const getConfigDependentToolDefinitions = (
|
|||
params: ConfigDependentToolParams,
|
||||
): Tool[] => [
|
||||
requestRuleTool(params),
|
||||
// Search and replace is now generally available
|
||||
searchAndReplaceInFileTool,
|
||||
// Keep edit file tool available for models that need it
|
||||
editFileTool,
|
||||
...(params.enableExperimentalTools
|
||||
? [
|
||||
searchAndReplaceInFileTool,
|
||||
viewRepoMapTool,
|
||||
viewSubdirectoryTool,
|
||||
codebaseTool,
|
||||
]
|
||||
: [editFileTool]),
|
||||
? [viewRepoMapTool, viewSubdirectoryTool, codebaseTool]
|
||||
: []),
|
||||
];
|
||||
|
||||
export const getToolsForIde = async (ide: IDE): Promise<Tool[]> =>
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ keywords: [customize, configure, config]
|
|||
|
||||
Continue can be deeply customized. For example you might:
|
||||
|
||||
- **Change your Model Provider**. Continue allows you to choose your favorite or even add multiple model providers. This allows you to use different models for different tasks, or to try another model if you're not happy with the results from your current model. Continue supports all of the popular model providers, including OpenAI, Anthropic, Microsoft/Azure, Mistral, and more. You can even self host your own model provider if you'd like. Learn more about [model providers](../advanced/model-providers/top-level/openai.mdx).
|
||||
- **Select different models for specific tasks**. Different Continue features can use different models. We call these _model roles_. For example, you can use a different model for chat than you do for autocomplete. Learn more about [model roles](../advanced/model-roles/00-intro.mdx).
|
||||
- **Add a Context Provider**. Context providers allow you to add information to your prompts, giving your LLM additional context to work with. Context providers allow you to reference snippets from your codebase, or lookup relevant documentation, or use a search engine to find information and much more. Learn more about [context providers](../advanced/custom-providers.mdx).
|
||||
- **Create a Slash Command**. Slash commands allow you to easily add custom functionality to Continue. You can use a slash command that allows you to generate a shell command from natural language, or perhaps generate a commit message, or create your own custom command to do whatever you want. Learn more about [slash commands](../advanced/deep-dives/slash-commands.mdx).
|
||||
- **Call external tools and functions**. Unchain your LLM with the power of tools using [Agent](../features/agent/quick-start.mdx). Add custom tools using [MCP Servers](../advanced/deep-dives/mcp.mdx)
|
||||
- **Change your Model Provider**. Continue allows you to choose your favorite or even add multiple model providers. This allows you to use different models for different tasks, or to try another model if you're not happy with the results from your current model. Continue supports all of the popular model providers, including OpenAI, Anthropic, Microsoft/Azure, Mistral, and more. You can even self host your own model provider if you'd like. Learn more about [model providers](../customize/model-providers/top-level/openai.mdx).
|
||||
- **Select different models for specific tasks**. Different Continue features can use different models. We call these _model roles_. For example, you can use a different model for chat than you do for autocomplete. Learn more about [model roles](../customize/model-roles/00-intro.mdx).
|
||||
- **Add a Context Provider**. Context providers allow you to add information to your prompts, giving your LLM additional context to work with. Context providers allow you to reference snippets from your codebase, or lookup relevant documentation, or use a search engine to find information and much more. Learn more about [context providers](../customize/custom-providers.mdx).
|
||||
- **Create a Slash Command**. Slash commands allow you to easily add custom functionality to Continue. You can use a slash command that allows you to generate a shell command from natural language, or perhaps generate a commit message, or create your own custom command to do whatever you want. Learn more about [slash commands](../customize/deep-dives/slash-commands.mdx).
|
||||
- **Call external tools and functions**. Unchain your LLM with the power of tools using [Agent](../features/agent/quick-start.mdx). Add custom tools using [MCP Servers](../customize/deep-dives/mcp.mdx)
|
||||
|
||||
Whatever you choose, you'll probably start by editing your Assistant.
|
||||
|
||||
|
|
@ -21,4 +21,4 @@ You can easily access your assistant configuration from the Continue Chat sideba
|
|||

|
||||
|
||||
- See [Editing Hub Assistants](../hub/assistants/edit-an-assistant.md) for more details on managing your hub assistant
|
||||
- See the [Config Deep Dive](../advanced/deep-dives/configuration.md) for more details on configuring local assistants.
|
||||
- See the [Config Deep Dive](../customize/deep-dives/configuration.md) for more details on configuring local assistants.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ Model Context Protocol servers provide specialized functionality:
|
|||
|
||||
## Learn More
|
||||
|
||||
Learn more in the [MCP deep dive](../advanced/deep-dives/mcp.mdx), and view [`mcpServers`](/reference#mcpservers) in the YAML Reference for more details.
|
||||
Learn more in the [MCP deep dive](../customize/deep-dives/mcp.mdx), and view [`mcpServers`](/reference#mcpservers) in the YAML Reference for more details.
|
||||
description: Model Context Protocol servers provide specialized functionality
|
||||
keywords: [mcp, blocks, model context protocol, integrations, tools]
|
||||
sidebar_position: 4
|
||||
|
|
@ -37,4 +37,4 @@ Model Context Protocol servers provide specialized functionality:
|
|||
|
||||
## Learn More
|
||||
|
||||
Learn more in the [MCP deep dive](../advanced/deep-dives/mcp.mdx), and view [`mcpServers`](/reference#mcpservers) in the YAML Reference for more details.
|
||||
Learn more in the [MCP deep dive](../customize/deep-dives/mcp.mdx), and view [`mcpServers`](/reference#mcpservers) in the YAML Reference for more details.
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@ sidebar_position: 1
|
|||
|
||||
These blocks form the foundation of the entire assistant experience, offering different specialized capabilities:
|
||||
|
||||
- **[Chat](../advanced/model-roles/chat.mdx)**: Power conversational interactions about code and provide detailed guidance
|
||||
- **[Edit](../advanced/model-roles/edit.mdx)**: Handle complex code transformations and refactoring tasks
|
||||
- **[Apply](../advanced/model-roles/apply.mdx)**: Execute targeted code modifications with high accuracy
|
||||
- **[Autocomplete](../advanced/model-roles/autocomplete.md)**: Provide real-time suggestions as developers type
|
||||
- **[Embedding](../advanced/model-roles/embeddings.mdx)**: Transform code into vector representations for semantic search
|
||||
- **[Reranker](../advanced/model-roles/reranking.mdx)**: Improve search relevance by ordering results based on semantic meaning
|
||||
- **[Chat](../customize/model-roles/chat.mdx)**: Power conversational interactions about code and provide detailed guidance
|
||||
- **[Edit](../customize/model-roles/edit.mdx)**: Handle complex code transformations and refactoring tasks
|
||||
- **[Apply](../customize/model-roles/apply.mdx)**: Execute targeted code modifications with high accuracy
|
||||
- **[Autocomplete](../customize/model-roles/autocomplete.md)**: Provide real-time suggestions as developers type
|
||||
- **[Embedding](../customize/model-roles/embeddings.mdx)**: Transform code into vector representations for semantic search
|
||||
- **[Reranker](../customize/model-roles/reranking.mdx)**: Improve search relevance by ordering results based on semantic meaning
|
||||
|
||||

|
||||
|
||||
## Learn More
|
||||
|
||||
Continue supports [many model providers](../advanced/model-providers/top-level/openai.mdx), including Anthropic, OpenAI, Gemini, Ollama, Amazon Bedrock, Azure, xAI, DeepSeek, and more. Models can have various roles like `chat`, `edit`, `apply`, `autocomplete`, `embed`, and `rerank`.
|
||||
Continue supports [many model providers](../customize/model-providers/top-level/openai.mdx), including Anthropic, OpenAI, Gemini, Ollama, Amazon Bedrock, Azure, xAI, DeepSeek, and more. Models can have various roles like `chat`, `edit`, `apply`, `autocomplete`, `embed`, and `rerank`.
|
||||
|
||||
Read more about roles [here](../advanced/model-roles/00-intro.mdx) and view [`models`](/reference#models) in the YAML Reference.
|
||||
Read more about roles [here](../customize/model-roles/00-intro.mdx) and view [`models`](/reference#models) in the YAML Reference.
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@ These are the specialized instructions that shape how models respond:
|
|||
|
||||
## Learn More
|
||||
|
||||
Prompt blocks have the same syntax as [prompt files](../advanced/deep-dives/prompts.md). The `config.yaml` spec for `prompts` can be found [here](/reference#prompts).
|
||||
Prompt blocks have the same syntax as [prompt files](../customize/deep-dives/prompts.md). The `config.yaml` spec for `prompts` can be found [here](/reference#prompts).
|
||||
|
|
|
|||
|
|
@ -22,4 +22,4 @@ Your assistant detects rule blocks and applies the specified rules while in [Age
|
|||
|
||||
## Learn More
|
||||
|
||||
Learn more in the [rules deep dive](../advanced/deep-dives/rules.mdx), and view [`rules`](/reference#rules) in the YAML Reference for more details.
|
||||
Learn more in the [rules deep dive](../customize/deep-dives/rules.mdx), and view [`rules`](/reference#rules) in the YAML Reference for more details.
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ Explore autocomplete model configurations on [the hub](https://hub.continue.dev/
|
|||
### Autocomplete User Settings
|
||||
|
||||
{/* - `Use autocomplete cache`: If on, caches completions */}
|
||||
The following settings can be configured for autocompletion in the IDE extension [User Settings Page](./settings.md):
|
||||
The following settings can be configured for autocompletion in the IDE extension [User Settings Page](../settings.md):
|
||||
|
||||
- `Multiline Autocompletions`: Controls multiline completions for autocomplete. Can be set to `always`, `never`, or `auto`. Defaults to `auto`
|
||||
- `Disable autocomplete in files`: List of comma-separated glob pattern to disable autocomplete in matching files. E.g., "\_/.md, \*/.txt"
|
||||
|
|
@ -110,6 +110,7 @@ MCP blocks follow the established syntax for blocks, with a few additional prope
|
|||
- `type` (optional): The type of the MCP server: `sse`, `stdio`, `streamable-http`
|
||||
- `args` (optional): Arguments to pass to the command.
|
||||
- `env` (optional): Secrets to be injected into the command as environment variables.
|
||||
- `cwd` (optional): Working directory to run the command in. Can be absolute or relative path.
|
||||
|
||||
### Transport Types
|
||||
|
||||
|
|
@ -132,12 +133,22 @@ For local MCP servers that communicate via standard input and output:
|
|||
|
||||
```yaml
|
||||
mcpServers:
|
||||
- name: Name
|
||||
- name: SQLite Server
|
||||
type: stdio
|
||||
command: npx
|
||||
args:
|
||||
- "@modelcontextprotocol/server-sqlite"
|
||||
- "/path/to/your/database.db"
|
||||
- "./database.db"
|
||||
cwd: "/path/to/project"
|
||||
|
||||
- name: Local Project Server
|
||||
command: npm
|
||||
args:
|
||||
- "run"
|
||||
- "mcp-server"
|
||||
cwd: "./my-project"
|
||||
env:
|
||||
NODE_ENV: "production"
|
||||
```
|
||||
|
||||
#### Streamable HTTP Transport
|
||||
|
|
@ -14,7 +14,7 @@ Below are details for each property that can be set in `config.json`. The config
|
|||
|
||||
### `models`
|
||||
|
||||
Your **chat** models are defined here, which are used for [Chat](/features/chat/how-it-works), [Edit](/features/edit/how-it-works) and [VS Code actions](/advanced/deep-dives/vscode-actions).
|
||||
Your **chat** models are defined here, which are used for [Chat](/features/chat/how-it-works), [Edit](/features/edit/how-it-works) and [VS Code actions](/customize/deep-dives/vscode-actions).
|
||||
|
||||
Each model has specific configuration options tailored to its provider and functionality, which can be seen as suggestions while editing the json.
|
||||
|
||||
|
|
@ -506,7 +506,7 @@ Example
|
|||
|
||||
### Fully deprecated settings
|
||||
|
||||
Some deprecated `config.json` settings are no longer stored in config and have been moved to be editable through the [User Settings Page](/advanced/deep-dives/settings). If found in `config.json`, they will be auto-migrated to User Settings and removed from `config.json`.
|
||||
Some deprecated `config.json` settings are no longer stored in config and have been moved to be editable through the [User Settings Page](/customize/settings). If found in `config.json`, they will be auto-migrated to User Settings and removed from `config.json`.
|
||||
|
||||
- `allowAnonymousTelemetry`: This value will be migrated to the safest merged value (`false` if either are `false`).
|
||||
- `promptPath`: This value will override during migration.
|
||||
|
|
@ -527,4 +527,4 @@ Some deprecated `config.json` settings are no longer stored in config and have b
|
|||
- `displayRawMarkdown`
|
||||
- `showChatScrollbar`
|
||||
|
||||
See [User Settings Page](/advanced/deep-dives/settings) for more information about each option.
|
||||
See [User Settings Page](/customize/settings) for more information about each option.
|
||||
|
Before Width: | Height: | Size: 858 KiB After Width: | Height: | Size: 858 KiB |
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue