feat(import): persist provenance and surface Imported on List · Entire

feat(import): persist provenance and surface Imported on List

ed881e0→main·

computermode·3w ago·2 files·+78 added/-0 removed

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

Sessions

f85986b0716eView transcript

Changes

2

463 unmodified lines

464
465
466
467
468
469
470
30 unmodified lines

501
502
503
504
505
506
507
508
509
510
8 unmodified lines

519
520
521
522
523
524
525
526
527
10 unmodified lines

538
539
540
541
542
543
544
783 unmodified lines

1328
1329
1330
1331
1332
1333
1334

463 unmodified lines

Summary:                     redactSummary(opts.Summary),
        CLIVersion:                  versioninfo.Version,
        Kind:                        opts.Kind,
        Provenance:                  opts.Provenance,
        ReviewSkills:                opts.ReviewSkills,
        ReviewPrompt:                opts.ReviewPrompt,
        InvestigateRunID:            opts.InvestigateRunID,
30 unmodified lines

checkpointVersion := CheckpointVersionBranchV1
    hasReview := opts.HasReview
    hasInvestigation := opts.HasInvestigation
    // imported is the umbrella flag: true when any session in this checkpoint
    // was imported (Kind == "imported"). Compared as a literal because the
    // session package imports checkpoint, so we can't reference its constant.
    imported := opts.Kind == "imported"
    rootMetadataPath := basePath + paths.MetadataFileName
    if entry, exists := entries[rootMetadataPath]; exists {
        existingSummary, readErr := s.readSummaryFromBlob(entry.Hash)
8 unmodified lines

if !hasInvestigation {
            hasInvestigation = existingSummary.HasInvestigation
        }
        if !imported {
            imported = existingSummary.Imported
        }
    }

10 unmodified lines

CombinedAttribution: combinedAttribution,
    HasReview:           hasReview,
    HasInvestigation:    hasInvestigation,
    Imported:            imported,
}

metadataJSON, err := jsonutil.MarshalIndentWithNewline(summary, "", "  ")
783 unmodified lines

info.CheckpointsCount = summary.CheckpointsCount
    info.FilesTouched = summary.FilesTouched
    info.SessionCount = len(summary.Sessions)
    info.Imported = summary.Imported

for i := range summary.Sessions {
        sessionMetadata, ok := readCommittedMetadataFromCheckpointTree(checkpointTree, i)

Mcmd/entire/cli/checkpoint/persistent.go+10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

package checkpoint

import (
    "context"
    "testing"

"github.com/go-git/go-git/v6"
    "github.com/go-git/go-git/v6/plumbing/object"

"github.com/entireio/cli/cmd/entire/cli/agent"
    "github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
    "github.com/entireio/cli/cmd/entire/cli/testutil"
    "github.com/entireio/cli/redact"
)

func TestWrite_ImportedSurfacesOnList(t *testing.T) {
    t.Parallel()
    tempDir := t.TempDir()
    testutil.InitRepo(t, tempDir)
    repo, err := git.PlainOpen(tempDir)
    if err != nil {
        t.Fatalf("open repo: %v", err)
    }
    // Initial commit so HEAD exists.
    wt, err := repo.Worktree()
    if err != nil {
        t.Fatal(err)
    }
    testutil.WriteFile(t, tempDir, "f.txt", "x")
    if _, err := wt.Add("f.txt"); err != nil {
        t.Fatal(err)
    }
    if _, err := wt.Commit("init", &git.CommitOptions{
        Author: &object.Signature{Name: "Test", Email: "test@test.com"},
    }); err != nil {
        t.Fatal(err)
    }

store := NewGitStore(repo, ImportsRefs())
    red, err := redact.JSONLBytes([]byte(`{"type":"user","uuid":"u1","message":{"role":"user","content":"hi"}}` + "\n"))
    if err != nil {
        t.Fatal(err)
    }
    err = store.Write(context.Background(), Session{
        CheckpointID:     id.MustCheckpointID("aabbccddeeff"),
        SessionID:        "s1",
        Strategy:         "import",
        Kind:             "imported",
        Agent:            agent.AgentTypeClaudeCode,
        Transcript:       red,
        Prompts:          []string{"hi"},
        CheckpointsCount: 1,
        Provenance: &Provenance{
            Source: "claude-code", SessionID: "s1", TurnUUID: "u1", ImportVersion: 1,
        },
    })
    if err != nil {
        t.Fatalf("write imported checkpoint: %v", err)
    }

infos, err := store.List(context.Background())
    if err != nil {
        t.Fatal(err)
    }
    if len(infos) != 1 || !infos[0].Imported {
        t.Fatalf("expected 1 imported checkpoint, got %+v", infos)
    }
}