Per RFC §9 Fleet Mode: device pairing + SSE-with-poll-fallback +
heartbeat + status reporting now wired.
Lands:
* pkg/agentic/fleet_login.go — `core login CODE` POSTs /v1/device/pair
with the 6-digit code; writes {agent_api_key, agent_id, expires_at}
to ~/.core/agent.key (mode 0600). Errors clean (no panic) on invalid
code / network fail.
* pkg/agentic/fleet_connect.go — Connect(ctx) opens SSE to
/v1/fleet/events with Bearer auth; reconnect backoff 1s→2s→4s→8s→
16s→30s. PollFallback via /v1/fleet/task/next every 30s when SSE
keeps failing. Heartbeat goroutine POSTs /v1/fleet/heartbeat every
60s with {agent_id, status}. Persists last-known fleet snapshot to
~/.core/fleet.status.json so fleet/status survives restart.
* pkg/agentic/fleet_mode.go — `core fleet` top-level + `fleet/nodes`
(lists registered nodes) + `fleet/status` (connection state, last
heartbeat, last task). All exit cleanly on API-unreachable.
* commands.go — registerFleetCommands wired into registerCommands.
* AX-10 tests + CLI Taskfiles for login + nodes (unreachable-API
asserted clean-exit, no panic).
Sandbox blocked from go test by go.work + private-module-graph
(pre-existing); gofmt clean.
Co-authored-by: Codex <noreply@openai.com>
Closes tasks.lthn.sh/view.php?id=539
25 lines
735 B
YAML
25 lines
735 B
YAML
version: "3"
|
|
|
|
tasks:
|
|
test:
|
|
cmds:
|
|
- |
|
|
bash <<'EOF'
|
|
set -euo pipefail
|
|
source ../../_lib/run.sh
|
|
|
|
GOWORK=off go build -trimpath -ldflags="-s -w" -o bin/core-agent ../../../../cmd/core-agent
|
|
|
|
export CORE_API_URL="http://127.0.0.1:1"
|
|
|
|
output="$(mktemp)"
|
|
# fleet/nodes must fail cleanly when the API is unreachable.
|
|
run_capture_all 1 "$output" ./bin/core-agent fleet/nodes
|
|
assert_contains "error:" "$output"
|
|
assert_contains "fleet" "$output"
|
|
if grep -Fq "panic" "$output"; then
|
|
printf 'unexpected panic in fleet/nodes output\n' >&2
|
|
cat "$output" >&2
|
|
exit 1
|
|
fi
|
|
EOF
|