Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(maker-core): 显式来源会话把路由核实窗口注入 CC 上下文映射 (#3678)

fico-hubf7371de0d8c8
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/env-builder.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/env-builder.test.ts
index 90ca1eeb9b..027bce8756 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/env-builder.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/env-builder.test.ts
@@ -242,6 +242,35 @@ describe('buildClaudeEnv', () => {
});
});
+ it('大写 [1M] 后缀不再镜像出 [1M][1m] 垃圾键 (#3661)', async () => {
+ const env = await buildClaudeEnv(createAuthAdapter(), {}, {
+ modelContextWindows: [
+ { id: 'claude-opus-4-6[1M]', contextWindow: 1_000_000 },
+ ],
+ });
+
+ expect(JSON.parse(env[MODEL_CONTEXT_WINDOWS_ENV] ?? '{}')).toEqual({
+ 'claude-opus-4-6[1M]': 1_000_000,
+ });
+ });
+
+ it('mirrorOneMillionSuffix=false 的条目只写原样键,不镜像 [1m] (#3661)', async () => {
+ // claude-* 的 [1m] 是真实 1M 通道,不是同窗口路由别名:按会话路由注入的
+ // 中转站窗口若被镜像,会把 200K 压到 Fast 切换后的 [1m] 形态上。
+ const env = await buildClaudeEnv(createAuthAdapter(), {}, {
+ modelContextWindows: [
+ { id: 'claude-opus-4-6', contextWindow: 1_000_000, mirrorOneMillionSuffix: false },
+ { id: 'deepseek/deepseek-v4-pro', contextWindow: 1_048_576 },
+ ],
+ });
+
+ expect(JSON.parse(env[MODEL_CONTEXT_WINDOWS_ENV] ?? '{}')).toEqual({
+ 'claude-opus-4-6': 1_000_000,
+ 'deepseek/deepseek-v4-pro': 1_048_576,
+ 'deepseek/deepseek-v4-pro[1m]': 1_048_576,
+ });
+ });
+
it('does not inject empty or invalid context windows', async () => {
const env = await buildClaudeEnv(createAuthAdapter(), {}, {
modelContextWindows: [
diff --git a/packages/maker-core/src/agents/claude-code/env-builder.ts b/packages/maker-core/src/agents/claude-code/env-builder.ts
index 13443e6906..d35464ae0e 100644
--- a/packages/maker-core/src/agents/claude-code/env-builder.ts
+++ b/packages/maker-core/src/agents/claude-code/env-builder.ts
@@ -18,6 +18,13 @@ export const MAKER_MODEL_CONTEXT_WINDOWS_ENV = 'XDT_MAKER_MODEL_CONTEXT_WINDOWS'
interface ModelContextWindowSource {
id: string;
contextWindow: number;
+ /**
+ * 是否把无 [1m] 后缀的 id 镜像出一个同窗口的 `${id}[1m]` 键(缺省 true,
+ * 兼容 provider 路由模型把 [1m] 当同窗口路由别名的历史语义)。claude-* 的
+ * [1m] 是真实的 1M 通道、不是同窗口别名,按会话路由注入的条目必须传 false,
+ * 否则 200K 会被镜像到 Fast 切换后的 [1m] 形态上(#3661)。
+ */
+ mirrorOneMillionSuffix?: boolean;
}
interface ClaudeEnvBuildOptions {
@@ -66,7 +73,10 @@ function serializeModelContextWindows(
}
const window = Math.floor(model.contextWindow);
entries[model.id] = window;
- if (!model.id.endsWith('[1m]')) {
+ // 后缀判定大小写不敏感(#3661):用户配置 `...[1M]` 时不能再镜像出
+ // `...[1M][1m]` 垃圾键。镜像本身仍按原样键写入,消费侧按字面匹配。
+ const hasOneMillionSuffix = /\[1m\]$/i.test(model.id);
+ if (model.mirrorOneMillionSuffix !== false && !hasOneMillionSuffix) {
entries[`${model.id}[1m]`] = window;
}
}
diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.ts
index 390cf09050..b6940cd63f 100644
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@ -1166,10 +1166,36 @@ export class ClaudeCodeAgent extends BaseAgent {
const providerRoutedModels = this.capabilities.availableModels.filter((model) =>
isProviderRoutedModel(model.id),
);
+ // #3661:扁平表按「CC 内建 resolver 认识 Anthropic 名」排除了 claude-*,但
+ // 中转/自定义来源上的 claude 模型窗口以用户配置为准(如 1M);CLI 内建
+ // resolver 会按 Anthropic 缺省收敛(~200K)并过早判满/auto-compact。显式
+ // 来源会话把「该路由已核实」的窗口(resolveVerifiedContextWindow:多来源
+ // 歧义或未核实返回 null,fail-open 回落 CLI 自解析)按本会话模型单点注入;
+ // 不做 [1m] 镜像 —— claude 的 [1m] 是真实 1M 通道,不是同窗口路由别名。
+ // 会话中途 setModel 到其它 claude 模型时该 env 键不覆盖新模型,行为与
+ // 修复前一致(CLI 自解析),无回归面。
+ const sessionRouteWindowEntry = ((): {
+ id: string;
+ contextWindow: number;
+ mirrorOneMillionSuffix: false;
+ } | null => {
+ if (!opts.providerId) return null;
+ if (!opts.model.startsWith('claude-')) return null;
+ const verified = this.deps.resolveVerifiedContextWindow?.(opts.providerId, opts.model);
+ if (typeof verified !== 'number' || verified <= 0) return null;
+ return {
+ id: sdkModelFor(opts.model),
+ contextWindow: verified,
+ mirrorOneMillionSuffix: false,
+ };
+ })();
+ const modelContextWindows = sessionRouteWindowEntry
+ ? [...providerRoutedModels, sessionRouteWindowEntry]
+ : providerRoutedModels;
const env = await buildClaudeEnv(this.deps.auth, this.deps.runtimeConfig, {
credentialMode,
sessionProviderId: opts.providerId ?? null,
- modelContextWindows: providerRoutedModels,
+ modelContextWindows,
// 先按「不设」建好 env(顺带删掉可能从 process.env 继承来的残留),真正的判定在下面
// 拿到这份 env 之后做 —— 扫描需要 env 里的 CLAUDE_CONFIG_DIR 才能找对目录。
subagentModel: null,
@@ -1253,7 +1279,7 @@ export class ClaudeCodeAgent extends BaseAgent {
credentialMode,
sessionProviderId: opts.providerId ?? null,
mode: 'remote',
- modelContextWindows: providerRoutedModels,
+ modelContextWindows,
// 远端不做本地扫描(见上),这里的值就是路由感知后的设置值 —— 保持 env 强制覆盖语义。
subagentModel: subagentDefault.envSubagentModel ?? null,
})