diff --git a/.changeset/sixty-wings-wonder.md b/.changeset/sixty-wings-wonder.md new file mode 100644 index 0000000..2fd1d89 --- /dev/null +++ b/.changeset/sixty-wings-wonder.md @@ -0,0 +1,5 @@ +--- +"@cephalization/phoenix-insight": patch +--- + +fix: Correct statistics in \_context.md diff --git a/packages/cli/src/snapshot/context.ts b/packages/cli/src/snapshot/context.ts index aa87df1..922735d 100644 --- a/packages/cli/src/snapshot/context.ts +++ b/packages/cli/src/snapshot/context.ts @@ -273,7 +273,9 @@ function buildWhatsHereSection( // Snapshot metadata lines.push( - `- **Snapshot**: Created ${formatRelativeTime(metadata.snapshotTime)} from ${metadata.phoenixUrl}` + `- **Snapshot**: Created ${formatRelativeTime( + metadata.snapshotTime + )} from ${metadata.phoenixUrl}` ); lines.push(""); @@ -328,9 +330,10 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ }; // Collect project stats + // Use relative paths since cwd is the phoenix directory in both modes try { const projectsExec = await mode.exec( - "cat /phoenix/projects/index.jsonl 2>/dev/null || true" + "cat projects/index.jsonl 2>/dev/null || true" ); if (projectsExec.stdout) { const projectLines = projectsExec.stdout @@ -348,7 +351,7 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ // Get span count for this project const spansMetaExec = await mode.exec( - `cat /phoenix/projects/${project.name}/spans/metadata.json 2>/dev/null || echo "{}"` + `cat projects/${project.name}/spans/metadata.json 2>/dev/null || echo "{}"` ); if (spansMetaExec.stdout) { try { @@ -372,7 +375,7 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ // Collect dataset stats try { const datasetsExec = await mode.exec( - "cat /phoenix/datasets/index.jsonl 2>/dev/null || true" + "cat datasets/index.jsonl 2>/dev/null || true" ); if (datasetsExec.stdout) { const datasetLines = datasetsExec.stdout @@ -386,7 +389,7 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ // Get example count const examplesExec = await mode.exec( - `wc -l < /phoenix/datasets/${dataset.name}/examples.jsonl 2>/dev/null || echo "0"` + `wc -l < datasets/${dataset.name}/examples.jsonl 2>/dev/null || echo "0"` ); const exampleCount = parseInt(examplesExec.stdout.trim()) || 0; @@ -407,7 +410,7 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ // Collect experiment stats try { const experimentsExec = await mode.exec( - "cat /phoenix/experiments/index.jsonl 2>/dev/null || true" + "cat experiments/index.jsonl 2>/dev/null || true" ); if (experimentsExec.stdout) { const experimentLines = experimentsExec.stdout @@ -444,7 +447,7 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ // Collect prompt stats try { const promptsExec = await mode.exec( - "cat /phoenix/prompts/index.jsonl 2>/dev/null || true" + "cat prompts/index.jsonl 2>/dev/null || true" ); if (promptsExec.stdout) { const promptLines = promptsExec.stdout @@ -458,7 +461,7 @@ async function collectSnapshotStats(mode: ExecutionMode): Promise<{ // Count versions const versionsExec = await mode.exec( - `wc -l < /phoenix/prompts/${prompt.name}/versions/index.jsonl 2>/dev/null || echo "0"` + `wc -l < prompts/${prompt.name}/versions/index.jsonl 2>/dev/null || echo "0"` ); const versionCount = parseInt(versionsExec.stdout.trim()) || 0; @@ -533,7 +536,10 @@ function getRecentActivity(stats: { for (const exp of recentExperiments.slice(0, 2)) { const timeAgo = formatRelativeTime(new Date(exp.updatedAt!)); activities.push( - `${exp.projectName || exp.datasetName}: experiment "${exp.id.slice(0, 8)}..." ${exp.status} ${timeAgo}` + `${exp.projectName || exp.datasetName}: experiment "${exp.id.slice( + 0, + 8 + )}..." ${exp.status} ${timeAgo}` ); } diff --git a/packages/cli/test/snapshot/context.test.ts b/packages/cli/test/snapshot/context.test.ts index b2c1bda..e8716e8 100644 --- a/packages/cli/test/snapshot/context.test.ts +++ b/packages/cli/test/snapshot/context.test.ts @@ -15,7 +15,8 @@ describe("generateContext", () => { }), exec: vi.fn(async (command: string) => { // Mock responses for different commands - if (command.includes("cat /phoenix/projects/index.jsonl")) { + // Use relative paths since cwd is the phoenix directory + if (command.includes("cat projects/index.jsonl")) { return { stdout: JSON.stringify({ @@ -33,9 +34,7 @@ describe("generateContext", () => { } if ( - command.includes( - "cat /phoenix/projects/chatbot-prod/spans/metadata.json" - ) + command.includes("cat projects/chatbot-prod/spans/metadata.json") ) { return { stdout: JSON.stringify({ spanCount: 2341 }), @@ -45,9 +44,7 @@ describe("generateContext", () => { } if ( - command.includes( - "cat /phoenix/projects/rag-experiment/spans/metadata.json" - ) + command.includes("cat projects/rag-experiment/spans/metadata.json") ) { return { stdout: JSON.stringify({ spanCount: 892 }), @@ -56,7 +53,7 @@ describe("generateContext", () => { }; } - if (command.includes("cat /phoenix/datasets/index.jsonl")) { + if (command.includes("cat datasets/index.jsonl")) { return { stdout: JSON.stringify({ @@ -75,21 +72,19 @@ describe("generateContext", () => { if ( command.includes( - "wc -l < /phoenix/datasets/customer-queries/examples.jsonl" + "wc -l < datasets/customer-queries/examples.jsonl" ) ) { return { stdout: "150", stderr: "", exitCode: 0 }; } if ( - command.includes( - "wc -l < /phoenix/datasets/test-cases/examples.jsonl" - ) + command.includes("wc -l < datasets/test-cases/examples.jsonl") ) { return { stdout: "75", stderr: "", exitCode: 0 }; } - if (command.includes("cat /phoenix/experiments/index.jsonl")) { + if (command.includes("cat experiments/index.jsonl")) { return { stdout: JSON.stringify({ id: "exp-123", @@ -107,7 +102,7 @@ describe("generateContext", () => { }; } - if (command.includes("cat /phoenix/prompts/index.jsonl")) { + if (command.includes("cat prompts/index.jsonl")) { return { stdout: JSON.stringify({ @@ -126,16 +121,14 @@ describe("generateContext", () => { if ( command.includes( - "wc -l < /phoenix/prompts/main-assistant/versions/index.jsonl" + "wc -l < prompts/main-assistant/versions/index.jsonl" ) ) { return { stdout: "5", stderr: "", exitCode: 0 }; } if ( - command.includes( - "wc -l < /phoenix/prompts/summarizer/versions/index.jsonl" - ) + command.includes("wc -l < prompts/summarizer/versions/index.jsonl") ) { return { stdout: "3", stderr: "", exitCode: 0 }; } @@ -347,7 +340,7 @@ describe("generateContext", () => { recentTime.setHours(recentTime.getHours() - 1); mockMode.exec = vi.fn(async (command: string) => { - if (command.includes("cat /phoenix/experiments/index.jsonl")) { + if (command.includes("cat experiments/index.jsonl")) { return { stdout: JSON.stringify({ id: "exp-recent", @@ -386,7 +379,7 @@ describe("generateContext", () => { oldTime.setDate(oldTime.getDate() - 2); mockMode.exec = vi.fn(async (command: string) => { - if (command.includes("cat /phoenix/experiments/index.jsonl")) { + if (command.includes("cat experiments/index.jsonl")) { return { stdout: JSON.stringify({ id: "exp-old", @@ -422,7 +415,7 @@ describe("generateContext", () => { describe("experiment status determination", () => { it("should correctly count experiments by status", async () => { mockMode.exec = vi.fn(async (command: string) => { - if (command.includes("cat /phoenix/experiments/index.jsonl")) { + if (command.includes("cat experiments/index.jsonl")) { return { stdout: // Completed experiment