feat: foundation for subagent trajectories (Stage 1)

This commit is contained in:
Aishanee Shah
2026-05-14 16:39:47 +00:00
parent eadc35c32a
commit e7891bbf53
2 changed files with 13 additions and 9 deletions

View File

@@ -195,7 +195,7 @@ describe('chatCommand', () => {
result = await saveCommand?.action?.(mockContext, tag);
expect(mockSaveCheckpoint).toHaveBeenCalledWith(
{
history: expect.any(Array),
version: '2.0',
authType: AuthType.LOGIN_WITH_GOOGLE,
trajectories: {},
messages: [],
@@ -242,7 +242,7 @@ describe('chatCommand', () => {
expect(mockCheckpointExists).not.toHaveBeenCalled(); // Should skip existence check
expect(mockSaveCheckpoint).toHaveBeenCalledWith(
{
history,
version: '2.0',
authType: AuthType.LOGIN_WITH_GOOGLE,
trajectories: {},
messages: [],

View File

@@ -57,10 +57,11 @@ export function serializeHistoryToMarkdown(
*/
export interface ExportHistoryOptions {
/**
* Optional full message records which contain metadata like agentId for tool calls,
* Full message records which contain metadata like agentId for tool calls,
* providing the link between history and trajectories.
* This is the primary source of truth.
*/
messages?: MessageRecord[];
messages: MessageRecord[];
/** The file path to export to. */
filePath: string;
/** Optional subagent trajectories to include. */
@@ -81,18 +82,21 @@ export async function exportHistoryToFile(
const {
messages,
filePath,
trajectories: _trajectories, // Collected but not yet included in Stage 2 JSON output
trajectories,
history: providedHistory,
} = options;
const extension = path.extname(filePath).toLowerCase();
let content: string;
if (extension === '.json') {
// Stage 1 & 2: Maintain legacy behavior - only export the raw history array.
// Trajectories and messages are collected but not yet included in Stage 2 JSON output.
content = JSON.stringify(providedHistory ?? [], null, 2);
// Stage 3: Pivot to the new format - export messages and trajectories as an object.
content = JSON.stringify(
{ version: '2.0', messages, trajectories },
null,
2,
);
} else if (extension === '.md') {
const history = providedHistory ?? reconstructHistory(messages ?? []);
const history = providedHistory ?? reconstructHistory(messages);
content = serializeHistoryToMarkdown(history);
} else {
throw new Error(