Skip to content

feat(project): add DELETE /project/:id endpoint (#25004)#25009

Open
georgernstgraf wants to merge 13 commits intoanomalyco:devfrom
georgernstgraf:feat/issue-25004-delete-project-endpoint
Open

feat(project): add DELETE /project/:id endpoint (#25004)#25009
georgernstgraf wants to merge 13 commits intoanomalyco:devfrom
georgernstgraf:feat/issue-25004-delete-project-endpoint

Conversation

@georgernstgraf
Copy link
Copy Markdown

@georgernstgraf georgernstgraf commented Apr 29, 2026

Issue for this PR

Closes #25004

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a DELETE /project/:projectID endpoint to remove projects and all associated data via cascading foreign keys. Currently, projects can be listed, updated, and created — but never deleted. This leaves stale entries in the database when directories are moved or removed.

Changes:

  • Project.remove(id) — new Effect service method that deletes a project row and returns the count of cascade-deleted sessions
  • DELETE /project/:projectID — Hono route with OpenAPI annotations (project.delete)
  • DELETE /project/:projectID — HttpApi endpoint for SDK generation
  • Tests — 3 service-level tests + 1 route integration test

The session table already has ON DELETE CASCADE on project_id, so deleting a project row automatically removes all sessions, messages, parts, todos, and session entries.

Related issues: #21554 (stale workspace entries), #8083 (manage stored data), #16101 (session lifecycle management).

How did you verify your code works?

bun test test/project/project.test.ts          → 35 pass, 0 fail
bun test test/server/httpapi-instance.test.ts   → 6 pass, 0 fail
turbo typecheck                                 → 13 successful

Screenshots / recordings

N/A — This is not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings April 29, 2026 21:08
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for deleting projects via a new DELETE /project/:projectID endpoint, backed by a new Project.remove(id) service method, and exposed through both the Hono instance routes and the experimental HttpApi surface (for SDK generation). This is intended to let users remove stale projects and rely on DB-level cascading deletes to clean up associated sessions and related data.

Changes:

  • Added Project.remove(id) Effect service method returning { deleted, sessionsRemoved }.
  • Added DELETE /project/:projectID route in Hono with OpenAPI metadata (project.delete).
  • Added matching HttpApi endpoint + handler (project.delete) and tests covering service + route behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/opencode/src/project/project.ts Adds remove() implementation and wires it into Project.Service.
packages/opencode/src/server/routes/instance/project.ts Adds Hono DELETE /project/:projectID route + OpenAPI schema.
packages/opencode/src/server/routes/instance/httpapi/project.ts Adds HttpApi delete endpoint and handler mapping to Project.remove.
packages/opencode/test/project/project.test.ts Adds service-level tests for Project.remove.
packages/opencode/test/server/httpapi-instance.test.ts Adds route integration test exercising delete via the Hono bridge.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +469 to +480
const existing = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
if (!existing) throw new Error(`Project not found: ${id}`)
const sessionsRow = yield* db((d) =>
d
.select({ count: sql<number>`count(*)` })
.from(SessionTable)
.where(eq(SessionTable.project_id, id))
.get(),
)
const sessionsRemoved = sessionsRow?.count ?? 0
yield* db((d) => d.delete(ProjectTable).where(eq(ProjectTable.id, id)).run())
return { deleted: true, sessionsRemoved }
const remove_ = Effect.fn("ProjectHttpApi.remove")(function* (ctx: {
params: { projectID: ProjectID }
}) {
return yield* svc.remove(ctx.params.projectID)
Comment on lines +144 to +153
await using tmp = await tmpdir({ config: { formatter: false, lsp: false } })

const current = await app().request("/project/current", { headers: { "x-opencode-directory": tmp.path } })
expect(current.status).toBe(200)
const project = (await current.json()) as { id: string }

const response = await app().request(`/project/${project.id}`, {
method: "DELETE",
headers: { "x-opencode-directory": tmp.path },
})
jsonRequest("ProjectRoutes.delete", c, function* () {
const projectID = c.req.valid("param").projectID
const svc = yield* Project.Service
return yield* svc.remove(projectID)
Comment on lines +468 to +471
const remove = Effect.fn("Project.remove")(function* (id: ProjectID) {
const existing = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get())
if (!existing) throw new Error(`Project not found: ${id}`)
const sessionsRow = yield* db((d) =>
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add DELETE /project/:id endpoint to remove stale projects

2 participants