chatimport

package
v0.182.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chatimport reads the conversation history a user exported from Claude.ai or ChatGPT themselves, and files each conversation as a read-only chat (ADR-074).

Neither service offers a supported way for a third-party program to read a consumer account's conversations (OQ-22), so this is an import, never a sync: the user asks the service for their data, downloads the archive it emails them, and hands Caprock the archive or the conversations.json inside it. Caprock reads the file on this machine and calls nothing (rule 4).

Neither service documents the file. The shapes read here are the ones open-source readers of the exports agree on (sources in OQ-22, read 2026-10-17), and every field is optional: a field a later export drops reads as empty, never as a failed import.

Both archives carry a conversations.json that is one JSON array of conversations, which can run to hundreds of megabytes; it is decoded one conversation at a time, so memory follows the largest conversation, not the archive.

Index

Constants

View Source
const (
	SourceClaudeAI = "claude.ai"
	SourceChatGPT  = "chatgpt"
)

Sources: what a conversation came from. The same values are stored as the imported chat's sessions.agent, so every screen that names an agent names the service.

View Source
const MaxText = 64000

MaxText caps one imported message, in runes. Higher than the live cap on an agent's prose (event.MaxAssistantText): an import is the user's own archive, read once, and the end of a long answer is often the part they kept it for.

Variables

View Source
var ErrNotExport = errors.New("this is not a Claude.ai or ChatGPT export: no conversations.json with conversations in it")

ErrNotExport is returned for a file that is neither export.

Functions

func File

func File(p string, fn func(Conversation) error) error

File reads an export at p — the zip the service emailed, or the conversations.json from inside it — and calls fn for each conversation. An error from fn stops the read with that error.

func IsSource

func IsSource(agent string) bool

IsSource reports whether an agent value is one of the import sources.

func JSON

func JSON(r io.Reader, fn func(Conversation) error) error

JSON reads a conversations.json: an array of conversations, each told apart by its own shape — Claude.ai's carry chat_messages, ChatGPT's a mapping.

func Save

func Save(ctx context.Context, st *store.Store, c Conversation, res *Result) error

Save files one conversation as a read-only chat and counts what it did.

The conversation is a session (ADR-071: a chat is a session) with `chat = 1`, `status = 'ended'`, no folder, no process, the source as its agent and the service's id as its native id. Each message is an event keyed by the service's message id, so a re-import adds only the messages that are new. The events carry no tokens and no cost and are marked `internal`, which every aggregate already leaves out: a conversation held on Claude.ai or ChatGPT is not work done on this machine, and must not move a day's activity or spend. The conversation view reads them all the same. No daily row, no session_stats row: nothing to take back out on delete.

func SessionID

func SessionID(source, id string) string

SessionID is the Caprock session an imported conversation is stored as: the source and the service's own id, so importing the same export again lands on the same row.

func SourceName

func SourceName(source string) string

SourceName is how a source is written on screen.

func Zip

func Zip(r io.ReaderAt, size int64, fn func(Conversation) error) error

Zip reads conversations.json out of an export archive. The shallowest one wins, so a stray copy in a sub-folder does not shadow the export's own.

Types

type Conversation

type Conversation struct {
	Source  string
	ID      string // the service's own conversation id
	Title   string
	Model   string // the model the service names, when it names one
	Created time.Time
	Updated time.Time
	// Messages is the conversation as the service shows it: the branch that
	// ends at its current message, not the edited versions beside it.
	Messages []Message
}

Conversation is one conversation from an export.

type Message

type Message struct {
	ID   string
	Role string // "user" or "assistant"
	Text string
	At   time.Time
}

Message is one message of a conversation.

type Result

type Result struct {
	// Conversations is how many the export held that had something to read.
	Conversations int `json:"conversations"`
	// Added is new chats; Updated is chats already imported that the export
	// carried new messages for; Unchanged is chats already imported as they
	// are.
	Added     int `json:"added"`
	Updated   int `json:"updated"`
	Unchanged int `json:"unchanged"`
	// Deleted is conversations the user deleted from Caprock after an earlier
	// import: they stay deleted (ADR-037's tombstone).
	Deleted int `json:"deleted"`
	// Empty is conversations with no message to show.
	Empty int `json:"empty"`
	// Messages is how many messages were added.
	Messages int `json:"messages"`
	// Sources counts the conversations read per source.
	Sources map[string]int `json:"sources"`
}

Result is what one import did, counted per conversation.

func Import

func Import(ctx context.Context, st *store.Store, path string) (Result, error)

Import reads an export file and saves every conversation in it.

Jump to

Keyboard shortcuts

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