Skip to content

Improve CLI operator reports and agent contracts - #142

Merged
zhongwencool merged 22 commits into
mainfrom
zw/cli-human-agent-improvements
Sep 30, 2026
Merged

zhongwencool merged 22 commits into
mainfrom
zw/cli-human-agent-improvements

Conversation

@zhongwencool

@zhongwencool zhongwencool commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

Improve the noninteractive CLI for human operators and agents without changing TUI behavior, target protocol 1, authorization boundaries, or runtime dependencies.

  • Make text reports concise and outcome-first; retain complete evidence with text-only --verbose and JSON/term output.
  • Repair execution preflight, error recovery, partial-result visibility, Unicode selectors, and diagnostic consistency.
  • Add offline describe, bundled schema export, typed response contracts, and controller-derived next-action proposals.
  • Add real-escript workflow acceptance, schema/units mutation tests, and Rebar/Mix packaging checks.

Requested implementation sequence

Each requested item has its own commit. Follow-up findings remain separate commits; no squash or history rewrite was used.

# Item Commit
1 Output capability preflight before work 65fbd68
2 Diagnostic summary/findings consistency e18ae1c
3 Reject orphan target options df78dd1
4 Schema-valid invalid-trace identities 270d144
5 Unicode saved contexts 0bd6a9f
6 Visible partial/truncated logs 1dd23e2
7 Executable public help names cc393fb
8 Concise reports and verbose evidence bf5822d
9 Actionable, privacy-aware recovery 7e42f77
10 Honest coverage and operational boundaries dc7ec8d
11 Validated, non-executing next actions 8479564
12 Complete response schema and formal validation a55a4a3
13 Offline command catalog and schema export 1dfd767
14 Identifier-safe investigation/share workflows 332727d
15 Stateless bounded agent workflows and CI acceptance 4d3ec7b

Separate follow-ups fix payload-independent preflight, Unicode public metadata, context guards/name-mode schema spelling, trace burst-breaker terminology, the updated compact snapshot regression, and schema-unit annotation drift.

Public interface and compatibility

  • Keep the six-field observer_cli.cli/v1 envelope and existing exit codes.
  • --verbose is text-only; JSON/term already contain full evidence.
  • describe [COMMAND [SUBCOMMAND]] is offline and does not access target credentials or saved context. describe --schema --json exports the bundled JSON Schema directly, not an envelope.
  • Diagnostic data.next_actions is optional and derived on the controller after evidence validation. The target diagnostic wire payload is unchanged. Proposed argv contain no credentials, invasive commands, or implicit saved-context fallback.
  • New selectors use internal UTF-8 context version 2; legacy version 1 remains readable. Downgrades can recreate a selector with connect.
  • JSON remains OTP 27+; OTP 26 retains text/term support and rejects JSON before any target work.
  • No automatic trace consent, misleading log redaction, relaxed scan budgets, new runtime dependency, daemon, profile system, shared limiter, or release/version change.

Validation

Local OTP 29.1.1 and Elixir 1.20.4:

  • rebar3 as ci check: compile, lint, formatting, xref, Dialyzer and documentation passed.
  • rebar3 eunit: 860 tests, 0 failures.
  • rebar3 as test do eunit, covertool generate: 860 tests, 0 failures; local line coverage 8250/8452 (97.6% rounded). Existing Codecov gates are unchanged.
  • Rebar escript build and generated-escript smoke passed.
  • Formal validator: 105 emitted fixtures, 1357 rejected payload mutations, and 14 rejected schema-unit mutations.
  • Real isolated agent workflows passed for both Rebar and Mix artifacts; each produced 18 validated envelopes with 119 rejected payload mutations. Both embedded schemas exactly match the normative source.
  • Mix locked dependencies, production escript, generated-escript smoke, local release build and crypto evaluation passed.
  • ExDoc, rebar3 fmt --check and git diff --check passed.

Cross-OTP acceptance:

  • Compiled all 27 project modules and 6 recon modules on OTP 26 with -Werror in an isolated temporary archive.
  • OTP 26 compatibility smoke passed (JSON workflow explicitly not claimed).
  • OTP 26 controller to owned OTP 29 target: complete memory text/term responses.
  • Unsupported JSON trace returned exit 2 without a new target connection or changes to pre-existing trace sentinels.

All live tests used owned temporary nodes, private EPMD/configuration/cookies/logs, and bounded cleanup. No production node was used. A stale compact-header test found by the first full run was corrected with both compact and verbose assertions; the full suite then passed twice. Final review also caught and corrected schema-unit descriptions, which now have explicit regression guards.

Scope boundaries

No TUI redesign, resource filters, multi-profile contexts, general target-wide limiter, production load test, MCP/daemon, tag, Hex publication, or merge. Hosted CI and review approval remain separate from the local evidence above.

Hosted CI result

