Skip to content

Commit 35ca373

Browse files
committed
chore: address reviewer feedback, cleanup unrelated files, and refactor to neutral env keys
1 parent e1f334f commit 35ca373

8 files changed

Lines changed: 108 additions & 221 deletions

File tree

src/services/api/utils.ts

Lines changed: 0 additions & 168 deletions
This file was deleted.

src/utils/context.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,10 @@ export function getContextWindowForModel(
8181
betas?: string[],
8282
): number {
8383
// Allow override via environment variable
84-
// OPENAI_CONTEXT_WINDOW_SIZE from the active provider profile takes precedence
85-
if (process.env.OPENAI_CONTEXT_WINDOW_SIZE) {
86-
const override = parseInt(process.env.OPENAI_CONTEXT_WINDOW_SIZE, 10)
87-
if (!isNaN(override) && override > 0) {
88-
return override
89-
}
90-
}
91-
92-
// Allow override via environment variable (internal-only)
9384
// This takes precedence over all other context window resolution, including 1M detection,
9485
// so users can cap the effective context window for local decisions (auto-compact, etc.)
9586
// while still using a 1M-capable endpoint.
96-
if (
97-
process.env.USER_TYPE === 'ant' &&
98-
process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS
99-
) {
87+
if (process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS) {
10088
const override = parseInt(process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS, 10)
10189
if (!isNaN(override) && override > 0) {
10290
return override
@@ -206,15 +194,6 @@ export function getModelMaxOutputTokens(model: string): {
206194
let defaultTokens: number
207195
let upperLimit: number
208196

209-
// Allow override via environment variable
210-
// OPENAI_MAX_OUTPUT_TOKENS from the active provider profile takes precedence
211-
if (process.env.OPENAI_MAX_OUTPUT_TOKENS) {
212-
const override = parseInt(process.env.OPENAI_MAX_OUTPUT_TOKENS, 10)
213-
if (!isNaN(override) && override > 0) {
214-
return { default: override, upperLimit: override }
215-
}
216-
}
217-
218197
if (process.env.USER_TYPE === 'ant') {
219198
const antModel = resolveAntModel(model.toLowerCase())
220199
if (antModel) {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { describe, expect, it, beforeEach, afterEach } from 'bun:test'
2+
import {
3+
addGlobalEntity,
4+
searchGlobalGraph,
5+
resetGlobalGraph,
6+
clearMemoryOnly
7+
} from './knowledgeGraph.js'
8+
import { mkdtempSync, rmSync } from 'fs'
9+
import { tmpdir } from 'os'
10+
import { join } from 'path'
11+
import { acquireEnvMutex, releaseEnvMutex } from '../entrypoints/sdk/shared.js'
12+
import { setClaudeConfigHomeDirForTesting } from './envUtils.js'
13+
14+
describe('KnowledgeGraph Search Optimizations', () => {
15+
const originalConfigDir = process.env.CLAUDE_CONFIG_DIR
16+
let configDir: string | undefined
17+
18+
beforeEach(async () => {
19+
await acquireEnvMutex()
20+
configDir = mkdtempSync(join(tmpdir(), 'openclaude-opt-test-'))
21+
process.env.CLAUDE_CONFIG_DIR = configDir
22+
process.env.OPENCLAUDE_KNOWLEDGE_ORAMA = '1'
23+
setClaudeConfigHomeDirForTesting(configDir)
24+
resetGlobalGraph()
25+
})
26+
27+
afterEach(() => {
28+
try {
29+
resetGlobalGraph()
30+
clearMemoryOnly()
31+
if (originalConfigDir === undefined) {
32+
delete process.env.CLAUDE_CONFIG_DIR
33+
} else {
34+
process.env.CLAUDE_CONFIG_DIR = originalConfigDir
35+
}
36+
setClaudeConfigHomeDirForTesting(undefined)
37+
} finally {
38+
if (configDir) {
39+
try { rmSync(configDir, { recursive: true, force: true }) } catch {}
40+
}
41+
releaseEnvMutex()
42+
}
43+
})
44+
45+
it('finds entities even with minor typos (Typo Tolerance)', async () => {
46+
await addGlobalEntity('tool', 'AuthenticationManager', { desc: 'Handles user login' })
47+
48+
// Search with a small typo: "Authenticatin" (missing 'o')
49+
const result = await searchGlobalGraph('Authenticatin')
50+
expect(result).toContain('AuthenticationManager')
51+
52+
// Search with another typo: "Managerr" (extra 'r')
53+
const result2 = await searchGlobalGraph('Managerr')
54+
expect(result2).toContain('AuthenticationManager')
55+
})
56+
57+
it('ranks matches in name higher than matches in content (Field Boosting)', async () => {
58+
// Entity A has the term in the name
59+
await addGlobalEntity('service', 'BillingService', { desc: 'Internal system' })
60+
// Entity B has the term only in the description
61+
await addGlobalEntity('doc', 'README', { desc: 'Information about billing' })
62+
63+
const result = await searchGlobalGraph('billing')
64+
65+
// We expect BillingService to be listed before README because of the boost on 'name'
66+
const billingPos = result.indexOf('BillingService')
67+
const readmePos = result.indexOf('README')
68+
69+
expect(billingPos).toBeGreaterThan(-1)
70+
expect(readmePos).toBeGreaterThan(-1)
71+
expect(billingPos).toBeLessThan(readmePos)
72+
})
73+
74+
it('ranks matches in type higher than matches in content (Field Boosting)', async () => {
75+
// Entity A has the term in the type
76+
await addGlobalEntity('Database', 'Store', { desc: 'Main storage' })
77+
// Entity B has the term only in the description
78+
await addGlobalEntity('note', 'Todo', { desc: 'Upgrade the database' })
79+
80+
const result = await searchGlobalGraph('database')
81+
82+
const dbPos = result.indexOf('[Database] Store')
83+
const todoPos = result.indexOf('Todo')
84+
85+
expect(dbPos).toBeGreaterThan(-1)
86+
expect(todoPos).toBeGreaterThan(-1)
87+
expect(dbPos).toBeLessThan(todoPos)
88+
})
89+
})

src/utils/providerProfile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ const PROFILE_ENV_KEYS = [
9393
'XAI_API_KEY',
9494
'VENICE_API_KEY',
9595
'MIMO_API_KEY',
96-
'OPENAI_CONTEXT_WINDOW_SIZE',
97-
'OPENAI_MAX_OUTPUT_TOKENS',
96+
'CLAUDE_CODE_MAX_CONTEXT_TOKENS',
97+
'CLAUDE_CODE_MAX_OUTPUT_TOKENS',
9898
] as const
9999

100100
export type CompatibilityProfileMode =
@@ -175,8 +175,8 @@ export type ProfileEnv = {
175175
XAI_API_KEY?: string
176176
VENICE_API_KEY?: string
177177
MIMO_API_KEY?: string
178-
OPENAI_CONTEXT_WINDOW_SIZE?: string
179-
OPENAI_MAX_OUTPUT_TOKENS?: string
178+
CLAUDE_CODE_MAX_CONTEXT_TOKENS?: string
179+
CLAUDE_CODE_MAX_OUTPUT_TOKENS?: string
180180
}
181181

182182
export type ProfileFile = {

src/utils/providerProfiles.persistence.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const RESTORED_KEYS = [
1313
'CLAUDE_CODE_USE_OPENAI',
1414
'OPENAI_BASE_URL',
1515
'OPENAI_MODEL',
16-
'OPENAI_CONTEXT_WINDOW_SIZE',
17-
'OPENAI_MAX_OUTPUT_TOKENS',
16+
'CLAUDE_CODE_MAX_CONTEXT_TOKENS',
17+
'CLAUDE_CODE_MAX_OUTPUT_TOKENS',
1818
] as const
1919

2020
type MockConfigState = {
@@ -104,8 +104,8 @@ describe('Provider Profile Persistence (Context Window & Max Tokens)', () => {
104104

105105
setActiveProviderProfile('test_params', { configDir: testConfigDir! })
106106

107-
expect(process.env.OPENAI_CONTEXT_WINDOW_SIZE).toBe('200000')
108-
expect(process.env.OPENAI_MAX_OUTPUT_TOKENS).toBe('8192')
107+
expect(process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBe('200000')
108+
expect(process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS).toBe('8192')
109109
})
110110

111111
test('persists new parameters to .openclaude-profile.json for startup fallback', async () => {
@@ -131,8 +131,8 @@ describe('Provider Profile Persistence (Context Window & Max Tokens)', () => {
131131
const persistedPath = join(testConfigDir!, '.openclaude-profile.json')
132132
const persisted = JSON.parse(readFileSync(persistedPath, 'utf8'))
133133

134-
expect(persisted.env.OPENAI_CONTEXT_WINDOW_SIZE).toBe('64000')
135-
expect(persisted.env.OPENAI_MAX_OUTPUT_TOKENS).toBe('2048')
134+
expect(persisted.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBe('64000')
135+
expect(persisted.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS).toBe('2048')
136136
})
137137

138138
test('uses empty string for unspecified parameters (no default values stored)', async () => {

src/utils/providerProfiles.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const RESTORED_KEYS = [
6262
'VENICE_API_KEY',
6363
'MIMO_API_KEY',
6464
'HICAP_API_KEY',
65-
'OPENAI_CONTEXT_WINDOW_SIZE',
66-
'OPENAI_MAX_OUTPUT_TOKENS',
65+
'CLAUDE_CODE_MAX_CONTEXT_TOKENS',
66+
'CLAUDE_CODE_MAX_OUTPUT_TOKENS',
6767
] as const
6868

6969
type MockConfigState = {

0 commit comments

Comments
 (0)