mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
feat(coding-agent): ingest external entries in in-memory sessions (#8980)
* feat(coding-agent): ingest external entries in in-memory sessions SessionManager.inMemory() takes the entries to start from, so a session held outside the filesystem can be resumed as it was stored. Replaying through appendMessage/appendCompaction cannot do this: ids are minted fresh, so every stored firstKeptEntryId, targetId and fromId has to be remapped, timestamps are rewritten, and parentId always comes from the current leaf, so a branched tree needs the original branch() choreography reproduced call by call. The entry-adoption half of _setSessionFile becomes _loadEntries, which the constructor also uses when there are entries but no file. Entries carrying a session header keep it; without one, the header comes from the options and the entries become its body. * fix(coding-agent): carry the stored version through restored entries inMemory() took SessionEntry[], which excludes SessionHeader, so an external store could not pass the header it saved and the header branch of _loadEntries was unreachable through the public API. A restore therefore always synthesised a current-version header, and the migration that ran next read that header and skipped: a v2 session kept its hookMessage roles forever. Widening to FileEntry[] lets the stored header through, version included. Migration moves inside the header branch, where a version exists to compare against; without a header the entries are adopted as current-version, which is the only thing they can mean.
This commit is contained in:
parent
1a773c8e7a
commit
2b768ba42c
3 changed files with 213 additions and 13 deletions
|
|
@ -788,6 +788,11 @@ const { session: opened } = await createAgentSession({
|
|||
sessionManager: SessionManager.open("/path/to/session.jsonl"),
|
||||
});
|
||||
|
||||
// Resume a session kept outside the filesystem, e.g. in a database
|
||||
const { session: restored } = await createAgentSession({
|
||||
sessionManager: SessionManager.inMemory(process.cwd(), { id: sessionId }, entries),
|
||||
});
|
||||
|
||||
// List sessions
|
||||
const currentProjectSessions = await SessionManager.list(process.cwd());
|
||||
const allSessions = await SessionManager.listAll(process.cwd());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue