Summary
hooks/WorkCompletionLearning.hook.ts (v4.0.3) has two bugs that prevent it from ever generating learning files in MEMORY/LEARNING/. The hook silently exits on every SessionEnd, meaning the WORK→LEARNING bridge has never functioned.
Bug 1: current-work.json dependency doesn't exist
Location: findStateFile() (line ~64)
The function looks for MEMORY/STATE/current-work.json or current-work-{sessionId}.json:
function findStateFile(sessionId?: string): string | null {
if (sessionId) {
const scoped = join(STATE_DIR, `current-work-${sessionId}.json`);
if (existsSync(scoped)) return scoped;
}
const legacy = join(STATE_DIR, 'current-work.json');
if (existsSync(legacy)) return legacy;
return null;
}
Problem: Nothing in PAI or Claude Code creates either of these files. The hook always exits with "No active work session" on line 276.
Fix: Replace with a lookup in MEMORY/STATE/work.json (populated by PRDSync hook), matching session_id from stdin to sessionUUID in work.json entries.
Bug 2: Section header mismatch
Location: ISC extraction regex (line ~326)
const iscMatch = prdContent.match(/## IDEAL STATE CRITERIA[\s\S]*?(?=\n## |$)/);
Problem: PAI/PRDFORMAT.md v2.0 defines the section as ## Criteria, not ## IDEAL STATE CRITERIA. The regex never matches, so ISC content is never extracted.
Fix: Update regex to accept both formats:
const iscMatch = prdContent.match(/## (?:IDEAL STATE CRITERIA|Criteria)[\s\S]*?(?=\n## |$)/);
Additional: Field name mismatch
PRD frontmatter uses task: but WorkMeta interface expects title:. Similarly slug:→id: and started:→created_at:. The parseYaml() output needs field mapping for v4.0 PRDs.
Impact
MEMORY/LEARNING/SYSTEM/ and MEMORY/LEARNING/ALGORITHM/ remain permanently empty
- The learning loop described in
MEMORYSYSTEM.md never activates
- 49 sessions tested, 0 learning files generated
Verification
Both bugs confirmed identical in upstream repo (Releases/v4.0.3/.claude/hooks/WorkCompletionLearning.hook.ts) and local install. Fix applied and tested locally — hook now correctly generates .md learning files with ISC content.
Environment
- PAI v4.0.3
- Claude Code on WSL2 (Linux 6.6.87.2)
- Bun runtime
Summary
hooks/WorkCompletionLearning.hook.ts(v4.0.3) has two bugs that prevent it from ever generating learning files inMEMORY/LEARNING/. The hook silently exits on every SessionEnd, meaning the WORK→LEARNING bridge has never functioned.Bug 1:
current-work.jsondependency doesn't existLocation:
findStateFile()(line ~64)The function looks for
MEMORY/STATE/current-work.jsonorcurrent-work-{sessionId}.json:Problem: Nothing in PAI or Claude Code creates either of these files. The hook always exits with
"No active work session"on line 276.Fix: Replace with a lookup in
MEMORY/STATE/work.json(populated by PRDSync hook), matchingsession_idfrom stdin tosessionUUIDin work.json entries.Bug 2: Section header mismatch
Location: ISC extraction regex (line ~326)
Problem:
PAI/PRDFORMAT.mdv2.0 defines the section as## Criteria, not## IDEAL STATE CRITERIA. The regex never matches, so ISC content is never extracted.Fix: Update regex to accept both formats:
Additional: Field name mismatch
PRD frontmatter uses
task:butWorkMetainterface expectstitle:. Similarlyslug:→id:andstarted:→created_at:. TheparseYaml()output needs field mapping for v4.0 PRDs.Impact
MEMORY/LEARNING/SYSTEM/andMEMORY/LEARNING/ALGORITHM/remain permanently emptyMEMORYSYSTEM.mdnever activatesVerification
Both bugs confirmed identical in upstream repo (
Releases/v4.0.3/.claude/hooks/WorkCompletionLearning.hook.ts) and local install. Fix applied and tested locally — hook now correctly generates.mdlearning files with ISC content.Environment