Conversation
| /** | ||
| * Adds additional injections to an existing session without duplicates. | ||
| */ | ||
| addInjections(sessionID: string, newInjections: string[]): void { |
There was a problem hiding this comment.
- Use rest params instead of an array
(Addressed in commit 04a085f)
| * Injections persist for the entire agentic loop until session idle. | ||
| */ | ||
| export class InjectionManager { | ||
| private activeInjections = new Map<string, string[]>(); |
There was a problem hiding this comment.
Should we potentially just store the injection keys as the map values?
There was a problem hiding this comment.
Good idea for a future optimization. For now, keeping the simple Map<sessionID, string[]> approach since duplicate checking is sufficient.
| parts: [{ type: "text", text: injectText }], | ||
| }); | ||
| } | ||
| logger.debug("Injected ephemeral user messages", { |
There was a problem hiding this comment.
Ahhh, this was the wording that finally clued me in on what this was about. Real messages kept at the top of the conversation.
Still not sure this is in scope of "snippets" :D But we can try
|
hey opencode, can you address the comments and put this feature behind an experimental flag? New experimental: {...} in config. Push on this branch directly, but don't change history. |
Changes MadeAddressed the PR feedback to put the inject feature behind an experimental flag. Summary of Changes
UsageTo enable inject blocks, users add to their config: {
"experimental": {
"inject": true
}
}All 186 tests pass. |
| @@ -0,0 +1,46 @@ | |||
| /** | |||
There was a problem hiding this comment.
- Oh these should definitely come from the OpenCode SDK, check node_modules for the correct import paths!
(Addressed - types imported from@opencode-ai/sdkat src/hook-types.ts:5)
There was a problem hiding this comment.
Done - types now imported from @opencode-ai/sdk (not plugin, as plugin only imports them internally but doesn't re-export).
✅ Validation added in |
|
Hey OpenCode, two more open tasks for you :) |
Changes MadeAddressed the two open tasks: 1. Validation:
|
Implementing #15
to summarize, the inject flag (might need semantic change) allows to send a snippet to the model during the agentic loop cycle, from user message to session.idle.
this is meant for things like "always read files speculatively, use parallel tool calling for read and edits as much as possible, use the question tool to ask me any question you migth have" things like that really - behavioral notes that you want to always have in "front" of the model's eyes without poisoning the context because you added it 13 times in your convo, it's never persisted for more than the agent loop, until session idle.
I think of it as a system prompt extension... sortof.
instead of cramming a huge paragraph in the system prompt, you can mention the thing in the system, and rehash/go deeper in that message - without poisoning context. And of course, being in front of the model leverages recency bias in your favor, so the model doesn't "forget" to use parallel tool calling or other things you prefer.
TLDR: really great for behavioral steering
PS: maybe "ephemeral" makes more sense than inject, since everything is an injection, that name might be confusing