fix: remove provisional workspace when launch is canceled with no changes
When `ctask new` launched the agent or shell and the child exited without touching any files (e.g. the user canceled at Claude Code's trust prompt), the workspace was left behind as empty clutter. Now, if the invocation just created the workspace and the manifest diff is empty (zero added, modified, deleted), the workspace directory is removed and finalize is skipped. resume/open/last are unaffected (NewlyCreated defaults to false), and --no-launch is unaffected (session.Run is never called). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,12 @@ type LaunchOpts struct {
|
||||
// stale-workspace warning (Layer 3). It does NOT disable the metadata
|
||||
// write lock or the session summary. Used for scripted/automated runs.
|
||||
Force bool
|
||||
|
||||
// NewlyCreated signals that this invocation just created WsDir (via
|
||||
// `ctask new`). When true and the session's manifest diff is empty, the
|
||||
// workspace is treated as provisional and removed on exit — see
|
||||
// handleProvisional. Set to false by resume/open/last.
|
||||
NewlyCreated bool
|
||||
}
|
||||
|
||||
// manifestStartPath returns the path to the start manifest file.
|
||||
@@ -146,6 +152,15 @@ func Run(opts LaunchOpts) error {
|
||||
hb.Stop()
|
||||
}
|
||||
|
||||
// ---- Provisional-workspace cleanup ----
|
||||
// If `ctask new` launched this session and the child exited without
|
||||
// changing any files, remove the workspace entirely and skip finalize.
|
||||
// Nothing to log, nothing to summarize, and the .ctask state files die
|
||||
// with the directory.
|
||||
if handleProvisional(opts, startManifest) {
|
||||
return childErr
|
||||
}
|
||||
|
||||
// ---- Post-session: manifest + summary + cleanup ----
|
||||
endTime := time.Now().UTC().Truncate(time.Second)
|
||||
if startManifest != nil {
|
||||
|
||||
Reference in New Issue
Block a user