Skip to content

fix: harvest session state before /clear and /compact#1044

Open
qozle wants to merge 1 commit intodanielmiessler:mainfrom
qozle:fix/pre-context-reset-hook
Open

fix: harvest session state before /clear and /compact#1044
qozle wants to merge 1 commit intodanielmiessler:mainfrom
qozle:fix/pre-context-reset-hook

Conversation

@qozle
Copy link
Copy Markdown

@qozle qozle commented Apr 7, 2026

Summary

  • /clear and /compact destroy conversation context without triggering SessionEnd, so WorkCompletionLearning, RelationshipMemory, and progress snapshots are silently lost
  • Adds PreContextReset.hook.ts — a UserPromptSubmit hook that detects /clear and /compact and runs a lightweight harvest before context is destroyed
  • Registered first in the UserPromptSubmit hook chain so it runs before other hooks

What it harvests

  1. Work completion learning — captures active work state and ISC progress to MEMORY/LEARNING/
  2. Relationship notes — appends session interaction notes to MEMORY/RELATIONSHIP/
  3. Progress snapshot — annotates active progress files with a context-reset marker
  4. Rating signal marker — marks the reset point in ratings.jsonl so downstream analysis knows context changed

Does NOT run cleanup (tab reset, state deletion) since the session continues after both commands.

Performance

  • Non-matching prompts (99% of traffic): <5ms fast exit
  • Matching prompts: <100ms — all disk I/O, no inference calls

Test plan

  • Run with non-reset prompt — verify silent fast exit, no side effects
  • Run with /clear — verify learning file created, relationship note appended, rating marker written
  • Run with /compact — same verification
  • Verify no active work state handles gracefully (no crash, no empty files)

Closes #1043

SessionEnd hooks (WorkCompletionLearning, RelationshipMemory) never fire
on /clear or /compact, so learnings, relationship notes, and progress
snapshots are silently lost. This adds a UserPromptSubmit hook that
detects these commands and runs a lightweight harvest before context
is destroyed.

Fast exit (<5ms) for all non-matching prompts — zero overhead on
normal usage.

Closes danielmiessler#1043
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.

SessionEnd hooks skipped on /clear and /compact — learnings lost

1 participant