noticeslot

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 17 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

Overview

Package noticeslot is the smart notice's open slot: an app (through its SDK) or an agent (through the `harnessly notice` command or the notice_ask MCP tool) shows the person a ready element in the black plate — a status, a progress, a choice, a confirmation, a short field, code cells or a view of its own — and gets the answer back. One description serves the three ways in. The page lists what is open and answers it.

What the slot never does: ask for a password, a key or a sign-in. There is no password field in any kind, a view of its own that brings one is refused, a field worded as a password or key is refused, and a typed answer that looks like a key is turned back with a pointer to the safe. Secrets go through the safe and the site sign-in.

It lives in memory: a notice is a question of the moment, and the call that waits for it is gone with a restart too. Only the sources the person turned off are kept (Muted), by the caller.

Index

Constants

View Source
const (
	SourceApp   = "app"
	SourceAgent = "agent"
)
View Source
const (
	StatusAnswered  = "answered"
	StatusDismissed = "dismissed"
	StatusTimeout   = "timeout"
	StatusMuted     = "muted"
)
View Source
const (
	DefaultTTL     = 10 * time.Minute
	MaxTTL         = 24 * time.Hour
	StatusTTL      = 8 * time.Second
	MaxShownPerSrc = 3  // waiting notices of one source shown at once on the machine
	MaxOpenPerSrc  = 12 // all open notices of one source, queued ones too
	RatePerMinute  = 5  // new notices of one source a minute
	MaxTitle       = 120
	MaxText        = 600
	MaxOption      = 80
	MinOptions     = 2
	MaxOptions     = 6
	MaxView        = 16 << 10
	MaxAnswer      = 2000
)

Limits.

View Source
const (
	ToolAsk    = "notice_ask"
	ToolShow   = "notice_show"
	ToolUpdate = "notice_update"
	ToolClose  = "notice_close"
)

The agent's MCP tools of the slot: the same description as `harnessly notice` and the SDK's hl.notice.

View Source
const AgentCodeRefusal = "refused: an agent does not get one-time codes through the notice. Run the command that needs the code " +
	"with `harnessly secret run --code VAR --why \"…\" -- COMMAND`: the person types it in the chat's panel and it goes " +
	"straight into the command's environment."

AgentCodeRefusal: an agent never sees a one-time code; the safe hands it to the command that needs it.

Variables

View Source
var (
	ErrArgs   = errors.New("noticeslot: bad notice")
	ErrSecret = errors.New("noticeslot: the slot does not take passwords, keys or sign-ins; use the safe")
	ErrBusy   = errors.New("noticeslot: this source has too many open notices")
	ErrRate   = errors.New("noticeslot: this source shows notices too often")
	ErrMuted  = errors.New("noticeslot: the person turned this source off")
	ErrGone   = errors.New("noticeslot: no such notice")
	ErrAnswer = errors.New("noticeslot: the answer does not fit the notice")
	// ErrAnswerSecret: the person typed something that looks like a key; the page points them to the safe.
	ErrAnswerSecret = errors.New("noticeslot: the answer looks like a key")
)

Functions

func AsksForSecret

func AsksForSecret(parts ...string) bool

AsksForSecret tells a field or code whose wording asks for a password, a key or a sign-in.

func Check

func Check(sp *Spec) error

Check validates a spec and fills its defaults; the error says what is wrong.

func HasPasswordField

func HasPasswordField(html string) bool

HasPasswordField tells a custom view that brings a password input of its own.

func LooksSecret

func LooksSecret(s string) bool

LooksSecret tells a text that is, or holds, a key, a token or a private key: a known prefix, a JWT, a bot token, or one long random word (at least 24 characters of letters and digits with no spaces, mixed and high in entropy).

func Refusal

func Refusal(err error) string

Refusal is the words an error of the slot gives a caller.

func ViewIsActive

func ViewIsActive(html string) bool

ViewIsActive tells a custom view that holds code, a field, a form, a frame or a link: a view is plain layout and buttons that answer with data-answer, and the page draws nothing else.

Types

type Kind

type Kind string

Kind is what the plate shows.

const (
	KindStatus   Kind = "status"
	KindProgress Kind = "progress"
	KindChoice   Kind = "choice"
	KindConfirm  Kind = "confirm"
	KindField    Kind = "field"
	KindCode     Kind = "code"
	KindCustom   Kind = "custom"
)

func (Kind) Waits

func (k Kind) Waits() bool

Waits tells a kind that waits for the person's answer (the others only tell).

type Mutes

type Mutes struct {
	Path string
	// contains filtered or unexported fields
}

Mutes are the sources the person turned off from the plate's menu («Не показывать от …»), kept in a file so they stay off after a restart. Path "" keeps them in memory only (tests).

func (*Mutes) Has

func (m *Mutes) Has(src Source) bool

Has tells a source that is off.

func (*Mutes) List

func (m *Mutes) List() []Source

List is the sources that are off, by name.

func (*Mutes) Set

func (m *Mutes) Set(src Source, off bool) error

Set turns a source off (on=false) or back on.

type Notice

type Notice struct {
	ID string `json:"id"`
	Spec
	Source       Source `json:"source"`
	Conversation string `json:"conversation,omitempty"`
	CreatedAt    int64  `json:"createdAt"`
	ExpiresAt    int64  `json:"expiresAt"`
	// Queued: another notice of the same source waits in the same chat before it; the page shows it after that one.
	Queued bool `json:"queued,omitempty"`
}

