cli

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReservedKeywords = map[string]bool{
	"myself": true,
	"self":   true,
	"me":     true,
}

ReservedKeywords contains keywords that cannot be used as aliases. These resolve to special chats (e.g., "myself", "self", "me" -> Note to Self).

Functions

func AddAccountIDs

func AddAccountIDs(params url.Values, accountIDs string)

func AddCSVParam

func AddCSVParam(params url.Values, key, csv string)

func ChatTypeToAPI added in v0.2.5

func ChatTypeToAPI(value string) string

ChatTypeToAPI translates user-facing chat type to API value. The CLI uses "dm" for user friendliness, but the API expects "single".

func ConfirmPrompt

func ConfirmPrompt(r io.Reader, w io.Writer, prompt string) (bool, error)

func ExtractBracketedTokenValue added in v0.2.6

func ExtractBracketedTokenValue(input, key string) (string, bool)

ExtractBracketedTokenValue extracts the value from a bracketed token like:

"... [chat:!abc] ..."
"... [id:$msg123] ..."

It returns the content after "key:" up to the closing "]".

func ExtractChatIDFromString added in v0.2.6

func ExtractChatIDFromString(input string) (string, bool)

ExtractChatIDFromString extracts a chat ID from common agent output tokens. Supported forms:

"[chat:!abc]" anywhere in the string
"chat:!abc" as a standalone value

func ExtractMessageIDFromString added in v0.2.6

func ExtractMessageIDFromString(input string) (string, bool)

ExtractMessageIDFromString extracts a message ID from common agent output tokens. Supported forms:

"[id:$msg]" anywhere in the string
"id:$msg" as a standalone value
"↩$msg" reply indicator copied from agent output

func FilterChats

func FilterChats(chats []api.Chat, unreadOnly, mutedOnly, pinnedOnly, archivedOnly bool, typeFilter string) []api.Chat

func FilterUnreadMessages

func FilterUnreadMessages(messages []api.Message, unreadOnly bool) []api.Message

func FormatHandle added in v0.2.5

func FormatHandle(kind string, index int) string

FormatHandle formats a handle token for output.

func FormatMessageLine

func FormatMessageLine(m api.Message, otherName string) string

func FormatMessageLineLight added in v0.2.15

func FormatMessageLineLight(m api.Message, otherName string) string

func FormatTime

func FormatTime(t time.Time) string

func IsReservedKeyword added in v0.2.1

func IsReservedKeyword(input string) bool

IsReservedKeyword returns true if the input is a reserved keyword.

func IsSelfMessage added in v0.2.3

func IsSelfMessage(senderID string) bool

IsSelfMessage returns true if the senderID belongs to the current user.

func LimitReplyDepth added in v0.2.1

func LimitReplyDepth(messages []api.Message, maxDepth int) []api.Message

LimitReplyDepth truncates reply chains beyond maxDepth. depth 0 = unlimited, depth 1 = no replies, depth 2 = one level of replies, etc.

func LimitSlice

func LimitSlice[T any](items []T, limit int) []T

func LooksLikeChatID

func LooksLikeChatID(s string) bool

LooksLikeChatID returns true if the string looks like a chat ID rather than a name.

func MessageDisplayText

func MessageDisplayText(m api.Message) string

func MessageSender

func MessageSender(m api.Message) string

func MessageSenderDisplay

func MessageSenderDisplay(m api.Message, otherName string) string

func MinInt

func MinInt(a, b int) int

func NewestSortKey

func NewestSortKey(messages []api.Message) string

func NormalizeDateAfter

func NormalizeDateAfter(value string) string

func OffsetSlice added in v0.2.1

func OffsetSlice[T any](items []T, offset int) []T

OffsetSlice skips the first n items from a slice.

func OldestSortKey

func OldestSortKey(messages []api.Message) string

func OtherChatName

func OtherChatName(chat api.Chat) string

func PaginateSlice added in v0.2.1

func PaginateSlice[T any](items []T, offset, limit int) []T

PaginateSlice applies offset and limit to a slice.

func ParseRelativeTime added in v0.2.1

func ParseRelativeTime(s string, now time.Time) (time.Time, error)

ParseRelativeTime parses human-friendly time expressions. Supports: "2h ago", "yesterday", "monday", "next tue", "30m", RFC3339, YYYY-MM-DD.

func ParseRelativeTimePast added in v0.2.15

func ParseRelativeTimePast(s string, now time.Time) (time.Time, error)

