fix pi cwd resolution and super admin home dir for all pi endpoints

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 20:31:35 +00:00
co-authored by Claude Opus 4.6
parent 4c2e40a46b
commit 25e8aaaea6
5 changed files with 48 additions and 55 deletions
+13 -13
View File
@@ -4,7 +4,7 @@ import * as storage from './storage';
import { readLocalProviders } from '../server-settings/pi-mono';
import { readSttConfig } from '../server-settings/stt';
import { listPiModels } from './list-models';
import { getHomeDir } from '../../data-path';
import { getHomeDirForRole } from '../../data-path';
import { resolveBaseCwd } from './websocket';
import { logger } from './logger';
@@ -50,8 +50,8 @@ piRestRouter.post('/pi/sessions', async (ctx: Context) => {
}
const body = await ctx.req.json().catch(() => ({}));
const userHome = getHomeDir(user.email);
const filterCwd = body.cwd ? resolveBaseCwd(user.email, body.cwdRoot, body.cwd) : null;
const userHome = getHomeDirForRole(user.email, user.role);
const filterCwd = body.cwd ? resolveBaseCwd(user.email, user.role, body.cwd) : null;
const contextFilter = body.context
? { context: body.context as string, contextId: body.contextId as string | undefined }
: undefined;
@@ -83,7 +83,7 @@ piRestRouter.get('/pi/sessions/:sessionId', async (ctx: Context) => {
return ctx.json({ error: 'Session ID required' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
// Try loading from root first
@@ -150,7 +150,7 @@ piRestRouter.patch('/pi/sessions/:sessionId', async (ctx: Context) => {
return ctx.json({ error: 'Title is required and must be a string' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
// Find the session (root or in group)
@@ -207,7 +207,7 @@ piRestRouter.delete('/pi/sessions/:sessionId', async (ctx: Context) => {
return ctx.json({ error: 'Session ID required' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
// Find the session (root or in group)
@@ -266,7 +266,7 @@ piRestRouter.delete('/pi/sessions', async (ctx: Context) => {
const contextFilter = body.context
? { context: body.context as string, contextId: body.contextId as string | undefined }
: undefined;
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
const allSessions = await storage.listUserSessions(userHome, contextFilter);
@@ -311,7 +311,7 @@ piRestRouter.get('/pi/sessions/search', async (ctx: Context) => {
return ctx.json({ error: 'Query parameter required' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
const results = await storage.searchSessions(userHome, query);
@@ -342,7 +342,7 @@ piRestRouter.post('/pi/groups', async (ctx: Context) => {
return ctx.json({ error: 'Slug is required and must be a string' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
// Check if group already exists
@@ -407,7 +407,7 @@ piRestRouter.get('/pi/groups', async (ctx: Context) => {
return ctx.json({ error: 'Unauthorized' }, 401);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
const groups = await storage.listGroups(userHome);
@@ -447,7 +447,7 @@ piRestRouter.patch('/pi/groups/:groupSlug', async (ctx: Context) => {
return ctx.json({ error: 'No valid updates provided' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
const updatedGroup = await storage.updateGroupMeta(userHome, groupSlug, updates);
@@ -476,7 +476,7 @@ piRestRouter.delete('/pi/groups/:groupSlug', async (ctx: Context) => {
return ctx.json({ error: 'Group slug required' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
await storage.deleteGroup(userHome, groupSlug);
@@ -509,7 +509,7 @@ piRestRouter.post('/pi/sessions/:sessionId/move', async (ctx: Context) => {
return ctx.json({ error: 'groupSlug must be a string or null' }, 400);
}
const userHome = getHomeDir(user.email);
const userHome = getHomeDirForRole(user.email, user.role);
try {
// Find the session in root or any group