Skip to content

Commit 57bae4f

Browse files
semantics changes
1 parent e3b7657 commit 57bae4f

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Logger } from "./lib/logger"
55
import { Janitor, type SessionStats } from "./lib/janitor"
66
import { checkForUpdates } from "./lib/version-checker"
77
import { loadPrompt } from "./lib/prompt"
8-
import { injectSynthInstruction, createToolResultTracker, maybeInjectToolResultNudge } from "./lib/synth-instruction"
8+
import { injectSynth, createToolTracker, injectNudge } from "./lib/synth-instruction"
99

1010
async function isSubagentSession(client: any, sessionID: string): Promise<boolean> {
1111
try {
@@ -16,9 +16,9 @@ async function isSubagentSession(client: any, sessionID: string): Promise<boolea
1616
}
1717
}
1818

19-
const TOOL_SYNTH_INSTRUCTION = loadPrompt("synthetic")
20-
const TOOL_CONTEXT_PRUNING_DESCRIPTION = loadPrompt("context_pruning")
21-
const TOOL_TOOL_PART_NUDGE = loadPrompt("tool-result-nudge")
19+
const SYNTH_INSTRUCTION = loadPrompt("synthetic")
20+
const TOOL_INSTRUCTION = loadPrompt("context_pruning")
21+
const NUDGE_INSTRUCTION = loadPrompt("nudge")
2222

2323
const plugin: Plugin = (async (ctx) => {
2424
const { config, migrations } = getConfig(ctx)
@@ -37,7 +37,7 @@ const plugin: Plugin = (async (ctx) => {
3737
const toolParametersCache = new Map<string, any>()
3838
const modelCache = new Map<string, { providerID: string; modelID: string }>()
3939
const janitor = new Janitor(ctx.client, prunedIdsState, statsState, logger, toolParametersCache, config.protectedTools, modelCache, config.model, config.showModelErrorToasts, config.strictModelSelection, config.pruning_summary, ctx.directory)
40-
const toolResultTracker = createToolResultTracker()
40+
const toolTracker = createToolTracker()
4141

4242
const cacheToolParameters = (messages: any[]) => {
4343
for (const message of messages) {
@@ -79,17 +79,17 @@ const plugin: Plugin = (async (ctx) => {
7979

8080
// Inject periodic nudge every 5 tool results
8181
if (config.strategies.onTool.length > 0) {
82-
if (maybeInjectToolResultNudge(body.messages, toolResultTracker, TOOL_TOOL_PART_NUDGE)) {
82+
if (injectNudge(body.messages, toolTracker, NUDGE_INSTRUCTION)) {
8383
logger.debug("fetch", "Injected tool-result nudge", {
84-
toolResultCount: toolResultTracker.toolResultCount
84+
toolResultCount: toolTracker.toolResultCount
8585
})
8686
modified = true
8787
}
8888
}
8989

9090
// Inject synthInstruction for the context_pruning tool
9191
if (config.strategies.onTool.length > 0) {
92-
if (injectSynthInstruction(body.messages, TOOL_SYNTH_INSTRUCTION)) {
92+
if (injectSynth(body.messages, SYNTH_INSTRUCTION)) {
9393
logger.debug("fetch", "Injected synthInstruction")
9494
modified = true
9595
}
@@ -263,7 +263,7 @@ const plugin: Plugin = (async (ctx) => {
263263

264264
tool: config.strategies.onTool.length > 0 ? {
265265
context_pruning: tool({
266-
description: TOOL_CONTEXT_PRUNING_DESCRIPTION,
266+
description: TOOL_INSTRUCTION,
267267
args: {
268268
reason: tool.schema.string().optional().describe(
269269
"Brief reason for triggering pruning (e.g., 'task complete', 'switching focus')"

lib/synth-instruction.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
export interface ToolResultTracker {
1+
export interface ToolTracker {
22
seenToolResultIds: Set<string>
33
toolResultCount: number
44
}
55

6-
export function createToolResultTracker(): ToolResultTracker {
6+
export function createToolTracker(): ToolTracker {
77
return {
88
seenToolResultIds: new Set(),
99
toolResultCount: 0
1010
}
1111
}
1212

13-
function countNewToolResults(messages: any[], tracker: ToolResultTracker): number {
13+
function countToolResults(messages: any[], tracker: ToolTracker): number {
1414
let newCount = 0
1515

1616
for (const m of messages) {
@@ -41,21 +41,21 @@ function countNewToolResults(messages: any[], tracker: ToolResultTracker): numbe
4141
* Counts new tool results and injects nudge instruction every 5th tool result.
4242
* Returns true if injection happened.
4343
*/
44-
export function maybeInjectToolResultNudge(
44+
export function injectNudge(
4545
messages: any[],
46-
tracker: ToolResultTracker,
46+
tracker: ToolTracker,
4747
nudgeText: string
4848
): boolean {
4949
const prevCount = tracker.toolResultCount
50-
const newCount = countNewToolResults(messages, tracker)
50+
const newCount = countToolResults(messages, tracker)
5151

5252
if (newCount > 0) {
5353
// Check if we crossed a multiple of 5
5454
const prevBucket = Math.floor(prevCount / 5)
5555
const newBucket = Math.floor(tracker.toolResultCount / 5)
5656
if (newBucket > prevBucket) {
5757
// Inject at the END of messages so it's in immediate context
58-
return injectNudgeAtEnd(messages, nudgeText)
58+
return appendNudge(messages, nudgeText)
5959
}
6060
}
6161
return false
@@ -82,10 +82,10 @@ export function isIgnoredUserMessage(msg: any): boolean {
8282
}
8383

8484
/**
85-
* Injects a nudge message at the END of the messages array as a new user message.
85+
* Appends a nudge message at the END of the messages array as a new user message.
8686
* This ensures it's in the model's immediate context, not buried in old messages.
8787
*/
88-
export function injectNudgeAtEnd(messages: any[], nudgeText: string): boolean {
88+
function appendNudge(messages: any[], nudgeText: string): boolean {
8989
messages.push({
9090
role: 'user',
9191
content: nudgeText,
@@ -94,7 +94,7 @@ export function injectNudgeAtEnd(messages: any[], nudgeText: string): boolean {
9494
return true
9595
}
9696

97-
export function injectSynthInstruction(messages: any[], instruction: string): boolean {
97+
export function injectSynth(messages: any[], instruction: string): boolean {
9898
// Find the last user message that is not ignored
9999
for (let i = messages.length - 1; i >= 0; i--) {
100100
const msg = messages[i]

0 commit comments

Comments
 (0)