Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compress-loop-responses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
buildStatusReport,
estimateTokensFast,
defaultCountTokens,
type CompressionCore,
type Config,
type CoreMessage,
Expand Down Expand Up @@ -102,7 +102,7 @@ function executeProxyTool(
return `Found ${blocks.length} block(s) for "${query}":\n\n${lines.join("\n\n")}`;
}
if (toolName === "acp_status") {
return buildStatusReport(ctx.session.state, ctx.messages, estimateTokensFast);
return buildStatusReport(ctx.session.state, ctx.messages, defaultCountTokens);
}
return `[Unknown proxy tool: ${toolName}]`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/loop/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
buildStatusReport,
estimateTokensFast,
defaultCountTokens,
formatRanges,
hideConsumedCompressCalls,
type CompressionCore,
Expand Down Expand Up @@ -145,7 +145,7 @@ function handleAcpStatus(args: Record<string, unknown>, ctx: LoopCtx): string {
const tool = typeof args.tool === "string" ? args.tool : undefined;
const sort = typeof args.sort === "string" ? (args.sort as "size" | "time" | "tool" | "age") : undefined;
const limit = typeof args.limit === "number" ? args.limit : undefined;
const base = buildStatusReport(ctx.session.state, ctx.messages, estimateTokensFast, { scope, view, tool, sort, limit });
const base = buildStatusReport(ctx.session.state, ctx.messages, defaultCountTokens, { scope, view, tool, sort, limit });
if (scope) return base;
const nudge = ctx.nudge;
const ranges = nudge?.compressibleRanges ?? [];
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import http from "node:http";
import fs from "node:fs";
import { randomUUID } from "node:crypto";
import { createCore, type CompressionCore, type CompressionState, type Config, type CoreMessage, type NudgeDecision, type Prompts, defaultPrompts, defaultCountTokens, estimateTokensFast, renderNudgeText, deactivateBlock, viableRanges } from "acp-kernel";
import { createCore, type CompressionCore, type CompressionState, type Config, type CoreMessage, type NudgeDecision, type Prompts, defaultPrompts, defaultCountTokens, renderNudgeText, deactivateBlock, viableRanges } from "acp-kernel";
import { resolveCompress, resolveCompressPrompts, resolveRequestConfig } from "./compress-settings.js";
import type { ProxyOptions } from "./config.js";
import { loadOptions, loadRoutes } from "./config.js";
Expand Down
4 changes: 2 additions & 2 deletions src/stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildStatusReport, collectBlockContent, estimateTokensFast, type CompressionCore, type Config, type CoreMessage, type CompressionState } from "acp-kernel";
import { buildStatusReport, collectBlockContent, defaultCountTokens, type CompressionCore, type Config, type CoreMessage, type CompressionState } from "acp-kernel";
import { type Session, cacheBlockContent } from "./session.js";
import { COMPRESS_TOOL_NAME, parseCompressInput, PROXY_TOOL_NAMES } from "./compress-tool.js";
import { resolveDecompress } from "./decompress-shared.js";
Expand Down Expand Up @@ -43,7 +43,7 @@ function executeAnthropicProxyTool(toolName: string, args: Record<string, unknow
return `Found ${blocks.length} block(s) for "${query}":\n\n${lines.join("\n\n")}`;
}
if (toolName === "acp_status") {
return buildStatusReport(ctx.session.state, ctx.messages, estimateTokensFast);
return buildStatusReport(ctx.session.state, ctx.messages, defaultCountTokens);
}
return `[Unknown proxy tool: ${toolName}]`;
}
Expand Down
39 changes: 38 additions & 1 deletion tests/loop-core.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import type { Config, CoreMessage } from "acp-kernel";
import { createCore, createInitialState } from "acp-kernel";
import { assignRefs, createCore, createInitialState } from "acp-kernel";
import type { Session } from "../src/session.ts";
import { runCompressLoop, createResponsesAdapter } from "../src/loop/index.ts";
import { buildCompressSystemPrompt } from "../src/compress-tool.ts";
Expand Down Expand Up @@ -92,6 +92,43 @@ test("loop #1: acp_status-only round → marker surfaced + re-request (avoids to
}
});

test("loop #390: acp_status breakdown uses the CJK-aware scale (no 4x underestimate)", async () => {
// 4000 CJK chars = 4000 tokens on defaultCountTokens (the nudge's scale),
// 1000 on estimateTokensFast — the old acp_status scale (issue #390).
const messages: CoreMessage[] = [
{ id: "m1", role: "user", contentType: "text", text: "中".repeat(4_000) },
];
const ctx = makeCtx(messages, "responses");
ctx.session.state.messageRefs = assignRefs(messages, {
existing: ctx.session.state.messageRefs,
nextIndex: 1,
}).map;
const round1 = [
sse("response.created", { response: { id: "resp_1", status: "in_progress" } }),
fcEvents(0, "call_status", "acp_status", "{}"),
COMPLETED,
].join("");
let captured = "";
const orig = globalThis.fetch;
globalThis.fetch = (async (_url: unknown, init?: RequestInit) => {
captured = typeof init?.body === "string" ? init.body : "";
return new Response(COMPLETED, { status: 200 });
}) as typeof fetch;
try {
await drain(
new Response(round1, { status: 200 }).body!,
ctx,
{ model: "gpt-4o", input: [], stream: true },
{ url: "http://mock", headers: {} },
);
assert.ok(captured, "re-request after acp_status carries the report");
assert.match(captured, /4\.0K text \(100%\)/, "CJK counted 1:1, not chars/4");
assert.doesNotMatch(captured, /1\.0K text \(100%\)/, "chars/4 scale must not appear");
} finally {
globalThis.fetch = orig;
}
});

test("loop #2: search_context-only round → marker surfaced + re-request", async () => {
const round1 = [
sse("response.created", { response: { id: "resp_1", status: "in_progress" } }),
Expand Down
Loading