fixed members login and permissions issues

This commit is contained in:
2026-02-23 00:57:34 +00:00
parent ed0debfeac
commit 97da2e2736
42 changed files with 574 additions and 113 deletions
+10 -6
View File
@@ -1,3 +1,4 @@
import { join, relative } from "path";
import type { Subprocess } from "bun";
import type { PiEvent, MessageCost } from "./types";
import { readApiKeys } from "../server-settings/pi-mono";
@@ -8,11 +9,10 @@ export type PiEventHandler = (event: PiEvent) => void;
type SandboxOptions = {
userId: number;
username: string;
homeDir: string;
};
const CONTAINER_HOME = '/home/officer';
const CONTAINER_PI_CONFIG = '/home/officer/.pi/agent';
export async function spawnPi(
cwd: string,
model: string,
@@ -25,21 +25,25 @@ export async function spawnPi(
const storedKeys = await readApiKeys();
const dockerPath = Bun.which('docker') ?? 'docker';
const containerId = `officer-terminal-${sandbox.userId}`;
const containerHome = `/home/${sandbox.username}`;
const containerPiConfig = `${containerHome}/.pi/agent`;
const piArgs = ['pi', '--mode', 'rpc', '--no-extensions', '--no-skills', '--no-prompt-templates', '--no-themes'];
if (model) piArgs.push('--model', model);
// Build env flags: Pi config dir + all stored API keys
const envFlags = [
'-e', `PI_CODING_AGENT_DIR=${CONTAINER_PI_CONFIG}`,
'-e', `HOME=${CONTAINER_HOME}`,
'-e', `PI_CODING_AGENT_DIR=${containerPiConfig}`,
'-e', `HOME=${containerHome}`,
];
for (const [key, value] of Object.entries(storedKeys)) {
if (value?.trim()) envFlags.push('-e', `${key}=${value.trim()}`);
}
const rel = relative(sandbox.homeDir, cwd);
const workdir = rel && !rel.startsWith('..') ? join(containerHome, rel) : containerHome;
proc = Bun.spawn([
dockerPath, 'exec', '-i',
'-w', CONTAINER_HOME,
'-w', workdir,
...envFlags,
containerId,
...piArgs,