CI run 36437133165 passed for OTP 26, 27, 28, 29 and the OTP 29 / Elixir 1.20 / Mix job. Both codecov/patch and codecov/project checks passed. The tag-only release job was skipped as expected.

This is a non-draft, open PR awaiting human review approval. It has not been merged or released.

Changes:
- Preflight the selected encoder for every command before remote or local work.
- Preserve existing context safeguards and document the OTP 26 JSON boundary.

Validation:
- Passed 94 observer_cli_escriptize_test EUnit tests on OTP 29.
- Compiled and passed the encoder-preflight regression on an isolated OTP 26 VM.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Distinguish incomplete required evidence from optional probe failures in quick and observation summaries.
- Report retained findings accurately for partial captures and document their meaning.

Validation:
- Passed 26 observer_cli_diagnostic_test EUnit tests, including required-gap and optional-failure regressions.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Reject orphan cookie-source and name-mode options rather than silently discarding them.
- Explain explicit-target selection and saved-context updates in errors and documentation.

Validation:
- Passed 45 observer_cli_cli_test EUnit tests, including orphan-option and explicit-target cases.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Use the pre-command null identity when a trace action cannot be recognized.
- Retain specific identities for recognized trace call and stop actions.

Validation:
- Passed observer_cli_escriptize_test and observer_cli_schema_test: 97 EUnit tests.
- Verified malformed trace actions produce parseable error envelopes with null command identity.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Serialize new saved selectors with UTF-8 context version 2 and retain legacy Latin-1 version 1 decoding.
- Bound serialized context size and convert persistence/encoding exceptions into controlled errors.
- Document downgrade recovery without persisting cookie values.

Validation:
- Passed 46 observer_cli_cli_test EUnit tests, including Unicode file/env round trips and legacy decoding.
- Verified malformed Unicode returns an error instead of escaping as an escript exception.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Display log outcomes and byte/line truncation metadata before untrusted log content.
- Preserve control escaping, physical-line prefixes, and complete versus partial semantics.

Validation:
- Passed 87 CLI and log EUnit tests, including byte-cap and line-cap visibility regressions.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Centralize public command spelling for text and error recovery hints.
- Generate working supervision-tree and trace help commands instead of exposing internal atom names.

Validation:
- Passed 143 CLI/escript EUnit tests, including help execution for every command identity.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Use a null payload when checking output capability so specialized log renderers cannot require capture data before execution.
- Exercise text and term preflight across remote, local-context, and log commands.

Validation:
- Passed the focused all-command encoder-preflight EUnit regression.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Render outcome-first compact diagnostic, memory, resource, trace, and distribution reports.
- Add text-only --verbose while preserving complete JSON/term evidence and specialized log/context output.
- Preserve full actionable identifiers, metric units, partial coverage, and terminal-control escaping.

Validation:
- Passed 159 CLI, escript, and report EUnit tests; reran all 15 report tests after final refinements.
- Built the escript and exercised an isolated OTP 29 target: memory 21 lines, three processes 22 lines, diagnose 25 lines; verbose memory retained 134 lines.
- Exercised 80/120-column rendering, Unicode, unavailable metrics, and redirected output.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Include rejected parameter values and applicable constraints while preserving public reason codes and exit statuses.
- Capture effective target selectors once for connection recovery hints without disclosing cookie contents or weakening redaction.
- Explain why reducing output limits does not bypass resource-count admission budgets.

Validation:
- Passed 148 CLI and escript EUnit tests, including isolated context replacement, unreachable target, credential errors, and redaction regressions.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- State evaluated rule scope, completed probes, nonrecursive supervision, and the limits of no-findings reports.
- Correct scheduler documentation to describe per-process registration cleanup rather than changing other tools' registrations.

Validation:
- Passed 117 selected escript/report/scheduler-regression EUnit tests.
- Verified on OTP 26, 27, 28, and 29 that releasing a child measurement registration preserves the parent's measurement.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Encode known Unicode cookie paths and environment names directly in public context metadata and recovery hints.
- Preserve raw-byte normalization for unrelated diagnostic values.

Validation:
- Passed the focused Unicode selector metadata regression for accented, Chinese, and invalid Unicode values.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Derive optional, allowlisted next actions on the controller after diagnostic evidence validation.
- Preserve legacy target wire payloads and existing recommendation strings.
- Require explicit original target binding, exclude credentials and invasive actions, and render safely quoted operator examples.

Validation:
- Passed 146 actions, diagnostic, escript, and report EUnit tests.
- Verified all suggested argv parse, duplicate findings deduplicate actions, and tampered or unrelated actions are rejected.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Define command-specific payload fields, findings/evidence, unavailable states, and trace/log completion shapes in the normative v1 schema.
- Add pinned development-only Draft 2020-12 validation with emitted fixtures and deliberate malformed variants.
- Check exact bundled schema equality in Rebar and Mix CI without adding runtime dependencies.

Validation:
- Passed both schema EUnit tests and the schema's Draft 2020-12 self-validation.
- Validated 102 emitted response fixtures and rejected 1348 negative cases.
- Built and verified the Rebar escript's packaged schema; final local Mix packaging verification remains scheduled with full validation.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Express context version validation with consistent short-circuit guard operators.
- Preserve Unicode and legacy selector decoding behavior.

Validation:
- Passed the Unicode and legacy context round-trip EUnit regression.
- Passed rebar3 fmt --check and git diff --check; the earlier Elvis guard warning is addressed without disabling the rule.
Changes:
- Describe public short/long name-mode values rather than internal Erlang shortnames/longnames atoms.
- Add a schema regression for actual context selector spelling.

Validation:
- Validated three real connect/status JSON responses and rejected their negative mutations.
- Passed the focused context schema EUnit check, rebar3 fmt --check, and git diff --check.
Changes:
- Add local describe commands and direct bundled JSON Schema export without target/context access.
- Share command names, option spellings, and sort values between parsing and a typed capability catalog.
- Describe machine-readable dependencies, timeout margins, identifier policies, risks, and authorization requirements.

Validation:
- Passed 166 catalog, CLI, escript, and schema EUnit tests.
- Completed the isolated real-escript agent workflow and validated its 18 JSON responses with 119 rejected negative mutations.
- Rebuilt and verified the packaged schema, and passed rebar3 fmt --check and git diff --check.
- The agent workflow harness will be committed with its dedicated workflow item.
Changes:
- Add trusted follow-up and redacted-sharing workflows with explicit target binding and private report handling.
- Explain response-local aliases, PID lifetime limits, untrusted logs, and non-executing action proposals.
- Register the guide in generated documentation and README navigation.

Validation:
- Passed four identifier/action EUnit tests covering within-response correlation and cross-response alias reuse.
- Built ExDoc documentation without warnings.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Add isolated real-escript acceptance with owned nodes, EPMD, cookies, logs, deadlines, cleanup, and schema-ready fixtures.
- Run agent workflows for Rebar and Mix in CI and document explicit target binding, conservative concurrency, and bounded retry policies.
- Record the CLI changes without introducing a daemon, shared limiter, TUI changes, or a release.

Validation:
- Passed the complete OTP 29 agent workflow; validated 18 emitted envelopes and rejected 119 negative mutations.
- Passed isolated OTP 26 compatibility checks and OTP 26-controller/OTP 29-target text/term checks; rejected JSON trace left sentinel tracing and connection count unchanged.
- Built ExDoc, compiled Python test tools, and passed rebar3 fmt --check and git diff --check.
Changes:
- Align offline rate metadata with recon's stop-on-burst behavior, including retained trip events.
- Keep rate bounds unchanged and avoid promising pacing or an N-event capture limit.

Validation:
- Passed 11 catalog EUnit tests, including the rate-semantics regression.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Update the snapshot integration test for the intentional outcome-first compact header.
- Retain the legacy detailed-header assertion through --verbose and check completed-probe visibility.

Validation:
- Passed the focused snapshot text/term integration test.
- The first full suite found this outdated header expectation (860 tests, one failure); full validation is being rerun.
- Passed rebar3 fmt --check and git diff --check.
Changes:
- Replace shared primitive annotations with property-local units for counts, bytes, bits, seconds, deltas, rates, and opaque scheduler counters.
- Preserve all validation keywords and data acceptance conditions while removing guessed raw OTP GC units.
- Add unconditional schema-unit checks and 14 deliberate unit-corruption regressions.

Validation:
- Validated 102 producer fixtures and rejected 1348 payload mutations.
- Validated 18 real CLI envelopes and rejected 119 payload mutations; both runs rejected 14 schema-unit mutations.
- Verified descriptions are the only schema keyword changes and passed formatting/diff checks.
@codecov

codecov Bot commented Sep 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.70552% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.65%. Comparing base (e0b9e19) to head (64a9bc8).

Files with missing lines Patch % Lines
src/observer_cli_cli.erl 90.56% 10 Missing ⚠️
src/observer_cli_escriptize.erl 90.90% 5 Missing ⚠️
src/observer_cli_catalog.erl 98.41% 3 Missing ⚠️
src/observer_cli_report.erl 97.45% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #142      +/-   ##
==========================================
- Coverage   97.81%   97.65%   -0.17%     
==========================================
  Files          24       27       +3     
  Lines        8064     8452     +388     
==========================================
+ Hits         7888     8254     +366     
- Misses        176      198      +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zhongwencool
zhongwencool merged commit 9682931 into main Sep 30, 2026
8 checks passed
@zhongwencool
zhongwencool deleted the zw/cli-human-agent-improvements branch September 30, 2026 02:39
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