Bug: pai-history-system missing src/lib/metadata-extraction.ts
Description
The pai-history-system pack is missing the required src/lib/metadata-extraction.ts file, causing installation failures. This file was lost during the kai-* → pai-* rebranding.
Impact
Severity: High - Breaks pai-history-system installation
When users install pai-history-system following the wizard in INSTALL.md, the hooks are copied but the required library file is missing, resulting in:
SessionEnd hook [bun run $PAI_DIR/hooks/capture-all-events.ts --event-type SessionEnd] failed:
error: Cannot find module './lib/metadata-extraction' from '/Users/user/.claude/hooks/capture-all-events.ts'
Files Affected
The following files import from the missing module:
-
src/capture-all-events.ts:8import { enrichEventWithAgentMetadata, isAgentSpawningCall } from './lib/metadata-extraction'; -
src/subagent-stop-hook.ts:8import { extractAgentInstanceId } from './lib/metadata-extraction';
Root Cause
Git history analysis:
-
Commit
1c34d06(directory-based migration): File existed atPacks/kai-history-system/src/lib/metadata-extraction.ts✓ -
Commit
0faf5e4(kai-* → pai-* rebranding): File was deleted (75 lines removed) but never re-added toPacks/pai-history-system/src/lib/
Evidence:
$ git ls-tree -r 1c34d06 --name-only | grep metadata-extraction
Packs/kai-history-system/src/lib/metadata-extraction.ts # ✓ existed
Packs/kai-observability-server/src/hooks/lib/metadata-extraction.ts
$ git ls-tree -r 0faf5e4 --name-only | grep metadata-extraction
Packs/pai-observability-server/src/hooks/lib/metadata-extraction.ts # ✗ pai-history-system missing
Expected vs Actual
Expected (per README.md line 35)
pai-history-system/
├── src/
│ ├── capture-all-events.ts
│ ├── stop-hook.ts
│ ├── subagent-stop-hook.ts
│ ├── capture-session-summary.ts
│ └── lib/
│ └── metadata-extraction.ts ← Should exist
Actual
pai-history-system/
├── src/
│ ├── capture-all-events.ts
│ ├── stop-hook.ts
│ ├── subagent-stop-hook.ts
│ ├── capture-session-summary.ts
│ └── lib/ ← Directory missing entirely
Proposed Fix
Restore the file from the last known good commit:
git show 1c34d06:Packs/kai-history-system/src/lib/metadata-extraction.ts \
> Packs/pai-history-system/src/lib/metadata-extraction.ts
The file should contain ~75 lines with these exports:
-
extractAgentInstanceId() -
enrichEventWithAgentMetadata() -
isAgentSpawningCall()
Workaround (for users)
Users can manually copy the file from pai-observability-server:
mkdir -p ~/.claude/hooks/lib
cp Packs/pai-observability-server/src/hooks/lib/metadata-extraction.ts \
~/.claude/hooks/lib/
Additional Context
- This does NOT indicate pai-history-system depends on pai-observability-server
- Both packs originally had independent copies of this shared utility
- The file should be restored to pai-history-system for proper installation
- Documentation (README.md, INSTALL.md) correctly references the file - only the actual file is missing
Verification
After fix, verify:
# File should exist
ls -la Packs/pai-history-system/src/lib/metadata-extraction.ts
# Should contain these exports
grep -E "export (function|interface)" Packs/pai-history-system/src/lib/metadata-extraction.ts
Expected output:
export interface AgentInstanceMetadata
export function extractAgentInstanceId
export function enrichEventWithAgentMetadata
export function isAgentSpawningCall
Fix Available in PR #411
I've restored lib/metadata-extraction.ts from git history (commit 1c34d06).
The file includes all required exports:
- extractAgentInstanceId()
- enrichEventWithAgentMetadata()
- isAgentSpawningCall()
- AgentInstanceMetadata interface
PR: https://github.com/danielmiessler/Personal_AI_Infrastructure/pull/411
This is part of a comprehensive fix that also restores the 4 deleted memory hooks and implements the three-tier MEMORY architecture.
Testing: Both capture-all-events.ts and subagent-stop-hook.ts now import successfully.
cc @danielmiessler