fix: list and open sessions across project directories

Sessions outside the server's launch directory were invisible and returned
404 on open, leaving the model picker empty. List without the SDK's
process-cwd filter and normalize working directories at the API boundary and
when reading stored session data, tolerating separator/normalization
differences (including Windows backslash vs forward slash). Requires Pi
coding agent SDK 0.78.0 or newer.
This commit is contained in:
Federico Jaramillo Martinez
2026-06-13 11:40:47 +02:00
parent 38cf334c40
commit c0d12222a2
14 changed files with 2342 additions and 2261 deletions
+9 -4
View File
@@ -1,5 +1,6 @@
import type { FastifyInstance } from "fastify";
import type { RawData } from "ws";
import { normalizeRequestCwd } from "../workingDirectory.js";
import type { TerminalCommandRun, TerminalCommandRunFilter, TerminalCommandRunStatus } from "../../shared/apiTypes.js";
import type { RunTerminalCommandOptions, TerminalInfo } from "./terminalService.js";
import { parseTerminalSize } from "./terminalSize.js";
@@ -22,12 +23,16 @@ export interface TerminalRouteService {
export function registerTerminalRoutes(app: FastifyInstance, terminals: TerminalRouteService, prefix = ""): void {
app.get<{ Querystring: { cwd?: string } }>(`${prefix}/terminals`, (request, reply) => {
if (request.query.cwd === undefined || request.query.cwd === "") return reply.code(400).send({ error: "cwd query parameter is required" });
return terminals.list(request.query.cwd);
try {
return terminals.list(normalizeRequestCwd(request.query.cwd));
} catch (error) {
return reply.code(400).send({ error: error instanceof Error ? error.message : String(error) });
}
});
app.post<{ Body: { cwd: string; name?: string; cols?: number; rows?: number } }>(`${prefix}/terminals`, (request, reply) => {
try {
return terminals.create(request.body);
return terminals.create({ ...request.body, cwd: normalizeRequestCwd(request.body.cwd) });
} catch (error) {
return reply.code(400).send({ error: error instanceof Error ? error.message : String(error) });
}
@@ -36,7 +41,7 @@ export function registerTerminalRoutes(app: FastifyInstance, terminals: Terminal
app.delete<{ Querystring: { cwd?: string } }>(`${prefix}/terminals`, (request, reply) => {
if (request.query.cwd === undefined || request.query.cwd === "") return reply.code(400).send({ error: "cwd query parameter is required" });
try {
terminals.closeForCwd(request.query.cwd);
terminals.closeForCwd(normalizeRequestCwd(request.query.cwd));
return { closed: true };
} catch (error) {
return reply.code(400).send({ error: error instanceof Error ? error.message : String(error) });
@@ -45,7 +50,7 @@ export function registerTerminalRoutes(app: FastifyInstance, terminals: Terminal
app.post<{ Body: RunTerminalCommandOptions }>(`${prefix}/terminal-command-runs`, (request, reply) => {
try {
return terminals.runCommand(request.body);
return terminals.runCommand({ ...request.body, cwd: normalizeRequestCwd(request.body.cwd) });
} catch (error) {
return reply.code(400).send({ error: error instanceof Error ? error.message : String(error) });
}