Documentation
¶
Overview ¶
Package interject answers a message that arrives while a conversation's main turn is still running, without stopping it.
The relay forks the main session (session/fork), asks the fork the new message, posts the fork's short answer at once, and lets the fork's own verdict decide what happens to the main turn:
None — the answer was enough; main continues untouched.
Queue — main continues; the message is held for the next prompt.
Steer — cancel main and re-prompt it with the message (the old
behaviour).
Abort — cancel main only.
Nothing is spliced into the main transcript. The side Q&A of the running turn (and any queued messages) is handed back once, by Take, as a prefix for the next main prompt. Every interrupt forks afresh, so each sees the main turn's latest progress; earlier side Q&A of the same turn is carried into the fork as text.
Index ¶
Constants ¶
const DefaultMinConf = 7
DefaultMinConf is the confidence below which a verdict becomes None.
const Instruction = `` /* 411-byte string literal not displayed */
Instruction is the rule appended to every fork prompt.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action int
Action is the fork's verdict on the main turn.
type Agent ¶
type Agent interface {
ForkSession(ctx context.Context, cwd string, parent acp.SessionId, at string, sink client.SessionUpdateSink) (acp.SessionId, error)
Prompt(ctx context.Context, sid acp.SessionId, prompt []acp.ContentBlock) (acp.StopReason, error)
CloseSession(ctx context.Context, sid acp.SessionId) error
}
Agent is the agent surface used. *client.AgentProc satisfies it.
type Config ¶
type Config struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// MinConf (0-9) is the confidence a verdict needs to act; 0 means
// DefaultMinConf.
MinConf int `json:"min_conf" yaml:"min_conf"`
}
Config is the relay's opt-in. The zero value is disabled.
type Interjector ¶
type Interjector struct {
// contains filtered or unexported fields
}
Interjector keeps the per-conversation side state. Safe for concurrent use.
func New ¶
func New(agent Agent, cfg Config) *Interjector
New returns an Interjector, or nil when cfg is disabled — so a relay can test `ij != nil`.
func (*Interjector) Ask ¶
func (i *Interjector) Ask(ctx context.Context, conv, cwd string, parent acp.SessionId, text string) (Reply, error)
Ask forks parent, asks it text and returns the answer. On a fork error (including client.ErrForkUnsupported) the caller falls back to its old behaviour. The fork is closed before Ask returns. Bound ctx: the fork prompt has no timeout of its own. Text may be empty when the fork gave only a verdict.
func (*Interjector) Queued ¶
func (i *Interjector) Queued(conv string) bool
Queued reports whether conv holds queued messages that need a main turn to deliver them.
func (*Interjector) Take ¶
func (i *Interjector) Take(conv string) string
Take returns the prefix for conv's next main prompt — the side Q&A digest and queued messages — and resets conv's side state. "" when there is none. Call it when building every main prompt: that is the merge, and it is what resets the side state for the next turn.