feat: add honcho capture hygiene controls#82
Conversation
WalkthroughThe PR extends message capture configuration with two features: conditional removal of runtime scaffolding before saving messages, and session isolation to exclude cron/heartbeat/temp-slug sessions from capture. It adds type fields, schema validation, message cleaning logic, session matching helpers, hook integration, and test coverage. ChangesMessage Capture Filtering & Runtime Scaffolding Cleanup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…-hygiene # Conflicts: # hooks/capture.ts # test/helpers.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@hooks/capture.ts`:
- Around line 29-32: Resolve the agentId and sessionKey before calling
shouldIsolateSession to ensure the same agent fallback is used for isolation
checks and later flushing; specifically, move the agentId resolution (const
agentId = ctx.agentId ?? state.resolveDefaultAgentId()) and sessionKey creation
(const sessionKey = buildSessionKey({ sessionKey: ctx.sessionKey, agentId })) so
they occur prior to the shouldIsolateSession(...) call, and then call
shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns, sessionKey) or
otherwise pass the computed sessionKey/agentId into
shouldIsolateSession/flushMessages so both use the same resolved agentId and
built session key.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4fa7e2a0-0690-4fd1-95ed-85904a292f84
📒 Files selected for processing (5)
config.tshelpers.tshooks/capture.tsopenclaw.plugin.jsontest/helpers.test.ts
| if (shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns)) return 0; | ||
|
|
||
| const agentId = ctx.agentId ?? state.resolveDefaultAgentId(); | ||
| const sessionKey = buildSessionKey({ sessionKey: ctx.sessionKey, agentId }); |
There was a problem hiding this comment.
Resolve agentId before evaluating session isolation.
Isolation currently runs before default agentId resolution. If ctx.agentId is absent, built-key matching inside shouldIsolateSession can use a different agent fallback than the one used later in flushMessages, so custom built-key patterns may not match.
Suggested fix
- if (!messages?.length) return 0;
- if (shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns)) return 0;
-
- const agentId = ctx.agentId ?? state.resolveDefaultAgentId();
+ if (!messages?.length) return 0;
+ const agentId = ctx.agentId ?? state.resolveDefaultAgentId();
+ if (shouldIsolateSession({ ...ctx, agentId }, state.cfg.isolatedSessionPatterns)) return 0;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@hooks/capture.ts` around lines 29 - 32, Resolve the agentId and sessionKey
before calling shouldIsolateSession to ensure the same agent fallback is used
for isolation checks and later flushing; specifically, move the agentId
resolution (const agentId = ctx.agentId ?? state.resolveDefaultAgentId()) and
sessionKey creation (const sessionKey = buildSessionKey({ sessionKey:
ctx.sessionKey, agentId })) so they occur prior to the shouldIsolateSession(...)
call, and then call shouldIsolateSession(ctx, state.cfg.isolatedSessionPatterns,
sessionKey) or otherwise pass the computed sessionKey/agentId into
shouldIsolateSession/flushMessages so both use the same resolved agentId and
built session key.
Summary
NO_REPLYto default noise patterns and keep subagent sessions captured by defaultThis is split out from #78 and intentionally excludes prompt-injection controls and dedupe/flush-lock behavior.
Notes
inferProviderFromSessionKeyis intentionally not included here to avoid relying on OpenClaw session-key heuristics.isolatedSessionPatternsentry if needed.Validation
pnpm exec vitest run test/helpers.test.tspnpm buildSummary by CodeRabbit
New Features
stripRuntimeScaffoldingconfiguration option (enabled by default) to clean up system scaffolding from captured messages.isolatedSessionPatternsconfiguration to exclude specified session types from message capture.Tests