-
Notifications
You must be signed in to change notification settings - Fork 1
[codex] add ao hooks activity command #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harshitsinghbhandari
merged 2 commits into
aoagents:main
from
yyovil:codex/ao-hooks-command
Jun 6, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
backend/internal/adapters/agent/activitydispatch/dispatch.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Package activitydispatch is the single source of truth mapping the agent | ||
| // token in `ao hooks <agent> <event>` onto the function that interprets that | ||
| // agent's hook callbacks as an AO activity state. | ||
| package activitydispatch | ||
|
|
||
| import ( | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/adapters/agent/claudecode" | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/adapters/agent/codex" | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/adapters/agent/opencode" | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
| ) | ||
|
|
||
| // DeriveFunc maps a native agent hook event and its raw stdin payload onto an AO | ||
| // activity state. ok=false means the event carries no activity signal. | ||
| type DeriveFunc func(event string, payload []byte) (domain.ActivityState, bool) | ||
|
|
||
| // Derivers maps the agent token in `ao hooks <agent> <event>` to its deriver. | ||
| var Derivers = map[string]DeriveFunc{ | ||
| "claude-code": claudecode.DeriveActivityState, | ||
| "codex": codex.DeriveActivityState, | ||
| "opencode": opencode.DeriveActivityState, | ||
| } | ||
|
|
||
| // Derive looks up the deriver for an agent token and applies it. ok=false when | ||
| // the token has no registered deriver or the event carries no activity signal. | ||
| func Derive(agent, event string, payload []byte) (domain.ActivityState, bool) { | ||
| derive, found := Derivers[agent] | ||
| if !found { | ||
| return "", false | ||
| } | ||
| return derive(event, payload) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package claudecode | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
| ) | ||
|
|
||
| // DeriveActivityState maps a Claude Code hook event and its native stdin payload | ||
| // onto an AO activity state. The bool is false when the event carries no | ||
| // activity signal. | ||
| func DeriveActivityState(event string, payload []byte) (domain.ActivityState, bool) { | ||
| switch event { | ||
| case "user-prompt-submit": | ||
| return domain.ActivityActive, true | ||
| case "stop": | ||
| return domain.ActivityIdle, true | ||
| case "notification": | ||
| return notificationState(payload) | ||
| case "session-end": | ||
| return sessionEndState(payload) | ||
| default: | ||
| return "", false | ||
| } | ||
| } | ||
|
|
||
| func notificationState(payload []byte) (domain.ActivityState, bool) { | ||
| var p struct { | ||
| NotificationType string `json:"notification_type"` | ||
| } | ||
| _ = json.Unmarshal(payload, &p) | ||
| switch p.NotificationType { | ||
| case "idle_prompt", "permission_prompt": | ||
| return domain.ActivityWaitingInput, true | ||
| default: | ||
| return "", false | ||
| } | ||
| } | ||
|
|
||
| func sessionEndState(payload []byte) (domain.ActivityState, bool) { | ||
| var p struct { | ||
| Reason string `json:"reason"` | ||
| } | ||
| _ = json.Unmarshal(payload, &p) | ||
| switch p.Reason { | ||
| case "clear", "resume": | ||
| return "", false | ||
| default: | ||
| return domain.ActivityExited, true | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
backend/internal/adapters/agent/claudecode/activity_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package claudecode | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
| ) | ||
|
|
||
| func TestDeriveActivityState(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| event string | ||
| payload string | ||
| want domain.ActivityState | ||
| wantOK bool | ||
| }{ | ||
| {"user prompt -> active", "user-prompt-submit", `{}`, domain.ActivityActive, true}, | ||
| {"stop -> idle", "stop", `{}`, domain.ActivityIdle, true}, | ||
| {"notification idle_prompt -> waiting_input", "notification", `{"notification_type":"idle_prompt"}`, domain.ActivityWaitingInput, true}, | ||
| {"notification permission_prompt -> waiting_input", "notification", `{"notification_type":"permission_prompt"}`, domain.ActivityWaitingInput, true}, | ||
| {"notification auth_success -> no signal", "notification", `{"notification_type":"auth_success"}`, "", false}, | ||
| {"notification malformed payload -> no signal", "notification", `not json`, "", false}, | ||
| {"session-end logout -> exited", "session-end", `{"reason":"logout"}`, domain.ActivityExited, true}, | ||
| {"session-end prompt_input_exit -> exited", "session-end", `{"reason":"prompt_input_exit"}`, domain.ActivityExited, true}, | ||
| {"session-end absent reason -> exited", "session-end", `{}`, domain.ActivityExited, true}, | ||
| {"session-end clear -> no signal", "session-end", `{"reason":"clear"}`, "", false}, | ||
| {"session-end resume -> no signal", "session-end", `{"reason":"resume"}`, "", false}, | ||
| {"session-start -> no signal", "session-start", `{}`, "", false}, | ||
| {"unknown event -> no signal", "frobnicate", `{}`, "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, ok := DeriveActivityState(tt.event, []byte(tt.payload)) | ||
| if got != tt.want || ok != tt.wantOK { | ||
| t.Fatalf("DeriveActivityState(%q, %q) = (%q, %v), want (%q, %v)", | ||
| tt.event, tt.payload, got, ok, tt.want, tt.wantOK) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package codex | ||
|
|
||
| import "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
|
|
||
| // DeriveActivityState maps a Codex hook event onto an AO activity state. The | ||
| // bool is false when the event carries no activity signal. | ||
| func DeriveActivityState(event string, _ []byte) (domain.ActivityState, bool) { | ||
| switch event { | ||
| case "user-prompt-submit": | ||
| return domain.ActivityActive, true | ||
| case "permission-request": | ||
| return domain.ActivityWaitingInput, true | ||
| case "stop": | ||
| return domain.ActivityIdle, true | ||
| default: | ||
| return "", false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package codex | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
| ) | ||
|
|
||
| func TestDeriveActivityState(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| event string | ||
| want domain.ActivityState | ||
| wantOK bool | ||
| }{ | ||
| {"user prompt -> active", "user-prompt-submit", domain.ActivityActive, true}, | ||
| {"permission request -> waiting input", "permission-request", domain.ActivityWaitingInput, true}, | ||
| {"stop -> idle", "stop", domain.ActivityIdle, true}, | ||
| {"session start -> no signal", "session-start", "", false}, | ||
| {"unknown event -> no signal", "frobnicate", "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, ok := DeriveActivityState(tt.event, []byte(`{}`)) | ||
| if got != tt.want || ok != tt.wantOK { | ||
| t.Fatalf("DeriveActivityState(%q) = (%q, %v), want (%q, %v)", | ||
| tt.event, got, ok, tt.want, tt.wantOK) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package opencode | ||
|
|
||
| import "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
|
|
||
| // DeriveActivityState maps an opencode plugin hook event onto an AO activity | ||
| // state. The bool is false when the event carries no activity signal. | ||
| func DeriveActivityState(event string, _ []byte) (domain.ActivityState, bool) { | ||
| switch event { | ||
| case "session-start": | ||
| return domain.ActivityActive, true | ||
| case "user-prompt-submit": | ||
| return domain.ActivityActive, true | ||
| case "stop": | ||
| return domain.ActivityIdle, true | ||
| default: | ||
| return "", false | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package opencode | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/aoagents/agent-orchestrator/backend/internal/domain" | ||
| ) | ||
|
|
||
| func TestDeriveActivityState(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| event string | ||
| want domain.ActivityState | ||
| wantOK bool | ||
| }{ | ||
| {"session start -> active", "session-start", domain.ActivityActive, true}, | ||
| {"user prompt -> active", "user-prompt-submit", domain.ActivityActive, true}, | ||
| {"stop -> idle", "stop", domain.ActivityIdle, true}, | ||
| {"unknown event -> no signal", "frobnicate", "", false}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, ok := DeriveActivityState(tt.event, []byte(`{}`)) | ||
| if got != tt.want || ok != tt.wantOK { | ||
| t.Fatalf("DeriveActivityState(%q) = (%q, %v), want (%q, %v)", | ||
| tt.event, got, ok, tt.want, tt.wantOK) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.