Documentation
¶
Overview ¶
Package parity parses upstream pi TypeScript declarations to drive parity tests. It extracts the ExtensionAPI surface (events + methods) and every Event / EventResult interface from .upstream/current/packages/coding-agent/src/core/extensions/types.ts.
The parser is regex-based and intentionally narrow. It does not implement a general TypeScript grammar: it relies on the upstream file using a consistent style (single-line `on(event: "...")` overloads, top-level `export interface XxxEvent {` blocks, etc.). If upstream restructures the file in a way that breaks the parser, the parser tests will fail loudly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelToGoField ¶
CamelToGoField converts upstream camelCase to Go PascalCase with idiomatic Go initialism handling at word boundaries.
Examples:
"toolCallId" → "ToolCallID" "newLeafId" → "NewLeafID" "baseUrl" → "BaseURL" "apiKey" → "APIKey" (leading initialism) "jsonValue" → "JSONValue" "id" → "ID" "customInstructions" → "CustomInstructions" (no change)
Word boundaries are detected as transitions from lower-case to upper-case after CamelToPascal is applied to the input. Each segment is tested against [goInitialisms]; matches are upper-cased.
func CamelToPascal ¶
CamelToPascal converts upstream camelCase to Go PascalCase. "registerTool" -> "RegisterTool", "exec" -> "Exec".
This helper is for METHOD names where Go style is plain PascalCase. For FIELD names that need idiomatic Go initialism handling (Id→ID, Url→URL, Api→API, Json→JSON), use CamelToGoField instead.
func SnakeEventToOnMethod ¶
SnakeEventToOnMethod converts an upstream event name to its expected Go `On*` method name. "tool_call" -> "OnToolCall", "session_before_compact" -> "OnSessionBeforeCompact".
Types ¶
type EventTypeDecl ¶
type EventTypeDecl struct {
Name string // e.g. "ToolCallEvent"
Fields map[string]string // fieldName -> raw TS type string
// FieldOrder preserves declaration order (maps don't).
FieldOrder []string
}
EventTypeDecl is the parsed shape of one `export interface XxxEvent {…}` or `XxxEventResult {…}` block.
type ExtensionAPISurface ¶
type ExtensionAPISurface struct {
// Events is the list of event names registrable via `on(event: "...")`,
// in declaration order, lower_snake_case as they appear in upstream.
Events []string
// Methods is the list of method names on ExtensionAPI other than `on`,
// in declaration order, camelCase as they appear in upstream.
Methods []string
}
ExtensionAPISurface is the parsed shape of upstream's ExtensionAPI interface.
type UpstreamSurface ¶
type UpstreamSurface struct {
API ExtensionAPISurface
EventTypes []EventTypeDecl // *Event interfaces (excluding *EventResult)
EventResults []EventTypeDecl // *EventResult interfaces
}
UpstreamSurface is the full parsed snapshot.
func LoadUpstream ¶
func LoadUpstream() (*UpstreamSurface, error)
LoadUpstream parses the upstream types.ts at the well-known path.
func LoadUpstreamFrom ¶
func LoadUpstreamFrom(src string) (*UpstreamSurface, error)
LoadUpstreamFrom parses TypeScript source from an explicit string. Used by parser self-tests against fixture inputs.