Skip to content

Commit 1eee49d

Browse files
committed
fix: address Codex review from PR #148 (3 P1 + 1 P2)
- Fix PromptRouter regex: \s not s for whitespace splitting - Fix ReactiveCompaction: downgrade least-relevant half, not most-relevant - Fix reactivePackerWrapper: truncate content after depth adjustment - Fix agentSearchIntegration: include metadata in cache key for freshness
1 parent da14857 commit 1eee49d

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/context/PromptRouter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function tokenizePrompt(prompt: string): Set<string> {
3030
return new Set(
3131
prompt
3232
.toLowerCase()
33-
.replace(/[^a-z0-9s/_-]/g, '')
34-
.split(/[s/_-]+/)
33+
.replace(/[^a-z0-9\s\/_-]/g, '')
34+
.split(/[\s\/_-]+/)
3535
.filter(t => t.length >= 2)
3636
);
3737
}

src/context/ReactiveCompaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export class ReactiveCompaction {
6868
}
6969
}
7070
} else if (signal.ratio >= this.config.pressureThreshold) {
71-
// Pressure: downgrade bottom half by one level
71+
// Pressure: downgrade least-relevant half by one level
7272
const half = Math.ceil(sorted.length / 2);
73-
for (let i = half; i < sorted.length; i++) {
73+
for (let i = 0; i < half; i++) {
7474
const f = sorted[i];
7575
const next = this.nextDepth(f.depth);
7676
if (next) adjustments.push({ fileId: f.fileId, currentDepth: f.depth, newDepth: next, reason: 'token_pressure' });

src/graph/reactivePackerWrapper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ export function withReactiveCompaction(
127127
const baseTokens = oldRatio > 0 ? item.tokens / oldRatio : item.tokens;
128128
const newTokens = Math.max(1, Math.ceil(baseTokens * newRatio));
129129
newTotal += newTokens;
130-
return { ...item, depth: newDepthNumeric, tokens: newTokens };
130+
// Truncate content proportionally to new depth
131+
const contentStr = typeof item.content === 'string' ? item.content : '';
132+
const truncatedLength = oldRatio > 0 ? Math.ceil(contentStr.length * (newRatio / oldRatio)) : contentStr.length;
133+
const truncatedContent = contentStr.length > truncatedLength
134+
? contentStr.slice(0, truncatedLength) + '
135+
[... truncated by reactive compaction]'
136+
: contentStr;
137+
return { ...item, depth: newDepthNumeric, tokens: newTokens, content: truncatedContent };
131138
}
132139
newTotal += item.tokens;
133140
return item;

src/services/agentSearchIntegration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function createAgentSearchService(
4343
agents: AgentConfig[],
4444
knowledge: KnowledgeSource[] = [],
4545
): AgentSearchService {
46-
const hash = JSON.stringify(agents.map(a => a.id).sort());
46+
const hash = JSON.stringify(agents.map(a => [a.id, a.description, a.role, ...(a.tags ?? [])].join('|')).sort());
4747
if (!_searchInstance || hash !== _lastIndexHash) {
4848
_searchInstance = new AgentSearch(agents, knowledge);
4949
_lastIndexHash = hash;

0 commit comments

Comments
 (0)