open-design/packages
YOMXXX 2bd83b6e23
feat(daemon): structured diagnostics for agent connection test results (#2248 PR 1/N) (#2419)
* feat(daemon): attach structured diagnostics to agent connection test results

Local agent connection-test failures currently flatten everything into
a single free-form `detail` string (e.g. "exit 1"). Settings UI and CLI
consumers can't tell what phase failed, which binary the daemon picked,
or what the child's exit metadata looked like — they have to scrape the
human-readable text.

Add an optional `diagnostics` block on the connection-test response so
callers can read structured fields instead. The existing `kind` and
`detail` strings are kept bit-for-bit identical, so older UIs keep
rendering unchanged.

- packages/contracts: add `ConnectionTestPhase`
  (binary_resolution / version_probe / model_list / spawn /
  connection_smoke_test / output_parse) and a `ConnectionTestDiagnostics`
  interface with optional `binaryPath`, `binaryVersion`, `exitCode`,
  `signal`, `stdoutTail`, `stderrTail`; extend
  `ConnectionTestResponse.diagnostics?` to carry it.
- apps/daemon/connectionTest.ts: thread a `phase` tracker through
  testAgentConnectionInternal, flip it at the meaningful boundaries
  (binary_resolution → spawn → connection_smoke_test / output_parse),
  and stamp diagnostics into every result return point — the four
  result helpers plus both early returns. Tail data already buffered
  by `createAgentSink` is reused; nothing new is captured.
- tests: three regressions per #2248 — success path attaches
  phase='connection_smoke_test' + exitCode 0, exit-failed path
  attaches phase='spawn' + the failing exitCode + the stderr tail,
  and a missing-CLI path attaches an early-phase diagnostics block.

This is PR 1 of the #2248 plan (contracts + minimum daemon fill);
follow-ups will introduce a normalized failure classifier
(binary_not_found, unsupported_version, auth_failed, quota_exceeded,
network_failed, unsupported_flags, no_text_output, output_parse_failed,
spawn_failed), candidate-alternative reporting via
inspectAgentExecutableResolution, and the Settings "View details"
disclosure.

Refs #2248.

* fix(connectionTest): honor diagnostics contract on all local return paths

Two follow-ups from review of #2419:

- packages/contracts/src/api/connectionTest.ts advertises diagnostics
  as 'Always set on local agent test responses', but three local
  returns still bypassed buildDiagnostics(): the buildArgs failure
  around 1295, the preflight probeAgentAuthStatus().status === 'missing'
  branch around 1317, and the outer catch around 1566. Thread
  buildDiagnostics() through all three; phase is still 'binary_resolution'
  at the first two and whatever the runtime advanced to at the catch.
- resultFromAgentText() hard-coded exitCode: 0 even though
  resultFromChildExit() routes ACP clean-SIGTERM completion through
  this success helper (winner.code === null, winner.signal ===
  'SIGTERM' with acpCleanCompletion). Add an optional exit argument
  threaded from both call sites so the diagnostics reflect the actual
  child code/signal pair instead of a synthesized 0 that masks the
  SIGTERM teardown. Only synthesize 0 when no exit context is
  available (theoretical text-without-exit path).

Tests:
- regression locking the diagnostics contract for the preflight auth
  path on Cursor Agent (phase: binary_resolution, binaryPath set)

* docs(contracts): widen diagnostics contract to match early-failure paths

Reviewer flagged that the JSDoc-style comment on
ConnectionTestResponse.diagnostics still said 'Populated only when the
test actually spawned an agent CLI', but the previous follow-up made
the daemon stamp diagnostics on three pre-spawn local-agent failures
too: the unknown-agent and unresolved-binary branches around
connectionTest.ts:1123-1148 and the preflight auth return around
1338-1353. Reword the contract so Settings/CLI consumers do not
incorrectly special-case those early local failures as
diagnostics === undefined.

* fix(connectionTest): keep contracts browser-safe and fold probe output into preflight diagnostics

Two follow-ups from review of #2419:

- ConnectionTestDiagnostics.signal was typed as
  `NodeJS.Signals | string | null`, which made the generated .d.ts of
  the shared @open-design/contracts surface depend on ambient Node
  types. Downstream consumers reading a plain HTTP response shape
  should not need @types/node. Narrow to `string | null` (NodeJS.Signals
  literals are strings, so the daemon write site is unchanged) and
  document the boundary in the field comment.
- The Cursor-style preflight auth path stamped diagnostics built from
  the smoke-test sink, which is always empty at that point because the
  smoke spawn never happened. As a result the diagnostics block
  silently dropped `cursor-agent status`'s own stderr/stdout/exit
  context — the only structured failure information available on that
  path. Thread the probe output back out of probeAgentAuthStatus()
  via new optional stdoutTail/stderrTail/exitCode/signal fields, then
  merge them into the diagnostics overrides in connectionTest.ts so
  Settings/CLI consumers can render the auth-failure context instead
  of just the guidance string.

Tests:
- extended the Cursor preflight regression to assert that diagnostics
  carries the probe's stderr ("Not logged in") and exit code (1).
2026-05-26 03:17:05 +00:00
..
agui-adapter chore: pin dependency versions and harden CI caches (#2189) 2026-05-19 13:58:27 +08:00
contracts feat(daemon): structured diagnostics for agent connection test results (#2248 PR 1/N) (#2419) 2026-05-26 03:17:05 +00:00
diagnostics feat(diagnostics): add one-click log export from Settings → About (#798) 2026-05-20 09:10:51 +08:00
download fix(download): handle pid reuse in stale locks (#2714) 2026-05-22 18:00:11 +08:00
host Merge origin/main into release/v0.8.0 2026-05-23 12:17:18 +08:00
platform Harden packaged updater downloads and install handoff (#2677) 2026-05-22 15:44:28 +08:00
plugin-runtime chore: pin dependency versions and harden CI caches (#2189) 2026-05-19 13:58:27 +08:00
registry-protocol chore: pin dependency versions and harden CI caches (#2189) 2026-05-19 13:58:27 +08:00
sidecar release: Open Design 0.8.0 2026-05-20 21:22:17 +08:00
sidecar-proto Merge origin/main into release/v0.8.0 2026-05-23 12:17:18 +08:00
AGENTS.md refactor desktop host bridge (#2246) 2026-05-19 18:27:05 +08:00