Remove unused Codex protocol registries and session APIs

This commit is contained in:
Ian Gulliver
2026-10-22 10:38:02 -07:00
parent 406f67a1a0
commit 8fb27f98a2
3 changed files with 110 additions and 223 deletions
+4 -17
View File
@@ -19,8 +19,6 @@ var clientMethods = []string{
"thread/start",
"thread/resume",
"thread/fork",
"thread/read",
"thread/compact/start",
"turn/start",
"turn/steer",
"turn/interrupt",
@@ -269,22 +267,11 @@ func (g *gen) generate(version string) []byte {
}
h.WriteString(")\n\n")
writeTable := func(name string, ms []method, field func(method) string) {
fmt.Fprintf(&h, "var %s = map[string]func() any{\n", name)
for _, m := range ms {
t := field(m)
if t == "" {
fmt.Fprintf(&h, "Method%s: nil,\n", pascal(m.name))
continue
}
fmt.Fprintf(&h, "Method%s: func() any { return &%s{} },\n", pascal(m.name), t)
}
h.WriteString("}\n\n")
h.WriteString("var notificationMethods = map[string]struct{}{\n")
for _, m := range notifications {
fmt.Fprintf(&h, "Method%s: {},\n", pascal(m.name))
}
writeTable("clientResults", client, func(m method) string { return m.response })
writeTable("notificationParams", notifications, func(m method) string { return m.params })
writeTable("serverRequestParams", requests, func(m method) string { return m.params })
writeTable("serverRequestResponses", requests, func(m method) string { return m.response })
h.WriteString("}\n\n")
h.Write(g.consts.Bytes())
h.Write(g.out.Bytes())
+101 -160
View File
@@ -11,8 +11,6 @@ const (
MethodThreadStart = "thread/start"
MethodThreadResume = "thread/resume"
MethodThreadFork = "thread/fork"
MethodThreadCompactStart = "thread/compact/start"
MethodThreadRead = "thread/read"
MethodTurnStart = "turn/start"
MethodTurnSteer = "turn/steer"
MethodTurnInterrupt = "turn/interrupt"
@@ -115,133 +113,92 @@ const (
MethodExecCommandApproval = "execCommandApproval"
)
var clientResults = map[string]func() any{
MethodInitialize: func() any { return &InitializeResponse{} },
MethodThreadStart: func() any { return &ThreadStartResponse{} },
MethodThreadResume: func() any { return &ThreadResumeResponse{} },
MethodThreadFork: func() any { return &ThreadForkResponse{} },
MethodThreadCompactStart: func() any { return &ThreadCompactStartResponse{} },
MethodThreadRead: func() any { return &ThreadReadResponse{} },
MethodTurnStart: func() any { return &TurnStartResponse{} },
MethodTurnSteer: func() any { return &TurnSteerResponse{} },
MethodTurnInterrupt: func() any { return &TurnInterruptResponse{} },
MethodAccountRateLimitsRead: func() any { return &GetAccountRateLimitsResponse{} },
}
var notificationParams = map[string]func() any{
MethodError: func() any { return &ErrorNotification{} },
MethodThreadStarted: func() any { return &ThreadStartedNotification{} },
MethodThreadStatusChanged: func() any { return &ThreadStatusChangedNotification{} },
MethodThreadReadStateChanged: func() any { return &ThreadReadStateChangedNotification{} },
MethodThreadArchived: func() any { return &ThreadArchivedNotification{} },
MethodThreadDeleted: func() any { return &ThreadDeletedNotification{} },
MethodThreadUnarchived: func() any { return &ThreadUnarchivedNotification{} },
MethodThreadClosed: func() any { return &ThreadClosedNotification{} },
MethodThreadReverted: func() any { return &ThreadRevertedNotification{} },
MethodSkillsChanged: func() any { return &SkillsChangedNotification{} },
MethodThreadNameUpdated: func() any { return &ThreadNameUpdatedNotification{} },
MethodThreadAttachmentUpdated: func() any { return &ThreadAttachmentUpdatedNotification{} },
MethodThreadGoalUpdated: func() any { return &ThreadGoalUpdatedNotification{} },
MethodThreadPredictionUpdated: func() any { return &ThreadPredictionUpdatedNotification{} },
MethodThreadGoalCleared: func() any { return &ThreadGoalClearedNotification{} },
MethodThreadQueueChanged: func() any { return &ThreadQueueChangedNotification{} },
MethodProjectChanged: func() any { return &ProjectChangedNotification{} },
MethodThreadProjectUpdated: func() any { return &ThreadProjectUpdatedNotification{} },
MethodThreadEnvironmentConnected: func() any { return &EnvironmentConnectionNotification{} },
MethodThreadEnvironmentDisconnected: func() any { return &EnvironmentConnectionNotification{} },
MethodThreadSettingsUpdated: func() any { return &ThreadSettingsUpdatedNotification{} },
MethodThreadTokenUsageUpdated: func() any { return &ThreadTokenUsageUpdatedNotification{} },
MethodTurnStarted: func() any { return &TurnStartedNotification{} },
MethodHookStarted: func() any { return &HookStartedNotification{} },
MethodTurnCompleted: func() any { return &TurnCompletedNotification{} },
MethodHookCompleted: func() any { return &HookCompletedNotification{} },
MethodTurnDiffUpdated: func() any { return &TurnDiffUpdatedNotification{} },
MethodTurnPlanUpdated: func() any { return &TurnPlanUpdatedNotification{} },
MethodItemStarted: func() any { return &ItemStartedNotification{} },
MethodItemAutoApprovalReviewStarted: func() any { return &ItemGuardianApprovalReviewStartedNotification{} },
MethodItemAutoApprovalReviewCompleted: func() any { return &ItemGuardianApprovalReviewCompletedNotification{} },
MethodAutoApprovalReviewStrictReviewRequired: func() any { return &StrictReviewRequiredNotification{} },
MethodItemCompleted: func() any { return &ItemCompletedNotification{} },
MethodItemAgentMessageDelta: func() any { return &AgentMessageDeltaNotification{} },
MethodItemPlanDelta: func() any { return &PlanDeltaNotification{} },
MethodCommandExecOutputDelta: func() any { return &CommandExecOutputDeltaNotification{} },
MethodProcessOutputDelta: func() any { return &ProcessOutputDeltaNotification{} },
MethodProcessExited: func() any { return &ProcessExitedNotification{} },
MethodItemCommandExecutionOutputDelta: func() any { return &CommandExecutionOutputDeltaNotification{} },
MethodItemCommandExecutionTerminalInteraction: func() any { return &TerminalInteractionNotification{} },
MethodItemFileChangeOutputDelta: func() any { return &FileChangeOutputDeltaNotification{} },
MethodItemFileChangePatchUpdated: func() any { return &FileChangePatchUpdatedNotification{} },
MethodServerRequestResolved: func() any { return &ServerRequestResolvedNotification{} },
MethodItemMcpToolCallProgress: func() any { return &McpToolCallProgressNotification{} },
MethodMcpServerOauthLoginCompleted: func() any { return &McpServerOauthLoginCompletedNotification{} },
MethodMcpServerStartupStatusUpdated: func() any { return &McpServerStatusUpdatedNotification{} },
MethodMcpServerEventStreamNotification: func() any { return &McpServerEventStreamNotification{} },
MethodAccountUpdated: func() any { return &AccountUpdatedNotification{} },
MethodAccountGatewayOAuthChanged: func() any { return &GatewayOAuthChangedNotification{} },
MethodAccountRateLimitsUpdated: func() any { return &AccountRateLimitsUpdatedNotification{} },
MethodAppListUpdated: func() any { return &AppListUpdatedNotification{} },
MethodRemoteControlStatusChanged: func() any { return &RemoteControlStatusChangedNotification{} },
MethodExternalAgentConfigImportProgress: func() any { return &ExternalAgentConfigImportProgressNotification{} },
MethodExternalAgentConfigImportCompleted: func() any { return &ExternalAgentConfigImportCompletedNotification{} },
MethodFsChanged: func() any { return &FsChangedNotification{} },
MethodItemReasoningSummaryTextDelta: func() any { return &ReasoningSummaryTextDeltaNotification{} },
MethodItemReasoningSummaryPartAdded: func() any { return &ReasoningSummaryPartAddedNotification{} },
MethodItemReasoningTextDelta: func() any { return &ReasoningTextDeltaNotification{} },
MethodThreadCompacted: func() any { return &ContextCompactedNotification{} },
MethodModelRerouted: func() any { return &ModelReroutedNotification{} },
MethodModelVerification: func() any { return &ModelVerificationNotification{} },
MethodModelProviderAuthRecoveryStarted: func() any { return &AuthRecoveryNotification{} },
MethodModelProviderAuthRecoveryCompleted: func() any { return &AuthRecoveryNotification{} },
MethodTurnModerationMetadata: func() any { return &TurnModerationMetadataNotification{} },
MethodModelSafetyBufferingUpdated: func() any { return &ModelSafetyBufferingUpdatedNotification{} },
MethodWarning: func() any { return &WarningNotification{} },
MethodGuardianWarning: func() any { return &GuardianWarningNotification{} },
MethodDeprecationNotice: func() any { return &DeprecationNoticeNotification{} },
MethodConfigWarning: func() any { return &ConfigWarningNotification{} },
MethodFuzzyFileSearchSessionUpdated: func() any { return &FuzzyFileSearchSessionUpdatedNotification{} },
MethodFuzzyFileSearchSessionCompleted: func() any { return &FuzzyFileSearchSessionCompletedNotification{} },
MethodThreadRealtimeStarted: func() any { return &ThreadRealtimeStartedNotification{} },
MethodThreadRealtimeItemAdded: func() any { return &ThreadRealtimeItemAddedNotification{} },
MethodThreadRealtimeItemStarted: func() any { return &ThreadRealtimeItemStartedNotification{} },
MethodThreadRealtimeItemTranscriptDelta: func() any { return &ThreadRealtimeItemTranscriptDeltaNotification{} },
MethodThreadRealtimeItemCompleted: func() any { return &ThreadRealtimeItemCompletedNotification{} },
MethodThreadRealtimeTranscriptDelta: func() any { return &ThreadRealtimeTranscriptDeltaNotification{} },
MethodThreadRealtimeTranscriptDone: func() any { return &ThreadRealtimeTranscriptDoneNotification{} },
MethodThreadRealtimeOutputAudioDelta: func() any { return &ThreadRealtimeOutputAudioDeltaNotification{} },
MethodThreadRealtimeSdp: func() any { return &ThreadRealtimeSdpNotification{} },
MethodThreadRealtimeError: func() any { return &ThreadRealtimeErrorNotification{} },
MethodThreadRealtimeClosed: func() any { return &ThreadRealtimeClosedNotification{} },
MethodWindowsWorldWritableWarning: func() any { return &WindowsWorldWritableWarningNotification{} },
MethodWindowsSandboxSetupCompleted: func() any { return &WindowsSandboxSetupCompletedNotification{} },
MethodAccountLoginCompleted: func() any { return &AccountLoginCompletedNotification{} },
}
var serverRequestParams = map[string]func() any{
MethodItemCommandExecutionRequestApproval: func() any { return &CommandExecutionRequestApprovalParams{} },
MethodItemFileChangeRequestApproval: func() any { return &FileChangeRequestApprovalParams{} },
MethodItemToolRequestUserInput: func() any { return &ToolRequestUserInputParams{} },
MethodMcpServerElicitationRequest: func() any { return &McpServerElicitationRequestParams{} },
MethodItemPermissionsRequestApproval: func() any { return &PermissionsRequestApprovalParams{} },
MethodItemToolCall: func() any { return &DynamicToolCallParams{} },
MethodAccountChatgptAuthTokensRefresh: func() any { return &ChatgptAuthTokensRefreshParams{} },
MethodAttestationGenerate: func() any { return &AttestationGenerateParams{} },
MethodCurrentTimeRead: func() any { return &CurrentTimeReadParams{} },
MethodApplyPatchApproval: func() any { return &ApplyPatchApprovalParams{} },
MethodExecCommandApproval: func() any { return &ExecCommandApprovalParams{} },
}
var serverRequestResponses = map[string]func() any{
MethodItemCommandExecutionRequestApproval: func() any { return &CommandExecutionRequestApprovalResponse{} },
MethodItemFileChangeRequestApproval: func() any { return &FileChangeRequestApprovalResponse{} },
MethodItemToolRequestUserInput: func() any { return &ToolRequestUserInputResponse{} },
MethodMcpServerElicitationRequest: func() any { return &McpServerElicitationRequestResponse{} },
MethodItemPermissionsRequestApproval: func() any { return &PermissionsRequestApprovalResponse{} },
MethodItemToolCall: func() any { return &DynamicToolCallResponse{} },
MethodAccountChatgptAuthTokensRefresh: func() any { return &ChatgptAuthTokensRefreshResponse{} },
MethodAttestationGenerate: func() any { return &AttestationGenerateResponse{} },
MethodCurrentTimeRead: func() any { return &CurrentTimeReadResponse{} },
MethodApplyPatchApproval: func() any { return &ApplyPatchApprovalResponse{} },
MethodExecCommandApproval: func() any { return &ExecCommandApprovalResponse{} },
var notificationMethods = map[string]struct{}{
MethodError: {},
MethodThreadStarted: {},
MethodThreadStatusChanged: {},
MethodThreadReadStateChanged: {},
MethodThreadArchived: {},
MethodThreadDeleted: {},
MethodThreadUnarchived: {},
MethodThreadClosed: {},
MethodThreadReverted: {},
MethodSkillsChanged: {},
MethodThreadNameUpdated: {},
MethodThreadAttachmentUpdated: {},
MethodThreadGoalUpdated: {},
MethodThreadPredictionUpdated: {},
MethodThreadGoalCleared: {},
MethodThreadQueueChanged: {},
MethodProjectChanged: {},
MethodThreadProjectUpdated: {},
MethodThreadEnvironmentConnected: {},
MethodThreadEnvironmentDisconnected: {},
MethodThreadSettingsUpdated: {},
MethodThreadTokenUsageUpdated: {},
MethodTurnStarted: {},
MethodHookStarted: {},
MethodTurnCompleted: {},
MethodHookCompleted: {},
MethodTurnDiffUpdated: {},
MethodTurnPlanUpdated: {},
MethodItemStarted: {},
MethodItemAutoApprovalReviewStarted: {},
MethodItemAutoApprovalReviewCompleted: {},
MethodAutoApprovalReviewStrictReviewRequired: {},
MethodItemCompleted: {},
MethodItemAgentMessageDelta: {},
MethodItemPlanDelta: {},
MethodCommandExecOutputDelta: {},
MethodProcessOutputDelta: {},
MethodProcessExited: {},
MethodItemCommandExecutionOutputDelta: {},
MethodItemCommandExecutionTerminalInteraction: {},
MethodItemFileChangeOutputDelta: {},
MethodItemFileChangePatchUpdated: {},
MethodServerRequestResolved: {},
MethodItemMcpToolCallProgress: {},
MethodMcpServerOauthLoginCompleted: {},
MethodMcpServerStartupStatusUpdated: {},
MethodMcpServerEventStreamNotification: {},
MethodAccountUpdated: {},
MethodAccountGatewayOAuthChanged: {},
MethodAccountRateLimitsUpdated: {},
MethodAppListUpdated: {},
MethodRemoteControlStatusChanged: {},
MethodExternalAgentConfigImportProgress: {},
MethodExternalAgentConfigImportCompleted: {},
MethodFsChanged: {},
MethodItemReasoningSummaryTextDelta: {},
MethodItemReasoningSummaryPartAdded: {},
MethodItemReasoningTextDelta: {},
MethodThreadCompacted: {},
MethodModelRerouted: {},
MethodModelVerification: {},
MethodModelProviderAuthRecoveryStarted: {},
MethodModelProviderAuthRecoveryCompleted: {},
MethodTurnModerationMetadata: {},
MethodModelSafetyBufferingUpdated: {},
MethodWarning: {},
MethodGuardianWarning: {},
MethodDeprecationNotice: {},
MethodConfigWarning: {},
MethodFuzzyFileSearchSessionUpdated: {},
MethodFuzzyFileSearchSessionCompleted: {},
MethodThreadRealtimeStarted: {},
MethodThreadRealtimeItemAdded: {},
MethodThreadRealtimeItemStarted: {},
MethodThreadRealtimeItemTranscriptDelta: {},
MethodThreadRealtimeItemCompleted: {},
MethodThreadRealtimeTranscriptDelta: {},
MethodThreadRealtimeTranscriptDone: {},
MethodThreadRealtimeOutputAudioDelta: {},
MethodThreadRealtimeSdp: {},
MethodThreadRealtimeError: {},
MethodThreadRealtimeClosed: {},
MethodWindowsWorldWritableWarning: {},
MethodWindowsSandboxSetupCompleted: {},
MethodAccountLoginCompleted: {},
}
const (
@@ -524,11 +481,6 @@ const (
ModeKindDefault ModeKind = "default"
)
const (
ThreadUnreadPositionTypeThreadStart = "threadStart"
ThreadUnreadPositionTypeTurn = "turn"
)
const (
AdditionalContextKindUntrusted AdditionalContextKind = "untrusted"
AdditionalContextKindApplication AdditionalContextKind = "application"
@@ -588,6 +540,11 @@ const (
RateLimitReachedTypeWorkspaceMemberUsageLimitReached RateLimitReachedType = "workspace_member_usage_limit_reached"
)
const (
ThreadUnreadPositionTypeThreadStart = "threadStart"
ThreadUnreadPositionTypeTurn = "turn"
)
const (
ThreadAttachmentOperationCreated ThreadAttachmentOperation = "created"
ThreadAttachmentOperationDeleted ThreadAttachmentOperation = "deleted"
@@ -1562,32 +1519,6 @@ type ThreadForkResponse struct {
Thread Thread `json:"thread"`
}
type ThreadCompactStartParams struct {
ThreadID string `json:"threadId"`
}
type ThreadCompactStartResponse = map[string]any
type ThreadReadParams struct {
IncludeTurns bool `json:"includeTurns,omitempty"`
ThreadID string `json:"threadId"`
}
type ThreadUnreadPosition struct {
TurnID string `json:"turnId,omitempty"`
Type string `json:"type"`
}
type ThreadReadState struct {
FirstUnread *ThreadUnreadPosition `json:"firstUnread,omitempty"`
Revision string `json:"revision"`
}
type ThreadReadResponse struct {
ReadState *ThreadReadState `json:"readState,omitempty"`
Thread Thread `json:"thread"`
}
type AdditionalContextKind string
type AdditionalContextEntry struct {
@@ -1745,6 +1676,16 @@ type ThreadStatusChangedNotification struct {
ThreadID string `json:"threadId"`
}
type ThreadUnreadPosition struct {
TurnID string `json:"turnId,omitempty"`
Type string `json:"type"`
}
type ThreadReadState struct {
FirstUnread *ThreadUnreadPosition `json:"firstUnread,omitempty"`
Revision string `json:"revision"`
}
type ThreadReadStateChangedNotification struct {
ReadState ThreadReadState `json:"readState"`
ThreadID string `json:"threadId"`
+5 -46
View File
@@ -41,22 +41,6 @@ type Event struct {
Read time.Time
}
func (e Event) Decode() (any, error) {
ctor, ok := notificationParams[e.Method]
if !ok {
return nil, fmt.Errorf("unknown notification %q", e.Method)
}
if ctor == nil {
return nil, nil
}
v := ctor()
err := json.Unmarshal(e.Params, v)
if err != nil {
return nil, fmt.Errorf("decode %s: %w", e.Method, err)
}
return v, nil
}
type RPCError struct {
Code int64 `json:"code"`
Message string `json:"message"`
@@ -92,11 +76,10 @@ type Session struct {
pendingMu sync.Mutex
pending map[int64]chan rpcResult
stateMu sync.Mutex
threadID string
turnID string
model string
userAgent string
stateMu sync.Mutex
threadID string
turnID string
model string
servers map[string]*mcp.Server
reminder string
@@ -264,10 +247,6 @@ func (s *Session) initialize(ctx context.Context) error {
return fmt.Errorf("initialize: %w", err)
}
s.stateMu.Lock()
s.userAgent = init.UserAgent
s.stateMu.Unlock()
return s.notify("initialized", nil)
}
@@ -314,10 +293,6 @@ func (s *Session) Events() <-chan Event {
return s.events
}
func (s *Session) Done() <-chan struct{} {
return s.done
}
func (s *Session) Pid() int {
return s.cmd.Process.Pid
}
@@ -341,18 +316,6 @@ func (s *Session) ID() string {
return s.threadID
}
func (s *Session) TurnID() string {
s.stateMu.Lock()
defer s.stateMu.Unlock()
return s.turnID
}
func (s *Session) UserAgent() string {
s.stateMu.Lock()
defer s.stateMu.Unlock()
return s.userAgent
}
func (s *Session) SetModel(model string) {
s.stateMu.Lock()
s.model = model
@@ -417,10 +380,6 @@ func (s *Session) Steer(text string) (*Reply, error) {
return s.request(context.Background(), MethodTurnSteer, params)
}
func (s *Session) Compact(ctx context.Context) error {
return s.Call(ctx, MethodThreadCompactStart, ThreadCompactStartParams{ThreadID: s.ID()}, nil)
}
const rpcTimeout = time.Minute
type Reply struct {
@@ -603,7 +562,7 @@ func (s *Session) handleLine(line []byte) {
return
}
if _, ok := notificationParams[m.Method]; !ok {
if _, ok := notificationMethods[m.Method]; !ok {
s.badLine(line, fmt.Sprintf("unrecognized method %q", m.Method))
}