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
- func Formats() []string
- func Lines(n Notice) []string
- func NoticeDir(stateDir string) string
- func NoticePath(stateDir string, appPID int, agent string) string
- func Render(format, event string, p Payload, n Notice) string
- func Run(in io.Reader, out io.Writer, format, event, agent, stateDir string, pids []int)
- func Text(n Notice) string
- type Notice
- type Payload
Constants ¶
const Plain = "plain"
Plain is the format that prints the text with no JSON.
Variables ¶
This section is empty.
Functions ¶
func Lines ¶ added in v3.1.0
Lines gives the text of each session of the notice that has new mail: the pool session first, then each named session.
func NoticePath ¶
NoticePath is the notice file of the bridge of one app process and one agent.
func Render ¶
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.
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 ¶
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
All gives the pool session first, when there is one, then each named session.
func (Notice) MarshalJSON ¶ added in v3.1.0
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 ¶
ParsePayload reads the payload of the app. A bad or empty payload gives the zero value.