# checkpoint resume: bare picker and non-TTY listing

`095936a`→[main](/content/gh/entireio/cli/commits/main/index.html)·

pfleidi·1w ago·2 files·+162 added/-2 removed

Bare invocation shows the newest 20 committed checkpoints: an interactive
picker on a terminal, a complete plain-text list (full IDs, timestamps,
branch, agent) otherwise, so agents can list and then resume by ID.

## Sessions

01KX1C7S64969W3NCJ3ZCK95CPView transcript

[?\
Implement Checkpoint Resume CommandClaude Code·1 step](/content/gh/entireio/cli/session/ba137a72-eaf9-443b-b868-49da78b39915#timeline-01KX1C7S64969W3NCJ3ZCK95CP/index.html)

## Changes

2

- cmd/entire/cli

- Mcheckpoint_resume.go+96/-2

- Mcheckpoint_resume_test.go+66

```
3 unmodified lines

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
190 unmodified lines

213
214
215
211
212
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

3 unmodified lines

"context"
	"errors"
	"fmt"
	"io"
	"regexp"
	"sort"

"github.com/entireio/cli/cmd/entire/cli/agent/external"
	"github.com/entireio/cli/cmd/entire/cli/checkpoint"
	"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
	"github.com/entireio/cli/cmd/entire/cli/interactive"
	"github.com/entireio/cli/cmd/entire/cli/logging"
	"github.com/entireio/cli/cmd/entire/cli/paths"
	"github.com/entireio/cli/cmd/entire/cli/trailers"

"charm.land/huh/v2"
	"github.com/spf13/cobra"

)

190 unmodified lines

return resumeSessionOnBranch(ctx, cmd, branch, cpID, force)
}

func runCheckpointResumePicker(_ context.Context, _ *cobra.Command, _ *explainCheckpointLookup, _ bool) error {
	return errors.New("pass a checkpoint ID, commit SHA, or branch (picker lands in the next commit)")
}
const checkpointResumePickerLimit = 20

func runCheckpointResumePicker(ctx context.Context, cmd *cobra.Command, lookup *explainCheckpointLookup, force bool) error {
	w := cmd.OutOrStdout()

entries := recentCheckpoints(lookup.committed, checkpointResumePickerLimit)
	if len(entries) == 0 {
		fmt.Fprintln(w, "No committed checkpoints found.")
		fmt.Fprintln(w, "Checkpoints are created when you commit during an agent session.")
		return nil
	}
	branchIndex := buildCheckpointBranchIndex(lookup.repo)

if !interactive.CanPromptInteractively() {
		printCheckpointResumeList(w, entries, branchIndex)
		return nil
	}

selected, ok, err := promptCheckpointSelection(ctx, entries, branchIndex)
	if err != nil || !ok {
		return err
	}
	return resumeResolvedCheckpoint(ctx, cmd, lookup, selected, force)
}

func recentCheckpoints(committed []checkpoint.CheckpointInfo, limit int) []checkpoint.CheckpointInfo {
	sorted := make([]checkpoint.CheckpointInfo, len(committed))
	copy(sorted, committed)
	sort.SliceStable(sorted, func(i, j int) bool {
		return sorted[i].CreatedAt.After(sorted[j].CreatedAt)
	})
	if len(sorted) > limit {
		sorted = sorted[:limit]
	}
	return sorted
}

func printCheckpointResumeList(w io.Writer, entries []checkpoint.CheckpointInfo, branchIndex map[string]string) {
	fmt.Fprintf(w, "Recent checkpoints (newest first, up to %d):\n\n", checkpointResumePickerLimit)
	for _, e := range entries {
		branch := branchIndex[e.CheckpointID.String()]
		if branch == "" {
			branch = "-"
		}
		fmt.Fprintf(w, "  %s  %s  %s  %s\n", e.CheckpointID, e.CreatedAt.Local().Format("2006-01-02 15:04"), branch, checkpointAgentLabel(e))
	}
	fmt.Fprintln(w, "\nResume one with: entire checkpoint resume <checkpoint-id>")
}

const checkpointPickerCancel = "cancel"

func promptCheckpointSelection(ctx context.Context, entries []checkpoint.CheckpointInfo, branchIndex map[string]string) (id.CheckpointID, bool, error) {
	options := make([]huh.Option[string], 0, len(entries)+1)
	for _, e := range entries {
		options = append(options, huh.NewOption(checkpointResumeOptionLabel(e, branchIndex), e.CheckpointID.String()))
	}
	options = append(options, huh.NewOption("Cancel", checkpointPickerCancel))

var choice string
	form := NewAccessibleForm(huh.NewGroup(
		huh.NewSelect[string]().
			Title("Resume which checkpoint?").
			Description("Checks out the checkpoint's branch (when one contains it) and restores the session log.").
			Options(options...).
			Value(&choice),
	))
	if err := form.RunWithContext(ctx); err != nil {
		if errors.Is(err, huh.ErrUserAborted) || errors.Is(err, context.Canceled) {
			return "", false, nil
		}
		return "", false, fmt.Errorf("failed to pick checkpoint: %w", err)
	}
	if choice == checkpointPickerCancel {
		return "", false, nil
	}
	return id.CheckpointID(choice), true, nil
}

func checkpointResumeOptionLabel(e checkpoint.CheckpointInfo, branchIndex map[string]string) string {
	branch := branchIndex[e.CheckpointID.String()]
	if branch == "" {
		branch = "no local branch"
	}
	return fmt.Sprintf("%s · %s · %s · %s", e.CheckpointID.DisplayShort(), branch, checkpointAgentLabel(e), timeAgo(e.CreatedAt))
}

func checkpointAgentLabel(e checkpoint.CheckpointInfo) string {
	if e.Agent == "" {
		return unknownAgentLabel
	}
	return string(e.Agent)
}

```

Mcmd/entire/cli/checkpoint_resume.go+96/-2

```
2 unmodified lines

3
4
5
6
7
8
9
10
11
12
13
14
15
16
156 unmodified lines

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

2 unmodified lines

import (
	"bytes"
	"context"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"testing"
	"time"

"github.com/entireio/cli/cmd/entire/cli/checkpoint"
	"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
	"github.com/spf13/cobra"
)

156 unmodified lines

t.Errorf("Execute() err = %v, want 'nothing matched'", err)
	}
}

func TestRecentCheckpoints_SortsNewestFirstAndCaps(t *testing.T) {
	t.Parallel()
	base := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
	var infos []checkpoint.CheckpointInfo
	for i := range 25 {
		infos = append(infos, checkpoint.CheckpointInfo{
			CheckpointID: id.MustCheckpointID(fmt.Sprintf("%012x", i)),
			CreatedAt:    base.Add(time.Duration(i) * time.Hour),
		})
	}
	got := recentCheckpoints(infos, 20)
	if len(got) != 20 {
			Fatalf("len = %d, want 20", len(got))
	}
	if !got[0].CreatedAt.After(got[19].CreatedAt) {
			t.Errorf("not sorted newest first: got[0]=%v got[19]=%v", got[0].CreatedAt, got[19].CreatedAt)
	}
	if got[0].CreatedAt != base.Add(24*time.Hour) {
			t.Errorf("newest = %v, want %v", got[0].CreatedAt, base.Add(24*time.Hour))
	}
}

// go test runs are non-interactive (CanPromptInteractively is false under
// testing.Testing()), so bare invocation exercises the non-TTY listing.
func TestCheckpointResumeBare_NonTTYListsCheckpoints(t *testing.T) {
	tmpDir := t.TempDir()
	t.Chdir(tmpDir)
	repo, _, _ := setupResumeTestRepo(t, tmpDir, false)
	cpOld := id.MustCheckpointID("aaa111bbb222")
	cpNew := id.MustCheckpointID("ccc333ddd444")
	writeCommittedResumeCheckpoint(t, repo, cpOld, "session-old", time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC))
	writeCommittedResumeCheckpoint(t, repo, cpNew, "session-new", time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC))

cmd, out := newCheckpointResumeTestCmd(t)
	cmd.SetArgs([]string{})
	if err := cmd.Execute(); err != nil {
			t.Fatalf("Execute() error = %v\noutput: %s", err, out.String())
	}
	output := out.String()
	for _, want := range []string{cpOld.String(), cpNew.String(), "entire checkpoint resume <checkpoint-id>"} {
		if !strings.Contains(output, want) {
			t.Errorf("output missing %q:\n%s", want, output)
		}
	}
	if strings.Index(output, cpNew.String()) > strings.Index(output, cpOld.String()) {
			t.Errorf("newest checkpoint should be listed first:\n%s", output)
	}
}

func TestCheckpointResumeBare_NoCheckpoints(t *testing.T) {
	tmpDir := t.TempDir()
	t.Chdir(tmpDir)
	setupResumeTestRepo(t, tmpDir, false)

cmd, out := newCheckpointResumeTestCmd(t)
	cmd.SetArgs([]string{})
	if err := cmd.Execute(); err != nil {
			t.Fatalf("Execute() error = %v", err)
	}
	if !strings.Contains(out.String(), "No committed checkpoints found") {
		t.Errorf("output should say no checkpoints found, got: %s", out.String())
	}
}

```
