Repository navigation
feat(projects): delete a project's sessions - #27
Merged
Merged
Conversation
added 8 commits
October 4, 2026 16:46
Adds POST /api/projects/delete plus the sidebar's type-to-confirm dialog. Scope: sessions data only.
F1: refuse any alive wrapper, not only a running one. F2: group against the scanner's non-realpath sessions dir; realpath both sides of the containment check. F10: count a nested child only once its carrying tree is gone.
F3: name leftovers and keep the dialog open; the partial key lives. F5: full project path in the dialog. F6: onSessionDeleted for every deleted session. F7: synchronous guard against a double submit. F8: symlink refusal gets its own copy. F4: mirror the CSS block into the demo. F12: demo 405.
Capture the project when the dialog opens: the success refresh drops it from the list, which unmounted the dialog mid-report. Hide the counts once the delete has run, and freeze the field.
R1: 409 copy says the session is still open (or running). R2: focus the Close button when the partial report appears. R3: note why the captured session ids are frozen. R4: annotate nestedChildren as SessionInfo[].
dreadster3
force-pushed
the
main
branch
4 times, most recently
from
October 5, 2026 02:02
613668d to
5149664
Compare
This was referenced Oct 5, 2026
Merged
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds destructive project deletion to pi web: a "Delete project…" action in the sidebar's project dropdown that removes all of pi's session data for a project — every session transcript, nested pi-subagent transcripts and artifacts, across all of the project's per-cwd session directories (including linked git-worktree cwds), and then the now-empty directories themselves — behind a type-to-confirm dialog.
Your actual code directory is never touched, and neither is anything outside
~/.pi/agent/sessions/(see "What is deleted" below). Nothing merges, tags, or publishes on your behalf in this PR — the action only affects pi's own session store.What "a project" means here
pi-web has no stored project entity: a project is the derived grouping of sessions whose
cwd/projectRootresolves to the same key (lib/project-groups.ts). A git repo with linked worktrees collapses into one project (itsprojectRootis the main checkout), and its sessions may live in several encoded directories under~/.pi/agent/sessions/. Deletion therefore enumerates the project's directories from the real session paths — it does not encode anything from the request.What is deleted / explicitly not
Deleted: every
.jsonlof the project's sessions in its per-cwd directories, each session's pi-subagents child tree, itssubagent-artifacts/, and the per-cwd project directory itself once empty.Never touched: the user's code directory,
<project>/.pi/**(project-owned config),trust.jsondecisions, and the hash-keyed global stores (~/.pi/agent/{missions,todos,pi-subagents}— their project-hash key is not exported by the agent SDK, so they are out of scope by design).Safety model
POST /api/projects/delete { projectKey }— request guards in the established order: same-host/origin (403 request-denied), JSON content type (415 content-type), body shape (400), and allowed-roots ancestry for every project cwd.projectKeyis only ever compared againstworkspaceKeyOf(session); it is never joined into a filesystem path. Every removed path derives from enumerated session files and islstat+realpathcontainment-verified inside the sessions root before anything is removed — so symlinked project dirs are refused whole (409 symlink), and no traversal through the request can move the deletion set.isAlive()), the route refuses with409 session-busyand names the sessions; nothing is deleted.failedPathsso a partial result is never shown as a full success.clearLastOpenand refresh.Dialog UX
Red warning listing exactly what is removed — session/dir counts (including nested subagents and worktree cwds) and the project's full path (so two checkouts both named
apiare distinguishable) — an input that must exactly match the project's display name before Delete enables, Esc to cancel, a specific message when a live session blocks deletion, and a partial-deletion report that stays on screen when any path survived.Notable decisions
POST /{api}/projects/deleterather thanDELETE /api/projects: a project isn't a stored entity (the body is a derived-grouping key), and the mutation keeps the guard chain and error shapes of the other mutating routes. Noteapp/api/worktrees/route.tsdoes already carry a JSON body onDELETE; the shape here simply follows theproject-trustprecedent and the key/body semantics.deletedSessionscounts nested pi-subagent children (they are genuinely removed with their carrying tree), and only counts a child once its tree's removal actually succeeded.Testing
route.test.mjs: guard order, 404 unknown/traversal keys, busy refusal naming titles incl. an idle-open wrapper, symlink refusal of a project dir + symlinked session file whose target survives, symlinked agent directory (regression-pinned), stray-file/partial reporting, read-only failure isolation, cache invalidation;ProjectDeleteDialog.test.mjs: counts, exact-match rule, path line, refusal copy, partial focus, Esc/portal wiring).tsc --noEmitclean for app and demo; lint clean for both; i18n parity (same keys + placeholders acrossen,zh-CN,zh-TW); demo build passes.demo/mock/, byte-parity locale copies, dialog CSS mirrored, anddemo/lib/stacked-dialog.tsadded byte-identical to the app's.Residual notes
piTUI) writing the same transcript concurrently remains undetectable — the pre-existing two-writer caveat of the sessions file format, now also applying to bulk unlink.