Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

RelationshipMemory.hook.ts silently broken in v4.0 — references nonexistent ParsedTranscript.userPrompt

Open catchingknives opened this issue 8 months ago • 2 comments

Summary

RelationshipMemory.hook.ts was refactored in v4.0.0 to use the new shared TranscriptParser, but the migration introduced a breaking reference to a field (userPrompt) that doesn't exist on the ParsedTranscript interface. The hook silently produces zero output and has been non-functional since v4.0.0.

Bug Details

In v3.0, the hook parsed transcripts directly via readFileSync + JSON line parsing, accessing entry.message.content on each JSONL entry. This worked — both user and assistant messages were read.

In v4.0.0, the hook was refactored to use parseTranscript() from PAI/Tools/TranscriptParser.ts:

// RelationshipMemory.hook.ts, lines 76-84
const parsed = parseTranscript(path);
const entries: TranscriptEntry[] = [];
if (parsed.userPrompt) {          // <-- doesn't exist
  entries.push({ type: 'user', text: parsed.userPrompt });
}
if (parsed.plainCompletion) {
  entries.push({ type: 'assistant', text: parsed.plainCompletion });
}

ParsedTranscript interface (TranscriptParser.ts) has these fields:

raw, lastMessage, currentResponseText, voiceCompletion,
plainCompletion, structured, responseState

No userPrompt field. It's always undefined.

Impact

Three compounding failures:

  1. User messages never captured — parsed.userPrompt is undefined, so preference/frustration/positive pattern matching against user input never fires
  2. Assistant content too narrow — plainCompletion is a short extracted string, not the full response. Most SUMMARY: and milestone regex patterns don't match against it
  3. Silent failure — the hook exits cleanly with [RelationshipMemory] No relationship notes to capture, no error thrown

Result: MEMORY/RELATIONSHIP/ receives zero new entries. In my install, the last entry is from Feb 27 (pre-v4.0 upgrade). No 2026-03 directory was ever created despite daily use.

Steps to Reproduce

  1. Install PAI v4.0.x
  2. Run any session and let it end cleanly (SessionEnd fires)
  3. Check MEMORY/RELATIONSHIP/ — no new files created
  4. Check stderr — hook logs "No relationship notes to capture"

Suggested Fix

Either:

  • Minimal: Add userPrompt field to ParsedTranscript in TranscriptParser.ts and populate it from the last user message in the transcript
  • Better: Expose full userMessages and assistantMessages arrays from ParsedTranscript so hooks can access the complete conversation, not just the last turn. The v3.0 approach of iterating all JSONL entries was more thorough

Environment

  • PAI v4.0.3 / Algorithm v3.7.0
  • Claude Code 2.1.78
  • macOS Darwin 25.3.0

catchingknives avatar Mar 18 '26 18:03 catchingknives

Confirmed + Fix Implemented

We independently discovered the same bugs and went deeper — the issues are actually more fundamental than the TranscriptParser reference:

Additional bugs beyond #971's scope

  1. Regex patterns are English-only — prefer|like|frustrate|annoyed never match for non-English users. PAI is used internationally.
  2. Threshold of 2+ matches is unreachable — even with TranscriptParser fixed, positives.length >= 2 or frustrations.length >= 2 from a single transcript pair will almost never trigger.
  3. The regex approach is architecturally wrong for this use case — bilingual free-text sentiment/preference detection via regex is fundamentally brittle.

Our fix: Replace regex with Haiku inference

We replaced analyzeForRelationship() entirely with a Haiku inference call via Inference.ts (already used successfully by RatingCapture.hook.ts). Key design choices:

  • Language-agnostic — Haiku handles any language naturally, no regex patterns needed
  • Structured output — returns JSON array of W/B/O notes with confidence scores
  • [unverified] tag — all AI-generated notes are tagged to prevent hallucination propagation to OPINIONS.md
  • Max 3 notes per session — prevents noise from technical-only sessions
  • Graceful degradation — timeout or API failure = silent skip (existing try/catch pattern)
  • Proven pattern — identical to how RatingCapture uses Inference.ts

Results

Tested with bilingual input (Spanish/English). Hook now generates proper W/B/O notes:

## 00:24 PST
- O(c=0.85) @Jacobo: Prefiere soluciones que no modifiquen excesivamente el código base [unverified]
- B @Atlas: Completó auditoría de PAI, identificó bugs en hooks, creó issue GitHub #972 [unverified]
- W @Nexus Colpro: Laura es COO de Nexus Colpro [unverified]

The full relationship pipeline (RelationshipMemory → OpinionTracker → RelationshipReflect → LoadContext) is now functional for the first time.

Upstream consideration

The regex approach should be replaced with inference for all users, not just patched. The fix is ~40 lines replacing the analyzeForRelationship() function body + adding import { inference }. All other hook code (formatNotes, ensureRelationshipDir, main flow) stays unchanged.

Happy to submit a PR if the maintainers agree with the inference-based approach.

jacobo-ortiz avatar Mar 19 '26 05:03 jacobo-ortiz

Hey @catchingknives — Kai here, Daniel's AI assistant. (Apologies — prior comment had shell-escaped backticks; reposting.)

Closing this out because the v5.0.0 RelationshipMemory.hook.ts no longer references ParsedTranscript.userPrompt at all — the bug path is gone (verified by grep against the v5 hook source).

If this still reproduces or matters in v5.0.0, please reopen or file a fresh issue against the new release. Thanks for taking the time to file this — really appreciated.

— Kai 🤖

danielmiessler avatar May 01 '26 19:05 danielmiessler