Skip to content

Commit 7e30a63

Browse files
authored
Merge pull request #7342 from continuedev/nate-3
Add tokenizer tests and fix auto-compact calculation to account for max_tokens
2 parents 4b41ad3 + d235cb4 commit 7e30a63

26 files changed

+1579
-265
lines changed

.github/actions/run-jetbrains-tests/action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ runs:
4444
- name: Setup FFmpeg
4545
uses: AnimMouse/setup-ffmpeg@v1
4646
with:
47+
version: 7.1
4748
token: ${{ inputs.github-token }}
4849

4950
- name: Setup Gradle
@@ -135,14 +136,22 @@ runs:
135136
shell: bash
136137
run: |
137138
cd extensions/intellij
138-
mv video build/reports
139+
if [ -d "video" ]; then
140+
mv video build/reports
141+
else
142+
echo "No video directory found to move"
143+
fi
139144
140145
- name: Copy logs
141146
if: ${{ failure() }}
142147
shell: bash
143148
run: |
144149
cd extensions/intellij
145-
mv build/idea-sandbox/system/log/ build/reports
150+
if [ -d "build/idea-sandbox/system/log/" ]; then
151+
mv build/idea-sandbox/system/log/ build/reports
152+
else
153+
echo "No log directory found to copy"
154+
fi
146155
147156
- name: Save fails report
148157
if: ${{ failure() }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Track Workflow Rerun
2+
description: Track when GitHub Actions workflows are rerun (attempt > 1)
3+
4+
runs:
5+
using: composite
6+
steps:
7+
# Eventually we can start logging this to monitor codebase health (e.g. to Slack, PostHog, etc.)
8+
- name: Track workflow rerun
9+
if: github.run_attempt > 1
10+
shell: bash
11+
run: |
12+
echo "🔄 Workflow rerun detected - Attempt #${{ github.run_attempt }}"
13+
echo "📊 Workflow: ${{ github.workflow }}"
14+
echo "🔀 PR: ${{ github.event.pull_request.number || 'N/A' }}"
15+
echo "📝 Commit: ${{ github.sha }}"
16+
echo "👤 Actor: ${{ github.actor }}"
17+
echo "⏰ Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
18+
echo ""
19+
echo "::notice title=Workflow Rerun Detected::This is attempt #${{ github.run_attempt }} of workflow '${{ github.workflow }}'"

.github/workflows/cli-pr-checks.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ permissions:
1212
issues: write
1313

1414
jobs:
15+
track-rerun:
16+
runs-on: ubuntu-latest
17+
if: github.run_attempt > 1
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Track workflow rerun
21+
uses: ./.github/actions/track-rerun
22+
1523
lint:
1624
runs-on: ubuntu-latest
1725
steps:

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
publish_build:
1010
description: "Whether or not to publish the built extension to the VS Code marketplace"
1111
required: true
12-
default: false
12+
default: "false"
1313

1414
jobs:
1515
check_release_name:

.github/workflows/pr-checks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ on:
1111
- main
1212

1313
jobs:
14+
track-rerun:
15+
runs-on: ubuntu-latest
16+
if: github.run_attempt > 1
17+
steps:
18+
- uses: actions/checkout@v5
19+
- name: Track workflow rerun
20+
uses: ./.github/actions/track-rerun
21+
1422
prettier-check:
1523
runs-on: ubuntu-latest
1624
steps:

.github/workflows/preview.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
publish_build:
1010
description: "Whether or not to publish the built extension to the VS Code marketplace"
1111
required: true
12-
default: false
12+
default: "false"
1313

1414
jobs:
1515
check_release_name:

extensions/cli/build.mjs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

33
import * as esbuild from "esbuild";
4-
import { writeFileSync, chmodSync } from "fs";
5-
import { resolve, dirname } from "path";
4+
import { chmodSync, writeFileSync } from "fs";
5+
import { dirname, resolve } from "path";
66
import { fileURLToPath } from "url";
77

88
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -59,9 +59,15 @@ try {
5959
__dirname,
6060
"../../packages/config-types/dist/index.js",
6161
),
62-
"core": resolve(__dirname, "../../core"),
63-
"@continuedev/fetch": resolve(__dirname, "../../packages/fetch/dist/index.js"),
64-
"@continuedev/llm-info": resolve(__dirname, "../../packages/llm-info/dist/index.js"),
62+
core: resolve(__dirname, "../../core"),
63+
"@continuedev/fetch": resolve(
64+
__dirname,
65+
"../../packages/fetch/dist/index.js",
66+
),
67+
"@continuedev/llm-info": resolve(
68+
__dirname,
69+
"../../packages/llm-info/dist/index.js",
70+
),
6571
},
6672

