Skip to content

feat(history): object change history (audit log) — CLI + MCP - #84

Merged
lance0 merged 2 commits into
masterfrom
feat/history-tool
Jun 25, 2026
Merged

lance0 merged 2 commits into
masterfrom
feat/history-tool

Conversation

@lance0

@lance0 lance0 commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

nbox history <kind> <ref> shows the system-recorded create/update/delete timeline for an object (who, when, and which fields changed), from /api/core/object-changes/ (NetBox 4.x). Distinct from nbox journal (operator notes): this is the audit trail.

Answers a top agent query — "what happened to this prefix/device/IP?" — that nbox could not answer before.

Shape

Each row carries: time / action / user / object / message / fields_changed / request_id.

fields_changed lists the top-level fields whose values differ pre vs post (a sorted diff), not the full before/after JSON (which can be kilobytes per row). The full diff is a planned --diff follow-up.

$ nbox history device edge01
2025-12-08T23:56:49Z  Updated  neteng  — edge01
  fields: asset_tag

2025-11-01T00:00:00Z  Created  fleetops  — edge01
  initial provisioning

Implementation (mirrors nbox journal)

The ref→kind→content-type→id resolution is shared (resolve_content_type_id) — just a different endpoint + richer payload:

Layer What
models/extras.rs ObjectChange model (action/user/time/object_repr/request_id/prechange/postchange)
endpoints.rs Endpoint::CoreObjectChanges → /api/core/object-changes/
query.rs object_changes(content_type, object_id, max) — mirrors journal_entries, scoped by changed_object_type + changed_object_id, ordered -time
domain/history_view.rs HistoryView + HistoryRow: from_models renders the fields-changed diff; to_plain renders the timeline
cli.rs nbox history <kind> <ref> [--limit N] — mirrors nbox journal
lib.rs run_history handler (mirrors run_journal)
mcp/mod.rs nbox_history MCP tool (mirrors nbox_journal) — tools 10 → 11

Tests (6 new)

  • 4 history_view unit tests: render-with-fields-and-user, empty-explicit, create-no-fields (prechange null → no diff), user-fallback-to-nested-object
  • 1 MCP functional: history_returns_changes_for_device — pins fields_changed = ["site_id", "status"] for an update (status changed, site_id added, name unchanged)
  • 1 MCP contract: history_view_shape_is_pinned — pins the key set (time/action/action_label/user/object/fields_changed/request_id; message omitted when empty)

EXPECTED_TOOLS bumped 10 → 11 in both mcp_serve_tests and mcp_serve_http_tests.

Verification

  • Gate: fmt, clippy --all-targets --all-features -- -D warnings, test --all-features (1116 pass, +6), test --no-default-features (1021 pass, +2) — all green.
  • Live: nbox history device <name> against the 4.6.2 box returns the audit timeline with fields_changed (e.g. fields: asset_tag on an update); JSON view carries the structured fields.
  • Scoping verified: changed_object_type=dcim.device&changed_object_id=573 isolates one object exactly (the dotted form works; id alone is ambiguous across types).

Docs

  • AGENTS.md, README.md, docs/FEATURES.md, docs/MCP.md, docs/SCRIPTING.md — command + tool lists updated; "ten tools" → "eleven tools"; "10 read tools" → "11" (ROADMAP).
  • CHANGELOG.md [Unreleased] → ### Added.
  • ROADMAP.md history item ☐ → ☑.

Files

18 files, +549/−12. New: src/domain/history_view.rs (+248 incl. tests).

This is a new capability — the highest-impact next win after three structural-but-imperceptible perf fixes (cap normalize, browse revert, search per-endpoint cap). A user will notice it's there.

lance0 added 2 commits June 24, 2026 21:11
nbox history <kind> <ref> shows the system-recorded create/update/delete
timeline for an object (who, when, and which fields changed) from
/api/core/object-changes/ (NetBox 4.x). Distinct from nbox journal (operator
notes): this is the audit trail. Answers a top agent query — "what happened to
this prefix/device/IP?" — that nbox could not answer before.

Each row carries time/action/user/object/message/fields_changed/request_id.
fields_changed lists the top-level fields whose values differ pre vs post (a
sorted diff), not the full before/after JSON (which can be kilobytes per row).
The full diff is a planned --diff follow-up.

Mirrors nbox journal almost exactly — the ref→kind→content-type→id resolution
is shared (resolve_content_type_id), just a different endpoint + richer payload:

- ObjectChange model (action/user/time/object_repr/request_id/prechange_data/
  postchange_data) in models/extras.rs
- Endpoint::CoreObjectChanges + object_changes(content_type, object_id, max)
  query (mirrors journal_entries, against /api/core/object-changes/)
- HistoryView + HistoryRow (domain/history_view.rs): from_models renders the
  fields-changed diff; to_plain renders the timeline
- nbox history CLI command (mirrors nbox journal) + run_history handler
- nbox_history MCP tool (mirrors nbox_journal) — tools 10 → 11
- EXPECTED_TOOLS bumped in mcp_serve_tests + mcp_serve_http_tests

Tests: 4 history_view unit tests (render, empty, create-no-fields, user
fallback) + 1 MCP functional test (history_returns_changes_for_device) + 1
MCP contract test (history_view_shape_is_pinned — pins the key set). 1116
all-features / 1021 no-default, clippy -D warnings, fmt.

Verified live against 4.6.2: nbox history device <name> returns the audit
timeline with fields_changed (e.g. "fields: asset_tag" on an update).

Docs: AGENTS, README, FEATURES, MCP, SCRIPTING command/tool lists updated;
"ten tools" → "eleven tools" across README/MCP/SCRIPTING; "10 read tools" →
"11" in ROADMAP; CHANGELOG [Unreleased] Added; ROADMAP history item ☐→☑.
@lance0
lance0 merged commit 61300d4 into master Jun 25, 2026
4 checks passed
@lance0
lance0 deleted the feat/history-tool branch June 25, 2026 01:21
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