Skip to content
Merged
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 apps/cli/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
SessionMeta,
StoredMessage,
} from '@deepcode/core';
import { redact, type Credentials } from '@deepcode/core';
import { contextWindowFor, redact, type Credentials } from '@deepcode/core';

export interface SessionContext {
cwd: string;
Expand Down Expand Up @@ -220,7 +220,7 @@ export const ContextCommand: SlashCommand = {
description: 'Show context window usage.',
run(_args, ctx) {
const used = ctx.usage.inputTokens + ctx.usage.outputTokens;
const ctxMax = 128_000;
const ctxMax = contextWindowFor(ctx.model);
const pct = ((used / ctxMax) * 100).toFixed(1);
return [
`Context: ${used.toLocaleString()} / ${ctxMax.toLocaleString()} (${pct}%)`,
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
buildSkillsDescriptionBlock,
closeAllMcpServers,
connectAllMcpServers,
contextWindowFor,
findStyle,
loadMemory,
loadOutputStyles,
Expand Down Expand Up @@ -239,7 +240,7 @@ export async function runHeadless(opts: HeadlessOpts): Promise<number> {
mode,
permissions: settings.permissions,
hooks,
autoCompact: { contextWindow: 128_000, threshold: 0.8 },
autoCompact: { contextWindow: contextWindowFor(model), threshold: 0.8 },
autoMode: settings.autoMode,
sandboxConfig: settings.sandbox,
// In headless mode there's no human to ask: auto-deny anything that
Expand Down
3 changes: 2 additions & 1 deletion apps/cli/src/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
loadOutputStyles,
loadSettings,
loadSkills,
contextWindowFor,
makeSkillTool,
resolveCredentials,
runAgent,
Expand Down Expand Up @@ -308,7 +309,7 @@ export async function startRepl(opts: ReplOpts): Promise<number> {
mode: ctx.mode as Mode,
permissions: settings.permissions,
hooks,
autoCompact: { contextWindow: 128_000, threshold: 0.8 },
autoCompact: { contextWindow: contextWindowFor(ctx.model), threshold: 0.8 },
autoMode: settings.autoMode,
sandboxConfig: settings.sandbox,
approval: async (toolName, _input, verdict) => {
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/screens/Repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
type KeyBinding,
type VimMode,
} from '@deepcode/core/dist/keybindings/vim.js';
import { contextWindowFor } from '@deepcode/core/dist/providers/deepseek.js';
import { Dropdown, type DropdownOption } from '../components/Dropdown.js';
import { Pill } from '../components/Pill.js';
import { PlusMenu } from '../components/PlusMenu.js';
Expand Down Expand Up @@ -476,7 +477,7 @@ export function ReplScreen({ projectPath, onTurnComplete }: ReplScreenProps): JS
const activeAssistantIdx = lastAssistantIndex(messages);

// ── Context bar fill ──
const contextWindow = 128_000;
const contextWindow = contextWindowFor(model);
const usedTokens = usage.inputTokens + usage.outputTokens;
const fillPct = Math.min(100, (usedTokens / contextWindow) * 100);

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export type * from './types.js';
export {
DeepSeekProvider,
DEEPSEEK_MODELS,
DEFAULT_CONTEXT_WINDOW,
EFFORT_PARAMS,
contextWindowFor,
type DeepSeekProviderOpts,
type Provider,
type ProviderResult,
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/providers/deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ export const DEEPSEEK_MODELS: Record<DeepSeekModel, { ctx: number; maxOutput: nu
'deepseek-v4-pro': { ctx: 128_000, maxOutput: 8_192 },
};

/** Fallback context window for an unrecognized model id. */
export const DEFAULT_CONTEXT_WINDOW = 128_000;

/**
* Context-window size (tokens) for a model id. Single source of truth for the
* context-bar + auto-compact threshold across CLI and desktop — avoids the
* 128_000 literal drifting out of sync with DEEPSEEK_MODELS. Falls back to
* DEFAULT_CONTEXT_WINDOW for unknown (e.g. user-typed) model ids.
*/
export function contextWindowFor(model: string): number {
return DEEPSEEK_MODELS[model as DeepSeekModel]?.ctx ?? DEFAULT_CONTEXT_WINDOW;
}

/**
* Effort → DeepSeek API parameters.
* Numbers from docs/design/effort-levels.md §3.2.
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ export type {
ProviderUsage,
ProviderStreamHandlers,
} from './types.js';
export { DeepSeekProvider, DEEPSEEK_MODELS, EFFORT_PARAMS } from './deepseek.js';
export {
DeepSeekProvider,
DEEPSEEK_MODELS,
DEFAULT_CONTEXT_WINDOW,
EFFORT_PARAMS,
contextWindowFor,
} from './deepseek.js';
export type { DeepSeekProviderOpts } from './deepseek.js';
Loading