Skip to content

CLI: discoverability & ergonomics improvements (projection flags, scaffolding, clearer verdicts)#299

Merged
maximelb merged 3 commits into
cli-v2from
cli-discoverability-ergonomics
May 30, 2026
Merged

CLI: discoverability & ergonomics improvements (projection flags, scaffolding, clearer verdicts)#299
maximelb merged 3 commits into
cli-v2from
cli-discoverability-ergonomics

Conversation

@maximelb

Copy link
Copy Markdown
Contributor

Proactive developer-experience / discoverability improvements found during routine review of the CLI surface. Each change is small, self-contained, and back-compatible.

Changes

  • Global projection flags. Add --fields (comma-separated), --sort-by, and --reverse on the root cli group, next to the existing --filter. They mirror the existing set_filter_expr/_filter_expr module-level mechanism in output.py, so they flow into every command's render path without per-command wiring. --ai-help global-options listing updated to match.
  • api-key list --name. Filter the result (an object keyed by key-hash whose values carry a name) down to the single matching entry, preserving the raw object shape for back-compat. Help/explain now documents that --output json returns a key-hash-keyed object.
  • ai start-session hive URI form. --definition now accepts both a bare record key and the hive://ai_agent/<name> URI form (the form the D&R start ai agent action uses); both resolve to the same record. SDK docstring and CLI help updated.
  • hive validate explicit verdict. On success, print Record is valid. to stderr (keeping stdout machine-stable) and emit {"valid": true} for json/yaml when the API response is empty. Failure still raises and exits non-zero.
  • hive set metadata flags. Add --tag-add/--tag-rm (repeatable, additive), --comment, and --expiry. Metadata-only update (modeled on enable/disable) when no data is supplied; applied as overrides when data is supplied.
  • secret set --value + tag subcommand. On hive-shortcut groups: add --value (wraps into {data: {secret: value}}), --tag, and --comment; plus a tag subgroup (add/rm/set) doing the get-metadata → merge → set round-trip (modeled on case tag). --value help notes the shell-history exposure; stdin/--input-file remains recommended.
  • dr set --detect/--respond/--tag. Assemble a rule from component files into {data:{detect,respond}, usr_mtd:{enabled,tags}}; mutually exclusive with --input-file. --input-file/stdin still work.
  • cloud-adapter/external-adapter list-types. New subcommand printing supported adapter types with descriptions, derived from the cloud_sensor JSON-schema with a curated fallback. Also fixes stale "...and others" prose that omitted threatlocker.
  • hive schema flat rendering. Default (non-json) output is now a flat field table resolving $ref/$defs into name | type | required | notes rows. Raw JSON-Schema remains available via --output json.
  • event types empty-result hint. Note that an empty result on a fresh org means no events have been observed yet (the schema is observed, not declared) — not a misconfiguration.

Tests

  • New tests/unit/test_cli_ergonomics.py covering projection state, api-key --name, validate verdict, hive set metadata flags, secret --value/tag, dr component assembly, adapter list-types, and schema flat rendering.
  • New start_session hive-URI tests in tests/unit/test_sdk_ai_sessions.py.
  • Updated CLI surface snapshots in test_cli_lazy_loading_regression.py and test_dataclasses.py.

All pre-existing test failures (111) are environmental in this checkout (toon_format stub NotImplementedError, and a newer click that dropped CliRunner(mix_stderr=...)) and are unrelated to these changes; no existing tests were weakened or skipped.

🤖 Generated with Claude Code

maximelb and others added 3 commits May 29, 2026 20:59
Proactive developer-experience improvements found during routine review
of the CLI surface. Each change is small and self-contained.

- Global projection flags: add --fields, --sort-by, --reverse on the
  root group, mirroring the existing --filter module-level mechanism in
  output.py so they flow into every command's render path.
- api-key list --name: filter the key-hash-keyed result down to the
  single matching key while preserving the raw object shape.
- start-session: accept the hive://ai_agent/<name> URI form (the form
  the D&R 'start ai agent' action uses) in addition to a bare key.
- hive validate: emit an explicit positive verdict ("Record is valid."
  to stderr; {"valid": true} for json/yaml when the API is silent),
  keeping stdout machine-stable.
- hive set: add --tag-add/--tag-rm (additive), --comment, --expiry;
  metadata-only update when no data is supplied, overrides otherwise.
- secret set --value and a 'tag' subcommand (add/rm/set) on hive
  shortcut groups; --value documents the shell-history exposure.
- dr set --detect/--respond/--tag: assemble a rule from component files
  (mutually exclusive with --input-file).
- cloud-adapter/external-adapter list-types: derive supported adapter
  types from the cloud_sensor schema with a curated fallback; fix stale
  "...and others" prose that omitted threatlocker.
- hive schema: default to a flat field table (resolving $ref/$defs);
  raw JSON-Schema still available via --output json.
- event types: note that an empty result on a fresh org is expected
  (the schema is observed, not declared).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The shared hive shortcut set command exposed --value wrapping the input as
{data: {secret: <value>}} for every hive, but only the secret hive uses a
single "secret" data field — the wrapper was meaningless (and wrong) for the
structured-data hives (lookup, fp, playbook, note, sop, adapters, ai-skill).

make_hive_group now takes an optional value_key naming the hive's single
scalar data field. --value is offered only when value_key is set (the secret
group declares value_key="secret") and wraps as {data: {<value_key>: <value>}}.
Structured-data hives no longer advertise --value at all.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
list-types derived its list from the bare JSON-Schema $defs keys, which are
helper structs (ClientOptions, AckBufferOptions, Dict, …), not adapter types —
so it printed garbage. The reflected schema is a root that $refs into the
record definition (CloudSensorRecord / ExternalAdapterConfig); the real type
names are that record's properties (s3, office365, threatlocker, …) minus the
sensor_type discriminator.

- Resolve the root $ref into the record and use its properties (fall back to
  inline root properties); never enumerate raw $defs keys.
- Parameterize by hive so cloud-adapter reads cloud_sensor and external-adapter
  reads external_adapter (their type sets genuinely differ).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maximelb maximelb requested a review from dzimine-lc May 30, 2026 15:21
@maximelb maximelb marked this pull request as ready for review May 30, 2026 15:21
@maximelb

Copy link
Copy Markdown
Contributor Author

/gcbrun

@maximelb maximelb merged commit 4ffb18a into cli-v2 May 30, 2026
6 of 7 checks passed
@maximelb maximelb deleted the cli-discoverability-ergonomics branch May 30, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant