Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(session): preserve saved values in YAML exports

Rudy Celeklid1bce896d651
diff --git a/v3/@claude-flow/cli/__tests__/session-yaml-export.test.ts b/v3/@claude-flow/cli/__tests__/session-yaml-export.test.ts
new file mode 100644
index 0000000000..37a6a52fd0
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/session-yaml-export.test.ts
@@ -0,0 +1,82 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { parse } from 'yaml';
+import { sessionCommand } from '../src/commands/session.js';
+import { callMCPTool } from '../src/mcp-client.js';
+
+interface SavedSession { sessionId: string }
+
+describe('session YAML export through the public command', () => {
+ let root: string;
+ let previous: string;
+
+ beforeEach(() => {
+ root = mkdtempSync(join(tmpdir(), 'ruflo-session-yaml-'));
+ previous = process.cwd();
+ process.chdir(root);
+ });
+
+ afterEach(() => {
+ process.chdir(previous);
+ rmSync(root, { recursive: true, force: true });
+ });
+
+ it.each([
+ ['true', 'plain description'],
+ ['00123', 'first line\nsecond line # comment'],
+ ['null', 'path: "quoted" and \\backslash'],
+ ['normal', 'retain # this text'],
+ ])('preserves the saved strings for %s', async (name, description) => {
+ const saved = await callMCPTool<SavedSession>('session_save', {
+ name, description, includeMemory: false, includeTasks: false, includeAgents: false,
+ });
+ const snapshot = await callMCPTool<{ data: unknown }>('session_export', {
+ sessionId: saved.sessionId,
+ });
+ const action = sessionCommand.subcommands?.find(command => command.name === 'export')?.action;
+ if (!action) throw new Error('session export action is unavailable');
+ const result = await action({
+ args: [saved.sessionId],
+ flags: { _: [], format: 'yaml', output: 'export.yaml', 'include-memory': false },
+ cwd: root, interactive: false,
+ });
+ expect(result?.success).toBe(true);
+ expect(parse(readFileSync(join(root, 'export.yaml'), 'utf8'))).toEqual(snapshot.data);
+ });
+
+ it('retains the JSON export format', async () => {
+ const saved = await callMCPTool<SavedSession>('session_save', {
+ name: 'true', includeMemory: false, includeTasks: false, includeAgents: false,
+ });
+ const snapshot = await callMCPTool<{ data: unknown }>('session_export', { sessionId: saved.sessionId });
+ const action = sessionCommand.subcommands?.find(command => command.name === 'export')?.action;
+ if (!action) throw new Error('session export action is unavailable');
+ const result = await action({
+ args: [saved.sessionId], flags: { _: [], format: 'json', output: 'export.json', 'include-memory': false },
+ cwd: root, interactive: false,
+ });
+ expect(result?.success).toBe(true);
+ expect(JSON.parse(readFileSync(join(root, 'export.json'), 'utf8'))).toEqual(snapshot.data);
+ });
+
+ it('preserves nested task arrays and empty collections', async () => {
+ const tasks = { tasks: { example: { description: 'quoted: "value"',
+ tags: ['true', '00123'], history: [{ status: 'queued', notes: [] }], metadata: {} } } };
+ mkdirSync(join(root, '.claude-flow', 'tasks'), { recursive: true });
+ writeFileSync(join(root, '.claude-flow', 'tasks', 'store.json'), JSON.stringify(tasks));
+ const saved = await callMCPTool<SavedSession>('session_save', {
+ name: 'nested', includeMemory: false, includeTasks: true, includeAgents: false,
+ });
+ const snapshot = await callMCPTool<{ data: unknown }>('session_export', { sessionId: saved.sessionId });
+ const action = sessionCommand.subcommands?.find(command => command.name === 'export')?.action;
+ if (!action) throw new Error('session export action is unavailable');
+ const result = await action({
+ args: [saved.sessionId], flags: { _: [], format: 'yaml', output: 'export.yaml', 'include-memory': false },
+ cwd: root, interactive: false,
+ });
+ expect(result?.success).toBe(true);
+ expect(parse(readFileSync(join(root, 'export.yaml'), 'utf8'))).toEqual(snapshot.data);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/session.ts b/v3/@claude-flow/cli/src/commands/session.ts
index e54d291975..4ba0d88530 100644
--- a/v3/@claude-flow/cli/src/commands/session.ts
+++ b/v3/@claude-flow/cli/src/commands/session.ts
@@ -9,6 +9,7 @@ import { confirm, input, select } from '../prompt.js';
import { callMCPTool, MCPClientError } from '../mcp-client.js';
import * as fs from 'fs';
import * as path from 'path';
+import { stringify as stringifyYaml } from 'yaml';
// Format date for display
function formatDate(dateStr: string): string {
@@ -678,7 +679,7 @@ const exportCommand: Command = {
// Format output
let content: string;
if (exportFormat === 'yaml') {
- content = toSimpleYaml(result.data);
+ content = stringifyYaml(result.data);
} else {
content = JSON.stringify(result.data, null, 2);
}
@@ -944,37 +945,6 @@ function formatDuration(ms: number): string {
return `${seconds}s`;
}
-function toSimpleYaml(obj: unknown, indent: number = 0): string {
- // Simple YAML serializer (for basic types)
- if (obj === null) return 'null';
- if (typeof obj === 'boolean') return String(obj);
- if (typeof obj === 'number') return String(obj);
- if (typeof obj === 'string') return obj.includes(':') ? `"${obj}"` : obj;
-
- const spaces = ' '.repeat(indent);
- let result = '';
-
- if (Array.isArray(obj)) {
- for (const item of obj) {
- result += `${spaces}- ${toSimpleYaml(item, indent + 1).trim()}\n`;
- }
- return result;
- }
-
- if (typeof obj === 'object') {
- for (const [key, value] of Object.entries(obj)) {
- if (typeof value === 'object' && value !== null) {
- result += `${spaces}${key}:\n${toSimpleYaml(value, indent + 1)}`;
- } else {
- result += `${spaces}${key}: ${toSimpleYaml(value, indent)}\n`;
- }
- }
- return result;
- }
-
- return String(obj);
-}
-
// Main session command
export const sessionCommand: Command = {
name: 'session',