-
Notifications
You must be signed in to change notification settings - Fork 27
Description
Bug Report: Crystallized hooks not active
Summary
When using foundry_crystallize to crystallize a pattern into a hook, the hook file is saved to ~/.openclaw/foundry/hooks/ but is not integrated into Foundry's runtime and therefore not being called.
Steps to Reproduce
- Run
foundry_learningsto see recurring failures - Run
foundry_crystallizeon a pattern (e.g., `foundry_crystallize patternId="fail_1771767040289_q5n00s"`) - Hook is saved successfully to: `~/.openclaw/foundry/hooks/crystallized_edit_1772232868618.ts`
- Gateway is restarted via `foundry_restart`
- Hook is not called when the error condition occurs (e.g., using `oldText` instead of `old_string` in edit tool)
- Check metrics: `cat ~/.openclaw/foundry/metrics.json` — shows edit tool still has low fitness and failures continue
Expected Behavior
The crystallized hook should be automatically integrated into Foundry's runtime and should intercept `before_tool_call` events for the `edit` tool, injecting guidance when deprecated parameter names are detected.
Actual Behavior
- Hook file exists in `~/.openclaw/foundry/hooks/` directory
- Hook is not called during tool execution
- Pattern continues to repeat (e.g., edit tool failures continue to increment)
- Metrics show `edit` tool at 36% fitness with recurring failures
Environment
- Foundry version: Latest from `openclaw plugins install @getfoundry/foundry-openclaw`
- OpenClaw version: Running from repo at `/home/apoapostolov/git/openclaw`
- OS: Linux (OpenClaw Gateway)
Hook File Content
The crystallized hook (`crystallized_edit_1772232868618.ts`):
```typescript
api.on("before_tool_call", async (event, ctx) => {
if (event.toolName === "edit") {
// Detects and prevents parameter mismatch
// ...
}
});
```
Additional Context
Looking at Foundry's `index.ts`, there is a `before_tool_call` handler at line 1594, but the crystallized hooks from `~/.openclaw/foundry/hooks/` do not appear to be loaded or integrated into the runtime.
Suggested Fix
Either:
- Auto-integration: `foundry_crystallize` should automatically integrate the hook into Foundry's `index.ts` or a hooks loading mechanism
- Manual integration: Provide clear documentation on how to manually integrate crystallized hooks into the runtime
- Hook loading: Implement a hook discovery/loader that automatically loads all hooks from `~/.openclaw/foundry/hooks/` into the runtime
Impact
- Crystallization is a core feature of Foundry for converting learned patterns into permanent behavior
- Without working hook integration, patterns are crystallized but never executed
- This defeats the purpose of the HexMachina crystallization system