ParseRelativeTimePast is like ParseRelativeTime but interprets bare durations ("7d", "2h") as past instead of future. Use for --after/--before flags where bare durations logically mean "N units ago".

func PickChat added in v0.2.10

func PickChat(chats []api.Chat, name string, opts ChatResolveOptions, warn io.Writer) (string, error)

PickChat filters, sorts, and selects the best chat from search results. DMs are preferred over groups; within the same type, most recently active wins.

func Poll

func Poll(ctx context.Context, interval time.Duration, fn func(context.Context) error, onError func(error) bool) error

Poll runs fn every interval until the context is canceled. If onError is nil, any error from fn stops polling. If onError returns true, polling continues after an error.

func PrintMessageLine

func PrintMessageLine(w io.Writer, m api.Message, otherName string)

func PrintMessageLineLight added in v0.2.15

func PrintMessageLineLight(w io.Writer, m api.Message, otherName string)

PrintMessageLineLight prints a minimal message line (timestamp + sender + truncated text).

func ReadFile

func ReadFile(path string) (string, error)

func ReadStdin

func ReadStdin(r io.Reader) (string, error)

func ResolveChatByName

func ResolveChatByName(ctx context.Context, client *api.Client, accountIDs string, name string, opts ChatResolveOptions, warn io.Writer) (string, error)

ResolveChatByName searches for a chat by name via the API and returns its ID. If multiple matches are found, the most recently active one is picked automatically.

func ResolveChatIDFromArgOrFlag

func ResolveChatIDFromArgOrFlag(ctx context.Context, client *api.Client, accountIDs string, args []string, flagValue, flagName string, opts ChatResolveOptions, warn io.Writer) (string, error)

ResolveChatIDFromArgOrFlag resolves a chat ID using either a flag value (chat name) or a positional chat ID argument.

func ResolveChatIDFromFlags

func ResolveChatIDFromFlags(ctx context.Context, client *api.Client, accountIDs string, nameFlag, idFlag, nameLabel, idLabel string, opts ChatResolveOptions, warn io.Writer) (string, error)

ResolveChatIDFromFlags resolves a chat ID using either a chat name or explicit chat ID flag.

func ResolveChatIdentifier added in v0.2.1

func ResolveChatIdentifier(input string, aliases map[string]string, noteToSelfID string) (string, error)

ResolveChatIdentifier resolves a chat identifier to a chat ID. Resolution order: 1. Reserved keywords (myself, self, me) -> Note to Self chat 2. Literal chat ID (starts with !) -> return as-is 3. Alias lookup -> resolved ID 4. Error

func ResolveMessageInput

func ResolveMessageInput(text string, stdin bool, file string, in io.Reader) (string, error)

func SenderName

func SenderName(senderID string) string

func SortMessagesByTime

func SortMessagesByTime(messages []api.Message) []api.Message

func StripShellEscape added in v0.2.7

func StripShellEscape(s string) string

StripShellEscape removes shell-escaped backslashes from chat IDs. In zsh (macOS default), "!" inside double quotes is escaped to "\!", so a user typing --chat "!abc:server" actually passes "\!abc:server". This strips the leading backslash to recover the real chat ID.

func TailSlice

func TailSlice[T any](items []T, limit int) []T

func Truncate

func Truncate(s string, max int) string

Types

type ChatResolveOptions

type ChatResolveOptions struct {
	Exact bool
	DM    bool
}

type HandleRef added in v0.2.5

type HandleRef struct {
	Kind  string
	Index int
}

HandleRef identifies a handle token like @chat:1 or @msg:2.

func ExtractHandleRefFromString added in v0.2.6

func ExtractHandleRefFromString(input string) (HandleRef, bool)

ExtractHandleRefFromString finds a handle reference either as a standalone token ("@chat:1") or embedded in brackets within a longer string ("... [@chat:1] ...").

func ParseHandleRef added in v0.2.5

func ParseHandleRef(input string) (HandleRef, bool)

ParseHandleRef parses handle tokens such as @chat:1, @msg:2, @contact:3.

type NameFlags

type NameFlags struct {
	Name  string
	Exact bool
	DM    bool
}

func AddNameFlags

func AddNameFlags(cmd *cobra.Command, flagName, description string, includeDM bool) *NameFlags

func (*NameFlags) ResolveOptions

func (f *NameFlags) ResolveOptions() ChatResolveOptions

Jump to

Keyboard shortcuts

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