Skip to content

feat(cases): fix create flag path, add comment subcommands, split case-management agent#504

Merged
platinummonkey merged 4 commits into
DataDog:mainfrom
avidal:feat/cases-improvements
May 14, 2026
Merged

feat(cases): fix create flag path, add comment subcommands, split case-management agent#504
platinummonkey merged 4 commits into
DataDog:mainfrom
avidal:feat/cases-improvements

Conversation

@avidal
Copy link
Copy Markdown
Contributor

@avidal avidal commented May 14, 2026

Summary

Two related changes bundled under "improve case management":

  1. CLI fixes for pup cases:

    • cases create flag path was sending malformed JSON (type_id stuffed into data.attributes.type instead of data.attributes.type_id, no way to attach a project relationship). Replaced the hand-rolled JSON with the typed CaseCreateRequest from the API client.
    • Added --project-id <uuid> flag to cases create so the flag path can assign a project on create (previously only --file could).
    • Added cases comment <case-id> --body "..." and cases delete-comment <case-id> --comment-id <id> subcommands wrapping comment_case / delete_case_comment. Previously the only path to commenting was raw pup api -X POST v2/cases/<id>/comment with hand-built JSON.
    • Added cases update-description <case-id> --description "..." subcommand wrapping update_case_description. The API method existed but wasn't exposed. Combined with the comment-API gaps, the description is the only case-level surface that's both updatable and discoverable via CLI, so this unlocks the "synthesize rollup status in the description" workflow.
    • Changed cases search --page-number default from 0 to 1. The API rejects 0 with page number must be > 0, so the documented default never produced a successful call.
    • Extracted a shared parse_priority helper (was duplicated between create_from_flags and update_priority).
  2. Agent docs refactor — extract case-management from incident-response:

    • Created agents/case-management.md covering the full pup cases ... surface. Case Management is a standalone Datadog product used by Incident Response, Error Tracking, Security Signals, and ad-hoc operator workflows — burying it inside incident-response made it harder for non-incident consumers to find.
    • Slimmed agents/incident-response.md (834 → 714 lines) to reference case-management for case ops, keeping only the short incident-flow snippets that chain into case actions.
    • Updated agents/error-tracking.md to point at the new agent for its case mention.
    • Fixed inaccurate CLI examples that didn't match the actual pup CLI (e.g., pup cases listpup cases search; pup cases update CASE --status=Xpup cases update-status CASE --status X; --user=<email>--user-id <uuid>; etc.).

Why these came up together

These fixes surfaced while using pup cases end-to-end against real cases — opening cases, leaving PR-link comments, synthesizing rollup status, etc. The CLI gaps (no --project-id, malformed create body, no comment subcommand, no description-update subcommand, --page-number 0 rejected) forced repeated raw-API workarounds, and the agent docs documented behavior that didn't match the actual CLI. Single PR keeps the "improve case management" thread coherent rather than splitting closely-related fixes.

Changes

CLI (src/)

  • src/commands/cases.rs — rewrote create_from_flags to use typed CaseCreateRequest + add project_id: Option<&str> parameter
  • src/commands/cases.rs — new comment, delete_comment, and update_description functions
  • src/commands/cases.rs — extracted parse_priority helper; update_priority now uses it
  • src/main.rscases search --page-number default → 1
  • src/main.rs — new project_id flag on the Create clap struct
  • src/main.rs — new Comment, DeleteComment, and UpdateDescription clap variants + routing

Tests

  • src/commands/cases.rs:tests — added tests for create_from_flags (happy path + with --project-id + invalid priority), comment, delete_comment, update_description, parse_priority (valid + invalid). All 13 case tests pass.

Docs (agents/)

  • agents/case-management.md — new, ~290 lines, full case CLI surface + known API gaps (no list-comments endpoint, comment text not search-indexed, comment_count always 0 on get and only populated by search). Recommends synthesizing rollup-style status in the description rather than comments when CLI discoverability matters.
  • agents/incident-response.md — slimmed to 714 lines, references case-management for case ops, fixed inaccurate CLI snippets in remaining workflow sections.
  • agents/error-tracking.md — pointer to case-management for its case mention.

Test plan

  • cargo build — clean
  • cargo test --bin pup cases:: — 13 tests pass
  • cargo fmt --check — clean
  • cargo clippy -- -D warnings — clean
  • Manual verification against live cases:
    • pup cases get <human-key> — works with the human key
    • pup cases search --query "project_id:<uuid>" — no --page-number needed (default 1)
    • pup cases comment <case-id> --body "..." — posts; response includes the new comment id
    • pup cases delete-comment <case-id> --comment-id <id> — deletes; second-delete returns 404 confirming the first took effect
    • Search-indexing observation: comment text is NOT indexed (free-text queries for unique comment substrings return 0); title/description text IS indexed

