Skip to content

feat: add --json structured output to runtime observability (CH-004)#3

Merged
dccoding1118 merged 1 commit into
mainfrom
feat/runtime-json-output
Jul 4, 2026
Merged

feat: add --json structured output to runtime observability (CH-004)#3
dccoding1118 merged 1 commit into
mainfrom
feat/runtime-json-output

Conversation

@dccoding1118

Copy link
Copy Markdown
Owner

摘要

gogents runtime list / gogents runtime status 加上 opt-in 的 --json,提供 agent-manager (am) 轉接器一個穩定的機器可讀契約,取代逐行解析人類可讀顯示層(欄位增減/順序/時間格式變動不再無聲破壞解析)。變更來源:docs/changes/change-add-json-output.md(CH-004)。

行為

  • runtime list --json:輸出 runtime 陣列 JSON;無註冊時輸出 [](非文字 (no registered runtimes))。
  • runtime status <target> --json:輸出單一扁平 JSON 物件;last_sync_at 零值輸出 ""(非 0001-01-01…),經 StatusView.MarshalJSON 處理。
  • --json 失敗:stderr 輸出 {"error":{"code","message"}}、非零 exit、stdout 無 payload;code 分類為 runtime_not_found / state_not_found / internal
  • --json 位置容忍:旗標可在 target 前或後。
  • 向後相容:未帶 --json 時所有現行文字輸出與 exit 行為完全不變;logs 不變。

變更範圍

程式

  • internal/cli/query.goRuntimeView 加 json tag、StatusView.MarshalJSON、新 sentinel ErrStateNotFound
  • internal/cli/cli.gorunRuntime--json 分支、extractBoolFlag(位置容忍)、printJSONemitRuntimeError + newRuntimeErrorEnvelope(error→code 分類)。

測試internal/cli/json_test.go

  • D08-11 list 陣列/空 [];D08-12 status flat 物件(down、空字串、RFC3339);D08-13 三 code + envelope marshal;extractBoolFlag 位置容忍。

文件

  • docs/designs/D08-runtime-cli.md(§3.1/§3.4/§4/§6/§7)、docs/requirements/reqs/R12-runtime-observability.mdREADME.mddocs/tests/unit-tests.md

驗證

  • go build ./... ✓、go test ./... 全通過 ✓、golangci-lint run 0 issues
  • CLI 煙測:list --json(有/空 [])、status --json(down、零值 ""、旗標前後)、錯誤(runtime_not_found/state_not_found 走 stderr、stdout 無 payload、exit 1)、text 模式不變,皆正確。

🤖 Generated with Claude Code

…(CH-004)

Add an opt-in `--json` flag to `gogents runtime list` and `gogents runtime
status`, giving the agent-manager adapter a stable machine-readable contract
instead of parsing the human-facing text layer.

- `runtime list --json`: JSON array of runtimes; `[]` when none registered.
- `runtime status <target> --json`: single flat JSON object; a zero
  last_sync_at renders as "" (not 0001-01-01…) via StatusView.MarshalJSON.
- `--json` failures emit {"error":{"code,message}}` to stderr with a
  classified code (runtime_not_found / state_not_found / internal) and a
  non-zero exit; stdout carries no payload.
- `--json` is position-tolerant (before or after the target).
- Without `--json`, all existing text output and exit behavior is unchanged.

Docs (D08, R12, README, unit-tests.md) fold the JSON contract into the
observability design. Tests cover the list array/empty case, the status
object (down / empty strings / RFC3339), error-code classification, and
flag position tolerance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dccoding1118
dccoding1118 merged commit d52f482 into main Jul 4, 2026
@dccoding1118
dccoding1118 deleted the feat/runtime-json-output branch July 4, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant