Documentation
¶
Overview ¶
Neutral provider model types (ADR-0005; change 0018). The agent loop, tools, memory, and compose packages depend on these types — never on an Anthropic- or OpenAI-shaped type.
Package ports declares the eleven seams the OpenPlus core depends on (T-004, design.md; changes 0018 and 0026). It is the single place to read the architecture: the core talks to these interfaces, and every external system is an adapter behind one of them.
The canonical Provider port and all provider-neutral model types (Request, Event, Message, Block, BlockKind, Role, ToolSchema, ToolCall, Usage, EventKind) live in this package — split across model.go (types) and provider.go (the Provider interface itself). The scripted test Fake lives in internal/ports/providerfake. The concrete adapters (internal/provider/anthropic, internal/provider/openaicompat, internal/provider/select) implement ports.Provider; the core never imports them.
A leak-guard test (internal/ports/leak_guard_test.go) fails the build if any package outside internal/provider/ and internal/ports/ reaches back into the adapter package.
Index ¶
- Variables
- func PortNames() []string
- type Block
- type BlockKind
- type Budgeter
- type Checkpointer
- type Diagnostic
- type Embedder
- type Event
- type EventKind
- type FakeBudgeter
- type FakeCheckpointer
- type FakeEmbedder
- type FakeLanguageService
- func (f FakeLanguageService) Definition(context.Context, string, int, int) ([]Location, error)
- func (f FakeLanguageService) Diagnostics(context.Context, string) ([]Diagnostic, error)
- func (f FakeLanguageService) DocumentSymbols(context.Context, string) ([]Symbol, error)
- func (f FakeLanguageService) Hover(context.Context, string, int, int) (string, error)
- func (f FakeLanguageService) References(context.Context, string, int, int) ([]Location, error)
- func (f FakeLanguageService) Shutdown(context.Context) error
- type FakeMemoryStore
- type FakePolicyGate
- type FakeProvider
- type FakeSkillIndex
- type FakeTokenizer
- type FakeTool
- type FakeWorkflow
- type LanguageService
- type Location
- type MemoryStore
- type Message
- type PolicyGate
- type Provider
- type Request
- type Role
- type Severity
- type SkillIndex
- type Symbol
- type Tokenizer
- type Tool
- type ToolCall
- type ToolSchema
- type Usage
- type Workflow
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = errors.New("ports: not implemented by this fake")
ErrNotImplemented is returned by fakes that deliberately refuse an operation.
Functions ¶
Types ¶
type Block ¶
type Block struct {
Kind BlockKind
// BlockText
Text string
// BlockToolCall
ToolCallID string
ToolName string
ToolInput []byte // raw JSON args, accumulated from streamed deltas
// BlockToolResult
ToolResultForID string
ToolResultText string
ToolResultError bool
// BlockImage
ImageMIME string
ImageData []byte
}
Block is one neutral unit of message content.
type Checkpointer ¶
type Checkpointer interface {
ShouldCheckpoint(used int) bool
Save(state string) error
Load() (string, error)
}
Checkpointer snapshots and restores session state (ADR-0008).
type Diagnostic ¶
type Diagnostic struct {
Path string // file the problem is in, relative to the project root
Line int // 1-based
Column int // 1-based
Severity Severity
Message string
Source string // which tool produced it ("compiler", "vet", …); may be empty
}
Diagnostic is one problem reported in a file: a compiler error, a vet warning, a linter hint.
type Embedder ¶
type Embedder interface {
Embed(ctx context.Context, texts []string) ([][]float32, error)
Dim() int
}
Embedder turns text into vectors (ADR-0004).
type Event ¶
Event is one streamed unit from a Provider. TextDelta carries Text; ToolCallStart/ToolArgsDelta carry partial tool-call state the adapter accumulates internally, surfaced to the caller only as a completed ToolCall on the turn's TurnEnd event (see Turn.ToolCalls in loop.go).
type FakeCheckpointer ¶
type FakeCheckpointer struct {
// contains filtered or unexported fields
}
FakeCheckpointer stores one state string in memory and never asks to checkpoint.
func (*FakeCheckpointer) Load ¶
func (c *FakeCheckpointer) Load() (string, error)
func (*FakeCheckpointer) Save ¶
func (c *FakeCheckpointer) Save(state string) error
func (*FakeCheckpointer) ShouldCheckpoint ¶
func (*FakeCheckpointer) ShouldCheckpoint(int) bool
type FakeEmbedder ¶
type FakeEmbedder struct {
Dimension int
}
FakeEmbedder returns deterministic vectors of a fixed dimension.
func (FakeEmbedder) Dim ¶
func (f FakeEmbedder) Dim() int
type FakeLanguageService ¶
type FakeLanguageService struct {
Diags []Diagnostic
HoverText string
Locs []Location
Syms []Symbol
}
FakeLanguageService returns canned answers. It lets tests exercise LSP-dependent code without spawning a language server.
func (FakeLanguageService) Definition ¶
func (FakeLanguageService) Diagnostics ¶
func (f FakeLanguageService) Diagnostics(context.Context, string) ([]Diagnostic, error)
func (FakeLanguageService) DocumentSymbols ¶
func (FakeLanguageService) References ¶
type FakeMemoryStore ¶
type FakeMemoryStore struct {
// contains filtered or unexported fields
}
FakeMemoryStore is an in-memory substring-matching store.
type FakePolicyGate ¶
type FakePolicyGate struct {
DenyAll bool
}
FakePolicyGate allows everything unless DenyAll is set.
type FakeSkillIndex ¶
type FakeSkillIndex struct {
Names []string
}
FakeSkillIndex matches skills by substring.
type FakeTokenizer ¶
type FakeTokenizer struct{}
FakeTokenizer counts whitespace-separated words.
func (FakeTokenizer) Count ¶
func (FakeTokenizer) Count(text string) int
type FakeTool ¶
FakeTool returns a canned result.
func (FakeTool) Description ¶
func (FakeTool) Schema ¶
func (f FakeTool) Schema() json.RawMessage
type FakeWorkflow ¶
type FakeWorkflow struct {
PhaseNames []string
}
FakeWorkflow reports named phases and honors cancellation.
func (FakeWorkflow) Phases ¶
func (f FakeWorkflow) Phases() []string
type LanguageService ¶
type LanguageService interface {
// Diagnostics reports the current problems in one file. It returns the
// latest known set; an implementation backed by a push-notification
// protocol serves what the server last published.
Diagnostics(ctx context.Context, path string) ([]Diagnostic, error)
// Hover describes the symbol at a position — typically its signature and
// doc comment, rendered as text.
Hover(ctx context.Context, path string, line, col int) (string, error)
// Definition locates where the symbol at a position is defined.
Definition(ctx context.Context, path string, line, col int) ([]Location, error)
// DocumentSymbols lists the symbols declared in one file.
DocumentSymbols(ctx context.Context, path string) ([]Symbol, error)
// References finds the uses of the symbol at a position.
References(ctx context.Context, path string, line, col int) ([]Location, error)
// Shutdown stops every language server this service started. It is
// idempotent so a deferred call after an error path is safe.
Shutdown(ctx context.Context) error
}
LanguageService is the code-intelligence seam (ADR-0017, change 0026): the eleventh port. It answers read-only questions about source code — what is broken, what a symbol means, where it is defined, and who uses it.
Every surface is read-only. Mutating surfaces (code actions, rename, apply-edit) are deliberately absent: they need a gating story of their own.
Neutrality rule (hard rule, ADR-0017): no LSP wire type may appear in this interface or in any type it returns. The concrete adapter in internal/lsp/ converts protocol values to the neutral types below at its boundary, exactly as internal/provider converts provider wire types to the neutral model. The regression guard internal/ports/lsp_leak_guard_test.go fails the build if a go.lsp.dev type reaches this package.
Positions are 1-based line and column numbers — what a human reads in an editor and what a compiler prints. The adapter converts from LSP's 0-based UTF-16 positions.
type Location ¶
type Location struct {
Path string // relative to the project root
Line int // 1-based
Column int // 1-based
}
Location points at a span of source — where something is defined, or one place it is used.
type MemoryStore ¶
type MemoryStore interface {
Write(ctx context.Context, text, source string) (int64, error)
Search(ctx context.Context, query string, k int) ([]string, error)
}
MemoryStore persists and retrieves memory chunks (ADR-0003).
type PolicyGate ¶
PolicyGate authorizes tool calls (ADR-0007).
type Provider ¶
type Provider interface {
// Stream sends req and returns a channel of Events. The channel is
// closed when the turn ends (after an EventTurnEnd) or ctx is done.
Stream(ctx context.Context, req Request) (<-chan Event, error)
}
Provider is the single port the agent loop depends on. Every model backend — Anthropic, OpenAI-compatible, or a test fake — implements this.
type Request ¶
type Request struct {
Model string // "<provider>/<model>", e.g. "anthropic/claude-…" or "local/qwen2.5-coder"
System string
Messages []Message
Tools []ToolSchema
Thinking bool
}
Request is a provider-neutral request for one turn.
type Severity ¶
type Severity int
Severity ranks a diagnostic. The zero value is SeverityError, so a diagnostic that loses its severity in translation is surfaced rather than silently demoted to a hint.
type SkillIndex ¶
SkillIndex discovers and ranks skills (ADR-0002).
type Symbol ¶
type Symbol struct {
Name string
Kind string // "func", "type", "var", … (the adapter maps LSP's numeric kinds)
Path string
Line int // 1-based
}
Symbol is one declaration in a file.
type Tool ¶
type Tool interface {
Name() string
Description() string
Schema() json.RawMessage
Execute(ctx context.Context, input json.RawMessage) (string, error)
}
Tool is one callable capability exposed to the model.
type ToolSchema ¶
ToolSchema describes a tool the model may call, in neutral form. Each adapter maps this to its native shape (Anthropic input_schema, OpenAI-compatible function.parameters).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package portsfake provides a scripted Provider for tests and for proving the agent loop without any network access or API key (change 0018; formerly provider.Fake in internal/provider/fake.go).
|
Package portsfake provides a scripted Provider for tests and for proving the agent loop without any network access or API key (change 0018; formerly provider.Fake in internal/provider/fake.go). |