chatccc 0.2.167 → 0.2.169
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -513,13 +513,15 @@ describe("buildClaudePromptText", () => {
|
|
|
513
513
|
});
|
|
514
514
|
|
|
515
515
|
describe("buildSdkEnv", () => {
|
|
516
|
-
it("
|
|
516
|
+
it("always sets CLAUDE_CODE_ATTRIBUTION_HEADER=0 to preserve prompt cache hit rate", () => {
|
|
517
517
|
const originalPath = process.env.PATH;
|
|
518
518
|
try {
|
|
519
519
|
process.env.PATH = process.platform === "win32"
|
|
520
520
|
? "C:\\Program Files\\Git\\usr\\bin;C:\\Windows\\System32"
|
|
521
521
|
: "/usr/bin:/bin";
|
|
522
|
-
|
|
522
|
+
const env = buildSdkEnv("", " ", undefined);
|
|
523
|
+
expect(env).toBeDefined();
|
|
524
|
+
expect(env!.CLAUDE_CODE_ATTRIBUTION_HEADER).toBe("0");
|
|
523
525
|
} finally {
|
|
524
526
|
process.env.PATH = originalPath;
|
|
525
527
|
}
|
|
@@ -87,6 +87,11 @@ export function buildSdkEnv(
|
|
|
87
87
|
const env: Record<string, string | undefined> = { ...process.env };
|
|
88
88
|
let mutated = preferGitBashOnWindows(env);
|
|
89
89
|
|
|
90
|
+
// Claude Code 2.1.136+ 会在每次请求中注入 x-anthropic-billing-header,
|
|
91
|
+
// 导致 prompt 前缀变化、缓存命中率急剧下降。设为 0 关闭。
|
|
92
|
+
env.CLAUDE_CODE_ATTRIBUTION_HEADER = "0";
|
|
93
|
+
mutated = true;
|
|
94
|
+
|
|
90
95
|
if (subagentModelTrim || apiKeyTrim || baseUrlTrim) {
|
|
91
96
|
delete env.ANTHROPIC_AUTH_TOKEN;
|
|
92
97
|
delete env.CLAUDE_CODE_OAUTH_TOKEN;
|
package/src/session.ts
CHANGED
|
@@ -1605,6 +1605,13 @@ export function stopSession(sessionId: string): boolean {
|
|
|
1605
1605
|
clearPromptProcessMonitor(sessionId);
|
|
1606
1606
|
cancelQueuedMessage(sessionId);
|
|
1607
1607
|
prompt.controller.abort();
|
|
1608
|
+
|
|
1609
|
+
// 强制杀死 CLI 子进程。controller.abort() 只在 for-await 收到下一条
|
|
1610
|
+
// stream 消息时才被检测到——如果 agent 陷入无输出的计算循环,abort 信号
|
|
1611
|
+
// 永远不会生效。直接 process.kill 让 stdout/stderr 管道关闭,stream 立即结束。
|
|
1612
|
+
if (prompt.processPid !== undefined) {
|
|
1613
|
+
try { process.kill(prompt.processPid); } catch { /* 进程可能已退出 */ }
|
|
1614
|
+
}
|
|
1608
1615
|
console.log(`[${ts()}] [STOP] Session ${sessionId} aborted`);
|
|
1609
1616
|
|
|
1610
1617
|
// fire-and-forget:立刻把 stream-state.status 改成 stopped,
|