jsonlstore

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package jsonlstore provides an append-only, JSONL-file checkpoint.Store for local development. Each Save/Delete appends one JSON record; the live state is the last record seen per key. On open the file is replayed to rebuild the in-memory index and the CAS counter, so state survives process restarts.

The store is safe for concurrent use within a single process, but the log file must not be shared between processes. Conformance with the Store contract is asserted by the shared storetest suite.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is an append-only JSONL-backed checkpoint.Store. Create with New; safe for concurrent use within a single process.

func New

func New(path string) (*Store, error)

New opens (creating if absent) the JSONL log at path and replays it to rebuild live state.

Example

ExampleNew demonstrates that a parked envelope survives a process restart: a fresh open of the same JSONL log replays it and serves the same state.

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"path/filepath"

	"chainguard.dev/driftlessaf/agents/checkpoint"
	"chainguard.dev/driftlessaf/agents/checkpoint/jsonlstore"
)

func main() {
	dir, err := os.MkdirTemp("", "jsonlstore-example")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	defer os.RemoveAll(dir)
	path := filepath.Join(dir, "checkpoints.jsonl")

	ctx := context.Background()
	first, err := jsonlstore.New(path)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	env := &checkpoint.Envelope{
		Version:       checkpoint.EnvelopeVersion,
		Provider:      checkpoint.ProviderAnthropic,
		ReconcilerKey: "org/repo#7",
		RunID:         "run-7",
		ProviderState: json.RawMessage(`{"model":"claude-fable-5"}`),
	}
	if err := first.Save(ctx, env.ReconcilerKey, env); err != nil {
		fmt.Println("error:", err)
		return
	}

	// A second open (a "restarted process") replays the log.
	second, err := jsonlstore.New(path)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	loaded, _, ok, err := second.Load(ctx, env.ReconcilerKey)
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println("survived reopen:", ok, loaded.RunID)
}
Output:
survived reopen: true run-7

func (*Store) Delete

func (s *Store) Delete(_ context.Context, key string, tok checkpoint.Token) error

Delete appends a tombstone for key only if tok matches the live generation.

func (*Store) Load

Load returns a deep copy of the latest live envelope for key and its token.

func (*Store) Save

func (s *Store) Save(_ context.Context, key string, env *checkpoint.Envelope) error

Save appends a new record for key and advances the CAS generation.

Jump to

Keyboard shortcuts

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