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
5 changes: 5 additions & 0 deletions .changeset/sixty-wings-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cephalization/phoenix-insight": patch
---

fix: Correct statistics in \_context.md
24 changes: 15 additions & 9 deletions packages/cli/src/snapshot/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");

Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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}`
);
}

Expand Down
35 changes: 14 additions & 21 deletions packages/cli/test/snapshot/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 }),
Expand All @@ -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 }),
Expand All @@ -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({
Expand All @@ -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",
Expand All @@ -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({
Expand All @@ -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 };
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down