fix(pi-plugin): retrospective provider SessionManager API mismatch#201
fix(pi-plugin): retrospective provider SessionManager API mismatch#201kachook wants to merge 1 commit into
Conversation
Fix two bugs in loadDefaultPiSessionDeps that prevented the retrospective dream task from discovering Pi sessions: 1. SessionManager.listSessions → listAll: pi-coding-agent exports listAll(), not listSessions(). The listAll(sessionDir?) signature matches the call site. 2. loadEntriesFromFile not exported: This function exists internally in pi-coding-agent but is not part of the public API. Added a fallback that reads the file with readFileSync and parses via the exported parseSessionEntries() function. Verified: /ctx-dream retrospective now runs successfully on Pi.
| const loadEntriesFromFile: ( | ||
| filePath: string, | ||
| ) => unknown[] | Promise<unknown[]> = | ||
| mod.loadEntriesFromFile ?? | ||
| ((filePath: string) => { | ||
| const content = readFileSync(filePath, "utf8"); | ||
| return mod.parseSessionEntries?.(content) ?? []; | ||
| }); |
There was a problem hiding this comment.
Silent fallback when
parseSessionEntries is also absent
The guard now only checks that SessionManager.listAll is present, but drops the check for any entry-loading API. If loadEntriesFromFile is not exported (the situation described in the PR) and parseSessionEntries is also not exported or is later removed, mod.parseSessionEntries?.(content) evaluates to undefined, undefined ?? [] returns [], and every call to loadEntriesFromFile silently produces zero entries — no exception is raised, and the retrospective task reports "Skipped (no work)" with no diagnostic error. This is the exact same symptom as the original bug, just without the helpful error message that would surface it.
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/pi-plugin/package.json">
<violation number="1" location="packages/pi-plugin/package.json:64">
P3: Missing trailing newline at end of file. This will produce a noisy diff when the next change adds one, and most linters (including Biome, which this repo uses) flag it.</violation>
</file>
<file name="packages/pi-plugin/src/dreamer/retrospective-raw-provider-pi.ts">
<violation number="1" location="packages/pi-plugin/src/dreamer/retrospective-raw-provider-pi.ts:214">
P2: Silent failure when `parseSessionEntries` is unavailable. If the peer package stops exporting `parseSessionEntries`, `mod.parseSessionEntries?.(content)` evaluates to `undefined`, and `?? []` silently returns an empty array. The retrospective will report "Skipped (no work)" with no diagnostic — reproducing the exact same symptom this PR intends to fix. Consider throwing (or at least logging a warning) when neither `loadEntriesFromFile` nor `parseSessionEntries` is available.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| mod.loadEntriesFromFile ?? | ||
| ((filePath: string) => { | ||
| const content = readFileSync(filePath, "utf8"); | ||
| return mod.parseSessionEntries?.(content) ?? []; |
There was a problem hiding this comment.
P2: Silent failure when parseSessionEntries is unavailable. If the peer package stops exporting parseSessionEntries, mod.parseSessionEntries?.(content) evaluates to undefined, and ?? [] silently returns an empty array. The retrospective will report "Skipped (no work)" with no diagnostic — reproducing the exact same symptom this PR intends to fix. Consider throwing (or at least logging a warning) when neither loadEntriesFromFile nor parseSessionEntries is available.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/pi-plugin/src/dreamer/retrospective-raw-provider-pi.ts, line 214:
<comment>Silent failure when `parseSessionEntries` is unavailable. If the peer package stops exporting `parseSessionEntries`, `mod.parseSessionEntries?.(content)` evaluates to `undefined`, and `?? []` silently returns an empty array. The retrospective will report "Skipped (no work)" with no diagnostic — reproducing the exact same symptom this PR intends to fix. Consider throwing (or at least logging a warning) when neither `loadEntriesFromFile` nor `parseSessionEntries` is available.</comment>
<file context>
@@ -191,20 +192,27 @@ async function loadDefaultPiSessionDeps(): Promise<
+ mod.loadEntriesFromFile ??
+ ((filePath: string) => {
+ const content = readFileSync(filePath, "utf8");
+ return mod.parseSessionEntries?.(content) ?? [];
+ });
return {
</file context>
| return mod.parseSessionEntries?.(content) ?? []; | |
| const entries = mod.parseSessionEntries?.(content); | |
| if (entries === undefined) { | |
| throw new Error( | |
| "Pi session APIs unavailable: neither loadEntriesFromFile nor parseSessionEntries found on pi-coding-agent", | |
| ); | |
| } | |
| return entries; |
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.js" | ||
| } |
There was a problem hiding this comment.
P3: Missing trailing newline at end of file. This will produce a noisy diff when the next change adds one, and most linters (including Biome, which this repo uses) flag it.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/pi-plugin/package.json, line 64:
<comment>Missing trailing newline at end of file. This will produce a noisy diff when the next change adds one, and most linters (including Biome, which this repo uses) flag it.</comment>
<file context>
@@ -1,71 +1,71 @@
+ "exports": {
+ ".": {
+ "import": "./dist/index.js"
+ }
+ },
+ "pi": {
</file context>
Summary
Fix two bugs in
loadDefaultPiSessionDeps()that prevented the/ctx-dream retrospectivedream task from discovering Pi sessions, causing it to silently report "Skipped (no work)".Bug 1: SessionManager.listSessions doesn't exist
Symptom:
loadDefaultPiSessionDeps()throws"Pi session APIs unavailable: expected SessionManager.listSessions and loadEntriesFromFile"Root cause: pi-coding-agent's
SessionManagerclass exportslistAll(sessionDir?), notlistSessions(). The code was looking for the wrong method name.Fix: Changed
mod.SessionManager?.listSessions→mod.SessionManager?.listAllBug 2: loadEntriesFromFile not exported
Symptom: Even after fixing Bug 1, the function would still throw because
loadEntriesFromFileis not part of pi-coding-agent's public API.Root cause:
loadEntriesFromFileexists internally insession-manager.jsbut is not re-exported from the package'sindex.js.Fix: Added a fallback that reads the file with
readFileSyncand parses via the exportedparseSessionEntries()function.Testing
Verified:
/ctx-dream retrospectivenow runs successfully on Pi agent.Files changed
packages/pi-plugin/src/dreamer/retrospective-raw-provider-pi.tspackages/pi-plugin/package.json(version bump 0.30.1 → 0.30.2)Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Restores Pi session discovery in the retrospective provider by aligning with
@earendil-works/pi-coding-agentAPIs./ctx-dream retrospectivenow runs instead of skipping with “no work”.SessionManager.listAll()instead of the non-existentlistSessions().loadEntriesFromFile: read file viareadFileSyncand parse with exportedparseSessionEntries().Written for commit 587ae8e. Summary will update on new commits.
Greptile Summary
This patch fixes two API-mismatch bugs in
loadDefaultPiSessionDeps()that prevented the retrospective dream task from discovering Pi sessions: the wrong method name (listSessions→listAll) and a missing public export (loadEntriesFromFile), the latter worked around via areadFileSync+parseSessionEntriesfallback.mod.SessionManager?.listSessionscorrected tomod.SessionManager?.listAll, matching pi-coding-agent's actual exported API.loadEntriesFromFileis no longer checked in the guard; instead a fallback lambda reads the file withreadFileSyncand delegates parsing tomod.parseSessionEntries. IfparseSessionEntriesis also absent, the optional chain returnsundefinedand?? []silently produces empty entries with no error thrown — the same silent "Skipped (no work)" outcome as the original bug.package.json: patch version bump 0.30.1 → 0.30.2; indentation reformatted from tabs to spaces; trailing newline removed.Confidence Score: 3/5
The listAll rename is correct and low-risk, but the fallback for entry loading introduces a silent no-op path that reproduces the original bug symptom without any diagnostic error.
The listAll rename is straightforward and correct. The parseSessionEntries fallback is more fragile: removing the guard means a future pi-coding-agent API change could silently zero out all session entries without throwing any error, leaving the retrospective task in exactly the Skipped (no work) state it was supposed to escape.
retrospective-raw-provider-pi.ts — specifically the fallback lambda at lines 208-215 and the absence of a guard for parseSessionEntries.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(pi-plugin): retrospective provider S..." | Re-trigger Greptile