6773
// Add banner to create require for CommonJS packages
@@ -76,7 +82,7 @@ const require = createRequire(import.meta.url);`,
7682

7783
// Create wrapper script with shebang
7884
writeFileSync("dist/cn.js", "#!/usr/bin/env node\nimport('./index.js');");
79-
85+
8086
// Make the wrapper script executable
8187
chmodSync("dist/cn.js", 0o755);
8288

extensions/cli/src/commands/chat.ts

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -159,72 +159,79 @@ async function handleManualCompaction(
159159
}
160160
}
161161

162-
// Helper function to handle auto-compaction
162+
// Helper function to handle auto-compaction for headless mode
163163
async function handleAutoCompaction(
164164
chatHistory: ChatCompletionMessageParam[],
165165
model: ModelConfig,
166166
llmApi: any,
167167
isHeadless: boolean,
168168
format?: "json",
169169
): Promise<number | null> {
170-
logger.info("Auto-compacting triggered due to context limit");
171-
172-
if (!isHeadless) {
173-
console.info(
174-
chalk.yellow(
175-
"\nApproaching context limit. Auto-compacting chat history...",
176-
),
177-
);
178-
} else if (format === "json") {
179-
safeStdout(
180-
JSON.stringify({
181-
status: "info",
182-
message: "Auto-compacting triggered",
183-
contextUsage:
184-
calculateContextUsagePercentage(
185-
countChatHistoryTokens(chatHistory),
186-
model,
187-
) + "%",
188-
}) + "\n",
189-
);
190-
}
170+
const { handleAutoCompaction: coreAutoCompaction } = await import(
171+
"../streamChatResponse.autoCompaction.js"
172+
);
191173

192-
try {
193-
const result = await compactChatHistory(chatHistory, model, llmApi);
194-
chatHistory.length = 0;
195-
chatHistory.push(...result.compactedHistory);
196-
saveSession(chatHistory);
174+
// Custom callbacks for headless mode console output
175+
const callbacks = {
176+
onSystemMessage: (message: string) => {
177+
if (
178+
message.includes("Auto-compacting") ||
179+
message.includes("Approaching")
180+
) {
181+
if (!isHeadless) {
182+
console.info(chalk.yellow(`\n${message}`));
183+
} else if (format === "json") {
184+
safeStdout(
185+
JSON.stringify({
186+
status: "info",
187+
message: "Auto-compacting triggered",
188+
contextUsage:
189+
calculateContextUsagePercentage(
190+
countChatHistoryTokens(chatHistory),
191+
model,
192+
) + "%",
193+
}) + "\n",
194+
);
195+
}
196+
} else if (message.includes("✓")) {
197+
if (!isHeadless) {
198+
console.info(chalk.green(message));
199+
} else if (format === "json") {
200+
safeStdout(
201+
JSON.stringify({
202+
status: "success",
203+
message: "Auto-compacted successfully",
204+
historyLength: chatHistory.length,
205+
}) + "\n",
206+
);
207+
}
208+
} else if (message.includes("Warning:")) {
209+
if (!isHeadless) {
210+
console.error(chalk.red(message));
211+
console.info(chalk.yellow("Continuing without compaction..."));
212+
} else if (format === "json") {
213+
safeStdout(
214+
JSON.stringify({
215+
status: "warning",
216+
message: "Auto-compaction failed, continuing without compaction",
217+
}) + "\n",
218+
);
219+
}
220+
}
221+
},
222+
};
197223

198-
if (!isHeadless) {
199-
console.info(chalk.green("✓ Chat history auto-compacted successfully."));
200-
} else if (format === "json") {
201-
safeStdout(
202-
JSON.stringify({
203-
status: "success",
204-
message: "Auto-compacted successfully",
205-
historyLength: chatHistory.length,
206-
}) + "\n",
207-
);
208-
}
224+
const result = await coreAutoCompaction(chatHistory, model, llmApi, {
225+
isHeadless,
226+
format,
227+
callbacks,
228+
});
209229

210-
return result.compactionIndex;
211-
} catch (error) {
212-
const errorMsg = `Auto-compaction error: ${formatError(error)}`;
213-
logger.error(errorMsg);
230+
// Update the original array reference for headless mode
231+
chatHistory.length = 0;
232+
chatHistory.push(...result.chatHistory);
214233

215-
if (!isHeadless) {
216-
console.error(chalk.red(`Warning: ${errorMsg}`));
217-
console.info(chalk.yellow("Continuing without compaction..."));
218-
} else if (format === "json") {
219-
safeStdout(
220-
JSON.stringify({
221-
status: "warning",
222-
message: "Auto-compaction failed, continuing without compaction",
223-
}) + "\n",
224-
);
225-
}
226-
return null;
227-
}
234+
return result.compactionIndex;
228235
}
229236

230237
interface ProcessMessageOptions {

extensions/cli/src/commands/commands.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { type AssistantConfig } from "@continuedev/sdk";
44
export { chat } from "./chat.js";
55
export { login } from "./login.js";
66
export { logout } from "./logout.js";
7+
export { listSessionsCommand } from "./ls.js";
78
export { remote } from "./remote.js";
89
export { serve } from "./serve.js";
9-
export { listSessionsCommand } from "./ls.js";
1010

1111
export interface SlashCommand {
1212
name: string;
@@ -45,6 +45,11 @@ export const SYSTEM_SLASH_COMMANDS: SystemCommand[] = [
4545
description: "Check who you're currently logged in as",
4646
category: "system",
4747
},
48+
{
49+
name: "info",
50+
description: "Show session information",
51+
category: "system",
52+
},
4853
{
4954
name: "model",
5055
description: "Switch between available chat models",

0 commit comments

Comments
 (0)