Known API gaps (not addressed in this PR — upstream Case Management API team)

  • No list-comments endpoint at this API client revision; documented in the new case-management agent.
  • comment_count is always 0 on the get_case response — only populated by search_cases results.
  • search_cases does not index comment text (title and description only).

The new agent documents these so users know to fall back to the UI for comment-based discovery.

avidal and others added 2 commits May 14, 2026 15:55
…number default

Four related case-management CLI fixes surfaced while using pup against
real cases:

- `cases create --type-id <id>` was sending a malformed JSON body. The
  type_id was being stuffed into `data.attributes.type` rather than
  `data.attributes.type_id`, and the project relationship couldn't be
  attached at all. Replace the hand-rolled JSON with the typed
  `CaseCreateRequest` from the API client so the shape matches the
  spec.

- Add `--project-id <uuid>` to `cases create`. Builds
  `CaseCreateRelationships` from the flag value. Closes the gap where
  the only way to assign a new case to a project was the `--file`
  path. Cases without a project assignment are hard to find later
  (most search facets require `project_id`).

- Add `cases comment <case-id> --body "..."` subcommand wrapping the
  `comment_case` API method. Previously there was no CLI surface for
  posting comments; users had to construct raw `pup api -X POST
  v2/cases/<id>/comment` calls with the right JSON:API shape, which
  required iteration to discover (the comment body needs
  `"type": "case"`, not the intuitive `"case_comment"`).

- Add `cases delete-comment <case-id> --comment-id <id>` wrapping
  `delete_case_comment`.

- `cases search --page-number` defaulted to 0, but the API rejects 0
  with `page number must be > 0`. Change the default to 1.

- Extract a shared `parse_priority` helper used by both
  `create_from_flags` and `update_priority` (previously duplicated).

Tests cover happy paths for both new subcommands, the new
`--project-id` path on create, the previously-broken-now-fixed flag
create path, and the priority parser (valid + invalid). All 12 case
tests pass; cargo fmt + clippy clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Datadog Case Management is a standalone product used by Incident Response,
Error Tracking, Security Signals, and ad-hoc operator workflows. The
incident-response agent bundled the entire case CLI surface inside it,
which made it hard for non-incident consumers to find and meant case
documentation only updated when someone touched incident-response.

Extract `agents/case-management.md` as its own agent covering the
full `pup cases ...` surface. Slim `agents/incident-response.md` to
reference case-management for case operations, retaining only the
short incident-flow examples that chain into case actions. Update
the case-management mention in `agents/error-tracking.md` to point
at the new agent.

While doing the extraction, fix several inaccurate CLI examples in
incident-response that didn't match the actual pup CLI:
- `pup cases list` -> `pup cases search` (with --query)
- `pup cases update CASE --status=X` -> `pup cases update-status CASE --status X`
- `pup cases comment --text=` -> `pup cases comment --body`
- `pup cases assign --user=<email>` -> `pup cases assign --user-id <uuid>`
- `pup cases unassign` -> removed (no such subcommand)
- `pup cases attribute` -> removed (no such subcommand)
- `pup cases projects create --name=` -> requires both --name and --key

The new case-management agent documents the correct CLI surface, the
known API gaps (no list-comments endpoint, comment_count doesn't refresh
promptly), and the well-supported search facet (`project_id:<uuid>`).

incident-response.md shrinks from 834 to 714 lines; case-management.md
is 288 lines.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avidal avidal requested a review from a team as a code owner May 14, 2026 20:59
Confirmed via dev-binary smoke test: searches for substrings that
exist only in comments return zero results (toolbox-shell comment
phrases, PR numbers posted as comments, etc.), while the same kind
of substring from a case title or description matches. Combined
with the missing list-comments endpoint, this means there's no way
to find a case by its comments via the CLI — operators must use
the Datadog UI for any comment-based discovery.

Also corrects the `comment_count` note: it's not a refresh-lag
issue — the field is always 0 on `pup cases get`, and is only
populated in `pup cases search` results.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avidal avidal force-pushed the feat/cases-improvements branch from ff5feae to db8e40c Compare May 14, 2026 21:06
The `update_case_description` API method exists in the client but
wasn't exposed by the CLI. Add `pup cases update-description <case-id>
--description "..."` matching the existing update-{status,priority,title}
pattern.

This is more than just symmetry. Combined with the gaps already
documented in the new case-management agent (no list-comments endpoint,
search not indexing comment text, comment_count always 0 on get), the
description is the only case-level surface that's both updatable and
discoverable via CLI. The new agent now recommends synthesizing
rollup-style status in the description rather than scattered comments
when CLI discoverability matters.

Test coverage parallels the existing update-* tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@platinummonkey platinummonkey merged commit 016e327 into DataDog:main May 14, 2026
6 checks passed
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.

2 participants