remoteagent

package
v1.261029.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MPL-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

Index

Constants

View Source
const (
	DefaultMaxImageSize = 25 * 1024 * 1024 // 25MB
	DefaultMaxDocSize   = 50 * 1024 * 1024 // 50MB
)
View Source
const ProjectAnswerPayload = "pj"

ProjectAnswerPayload names the callbacks of a Projects prompt's buttons.

Variables

View Source
var AllowedMIMETypes = map[string]string{

	"image/jpeg": "image",
	"image/png":  "image",
	"image/gif":  "image",
	"image/webp": "image",

	"application/pdf": "document",
	"text/plain":      "document",
	"text/markdown":   "document",
	"text/csv":        "document",

	"application/msword": "document",
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "document",

	"application/vnd.ms-excel": "document",
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "document",
}

AllowedMIMETypes lists supported file types

Functions

func BuildCustomPathPrompt

func BuildCustomPathPrompt() string

BuildCustomPathPrompt returns the text for custom path input prompt

func EnsureContext

func EnsureContext(t testing.TB) context.Context

EnsureContext provides a context that propagates either through t.Context() (Go 1.24+) or a fresh background context.

func ExpandPath

func ExpandPath(path string) (string, error)

ExpandPath expands ~ and environment variables in a path

func ExpandPathFrom

func ExpandPathFrom(path, baseDir string) (string, error)

ExpandPathFrom expands a user-provided path with the given baseDir as the reference for relative paths. ~/ and absolute paths are handled as in ExpandPath. When path is relative and baseDir is non-empty, it is joined with baseDir; otherwise it falls back to filepath.Abs (process cwd).

func NewConsumer

func NewConsumer(store bot2.SettingsStore, opts ...ConsumerOption) bot2.Consumer

NewConsumer builds the consumer that binds a bot to the remote-agent purpose. store may be nil (test use): settings are then read once.

func RegisterBuiltinCommands

func RegisterBuiltinCommands(registry *imbot.CommandRegistry, botHandler BotHandlerAdapter) error

RegisterBuiltinCommands registers the chat commands (.design/remote-into-projects.md, "命令精简"): which folder (/cd, /dir), the session commands Projects runs, /help, and access (/bind, /join, which /help does not list). The registry is also what a platform shows as its command menu.

func ShortenPath

func ShortenPath(path string) string

ShortenPath shortens a path for display

func ValidateProjectPath

func ValidateProjectPath(path string) error

ValidateProjectPath validates that a path is a valid project directory

Types

type BotHandler

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

BotHandler handles what a chat sends a bot: access (pairing, group whitelist), which folder it works in (/cd, /dir, the directory browser), and everything else, which goes to Claude Code through Projects (project_route.go).

func NewBotHandler

func NewBotHandler(
	ctx context.Context,
	botSetting bot2.BotSetting,
	chatStore bot2.ChatStoreInterface,
	directoryBrowser *feature.DirectoryBrowser,
	manager *imbot.Manager,
	pairing *bot2.PairingManager,
	store bot2.SettingsStore,
) *BotHandler

func (*BotHandler) GetCommandRegistry

func (h *BotHandler) GetCommandRegistry() *imbot.CommandRegistry

GetCommandRegistry returns the command registry.

func (*BotHandler) HandleMessage

func (h *BotHandler) HandleMessage(msg imbot.Message, platform imbot.Platform, botUUID string)

func (*BotHandler) InitCommandRegistry

func (h *BotHandler) InitCommandRegistry() error

InitCommandRegistry initializes the command registry with built-in commands.

func (*BotHandler) SendText

func (h *BotHandler) SendText(hCtx HandlerContext, text string)

func (*BotHandler) SetProjectRouter added in v1.261022.2

func (h *BotHandler) SetProjectRouter(r ProjectRouter)

SetProjectRouter plugs in the router; nil turns chat control off.

func (*BotHandler) VerifyAndPair

func (h *BotHandler) VerifyAndPair(botUUID, chatID, senderID, platform, code string) error

VerifyAndPair runs the pairing-code check and, on success, persists the binding in the chat store. It is invoked by the /bind command handler.

type BotHandlerAdapter

