Skip to content

feat: TTL-cached team-knowledge index (no clone required)#63

Merged
arzafran merged 1 commit into
mainfrom
feat/knowledge-index-cache
Jun 19, 2026
Merged

feat: TTL-cached team-knowledge index (no clone required)#63
arzafran merged 1 commit into
mainfrom
feat/knowledge-index-cache

Conversation

@arzafran

Copy link
Copy Markdown
Member

What this does

Follow-up to #62. That PR's session-start ping only worked if you'd cloned team-knowledge and set KNOWLEDGE_REPO_PATH — which almost nobody does, so for most people it stayed dark. This makes it work for anyone with gh auth, no clone and no setup.

Instead of vendoring a copy of the index into this repo (which would be a second source of truth that drifts, and would need a cross-repo write token), it caches the corpus listing the same way the Codex bridge caches its verdict: fetch via gh api at most once every 6 hours into ~/.claude/tmp/knowledge-index.json, read it instantly at session start. The cache is per-user, self-refreshing, and can't drift from the source.

Verified end-to-end against the live repo — the refresh populated the cache with the real note set on first run.

Summary

  • src/lib/knowledge-index.tsrefreshKnowledgeIndex() (TTL-gated, fetches gh api repos/$KNOWLEDGE_REPO/contents only when stale, fail-open: any gh/network/parse error returns the existing cache and never clobbers good data or throws), readKnowledgeIndex(), and pure parseContentsListing / isStale helpers.
  • src/scripts/refresh-knowledge-index.ts — detached entrypoint that session-start fire-and-forgets (same pattern as the MCP-auth prune); cheap when fresh because the TTL gate lives in the refresh.
  • teamKnowledgeAwareness() now prefers the cache; an explicit repoPath still uses a local clone, so offline / no-gh users with KNOWLEDGE_REPO_PATH keep working.
  • KNOWLEDGE_REPO env overrides the default darkroomengineering/team-knowledge.

Why not a committed/vendored index

Vendoring would add a derived artifact that drifts from the source (the same bug class as the MANAGED_SKILLS drift fixed in #61), and a push-from-team-knowledge sync would need a write credential into this repo. The cache gets the same "every install has the index" benefit with none of that.

Test Plan

  • bun run typecheck — clean
  • bun test tests/knowledge-index.test.ts tests/team-knowledge.test.ts — 21/21 (pure parse + staleness; existing clone cases preserved)
  • bun test — 615 pass / 0 fail
  • bun run lint — clean
  • End-to-end: bun src/scripts/refresh-knowledge-index.ts populated the cache with the live corpus listing

Branches off main (has #61 + #62). Standalone.

Makes the session-start awareness ping (and a future /knowledge consult) work
for anyone with gh auth, not just people who cloned the repo and set
KNOWLEDGE_REPO_PATH. Mirrors the codex-verdict cache pattern:

- src/lib/knowledge-index.ts: refreshKnowledgeIndex() fetches the corpus listing
  via gh api at most once per 6h TTL, writes ~/.claude/tmp/knowledge-index.json;
  readKnowledgeIndex() reads it instantly. Fully fail-open — no gh / network
  error returns the existing cache, never clobbers good data, never throws.
- src/scripts/refresh-knowledge-index.ts: detached entrypoint session-start
  spawns fire-and-forget (TTL-gated internally, so it only calls gh when stale).
- teamKnowledgeAwareness() now prefers the cache (no clone needed); an explicit
  repoPath still uses the local clone, so it falls back for offline/no-gh users.

No second source of truth, no cross-repo token, no vendored index — the cache is
per-user, self-refreshing, and never drifts. parseContentsListing + isStale are
pure and unit-tested (no network in tests).
@arzafran arzafran merged commit 3b197ed into main Jun 19, 2026
15 checks passed
@arzafran arzafran deleted the feat/knowledge-index-cache branch June 19, 2026 20:37
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.

1 participant