| 1 | package protocol |
| 2 | |
| 3 | import "encoding/json" |
| 4 | |
| 5 | // Lifecycle DTOs: initialize handshake, initialized notification, graceful |
| 6 | // shutdown, event observation, and resource change notification. |
| 7 | |
| 8 | // InitializeParams is the host's opening handshake. The sidecar must answer |
| 9 | // with InitializeResult before any other method runs. |
| 10 | type InitializeParams struct { |
| 11 | ProtocolVersion string `json:"protocolVersion" validate:"nonempty"` |
| 12 | ProtocolID string `json:"protocolId" validate:"nonempty"` |
| 13 | Manifest ManifestExpectation `json:"manifest"` |
| 14 | Session SessionContext `json:"session"` |
| 15 | Capabilities HostCapabilities `json:"capabilities"` |
| 16 | } |
| 17 | |
| 18 | // ManifestExpectation is what the host will accept from this extension, |
| 19 | // derived from its installed manifest. The sidecar must not use anything |
| 20 | // outside this set; doing so fails with capability_not_declared. |
| 21 | type ManifestExpectation struct { |
| 22 | Intercepts []string `json:"intercepts,omitempty"` |
| 23 | Replaces []string `json:"replaces,omitempty"` |
| 24 | Providers []string `json:"providers,omitempty"` |
| 25 | UIActions []string `json:"uiActions,omitempty"` |
| 26 | Capabilities []string `json:"capabilities,omitempty"` |
| 27 | } |
| 28 | |
| 29 | // SessionContext identifies the session the extension serves. |
| 30 | type SessionContext struct { |
| 31 | SessionID string `json:"sessionId" validate:"nonempty"` |
| 32 | WorkspaceRoot string `json:"workspaceRoot" validate:"nonempty"` |
| 33 | Generation uint64 `json:"generation"` |
| 34 | } |
| 35 | |
| 36 | // HostCapabilities tells the sidecar what this host supports. |
| 37 | type HostCapabilities struct { |
| 38 | ContentRefs bool `json:"contentRefs"` |
| 39 | UIHost UIHostKind `json:"uiHost"` |
| 40 | ProtocolVersion string `json:"protocolVersion" validate:"nonempty"` |
| 41 | } |
| 42 | |
| 43 | // InitializeResult is the sidecar's handshake answer: its identity plus the |
| 44 | // contributions it actually activated for this session. |
| 45 | type InitializeResult struct { |
| 46 | ProtocolVersion string `json:"protocolVersion" validate:"nonempty"` |
| 47 | Name string `json:"name" validate:"nonempty"` |
| 48 | Version string `json:"version" validate:"nonempty"` |
| 49 | Subscriptions []string `json:"subscriptions,omitempty"` |
| 50 | Replaces []string `json:"replaces,omitempty"` |
| 51 | Providers []ProviderDescriptor `json:"providers,omitempty"` |
| 52 | UIActions []UIActionDecl `json:"uiActions,omitempty"` |
| 53 | StateSchemaVersion int `json:"stateSchemaVersion" validate:"min=0"` |
| 54 | } |
| 55 | |
| 56 | // InitializedParams carries no payload; the notification only signals the |
| 57 | // sidecar may start receiving intercepts and events. |
| 58 | type InitializedParams struct{} |
| 59 | |
| 60 | // ShutdownParams requests a graceful stop. The sidecar must answer within |
| 61 | // TimeoutMillis or the host reports shutdown_timeout and kills the process. |
| 62 | type ShutdownParams struct { |
| 63 | TimeoutMillis int `json:"timeoutMillis" validate:"min=0"` |
| 64 | } |
| 65 | |
| 66 | // ShutdownResult acknowledges the shutdown request. |
| 67 | type ShutdownResult struct { |
| 68 | Accepted bool `json:"accepted"` |
| 69 | } |
| 70 | |
| 71 | // EventParams is the fire-and-forget observation of one of the 17 hook |
| 72 | // points. Unlike extension/intercept, the extension's answer (if any) is |
| 73 | // discarded and cannot change host behavior. When Payload exceeds |
| 74 | // ExternalizeFieldBytes it travels as null and Externalized carries its |
| 75 | // content-ref descriptor. |
| 76 | type EventParams struct { |
| 77 | Event InterceptEvent `json:"event"` |
| 78 | Payload json.RawMessage `json:"payload" externalizable:"true"` |
| 79 | Externalized []ExternalizedField `json:"externalized,omitempty"` |
| 80 | } |
| 81 | |
| 82 | // ResourcesChangedParams notifies the extension that watched resources |
| 83 | // (skills, commands, prompts, themes, …) changed on disk. |
| 84 | type ResourcesChangedParams struct { |
| 85 | Paths []string `json:"paths"` |
| 86 | } |
| 87 |