type BotHandlerAdapter interface {
	// SendText sends a text message to a chat
	SendText(chatID, text string) error

	// GetProjectPath gets the folder of a chat
	GetProjectPath(chatID string) (string, error)

	// SetProjectPath moves a chat to a folder, and says so in the chat
	SetProjectPath(chatID, path string) error

	// ListChatProjectPaths lists the folders a chat used, most recent first.
	ListChatProjectPaths(chatID string) ([]string, error)

	// IsWhitelisted checks if a group is whitelisted
	IsWhitelisted(groupID string) bool

	// AddToWhitelist adds a group to whitelist
	AddToWhitelist(groupID, platform, userID string) error

	// VerifyAndPair verifies a one-time pairing code and, on success, records
	// the chat as paired with the bot. Implementations should also emit the
	// matching audit events (success / failure).
	VerifyAndPair(botUUID, chatID, senderID, platform, code string) error

	// RunSessionCommand runs one of sessionCommands in Projects and tells the
	// chat the result.
	RunSessionCommand(ctx *imbot.HandlerContext, name, arg string)
}

BotHandlerAdapter provides methods needed by command handlers. This allows commands to interact with the bot without direct coupling.

func NewBotHandlerAdapter

func NewBotHandlerAdapter(handler *BotHandler) BotHandlerAdapter

NewBotHandlerAdapter creates a new adapter for the given handler.

type ConsumerOption added in v1.261022.2

type ConsumerOption func(*consumer)

ConsumerOption customises NewConsumer.

func WithProjectRouter added in v1.261022.2

func WithProjectRouter(r ProjectRouter) ConsumerOption

WithProjectRouter hands chats to Projects (see ProjectRouter).

type FileStore

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

FileStore handles project-based file storage for bot media

func NewFileStore

func NewFileStore() *FileStore

NewFileStore creates a new file store with default limits

func NewFileStoreWithProxy

func NewFileStoreWithProxy(proxyURL string) (*FileStore, error)

NewFileStoreWithProxy creates a new file store with proxy support

func (*FileStore) DownloadFile

func (s *FileStore) DownloadFile(ctx context.Context, projectPath, url, mimeType string) (*StoredFile, error)

DownloadFile downloads a file from a URL to the project's .download directory Returns an error if file size exceeds limits

func (*FileStore) GetDownloadDir

func (s *FileStore) GetDownloadDir(projectPath string) string

GetDownloadDir returns the .download directory for a project

func (*FileStore) IsAllowedSize

func (s *FileStore) IsAllowedSize(mimeType string, size int64) bool

IsAllowedSize checks if the size is within limits for the mime type

func (*FileStore) IsAllowedType

func (s *FileStore) IsAllowedType(mimeType string) bool

IsAllowedType checks if the mime type is allowed

func (*FileStore) SetTelegramToken

func (s *FileStore) SetTelegramToken(token string)

SetTelegramToken sets the Telegram bot token for resolving file URLs

type HandlerContext

type HandlerContext struct {
	Bot       imbot.Bot
	BotUUID   string
	ChatID    string
	SenderID  string
	MessageID string
	Platform  imbot.Platform
	Message   imbot.Message
}

HandlerContext contains per-message context data

func (*HandlerContext) IsDirect

func (c *HandlerContext) IsDirect() bool

func (*HandlerContext) Text

func (c *HandlerContext) Text() string

type ProjectFile added in v1.261023.0

type ProjectFile struct {
	Name string
	Path string
}

ProjectFile is a file a chat sent, saved at Path under its own Name.

type ProjectInbound added in v1.261022.2

type ProjectInbound struct {
	Platform string
	BotUUID  string
	ChatID   string
	SenderID string
	Text     string
	// Files are what the chat sent with the message, saved on local disk;
	// they are removed once RouteInbound returns.
	Files []ProjectFile
	// Profile is the bot's Claude Code profile (its default agent), which a
	// chat's first session in Projects runs under; empty for the default.
	Profile string
}

ProjectInbound is one message from a chat.

type ProjectRouter added in v1.261022.2

type ProjectRouter interface {
	// RouteInbound hands a chat's text to its session. handled is false when
	// the chat has no place in Projects. When handled is true Projects owns the message:
	// its reply comes back through the host's outbound path, and err, if set,
	// is why the message could not be delivered (for example a paused
	// project) and is shown to the chat.
	RouteInbound(ctx context.Context, in ProjectInbound) (handled bool, err error)
	// RouteCommand runs a session command (see projectCommand); in.Text is
	// the text after the command. handled is false when the chat has no
	// place in Projects. reply is
	// what to tell the chat; err, if set, is why the command failed.
	RouteCommand(ctx context.Context, name string, in ProjectInbound) (handled bool, reply string, err error)
	// RouteAnswer answers a Projects thread's approval or question with the
	// button a chat pressed (payload ProjectAnswerPayload, thread id, request
	// id, choice). reply, when set, is what to tell the chat; the prompt
	// itself is restated by the project.
	RouteAnswer(ctx context.Context, in ProjectInbound, threadID, requestID, choice string) (reply string, err error)
	// Enabled reports whether chats are handled by Projects at all (its
	// switch). When it is off a chat gets no Claude Code, only pairing and
	// notifications.
	Enabled() bool
	// ToFolder moves the chat to a folder: its next message starts a new
	// session there. With ifNew a chat that already has a place is left alone.
	ToFolder(ctx context.Context, in ProjectInbound, folder string, ifNew bool) error
}

ProjectRouter is how a chat talks to Claude Code: through Projects, where every chat has a folder or a session (.design/remote-into-projects.md). The host implements it (see internal/server/module/projects); a BotHandler without one, or with Projects switched off, gives chats access and notifications only.

type StoredFile

type StoredFile struct {
	Path     string // Full path: {projectPath}/.agent/{filename}
	RelPath  string // Relative path for agent: .agent/{filename}
	URL      string // Original URL
	Filename string
	Size     int64
	MimeType string
}

StoredFile represents a stored file

type TelegramFile

type TelegramFile struct {
	Ok     bool `json:"ok"`
	Result struct {
		FileID   string `json:"file_id"`
		FileSize int    `json:"file_size"`
		FilePath string `json:"file_path"`
	} `json:"result"`
}

TelegramFile represents the response from Telegram's getFile API

type TestBootOptions

type TestBootOptions struct {
	// DataDir overrides the chat-store directory (default: t.TempDir()).
	DataDir string

	// Router hands chats to Projects (see ProjectRouter); nil leaves chat
	// control off. A test may also set it later with SetProjectRouter,
	// before messages flow.
	Router ProjectRouter
}

TestBootOptions tweaks BootForTest defaults. All fields are optional.

type TestHarness

type TestHarness struct {
	Setting   bot.BotSetting
	Handler   *BotHandler
	ChatStore bot.ChatStoreInterface
	Pairing   *bot.PairingManager
	DataDir   string
	Manager   *imbot.Manager
	// contains filtered or unexported fields
}

TestHarness wires the production BotHandler against a test imbot.Manager (typically backed by the tingly platform). It owns the support infrastructure — chat store, pairing — and exposes them so tests can drive state directly.

Construction:

env := testenv.NewTestEnv(t)
uuid := env.BotUUID() // creates a tingly bot in env.Manager()
harness := bot.BootForTest(t, env.Manager(), bot.BotSetting{
    UUID:     uuid,
    Platform: "tingly",
    Enabled:  true,
})
require.NoError(t, env.Manager().Start(env.Context()))

Tests then drive the bot through the testenv chat helpers.

func BootForTest

func BootForTest(t *testing.T, manager *imbot.Manager, setting bot.BotSetting, opts ...TestBootOptions) *TestHarness

BootForTest spins up a production BotHandler against the given imbot.Manager. It assumes the Manager already has a bot registered for setting.UUID (the tingly testenv arranges this via AddTinglyBotWithUUID when env.BotUUID() is called).

The harness registers the BotHandler.HandleMessage callback on the Manager. Callers must Start the Manager themselves — keeping that step in the test makes it explicit when inbound messages start flowing.

func (*TestHarness) MarkChatPaired

func (h *TestHarness) MarkChatPaired(chatID, senderID string)

MarkChatPaired records a pairing for the harness's bot via the same production API path that VerifyAndPair uses. Tests focused on post-pairing behavior can skip the /bind handshake without bypassing the real persistence path — exercising any future bug in SetPaired.

func (*TestHarness) MintPairingCode

func (h *TestHarness) MintPairingCode() (code string, expiresAt time.Time)

MintPairingCode mints a fresh pairing code for the harness's bot. Tests that exercise the pairing-required path use this to obtain the code the user must send via /bind.

func (*TestHarness) WhitelistGroup

func (h *TestHarness) WhitelistGroup(chatID, ownerID string)

WhitelistGroup adds a group chat to the bot's whitelist (required for the bot to respond to group messages).

Jump to

Keyboard shortcuts

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