Skip to content

Commit 96d55ef

Browse files
authored
Merge pull request #891 from entireio/add-migrate-v2-command-rebased
Checkpoints V2: add migration option
2 parents ea05651 + cef06e7 commit 96d55ef

File tree

7 files changed

+1105
-4
lines changed

7 files changed

+1105
-4
lines changed

cmd/entire/cli/checkpoint/committed.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (s *GitStore) writeSessionToSubdirectory(ctx context.Context, opts WriteCom
350350

351351
// Write prompts
352352
if len(opts.Prompts) > 0 {
353-
promptContent := redact.String(strings.Join(opts.Prompts, "\n\n---\n\n"))
353+
promptContent := redact.String(JoinPrompts(opts.Prompts))
354354
blobHash, err := CreateBlobFromContent(s.repo, []byte(promptContent))
355355
if err != nil {
356356
return filePaths, err
@@ -1281,7 +1281,7 @@ func (s *GitStore) UpdateCommitted(ctx context.Context, opts UpdateCommittedOpti
12811281

12821282
// Replace prompts (apply redaction as safety net)
12831283
if len(opts.Prompts) > 0 {
1284-
promptContent := redact.String(strings.Join(opts.Prompts, "\n\n---\n\n"))
1284+
promptContent := redact.String(JoinPrompts(opts.Prompts))
12851285
blobHash, err := CreateBlobFromContent(s.repo, []byte(promptContent))
12861286
if err != nil {
12871287
return fmt.Errorf("failed to create prompt blob: %w", err)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package checkpoint
2+
3+
import "strings"
4+
5+
// PromptSeparator is the canonical separator used in prompt.txt when multiple
6+
// prompts are stored in a single file.
7+
const PromptSeparator = "\n\n---\n\n"
8+
9+
// JoinPrompts serializes prompts to prompt.txt format.
10+
func JoinPrompts(prompts []string) string {
11+
return strings.Join(prompts, PromptSeparator)
12+
}
13+
14+
// SplitPromptContent deserializes prompt.txt content into individual prompts.
15+
func SplitPromptContent(content string) []string {
16+
if content == "" {
17+
return nil
18+
}
19+
20+
prompts := strings.Split(content, PromptSeparator)
21+
for len(prompts) > 0 && prompts[len(prompts)-1] == "" {
22+
prompts = prompts[:len(prompts)-1]
23+
}
24+
return prompts
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package checkpoint
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestJoinAndSplitPrompts_RoundTrip(t *testing.T) {
11+
t.Parallel()
12+
13+
original := []string{
14+
"first line\nwith newline",
15+
"second prompt",
16+
}
17+
18+
joined := JoinPrompts(original)
19+
split := SplitPromptContent(joined)
20+
21+
require.Len(t, split, 2)
22+
assert.Equal(t, original, split)
23+
}
24+
25+
func TestSplitPromptContent_EmptyContent(t *testing.T) {
26+
t.Parallel()
27+
28+
assert.Nil(t, SplitPromptContent(""))
29+
}

cmd/entire/cli/checkpoint/v2_committed.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (s *V2GitStore) updateCommittedMain(ctx context.Context, opts UpdateCommitt
121121
sessionPath := fmt.Sprintf("%s%d/", basePath, sessionIndex)
122122

123123
if len(opts.Prompts) > 0 {
124-
promptContent := redact.String(strings.Join(opts.Prompts, "\n\n---\n\n"))
124+
promptContent := redact.String(JoinPrompts(opts.Prompts))
125125
blobHash, err := CreateBlobFromContent(s.repo, []byte(promptContent))
126126
if err != nil {
127127
return 0, fmt.Errorf("failed to create prompt blob: %w", err)
@@ -334,7 +334,7 @@ func (s *V2GitStore) writeMainSessionToSubdirectory(opts WriteCommittedOptions,
334334

335335
// Write prompts
336336
if len(opts.Prompts) > 0 {
337-
promptContent := redact.String(strings.Join(opts.Prompts, "\n\n---\n\n"))
337+
promptContent := redact.String(JoinPrompts(opts.Prompts))
338338
blobHash, err := CreateBlobFromContent(s.repo, []byte(promptContent))
339339
if err != nil {
340340
return filePaths, err

0 commit comments

Comments
 (0)