Skip to content
Closed
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
7 changes: 3 additions & 4 deletions src/context/PromptRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function tokenizePrompt(prompt: string): Set<string> {
return new Set(
prompt
.toLowerCase()
.replace(/[^a-z0-9s/_-]/g, '')
.split(/[s/_-]+/)
.replace(/[^a-z0-9\s\/_-]/g, '')
.split(/[\s\/_-]+/)
.filter(t => t.length >= 2)
);
}
Expand Down Expand Up @@ -133,6 +133,5 @@ export function renderRoutedTools<T extends RoutableItem>(matches: RoutedMatch<T
for (const m of matches) {
lines.push(`- **${m.item.name}** — ${m.item.description} (relevance: ${m.score})`);
}
return lines.join('
');
return lines.join('\n');
}
4 changes: 2 additions & 2 deletions src/context/ReactiveCompaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export class ReactiveCompaction {
}
}
} else if (signal.ratio >= this.config.pressureThreshold) {
// Pressure: downgrade bottom half by one level
// Pressure: downgrade least-relevant half by one level
const half = Math.ceil(sorted.length / 2);
for (let i = half; i < sorted.length; i++) {
for (let i = 0; i < half; i++) {
const f = sorted[i];
const next = this.nextDepth(f.depth);
if (next) adjustments.push({ fileId: f.fileId, currentDepth: f.depth, newDepth: next, reason: 'token_pressure' });
Expand Down
3 changes: 1 addition & 2 deletions src/context/TranscriptCompaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ export class TranscriptCompaction {
if (toolMsgs.length) {
parts.push(`Tool calls: ${toolMsgs.map(m => m.metadata?.toolName ?? 'unknown').join(', ')}`);
}
return parts.join('
');
return parts.join('\n');
}

/** Estimate tokens for a string (rough approximation). */
Expand Down
8 changes: 7 additions & 1 deletion src/graph/reactivePackerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export function withReactiveCompaction(
const baseTokens = oldRatio > 0 ? item.tokens / oldRatio : item.tokens;
const newTokens = Math.max(1, Math.ceil(baseTokens * newRatio));
newTotal += newTokens;
return { ...item, depth: newDepthNumeric, tokens: newTokens };
// Truncate content proportionally to new depth
const contentStr = typeof item.content === 'string' ? item.content : '';
const truncatedLength = oldRatio > 0 ? Math.ceil(contentStr.length * (newRatio / oldRatio)) : contentStr.length;
const truncatedContent = contentStr.length > truncatedLength
? contentStr.slice(0, truncatedLength) + '\n[... truncated by reactive compaction]'
: contentStr;
return { ...item, depth: newDepthNumeric, tokens: newTokens, content: truncatedContent };
}
newTotal += item.tokens;
return item;
Expand Down
4 changes: 2 additions & 2 deletions src/services/agentSearchIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function createAgentSearchService(
agents: AgentConfig[],
knowledge: KnowledgeSource[] = [],
): AgentSearchService {
const hash = JSON.stringify(agents.map(a => a.id).sort());
const hash = JSON.stringify(agents.map(a => [a.id, a.description, a.role, ...(a.tags ?? [])].join('|')).sort());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep cache hash format consistent after reindex

This hash now includes description/role/tags, but reindex() still writes _lastIndexHash using only agent IDs, so the next createAgentSearchService() call will always see a mismatch and rebuild the index even when nothing changed. That effectively disables the intended cache fast path after any reindex() call and adds avoidable reindex cost.

Useful? React with 👍 / 👎.

if (!_searchInstance || hash !== _lastIndexHash) {
_searchInstance = new AgentSearch(agents, knowledge);
_lastIndexHash = hash;
Expand All @@ -64,7 +64,7 @@ export function createAgentSearchService(

reindex(newAgents: AgentConfig[], newKnowledge?: KnowledgeSource[]): void {
_searchInstance = new AgentSearch(newAgents, newKnowledge ?? knowledge);
_lastIndexHash = JSON.stringify(newAgents.map(a => a.id).sort());
_lastIndexHash = JSON.stringify(newAgents.map(a => [a.id, a.description, a.role, ...(a.tags ?? [])].join('|')).sort());
},
};
}
Expand Down
26 changes: 8 additions & 18 deletions src/services/systemFrameBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export function buildProvenanceSection(provenance: ProvenanceSummary): string {
lines.push('</context_provenance>');
}

return lines.join('
');
return lines.join('\n');
}

export function buildSystemFrame(provenance?: ProvenanceSummary): string {
Expand All @@ -62,8 +61,7 @@ export function buildSystemFrame(provenance?: ProvenanceSummary): string {
if (agentMeta.avatar) identity.push(`Avatar: ${agentMeta.avatar}`);
if (agentMeta.tags?.length) identity.push(`Tags: ${agentMeta.tags.join(', ')}`);
parts.push(`<identity>
${identity.join('
')}
${identity.join('\n')}
</identity>`);
}

Expand All @@ -80,17 +78,13 @@ ${identity.join('
lines.push(`Primary Objective: ${instructionState.objectives.primary}`);
if (instructionState.objectives.successCriteria.length > 0)
lines.push(`Success Criteria:
${instructionState.objectives.successCriteria.map(c => `- ${c}`).join('
')}`);
${instructionState.objectives.successCriteria.map(c => `- ${c}`).join('\n')}`);
if (instructionState.objectives.failureModes.length > 0)
lines.push(`Failure Modes to Avoid:
${instructionState.objectives.failureModes.map(f => `- ${f}`).join('
')}`);
${instructionState.objectives.failureModes.map(f => `- ${f}`).join('\n')}`);
}
parts.push(`<instructions>
${lines.join('

')}
${lines.join('\n\n')}
</instructions>`);
}

Expand All @@ -106,8 +100,7 @@ ${lines.join('
if (instructionState.constraints.customConstraints)
constraints.push(`Additional constraints: ${instructionState.constraints.customConstraints}`);
if (constraints.length > 0) parts.push(`<constraints>
${constraints.map(c => `- ${c}`).join('
')}
${constraints.map(c => `- ${c}`).join('\n')}
</constraints>`);

// Workflow
Expand All @@ -128,9 +121,7 @@ ${compiled}
parts.push(provenanceSection);
}

return parts.join('

');
return parts.join('\n\n');
}

/**
Expand Down Expand Up @@ -317,7 +308,6 @@ export function buildToolGuide(): string {
}

return `<tool_guide>
${lines.join('
')}
${lines.join('\n')}
</tool_guide>`;
}
Loading