Skip to content

fix(pi-plugin): retrospective provider SessionManager API mismatch#201

Open
kachook wants to merge 1 commit into
cortexkit:masterfrom
kachook:fix/retrospective-session-listing
Open

fix(pi-plugin): retrospective provider SessionManager API mismatch#201
kachook wants to merge 1 commit into
cortexkit:masterfrom
kachook:fix/retrospective-session-listing

Conversation

@kachook

@kachook kachook commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Fix two bugs in loadDefaultPiSessionDeps() that prevented the /ctx-dream retrospective dream 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 SessionManager class exports listAll(sessionDir?), not listSessions(). The code was looking for the wrong method name.

Fix: Changed mod.SessionManager?.listSessionsmod.SessionManager?.listAll

Bug 2: loadEntriesFromFile not exported

Symptom: Even after fixing Bug 1, the function would still throw because loadEntriesFromFile is not part of pi-coding-agent's public API.

Root cause: loadEntriesFromFile exists internally in session-manager.js but is not re-exported from the package's index.js.

Fix: Added a fallback that reads the file with readFileSync and parses via the exported parseSessionEntries() function.

Testing

Verified: /ctx-dream retrospective now runs successfully on Pi agent.

Files changed

  • packages/pi-plugin/src/dreamer/retrospective-raw-provider-pi.ts
  • packages/pi-plugin/package.json (version bump 0.30.1 → 0.30.2)

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Restores Pi session discovery in the retrospective provider by aligning with @earendil-works/pi-coding-agent APIs. /ctx-dream retrospective now runs instead of skipping with “no work”.

  • Bug Fixes
    • Use SessionManager.listAll() instead of the non-existent listSessions().
    • Add fallback for loadEntriesFromFile: read file via readFileSync and parse with exported parseSessionEntries().

Written for commit 587ae8e. Summary will update on new commits.

Review in cubic

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 (listSessionslistAll) and a missing public export (loadEntriesFromFile), the latter worked around via a readFileSync + parseSessionEntries fallback.

  • Bug 1 (method name): mod.SessionManager?.listSessions corrected to mod.SessionManager?.listAll, matching pi-coding-agent's actual exported API.
  • Bug 2 (missing export): loadEntriesFromFile is no longer checked in the guard; instead a fallback lambda reads the file with readFileSync and delegates parsing to mod.parseSessionEntries. If parseSessionEntries is also absent, the optional chain returns undefined and ?? [] 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

Filename Overview
packages/pi-plugin/src/dreamer/retrospective-raw-provider-pi.ts Fixes the SessionManager.listSessions → listAll method name and adds a readFileSync+parseSessionEntries fallback for loadEntriesFromFile; the fallback silently returns empty arrays if parseSessionEntries is also absent, reproducing the original "Skipped (no work)" symptom without any diagnostic error.
packages/pi-plugin/package.json Patch version bump 0.30.1 → 0.30.2 and reformatting from tabs to spaces; missing trailing newline at end of file.

Reviews (1): Last reviewed commit: "fix(pi-plugin): retrospective provider S..." | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

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.
Comment on lines +208 to +215
const loadEntriesFromFile: (
filePath: string,
) => unknown[] | Promise<unknown[]> =
mod.loadEntriesFromFile ??
((filePath: string) => {
const content = readFileSync(filePath, "utf8");
return mod.parseSessionEntries?.(content) ?? [];
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Comment on lines +70 to +71
}
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The file is missing a trailing newline after the reformatting. Most linters and editors expect one, and it produces a noisy diff in future PRs.

Suggested change
}
}
}
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) ?? [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

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.

2 participants