Documentation
¶
Overview ¶
Package modes corresponds to pi's packages/coding-agent/src/modes.
pi: modes/json-event.ts — session event shape emitted by the JSON and RPC stdout protocols: cumulative assistant snapshots are stripped from streaming wire events (message_start provides the initial message, deltas build it, and message_end provides the final authoritative message). Cumulative usage, tool-call ids, and tool names remain available because their size is constant. pig's AssistantMessageEvent already carries toolCall as a typed field, so pi's content-index extraction collapses to reading event.ToolCall.
pi: modes/print-mode.ts — print mode (single-shot): send prompts, output result, exit. Used for `pig -p "prompt"` (text output) and `pig --mode json "prompt"` (JSON event stream).
pig declares a PrintRuntimeHost interface instead of depending on the concrete core.AgentSessionRuntime (pi: runtimeHost: AgentSessionRuntime) — the method set used here is exactly pi's consumption surface, and the interface keeps the mode testable without the runtime constructor.
Index ¶
- func MarshalJsonEvent(event any) ([]byte, error)
- func RunPrintMode(ctx context.Context, runtimeHost PrintRuntimeHost, options PrintModeOptions) int
- func ToJsonEvent(event core.AgentSessionEvent) (any, error)
- type JsonAgentSessionEvent
- type JsonAssistantMessageEvent
- type JsonMessageUpdateEvent
- type PrintModeOptions
- type PrintRuntimeHost
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalJsonEvent ¶
MarshalJsonEvent renders one wire event as JSON (pi's JSON.stringify call site in print-mode).
func RunPrintMode ¶
func RunPrintMode(ctx context.Context, runtimeHost PrintRuntimeHost, options PrintModeOptions) int
RunPrintMode runs in print (single-shot) mode: sends prompts to the agent and outputs the result (pi: runPrintMode). Returns the process exit code.
func ToJsonEvent ¶
func ToJsonEvent(event core.AgentSessionEvent) (any, error)
ToJsonEvent removes cumulative assistant snapshots from streaming wire events (pi: toJsonEvent). Returns the event unchanged for non message_update types.
Types ¶
type JsonAgentSessionEvent ¶
type JsonAgentSessionEvent = core.AgentSessionEvent
JsonAgentSessionEvent is the wire event (pi: JsonAgentSessionEvent).
type JsonAssistantMessageEvent ¶
type JsonAssistantMessageEvent struct {
types.AssistantMessageEvent
ID string `json:"id,omitempty"`
ToolName string `json:"toolName,omitempty"`
}
JsonAssistantMessageEvent is AssistantMessageEvent plus the toolcall_start id/toolName fields (pi's { ...deltaEvent, id, toolName } spread). The embedded struct's fields marshal inline.
type JsonMessageUpdateEvent ¶
type JsonMessageUpdateEvent struct {
Type string `json:"type"`
Usage *types.Usage `json:"usage"`
AssistantMessageEvent JsonAssistantMessageEvent `json:"assistantMessageEvent"`
}
JsonMessageUpdateEvent is the message_update event with the assistant snapshot removed (pi: JsonMessageUpdateEvent; pig's AssistantMessageEvent clears Partial instead of omitting the key — the JSON shape keeps "partial" absent via omitempty).
type PrintModeOptions ¶
type PrintModeOptions struct {
// Mode is the output mode: "text" for final response only, "json" for
// all events.
Mode string
// Messages are additional prompts to send after InitialMessage.
Messages []string
// InitialMessage is the first message to send (may contain @file
// content); "" = none.
InitialMessage string
// InitialImages are images attached to the initial message.
InitialImages []types.ImageContent
}
PrintModeOptions are the print mode options (pi: PrintModeOptions).
type PrintRuntimeHost ¶
type PrintRuntimeHost interface {
Session() *core.AgentSession
NewSession(ctx context.Context, options *core.RuntimeNewSessionOptions) (cancelled bool, err error)
Fork(ctx context.Context, entryID string, options *core.ForkOptions) (*core.ForkResult, error)
SwitchSession(ctx context.Context, sessionPath string, options *core.SwitchSessionOptions) (cancelled bool, err error)
Dispose() error
SetRebindSession(rebindSession func(session *core.AgentSession) error)
}
PrintRuntimeHost is the runtime host consumption surface (pi: AgentSessionRuntime's members used by runPrintMode).
Directories
¶
| Path | Synopsis |
|---|---|
|
chat_viewport.go (pi: modes/interactive/chat-viewport.ts, v0.85.1) — shared fullscreen transcript and fixed input-dock layout.
|
chat_viewport.go (pi: modes/interactive/chat-viewport.ts, v0.85.1) — shared fullscreen transcript and fixed input-dock layout. |
|
components
armin.go (pi: components/armin.ts) — "Armin says hi!" easter egg with animated half-block XBM art and 7 random effects.
|
armin.go (pi: components/armin.ts) — "Armin says hi!" easter egg with animated half-block XBM art and 7 random effects. |
|
theme
fs_watch.go (pi: src/modes/interactive/theme — theme file watching).
|
fs_watch.go (pi: src/modes/interactive/theme — theme file watching). |
|
Package rpc corresponds to pi's packages/coding-agent/src/modes/rpc.
|
Package rpc corresponds to pi's packages/coding-agent/src/modes/rpc. |