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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ test-update.ts
docs/
SCHEMA_NOTES.md

repomix-output.xml
repomix-output.xml

# Python
__pycache__/
*.pyc
*.pyo
*.pyd
7 changes: 6 additions & 1 deletion lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ export function createSystemPromptHandler(
return
}

output.system.push(renderSystemPrompt(flags))
const newPrompt = renderSystemPrompt(flags)
if (output.system.length > 0) {
output.system[output.system.length - 1] += "\n\n" + newPrompt
} else {
output.system.push(newPrompt)
}
}
}

Expand Down
32 changes: 23 additions & 9 deletions lib/messages/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
extractParameterKey,
createSyntheticTextPart,
createSyntheticToolPart,
isIgnoredUserMessage,
appendMessageIdTagToToolOutput,
findLastToolPart,
isIgnoredUserMessage,
rejectsTextParts,
} from "./utils"
import { getFilePathsFromParameters, isProtected } from "../protected-file-patterns"
import { getLastUserMessage, isMessageCompacted } from "../shared-utils"
Expand Down Expand Up @@ -314,13 +315,22 @@ export const insertPruneToolContext = (
)
lastNonIgnoredMessage.parts.push(textPart)
} else {
const toolPart = createSyntheticToolPart(
lastNonIgnoredMessage,
combinedContent,
modelId ?? "",
`${lastNonIgnoredMessage.info.id}:context`,
)
lastNonIgnoredMessage.parts.push(toolPart)
if (rejectsTextParts(modelId ?? "")) {
const toolPart = createSyntheticToolPart(
lastNonIgnoredMessage,
combinedContent,
modelId ?? "",
`${lastNonIgnoredMessage.info.id}:context`,
)
lastNonIgnoredMessage.parts.push(toolPart)
} else {
const textPart = createSyntheticTextPart(
lastNonIgnoredMessage,
combinedContent,
`${lastNonIgnoredMessage.info.id}:context`,
)
lastNonIgnoredMessage.parts.push(textPart)
}
}
}

Expand Down Expand Up @@ -365,6 +375,10 @@ export const insertMessageIdContext = (
continue
}

message.parts.push(createSyntheticToolPart(message, tag, toolModelId, messageIdSeed))
if (rejectsTextParts(toolModelId)) {
message.parts.push(createSyntheticToolPart(message, tag, toolModelId, messageIdSeed))
} else {
message.parts.push(createSyntheticTextPart(message, tag, messageIdSeed))
}
}
}
5 changes: 5 additions & 0 deletions lib/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const isGeminiModel = (modelID: string): boolean => {
return lowerModelID.includes("gemini")
}

export const rejectsTextParts = (modelID: string): boolean => {
const lowerModelID = modelID.toLowerCase()
return lowerModelID.includes("claude")
}

export const createSyntheticUserMessage = (
baseMessage: WithParts,
content: string,
Expand Down