Repository navigation
Add ao spawn + ao project add (spawn a real worker end-to-end)
#77
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dca6135
Add `ao spawn` and `ao project add`; resolve project repos for worktrees
yyovil 5b242b4
Address Copilot review on #77
yyovil 798a4e5
Assert the project-not-resolvable sentinel in the resolver test
yyovil cb77df5
Fix ao spawn 500 on long session ids (zellij socket-path overflow)
yyovil 9a5e940
test(cli): guard CLI/daemon DTO drift with an e2e round-trip
harshitsinghbhandari 5deafde
fix(cli,daemon): address review findings on ao spawn
harshitsinghbhandari 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
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,97 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/aoagents/agent-orchestrator/backend/internal/config" | ||
| "github.com/aoagents/agent-orchestrator/backend/internal/runfile" | ||
| ) | ||
|
|
||
| // commandTimeout bounds a mutating daemon call. Spawns do real work (git | ||
| // worktree add, zellij launch, hook install), so it is generous compared to the | ||
| // status probe timeout. | ||
| const commandTimeout = 2 * time.Minute | ||
|
|
||
| // apiError is the subset of the daemon's JSON error envelope the CLI surfaces. | ||
| // RequestID is surfaced so a failed command can be correlated with daemon logs. | ||
| type apiError struct { | ||
| Message string `json:"message"` | ||
| Code string `json:"code"` | ||
| RequestID string `json:"requestId"` | ||
| } | ||
|
|
||
| // String renders the envelope for the user: "<message> (<code>) [request <id>]", | ||
| // omitting whichever parts the daemon left empty. | ||
| func (e apiError) String() string { | ||
| msg := e.Message | ||
| if e.Code != "" { | ||
| msg = fmt.Sprintf("%s (%s)", msg, e.Code) | ||
| } | ||
| if e.RequestID != "" { | ||
| msg = fmt.Sprintf("%s [request %s]", msg, e.RequestID) | ||
| } | ||
| return msg | ||
| } | ||
|
|
||
| // postJSON sends body as JSON to POST /api/v1/<path> on the running daemon and | ||
| // decodes a 2xx response into out (out may be nil). A non-2xx response becomes | ||
| // an error built from the API error envelope. A missing run-file or a stale one | ||
| // (dead PID) yields a clear "not running" message rather than a | ||
| // connection-refused dump. | ||
| func (c *commandContext) postJSON(ctx context.Context, path string, body, out any) error { | ||
| cfg, err := config.Load() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| info, err := runfile.Read(cfg.RunFilePath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if info == nil { | ||
| return fmt.Errorf("AO daemon is not running — start it with `ao start`") | ||
| } | ||
| if !c.deps.ProcessAlive(info.PID) { | ||
| return fmt.Errorf("AO daemon is not running (stale run-file at %s) — start it with `ao start`", cfg.RunFilePath) | ||
| } | ||
|
|
||
| payload, err := json.Marshal(body) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| url := fmt.Sprintf("http://%s:%d/api/v1/%s", config.LoopbackHost, info.Port, path) | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(payload)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| req.Header.Set("Content-Type", "application/json") | ||
|
|
||
| // Reuse the injected client's transport (keeps it stubbable in tests) but | ||
| // give mutating calls far more headroom than the 2s status-probe timeout. | ||
| client := *c.deps.HTTPClient | ||
| client.Timeout = commandTimeout | ||
| resp, err := client.Do(req) | ||
| if err != nil { | ||
| return fmt.Errorf("call daemon: %w", err) | ||
| } | ||
| defer func() { _ = resp.Body.Close() }() | ||
|
|
||
| if resp.StatusCode < 200 || resp.StatusCode >= 300 { | ||
| var e apiError | ||
| _ = json.NewDecoder(resp.Body).Decode(&e) | ||
| if e.Message == "" { | ||
| return fmt.Errorf("daemon returned HTTP %d", resp.StatusCode) | ||
| } | ||
| return fmt.Errorf("%s", e.String()) | ||
| } | ||
| if out != nil { | ||
| if err := json.NewDecoder(resp.Body).Decode(out); err != nil { | ||
| return fmt.Errorf("decode response: %w", err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
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,25 @@ | ||
| package cli | ||
|
|
||
| import "testing" | ||
|
|
||
| // TestAPIErrorString covers how the CLI renders the daemon's error envelope, | ||
| // including the requestId it now surfaces for log correlation. | ||
| func TestAPIErrorString(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| in apiError | ||
| want string | ||
| }{ | ||
| {"message only", apiError{Message: "boom"}, "boom"}, | ||
| {"message and code", apiError{Message: "boom", Code: "X"}, "boom (X)"}, | ||
| {"with request id", apiError{Message: "boom", Code: "X", RequestID: "req-1"}, "boom (X) [request req-1]"}, | ||
| {"message and request id", apiError{Message: "boom", RequestID: "req-1"}, "boom [request req-1]"}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| if got := tc.in.String(); got != tc.want { | ||
| t.Fatalf("String() = %q, want %q", got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.