<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Adds Smart Context v3 with selectable modes (Off, Conservative,
Balanced) and surfaces token savings in chat. Also improves token
estimation by counting per-file tokens when Smart Context is enabled.
- **New Features**
- Smart Context selector in Pro settings with three options.
Conservative is the default when enabled without an explicit choice.
- New setting: proSmartContextOption ("balanced"); undefined implies
Conservative.
- Engine now receives enable_smart_files_context and smart_context_mode.
- Chat shows a DyadTokenSavings card when the message contains
token-savings?original-tokens=...&smart-context-tokens=..., with percent
saved and a tooltip for exact tokens.
- Token estimation uses extracted file contents for accuracy when Pro +
Smart Context is on; otherwise falls back to formatted codebase output.
<!-- End of auto-generated description by cubic. -->
138 lines
4.4 KiB
TypeScript
138 lines
4.4 KiB
TypeScript
import { test } from "./helpers/test_helper";
|
|
|
|
test("manage context - default", async ({ po }) => {
|
|
await po.setUp();
|
|
await po.importApp("context-manage");
|
|
|
|
const dialog = await po.openContextFilesPicker();
|
|
await po.snapshotDialog();
|
|
await dialog.addManualContextFile("DELETETHIS");
|
|
await dialog.removeManualContextFile();
|
|
await dialog.addManualContextFile("src/**/*.ts");
|
|
await dialog.addManualContextFile("src/sub/**");
|
|
await po.snapshotDialog();
|
|
await dialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
|
|
await po.snapshotServerDump("all-messages");
|
|
});
|
|
|
|
test("manage context - smart context", async ({ po }) => {
|
|
await po.setUpDyadPro();
|
|
await po.selectModel({ provider: "Google", model: "Gemini 2.5 Pro" });
|
|
await po.importApp("context-manage");
|
|
|
|
let dialog = await po.openContextFilesPicker();
|
|
await po.snapshotDialog();
|
|
|
|
await dialog.addManualContextFile("src/**/*.ts");
|
|
await dialog.addManualContextFile("src/sub/**");
|
|
await dialog.addAutoIncludeContextFile("a.ts");
|
|
await dialog.addAutoIncludeContextFile("manual/**");
|
|
await po.snapshotDialog();
|
|
await dialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
|
|
await po.snapshotServerDump("request");
|
|
await po.snapshotServerDump("all-messages");
|
|
|
|
// Disabling smart context will automatically disable
|
|
// the auto-includes.
|
|
const proModesDialog = await po.openProModesDialog();
|
|
await proModesDialog.setSmartContextMode("off");
|
|
await proModesDialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
await po.snapshotServerDump("request");
|
|
|
|
// Removing manual context files will result in all files being included.
|
|
dialog = await po.openContextFilesPicker();
|
|
await dialog.removeManualContextFile();
|
|
await dialog.removeManualContextFile();
|
|
await dialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
await po.snapshotServerDump("request");
|
|
});
|
|
|
|
test("manage context - smart context - auto-includes only", async ({ po }) => {
|
|
await po.setUpDyadPro();
|
|
await po.selectModel({ provider: "Google", model: "Gemini 2.5 Pro" });
|
|
await po.importApp("context-manage");
|
|
|
|
const dialog = await po.openContextFilesPicker();
|
|
await po.snapshotDialog();
|
|
|
|
await dialog.addAutoIncludeContextFile("a.ts");
|
|
await dialog.addAutoIncludeContextFile("manual/**");
|
|
await po.snapshotDialog();
|
|
await dialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
|
|
await po.snapshotServerDump("request");
|
|
});
|
|
|
|
test("manage context - exclude paths", async ({ po }) => {
|
|
await po.setUp();
|
|
await po.importApp("context-manage");
|
|
|
|
const dialog = await po.openContextFilesPicker();
|
|
await po.snapshotDialog();
|
|
|
|
// Add some include paths first
|
|
await dialog.addManualContextFile("src/**/*.ts");
|
|
await dialog.addManualContextFile("manual/**");
|
|
|
|
// Add exclude paths
|
|
await dialog.addExcludeContextFile("src/components/**");
|
|
await dialog.addExcludeContextFile("manual/exclude/**");
|
|
await po.snapshotDialog();
|
|
await dialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
await po.snapshotServerDump("all-messages", { name: "exclude-paths-basic" });
|
|
|
|
// Test that exclude paths take precedence over include paths
|
|
const dialog2 = await po.openContextFilesPicker();
|
|
await dialog2.removeExcludeContextFile(); // Remove src/components/**
|
|
await dialog2.addExcludeContextFile("src/**"); // This should exclude everything from src
|
|
await po.snapshotDialog();
|
|
await dialog2.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
await po.snapshotServerDump("all-messages", {
|
|
name: "exclude-paths-precedence",
|
|
});
|
|
});
|
|
|
|
test("manage context - exclude paths with smart context", async ({ po }) => {
|
|
await po.setUpDyadPro();
|
|
await po.selectModel({ provider: "Google", model: "Gemini 2.5 Pro" });
|
|
await po.importApp("context-manage");
|
|
|
|
const dialog = await po.openContextFilesPicker();
|
|
await po.snapshotDialog();
|
|
|
|
// Add manual context files
|
|
await dialog.addManualContextFile("src/**/*.ts");
|
|
await dialog.addManualContextFile("manual/**");
|
|
|
|
// Add smart context auto-includes
|
|
await dialog.addAutoIncludeContextFile("a.ts");
|
|
await dialog.addAutoIncludeContextFile("exclude/**");
|
|
|
|
// Add exclude paths that should filter out some of the above
|
|
await dialog.addExcludeContextFile("src/components/**");
|
|
await dialog.addExcludeContextFile("exclude/exclude.ts");
|
|
await po.snapshotDialog();
|
|
await dialog.close();
|
|
|
|
await po.sendPrompt("[dump]");
|
|
await po.snapshotServerDump("all-messages", {
|
|
name: "exclude-paths-with-smart-context",
|
|
});
|
|
});
|