checkpoint

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckpointCmd = &cobra.Command{
	Use:   "checkpoint <name> [description]",
	Short: "Create a state snapshot checkpoint",
	Long: `Create a checkpoint to capture current state of all tokens.

Checkpoints include:
- Counts by status (STUB, IMPL, TESTED, BENCHED)
- Commit hash and timestamp
- Full JSON snapshot of all tokens

Useful for tracking progress over time.`,
	Args: cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		prompt, _ := cmd.Flags().GetString("prompt")
		if prompt != "" {
			if _, err := utils.LoadPrompt(prompt); err != nil {
				return err
			}
		}
		dbPath, _ := cmd.Flags().GetString("db")
		name := args[0]
		description := ""
		if len(args) > 1 {
			description = strings.Join(args[1:], " ")
		}

		db, err := storage.Open(dbPath)
		if err != nil {
			return fmt.Errorf("open database: %w", err)
		}

		defer func() { _ = db.Close() }()

		commitHash := ""
		if gitCmd := exec.Command("git", "rev-parse", "HEAD"); gitCmd.Dir == "" {
			if output, err := gitCmd.Output(); err == nil {
				commitHash = strings.TrimSpace(string(output))
			}
		}

		cfg, _ := utils.LoadProjectConfig()
		idPattern := ""
		if cfg != nil && cfg.Requirements.IDPattern != "" {
			idPattern = cfg.Requirements.IDPattern
		}

		tokens, err := db.ListTokens(nil, idPattern, "", 0)
		if err != nil {
			return fmt.Errorf("get tokens: %w", err)
		}

		snapshotJSON, err := json.Marshal(tokens)
		if err != nil {
			return fmt.Errorf("marshal snapshot: %w", err)
		}

		if err := db.CreateCheckpoint(name, description, commitHash, string(snapshotJSON)); err != nil {
			return fmt.Errorf("create checkpoint: %w", err)
		}

		fmt.Printf("✅ Created checkpoint: %s\n", name)
		if commitHash != "" {
			fmt.Printf("Commit: %s\n", commitHash[:8])
		}
		fmt.Printf("Tokens: %d\n", len(tokens))

		return nil
	},
}

CANARY: REQ=ENG-4311; FEATURE="CheckpointCmd"; ASPECT=CLI; STATUS=IMPL; OWNER=canary; UPDATED=2025-10-16

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL