Compare commits
4 Commits
fix/milest
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e4803a5541 | |||
| 782f62cc78 | |||
| 0d656a6678 | |||
| f145979684 |
@@ -60,11 +60,19 @@ func main() {
|
|||||||
// `POST /calendar/agent/status`, identifies caller via
|
// `POST /calendar/agent/status`, identifies caller via
|
||||||
// AGENT_ID/CLAW_IDENTIFIER env, no token needed).
|
// AGENT_ID/CLAW_IDENTIFIER env, no token needed).
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
output.Error("usage: hf agent status --set <idle|busy|on_call|exhausted|offline>")
|
output.Error("usage: hf agent status --set <idle|busy|on_call|exhausted|offline> | hf agent status-of <agent-id>")
|
||||||
}
|
}
|
||||||
switch args[1] {
|
switch args[1] {
|
||||||
case "status":
|
case "status":
|
||||||
commands.RunAgentStatus(args[2:])
|
commands.RunAgentStatus(args[2:])
|
||||||
|
case "status-of":
|
||||||
|
// `hf agent status-of <agent-id>` — read ANOTHER agent's runtime
|
||||||
|
// status (no side effects), wrapping GET /calendar/agent/status.
|
||||||
|
// Used by delegate-task / on-call-handoff status gates.
|
||||||
|
if len(args) < 3 {
|
||||||
|
output.Error("usage: hf agent status-of <agent-id>")
|
||||||
|
}
|
||||||
|
commands.RunAgentStatusOf(args[2])
|
||||||
default:
|
default:
|
||||||
output.Errorf("unknown agent subcommand: %s", args[1])
|
output.Errorf("unknown agent subcommand: %s", args[1])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
neturl "net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -138,3 +139,69 @@ func RunAgentStatus(args []string) {
|
|||||||
"ok", "true",
|
"ok", "true",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunAgentStatusOf implements `hf agent status-of <agent-id>` — read ANOTHER
|
||||||
|
// agent's current runtime status without side effects, wrapping
|
||||||
|
// `GET /calendar/agent/status?agent_id=<id>`. Used by the delegate-task and
|
||||||
|
// on-call-handoff status gates (which previously referenced this endpoint with
|
||||||
|
// no CLI to reach it). Like RunAgentStatus this is header-identified, not
|
||||||
|
// token-authed; the X-Claw-Identifier comes from CLAW_IDENTIFIER env or
|
||||||
|
// hostname. Prints `{agent_id, status}`; backend returns 404 for unknown
|
||||||
|
// agents so callers can fail-open or fail-closed.
|
||||||
|
func RunAgentStatusOf(targetAgentID string) {
|
||||||
|
targetAgentID = strings.TrimSpace(targetAgentID)
|
||||||
|
if targetAgentID == "" {
|
||||||
|
output.Error("usage: hf agent status-of <agent-id>")
|
||||||
|
}
|
||||||
|
|
||||||
|
clawID := strings.TrimSpace(os.Getenv("CLAW_IDENTIFIER"))
|
||||||
|
if clawID == "" {
|
||||||
|
if h, err := os.Hostname(); err == nil {
|
||||||
|
clawID = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if clawID == "" {
|
||||||
|
output.Error("CLAW_IDENTIFIER env not set and hostname() failed — set CLAW_IDENTIFIER explicitly")
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, err := config.Load()
|
||||||
|
if err != nil {
|
||||||
|
output.Errorf("config error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
url := strings.TrimRight(cfg.BaseURL, "/") + "/calendar/agent/status?agent_id=" + neturl.QueryEscape(targetAgentID)
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
output.Errorf("cannot build request: %v", err)
|
||||||
|
}
|
||||||
|
req.Header.Set("X-Claw-Identifier", clawID)
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 30 * time.Second}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
output.Errorf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
_, _ = buf.ReadFrom(resp.Body)
|
||||||
|
if resp.StatusCode/100 != 2 {
|
||||||
|
output.Errorf("backend returned %d: %s", resp.StatusCode, buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if output.JSONMode {
|
||||||
|
fmt.Println(buf.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var parsed struct {
|
||||||
|
AgentID string `json:"agent_id"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(buf.Bytes(), &parsed); err != nil {
|
||||||
|
output.Errorf("cannot parse response: %v", err)
|
||||||
|
}
|
||||||
|
output.PrintKeyValue(
|
||||||
|
"agent_id", parsed.AgentID,
|
||||||
|
"status", parsed.Status,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/output"
|
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/output"
|
||||||
)
|
)
|
||||||
@@ -35,9 +36,18 @@ func RunWorklogAdd(taskCode string, hours float64, desc, date, tokenFlag string)
|
|||||||
if desc != "" {
|
if desc != "" {
|
||||||
payload["description"] = desc
|
payload["description"] = desc
|
||||||
}
|
}
|
||||||
|
// logged_date is a REQUIRED datetime on the backend. Default to now; if
|
||||||
|
// the operator passed --date <yyyy-mm-dd>, anchor it to start-of-day so a
|
||||||
|
// bare date still parses as a datetime.
|
||||||
|
loggedDate := time.Now().UTC().Format(time.RFC3339)
|
||||||
if date != "" {
|
if date != "" {
|
||||||
payload["logged_date"] = date
|
if len(date) == 10 { // bare YYYY-MM-DD
|
||||||
|
loggedDate = date + "T00:00:00Z"
|
||||||
|
} else {
|
||||||
|
loggedDate = date
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
payload["logged_date"] = loggedDate
|
||||||
|
|
||||||
body, err := json.Marshal(payload)
|
body, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user