Skip to content

feat: introduce macher-context-resolved-functions hook#61

Closed
elij wants to merge 1 commit into
kmontag:mainfrom
elij:context-hook
Closed

feat: introduce macher-context-resolved-functions hook#61
elij wants to merge 1 commit into
kmontag:mainfrom
elij:context-hook

Conversation

@elij
Copy link
Copy Markdown

@elij elij commented May 7, 2026

This PR introduces a new hook to better support downstream packages that need to hook into the macher request lifecycle.

Previously, packages requiring a persistent context or file system syncs before a revision request had to aggressively advise macher--setup-tools. By natively triggering macher-context-resolved-functions inside the lazy initializer, extensions can safely tap into the flow.

Key changes:

  • Added macher-context-resolved-functions as a defcustom in the macher-processing group.
  • Integrated the hook directly into the lazy initialiser inside macher--transform-setup-tools.
  • Ensured that if a hook modifies the gptel-fsm-info to swap out the :macher--context, the newly swapped context is returned and utilised by the request.

@kmontag
Copy link
Copy Markdown
Owner

kmontag commented May 7, 2026

Thanks @elij !

I'm definitely open to adding something like this, though I've also been messing with the idea of storing the context buffer-locally (rather than scoped to a closure for the request) - the idea would be that the context can then be reset at the beginning of a request (this would probably be the default behavior as it functionally matches the current behavior), or preserved and passed forward to the next request, or modified by other packages, etc. This might solve the issue in a way that doesn't lock macher into this tool-override magic that's currently being performed.

Alongside this, I'd probably also add tools to view the current diff between the workspace and the filesystem, and/or merge the current filesystem state into the workspace.

The best API for this isn't quite obvious to me yet. Could you share a bit more about your use case?

@elij
Copy link
Copy Markdown
Author

elij commented May 7, 2026

It's basically as you describe so it's good to know you're thinking about it!

The use case is a feed forward in a 3 way merge (or macher revise by default) -- original file system, in flight diff, and context invalidation (file system changed). Context invalidation is either manual (rejected patch, but this needs strong prompts) or file system modified without applying patch.

Basically using macher in agentic workflows -- this is in flight diffs but I'm also doing cross buffer workflows and using tools on the context state. This is strictly in the macher workflow which is my preferred framework for this.

I am curious about your vision for tools applied to context as I'm using rsync but there might be a better way that you're thinking about!

Introduces `macher-context-resolved-functions`, a context
interception  hook that fires immediately after it is
lazily resolved for a request.

This enables dependent packages to safely modify the context object, trigger
file system side-effects, or inject a persistent context by updating the FSM
state prior to tool execution. If a hook function replaces the context in the
FSM, the new context is correctly adopted and returned.
@elij elij closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants