hook

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package hook gives the output of "mai hook": the count of new mail of each session of the bridge of the app, in the hook format of the app. The output has one line for each session with new mail.

The bridge writes a notice file. The hook finds the file through the process chain and never calls the server.

Index

Constants

View Source
const Plain = "plain"

Plain is the format that prints the text with no JSON.

Variables

This section is empty.

Functions

func Formats

func Formats() []string

Formats are the names of the known formats.

func Lines added in v3.1.0

func Lines(n Notice) []string

Lines gives the text of each session of the notice that has new mail: the pool session first, then each named session.

func NoticeDir

func NoticeDir(stateDir string) string

NoticeDir is the folder of the notice files in the state folder.

func NoticePath

func NoticePath(stateDir string, appPID int, agent string) string

NoticePath is the notice file of the bridge of one app process and one agent.

func Render

func Render(format, event string, p Payload, n Notice) string

Render gives the output for the app, or "" when the hook must print nothing: an unknown format or event, no new mail, or a Stop hook in a turn that a Stop hook already continued. The text has one line for each session with new mail.

func Run

func Run(in io.Reader, out io.Writer, format, event, agent, stateDir string, pids []int)

Run reads the payload on in, finds the notice of the app in stateDir through pids (the process chain, nearest first), and writes the output to out. Run never fails: on an error it writes nothing.

func Text

func Text(n Notice) string

Text is the notice text for a session with new mail.

Types

type Notice

type Notice struct {
	Session   string   `json:"session"`
	NewMail   int      `json:"new_mail"`
	UpdatedAt string   `json:"updated_at"`
	Named     []Notice `json:"named,omitempty"`
}

Notice is the content of a notice file. It holds no secret and no mail text.

Session and NewMail are the pool session of the bridge. Named has one notice for each named session that a chat logged in to through the bridge, sorted by login. A notice in Named has no Named list.

While the pool lease of the bridge has no session, Session is "". The file then has no pool entry: its JSON has only the list named.

func FindNotice

func FindNotice(stateDir, agent string, pids []int) (Notice, bool)

FindNotice returns the notice of the nearest process of pids that has a notice file. With an agent, only the file of that agent counts. With no agent, the first file of the process in name order counts.

func (Notice) All added in v3.1.0

func (n Notice) All() []Notice

All gives the pool session first, when there is one, then each named session.

func (Notice) MarshalJSON added in v3.1.0

func (n Notice) MarshalJSON() ([]byte, error)

MarshalJSON gives only the list named when the notice has no pool session.

type Payload

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

Payload is the part of the payload of the app that changes the output. The hook uses only these fields: the harness of Copilot, and the marks that stop a loop of Stop hooks.

func ParsePayload

func ParsePayload(raw []byte) Payload

ParsePayload reads the payload of the app. A bad or empty payload gives the zero value.

Jump to

Keyboard shortcuts

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