amp

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package amp provides an adapter for Amp Code that reads thread JSON files from ~/.local/share/amp/threads/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWatcher

func NewWatcher(threadsDir string) (<-chan adapter.Event, io.Closer, error)

NewWatcher creates a watcher for Amp thread changes.

Types

type Adapter

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

Adapter implements the adapter.Adapter interface for Amp Code threads.

func New

func New() *Adapter

New creates a new Amp adapter.

func (*Adapter) Capabilities

func (a *Adapter) Capabilities() adapter.CapabilitySet

Capabilities returns the supported features.

func (*Adapter) Detect

func (a *Adapter) Detect(projectRoot string) (bool, error)

Detect checks if Amp threads exist for the given project.

func (*Adapter) ID

func (a *Adapter) ID() string

ID returns the adapter identifier.

func (*Adapter) Icon

func (a *Adapter) Icon() string

Icon returns the adapter icon for badge display.

func (*Adapter) Messages

func (a *Adapter) Messages(sessionID string) ([]adapter.Message, error)

Messages returns all messages for the given session.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the human-readable adapter name.

func (*Adapter) SearchMessages

func (a *Adapter) SearchMessages(sessionID, query string, opts adapter.SearchOptions) ([]adapter.MessageMatch, error)

SearchMessages searches message content within a session. Implements adapter.MessageSearcher interface.

func (*Adapter) SessionByID

func (a *Adapter) SessionByID(sessionID string) (*adapter.Session, error)

SessionByID returns a single session by ID without scanning the directory. Implements adapter.TargetedRefresher.

func (*Adapter) Sessions

func (a *Adapter) Sessions(projectRoot string) ([]adapter.Session, error)

Sessions returns all sessions for the given project, sorted by update time.

func (*Adapter) Usage

func (a *Adapter) Usage(sessionID string) (*adapter.UsageStats, error)

Usage returns aggregate usage stats for the given session.

func (*Adapter) Watch

func (a *Adapter) Watch(projectRoot string) (<-chan adapter.Event, io.Closer, error)

Watch returns a channel that emits events when thread data changes.

func (*Adapter) WatchScope

func (a *Adapter) WatchScope() adapter.WatchScope

WatchScope returns Global because amp watches a global threads directory.

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"` // "text", "thinking", "tool_use", "tool_result"

	// Text block fields
	Text string `json:"text,omitempty"`

	// Thinking block fields
	Thinking  string `json:"thinking,omitempty"`
	Signature string `json:"signature,omitempty"`
	Provider  string `json:"provider,omitempty"`

	// Tool use fields
	Complete bool            `json:"complete,omitempty"`
	BlockID  string          `json:"id,omitempty"`
	Name     string          `json:"name,omitempty"`
	Input    json.RawMessage `json:"input,omitempty"`

	// Tool result fields
	ToolUseID string     `json:"toolUseID,omitempty"`
	Run       *ToolRun   `json:"run,omitempty"`
	Content_  []SubBlock `json:"content,omitempty"` // Nested content for tool results
}

ContentBlock represents a content block in an Amp message.

type Env

type Env struct {
	Initial *EnvInitial `json:"initial,omitempty"`
}

Env holds environment information for the thread.

type EnvInitial

type EnvInitial struct {
	Trees    []Tree    `json:"trees,omitempty"`
	Platform *Platform `json:"platform,omitempty"`
}

EnvInitial holds initial environment info including workspace trees.

type Message

type Message struct {
	Role      string         `json:"role"` // "user" or "assistant"
	MessageID int            `json:"messageId"`
	Content   []ContentBlock `json:"content"`
	State     *MessageState  `json:"state,omitempty"`
	Usage     *Usage         `json:"usage,omitempty"`
	Meta      *MessageMeta   `json:"meta,omitempty"`
}

Message represents a message in an Amp thread.

type MessageMeta

type MessageMeta struct {
	SentAt int64 `json:"sentAt,omitempty"` // Unix millis
}

MessageMeta holds metadata for user messages.

func (*MessageMeta) SentAtTime

func (m *MessageMeta) SentAtTime() time.Time

SentAtTime returns the sentAt time.

type MessageState

type MessageState struct {
	Type       string `json:"type,omitempty"`
	StopReason string `json:"stopReason,omitempty"`
}

MessageState indicates the completion state of an assistant message.

type Platform

type Platform struct {
	OS            string `json:"os,omitempty"`
	Client        string `json:"client,omitempty"`
	ClientVersion string `json:"clientVersion,omitempty"`
}

Platform holds platform information.

type Repository

type Repository struct {
	URL string `json:"url,omitempty"`
	Ref string `json:"ref,omitempty"`
	SHA string `json:"sha,omitempty"`
}

Repository holds git repository info for a tree.

type SubBlock

type SubBlock struct {
	Type string `json:"type,omitempty"`
	Text string `json:"text,omitempty"`
}

SubBlock represents nested content within a tool result.

type Thread

type Thread struct {
	V        int       `json:"v"`
	ID       string    `json:"id"`
	Created  int64     `json:"created"` // Unix millis
	Messages []Message `json:"messages"`
	Env      *Env      `json:"env,omitempty"`
}

Thread represents a top-level Amp thread from threads/T-{uuid}.json.

func (*Thread) CreatedTime

func (t *Thread) CreatedTime() time.Time

CreatedTime returns the thread creation time.

type ToolResult

type ToolResult struct {
	Output   string `json:"output,omitempty"`
	ExitCode int    `json:"exitCode,omitempty"`
}

ToolResult holds the output of a tool execution (dict form).

type ToolRun

type ToolRun struct {
	Status string          `json:"status,omitempty"`
	Result json.RawMessage `json:"result,omitempty"` // Can be {output,exitCode}, []string, or string
}

ToolRun holds the result of a tool execution.

func (*ToolRun) ParseResult

func (r *ToolRun) ParseResult() (output string, exitCode int)

ParseResult tries to extract output text and exit code from the polymorphic result field.

type Tree

type Tree struct {
	DisplayName string      `json:"displayName,omitempty"`
	URI         string      `json:"uri,omitempty"` // file:// URI
	Repository  *Repository `json:"repository,omitempty"`
}

Tree represents a workspace tree (project) in the Amp environment.

type Usage

type Usage struct {
	Model                    string `json:"model,omitempty"`
	InputTokens              int    `json:"inputTokens,omitempty"`
	OutputTokens             int    `json:"outputTokens,omitempty"`
	CacheCreationInputTokens int    `json:"cacheCreationInputTokens,omitempty"`
	CacheReadInputTokens     int    `json:"cacheReadInputTokens,omitempty"`
	TotalInputTokens         int    `json:"totalInputTokens,omitempty"`
	Timestamp                string `json:"timestamp,omitempty"`
}

Usage holds per-message token usage information.

Jump to

Keyboard shortcuts

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