Skip to content

fix: WorkCompletionLearning reads nonexistent state files#1050

Open
qozle wants to merge 1 commit intodanielmiessler:mainfrom
qozle:fix/work-completion-learning-972
Open

fix: WorkCompletionLearning reads nonexistent state files#1050
qozle wants to merge 1 commit intodanielmiessler:mainfrom
qozle:fix/work-completion-learning-972

Conversation

@qozle
Copy link
Copy Markdown

@qozle qozle commented Apr 7, 2026

Fixes #972

Problem

WorkCompletionLearning.hook.ts never generates learning files due to two bugs:

  1. findStateFile() looks for files that don't exist. It searches for MEMORY/STATE/current-work.json or current-work-{sessionId}.json, but nothing in PAI creates these files. The hook always exits with "No active work session."

  2. ISC regex doesn't match PRD v2.0 format. The regex looks for ## IDEAL STATE CRITERIA but PRDFORMAT.md v2.0 defines the section as ## Criteria. ISC content is never extracted.

There's also a field name mismatch: PRD frontmatter uses task/slug/started but the WorkMeta interface expects title/id/created_at.

Fix

  1. Replace findStateFile() with findWorkSession() that reads work.json (the actual state file, populated by PRDSync hook) and matches sessions by sessionUUID.

  2. Update the ISC regex to accept both ## IDEAL STATE CRITERIA (legacy) and ## Criteria (v2.0).

  3. Add field mapping in parseYaml() so v2.0 frontmatter fields get mapped to the interface fields the rest of the hook expects.

Verification

  • Confirmed PRDSync.hook.ts writes to MEMORY/STATE/work.json via syncToWorkJson() in prd-utils.ts
  • Confirmed prd-utils.ts countCriteria() uses ## Criteria header (line 61), matching the fix
  • Confirmed work.json registry keys sessions by slug (= the WORK directory name), so session_dir mapping is correct

…lmiessler#972)

Two bugs prevented the hook from ever generating learning files:

1. findStateFile() looked for current-work.json / current-work-{sessionId}.json
   but nothing in PAI creates these files. Replaced with findWorkSession() that
   reads work.json (populated by PRDSync hook) and matches by sessionUUID.

2. ISC regex matched "## IDEAL STATE CRITERIA" but PRD format v2.0 uses
   "## Criteria". Updated regex to accept both headers.

Also added field mapping in parseYaml() for v2.0 frontmatter fields
(task->title, slug->id, started->created_at).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

WorkCompletionLearning hook never generates learnings (2 bugs)

1 participant