Skip to content

feat(memory): auto-index all harnesses on session end (debounced sweep) - #116

Merged
sandstream merged 1 commit into
mainfrom
feat/memory-auto-index-harnesses
Jun 27, 2026
Merged

sandstream merged 1 commit into
mainfrom
feat/memory-auto-index-harnesses

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes item 3 from the OpenCode/memory follow-ups: get all harnesses indexed automatically, without paying for it on every session.

Problem

The SessionEnd hook (runSessionEndIndex) only ran indexClaudeTranscripts. The other harnesses (codex/cursor/gemini/cline/amazon-q, and OpenCode once #115 lands) have no kit hook, so they were only indexed when a user manually ran kit memory index.

Fix — debounced sweep, not hot-path

runSessionEndIndex now runs the full indexAllHarnesses, but debounced to at most once per 6h, gated by a .harness-sweep marker file's mtime under the memory dir:

  • Common path stays cheap — just the incremental Claude index of the just-ended session.
  • When due — sweep all harness dirs once, then touch the marker.
  • Deliberately not added to the SessionStart hot path (that one only does fast recovery).
  • Fail-open throughout: if the marker can't be read we skip the sweep rather than add latency; a missed marker just means we sweep next time.

ensureMemoryDir is exported for the marker writer (written 0o600).

This was the design choice flagged earlier — periodic background-style sweep rather than walking six extra dirs on every session end.

Test: debounce logic (due when no marker; not due for 6h after a sweep; due again once the interval elapses). Full suite 1537/0. Independent of #115 (composes with it — once #115 merges, the sweep picks up OpenCode too).


🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

The SessionEnd hook only indexed Claude Code, so other harnesses
(codex/cursor/gemini/cline/amazon-q/opencode) were never picked up
automatically — they required a manual `kit memory index`.

runSessionEndIndex now sweeps ALL harnesses via indexAllHarnesses, but
debounced: at most once per 6h, gated by a `.harness-sweep` marker file's
mtime under the memory dir. The common path stays cheap (just the
incremental Claude index of the just-ended session); the full multi-dir
sweep runs only when due. Deliberately NOT added to the SessionStart hot
path. Fail-open throughout: if we can't read the marker we skip the sweep
rather than add latency, and a missed marker just means we sweep next time.

ensureMemoryDir is now exported for the marker writer (0o600). Test covers
the debounce: due when no marker, not due for 6h after a sweep, due again
once the interval elapses. Full suite 1537/0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit e975e20 into main Jun 27, 2026
15 checks passed
@sandstream
sandstream deleted the feat/memory-auto-index-harnesses branch June 27, 2026 09:06
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