Skip to content

Bug: pai-history-system missing src/lib/metadata-extraction.ts #362

Description

@a1wilson

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:

  1. src/capture-all-events.ts:8

    import { enrichEventWithAgentMetadata, isAgentSpawningCall } from './lib/metadata-extraction';
  2. src/subagent-stop-hook.ts:8

    import { extractAgentInstanceId } from './lib/metadata-extraction';

Root Cause

Git history analysis:

  • Commit 1c34d06 (directory-based migration): File existed at Packs/kai-history-system/src/lib/metadata-extraction.ts
  • Commit 0faf5e4 (kai-* → pai-* rebranding): File was deleted (75 lines removed) but never re-added to Packs/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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions