refactor: codebase audit cleanup — dead code, dedup, module splits
Multi-agent audit + aggressive cleanup across server/web/coder/booterm, delivered behind a DEFER discipline so none of the in-flight files were touched. Removes dead code/deps/columns, dedups server + coder helpers, and splits the oversized modules (tools.ts, opencode-server.ts, sentinel-summaries, turn.ts, TerminalPane.tsx) behind stable contracts. Adds 78 parity/unit tests (server 587, coder 323); fixes two latent bugs (ChatPane queue keys, FileViewerOverlay blank-line parity). Intended tag: v2.7.12-audit-cleanup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,20 @@ export async function resolveProjectPath(
|
||||
return { real, name: basename(real) };
|
||||
}
|
||||
|
||||
async function selectProject(sql: Sql, id: string): Promise<Project | null> {
|
||||
const rows = await sql<Project[]>`
|
||||
SELECT id, name, path, added_at, last_session_id, status, gitea_remote,
|
||||
default_system_prompt, default_web_search_enabled
|
||||
FROM projects WHERE id = ${id}
|
||||
`;
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
async function selectProjectPath(sql: Sql, id: string): Promise<string | null> {
|
||||
const rows = await sql<{ path: string }[]>`SELECT path FROM projects WHERE id = ${id}`;
|
||||
return rows[0]?.path ?? null;
|
||||
}
|
||||
|
||||
export function registerProjectRoutes(
|
||||
app: FastifyInstance,
|
||||
sql: Sql,
|
||||
@@ -199,16 +213,12 @@ export function registerProjectRoutes(
|
||||
// v1.9: single-project fetch so the settings pane can refetch on
|
||||
// project_updated without pulling the whole project list.
|
||||
app.get<{ Params: { id: string } }>('/api/projects/:id', async (req, reply) => {
|
||||
const rows = await sql<Project[]>`
|
||||
SELECT id, name, path, added_at, last_session_id, status, gitea_remote,
|
||||
default_system_prompt, default_web_search_enabled
|
||||
FROM projects WHERE id = ${req.params.id}
|
||||
`;
|
||||
if (rows.length === 0) {
|
||||
const project = await selectProject(sql, req.params.id);
|
||||
if (!project) {
|
||||
reply.code(404);
|
||||
return { error: 'not found' };
|
||||
}
|
||||
return rows[0];
|
||||
return project;
|
||||
});
|
||||
|
||||
app.patch<{ Params: { id: string } }>('/api/projects/:id', async (req, reply) => {
|
||||
@@ -340,18 +350,14 @@ export function registerProjectRoutes(
|
||||
const { id } = req.params;
|
||||
const relPath = req.query.path ?? '.';
|
||||
|
||||
const rows = await sql<Project[]>`
|
||||
SELECT id, name, path, added_at, last_session_id, status, gitea_remote
|
||||
FROM projects WHERE id = ${id}
|
||||
`;
|
||||
if (rows.length === 0) {
|
||||
const projectPath = await selectProjectPath(sql, id);
|
||||
if (projectPath === null) {
|
||||
reply.code(404);
|
||||
return { error: 'not found' };
|
||||
}
|
||||
const project = rows[0]!;
|
||||
let projectRoot: string;
|
||||
try {
|
||||
projectRoot = await resolveProjectRoot(project.path);
|
||||
projectRoot = await resolveProjectRoot(projectPath);
|
||||
} catch (err) {
|
||||
if (err instanceof PathScopeError) {
|
||||
reply.code(404);
|
||||
@@ -385,18 +391,14 @@ export function registerProjectRoutes(
|
||||
return { error: 'path is required' };
|
||||
}
|
||||
|
||||
const rows = await sql<Project[]>`
|
||||
SELECT id, name, path, added_at, last_session_id, status, gitea_remote
|
||||
FROM projects WHERE id = ${id}
|
||||
`;
|
||||
if (rows.length === 0) {
|
||||
const projectPath = await selectProjectPath(sql, id);
|
||||
if (projectPath === null) {
|
||||
reply.code(404);
|
||||
return { error: 'not found' };
|
||||
}
|
||||
const project = rows[0]!;
|
||||
let projectRoot: string;
|
||||
try {
|
||||
projectRoot = await resolveProjectRoot(project.path);
|
||||
projectRoot = await resolveProjectRoot(projectPath);
|
||||
} catch (err) {
|
||||
if (err instanceof PathScopeError) {
|
||||
reply.code(404);
|
||||
@@ -431,18 +433,14 @@ export function registerProjectRoutes(
|
||||
'/api/projects/:id/git',
|
||||
async (req, reply) => {
|
||||
const { id } = req.params;
|
||||
const rows = await sql<Project[]>`
|
||||
SELECT id, name, path, added_at, last_session_id, status, gitea_remote
|
||||
FROM projects WHERE id = ${id}
|
||||
`;
|
||||
if (rows.length === 0) {
|
||||
const projectPath = await selectProjectPath(sql, id);
|
||||
if (projectPath === null) {
|
||||
reply.code(404);
|
||||
return { error: 'not found' };
|
||||
}
|
||||
const project = rows[0]!;
|
||||
let projectRoot: string;
|
||||
try {
|
||||
projectRoot = await resolveProjectRoot(project.path);
|
||||
projectRoot = await resolveProjectRoot(projectPath);
|
||||
} catch (err) {
|
||||
if (err instanceof PathScopeError) {
|
||||
reply.code(404);
|
||||
@@ -461,18 +459,14 @@ export function registerProjectRoutes(
|
||||
async (req, reply) => {
|
||||
const { id } = req.params;
|
||||
|
||||
const rows = await sql<Project[]>`
|
||||
SELECT id, name, path, added_at, last_session_id, status, gitea_remote
|
||||
FROM projects WHERE id = ${id}
|
||||
`;
|
||||
if (rows.length === 0) {
|
||||
const projectPath = await selectProjectPath(sql, id);
|
||||
if (projectPath === null) {
|
||||
reply.code(404);
|
||||
return { error: 'not found' };
|
||||
}
|
||||
const project = rows[0]!;
|
||||
let projectRoot: string;
|
||||
try {
|
||||
projectRoot = await resolveProjectRoot(project.path);
|
||||
projectRoot = await resolveProjectRoot(projectPath);
|
||||
} catch (err) {
|
||||
if (err instanceof PathScopeError) {
|
||||
reply.code(404);
|
||||
|
||||
Reference in New Issue
Block a user