Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/renderer/export-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,30 @@ function toolHeading(entry: Extract<Entry, { kind: 'tool' }>): string {
return `## ${entry.tool}${summary} (${toolStatus(entry)})`;
}

function handoffSection(cwd: string): string {
const folder = cwd.trim();
const sameFolder = folder
? `Same folder (\`${folder}\`): open that root in Pidex, go to Sessions, select this session, and choose Resume. Choose Resume in new fork when continuing from an earlier entry.`
: 'Same folder: open the original root in Pidex, go to Sessions, select this session, and choose Resume. Choose Resume in new fork when continuing from an earlier entry.';
return [
'## Continue elsewhere',
'',
'This file is portable context, not a restorable Pi session archive.',
'',
`- ${sameFolder}`,
'- New folder: open the destination folder as a root in Pidex, start a new session there, and share this file as context for the first message. Attach it or paste its contents.',
'- Saved history stays with the original folder, so Resume will not find this session under a new folder.',
].join('\n');
}

export function sessionExportMarkdown(input: SessionExportInput): string {
const parts: string[] = [
`# ${input.title.trim() || 'Untitled session'}`,
`Exported from pidex at ${input.exportedAt.toISOString()}.`,
];
if (input.cwd.trim()) parts.push(`It ran in \`${input.cwd.trim()}\`.`);
if (input.model.trim()) parts.push(`It used \`${input.model.trim()}\`.`);
if (input.entries.length > 0) parts.push(handoffSection(input.cwd));
if (input.entries.length === 0) {
parts.push('No messages in this selection.');
return `${parts.join('\n\n')}\n`;
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/export-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ describe('sessionExportMarkdown', () => {
'',
'It used `anthropic/claude-test`.',
'',
'## Continue elsewhere',
'',
'This file is portable context, not a restorable Pi session archive.',
'',
'- Same folder (`/repo/app`): open that root in Pidex, go to Sessions, select this session, and choose Resume. Choose Resume in new fork when continuing from an earlier entry.',
'- New folder: open the destination folder as a root in Pidex, start a new session there, and share this file as context for the first message. Attach it or paste its contents.',
'- Saved history stays with the original folder, so Resume will not find this session under a new folder.',
'',
'## You',
'',
'please fix it',
Expand Down Expand Up @@ -122,6 +130,34 @@ describe('sessionExportMarkdown', () => {
expect(markdown).toContain('\n````\nbefore\n```\ncode\n```\nafter\n````');
});

it('guides a reader to resume or hand off in a new folder', () => {
const markdown = sessionExportMarkdown({
title: 'T',
cwd: '/repo/app',
model: '',
exportedAt,
entries: [{ key: 'u1', kind: 'user', text: 'hi' }],
});
expect(markdown).toContain('## Continue elsewhere');
expect(markdown).toContain('not a restorable Pi session archive');
expect(markdown).toContain(
'Saved history stays with the original folder',
);
expect(markdown).toContain('start a new session there');
});

it('keeps the handoff generic when the folder is unknown', () => {
const markdown = sessionExportMarkdown({
title: 'T',
cwd: ' ',
model: '',
exportedAt,
entries: [{ key: 'u1', kind: 'user', text: 'hi' }],
});
expect(markdown).toContain('open the original root in Pidex');
expect(markdown).not.toContain('Same folder (`');
});

it('handles an empty selection and a blank title', () => {
const markdown = sessionExportMarkdown({
title: ' ',
Expand All @@ -134,6 +170,7 @@ describe('sessionExportMarkdown', () => {
expect(markdown).toContain('No messages in this selection.');
expect(markdown).not.toContain('It ran in');
expect(markdown).not.toContain('It used');
expect(markdown).not.toContain('Continue elsewhere');
});
});

Expand Down
Loading