Notice is one open notice as the page lists it.

type Result

type Result struct {
	// Status: answered, dismissed (the person said no or closed it), timeout, or muted (the person turned the source off).
	Status string `json:"status"`
	// Value is the answer: a choice's index ({"choice": n}) or own words ({"text": s}), a confirmation's true/false, a
	// field's or code's text, a view's own JSON.
	Value json.RawMessage `json:"value,omitempty"`
}

Result is what the caller gets back.

type Slot

type Slot struct {
	Now func() time.Time
	// Muted tells a source the person turned off; nil for none.
	Muted func(Source) bool
	// FirstOption answers every choice notice with its first option at once (an eval stand has no person; HRN-1561).
	FirstOption bool
	// Changed is told when the list changes (the page refreshes); nil for none.
	Changed func()
	// Journal is told when a notice opens ("open") and when it ends ("end", with its status), for the store to keep
	// nil for none. It is called with the slot's lock held, so it must only queue the news.
	Journal func(event string, n Notice, status string)
	// contains filtered or unexported fields
}

Slot is the machine's open notices.

func New

func New() *Slot

func (*Slot) Answer

func (s *Slot) Answer(id string, value json.RawMessage) error

Answer is the person's answer; it is checked against the notice's kind. A typed text that looks like a key is refused with ErrAnswerSecret and the notice stays open.

func (*Slot) Ask

func (s *Slot) Ask(ctx context.Context, src Source, conv string, sp Spec) (Result, error)

Ask shows a notice and waits for its result (a telling kind returns answered at once).

func (*Slot) Close

func (s *Slot) Close(src Source, id string) error

Close takes a notice away for its source (a progress that ended, a question no longer needed).

func (*Slot) Dismiss

func (s *Slot) Dismiss(id string) error

Dismiss is the person closing a notice (no answer).

func (*Slot) MuteSource

func (s *Slot) MuteSource(src Source)

MuteSource ends every open notice of a source the person just turned off.

func (*Slot) Open

func (s *Slot) Open(src Source, conv string, sp Spec) (Notice, error)

Open shows a notice and returns it at once; Wait gets its result. The same question from the same source in the same chat while the first is open joins it (its id comes back), so a caller that repeats itself shows one plate.

func (*Slot) Pending

func (s *Slot) Pending() []Notice

Pending is what the page shows: the open notices, oldest first; of one source in one chat only the first is shown, the rest are Queued behind it, and at most MaxShownPerSrc waiting ones of a source are shown on the machine.

func (*Slot) SourceOf

func (s *Slot) SourceOf(id string) (Source, bool)

SourceOf is who opened a notice (ok=false when there is none).

func (*Slot) Update

func (s *Slot) Update(src Source, id string, progress *float64, text *string, title *string) error

Update changes an open progress or status: its share done and its text. Only the source that opened it may.

func (*Slot) Wait

func (s *Slot) Wait(ctx context.Context, id string) (Result, bool)

Wait waits for a notice's result until ctx ends; done=false while it is still open. A finished notice gives its result once more for a while, so a caller polling again after a lost answer still gets it.

type Source

type Source struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
	Name string `json:"name"`
}

Source is who asks: an app (ID is its id, Name its name from the manifest) or the agent of a chat (ID is the chat). The page draws it as the label over the plate, which the caller cannot change.

func (Source) Key

func (s Source) Key() string

Key names the source for limits and muting.

type Spec

type Spec struct {
	Kind  Kind   `json:"kind"`
	Title string `json:"title"`
	Text  string `json:"text,omitempty"`
	// Icon is a harnessly icon name for the plate; empty for the kind's own.
	Icon string `json:"icon,omitempty"`
	// Options are a choice's 2…6 answers; Own adds a line for the person's own words.
	Options []string `json:"options,omitempty"`
	Own     bool     `json:"own,omitempty"`
	// Yes and No name a confirmation's buttons; Danger marks an action that cannot be undone.
	Yes    string `json:"yes,omitempty"`
	No     string `json:"no,omitempty"`
	Danger bool   `json:"danger,omitempty"`
	// Placeholder is a field's hint while it is empty (a field is one line).
	Placeholder string `json:"placeholder,omitempty"`
	// Digits is a code's length, 4…8.
	Digits int `json:"digits,omitempty"`
	// Progress is a progress's share done, 0…1; nil while it is not known.
	Progress *float64 `json:"progress,omitempty"`
	// View is a view of its own: an HTML fragment of layout and buttons (data-answer), drawn with the plate's tokens and kit.
	View string `json:"view,omitempty"`
	// TimeoutSec is how long it waits; 0 for the default, at most a day.
	TimeoutSec int `json:"timeoutSec,omitempty"`
}

Spec is what a caller asks to show.

type Tools

type Tools struct {
	S          *Slot
	Chat, Name string
	Why        string
}

Tools is the slot's MCP tools for one calling agent: Chat is its chat ("" when the runtime could not tell, Why says why), Name the chat's title for the label over the plate.

func (Tools) Call

func (t Tools) Call(ctx context.Context, name string, args *jsvalue.Object) *jsvalue.Object

func (Tools) Has

func (Tools) Has(name string) bool

func (Tools) Instructions

func (Tools) Instructions() string

func (Tools) Tools

func (Tools) Tools() []any

Jump to

Keyboard shortcuts

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